diff --git a/CHANGELOG.sf.md b/CHANGELOG.sf.md index 29fd701c25a..acb7ebe35c8 100644 --- a/CHANGELOG.sf.md +++ b/CHANGELOG.sf.md @@ -9,6 +9,16 @@ The `sf-release.yml` workflow publishes the top-most version section here as the GitHub release notes (via `sfreleaser changelog extract-section`), so keep the most recent release at the top. +## Unreleased + +### Fixed + +* With `--proofs-history`, the proofs ExEx no longer prints a second `FIRE BLOCK` for each block + it re-executes to build its proof storage. Blocks it caught up on at startup or after falling + behind, blocks without precomputed trie data and blocks picked by + `--proofs-history.verification-interval` appeared twice in the Firehose output, often out of + order. + ## op-reth-v2.8.2-fh3.1 Bumps the SF op-reth fork to upstream `op-reth/v2.8.2` (18 upstream commits on top of diff --git a/rust/Cargo.lock b/rust/Cargo.lock index c055c209215..2035dccc953 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -14408,6 +14408,7 @@ dependencies = [ "reth-evm", "reth-evm-ethereum", "reth-execution-errors", + "reth-firehose", "reth-metrics", "reth-node-api", "reth-optimism-trie", diff --git a/rust/op-reth/crates/trie/Cargo.toml b/rust/op-reth/crates/trie/Cargo.toml index 2e896e40b74..9830cedf3e4 100644 --- a/rust/op-reth/crates/trie/Cargo.toml +++ b/rust/op-reth/crates/trie/Cargo.toml @@ -75,6 +75,7 @@ reth-chainspec.workspace = true reth-db-common.workspace = true reth-ethereum-primitives.workspace = true reth-evm-ethereum.workspace = true +reth-firehose.workspace = true reth-storage-errors.workspace = true secp256k1 = { workspace = true, features = ["rand", "std"] } mockall.workspace = true diff --git a/rust/op-reth/crates/trie/src/engine/tasks/execute_block.rs b/rust/op-reth/crates/trie/src/engine/tasks/execute_block.rs index c67f7bf3856..7e49e72ff29 100644 --- a/rust/op-reth/crates/trie/src/engine/tasks/execute_block.rs +++ b/rust/op-reth/crates/trie/src/engine/tasks/execute_block.rs @@ -115,11 +115,14 @@ where let state_provider = state.memory.state_provider(block.parent_hash(), inner_provider); let db = StateProviderDatabase::new(&state_provider); - let block_executor = state.evm_config.batch_executor(db); - let execution_result = block_executor.execute(block)?; + // Must stay `execute_one`, not `execute`: the node's Firehose executor traces `execute` and + // would print a second `FIRE BLOCK` for a block reth's import already traced. + let mut block_executor = state.evm_config.batch_executor(db); + block_executor.execute_one(block)?; + let bundle_state = block_executor.into_state().take_bundle(); let execution_duration = start.elapsed(); - let hashed_state = state_provider.hashed_post_state(&execution_result.state)?; + let hashed_state = state_provider.hashed_post_state(&bundle_state)?; let (state_root, trie_updates) = state_provider.state_root_with_updates(hashed_state.clone())?; let state_root_duration = start.elapsed() - execution_duration; diff --git a/rust/op-reth/crates/trie/tests/live.rs b/rust/op-reth/crates/trie/tests/live.rs index 26acd703190..877ea2c6183 100644 --- a/rust/op-reth/crates/trie/tests/live.rs +++ b/rust/op-reth/crates/trie/tests/live.rs @@ -715,3 +715,55 @@ fn execute_deployed_contract_without_reth_parent_state() -> eyre::Result<()> { assert_eq!(storage.provider_ro()?.get_latest_block()?.number, 2); Ok(()) } + +/// The proofs engine re-executes blocks reth has already imported and traced, so it must not print +/// them to the Firehose output a second time. +#[test] +#[serial] +fn execute_block_emits_no_firehose_block() -> eyre::Result<()> { + let key_pair = Keypair::new(&Secp256k1::new(), &mut rng()); + let sender = public_key_to_address(key_pair.public_key()); + let chain_spec = chain_spec_with_address(sender); + // The only test in this binary that installs the process-wide Firehose tracer. + let firehose_output = + reth_firehose::init_tracer_with_buffer(chain_spec.chain.id(), None, None, None); + + let factory = create_test_provider_factory_with_chain_spec(chain_spec.clone()); + init_genesis(&factory)?; + let storage: OpProofsStorage> = create_mdbx_proofs_storage().into(); + { + let tx = factory.db_ref().tx()?; + InitializationJob::new(storage.clone(), tx, RethTrieStorageLayout::Legacy) + .run(0, chain_spec.genesis_hash())?; + } + let blockchain = BlockchainProvider::new(factory.clone())?; + let pruner = OpProofStoragePruner::new(storage.clone(), blockchain.clone(), 1000); + let engine = EngineHandle::spawn( + reth_firehose::FirehoseEvmConfig::new(EthEvmConfig::ethereum(chain_spec.clone())), + blockchain, + storage, + pruner, + ); + + let transfer = + BlockSpec::new(vec![TxSpec::transfer(Address::repeat_byte(0x42), U256::from(1))]); + let mut nonce = 0; + let mut block = create_block_from_spec( + &transfer, + 1, + chain_spec.genesis_hash(), + &chain_spec, + key_pair, + &mut nonce, + ); + execute_block(&mut block, &factory, &chain_spec)?; + // Returns once the engine has executed the block and matched its state root. + engine.execute_block(&block)?; + + let output = String::from_utf8(firehose_output.get_bytes())?; + assert!( + !output.contains("FIRE BLOCK"), + "the proofs engine printed a Firehose block:\n{output}" + ); + Ok(()) +}