Skip to content
Closed
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
2 changes: 2 additions & 0 deletions rust/Cargo.lock

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

3 changes: 3 additions & 0 deletions rust/op-reth/crates/trie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ reth-db = { workspace = true, features = ["test-utils"] }
reth-db-api = { workspace = true, features = ["test-utils"] }
reth-trie = { workspace = true, features = ["test-utils"] }
reth-provider = { workspace = true, features = ["test-utils"] }
reth-chain-state.workspace = true
reth-node-api.workspace = true
alloy-consensus.workspace = true
alloy-genesis.workspace = true
Expand All @@ -76,8 +77,10 @@ reth-db-common.workspace = true
reth-ethereum-primitives.workspace = true
reth-evm-ethereum.workspace = true
reth-storage-errors.workspace = true
reth-storage-overlay.workspace = true
secp256k1 = { workspace = true, features = ["rand", "std"] }
mockall.workspace = true
rstest.workspace = true
eyre.workspace = true

# misc
Expand Down
50 changes: 39 additions & 11 deletions rust/op-reth/crates/trie/tests/live.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! End-to-end test of the live trie collector.

use alloy_consensus::{BlockHeader, Header, TxEip2930, constants::ETH_TO_WEI};
use alloy_eips::BlockNumHash;
use alloy_genesis::{Genesis, GenesisAccount};
use alloy_primitives::{Address, B256, Bytes, TxKind, U256, keccak256};
use derive_more::Constructor;
Expand Down Expand Up @@ -31,6 +32,9 @@ use std::sync::Arc;
use tempfile::TempDir;
use test_case::test_case;

#[path = "live/parent_states.rs"]
mod parent_states;

fn create_mdbx_proofs_storage() -> Arc<MdbxProofsStorage> {
let path = TempDir::new().unwrap().keep();
Arc::new(MdbxProofsStorage::new(&path).unwrap())
Expand Down Expand Up @@ -77,6 +81,16 @@ impl TxSpec {
nonce: None,
}
}

/// Create a contract deployment running `initcode`.
const fn create(initcode: Bytes, gas_limit: u64) -> Self {
Self { to: TxKind::Create, data: initcode, gas_limit, value: U256::ZERO, nonce: None }
}

/// Create a call to `contract` with `data` as input.
const fn call(contract: Address, data: Bytes, gas_limit: u64) -> Self {
Self { to: TxKind::Call(contract), data, gas_limit, value: U256::ZERO, nonce: None }
}
}

/// Specification for a block in the test chain
Expand Down Expand Up @@ -233,6 +247,26 @@ where
Ok(())
}

/// Seeds `storage` with reth's state and trie at `block`, the proofs store's starting point.
fn initialize_storage<N, S>(
storage: S,
provider_factory: &ProviderFactory<N>,
block: BlockNumHash,
) -> eyre::Result<()>
where
N: NodeTypesWithDB,
S: OpProofsStore + Send + Sync + Clone + std::fmt::Debug + 'static,
{
let trie_layout = if provider_factory.cached_storage_settings().is_v2() {
RethTrieStorageLayout::Packed
} else {
RethTrieStorageLayout::Legacy
};
let tx = provider_factory.db_ref().tx()?;
InitializationJob::new(storage, tx, trie_layout).run(block.number, block.hash)?;
Ok(())
}

/// Runs a test scenario with the given configuration
fn run_test_scenario<N, S>(
scenario: TestScenario,
Expand Down Expand Up @@ -272,17 +306,11 @@ where
last_block_number = block_number;
}

{
let trie_layout = if provider_factory.cached_storage_settings().is_v2() {
RethTrieStorageLayout::Packed
} else {
RethTrieStorageLayout::Legacy
};
let provider = provider_factory.db_ref();
let tx = provider.tx()?;
let initialization_job = InitializationJob::new(storage.clone(), tx, trie_layout);
initialization_job.run(last_block_number, last_block_hash)?;
}
initialize_storage(
storage.clone(),
&provider_factory,
BlockNumHash::new(last_block_number, last_block_hash),
)?;

// Execute blocks after initialization using live collector.
// A single collector is shared across all blocks so the in-memory buffer accumulates
Expand Down
Loading
Loading