diff --git a/Cargo.lock b/Cargo.lock index a0e4565870..d47b980e7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9734,11 +9734,11 @@ dependencies = [ [[package]] name = "reth-trie-prefetch" -version = "1.0.2" +version = "1.0.3" dependencies = [ "alloy-rlp", "criterion", - "derive_more", + "derive_more 1.0.0", "metrics", "proptest", "rand 0.8.5", @@ -9750,6 +9750,7 @@ dependencies = [ "reth-provider", "reth-tasks", "reth-trie", + "reth-trie-db", "reth-trie-parallel", "thiserror", "tokio", diff --git a/Dockerfile b/Dockerfile index 26a1ad8900..89c26d9d27 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM lukemathwalker/cargo-chef:latest-rust-1.80 AS chef WORKDIR /app -LABEL org.opencontainers.image.source=https://github.com/paradigmxyz/reth +LABEL org.opencontainers.image.source=https://github.com/bnb-chain/reth LABEL org.opencontainers.image.licenses="MIT OR Apache-2.0" # Install system dependencies diff --git a/Dockerfile.cross b/Dockerfile.cross index f477f1ed3e..493bf7e825 100644 --- a/Dockerfile.cross +++ b/Dockerfile.cross @@ -3,7 +3,7 @@ # locatable in `./dist/bin/$TARGETARCH` FROM --platform=$TARGETPLATFORM ubuntu:22.04 -LABEL org.opencontainers.image.source=https://github.com/paradigmxyz/reth +LABEL org.opencontainers.image.source=https://github.com/bnb-chain/reth LABEL org.opencontainers.image.licenses="MIT OR Apache-2.0" # Filled by docker buildx diff --git a/DockerfileBsc.cross b/DockerfileBsc.cross index 6e0bdbee2f..718b209a14 100644 --- a/DockerfileBsc.cross +++ b/DockerfileBsc.cross @@ -3,7 +3,7 @@ # locatable in `./dist/bin/$TARGETARCH` FROM --platform=$TARGETPLATFORM ubuntu:22.04 -LABEL org.opencontainers.image.source=https://github.com/paradigmxyz/reth +LABEL org.opencontainers.image.source=https://github.com/bnb-chain/reth LABEL org.opencontainers.image.licenses="MIT OR Apache-2.0" # Filled by docker buildx diff --git a/DockerfileOp.cross b/DockerfileOp.cross index 47606a8283..df41a9f878 100644 --- a/DockerfileOp.cross +++ b/DockerfileOp.cross @@ -3,7 +3,7 @@ # locatable in `./dist/bin/$TARGETARCH` FROM --platform=$TARGETPLATFORM ubuntu:22.04 -LABEL org.opencontainers.image.source=https://github.com/paradigmxyz/reth +LABEL org.opencontainers.image.source=https://github.com/bnb-chain/reth LABEL org.opencontainers.image.licenses="MIT OR Apache-2.0" # Filled by docker buildx diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index 3e675b0636..b8b4ca3187 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -157,11 +157,11 @@ opbnb = [ bsc = [ "reth-rpc/bsc", "reth-primitives/bsc", - "dep:reth-node-bsc", "reth-node-core/bsc", "reth-stages/bsc", "reth-node-builder/bsc", "reth-beacon-consensus/bsc", + "dep:reth-node-bsc", ] # no-op feature flag for switching between the `optimism` and default functionality in CI matrices diff --git a/bsc.Dockerfile b/bsc.Dockerfile index 3743b985b2..8dd8951a91 100644 --- a/bsc.Dockerfile +++ b/bsc.Dockerfile @@ -1,7 +1,7 @@ FROM lukemathwalker/cargo-chef:latest-rust-1.80 AS chef WORKDIR /app -LABEL org.opencontainers.image.source=https://github.com/paradigmxyz/reth +LABEL org.opencontainers.image.source=https://github.com/bnb-chain/reth LABEL org.opencontainers.image.licenses="MIT OR Apache-2.0" # Builds a cargo-chef plan diff --git a/crates/bsc/evm/src/lib.rs b/crates/bsc/evm/src/lib.rs index bc0ab2dda6..3b96db826c 100644 --- a/crates/bsc/evm/src/lib.rs +++ b/crates/bsc/evm/src/lib.rs @@ -2,7 +2,6 @@ // TODO: doc #![allow(missing_docs)] -#![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] // The `bsc` feature must be enabled to use this crate. #![cfg(feature = "bsc")] diff --git a/crates/chainspec/src/spec.rs b/crates/chainspec/src/spec.rs index 5030c95388..2a429cb705 100644 --- a/crates/chainspec/src/spec.rs +++ b/crates/chainspec/src/spec.rs @@ -2244,6 +2244,7 @@ Post-merge hard forks (timestamp based): } #[test] + #[cfg(not(feature = "bsc"))] fn test_default_cancun_header_forkhash() { // set the gas limit from the hive test genesis according to the hash let genesis = Genesis { gas_limit: 0x2fefd8u128, ..Default::default() }; @@ -2270,20 +2271,12 @@ Post-merge hard forks (timestamp based): // check the genesis hash let genesis_hash = header.hash_slow(); - let expected_hash = if cfg!(feature = "bsc") { - // bsc has zero base fee - b256!("8498b49617a74f5750dfe77e025989bd06955a177d255b8fb90ed3ebbe9aaf0f") - } else { - b256!("16bb7c59613a5bad3f7c04a852fd056545ade2483968d9a25a1abb05af0c4d37") - }; + let expected_hash = + b256!("16bb7c59613a5bad3f7c04a852fd056545ade2483968d9a25a1abb05af0c4d37"); assert_eq!(genesis_hash, expected_hash); // check that the forkhash is correct - let expected_forkhash = if cfg!(feature = "bsc") { - ForkHash(hex!("1e7c5080")) - } else { - ForkHash(hex!("8062457a")) - }; + let expected_forkhash = ForkHash(hex!("8062457a")); assert_eq!(ForkHash::from(genesis_hash), expected_forkhash); } diff --git a/crates/evm/src/execute.rs b/crates/evm/src/execute.rs index 2ba681e2c0..9de543f3b8 100644 --- a/crates/evm/src/execute.rs +++ b/crates/evm/src/execute.rs @@ -7,12 +7,9 @@ pub use reth_storage_errors::provider::ProviderError; use core::fmt::Display; -use std::collections::HashMap; - use reth_primitives::{BlockNumber, BlockWithSenders, Header, Receipt}; use reth_prune_types::PruneModes; -use revm_primitives::db::Database; -use revm_primitives::EvmState; +use revm_primitives::{db::Database, EvmState}; use tokio::sync::mpsc::UnboundedSender; /// A general purpose executor trait that executes an input (e.g. block) and produces an output diff --git a/crates/exex/exex/src/backfill/test_utils.rs b/crates/exex/exex/src/backfill/test_utils.rs index 461a5c76b0..9ee68831ca 100644 --- a/crates/exex/exex/src/backfill/test_utils.rs +++ b/crates/exex/exex/src/backfill/test_utils.rs @@ -59,10 +59,13 @@ where // Execute the block to produce a block execution output let mut block_execution_output = EthExecutorProvider::ethereum(chain_spec) - .executor(StateProviderDatabase::new(LatestStateProviderRef::new( - provider.tx_ref(), - provider.static_file_provider().clone(), - ))) + .executor( + StateProviderDatabase::new(LatestStateProviderRef::new( + provider.tx_ref(), + provider.static_file_provider().clone(), + )), + None, + ) .execute(BlockExecutionInput { block, total_difficulty: U256::ZERO, diff --git a/crates/node/core/src/args/pruning.rs b/crates/node/core/src/args/pruning.rs index 25626a5bef..e8591faca5 100644 --- a/crates/node/core/src/args/pruning.rs +++ b/crates/node/core/src/args/pruning.rs @@ -33,7 +33,7 @@ impl PruningArgs { .deposit_contract .as_ref() .map(|contract| PruneMode::Before(contract.block)) - .or(Some(PruneMode::Full)), + .or(Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE))), account_history: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)), storage_history: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)), receipts_log_filter: ReceiptsLogPruneConfig( diff --git a/crates/node/core/src/args/utils.rs b/crates/node/core/src/args/utils.rs index f1dc961ece..b96e997f09 100644 --- a/crates/node/core/src/args/utils.rs +++ b/crates/node/core/src/args/utils.rs @@ -19,8 +19,15 @@ use reth_optimism_chainspec::{OPBNB_MAINNET, OPBNB_QA, OPBNB_TESTNET}; pub const SUPPORTED_CHAINS: &[&str] = &["bsc", "bsc-testnet"]; #[cfg(feature = "optimism")] /// Chains supported by op-reth. First value should be used as the default. -pub const SUPPORTED_CHAINS: &[&str] = - &["optimism", "optimism-sepolia", "base", "base-sepolia", "opbnb-mainnet", "opbnb-testnet", "dev"]; +pub const SUPPORTED_CHAINS: &[&str] = &[ + "optimism", + "optimism-sepolia", + "base", + "base-sepolia", + "opbnb-mainnet", + "opbnb-testnet", + "dev", +]; #[cfg(all(not(feature = "optimism"), not(feature = "bsc")))] /// Chains supported by reth. First value should be used as the default. pub const SUPPORTED_CHAINS: &[&str] = &["mainnet", "sepolia", "holesky", "dev"]; diff --git a/crates/optimism/evm/src/execute.rs b/crates/optimism/evm/src/execute.rs index 827a5a64f4..0ea21cc84b 100644 --- a/crates/optimism/evm/src/execute.rs +++ b/crates/optimism/evm/src/execute.rs @@ -1,5 +1,7 @@ //! Optimism block executor. +use std::{collections::HashMap, str::FromStr, sync::Arc}; + use crate::{l1::ensure_create2_deployer, OptimismBlockExecutionError, OptimismEvmConfig}; use reth_chainspec::{ChainSpec, EthereumHardforks, OptimismHardfork}; use reth_evm::{ @@ -25,7 +27,6 @@ use revm_primitives::{ db::{Database, DatabaseCommit}, BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg, EvmState, ResultAndState, }; -use std::{collections::HashMap, str::FromStr, sync::Arc}; use tokio::sync::mpsc::UnboundedSender; use tracing::{debug, trace}; diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index 7c1187f2c5..e68a50b9c8 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -2095,13 +2095,20 @@ impl BlockReader for DatabaseProvider { transaction_kind, |block_number| self.header_by_number(block_number), |header, body, senders, ommers, withdrawals, requests| { - Block { header, body, ommers, withdrawals, sidecars: Some(Default::default()), requests } - // Note: we're using unchecked here because we know the block contains valid txs - // wrt to its height and can ignore the s value check so pre - // EIP-2 txs are allowed - .try_with_senders_unchecked(senders) - .map(Some) - .map_err(|_| ProviderError::SenderRecoveryError) + Block { + header, + body, + ommers, + withdrawals, + sidecars: Some(Default::default()), + requests, + } + // Note: we're using unchecked here because we know the block contains valid txs + // wrt to its height and can ignore the s value check so pre + // EIP-2 txs are allowed + .try_with_senders_unchecked(senders) + .map(Some) + .map_err(|_| ProviderError::SenderRecoveryError) }, ) } @@ -2116,13 +2123,20 @@ impl BlockReader for DatabaseProvider { transaction_kind, |block_number| self.sealed_header(block_number), |header, body, senders, ommers, withdrawals, requests| { - SealedBlock { header, body, ommers, withdrawals, sidecars: Some(Default::default()), requests } - // Note: we're using unchecked here because we know the block contains valid txs - // wrt to its height and can ignore the s value check so pre - // EIP-2 txs are allowed - .try_with_senders_unchecked(senders) - .map(Some) - .map_err(|_| ProviderError::SenderRecoveryError) + SealedBlock { + header, + body, + ommers, + withdrawals, + sidecars: Some(Default::default()), + requests, + } + // Note: we're using unchecked here because we know the block contains valid txs + // wrt to its height and can ignore the s value check so pre + // EIP-2 txs are allowed + .try_with_senders_unchecked(senders) + .map(Some) + .map_err(|_| ProviderError::SenderRecoveryError) }, ) } diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index 892d42b9d4..f29d220fe4 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -1235,7 +1235,7 @@ impl AllTransactions { pub(crate) fn descendant_txs_exclusive<'a, 'b: 'a>( &'a self, id: &'b TransactionId, - ) -> impl Iterator)> + '_ { + ) -> impl Iterator)> + 'a { self.txs.range((Excluded(id), Unbounded)).take_while(|(other, _)| id.sender == other.sender) } @@ -1246,7 +1246,7 @@ impl AllTransactions { pub(crate) fn descendant_txs_inclusive<'a, 'b: 'a>( &'a self, id: &'b TransactionId, - ) -> impl Iterator)> + '_ { + ) -> impl Iterator)> + 'a { self.txs.range(id..).take_while(|(other, _)| id.sender == other.sender) } @@ -1257,7 +1257,7 @@ impl AllTransactions { pub(crate) fn descendant_txs_mut<'a, 'b: 'a>( &'a mut self, id: &'b TransactionId, - ) -> impl Iterator)> + '_ { + ) -> impl Iterator)> + 'a { self.txs.range_mut(id..).take_while(|(other, _)| id.sender == other.sender) } diff --git a/crates/trie/prefetch/Cargo.toml b/crates/trie/prefetch/Cargo.toml index 1fbc385c9d..20ed081a60 100644 --- a/crates/trie/prefetch/Cargo.toml +++ b/crates/trie/prefetch/Cargo.toml @@ -16,6 +16,7 @@ workspace = true reth-primitives.workspace = true reth-db.workspace = true reth-trie.workspace = true +reth-trie-db.workspace = true reth-provider.workspace = true reth-trie-parallel.workspace = true reth-tasks.workspace = true diff --git a/crates/trie/prefetch/src/prefetch.rs b/crates/trie/prefetch/src/prefetch.rs index 2d9071b938..1bb70c3cd7 100644 --- a/crates/trie/prefetch/src/prefetch.rs +++ b/crates/trie/prefetch/src/prefetch.rs @@ -12,6 +12,7 @@ use reth_trie::{ walker::TrieWalker, HashedPostState, HashedStorage, StorageRoot, }; +use reth_trie_db::{DatabaseHashedCursorFactory, DatabaseTrieCursorFactory}; use reth_trie_parallel::{parallel_root::ParallelStateRootError, StorageRootTargets}; use std::{collections::HashMap, sync::Arc}; use thiserror::Error; @@ -158,10 +159,14 @@ impl TriePrefetch { .into_par_iter() .map(|(hashed_address, prefix_set)| { let provider_ro = consistent_view.provider_ro()?; - + let trie_cursor_factory = DatabaseTrieCursorFactory::new(provider_ro.tx_ref()); + let hashed_cursor_factory = HashedPostStateCursorFactory::new( + DatabaseHashedCursorFactory::new(provider_ro.tx_ref()), + &hashed_state_sorted, + ); let storage_root_result = StorageRoot::new_hashed( - provider_ro.tx_ref(), - HashedPostStateCursorFactory::new(provider_ro.tx_ref(), &hashed_state_sorted), + trie_cursor_factory, + hashed_cursor_factory, hashed_address, #[cfg(feature = "metrics")] self.metrics.clone(), @@ -175,9 +180,12 @@ impl TriePrefetch { trace!(target: "trie::trie_prefetch", "prefetching account tries"); let provider_ro = consistent_view.provider_ro()?; - let hashed_cursor_factory = - HashedPostStateCursorFactory::new(provider_ro.tx_ref(), &hashed_state_sorted); - let trie_cursor_factory = provider_ro.tx_ref(); + let tx = provider_ro.tx_ref(); + let trie_cursor_factory = DatabaseTrieCursorFactory::new(tx); + let hashed_cursor_factory = HashedPostStateCursorFactory::new( + DatabaseHashedCursorFactory::new(tx), + &hashed_state_sorted, + ); let walker = TrieWalker::new( trie_cursor_factory.account_trie_cursor().map_err(ProviderError::Database)?, @@ -200,7 +208,7 @@ impl TriePrefetch { // Since we do not store all intermediate nodes in the database, there might // be a possibility of re-adding a non-modified leaf to the hash builder. None => StorageRoot::new_hashed( - trie_cursor_factory, + trie_cursor_factory.clone(), hashed_cursor_factory.clone(), hashed_address, #[cfg(feature = "metrics")] @@ -250,44 +258,10 @@ impl From for ProviderError { fn from(error: TriePrefetchError) -> Self { match error { TriePrefetchError::Provider(error) => error, - TriePrefetchError::StorageRoot(StorageRootError::DB(error)) => Self::Database(error), - TriePrefetchError::ParallelStateRoot(error) => error.into(), - } - } -} - -#[cfg(test)] -mod tests { - use tokio::time; - - #[tokio::test] - async fn test_channel() { - let (prefetch_tx, mut prefetch_rx) = tokio::sync::mpsc::unbounded_channel(); - let (interrupt_tx, mut interrupt_rx) = tokio::sync::oneshot::channel(); - - tokio::spawn(async move { - loop { - tokio::select! { - _ = prefetch_rx.recv() => { - println!("got message"); - time::sleep(time::Duration::from_secs(3)).await; - } - _ = &mut interrupt_rx => { - println!("left items in channel: {}" ,prefetch_rx.len()); - break; - } - } + TriePrefetchError::StorageRoot(StorageRootError::Database(error)) => { + Self::Database(error) } - }); - - for _ in 0..10 { - prefetch_tx.send(()).unwrap(); + TriePrefetchError::ParallelStateRoot(error) => error.into(), } - - time::sleep(time::Duration::from_secs(3)).await; - - interrupt_tx.send(()).unwrap(); - - time::sleep(time::Duration::from_secs(10)).await; } } diff --git a/crates/trie/trie/src/state.rs b/crates/trie/trie/src/state.rs index 14eb5fd0a6..a5e58341ff 100644 --- a/crates/trie/trie/src/state.rs +++ b/crates/trie/trie/src/state.rs @@ -1,14 +1,16 @@ -use crate::{ - prefix_set::{PrefixSetMut, TriePrefixSetsMut}, - Nibbles, +use std::{ + borrow::Cow, + collections::{hash_map, HashMap, HashSet}, }; + use itertools::Itertools; use rayon::prelude::{IntoParallelIterator, ParallelIterator}; use reth_primitives::{keccak256, Account, Address, B256, U256}; use revm::db::{states::CacheAccount, AccountStatus, BundleAccount}; -use std::{ - borrow::Cow, - collections::{hash_map, HashMap, HashSet}, + +use crate::{ + prefix_set::{PrefixSetMut, TriePrefixSetsMut}, + Nibbles, }; /// Representation of in-memory hashed state. @@ -59,7 +61,7 @@ impl HashedPostState { this.accounts.insert(hashed_address, Some(account.info.clone().into())); let hashed_storage = HashedStorage::from_iter( - account.status == AccountStatus::SelfDestructed, + account.status == revm::primitives::AccountStatus::SelfDestructed, account.storage.iter().map(|(key, value)| { (keccak256(B256::new(key.to_be_bytes())), value.present_value) }), diff --git a/op.Dockerfile b/op.Dockerfile index 93d0b45c11..e06f1dd56c 100644 --- a/op.Dockerfile +++ b/op.Dockerfile @@ -1,7 +1,7 @@ FROM lukemathwalker/cargo-chef:latest-rust-1.80 AS chef WORKDIR /app -LABEL org.opencontainers.image.source=https://github.com/paradigmxyz/reth +LABEL org.opencontainers.image.source=https://github.com/bnb-chain/reth LABEL org.opencontainers.image.licenses="MIT OR Apache-2.0" # Builds a cargo-chef plan