-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ExecutionInfo and ExecutedPayload Refactoring
- Loading branch information
Showing
3 changed files
with
75 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use alloy_consensus::Transaction; | ||
use alloy_primitives::private::alloy_rlp::Encodable; | ||
use alloy_primitives::{Address, B256, U256}; | ||
use reth_primitives_traits::NodePrimitives; | ||
|
||
/// Holds the state after execution | ||
#[derive(Debug)] | ||
pub struct ExecutedPayload<N: NodePrimitives> { | ||
/// Tracked execution info | ||
pub info: ExecutionInfo<N>, | ||
/// Withdrawal hash. | ||
pub withdrawals_root: Option<B256>, | ||
} | ||
|
||
/// This acts as the container for executed transactions and its byproducts (receipts, gas used) | ||
#[derive(Default, Debug)] | ||
pub struct ExecutionInfo<N: NodePrimitives> { | ||
/// All executed transactions (unrecovered). | ||
pub executed_transactions: Vec<N::SignedTx>, | ||
/// The recovered senders for the executed transactions. | ||
pub executed_senders: Vec<Address>, | ||
/// The transaction receipts | ||
pub receipts: Vec<N::Receipt>, | ||
/// All gas used so far | ||
pub cumulative_gas_used: u64, | ||
/// Estimated DA size | ||
pub cumulative_da_bytes_used: u64, | ||
/// Tracks fees from executed mempool transactions | ||
pub total_fees: U256, | ||
} | ||
|
||
impl<N: NodePrimitives> ExecutionInfo<N> { | ||
/// Create a new instance with allocated slots. | ||
pub fn with_capacity(capacity: usize) -> Self { | ||
Self { | ||
executed_transactions: Vec::with_capacity(capacity), | ||
executed_senders: Vec::with_capacity(capacity), | ||
receipts: Vec::with_capacity(capacity), | ||
cumulative_gas_used: 0, | ||
cumulative_da_bytes_used: 0, | ||
total_fees: U256::ZERO, | ||
} | ||
} | ||
|
||
/// Returns true if the transaction would exceed the block limits: | ||
/// - block gas limit: ensures the transaction still fits into the block. | ||
/// - tx DA limit: if configured, ensures the tx does not exceed the maximum allowed DA limit | ||
/// per tx. | ||
/// - block DA limit: if configured, ensures the transaction's DA size does not exceed the | ||
/// maximum allowed DA limit per block. | ||
pub fn is_tx_over_limits( | ||
&self, | ||
tx: &N::SignedTx, | ||
block_gas_limit: u64, | ||
tx_data_limit: Option<u64>, | ||
block_data_limit: Option<u64>, | ||
) -> bool { | ||
if tx_data_limit.is_some_and(|da_limit| tx.length() as u64 > da_limit) { | ||
return true; | ||
} | ||
|
||
if block_data_limit | ||
.is_some_and(|da_limit| self.cumulative_da_bytes_used + (tx.length() as u64) > da_limit) | ||
{ | ||
return true; | ||
} | ||
|
||
self.cumulative_gas_used + tx.gas_limit() > block_gas_limit | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
//! This module contains types from the reth that weren't heavily modified | ||
mod execution; | ||
mod payload_builder_service; | ||
|
||
pub use payload_builder_service::PayloadBuilderService; | ||
|
||
pub use execution::{ExecutedPayload, ExecutionInfo}; |