From 7988767a9545f7487e46bd318c9f4f0c4f01654f Mon Sep 17 00:00:00 2001 From: Jesse Schulman Date: Sat, 3 Feb 2024 22:59:29 -0800 Subject: [PATCH 1/3] Disable some rules for block validation --- bin/reth/Cargo.toml | 2 ++ crates/blockchain-tree/Cargo.toml | 1 + crates/blockchain-tree/src/blockchain_tree.rs | 2 ++ crates/interfaces/Cargo.toml | 1 + crates/interfaces/src/blockchain_tree/mod.rs | 2 ++ crates/rpc/rpc-types-compat/Cargo.toml | 1 + crates/rpc/rpc-types-compat/src/engine/payload.rs | 3 +++ crates/rpc/rpc/Cargo.toml | 1 + 8 files changed, 13 insertions(+) diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index 250955d590ab..3ac8ef637838 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -168,6 +168,8 @@ ethereum = [] telos = [ "dep:antelope-client", "dep:reth-telos", + "reth-blockchain-tree/telos", + "reth-interfaces/telos", "reth-rpc/telos", "reth-network/telos", "reth-primitives/telos", diff --git a/crates/blockchain-tree/Cargo.toml b/crates/blockchain-tree/Cargo.toml index 7565fe06d702..1d4f14864920 100644 --- a/crates/blockchain-tree/Cargo.toml +++ b/crates/blockchain-tree/Cargo.toml @@ -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 = [] diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index 0aa5333432b3..36f1f9459bfa 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -387,6 +387,7 @@ impl BlockchainTree { ) })?; + #[cfg(not(feature = "telos"))] { // Pass the parent total difficulty to short-circuit unnecessary calculations. if !self .externals @@ -400,6 +401,7 @@ impl BlockchainTree { block.block, )) } + } let parent_header = provider .header(&block.parent_hash) diff --git a/crates/interfaces/Cargo.toml b/crates/interfaces/Cargo.toml index fafcdaf88e62..45df433e0d85 100644 --- a/crates/interfaces/Cargo.toml +++ b/crates/interfaces/Cargo.toml @@ -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 = [] diff --git a/crates/interfaces/src/blockchain_tree/mod.rs b/crates/interfaces/src/blockchain_tree/mod.rs index 3d77fef03cf9..efa319f098eb 100644 --- a/crates/interfaces/src/blockchain_tree/mod.rs +++ b/crates/interfaces/src/blockchain_tree/mod.rs @@ -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) } } diff --git a/crates/rpc/rpc-types-compat/Cargo.toml b/crates/rpc/rpc-types-compat/Cargo.toml index 6dc225ffad9d..69b53a3a7cee 100644 --- a/crates/rpc/rpc-types-compat/Cargo.toml +++ b/crates/rpc/rpc-types-compat/Cargo.toml @@ -20,3 +20,4 @@ serde_json.workspace = true [features] optimism = ["reth-primitives/optimism", "reth-rpc-types/optimism"] +telos = [] diff --git a/crates/rpc/rpc-types-compat/src/engine/payload.rs b/crates/rpc/rpc-types-compat/src/engine/payload.rs index b9b51f00feb0..63ba9c50a877 100644 --- a/crates/rpc/rpc-types-compat/src/engine/payload.rs +++ b/crates/rpc/rpc-types-compat/src/engine/payload.rs @@ -41,6 +41,9 @@ pub fn try_payload_v1_to_block(payload: ExecutionPayloadV1) -> Result Date: Mon, 5 Feb 2024 13:31:36 -0800 Subject: [PATCH 2/3] Accepting blocks! --- bin/reth/Cargo.toml | 2 ++ crates/blockchain-tree/src/blockchain_tree.rs | 1 + crates/consensus/common/Cargo.toml | 1 + crates/consensus/common/src/validation.rs | 1 + crates/storage/provider/Cargo.toml | 1 + crates/storage/provider/src/providers/database/provider.rs | 3 +++ 6 files changed, 9 insertions(+) diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index 3ac8ef637838..5b7d3e2f915e 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -173,6 +173,8 @@ telos = [ "reth-rpc/telos", "reth-network/telos", "reth-primitives/telos", + "reth-provider/telos", + "reth-consensus-common/telos", ] [build-dependencies] diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index 36f1f9459bfa..ddc7d986a8cf 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -1181,6 +1181,7 @@ impl BlockchainTree { .state_root_with_updates(provider.tx_ref()) .map_err(Into::::into)?; let tip = blocks.tip(); + #[cfg(not(feature = "telos"))] if state_root != tip.state_root { return Err(RethError::Provider(ProviderError::StateRootMismatch(Box::new( RootMismatch { diff --git a/crates/consensus/common/Cargo.toml b/crates/consensus/common/Cargo.toml index 51c3134c0e94..604dbe3691c8 100644 --- a/crates/consensus/common/Cargo.toml +++ b/crates/consensus/common/Cargo.toml @@ -27,3 +27,4 @@ mockall = "0.11.3" [features] optimism = ["reth-primitives/optimism"] +telos = [] \ No newline at end of file diff --git a/crates/consensus/common/src/validation.rs b/crates/consensus/common/src/validation.rs index 6ee52bad4c51..468fc06c67e0 100644 --- a/crates/consensus/common/src/validation.rs +++ b/crates/consensus/common/src/validation.rs @@ -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, diff --git a/crates/storage/provider/Cargo.toml b/crates/storage/provider/Cargo.toml index 64ff9742a4c9..44900feabe54 100644 --- a/crates/storage/provider/Cargo.toml +++ b/crates/storage/provider/Cargo.toml @@ -65,3 +65,4 @@ optimism = [ "reth-primitives/optimism", "reth-interfaces/optimism" ] +telos = [] diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index 1180a755cce2..31ca30773404 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -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. @@ -2091,6 +2092,7 @@ impl HashingWriter for DatabaseProvider { .with_destroyed_accounts(destroyed_accounts) .root_with_updates() .map_err(Into::::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 }, @@ -2284,6 +2286,7 @@ impl BlockExecutionWriter for DatabaseProvider { // 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)? From bc71f23060f6ab557f41b9fcb5c14358828dde94 Mon Sep 17 00:00:00 2001 From: Amir Pasha Motamed Date: Wed, 7 Feb 2024 17:12:59 +0330 Subject: [PATCH 3/3] Disable state root validation in Merkle stage --- bin/reth/Cargo.toml | 1 + crates/stages/Cargo.toml | 1 + crates/stages/src/stages/merkle.rs | 2 ++ 3 files changed, 4 insertions(+) diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index 5b7d3e2f915e..c6906fe02554 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -175,6 +175,7 @@ telos = [ "reth-primitives/telos", "reth-provider/telos", "reth-consensus-common/telos", + "reth-stages/telos", ] [build-dependencies] diff --git a/crates/stages/Cargo.toml b/crates/stages/Cargo.toml index d3ddca5be3ae..c8d165c88521 100644 --- a/crates/stages/Cargo.toml +++ b/crates/stages/Cargo.toml @@ -82,6 +82,7 @@ serde_json.workspace = true [features] test-utils = ["reth-interfaces/test-utils", "reth-db/test-utils"] +telos = [] [[bench]] name = "criterion" diff --git a/crates/stages/src/stages/merkle.rs b/crates/stages/src/stages/merkle.rs index 7b74ca47b8fb..ec0c0be19b32 100644 --- a/crates/stages/src/stages/merkle.rs +++ b/crates/stages/src/stages/merkle.rs @@ -251,6 +251,7 @@ impl Stage 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 { @@ -301,6 +302,7 @@ impl Stage 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.