Skip to content

Commit

Permalink
touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Feb 5, 2025
1 parent eecd005 commit e2af03d
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions crates/ethereum/payload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#![allow(clippy::useless_let_if_seq)]

use alloy_consensus::{BlockHeader, Header, Transaction, Typed2718, EMPTY_OMMER_ROOT_HASH};
use alloy_eips::{eip6110, eip7685::Requests, eip7840::BlobParams, merge::BEACON_NONCE};
use alloy_eips::{eip4844::DATA_GAS_PER_BLOB, eip6110, eip7685::Requests, merge::BEACON_NONCE};
use alloy_primitives::U256;
use reth_basic_payload_builder::{
commit_withdrawals, is_better_payload, BuildArguments, BuildOutcome, PayloadBuilder,
Expand Down Expand Up @@ -50,6 +50,7 @@ use tracing::{debug, trace, warn};

mod config;
pub use config::*;
use reth_transaction_pool::error::Eip4844PoolTransactionError;

type BestTransactionsIter<Pool> = Box<
dyn BestTransactions<Item = Arc<ValidPoolTransaction<<Pool as TransactionPool>::Transaction>>>,
Expand Down Expand Up @@ -183,7 +184,6 @@ where

debug!(target: "payload_builder", id=%attributes.id, parent_header = ?parent_header.hash(), parent_number = parent_header.number, "building new payload");
let mut cumulative_gas_used = 0;
let mut sum_blob_gas_used = 0;
let block_gas_limit: u64 = evm_env.block_env.gas_limit.to::<u64>();
let base_fee = evm_env.block_env.basefee.to::<u64>();

Expand Down Expand Up @@ -226,7 +226,11 @@ where
let mut evm = evm_config.evm_with_env(&mut db, evm_env);

let mut receipts = Vec::new();
let mut block_blob_txn_count = 0;
let mut block_blob_count = 0;
let blob_params = chain_spec.blob_params_at_timestamp(attributes.timestamp);
let max_blob_count =
blob_params.as_ref().map(|params| params.max_blob_count).unwrap_or_default();

while let Some(pool_tx) = best_txs.next() {
// ensure we still have capacity for this transaction
if cumulative_gas_used + pool_tx.gas_limit() > block_gas_limit {
Expand All @@ -252,25 +256,24 @@ where
// the EIP-4844 can still fit in the block
if let Some(blob_tx) = tx.as_eip4844() {
let tx_blob_count = blob_tx.blob_versioned_hashes.len() as u64;
if block_blob_txn_count + tx_blob_count > BlobParams::cancun().max_blob_count {

if block_blob_count + tx_blob_count > max_blob_count {
// we can't fit this _blob_ transaction into the block, so we mark it as
// invalid, which removes its dependent transactions from
// the iterator. This is similar to the gas limit condition
// for regular transactions above.
trace!(target: "payload_builder", tx=?tx.hash(), ?block_blob_txn_count, "skipping blob transaction because it would exceed the max blob count per block");
trace!(target: "payload_builder", tx=?tx.hash(), ?block_blob_count, "skipping blob transaction because it would exceed the max blob count per block");
best_txs.mark_invalid(
&pool_tx,
InvalidPoolTransactionError::ExceedsGasLimit(
block_blob_txn_count + tx_blob_count,
chain_spec
.blob_params_at_timestamp(attributes.timestamp)
.unwrap()
.max_blob_count,
InvalidPoolTransactionError::Eip4844(
Eip4844PoolTransactionError::TooManyEip4844Blobs {
have: (block_blob_count + tx_blob_count) as usize,
permitted: max_blob_count as usize,
},
),
);
continue
}
block_blob_txn_count += tx_blob_count;
}

// Configure the environment for the tx.
Expand Down Expand Up @@ -306,11 +309,10 @@ where

// add to the total blob gas used if the transaction successfully executed
if let Some(blob_tx) = tx.as_eip4844() {
let tx_blob_gas = blob_tx.blob_gas();
sum_blob_gas_used += tx_blob_gas;
block_blob_count += blob_tx.blob_versioned_hashes.len() as u64;

// if we've reached the max block count, we can skip blob txs entirely
if block_blob_txn_count == BlobParams::cancun().max_blob_count {
if block_blob_count == max_blob_count {
best_txs.skip_blobs();
}
}
Expand Down Expand Up @@ -421,16 +423,14 @@ where
.map_err(PayloadBuilderError::other)?;

excess_blob_gas = if chain_spec.is_cancun_active_at_timestamp(parent_header.timestamp) {
parent_header.maybe_next_block_excess_blob_gas(
chain_spec.blob_params_at_timestamp(attributes.timestamp),
)
parent_header.maybe_next_block_excess_blob_gas(blob_params)
} else {
// for the first post-fork block, both parent.blob_gas_used and
// parent.excess_blob_gas are evaluated as 0
Some(alloy_eips::eip7840::BlobParams::cancun().next_block_excess_blob_gas(0, 0))
};

blob_gas_used = Some(sum_blob_gas_used);
blob_gas_used = Some(block_blob_count * DATA_GAS_PER_BLOB);
}

let header = Header {
Expand Down

0 comments on commit e2af03d

Please sign in to comment.