Skip to content

Commit

Permalink
Node stuck and eth_syncing (#2292)
Browse files Browse the repository at this point in the history
* feat: dump some statistics to eth_syncing RPC call, to indicate progress.

* feat: dump more error stats.

* fix: #2252 - #2252

* nit: change the max_batch_size/max_blocks_in_flight clamps to more logical numbers.

* feat: return current_state as a string instead.

* fix: post cherry-pick issues.

* feat: implement ToString trait for SyncState.

* fix: removed prototype sub-segments.
  • Loading branch information
shawn-zil authored Feb 5, 2025
1 parent fd5eb37 commit 1f09adc
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 73 deletions.
12 changes: 3 additions & 9 deletions zilliqa/src/api/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use tracing::*;
use super::{
to_hex::ToHex,
types::eth::{
self, CallParams, ErrorCode, HashOrTransaction, OneOrMany, SyncingResult, SyncingStruct,
self, CallParams, ErrorCode, HashOrTransaction, OneOrMany, SyncingResult,
TransactionReceipt,
},
};
Expand Down Expand Up @@ -895,14 +895,8 @@ fn protocol_version(_: Params, _: &Arc<Mutex<Node>>) -> Result<String> {

fn syncing(params: Params, node: &Arc<Mutex<Node>>) -> Result<SyncingResult> {
expect_end_of_params(&mut params.sequence(), 0, 0)?;
if let Some((starting_block, current_block, highest_block)) =
node.lock().unwrap().consensus.get_sync_data()?
{
Ok(SyncingResult::Struct(SyncingStruct {
starting_block,
current_block,
highest_block,
}))
if let Some(result) = node.lock().unwrap().consensus.get_sync_data()? {
Ok(SyncingResult::Struct(result))
} else {
Ok(SyncingResult::Bool(false))
}
Expand Down
14 changes: 14 additions & 0 deletions zilliqa/src/api/types/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,26 @@ pub struct TxPoolContent {
pub queued: HashMap<Address, HashMap<u64, Transaction>>,
}

#[derive(Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncingMeta {
pub current_phase: String,
pub peer_count: usize,
pub header_downloads: u64,
pub block_downloads: u64,
pub buffered_blocks: usize,
pub empty_count: u64,
pub retry_count: u64,
pub timeout_count: u64,
}

#[derive(Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncingStruct {
pub starting_block: u64,
pub current_block: u64,
pub highest_block: u64,
pub status: SyncingMeta,
}

#[derive(Clone, Serialize)]
Expand Down
5 changes: 3 additions & 2 deletions zilliqa/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
time::Duration,
};

use alloy::primitives::{Address, BlockNumber, U256};
use alloy::primitives::{Address, U256};
use anyhow::{anyhow, Context, Result};
use bitvec::{bitarr, order::Msb0};
use eth_trie::{EthTrie, MemoryDB, Trie};
Expand All @@ -19,6 +19,7 @@ use tokio::sync::{broadcast, mpsc::UnboundedSender};
use tracing::*;

use crate::{
api::types::eth::SyncingStruct,
blockhooks,
cfg::{ConsensusConfig, NodeConfig},
constants::TIME_TO_ALLOW_PROPOSAL_BROADCAST,
Expand Down Expand Up @@ -3119,7 +3120,7 @@ impl Consensus {
Ok(())
}

pub fn get_sync_data(&self) -> Result<Option<(BlockNumber, BlockNumber, BlockNumber)>> {
pub fn get_sync_data(&self) -> Result<Option<SyncingStruct>> {
self.sync.get_sync_data()
}
}
Expand Down
2 changes: 1 addition & 1 deletion zilliqa/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ impl Db {
}

/// Pushes a particular segment into the stack.
pub fn push_sync_segment(&self, peer: PeerInfo, meta: BlockHeader) -> Result<()> {
pub fn push_sync_segment(&self, peer: &PeerInfo, meta: &BlockHeader) -> Result<()> {
let db = self.db.lock().unwrap();
db.prepare_cached(
"INSERT OR REPLACE INTO sync_metadata (parent_hash, block_hash, block_number, version, peer, rawdata) VALUES (:parent_hash, :block_hash, :block_number, :version, :peer, :rawdata)")?
Expand Down
2 changes: 1 addition & 1 deletion zilliqa/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ impl Node {
}
trace!("Handling proposal for view {0}", req.block.header.view);
let proposal = self.consensus.receive_block(from, req.block)?;
self.consensus.sync.mark_received_proposal(req.from)?;
self.consensus.sync.mark_received_proposal()?;
if let Some(proposal) = proposal {
trace!(
" ... broadcasting proposal for view {0}",
Expand Down
Loading

0 comments on commit 1f09adc

Please sign in to comment.