From 66e9ba092690cb1e5a7615cf5959b363193bc0ea Mon Sep 17 00:00:00 2001 From: clabby Date: Sat, 21 Oct 2023 13:20:50 -0400 Subject: [PATCH] Set forkchoice state on startup Add param for enabling genesis walkback --- bin/reth/src/args/rollup_args.rs | 5 +++++ bin/reth/src/node/mod.rs | 20 ++++++++++++++++++++ crates/net/network/tests/it/main.rs | 1 + 3 files changed, 26 insertions(+) diff --git a/bin/reth/src/args/rollup_args.rs b/bin/reth/src/args/rollup_args.rs index 887d04a10464..abd38f6db7a3 100644 --- a/bin/reth/src/args/rollup_args.rs +++ b/bin/reth/src/args/rollup_args.rs @@ -11,4 +11,9 @@ pub struct RollupArgs { /// Disable transaction pool gossip #[arg(long = "rollup.disable-tx-pool-gossip")] pub disable_txpool_gossip: bool, + + /// Enable walkback to genesis on startup. This is useful for re-validating the existing DB + /// prior to beginning normal syncing. + #[arg(long = "rollup.enable-genesis-walkback")] + pub enable_genesis_walkback: bool, } diff --git a/bin/reth/src/node/mod.rs b/bin/reth/src/node/mod.rs index 870dd0b38b23..2e3d3b22d4e1 100644 --- a/bin/reth/src/node/mod.rs +++ b/bin/reth/src/node/mod.rs @@ -87,6 +87,11 @@ use std::{ use tokio::sync::{mpsc::unbounded_channel, oneshot, watch}; use tracing::*; +#[cfg(feature = "optimism")] +use reth_rpc_api::EngineApiClient; +#[cfg(feature = "optimism")] +use reth_rpc_types::engine::ForkchoiceState; + pub mod cl_events; pub mod events; @@ -551,6 +556,21 @@ impl NodeCommand { self.ext.on_node_started(&components)?; + #[cfg(feature = "optimism")] + if self.chain.optimism && !self.rollup.enable_genesis_walkback { + let client = _rpc_server_handles.auth.http_client(); + EngineApiClient::fork_choice_updated_v2( + &client, + ForkchoiceState { + head_block_hash: head.hash, + safe_block_hash: head.hash, + finalized_block_hash: head.hash, + }, + None, + ) + .await?; + } + rx.await??; info!(target: "reth::cli", "Consensus engine has exited."); diff --git a/crates/net/network/tests/it/main.rs b/crates/net/network/tests/it/main.rs index 94277d08bb08..1d65a90cc8a0 100644 --- a/crates/net/network/tests/it/main.rs +++ b/crates/net/network/tests/it/main.rs @@ -5,6 +5,7 @@ mod geth; mod requests; mod session; mod startup; +#[cfg(not(feature = "optimism"))] mod txgossip; fn main() {}