Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storage): dont skip consistency checks for op-mainnet if using minimal bootstrap #11099

Merged
merged 9 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions book/run/sync-op-mainnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -16,7 +16,9 @@ $ op-reth node --chain optimism --datadir op-mainnet --debug.tip 0x098f87b75c8b8
```


## Full bootstrap
## 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

Expand Down
4 changes: 4 additions & 0 deletions crates/optimism/primitives/src/bedrock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ 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");
Expand Down
5 changes: 4 additions & 1 deletion crates/storage/provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down Expand Up @@ -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",
Expand Down
21 changes: 15 additions & 6 deletions crates/storage/provider/src/providers/static_file/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -632,14 +632,23 @@ 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 <https://github.com/paradigmxyz/reth/blob/v1.0.3/crates/optimism/primitives/src/bedrock_import.rs>). Undefined behaviour for queries
// to OVM chain is also in op-erigon.
if provider.chain_spec().chain() == Chain::optimism_mainnet() {
// 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 <https://optimistic.etherscan.io/block/1>), skip it.
// More on [#11099](https://github.com/paradigmxyz/reth/pull/11099).
#[cfg(feature = "optimism")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can keep this cfg, but not strictly required because not expensive to check and only reachable by op mainnet

if reth_chainspec::EthChainSpec::chain(&provider.chain_spec()) ==
reth_chainspec::Chain::optimism_mainnet() &&
emhane marked this conversation as resolved.
Show resolved Hide resolved
provider
.block_number(reth_optimism_primitives::bedrock::OVM_HEADER_1_HASH)?
.is_some()
{
info!(target: "reth::cli",
"Skipping storage verification for OP mainnet, expected inconsistency in OVM chain"
);
return Ok(None);
return Ok(None)
}

info!(target: "reth::cli", "Verifying storage consistency.");
Expand Down
Loading