Skip to content

Commit

Permalink
chore: resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 committed Sep 3, 2024
1 parent 785411b commit 82d3a1c
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 78 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

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

5 changes: 1 addition & 4 deletions crates/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions crates/exex/exex/src/backfill/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions crates/node/core/src/args/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
3 changes: 2 additions & 1 deletion crates/optimism/evm/src/execute.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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};

Expand Down
42 changes: 28 additions & 14 deletions crates/storage/provider/src/providers/database/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2095,13 +2095,20 @@ impl<TX: DbTx> BlockReader for DatabaseProvider<TX> {
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)
},
)
}
Expand All @@ -2116,13 +2123,20 @@ impl<TX: DbTx> BlockReader for DatabaseProvider<TX> {
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)
},
)
}
Expand Down
1 change: 1 addition & 0 deletions crates/trie/prefetch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 18 additions & 44 deletions crates/trie/prefetch/src/prefetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand All @@ -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)?,
Expand All @@ -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")]
Expand Down Expand Up @@ -250,44 +258,10 @@ impl From<TriePrefetchError> 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;
}
}
16 changes: 9 additions & 7 deletions crates/trie/trie/src/state.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
}),
Expand Down

0 comments on commit 82d3a1c

Please sign in to comment.