Skip to content
Draft
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
547 changes: 270 additions & 277 deletions Cargo.lock

Large diffs are not rendered by default.

110 changes: 55 additions & 55 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,60 +16,60 @@ name = "reth-bsc"
path = "src/main.rs"

[dependencies]
reth = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-cli = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-cli-commands = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-basic-payload-builder = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-db = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-engine-local = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-engine-tree = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-node-builder = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-chainspec = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-cli-util = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-discv4 = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1", features = [
reth = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-cli = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-cli-commands = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-basic-payload-builder = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-db = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-engine-local = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-engine-tree = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-node-builder = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-chainspec = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-cli-util = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-discv4 = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2", features = [
"test-utils",
] }
reth-engine-primitives = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-ethereum-forks = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1", features = [
reth-engine-primitives = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-ethereum-forks = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2", features = [
"serde",
] }
reth-ethereum-payload-builder = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-payload-builder-primitives = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-chain-state = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-ethereum-primitives = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-eth-wire = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-eth-wire-types = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-evm = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-evm-ethereum = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-execution-types = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-ipc = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-metrics = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-node-core = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-revm = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-network = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1", features = [
reth-ethereum-payload-builder = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-payload-builder-primitives = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-chain-state = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-ethereum-primitives = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-eth-wire = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-eth-wire-types = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-evm = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-evm-ethereum = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-execution-types = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-ipc = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-metrics = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-node-core = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-revm = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-network = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2", features = [
"test-utils",
] }
reth-network-p2p = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-network-api = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-node-ethereum = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1", features = [
reth-network-p2p = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-network-api = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-node-ethereum = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2", features = [
"test-utils",
] }
reth-network-peers = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-payload-primitives = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-ethereum-engine-primitives = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-primitives-traits = { git = "https://github.com/bnb-chain/reth-core.git", branch = "v0.3.0-v2", default-features = false }
reth-codecs = { git = "https://github.com/bnb-chain/reth-core.git", branch = "v0.3.0-v2" }
reth-provider = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1", features = [
reth-network-peers = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-payload-primitives = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-ethereum-engine-primitives = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-primitives-traits = { git = "https://github.com/bnb-chain/reth-core.git", branch = "v0.3.1-v2", default-features = false }
reth-codecs = { git = "https://github.com/bnb-chain/reth-core.git", branch = "v0.3.1-v2" }
reth-provider = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2", features = [
"test-utils",
] }
reth-rpc-eth-api = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-rpc-convert = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-rpc-engine-api = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-rpc-server-types = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-trie-common = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-trie-db = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-tasks = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-transaction-pool = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.1" }
reth-rpc-eth-api = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-rpc-convert = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-rpc-engine-api = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-rpc-server-types = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-trie-common = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-trie-db = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-tasks = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }
reth-transaction-pool = { git = "https://github.com/bnb-chain/reth.git", branch = "develop-v2.2" }

# triedb dependencies
rust-eth-triedb = { git = "https://github.com/bnb-chain/reth-bsc-triedb.git", tag = "v0.0.2" }
Expand All @@ -86,17 +86,17 @@ revm-interpreter = "35.0.0"
revm-database-interface = "11.0.0"

# alloy dependencies
alloy-evm = { version = "0.33.0", features = ["rpc"] }

alloy-genesis = "2.0.0"
alloy-consensus = "2.0.0"
alloy-eips = "2.0.0"
alloy-network = "2.0.0"
alloy-rpc-types = { version = "2.0.0", features = ["eth"] }
alloy-rpc-types-eth = "2.0.0"
alloy-rpc-types-engine = "2.0.0"
alloy-rpc-types-mev = "2.0.0"
alloy-signer = "2.0.0"
alloy-evm = { version = "0.34.0", features = ["rpc"] }

alloy-genesis = "2.0.4"
alloy-consensus = "2.0.4"
alloy-eips = "2.0.4"
alloy-network = "2.0.4"
alloy-rpc-types = { version = "2.0.4", features = ["eth"] }
alloy-rpc-types-eth = "2.0.4"
alloy-rpc-types-engine = "2.0.4"
alloy-rpc-types-mev = "2.0.4"
alloy-signer = "2.0.4"

alloy-chains = "0.2.33"
alloy-rlp = { version = "0.3.13", default-features = false, features = [
Expand Down
22 changes: 11 additions & 11 deletions src/consensus/parlia/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use reth_primitives_traits::GotExpected;
use alloy_eips::eip4844::{DATA_GAS_PER_BLOB, MAX_DATA_GAS_PER_BLOCK_DENCUN};
use crate::BscBlock;
use reth_primitives_traits::Block;
use std::time::SystemTime;
use std::{sync::Arc, time::SystemTime};

const MAX_RLP_BLOCK_SIZE_OSAKA: usize = 8 * 1024 * 1024;

Expand Down Expand Up @@ -51,11 +51,11 @@ pub fn validate_4844_header_of_bsc<ChainSpec: BscHardforks>(

// BEP-657: After Mendel, non-eligible blocks must have blob_gas_used == 0
if !is_blob_eligible_block(chain_spec, header.number, header.timestamp) && blob_gas_used != 0 {
return Err(ConsensusError::Other(format!(
return Err(ConsensusError::Other(Arc::new(std::io::Error::other(format!(
"blob transactions not allowed in block {} (N % {} != 0)",
header.number,
crate::consensus::eip4844::BLOB_ELIGIBLE_BLOCK_INTERVAL
)));
)))));
}

if blob_gas_used > MAX_DATA_GAS_PER_BLOCK_DENCUN {
Expand Down Expand Up @@ -114,16 +114,16 @@ fn validate_mix_digest_for_parlia(
) -> Result<(), ConsensusError> {
if !lorentz_active {
if header.mix_hash != B256::ZERO {
return Err(ConsensusError::Other("non-zero mix digest".to_string()));
return Err(ConsensusError::Other(Arc::new(std::io::Error::other("non-zero mix digest"))));
}
return Ok(());
}

// In Lorentz+, mix digest carries the millisecond remainder. It must not overflow seconds.
if calculate_millisecond_timestamp(header) / 1000 != header.timestamp {
return Err(ConsensusError::Other(
"invalid mix digest milliseconds component".to_string(),
));
return Err(ConsensusError::Other(Arc::new(std::io::Error::other(
"invalid mix digest milliseconds component",
))));
}
Ok(())
}
Expand Down Expand Up @@ -172,7 +172,7 @@ impl<ChainSpec: EthChainSpec + BscHardforks + std::fmt::Debug + Send + Sync + 's
validate_header_not_from_future(header, present_unix_seconds())?;

// Check extra data
self.check_header_extra(header).map_err(|e| ConsensusError::Other(format!("Invalid header extra: {e}")))?;
self.check_header_extra(header).map_err(|e| ConsensusError::Other(Arc::new(std::io::Error::other(format!("Invalid header extra: {e}")))))?;

// Ensure that the block with no uncles
if header.ommers_hash != EMPTY_OMMER_ROOT_HASH {
Expand Down Expand Up @@ -268,9 +268,9 @@ impl<ChainSpec: EthChainSpec + BscHardforks + std::fmt::Debug + Send + Sync + 's
if !is_blob_eligible_block(&*self.spec, block.number, block.timestamp)
&& block.body().transactions().any(|tx| tx.is_eip4844())
{
return Err(ConsensusError::Other(
"blob transactions not allowed in this block".to_string(),
));
return Err(ConsensusError::Other(Arc::new(std::io::Error::other(
"blob transactions not allowed in this block",
))));
}
// Check that the blob gas used in the header matches the sum of the blob gas used by
// each blob tx
Expand Down
8 changes: 4 additions & 4 deletions src/node/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ fn validate_bsc_gas_limit_against_parent<ChainSpec: BscHardforks>(
) -> Result<(), ConsensusError> {
// Keep parity with go-bsc's Parlia checks.
if header.gas_limit > GAS_LIMIT_CAPACITY {
return Err(ConsensusError::Other(format!(
return Err(ConsensusError::Other(Arc::new(std::io::Error::other(format!(
"invalid gasLimit: have {}, max {}",
header.gas_limit, GAS_LIMIT_CAPACITY
)));
)))));
}

if header.gas_used > header.gas_limit {
Expand All @@ -109,12 +109,12 @@ fn validate_bsc_gas_limit_against_parent<ChainSpec: BscHardforks>(
let limit = parent.gas_limit / bound_divisor;

if diff >= limit || header.gas_limit < MINIMUM_GAS_LIMIT {
return Err(ConsensusError::Other(format!(
return Err(ConsensusError::Other(Arc::new(std::io::Error::other(format!(
"invalid gas limit: have {}, want {} += {}",
header.gas_limit,
parent.gas_limit,
limit.saturating_sub(1)
)));
)))));
}

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions src/node/evm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
BscPrimitives,
};
use alloy_consensus::BlockHeader as _;
use alloy_evm::block::BlockExecutor;
use alloy_evm::block::{BlockExecutor, GasOutput};
use alloy_evm::eth::receipt_builder::ReceiptBuilder;
use alloy_primitives::BlockHash;
use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
Expand Down Expand Up @@ -95,13 +95,13 @@ where
&mut self,
tx: impl ExecutorTx<Self::Executor>,
f: impl FnOnce(&<Self::Executor as alloy_evm::block::BlockExecutor>::Result) -> alloy_evm::block::CommitChanges,
) -> Result<Option<u64>, BlockExecutionError> {
) -> Result<Option<GasOutput>, BlockExecutionError> {
let (tx_env, recovered) = tx.into_parts();
if let Some(gas_output) =
self.executor.execute_transaction_with_commit_condition((tx_env, &recovered), f)?
{
self.transactions.push(recovered);
Ok(Some(gas_output.tx_gas_used()))
Ok(Some(gas_output))
} else {
Ok(None)
}
Expand Down
15 changes: 9 additions & 6 deletions src/node/evm/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::{
assembler::BscBlockAssembler, builder::BscBlockBuilder, executor::BscBlockExecutor,
assembler::BscBlockAssembler, builder::BscBlockBuilder,
executor::{BscBlockExecutor, BscTxResult},
factory::BscEvmFactory,
};
use crate::{
Expand Down Expand Up @@ -230,23 +231,25 @@ where
BscTxEnv: IntoTxEnv<<EvmF as EvmFactory>::Tx>,
{
type EvmFactory = EvmF;
type TxExecutionResult = BscTxResult<<EvmF as EvmFactory>::HaltReason>;
type ExecutionCtx<'a> = BscBlockExecutionCtx<'a>;
type Transaction = TransactionSigned;
type Receipt = R::Receipt;
type Executor<'a, DB: alloy_evm::block::StateDB, I: Inspector<<Self::EvmFactory as EvmFactory>::Context<DB>>> =
BscBlockExecutor<'a, <EvmF as EvmFactory>::Evm<DB, I>, Spec, R>;

fn evm_factory(&self) -> &Self::EvmFactory {
&self.evm_factory
}

#[allow(refining_impl_trait)]
fn create_executor<'a, DB, I>(
&'a self,
evm: <Self::EvmFactory as EvmFactory>::Evm<DB, I>,
ctx: Self::ExecutionCtx<'a>,
) -> BscBlockExecutor<'a, <Self::EvmFactory as EvmFactory>::Evm<DB, I>, Spec, R>
) -> Self::Executor<'a, DB, I>
where
DB: alloy_evm::block::StateDB + 'a,
I: Inspector<<Self::EvmFactory as EvmFactory>::Context<DB>> + 'a,
DB: alloy_evm::block::StateDB,
I: Inspector<<Self::EvmFactory as EvmFactory>::Context<DB>>,
{
BscBlockExecutor::new(
evm,
Expand Down Expand Up @@ -474,7 +477,7 @@ where
ctx: <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'a>,
) -> impl BlockBuilder<
Primitives = Self::Primitives,
Executor: BlockExecutorFor<'a, Self::BlockExecutorFactory, &'a mut State<DB>, I>,
Executor = BlockExecutorFor<'a, Self::BlockExecutorFactory, &'a mut State<DB>, I>,
>
where
DB: Database,
Expand Down
23 changes: 16 additions & 7 deletions src/node/evm/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct BscTxResult<H> {
pub is_system: bool,
}

impl<H> TxResult for BscTxResult<H> {
impl<H: Send + 'static> TxResult for BscTxResult<H> {
type HaltReason = H;

fn result(&self) -> &ResultAndState<H> {
Expand Down Expand Up @@ -124,12 +124,14 @@ where
pub(super) executor_metrics: BscExecutorMetrics,
/// Rewards metrics for tracking reward distributions.
pub(super) rewards_metrics: BscRewardsMetrics,
/// Deferred error from commit_transaction (e.g. hertz patch), returned from finish().
pub(super) deferred_error: Option<BlockExecutionError>,
}

impl<'a, EVM, Spec, R: ReceiptBuilder> BscBlockExecutor<'a, EVM, Spec, R>
where
EVM: Evm<
DB: alloy_evm::block::StateDB + 'a,
DB: alloy_evm::block::StateDB,
Tx: FromRecoveredTx<R::Transaction>
+ FromRecoveredTx<TransactionSigned>
+ FromTxWithEncoded<TransactionSigned>,
Expand Down Expand Up @@ -199,6 +201,7 @@ where
vote_metrics: BscVoteMetrics::default(),
executor_metrics: BscExecutorMetrics::default(),
rewards_metrics: BscRewardsMetrics::default(),
deferred_error: None,
}
}

Expand Down Expand Up @@ -385,7 +388,7 @@ where
impl<'a, E, Spec, R> BlockExecutor for BscBlockExecutor<'a, E, Spec, R>
where
E: Evm<
DB: alloy_evm::block::StateDB + 'a,
DB: alloy_evm::block::StateDB,
Tx: FromRecoveredTx<R::Transaction>
+ FromRecoveredTx<TransactionSigned>
+ FromTxWithEncoded<TransactionSigned>,
Expand Down Expand Up @@ -549,9 +552,9 @@ where
fn commit_transaction(
&mut self,
output: BscTxResult<E::HaltReason>,
) -> Result<GasOutput, BlockExecutionError> {
) -> GasOutput {
if output.is_system {
return Ok(GasOutput::new(0));
return GasOutput::new(0);
}

let ResultAndState { result, state } = output.inner;
Expand All @@ -576,16 +579,22 @@ where
self.evm.db_mut().commit(state);

// Apply hertz patch after tx (validation only, not mining).
// commit_transaction cannot return errors in the new API, so defer any error to finish().
if !self.ctx.is_miner {
self.hertz_patch_manager.patch_after_tx(&output.tx, self.evm.db_mut())?;
if let Err(e) = self.hertz_patch_manager.patch_after_tx(&output.tx, self.evm.db_mut()) {
self.deferred_error = Some(e);
}
}

Ok(GasOutput::new(gas_used))
GasOutput::new(gas_used)
}

fn finish(
mut self,
) -> Result<(Self::Evm, BlockExecutionResult<R::Receipt>), BlockExecutionError> {
if let Some(err) = self.deferred_error.take() {
return Err(err);
}
let block_env = self.evm.block().clone();
debug!(
target: "bsc::executor",
Expand Down
2 changes: 1 addition & 1 deletion src/node/evm/post_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn turn_length_matches(turn_length_from_header: Option<u8>, expected_turn_length
impl<'a, EVM, Spec, R: ReceiptBuilder> BscBlockExecutor<'a, EVM, Spec, R>
where
EVM: Evm<
DB: alloy_evm::block::StateDB + 'a,
DB: alloy_evm::block::StateDB,
Tx: FromRecoveredTx<R::Transaction>
+ FromRecoveredTx<TransactionSigned>
+ FromTxWithEncoded<TransactionSigned>,
Expand Down
Loading
Loading