mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: OP: keep encoded txs in payload attributes (#9467)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -319,7 +319,7 @@ where
|
||||
}
|
||||
|
||||
// A sequencer's block should never contain blob transactions.
|
||||
if sequencer_tx.is_eip4844() {
|
||||
if sequencer_tx.value().is_eip4844() {
|
||||
return Err(PayloadBuilderError::other(
|
||||
OptimismPayloadBuilderError::BlobTransactionRejected,
|
||||
))
|
||||
@ -329,7 +329,7 @@ where
|
||||
// purely for the purposes of utilizing the `evm_config.tx_env`` function.
|
||||
// Deposit transactions do not have signatures, so if the tx is a deposit, this
|
||||
// will just pull in its `from` address.
|
||||
let sequencer_tx = sequencer_tx.clone().try_into_ecrecovered().map_err(|_| {
|
||||
let sequencer_tx = sequencer_tx.value().clone().try_into_ecrecovered().map_err(|_| {
|
||||
PayloadBuilderError::other(OptimismPayloadBuilderError::TransactionEcRecoverFailed)
|
||||
})?;
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ use reth_payload_builder::EthPayloadBuilderAttributes;
|
||||
use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes};
|
||||
use reth_primitives::{
|
||||
revm_primitives::{BlobExcessGasAndPrice, BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, SpecId},
|
||||
transaction::WithEncoded,
|
||||
Address, BlobTransactionSidecar, Header, SealedBlock, TransactionSigned, Withdrawals, B256,
|
||||
U256,
|
||||
};
|
||||
@ -33,8 +34,9 @@ pub struct OptimismPayloadBuilderAttributes {
|
||||
pub payload_attributes: EthPayloadBuilderAttributes,
|
||||
/// `NoTxPool` option for the generated payload
|
||||
pub no_tx_pool: bool,
|
||||
/// Transactions for the generated payload
|
||||
pub transactions: Vec<TransactionSigned>,
|
||||
/// Decoded transactions and the original EIP-2718 encoded bytes as received in the payload
|
||||
/// attributes.
|
||||
pub transactions: Vec<WithEncoded<TransactionSigned>>,
|
||||
/// The gas limit for the generated payload
|
||||
pub gas_limit: Option<u64>,
|
||||
}
|
||||
@ -47,16 +49,17 @@ impl PayloadBuilderAttributes for OptimismPayloadBuilderAttributes {
|
||||
///
|
||||
/// Derives the unique [`PayloadId`] for the given parent and attributes
|
||||
fn try_new(parent: B256, attributes: OptimismPayloadAttributes) -> Result<Self, Self::Error> {
|
||||
let (id, transactions) = {
|
||||
let transactions: Vec<_> = attributes
|
||||
.transactions
|
||||
.as_deref()
|
||||
.unwrap_or(&[])
|
||||
.iter()
|
||||
.map(|tx| TransactionSigned::decode_enveloped(&mut tx.as_ref()))
|
||||
.collect::<Result<_, _>>()?;
|
||||
(payload_id_optimism(&parent, &attributes, &transactions), transactions)
|
||||
};
|
||||
let id = payload_id_optimism(&parent, &attributes);
|
||||
|
||||
let transactions = attributes
|
||||
.transactions
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(|data| {
|
||||
TransactionSigned::decode_enveloped(&mut data.as_ref())
|
||||
.map(|tx| WithEncoded::new(data, tx))
|
||||
})
|
||||
.collect::<Result<_, _>>()?;
|
||||
|
||||
let payload_attributes = EthPayloadBuilderAttributes {
|
||||
id,
|
||||
@ -308,7 +311,6 @@ impl From<OptimismBuiltPayload> for OptimismExecutionPayloadEnvelopeV4 {
|
||||
pub(crate) fn payload_id_optimism(
|
||||
parent: &B256,
|
||||
attributes: &OptimismPayloadAttributes,
|
||||
txs: &[TransactionSigned],
|
||||
) -> PayloadId {
|
||||
use sha2::Digest;
|
||||
let mut hasher = sha2::Sha256::new();
|
||||
@ -327,10 +329,9 @@ pub(crate) fn payload_id_optimism(
|
||||
}
|
||||
|
||||
let no_tx_pool = attributes.no_tx_pool.unwrap_or_default();
|
||||
if no_tx_pool || !txs.is_empty() {
|
||||
hasher.update([no_tx_pool as u8]);
|
||||
hasher.update(txs.len().to_be_bytes());
|
||||
txs.iter().for_each(|tx| hasher.update(tx.hash()));
|
||||
hasher.update([no_tx_pool as u8]);
|
||||
if let Some(txs) = &attributes.transactions {
|
||||
txs.iter().for_each(|tx| hasher.update(tx));
|
||||
}
|
||||
|
||||
if let Some(gas_limit) = attributes.gas_limit {
|
||||
|
||||
@ -1695,6 +1695,60 @@ impl IntoRecoveredTransaction for TransactionSignedEcRecovered {
|
||||
}
|
||||
}
|
||||
|
||||
/// Generic wrapper with encoded Bytes, such as transaction data.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct WithEncoded<T>(Bytes, pub T);
|
||||
|
||||
impl<T> From<(Bytes, T)> for WithEncoded<T> {
|
||||
fn from(value: (Bytes, T)) -> Self {
|
||||
Self(value.0, value.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> WithEncoded<T> {
|
||||
/// Wraps the value with the bytes.
|
||||
pub const fn new(bytes: Bytes, value: T) -> Self {
|
||||
Self(bytes, value)
|
||||
}
|
||||
|
||||
/// Get the encoded bytes
|
||||
pub fn encoded_bytes(&self) -> Bytes {
|
||||
self.0.clone()
|
||||
}
|
||||
|
||||
/// Get the underlying value
|
||||
pub const fn value(&self) -> &T {
|
||||
&self.1
|
||||
}
|
||||
|
||||
/// Returns ownership of the underlying value.
|
||||
pub fn into_value(self) -> T {
|
||||
self.1
|
||||
}
|
||||
|
||||
/// Transform the value
|
||||
pub fn transform<F: From<T>>(self) -> WithEncoded<F> {
|
||||
WithEncoded(self.0, self.1.into())
|
||||
}
|
||||
|
||||
/// Split the wrapper into [`Bytes`] and value tuple
|
||||
pub fn split(self) -> (Bytes, T) {
|
||||
(self.0, self.1)
|
||||
}
|
||||
|
||||
/// Maps the inner value to a new value using the given function.
|
||||
pub fn map<U, F: FnOnce(T) -> U>(self, op: F) -> WithEncoded<U> {
|
||||
WithEncoded(self.0, op(self.1))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> WithEncoded<Option<T>> {
|
||||
/// returns `None` if the inner value is `None`, otherwise returns `Some(WithEncoded<T>)`.
|
||||
pub fn transpose(self) -> Option<WithEncoded<T>> {
|
||||
self.1.map(|v| WithEncoded(self.0, v))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{
|
||||
|
||||
Reference in New Issue
Block a user