Skip to content
23 changes: 22 additions & 1 deletion madara/crates/client/sync/src/gateway/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ pub fn block_with_state_update_pipeline(
batch_size: usize,
keep_pre_v0_13_2_hashes: bool,
sync_bouncer_config: bool,
no_reorg: bool,
) -> GatewayBlockSync {
PipelineController::new(
GatewaySyncSteps { _backend: backend, importer, client, keep_pre_v0_13_2_hashes, sync_bouncer_config },
GatewaySyncSteps { _backend: backend, importer, client, keep_pre_v0_13_2_hashes, sync_bouncer_config, no_reorg },
parallelization,
batch_size,
starting_block_n,
Expand All @@ -43,6 +44,7 @@ pub struct GatewaySyncSteps {
client: Arc<GatewayProvider>,
keep_pre_v0_13_2_hashes: bool,
sync_bouncer_config: bool,
no_reorg: bool,
}

impl GatewaySyncSteps {
Expand Down Expand Up @@ -290,6 +292,25 @@ impl PipelineSteps for GatewaySyncSteps {
block_n, incoming_parent_hash, local_parent_hash
);

// Check if reorg is disabled
if self.no_reorg {
tracing::error!("❌ REORG DETECTED but --no-reorg flag is enabled!");
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick : Let's re-write -> --no-reorg flag
to Reorganisation is explicitly denied by config or something that suite you better maybe

Copy link
Contributor

Choose a reason for hiding this comment

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

disagree! previous message was more specific, --no-reorg flag disabled reorging

tracing::error!(" Block number: {}", block_n);
tracing::error!(" Expected parent hash: {:#x}", local_parent_hash);
tracing::error!(" Incoming parent hash: {:#x}", incoming_parent_hash);
tracing::error!("");
tracing::error!("⚠️ Divergent state detected - the local chain has diverged from the upstream chain.");
tracing::error!("⚠️ Blockchain reorganization is required but disabled by --no-reorg flag.");
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor

Choose a reason for hiding this comment

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

  • for line 309 as well

Copy link
Contributor

Choose a reason for hiding this comment

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

same as above!

tracing::error!("");
tracing::error!("To resolve this issue, you can:");
tracing::error!(" 1. Remove the --no-reorg flag to allow automatic reorganization");
tracing::error!(" 2. Manually investigate the divergence and wipe the database if needed");
anyhow::bail!(
"Reorg required but disabled by --no-reorg flag. Parent hash mismatch at block {}: expected {:#x}, got {:#x}",
block_n, local_parent_hash, incoming_parent_hash
);
}

// Try to find common ancestor
match self.find_common_ancestor(block_n - 1).await {
Ok(common_ancestor_hash) => {
Expand Down
6 changes: 6 additions & 0 deletions madara/crates/client/sync/src/gateway/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct ForwardSyncConfig {
pub disable_tries: bool,
pub keep_pre_v0_13_2_hashes: bool,
pub enable_bouncer_config_sync: bool,
pub no_reorg: bool,
}

impl Default for ForwardSyncConfig {
Expand All @@ -40,6 +41,7 @@ impl Default for ForwardSyncConfig {
disable_tries: false,
keep_pre_v0_13_2_hashes: false,
enable_bouncer_config_sync: false,
no_reorg: false,
}
}
}
Expand All @@ -54,6 +56,9 @@ impl ForwardSyncConfig {
pub fn enable_bouncer_config_sync(self, val: bool) -> Self {
Self { enable_bouncer_config_sync: val, ..self }
}
pub fn no_reorg(self, val: bool) -> Self {
Self { no_reorg: val, ..self }
}
}

pub type GatewaySync = SyncController<GatewayForwardSync>;
Expand Down Expand Up @@ -104,6 +109,7 @@ impl GatewayForwardSync {
config.block_batch_size,
config.keep_pre_v0_13_2_hashes,
config.enable_bouncer_config_sync,
config.no_reorg,
);
let classes_pipeline = classes::classes_pipeline(
backend.clone(),
Expand Down
6 changes: 6 additions & 0 deletions madara/node/src/cli/l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ pub struct L2SyncParams {
/// Enable bouncer config syncing.
#[arg(env = "MADARA_ENABLE_BOUNCER_CONFIG_SYNCING", long, default_value_t = false)]
pub bouncer_config_sync_enable: bool,

/// Disable blockchain reorganization. When enabled, if a divergent state is discovered,
/// the node will stop with an error instead of performing a reorg. This is useful for
/// operators who want to manually handle chain divergences.
#[clap(env = "MADARA_NO_REORG", long, default_value_t = true)]
pub no_reorg: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub no_reorg: bool,
pub disable_reorg: bool,

}

impl L2SyncParams {
Expand Down
6 changes: 4 additions & 2 deletions madara/node/src/service/l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ impl Service for SyncService {
mc_sync::gateway::ForwardSyncConfig::default()
.disable_tries(this.params.disable_tries)
.keep_pre_v0_13_2_hashes(this.params.keep_pre_v0_13_2_hashes())
.enable_bouncer_config_sync(this.params.bouncer_config_sync_enable),
.enable_bouncer_config_sync(this.params.bouncer_config_sync_enable)
.no_reorg(this.params.no_reorg),
)
.run(ctx.clone())
.await?;
Expand Down Expand Up @@ -157,7 +158,8 @@ impl Service for SyncService {
mc_sync::gateway::ForwardSyncConfig::default()
.disable_tries(this.params.disable_tries)
.keep_pre_v0_13_2_hashes(this.params.keep_pre_v0_13_2_hashes())
.enable_bouncer_config_sync(this.params.bouncer_config_sync_enable),
.enable_bouncer_config_sync(this.params.bouncer_config_sync_enable)
.no_reorg(this.params.no_reorg),
)
.run(ctx)
.await
Expand Down
Loading