Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions crates/networking/p2p/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use tokio_util::sync::CancellationToken;
use tracing::{debug, error, info, warn};

/// The minimum amount of blocks from the head that we want to full sync during a snap sync
const MIN_FULL_BLOCKS: usize = 64;
const MIN_FULL_BLOCKS: u64 = 10_000;
/// Amount of blocks to execute in a single batch during FullSync
const EXECUTE_BATCH_SIZE_DEFAULT: usize = 1024;
/// Amount of seconds between blocks
Expand Down Expand Up @@ -285,17 +285,16 @@ impl Syncer {
current_head = last_block_hash;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to revert #4985 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing in 636a594

current_head_number = last_block_number;

// If the sync head is less than 64 blocks away from our current head switch to full-sync
if sync_head_found {
let latest_block_number = store.get_latest_block_number().await?;
if last_block_number.saturating_sub(latest_block_number) < MIN_FULL_BLOCKS as u64 {
// Too few blocks for a snap sync, switching to full sync
debug!(
"Sync head is less than {MIN_FULL_BLOCKS} blocks away, switching to FullSync"
);
self.snap_enabled.store(false, Ordering::Relaxed);
return self.sync_cycle_full(sync_head, store.clone()).await;
}
// If the sync head is not 0 we search to fullsync
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, if the sync head is 0 pero is less than X blocks away, we should also not do snap sync. Snap sync is for 1M blocks distance, not 100.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e4dc36d

let head_found = sync_head_found && store.get_latest_block_number().await? > 0;
// Or the head is very close to 0
let head_close_to_0 = last_block_number < MIN_FULL_BLOCKS;
Copy link
Collaborator

@MegaRedHand MegaRedHand Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This skips snap-syncing when we have a few blocks in the DB, while the old logic compared the distance between head and sync-head.

Edit: this skips snap-syncing when the sync-head's block number is less than 10000


if head_found || head_close_to_0 {
// Too few blocks for a snap sync, switching to full sync
info!("Sync head is found, switching to FullSync");
self.snap_enabled.store(false, Ordering::Relaxed);
return self.sync_cycle_full(sync_head, store.clone()).await;
}

// Discard the first header as we already have it
Expand Down
4 changes: 2 additions & 2 deletions crates/networking/rpc/engine/fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use ethrex_blockchain::{
payload::{BuildPayloadArgs, create_payload},
};
use ethrex_common::types::{BlockHeader, ELASTICITY_MULTIPLIER};
use ethrex_p2p::sync::SyncMode;
use serde_json::Value;
use tracing::{info, warn};

Expand Down Expand Up @@ -215,6 +214,7 @@ async fn handle_forkchoice(
));
}

/* Revert #4985
if context.syncer.sync_mode() == SyncMode::Snap {
// Don't trigger a sync if the block is already canonical
if context
Expand All @@ -229,7 +229,7 @@ async fn handle_forkchoice(
.sync_to_head(fork_choice_state.head_block_hash);
return Ok((None, PayloadStatus::syncing().into()));
}
}
} */

match apply_fork_choice(
&context.storage,
Expand Down