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

Early blocks #9

Merged
merged 3 commits into from
Feb 9, 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
5 changes: 5 additions & 0 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,14 @@ ethereum = []
telos = [
"dep:antelope-client",
"dep:reth-telos",
"reth-blockchain-tree/telos",
"reth-interfaces/telos",
"reth-rpc/telos",
"reth-network/telos",
"reth-primitives/telos",
"reth-provider/telos",
"reth-consensus-common/telos",
"reth-stages/telos",
]

[build-dependencies]
Expand Down
1 change: 1 addition & 0 deletions crates/blockchain-tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ assert_matches.workspace = true
[features]
test-utils = []
optimism = ["reth-primitives/optimism", "reth-interfaces/optimism", "reth-provider/optimism", "reth-revm/optimism"]
telos = []
3 changes: 3 additions & 0 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ impl<DB: Database, EF: ExecutorFactory> BlockchainTree<DB, EF> {
)
})?;

#[cfg(not(feature = "telos"))] {
// Pass the parent total difficulty to short-circuit unnecessary calculations.
if !self
.externals
Expand All @@ -400,6 +401,7 @@ impl<DB: Database, EF: ExecutorFactory> BlockchainTree<DB, EF> {
block.block,
))
}
}

let parent_header = provider
.header(&block.parent_hash)
Expand Down Expand Up @@ -1179,6 +1181,7 @@ impl<DB: Database, EF: ExecutorFactory> BlockchainTree<DB, EF> {
.state_root_with_updates(provider.tx_ref())
.map_err(Into::<DatabaseError>::into)?;
let tip = blocks.tip();
#[cfg(not(feature = "telos"))]
if state_root != tip.state_root {
return Err(RethError::Provider(ProviderError::StateRootMismatch(Box::new(
RootMismatch {
Expand Down
1 change: 1 addition & 0 deletions crates/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ mockall = "0.11.3"

[features]
optimism = ["reth-primitives/optimism"]
telos = []
1 change: 1 addition & 0 deletions crates/consensus/common/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ pub fn validate_header_regarding_parent(
}

// timestamp in past check
#[cfg(not(feature = "telos"))]
if child.timestamp <= parent.timestamp {
return Err(ConsensusError::TimestampIsInPast {
parent_timestamp: parent.timestamp,
Expand Down
1 change: 1 addition & 0 deletions crates/interfaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ secp256k1 = { workspace = true, features = ["alloc", "recovery", "rand"] }
test-utils = ["secp256k1", "rand", "parking_lot"]
cli = ["clap"]
optimism = ["reth-eth-wire/optimism"]
telos = []
2 changes: 2 additions & 0 deletions crates/interfaces/src/blockchain_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ pub enum BlockValidationKind {
impl BlockValidationKind {
/// Returns true if the state root should be validated if possible.
pub fn is_exhaustive(&self) -> bool {
#[cfg(feature = "telos")]
return false;
matches!(self, BlockValidationKind::Exhaustive)
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/rpc/rpc-types-compat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ serde_json.workspace = true

[features]
optimism = ["reth-primitives/optimism", "reth-rpc-types/optimism"]
telos = []
3 changes: 3 additions & 0 deletions crates/rpc/rpc-types-compat/src/engine/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub fn try_payload_v1_to_block(payload: ExecutionPayloadV1) -> Result<Block, Pay
gas_used: payload.gas_used,
timestamp: payload.timestamp,
mix_hash: payload.prev_randao,
#[cfg(feature = "telos")]
base_fee_per_gas: None,
#[cfg(not(feature = "telos"))]
base_fee_per_gas: Some(
payload
.base_fee_per_gas
Expand Down
1 change: 1 addition & 0 deletions crates/rpc/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,5 @@ optimism = [

telos = [
"dep:reth-telos",
"reth-rpc-types-compat/telos",
]
1 change: 1 addition & 0 deletions crates/stages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ serde_json.workspace = true

[features]
test-utils = ["reth-interfaces/test-utils", "reth-db/test-utils"]
telos = []

[[bench]]
name = "criterion"
Expand Down
2 changes: 2 additions & 0 deletions crates/stages/src/stages/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ impl<DB: Database> Stage<DB> for MerkleStage {
// Reset the checkpoint
self.save_execution_checkpoint(provider, None)?;

#[cfg(not(feature = "telos"))]
validate_state_root(trie_root, target_block.seal_slow(), to_block)?;

Ok(ExecOutput {
Expand Down Expand Up @@ -301,6 +302,7 @@ impl<DB: Database> Stage<DB> for MerkleStage {
let target = provider
.header_by_number(input.unwind_to)?
.ok_or_else(|| ProviderError::HeaderNotFound(input.unwind_to.into()))?;
#[cfg(not(feature = "telos"))]
validate_state_root(block_root, target.seal_slow(), input.unwind_to)?;

// Validation passed, apply unwind changes to the database.
Expand Down
1 change: 1 addition & 0 deletions crates/storage/provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ optimism = [
"reth-primitives/optimism",
"reth-interfaces/optimism"
]
telos = []
3 changes: 3 additions & 0 deletions crates/storage/provider/src/providers/database/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use std::{
sync::{mpsc, Arc},
time::{Duration, Instant},
};
use revm::interpreter::instructions::bitwise::not;
use tracing::{debug, warn};

/// A [`DatabaseProvider`] that holds a read-only database transaction.
Expand Down Expand Up @@ -2091,6 +2092,7 @@ impl<TX: DbTxMut + DbTx> HashingWriter for DatabaseProvider<TX> {
.with_destroyed_accounts(destroyed_accounts)
.root_with_updates()
.map_err(Into::<reth_db::DatabaseError>::into)?;
#[cfg(not(feature = "telos"))]
if state_root != expected_state_root {
return Err(ProviderError::StateRootMismatch(Box::new(RootMismatch {
root: GotExpected { got: state_root, expected: expected_state_root },
Expand Down Expand Up @@ -2284,6 +2286,7 @@ impl<TX: DbTxMut + DbTx> BlockExecutionWriter for DatabaseProvider<TX> {

// state root should be always correct as we are reverting state.
// but for sake of double verification we will check it again.
#[cfg(not(feature = "telos"))]
if new_state_root != parent_state_root {
let parent_hash = self
.block_hash(parent_number)?
Expand Down