Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into joshie/sto
Browse files Browse the repository at this point in the history
  • Loading branch information
joshieDo committed Nov 6, 2024
2 parents a8225e2 + 12b0637 commit 86e0bd7
Show file tree
Hide file tree
Showing 138 changed files with 2,356 additions and 846 deletions.
262 changes: 141 additions & 121 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "1.1.0"
version = "1.1.1"
edition = "2021"
rust-version = "1.82"
license = "MIT OR Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ install-op: ## Build and install the op-reth binary under `~/.cargo/bin`.
build: ## Build the reth binary into `target` directory.
cargo build --bin reth --features "$(FEATURES)" --profile "$(PROFILE)"

SOURCE_DATE_EPOCH := $(shell git log -1 --pretty=%ct)
SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct)
.PHONY: reproducible
reproducible: ## Build the reth binary into `target` directory with reproducible builds. Only works for x86_64-unknown-linux-gnu currently
SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) \
Expand Down
7 changes: 3 additions & 4 deletions bin/reth/src/commands/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Command for debugging block building.
use alloy_consensus::TxEip4844;
use alloy_eips::eip2718::Encodable2718;
use alloy_eips::{eip2718::Encodable2718, eip4844::BlobTransactionSidecar};
use alloy_primitives::{Address, Bytes, B256, U256};
use alloy_rlp::Decodable;
use alloy_rpc_types::engine::{BlobsBundleV1, PayloadAttributes};
Expand All @@ -27,9 +27,8 @@ use reth_node_api::{
};
use reth_node_ethereum::{EthEvmConfig, EthExecutorProvider};
use reth_primitives::{
revm_primitives::KzgSettings, BlobTransaction, BlobTransactionSidecar,
PooledTransactionsElement, SealedBlock, SealedBlockWithSenders, SealedHeader, Transaction,
TransactionSigned,
revm_primitives::KzgSettings, BlobTransaction, PooledTransactionsElement, SealedBlock,
SealedBlockWithSenders, SealedHeader, Transaction, TransactionSigned,
};
use reth_provider::{
providers::BlockchainProvider, BlockHashReader, BlockReader, BlockWriter, ChainSpecProvider,
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/commands/debug_cmd/execution.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Command for debugging execution.
use crate::{args::NetworkArgs, utils::get_single_header};
use alloy_eips::BlockHashOrNumber;
use alloy_primitives::{BlockNumber, B256};
use clap::Parser;
use futures::{stream::select as stream_select, StreamExt};
Expand All @@ -23,7 +24,6 @@ use reth_network_api::NetworkInfo;
use reth_network_p2p::{headers::client::HeadersClient, BlockClient};
use reth_node_api::{NodeTypesWithDB, NodeTypesWithDBAdapter, NodeTypesWithEngine};
use reth_node_ethereum::EthExecutorProvider;
use reth_primitives::BlockHashOrNumber;
use reth_provider::{
BlockExecutionWriter, ChainSpecProvider, ProviderFactory, StageCheckpointReader,
};
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/commands/debug_cmd/in_memory_merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
args::NetworkArgs,
utils::{get_single_body, get_single_header},
};
use alloy_eips::BlockHashOrNumber;
use backon::{ConstantBuilder, Retryable};
use clap::Parser;
use reth_chainspec::ChainSpec;
Expand All @@ -19,7 +20,6 @@ use reth_network::{BlockDownloaderProvider, NetworkHandle};
use reth_network_api::NetworkInfo;
use reth_node_api::{NodeTypesWithDB, NodeTypesWithEngine};
use reth_node_ethereum::EthExecutorProvider;
use reth_primitives::BlockHashOrNumber;
use reth_provider::{
writer::UnifiedStorageWriter, AccountExtReader, ChainSpecProvider, HashingWriter,
HeaderProvider, LatestStateProviderRef, OriginalValuesKnown, ProviderFactory,
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/commands/debug_cmd/merkle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Command for debugging merkle trie calculation.
use crate::{args::NetworkArgs, utils::get_single_header};
use alloy_eips::BlockHashOrNumber;
use backon::{ConstantBuilder, Retryable};
use clap::Parser;
use reth_beacon_consensus::EthBeaconConsensus;
Expand All @@ -18,7 +19,6 @@ use reth_network_api::NetworkInfo;
use reth_network_p2p::full_block::FullBlockClient;
use reth_node_api::{NodeTypesWithDB, NodeTypesWithEngine};
use reth_node_ethereum::EthExecutorProvider;
use reth_primitives::BlockHashOrNumber;
use reth_provider::{
writer::UnifiedStorageWriter, BlockNumReader, BlockWriter, ChainSpecProvider,
DatabaseProviderFactory, HeaderProvider, LatestStateProviderRef, OriginalValuesKnown,
Expand Down
1 change: 1 addition & 0 deletions crates/blockchain-tree-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ reth-storage-errors.workspace = true

# alloy
alloy-primitives.workspace = true
alloy-eips.workspace = true

# misc
thiserror.workspace = true
3 changes: 2 additions & 1 deletion crates/blockchain-tree-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

use self::error::CanonicalError;
use crate::error::InsertBlockError;
use alloy_eips::BlockNumHash;
use alloy_primitives::{BlockHash, BlockNumber};
use reth_primitives::{BlockNumHash, Receipt, SealedBlock, SealedBlockWithSenders, SealedHeader};
use reth_primitives::{Receipt, SealedBlock, SealedBlockWithSenders, SealedHeader};
use reth_storage_errors::provider::{ProviderError, ProviderResult};
use std::collections::BTreeMap;

Expand Down
6 changes: 3 additions & 3 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ mod tests {
use alloy_consensus::{TxEip1559, EMPTY_ROOT_HASH};
use alloy_eips::eip1559::INITIAL_BASE_FEE;
use alloy_genesis::{Genesis, GenesisAccount};
use alloy_primitives::{keccak256, Address, Sealable, B256};
use alloy_primitives::{keccak256, Address, Sealable, Signature, B256};
use assert_matches::assert_matches;
use linked_hash_set::LinkedHashSet;
use reth_chainspec::{ChainSpecBuilder, MAINNET, MIN_TRANSACTION_GAS};
Expand All @@ -1389,8 +1389,8 @@ mod tests {
use reth_primitives::{
proofs::{calculate_receipt_root, calculate_transaction_root},
revm_primitives::AccountInfo,
Account, BlockBody, Header, Signature, Transaction, TransactionSigned,
TransactionSignedEcRecovered, Withdrawals,
Account, BlockBody, Header, Transaction, TransactionSigned, TransactionSignedEcRecovered,
Withdrawals,
};
use reth_provider::{
test_utils::{
Expand Down
3 changes: 2 additions & 1 deletion crates/consensus/auto-seal/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! This includes download client implementations for auto sealing miners.
use crate::Storage;
use alloy_eips::BlockHashOrNumber;
use alloy_primitives::B256;
use reth_network_p2p::{
bodies::client::{BodiesClient, BodiesFut},
Expand All @@ -9,7 +10,7 @@ use reth_network_p2p::{
priority::Priority,
};
use reth_network_peers::{PeerId, WithPeerId};
use reth_primitives::{BlockBody, BlockHashOrNumber, Header};
use reth_primitives::{BlockBody, Header};
use std::fmt::Debug;
use tracing::{trace, warn};

Expand Down
6 changes: 3 additions & 3 deletions crates/consensus/auto-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use alloy_eips::eip7685::Requests;
use alloy_eips::{eip1898::BlockHashOrNumber, eip7685::Requests};
use alloy_primitives::{BlockHash, BlockNumber, Bloom, B256, U256};
use reth_beacon_consensus::BeaconEngineMessage;
use reth_chainspec::{EthChainSpec, EthereumHardforks};
Expand All @@ -26,8 +26,8 @@ use reth_execution_errors::{
};
use reth_execution_types::ExecutionOutcome;
use reth_primitives::{
proofs, Block, BlockBody, BlockHashOrNumber, BlockWithSenders, Header, SealedBlock,
SealedHeader, TransactionSigned, Withdrawals,
proofs, Block, BlockBody, BlockWithSenders, Header, SealedBlock, SealedHeader,
TransactionSigned, Withdrawals,
};
use reth_provider::{BlockReaderIdExt, StateProviderFactory, StateRootProvider};
use reth_revm::database::StateProviderDatabase;
Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/beacon/src/engine/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_eips::merge::EPOCH_SLOTS;
use alloy_eips::{merge::EPOCH_SLOTS, BlockNumHash};
use alloy_primitives::{BlockNumber, B256};
use alloy_rpc_types_engine::{
ExecutionPayload, ExecutionPayloadSidecar, ForkchoiceState, PayloadStatus, PayloadStatusEnum,
Expand All @@ -20,7 +20,7 @@ use reth_node_types::NodeTypesWithEngine;
use reth_payload_builder::PayloadBuilderHandle;
use reth_payload_primitives::{PayloadAttributes, PayloadBuilder, PayloadBuilderAttributes};
use reth_payload_validator::ExecutionPayloadValidator;
use reth_primitives::{BlockNumHash, Head, Header, SealedBlock, SealedHeader};
use reth_primitives::{Head, Header, SealedBlock, SealedHeader};
use reth_provider::{
providers::ProviderNodeTypes, BlockIdReader, BlockReader, BlockSource, CanonChainTracker,
ChainSpecProvider, ProviderError, StageCheckpointReader,
Expand Down
6 changes: 3 additions & 3 deletions crates/consensus/common/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ pub fn validate_against_parent_4844(
mod tests {
use super::*;
use alloy_consensus::{TxEip4844, EMPTY_OMMER_ROOT_HASH, EMPTY_ROOT_HASH};
use alloy_eips::{eip4895::Withdrawal, BlockHashOrNumber};
use alloy_primitives::{
hex_literal::hex, Address, BlockHash, BlockNumber, Bytes, Parity, Sealable, U256,
hex_literal::hex, Address, BlockHash, BlockNumber, Bytes, Parity, Sealable, Signature, U256,
};
use mockall::mock;
use rand::Rng;
use reth_chainspec::ChainSpecBuilder;
use reth_primitives::{
proofs, Account, BlockBody, BlockHashOrNumber, Signature, Transaction, TransactionSigned,
Withdrawal, Withdrawals,
proofs, Account, BlockBody, Transaction, TransactionSigned, Withdrawals,
};
use reth_storage_api::{
errors::provider::ProviderResult, AccountReader, HeaderProvider, WithdrawalsProvider,
Expand Down
6 changes: 3 additions & 3 deletions crates/engine/local/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ workspace = true

[features]
optimism = [
"op-alloy-rpc-types-engine",
"reth-beacon-consensus/optimism",
"reth-provider/optimism"
"op-alloy-rpc-types-engine",
"reth-beacon-consensus/optimism",
"reth-provider/optimism",
]
3 changes: 3 additions & 0 deletions crates/engine/tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ alloy-primitives.workspace = true
alloy-eips.workspace = true
alloy-rpc-types-engine.workspace = true

revm-primitives.workspace = true

# common
futures.workspace = true
tokio = { workspace = true, features = ["macros", "sync"] }
tokio-stream.workspace = true
thiserror.workspace = true

# metrics
Expand Down
12 changes: 11 additions & 1 deletion crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use reth_revm::database::StateProviderDatabase;
use reth_stages_api::ControlFlow;
use reth_trie::{updates::TrieUpdates, HashedPostState, TrieInput};
use reth_trie_parallel::parallel_root::{ParallelStateRoot, ParallelStateRootError};
use revm_primitives::ResultAndState;
use std::{
cmp::Ordering,
collections::{btree_map, hash_map, BTreeMap, VecDeque},
Expand Down Expand Up @@ -75,6 +76,8 @@ pub use invalid_block_hook::{InvalidBlockHooks, NoopInvalidBlockHook};
pub use persistence_state::PersistenceState;
pub use reth_engine_primitives::InvalidBlockHook;

mod root;

/// Keeps track of the state of the tree.
///
/// ## Invariants
Expand Down Expand Up @@ -2185,7 +2188,14 @@ where
let block = block.unseal();

let exec_time = Instant::now();
let output = self.metrics.executor.execute_metered(executor, (&block, U256::MAX).into())?;
// TODO: create StateRootTask with the receiving end of a channel and
// pass the sending end of the channel to the state hook.
let noop_state_hook = |_result_and_state: &ResultAndState| {};
let output = self.metrics.executor.execute_metered(
executor,
(&block, U256::MAX).into(),
Box::new(noop_state_hook),
)?;

trace!(target: "engine::tree", elapsed=?exec_time.elapsed(), ?block_number, "Executed block");
if let Err(err) = self.consensus.validate_block_post_execution(
Expand Down
60 changes: 60 additions & 0 deletions crates/engine/tree/src/tree/root.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//! State root task related functionality.
use reth_provider::providers::ConsistentDbView;
use reth_trie::{updates::TrieUpdates, TrieInput};
use reth_trie_parallel::parallel_root::ParallelStateRootError;
use revm_primitives::{EvmState, B256};
use std::{
future::Future,
pin::Pin,
sync::Arc,
task::{Context, Poll},
};
use tokio_stream::wrappers::UnboundedReceiverStream;

/// Standalone task that receives a transaction state stream and updates relevant
/// data structures to calculate state root.
///
/// It is responsile of initializing a blinded sparse trie and subscribe to
/// transaction state stream. As it receives transaction execution results, it
/// fetches the proofs for relevant accounts from the database and reveal them
/// to the tree.
/// Then it updates relevant leaves according to the result of the transaction.
#[allow(dead_code)]
pub(crate) struct StateRootTask<Factory> {
/// View over the state in the database.
consistent_view: ConsistentDbView<Factory>,
/// Incoming state updates.
state_stream: UnboundedReceiverStream<EvmState>,
/// Latest trie input.
input: Arc<TrieInput>,
}

#[allow(dead_code)]
impl<Factory> StateRootTask<Factory> {
/// Creates a new `StateRootTask`.
pub(crate) const fn new(
consistent_view: ConsistentDbView<Factory>,
input: Arc<TrieInput>,
state_stream: UnboundedReceiverStream<EvmState>,
) -> Self {
Self { consistent_view, state_stream, input }
}

/// Handles state updates.
pub(crate) fn on_state_update(&self, _update: EvmState) {
// TODO: calculate hashed state update and dispatch proof gathering for it.
}
}

impl<Factory> Future for StateRootTask<Factory> {
type Output = Result<(B256, TrieUpdates), ParallelStateRootError>;

fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
// TODO:
// * poll incoming state updates stream
// * keep track of proof calculation
// * keep track of intermediate root computation
Poll::Pending
}
}
1 change: 1 addition & 0 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ parking_lot = { workspace = true, optional = true }
parking_lot.workspace = true
reth-ethereum-forks.workspace = true
alloy-consensus.workspace = true
metrics-util = { workspace = true, features = ["debugging"] }

[features]
default = ["std"]
Expand Down
Loading

0 comments on commit 86e0bd7

Please sign in to comment.