Skip to content

Commit d413c55

Browse files
authored
fix(l1): always use fullsync if db had data (#5196)
**Motivation** When the db had data, we should fullsync, not override the user's data **Description** - Changes the fullsync option instead of snap to be any number instead of `MIN_FULL_BLOCKS`
1 parent 11fe1c1 commit d413c55

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

crates/networking/p2p/sync.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use tokio_util::sync::CancellationToken;
4747
use tracing::{debug, error, info, warn};
4848

4949
/// The minimum amount of blocks from the head that we want to full sync during a snap sync
50-
const MIN_FULL_BLOCKS: usize = 64;
50+
const MIN_FULL_BLOCKS: u64 = 10_000;
5151
/// Amount of blocks to execute in a single batch during FullSync
5252
const EXECUTE_BATCH_SIZE_DEFAULT: usize = 1024;
5353
/// Amount of seconds between blocks
@@ -288,17 +288,16 @@ impl Syncer {
288288
current_head = last_block_hash;
289289
current_head_number = last_block_number;
290290

291-
// If the sync head is less than 64 blocks away from our current head switch to full-sync
292-
if sync_head_found {
293-
let latest_block_number = store.get_latest_block_number().await?;
294-
if last_block_number.saturating_sub(latest_block_number) < MIN_FULL_BLOCKS as u64 {
295-
// Too few blocks for a snap sync, switching to full sync
296-
debug!(
297-
"Sync head is less than {MIN_FULL_BLOCKS} blocks away, switching to FullSync"
298-
);
299-
self.snap_enabled.store(false, Ordering::Relaxed);
300-
return self.sync_cycle_full(sync_head, store.clone()).await;
301-
}
291+
// If the sync head is not 0 we search to fullsync
292+
let head_found = sync_head_found && store.get_latest_block_number().await? > 0;
293+
// Or the head is very close to 0
294+
let head_close_to_0 = last_block_number < MIN_FULL_BLOCKS;
295+
296+
if head_found || head_close_to_0 {
297+
// Too few blocks for a snap sync, switching to full sync
298+
info!("Sync head is found, switching to FullSync");
299+
self.snap_enabled.store(false, Ordering::Relaxed);
300+
return self.sync_cycle_full(sync_head, store.clone()).await;
302301
}
303302

304303
// Discard the first header as we already have it

crates/networking/rpc/engine/fork_choice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use ethrex_blockchain::{
44
payload::{BuildPayloadArgs, create_payload},
55
};
66
use ethrex_common::types::{BlockHeader, ELASTICITY_MULTIPLIER};
7-
use ethrex_p2p::sync::SyncMode;
87
use serde_json::Value;
98
use tracing::{info, warn};
109

@@ -215,6 +214,7 @@ async fn handle_forkchoice(
215214
));
216215
}
217216

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

234234
match apply_fork_choice(
235235
&context.storage,

0 commit comments

Comments
 (0)