From b7a976c3fb406279f7f438503faeaa588186871c Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Sat, 21 Sep 2024 22:09:43 +0100 Subject: [PATCH 1/9] dont skip consistency check --- .../provider/src/providers/static_file/manager.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/crates/storage/provider/src/providers/static_file/manager.rs b/crates/storage/provider/src/providers/static_file/manager.rs index 36cb3629b11f..f536da282155 100644 --- a/crates/storage/provider/src/providers/static_file/manager.rs +++ b/crates/storage/provider/src/providers/static_file/manager.rs @@ -632,16 +632,6 @@ impl StaticFileProvider { where Provider: DBProvider + BlockReader + StageCheckpointReader + ChainSpecProvider, { - // OVM chain contains duplicate transactions, so is inconsistent by default since reth db - // not designed for duplicate transactions (see ). Undefined behaviour for queries - // to OVM chain is also in op-erigon. - if provider.chain_spec().chain() == Chain::optimism_mainnet() { - info!(target: "reth::cli", - "Skipping storage verification for OP mainnet, expected inconsistency in OVM chain" - ); - return Ok(None); - } - info!(target: "reth::cli", "Verifying storage consistency."); let mut unwind_target: Option = None; From 82eb9d81e13ae17ec5df0be481c1eeec4f2603a5 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Sat, 21 Sep 2024 22:13:53 +0100 Subject: [PATCH 2/9] rm unused imports --- crates/storage/provider/src/providers/static_file/manager.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/storage/provider/src/providers/static_file/manager.rs b/crates/storage/provider/src/providers/static_file/manager.rs index f536da282155..9681a5ab5f25 100644 --- a/crates/storage/provider/src/providers/static_file/manager.rs +++ b/crates/storage/provider/src/providers/static_file/manager.rs @@ -12,7 +12,7 @@ use alloy_primitives::{keccak256, Address, BlockHash, BlockNumber, TxHash, TxNum use dashmap::DashMap; use notify::{RecommendedWatcher, RecursiveMode, Watcher}; use parking_lot::RwLock; -use reth_chainspec::{Chain, ChainInfo, ChainSpecProvider, EthChainSpec}; +use reth_chainspec::{ChainInfo, ChainSpecProvider}; use reth_db::{ lockfile::StorageLock, static_file::{iter_static_files, HeaderMask, ReceiptMask, StaticFileCursor, TransactionMask}, From 651962332045fb8d2910efb0bfc48bd5d0834eee Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Sun, 22 Sep 2024 14:22:22 +0100 Subject: [PATCH 3/9] skip consistency check if ovm historical exists --- .../src/providers/static_file/manager.rs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/storage/provider/src/providers/static_file/manager.rs b/crates/storage/provider/src/providers/static_file/manager.rs index 9681a5ab5f25..99e23a956aa5 100644 --- a/crates/storage/provider/src/providers/static_file/manager.rs +++ b/crates/storage/provider/src/providers/static_file/manager.rs @@ -12,7 +12,7 @@ use alloy_primitives::{keccak256, Address, BlockHash, BlockNumber, TxHash, TxNum use dashmap::DashMap; use notify::{RecommendedWatcher, RecursiveMode, Watcher}; use parking_lot::RwLock; -use reth_chainspec::{ChainInfo, ChainSpecProvider}; +use reth_chainspec::{Chain, ChainInfo, ChainSpecProvider, EthChainSpec}; use reth_db::{ lockfile::StorageLock, static_file::{iter_static_files, HeaderMask, ReceiptMask, StaticFileCursor, TransactionMask}, @@ -26,6 +26,7 @@ use reth_db_api::{ }; use reth_nippy_jar::{NippyJar, NippyJarChecker, CONFIG_FILE_EXTENSION}; use reth_primitives::{ + b256, static_file::{ find_fixed_range, HighestStaticFiles, SegmentHeader, SegmentRangeInclusive, DEFAULT_BLOCKS_PER_STATIC_FILE, @@ -632,6 +633,24 @@ impl StaticFileProvider { where Provider: DBProvider + BlockReader + StageCheckpointReader + ChainSpecProvider, { + // OVM historical import is broken and does not work with this check. It's importing + // duplicated receipts resulting in having more receipts than the expected transaction + // range. + // + // If we detect an OVM import was done (block #1 ), skip it. + if provider.chain_spec().chain() == Chain::optimism_mainnet() && + provider + .block_number(b256!( + "bee7192e575af30420cae0c7776304ac196077ee72b048970549e4f08e875453" + ))? + .is_some() + { + info!(target: "reth::cli", + "Skipping storage verification for OP mainnet, expected inconsistency in OVM chain" + ); + return Ok(None) + } + info!(target: "reth::cli", "Verifying storage consistency."); let mut unwind_target: Option = None; From 03f9303229bcac91c6a656ba8600a3511c3372c8 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Sun, 22 Sep 2024 14:38:17 +0100 Subject: [PATCH 4/9] add recommendations to book --- book/run/sync-op-mainnet.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/book/run/sync-op-mainnet.md b/book/run/sync-op-mainnet.md index 75b6bb1611f6..89ed4c95ca9f 100644 --- a/book/run/sync-op-mainnet.md +++ b/book/run/sync-op-mainnet.md @@ -2,10 +2,10 @@ To sync OP mainnet, bedrock state needs to be imported as a starting point. There are currently two ways: -* Minimal bootstrap: only state snapshot at Bedrock block is imported without any OVM historical data. -* Full bootstrap: state, blocks and receipts are imported. +* Minimal bootstrap **(recommended)**: only state snapshot at Bedrock block is imported without any OVM historical data. +* Full bootstrap **(not recommended)**: state, blocks and receipts are imported. *Not recommended for now: [storage consistency issue](https://github.com/paradigmxyz/reth/pull/11099) tldr: sudden crash may break the node -## Minimal bootstrap +## Minimal bootstrap (recommended) **The state snapshot at Bedrock block is required.** It can be exported from [op-geth](https://github.com/testinprod-io/op-erigon/blob/pcw109550/bedrock-db-migration/bedrock-migration.md#export-state) (**.jsonl**) or downloaded directly from [here](https://mega.nz/file/GdZ1xbAT#a9cBv3AqzsTGXYgX7nZc_3fl--tcBmOAIwIA5ND6kwc). @@ -16,7 +16,7 @@ $ op-reth node --chain optimism --datadir op-mainnet --debug.tip 0x098f87b75c8b8 ``` -## Full bootstrap +## Full bootstrap (not recommended) ### Import state From 330d2de3e770450cdd2ab9470d4d0dc15103b5b2 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Sun, 22 Sep 2024 14:42:51 +0100 Subject: [PATCH 5/9] more docs --- book/run/sync-op-mainnet.md | 2 ++ crates/storage/provider/src/providers/static_file/manager.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/book/run/sync-op-mainnet.md b/book/run/sync-op-mainnet.md index 89ed4c95ca9f..ebdacdf6167f 100644 --- a/book/run/sync-op-mainnet.md +++ b/book/run/sync-op-mainnet.md @@ -18,6 +18,8 @@ $ op-reth node --chain optimism --datadir op-mainnet --debug.tip 0x098f87b75c8b8 ## Full bootstrap (not recommended) +**Not recommended for now**: [storage consistency issue](https://github.com/paradigmxyz/reth/pull/11099) tldr: sudden crash may break the node. + ### Import state To sync OP mainnet, the Bedrock datadir needs to be imported to use as starting point. diff --git a/crates/storage/provider/src/providers/static_file/manager.rs b/crates/storage/provider/src/providers/static_file/manager.rs index 99e23a956aa5..6a8be19f9070 100644 --- a/crates/storage/provider/src/providers/static_file/manager.rs +++ b/crates/storage/provider/src/providers/static_file/manager.rs @@ -638,6 +638,7 @@ impl StaticFileProvider { // range. // // If we detect an OVM import was done (block #1 ), skip it. + // More on [#11099](https://github.com/paradigmxyz/reth/pull/11099). if provider.chain_spec().chain() == Chain::optimism_mainnet() && provider .block_number(b256!( From a3f7fea076e5a7bb564754be6f7661a993be739b Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Sun, 22 Sep 2024 14:50:29 +0100 Subject: [PATCH 6/9] add OVM_HEADER_1_HASH --- crates/optimism/primitives/src/bedrock.rs | 5 +++++ crates/storage/provider/Cargo.toml | 5 ++++- crates/storage/provider/src/providers/static_file/manager.rs | 5 ++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/optimism/primitives/src/bedrock.rs b/crates/optimism/primitives/src/bedrock.rs index f63fc191798b..599fa89e22b4 100644 --- a/crates/optimism/primitives/src/bedrock.rs +++ b/crates/optimism/primitives/src/bedrock.rs @@ -55,6 +55,11 @@ pub fn is_dup_tx(block_number: u64) -> bool { false } +/// OVM Header #1 hash. +pub const OVM_HEADER_1_HASH: B256 = b256!( + "bee7192e575af30420cae0c7776304ac196077ee72b048970549e4f08e875453" +); + /// Bedrock hash on Optimism Mainnet. pub const BEDROCK_HEADER_HASH: B256 = b256!("dbf6a80fef073de06add9b0d14026d6e5a86c85f6d102c36d3d8e9cf89c2afd3"); diff --git a/crates/storage/provider/Cargo.toml b/crates/storage/provider/Cargo.toml index ea04ac8c6341..7524fde6a2d7 100644 --- a/crates/storage/provider/Cargo.toml +++ b/crates/storage/provider/Cargo.toml @@ -40,6 +40,9 @@ alloy-primitives.workspace = true alloy-rpc-types-engine.workspace = true revm.workspace = true +# optimism +reth-optimism-primitives = { workspace = true, optional = true } + # async tokio = { workspace = true, features = ["sync", "macros", "rt-multi-thread"] } @@ -79,7 +82,7 @@ once_cell.workspace = true eyre.workspace = true [features] -optimism = ["reth-primitives/optimism", "reth-execution-types/optimism"] +optimism = ["reth-primitives/optimism", "reth-execution-types/optimism", "reth-optimism-primitives"] serde = ["reth-execution-types/serde"] test-utils = [ "reth-db/test-utils", diff --git a/crates/storage/provider/src/providers/static_file/manager.rs b/crates/storage/provider/src/providers/static_file/manager.rs index 6a8be19f9070..e82c25de0058 100644 --- a/crates/storage/provider/src/providers/static_file/manager.rs +++ b/crates/storage/provider/src/providers/static_file/manager.rs @@ -639,11 +639,10 @@ impl StaticFileProvider { // // If we detect an OVM import was done (block #1 ), skip it. // More on [#11099](https://github.com/paradigmxyz/reth/pull/11099). + #[cfg(feature = "optimism")] if provider.chain_spec().chain() == Chain::optimism_mainnet() && provider - .block_number(b256!( - "bee7192e575af30420cae0c7776304ac196077ee72b048970549e4f08e875453" - ))? + .block_number(reth_optimism_primitives::bedrock::OVM_HEADER_1_HASH)? .is_some() { info!(target: "reth::cli", From 0549cf7c726b01e9dd8fa9e8e4e63b82e196f8ff Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Sun, 22 Sep 2024 14:51:28 +0100 Subject: [PATCH 7/9] fmt --- Cargo.lock | 1 + crates/optimism/primitives/src/bedrock.rs | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d8cb12886506..1b70de22ce4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8291,6 +8291,7 @@ dependencies = [ "reth-network-p2p", "reth-nippy-jar", "reth-node-types", + "reth-optimism-primitives", "reth-primitives", "reth-prune-types", "reth-stages-types", diff --git a/crates/optimism/primitives/src/bedrock.rs b/crates/optimism/primitives/src/bedrock.rs index 599fa89e22b4..7da68c4c193f 100644 --- a/crates/optimism/primitives/src/bedrock.rs +++ b/crates/optimism/primitives/src/bedrock.rs @@ -56,9 +56,8 @@ pub fn is_dup_tx(block_number: u64) -> bool { } /// OVM Header #1 hash. -pub const OVM_HEADER_1_HASH: B256 = b256!( - "bee7192e575af30420cae0c7776304ac196077ee72b048970549e4f08e875453" -); +pub const OVM_HEADER_1_HASH: B256 = + b256!("bee7192e575af30420cae0c7776304ac196077ee72b048970549e4f08e875453"); /// Bedrock hash on Optimism Mainnet. pub const BEDROCK_HEADER_HASH: B256 = From 7a5999b5aa1eeabc36563efd8053f58ca6bd1703 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Sun, 22 Sep 2024 14:53:21 +0100 Subject: [PATCH 8/9] rm unused import --- crates/storage/provider/src/providers/static_file/manager.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/storage/provider/src/providers/static_file/manager.rs b/crates/storage/provider/src/providers/static_file/manager.rs index e82c25de0058..8ebf50945307 100644 --- a/crates/storage/provider/src/providers/static_file/manager.rs +++ b/crates/storage/provider/src/providers/static_file/manager.rs @@ -26,7 +26,6 @@ use reth_db_api::{ }; use reth_nippy_jar::{NippyJar, NippyJarChecker, CONFIG_FILE_EXTENSION}; use reth_primitives::{ - b256, static_file::{ find_fixed_range, HighestStaticFiles, SegmentHeader, SegmentRangeInclusive, DEFAULT_BLOCKS_PER_STATIC_FILE, From 18b5c20c3a2a62840c4f7ba537d6527863ecf05e Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Sun, 22 Sep 2024 16:19:43 +0100 Subject: [PATCH 9/9] clippy --- crates/storage/provider/src/providers/static_file/manager.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/storage/provider/src/providers/static_file/manager.rs b/crates/storage/provider/src/providers/static_file/manager.rs index 8ebf50945307..1cfce1ef7481 100644 --- a/crates/storage/provider/src/providers/static_file/manager.rs +++ b/crates/storage/provider/src/providers/static_file/manager.rs @@ -12,7 +12,7 @@ use alloy_primitives::{keccak256, Address, BlockHash, BlockNumber, TxHash, TxNum use dashmap::DashMap; use notify::{RecommendedWatcher, RecursiveMode, Watcher}; use parking_lot::RwLock; -use reth_chainspec::{Chain, ChainInfo, ChainSpecProvider, EthChainSpec}; +use reth_chainspec::{ChainInfo, ChainSpecProvider}; use reth_db::{ lockfile::StorageLock, static_file::{iter_static_files, HeaderMask, ReceiptMask, StaticFileCursor, TransactionMask}, @@ -639,7 +639,8 @@ impl StaticFileProvider { // If we detect an OVM import was done (block #1 ), skip it. // More on [#11099](https://github.com/paradigmxyz/reth/pull/11099). #[cfg(feature = "optimism")] - if provider.chain_spec().chain() == Chain::optimism_mainnet() && + if reth_chainspec::EthChainSpec::chain(&provider.chain_spec()) == + reth_chainspec::Chain::optimism_mainnet() && provider .block_number(reth_optimism_primitives::bedrock::OVM_HEADER_1_HASH)? .is_some()