feat: update revm 19 alloy 09 (#13594)

This commit is contained in:
Matthias Seitz
2024-12-30 19:49:39 +01:00
committed by GitHub
parent a6325c41e0
commit 0b135a2670
54 changed files with 273 additions and 341 deletions

View File

@ -279,11 +279,7 @@ where
payload,
ExecutionPayloadSidecar::v4(
CancunPayloadFields { versioned_hashes, parent_beacon_block_root },
PraguePayloadFields {
requests: RequestsOrHash::Requests(execution_requests),
// TODO: add as an argument and handle in `try_into_block`
target_blobs_per_block: 0,
},
PraguePayloadFields { requests: RequestsOrHash::Requests(execution_requests) },
),
)
.await

View File

@ -1,7 +1,7 @@
//! `eth_` Extension traits.
use alloy_primitives::{Bytes, B256};
use alloy_rpc_types_eth::erc4337::ConditionalOptions;
use alloy_rpc_types_eth::erc4337::TransactionConditional;
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
/// Extension trait for `eth_` namespace for L2s.
@ -13,6 +13,6 @@ pub trait L2EthApiExt {
async fn send_raw_transaction_conditional(
&self,
bytes: Bytes,
condition: ConditionalOptions,
condition: TransactionConditional,
) -> RpcResult<B256>;
}

View File

@ -1,6 +1,7 @@
//! Loads fee history from database. Helper trait for `eth_` fee and transaction RPC methods.
use alloy_consensus::BlockHeader;
use alloy_eips::eip7840::BlobParams;
use alloy_primitives::U256;
use alloy_rpc_types_eth::{BlockNumberOrTag, FeeHistory};
use futures::Future;
@ -166,7 +167,7 @@ pub trait EthFees: LoadFee {
for header in &headers {
base_fee_per_gas.push(header.base_fee_per_gas().unwrap_or_default() as u128);
gas_used_ratio.push(header.gas_used() as f64 / header.gas_limit() as f64);
base_fee_per_blob_gas.push(header.blob_fee().unwrap_or_default());
base_fee_per_blob_gas.push(header.blob_fee(BlobParams::cancun()).unwrap_or_default());
blob_gas_used_ratio.push(
header.blob_gas_used().unwrap_or_default() as f64
/ alloy_eips::eip4844::MAX_DATA_GAS_PER_BLOCK as f64,
@ -207,7 +208,7 @@ pub trait EthFees: LoadFee {
// Same goes for the `base_fee_per_blob_gas`:
// > "[..] includes the next block after the newest of the returned range, because this value can be derived from the newest block.
base_fee_per_blob_gas.push(last_header.next_block_blob_fee().unwrap_or_default());
base_fee_per_blob_gas.push(last_header.next_block_blob_fee(BlobParams::cancun()).unwrap_or_default());
};
Ok(FeeHistory {
@ -332,7 +333,7 @@ pub trait LoadFee: LoadBlock {
async move {
self.block_with_senders(BlockNumberOrTag::Latest.into())
.await?
.and_then(|h| h.next_block_blob_fee())
.and_then(|h| h.next_block_blob_fee(BlobParams::cancun()))
.ok_or(EthApiError::ExcessBlobGasNotSet.into())
.map(U256::from)
}

View File

@ -408,10 +408,8 @@ pub enum RpcInvalidTransactionError {
#[error("blob transaction missing blob hashes")]
BlobTransactionMissingBlobHashes,
/// Blob transaction has too many blobs
#[error("blob transaction exceeds max blobs per block; got {have}, max {max}")]
#[error("blob transaction exceeds max blobs per block; got {have}")]
TooManyBlobs {
/// The maximum number of blobs allowed.
max: usize,
/// The number of blobs in the transaction.
have: usize,
},
@ -522,7 +520,7 @@ impl From<revm::primitives::InvalidTransaction> for RpcInvalidTransactionError {
InvalidTransaction::BlobGasPriceGreaterThanMax => Self::BlobFeeCapTooLow,
InvalidTransaction::EmptyBlobs => Self::BlobTransactionMissingBlobHashes,
InvalidTransaction::BlobVersionNotSupported => Self::BlobHashVersionMismatch,
InvalidTransaction::TooManyBlobs { max, have } => Self::TooManyBlobs { max, have },
InvalidTransaction::TooManyBlobs { have } => Self::TooManyBlobs { have },
InvalidTransaction::BlobCreateTransaction => Self::BlobTransactionIsCreate,
InvalidTransaction::EofCrateShouldHaveToAddress => Self::EofCrateShouldHaveToAddress,
InvalidTransaction::AuthorizationListNotSupported => {

View File

@ -21,7 +21,6 @@ use reth_primitives::{NodePrimitives, SealedBlock};
use reth_primitives_traits::BlockBody;
use reth_rpc_server_types::constants::gas_oracle::MAX_HEADER_HISTORY;
use reth_storage_api::BlockReaderIdExt;
use revm_primitives::{calc_blob_gasprice, calc_excess_blob_gas};
use serde::{Deserialize, Serialize};
use tracing::trace;
@ -294,7 +293,7 @@ where
*previous_gas = receipt.cumulative_gas_used();
Some(TxGasAndReward {
gas_used: gas_used as u64,
gas_used,
reward: tx.effective_tip_per_gas(base_fee_per_gas).unwrap_or_default(),
})
})
@ -368,7 +367,9 @@ impl FeeHistoryEntry {
Self {
base_fee_per_gas: block.base_fee_per_gas().unwrap_or_default(),
gas_used_ratio: block.gas_used() as f64 / block.gas_limit() as f64,
base_fee_per_blob_gas: block.excess_blob_gas().map(calc_blob_gasprice),
base_fee_per_blob_gas: block
.excess_blob_gas()
.map(alloy_eips::eip4844::calc_blob_gasprice),
blob_gas_used_ratio: block.body.blob_gas_used() as f64 /
alloy_eips::eip4844::MAX_DATA_GAS_PER_BLOCK as f64,
excess_blob_gas: block.excess_blob_gas(),
@ -397,13 +398,13 @@ impl FeeHistoryEntry {
///
/// See also [`Self::next_block_excess_blob_gas`]
pub fn next_block_blob_fee(&self) -> Option<u128> {
self.next_block_excess_blob_gas().map(calc_blob_gasprice)
self.next_block_excess_blob_gas().map(alloy_eips::eip4844::calc_blob_gasprice)
}
/// Calculate excess blob gas for the next block according to the EIP-4844 spec.
///
/// Returns a `None` if no excess blob gas is set, no EIP-4844 support
pub fn next_block_excess_blob_gas(&self) -> Option<u64> {
Some(calc_excess_blob_gas(self.excess_blob_gas?, self.blob_gas_used?))
Some(alloy_eips::eip4844::calc_excess_blob_gas(self.excess_blob_gas?, self.blob_gas_used?))
}
}

View File

@ -6,7 +6,6 @@ use alloy_primitives::{Address, TxKind};
use alloy_rpc_types_eth::{Log, ReceiptWithBloom, TransactionReceipt};
use reth_primitives::{Receipt, TransactionMeta, TransactionSigned, TxType};
use reth_primitives_traits::SignedTransaction;
use revm_primitives::calc_blob_gasprice;
/// Builds an [`TransactionReceipt`] obtaining the inner receipt envelope from the given closure.
pub fn build_receipt<R, T, E>(
@ -38,7 +37,8 @@ where
let blob_gas_used = transaction.blob_gas_used();
// Blob gas price should only be present if the transaction is a blob transaction
let blob_gas_price = blob_gas_used.and_then(|_| meta.excess_blob_gas.map(calc_blob_gasprice));
let blob_gas_price = blob_gas_used
.and_then(|_| meta.excess_blob_gas.map(alloy_eips::eip4844::calc_blob_gasprice));
let logs_bloom = receipt.bloom();
// get number of logs in the block
@ -87,7 +87,7 @@ where
effective_gas_price: transaction.effective_gas_price(meta.base_fee),
// EIP-4844 fields
blob_gas_price,
blob_gas_used: blob_gas_used.map(u128::from),
blob_gas_used,
authorization_list: transaction.authorization_list().map(|l| l.to_vec()),
})
}

View File

@ -86,7 +86,6 @@ pub fn try_payload_v1_to_block<T: Decodable2718>(
ommers_hash: EMPTY_OMMER_ROOT_HASH,
difficulty: Default::default(),
nonce: Default::default(),
target_blobs_per_block: None,
};
Ok(Block { header, body: BlockBody { transactions, ..Default::default() } })
@ -132,14 +131,9 @@ pub fn block_to_payload<T: SignedTransaction>(
None
};
let prague = if let Some(requests_hash) = value.requests_hash {
Some(PraguePayloadFields {
requests: RequestsOrHash::Hash(requests_hash),
target_blobs_per_block: value.target_blobs_per_block.unwrap_or_default(),
})
} else {
None
};
let prague = value
.requests_hash
.map(|requests_hash| PraguePayloadFields { requests: RequestsOrHash::Hash(requests_hash) });
let sidecar = match (cancun, prague) {
(Some(cancun), Some(prague)) => ExecutionPayloadSidecar::v4(cancun, prague),

View File

@ -1,6 +1,7 @@
//! `Eth` bundle implementation and helpers.
use alloy_consensus::{BlockHeader, Transaction as _};
use alloy_eips::eip4844::MAX_DATA_GAS_PER_BLOCK;
use alloy_primitives::{Keccak256, U256};
use alloy_rpc_types_mev::{EthCallBundle, EthCallBundleResponse, EthCallBundleTransactionResult};
use jsonrpsee::core::RpcResult;
@ -22,7 +23,7 @@ use revm::{
db::{CacheDB, DatabaseCommit, DatabaseRef},
primitives::{ResultAndState, TxEnv},
};
use revm_primitives::{EnvKzgSettings, EnvWithHandlerCfg, SpecId, MAX_BLOB_GAS_PER_BLOCK};
use revm_primitives::{EnvKzgSettings, EnvWithHandlerCfg, SpecId};
use std::sync::Arc;
/// `Eth` bundle implementation.
@ -90,7 +91,7 @@ where
// Validate that the bundle does not contain more than MAX_BLOB_NUMBER_PER_BLOCK blob
// transactions.
if transactions.iter().filter_map(|tx| tx.blob_gas_used()).sum::<u64>() >
MAX_BLOB_GAS_PER_BLOCK
MAX_DATA_GAS_PER_BLOCK
{
return Err(EthApiError::InvalidParams(
EthBundleError::Eip4844BlobGasExceeded.to_string(),
@ -317,8 +318,7 @@ pub enum EthBundleError {
/// Thrown if the bundle does not contain a block number, or block number is 0.
#[error("bundle missing blockNumber")]
BundleMissingBlockNumber,
/// Thrown when the blob gas usage of the blob transactions in a bundle exceed
/// [`MAX_BLOB_GAS_PER_BLOCK`].
#[error("blob gas usage exceeds the limit of {MAX_BLOB_GAS_PER_BLOCK} gas per block.")]
/// Thrown when the blob gas usage of the blob transactions in a bundle exceed the maximum.
#[error("blob gas usage exceeds the limit of {MAX_DATA_GAS_PER_BLOCK} gas per block.")]
Eip4844BlobGasExceeded,
}

View File

@ -97,7 +97,6 @@ where
extra_data: Default::default(),
parent_beacon_block_root: is_cancun.then_some(B256::ZERO),
requests_hash: is_prague.then_some(EMPTY_REQUESTS_HASH),
target_blobs_per_block: None,
};
// seal the block

View File

@ -109,7 +109,6 @@ where
TxEip4844Variant::TxEip4844WithSidecar(tx) => &mut tx.tx.input,
},
TxEnvelope::Eip7702(tx) => &mut tx.tx_mut().input,
_ => return,
};
*input = input.slice(..4);
}

View File

@ -53,7 +53,9 @@ where
// blob fee is burnt, so we don't need to calculate it
let total_fees = receipts
.iter()
.map(|receipt| receipt.gas_used().saturating_mul(receipt.effective_gas_price()))
.map(|receipt| {
(receipt.gas_used() as u128).saturating_mul(receipt.effective_gas_price())
})
.sum::<u128>();
Ok(BlockDetails::new(block, Default::default(), U256::from(total_fees)))
@ -256,7 +258,7 @@ where
.map(|(receipt, tx_ty)| {
let inner = OtsReceipt {
status: receipt.status(),
cumulative_gas_used: receipt.cumulative_gas_used() as u64,
cumulative_gas_used: receipt.cumulative_gas_used(),
logs: None,
logs_bloom: None,
r#type: tx_ty,

View File

@ -108,7 +108,7 @@ where
TxpoolInspectSummary {
to: tx.to(),
value: tx.value(),
gas: tx.gas_limit() as u128,
gas: tx.gas_limit(),
gas_price: tx.max_fee_per_gas(),
},
);

View File

@ -380,7 +380,6 @@ where
requests: RequestsOrHash::Requests(
request.request.execution_requests.to_requests(),
),
target_blobs_per_block: request.request.target_blobs_per_block,
},
),
)?