From e2033db822576d3edf2b9741193253f136e50474 Mon Sep 17 00:00:00 2001 From: Francisco Xavier Gauna Date: Wed, 5 Nov 2025 11:22:32 -0300 Subject: [PATCH 1/5] Update sync.rs --- crates/networking/p2p/sync.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/networking/p2p/sync.rs b/crates/networking/p2p/sync.rs index 37bf6fdeb35..4fddb29c64a 100644 --- a/crates/networking/p2p/sync.rs +++ b/crates/networking/p2p/sync.rs @@ -285,14 +285,12 @@ impl Syncer { current_head = last_block_hash; 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 the sync head is not 0 we search to fullsync 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 { + if latest_block_number != 0 { // 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" - ); + debug!("Sync head is found switching to FullSync"); self.snap_enabled.store(false, Ordering::Relaxed); return self.sync_cycle_full(sync_head, store.clone()).await; } From e4dc36da0170638e368890a4601bd52156c35abf Mon Sep 17 00:00:00 2001 From: Francisco Xavier Gauna Date: Wed, 5 Nov 2025 11:43:51 -0300 Subject: [PATCH 2/5] Update sync.rs --- crates/networking/p2p/sync.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/networking/p2p/sync.rs b/crates/networking/p2p/sync.rs index 4fddb29c64a..9d2ba62124e 100644 --- a/crates/networking/p2p/sync.rs +++ b/crates/networking/p2p/sync.rs @@ -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 = 1_000_000; /// Amount of blocks to execute in a single batch during FullSync const EXECUTE_BATCH_SIZE_DEFAULT: usize = 1024; /// Amount of seconds between blocks @@ -286,14 +286,15 @@ impl Syncer { current_head_number = last_block_number; // If the sync head is not 0 we search to fullsync - if sync_head_found { - let latest_block_number = store.get_latest_block_number().await?; - if latest_block_number != 0 { - // Too few blocks for a snap sync, switching to full sync - debug!("Sync head is found switching to FullSync"); - self.snap_enabled.store(false, Ordering::Relaxed); - return self.sync_cycle_full(sync_head, store.clone()).await; - } + 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; + + 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 From 68d046df31cb095425766aaa0b3c9753860cd4c8 Mon Sep 17 00:00:00 2001 From: Francisco Xavier Gauna Date: Wed, 5 Nov 2025 11:44:29 -0300 Subject: [PATCH 3/5] Lowered number --- crates/networking/p2p/sync.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/networking/p2p/sync.rs b/crates/networking/p2p/sync.rs index 9d2ba62124e..7e891f1d44a 100644 --- a/crates/networking/p2p/sync.rs +++ b/crates/networking/p2p/sync.rs @@ -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: u64 = 1_000_000; +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 From 636a5945cadb5db7b9ccfc6e125267b8e13da798 Mon Sep 17 00:00:00 2001 From: Francisco Xavier Gauna Date: Wed, 5 Nov 2025 12:28:59 -0300 Subject: [PATCH 4/5] Reverted PR 4985 --- crates/networking/rpc/engine/fork_choice.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/networking/rpc/engine/fork_choice.rs b/crates/networking/rpc/engine/fork_choice.rs index f1e74bb4fa6..f065112cc6e 100644 --- a/crates/networking/rpc/engine/fork_choice.rs +++ b/crates/networking/rpc/engine/fork_choice.rs @@ -215,6 +215,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 @@ -229,7 +230,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, From 97b035e94c846594070da536e4020217bf9c402d Mon Sep 17 00:00:00 2001 From: Francisco Xavier Gauna Date: Wed, 5 Nov 2025 12:40:05 -0300 Subject: [PATCH 5/5] Update fork_choice.rs --- crates/networking/rpc/engine/fork_choice.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/networking/rpc/engine/fork_choice.rs b/crates/networking/rpc/engine/fork_choice.rs index f065112cc6e..5ee2984015c 100644 --- a/crates/networking/rpc/engine/fork_choice.rs +++ b/crates/networking/rpc/engine/fork_choice.rs @@ -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};