Skip to content

Commit d70e9b1

Browse files
byteZorvinheemankv
andauthored
Feature/add no reorg (#822)
Co-authored-by: Heemank Verma <[email protected]>
1 parent d165ac9 commit d70e9b1

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

configs/args/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"n_blocks_to_sync": null,
4949
"stop_on_sync": false,
5050
"backup_every_n_blocks": null,
51-
"bouncer_config_sync_enable": false
51+
"bouncer_config_sync_enable": false,
52+
"disable_reorg": false
5253
},
5354
"l1_sync_params": {
5455
"l1_sync_disabled": true,

madara/crates/client/sync/src/gateway/blocks.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@ pub fn block_with_state_update_pipeline(
2828
batch_size: usize,
2929
keep_pre_v0_13_2_hashes: bool,
3030
sync_bouncer_config: bool,
31+
disable_reorg: bool,
3132
) -> GatewayBlockSync {
3233
PipelineController::new(
33-
GatewaySyncSteps { _backend: backend, importer, client, keep_pre_v0_13_2_hashes, sync_bouncer_config },
34+
GatewaySyncSteps {
35+
_backend: backend,
36+
importer,
37+
client,
38+
keep_pre_v0_13_2_hashes,
39+
sync_bouncer_config,
40+
disable_reorg,
41+
},
3442
parallelization,
3543
batch_size,
3644
starting_block_n,
@@ -44,6 +52,7 @@ pub struct GatewaySyncSteps {
4452
client: Arc<GatewayProvider>,
4553
keep_pre_v0_13_2_hashes: bool,
4654
sync_bouncer_config: bool,
55+
disable_reorg: bool,
4756
}
4857

4958
impl GatewaySyncSteps {
@@ -291,6 +300,25 @@ impl PipelineSteps for GatewaySyncSteps {
291300
block_n, incoming_parent_hash, local_parent_hash
292301
);
293302

303+
// Check if reorg is disabled
304+
if self.disable_reorg {
305+
tracing::error!("❌ REORG DETECTED but reorg is explicitly denied by config!");
306+
tracing::error!(" Block number: {}", block_n);
307+
tracing::error!(" Expected parent hash: {:#x}", local_parent_hash);
308+
tracing::error!(" Incoming parent hash: {:#x}", incoming_parent_hash);
309+
tracing::error!("");
310+
tracing::error!("⚠️ Divergent state detected - the local chain has diverged from the upstream chain.");
311+
tracing::error!("⚠️ Blockchain reorganization is required but disabled by reorg is explicitly denied by config.");
312+
tracing::error!("");
313+
tracing::error!("To resolve this issue, you can:");
314+
tracing::error!(" 1. Allow auto reorgs using the config");
315+
tracing::error!(" 2. Manually investigate the divergence and wipe the database if needed");
316+
anyhow::bail!(
317+
"Reorg required but disabled by config. Parent hash mismatch at block {}: expected {:#x}, got {:#x}",
318+
block_n, local_parent_hash, incoming_parent_hash
319+
);
320+
}
321+
294322
// Try to find common ancestor
295323
match self.find_common_ancestor(block_n - 1).await {
296324
Ok(common_ancestor_hash) => {

madara/crates/client/sync/src/gateway/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub struct ForwardSyncConfig {
2727
pub snap_sync: bool,
2828
pub keep_pre_v0_13_2_hashes: bool,
2929
pub enable_bouncer_config_sync: bool,
30+
pub disable_reorg: bool,
3031
}
3132

3233
impl Default for ForwardSyncConfig {
@@ -42,6 +43,7 @@ impl Default for ForwardSyncConfig {
4243
snap_sync: false,
4344
keep_pre_v0_13_2_hashes: false,
4445
enable_bouncer_config_sync: false,
46+
disable_reorg: false,
4547
}
4648
}
4749
}
@@ -60,6 +62,9 @@ impl ForwardSyncConfig {
6062
pub fn enable_bouncer_config_sync(self, val: bool) -> Self {
6163
Self { enable_bouncer_config_sync: val, ..self }
6264
}
65+
pub fn disable_reorg(self, val: bool) -> Self {
66+
Self { disable_reorg: val, ..self }
67+
}
6368
}
6469

6570
pub type GatewaySync = SyncController<GatewayForwardSync>;
@@ -110,6 +115,7 @@ impl GatewayForwardSync {
110115
config.block_batch_size,
111116
config.keep_pre_v0_13_2_hashes,
112117
config.enable_bouncer_config_sync,
118+
config.disable_reorg,
113119
);
114120
let classes_pipeline = classes::classes_pipeline(
115121
backend.clone(),

madara/node/src/cli/l2.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ pub struct L2SyncParams {
8282
/// Enable bouncer config syncing.
8383
#[arg(env = "MADARA_ENABLE_BOUNCER_CONFIG_SYNCING", long, default_value_t = false)]
8484
pub bouncer_config_sync_enable: bool,
85+
86+
/// Disable blockchain reorganization. When enabled, if a divergent state is discovered,
87+
/// the node will stop with an error instead of performing a reorg. This is useful for
88+
/// operators who want to manually handle chain divergences.
89+
#[clap(env = "MADARA_DISABLE_REORG", long, default_value_t = false)]
90+
pub disable_reorg: bool,
8591
}
8692

8793
impl L2SyncParams {

madara/node/src/service/l2.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ impl Service for SyncService {
124124
.disable_tries(this.params.disable_tries)
125125
.snap_sync(this.params.snap_sync)
126126
.keep_pre_v0_13_2_hashes(this.params.keep_pre_v0_13_2_hashes())
127-
.enable_bouncer_config_sync(this.params.bouncer_config_sync_enable),
127+
.enable_bouncer_config_sync(this.params.bouncer_config_sync_enable)
128+
.disable_reorg(this.params.disable_reorg),
128129
)
129130
.run(ctx.clone())
130131
.await?;
@@ -160,7 +161,8 @@ impl Service for SyncService {
160161
.disable_tries(this.params.disable_tries)
161162
.snap_sync(this.params.snap_sync)
162163
.keep_pre_v0_13_2_hashes(this.params.keep_pre_v0_13_2_hashes())
163-
.enable_bouncer_config_sync(this.params.bouncer_config_sync_enable),
164+
.enable_bouncer_config_sync(this.params.bouncer_config_sync_enable)
165+
.disable_reorg(this.params.disable_reorg),
164166
)
165167
.run(ctx)
166168
.await

0 commit comments

Comments
 (0)