feat: use reth-ethereum-primitives (#13830)

This commit is contained in:
Arsenii Kulikov
2025-01-17 04:22:21 +04:00
committed by GitHub
parent 7e972ea23d
commit 8efe441cc0
67 changed files with 941 additions and 3025 deletions

View File

@ -83,7 +83,6 @@ optimism = [
"alloy-consensus",
"dep:derive_more",
"dep:serde",
"reth-primitives/optimism",
"reth-optimism-evm/optimism",
"reth-provider/optimism",
"reth-node-core/optimism",

View File

@ -1,6 +1,6 @@
use alloy_consensus::{
transaction::{from_eip155_value, RlpEcdsaTx},
Header, TxEip1559, TxEip2930, TxEip4844, TxEip7702, TxLegacy,
Header, TxEip1559, TxEip2930, TxEip7702, TxLegacy,
};
use alloy_eips::{
eip2718::{Decodable2718, Eip2718Error, Eip2718Result, Encodable2718},
@ -12,9 +12,8 @@ use alloy_primitives::{
};
use alloy_rlp::{Decodable, Error as RlpError, RlpDecodable};
use derive_more::{AsRef, Deref};
use op_alloy_consensus::TxDeposit;
use op_alloy_consensus::{OpTxType, OpTypedTransaction, TxDeposit};
use reth_downloaders::file_client::FileClientError;
use reth_primitives::transaction::{Transaction, TxType};
use serde::{Deserialize, Serialize};
use tokio_util::codec::Decoder;
@ -83,17 +82,7 @@ pub struct TransactionSigned {
/// Raw transaction info
#[deref]
#[as_ref]
pub transaction: Transaction,
}
impl Default for TransactionSigned {
fn default() -> Self {
Self {
hash: Default::default(),
signature: Signature::test_signature(),
transaction: Default::default(),
}
}
pub transaction: OpTypedTransaction,
}
impl AsRef<Self> for TransactionSigned {
@ -113,7 +102,10 @@ impl TransactionSigned {
/// Create a new signed transaction from a transaction and its signature.
///
/// This will also calculate the transaction hash using its encoding.
pub fn from_transaction_and_signature(transaction: Transaction, signature: Signature) -> Self {
pub fn from_transaction_and_signature(
transaction: OpTypedTransaction,
signature: Signature,
) -> Self {
let mut initial_tx = Self { transaction, hash: Default::default(), signature };
initial_tx.hash = initial_tx.recalculate_hash();
initial_tx
@ -190,7 +182,7 @@ impl TransactionSigned {
// so decoding methods do not need to manually advance the buffer
pub fn decode_rlp_legacy_transaction(data: &mut &[u8]) -> alloy_rlp::Result<Self> {
let (transaction, hash, signature) = Self::decode_rlp_legacy_transaction_tuple(data)?;
let signed = Self { transaction: Transaction::Legacy(transaction), hash, signature };
let signed = Self { transaction: OpTypedTransaction::Legacy(transaction), hash, signature };
Ok(signed)
}
}
@ -229,55 +221,58 @@ impl Decodable for TransactionSigned {
impl Encodable2718 for TransactionSigned {
fn type_flag(&self) -> Option<u8> {
match self.transaction.tx_type() {
TxType::Legacy => None,
OpTxType::Legacy => None,
tx_type => Some(tx_type as u8),
}
}
fn encode_2718_len(&self) -> usize {
match &self.transaction {
Transaction::Legacy(legacy_tx) => legacy_tx.eip2718_encoded_length(&self.signature),
Transaction::Eip2930(access_list_tx) => {
OpTypedTransaction::Legacy(legacy_tx) => {
legacy_tx.eip2718_encoded_length(&self.signature)
}
OpTypedTransaction::Eip2930(access_list_tx) => {
access_list_tx.eip2718_encoded_length(&self.signature)
}
Transaction::Eip1559(dynamic_fee_tx) => {
OpTypedTransaction::Eip1559(dynamic_fee_tx) => {
dynamic_fee_tx.eip2718_encoded_length(&self.signature)
}
Transaction::Eip4844(blob_tx) => blob_tx.eip2718_encoded_length(&self.signature),
Transaction::Eip7702(set_code_tx) => {
OpTypedTransaction::Eip7702(set_code_tx) => {
set_code_tx.eip2718_encoded_length(&self.signature)
}
Transaction::Deposit(deposit_tx) => deposit_tx.eip2718_encoded_length(),
OpTypedTransaction::Deposit(deposit_tx) => deposit_tx.eip2718_encoded_length(),
}
}
fn encode_2718(&self, out: &mut dyn alloy_rlp::BufMut) {
self.transaction.eip2718_encode(&self.signature, out)
match &self.transaction {
OpTypedTransaction::Legacy(tx) => tx.eip2718_encode(&self.signature, out),
OpTypedTransaction::Eip2930(tx) => tx.eip2718_encode(&self.signature, out),
OpTypedTransaction::Eip1559(tx) => tx.eip2718_encode(&self.signature, out),
OpTypedTransaction::Eip7702(tx) => tx.eip2718_encode(&self.signature, out),
OpTypedTransaction::Deposit(tx) => tx.encode_2718(out),
}
}
}
impl Decodable2718 for TransactionSigned {
fn typed_decode(ty: u8, buf: &mut &[u8]) -> Eip2718Result<Self> {
match ty.try_into().map_err(|_| Eip2718Error::UnexpectedType(ty))? {
TxType::Legacy => Err(Eip2718Error::UnexpectedType(0)),
TxType::Eip2930 => {
OpTxType::Legacy => Err(Eip2718Error::UnexpectedType(0)),
OpTxType::Eip2930 => {
let (tx, signature, hash) = TxEip2930::rlp_decode_signed(buf)?.into_parts();
Ok(Self { transaction: Transaction::Eip2930(tx), signature, hash })
Ok(Self { transaction: OpTypedTransaction::Eip2930(tx), signature, hash })
}
TxType::Eip1559 => {
OpTxType::Eip1559 => {
let (tx, signature, hash) = TxEip1559::rlp_decode_signed(buf)?.into_parts();
Ok(Self { transaction: Transaction::Eip1559(tx), signature, hash })
Ok(Self { transaction: OpTypedTransaction::Eip1559(tx), signature, hash })
}
TxType::Eip7702 => {
OpTxType::Eip7702 => {
let (tx, signature, hash) = TxEip7702::rlp_decode_signed(buf)?.into_parts();
Ok(Self { transaction: Transaction::Eip7702(tx), signature, hash })
Ok(Self { transaction: OpTypedTransaction::Eip7702(tx), signature, hash })
}
TxType::Eip4844 => {
let (tx, signature, hash) = TxEip4844::rlp_decode_signed(buf)?.into_parts();
Ok(Self { transaction: Transaction::Eip4844(tx), signature, hash })
}
TxType::Deposit => Ok(Self::from_transaction_and_signature(
Transaction::Deposit(TxDeposit::rlp_decode(buf)?),
OpTxType::Deposit => Ok(Self::from_transaction_and_signature(
OpTypedTransaction::Deposit(TxDeposit::rlp_decode(buf)?),
TxDeposit::signature(),
)),
}
@ -291,8 +286,9 @@ impl Decodable2718 for TransactionSigned {
#[cfg(test)]
mod tests {
use crate::ovm_file_codec::TransactionSigned;
use alloy_consensus::Typed2718;
use alloy_primitives::{address, hex, TxKind, B256, U256};
use reth_primitives::transaction::Transaction;
use op_alloy_consensus::OpTypedTransaction;
const DEPOSIT_FUNCTION_SELECTOR: [u8; 4] = [0xb6, 0xb5, 0x5f, 0x25];
use alloy_rlp::Decodable;
@ -305,7 +301,7 @@ mod tests {
// Verify deposit transaction
let deposit_tx = match &deposit_decoded.transaction {
Transaction::Legacy(ref tx) => tx,
OpTypedTransaction::Legacy(ref tx) => tx,
_ => panic!("Expected legacy transaction for NFT deposit"),
};
@ -345,7 +341,7 @@ mod tests {
assert!(system_decoded.is_legacy());
let system_tx = match &system_decoded.transaction {
Transaction::Legacy(ref tx) => tx,
OpTypedTransaction::Legacy(ref tx) => tx,
_ => panic!("Expected Legacy transaction"),
};

View File

@ -5,9 +5,9 @@ use alloy_primitives::{
Address, Bloom, Bytes, B256,
};
use alloy_rlp::{Decodable, RlpDecodable};
use op_alloy_consensus::OpDepositReceipt;
use op_alloy_consensus::{OpDepositReceipt, OpTxType};
use reth_optimism_primitives::OpReceipt;
use reth_primitives::{Log, Receipt, TxType};
use reth_primitives::{Log, Receipt};
use tokio_util::codec::Decoder;
use reth_downloaders::{file_client::FileClientError, receipt_file_client::ReceiptWithBlockNumber};
@ -92,49 +92,27 @@ pub struct OpGethReceipt {
#[rlp(trailing)]
struct OpGethReceiptContainer(Option<OpGethReceipt>);
impl TryFrom<OpGethReceipt> for Receipt {
type Error = &'static str;
impl TryFrom<OpGethReceipt> for OpReceipt {
type Error = FileClientError;
fn try_from(exported_receipt: OpGethReceipt) -> Result<Self, Self::Error> {
let OpGethReceipt { tx_type, status, cumulative_gas_used, logs, .. } = exported_receipt;
#[allow(clippy::needless_update)]
Ok(Self {
tx_type: TxType::try_from(tx_type.to_be_bytes()[0])?,
success: status != 0,
cumulative_gas_used,
logs,
..Default::default()
})
}
}
impl TryFrom<OpGethReceipt> for OpReceipt {
type Error = &'static str;
fn try_from(exported_receipt: OpGethReceipt) -> Result<Self, Self::Error> {
let Receipt {
tx_type,
success,
cumulative_gas_used,
logs,
deposit_nonce,
deposit_receipt_version,
} = exported_receipt.try_into()?;
let tx_type = OpTxType::try_from(tx_type.to_be_bytes()[0])
.map_err(|e| FileClientError::Rlp(e.into(), vec![tx_type]))?;
let receipt =
alloy_consensus::Receipt { status: success.into(), cumulative_gas_used, logs };
alloy_consensus::Receipt { status: (status != 0).into(), cumulative_gas_used, logs };
match tx_type {
TxType::Legacy => Ok(Self::Legacy(receipt)),
TxType::Eip2930 => Ok(Self::Eip2930(receipt)),
TxType::Eip1559 => Ok(Self::Eip1559(receipt)),
TxType::Eip7702 => Ok(Self::Eip7702(receipt)),
TxType::Eip4844 => Err("EIP-4844 receipts are not supported for OP"),
TxType::Deposit => Ok(Self::Deposit(OpDepositReceipt {
OpTxType::Legacy => Ok(Self::Legacy(receipt)),
OpTxType::Eip2930 => Ok(Self::Eip2930(receipt)),
OpTxType::Eip1559 => Ok(Self::Eip1559(receipt)),
OpTxType::Eip7702 => Ok(Self::Eip7702(receipt)),
OpTxType::Deposit => Ok(Self::Deposit(OpDepositReceipt {
inner: receipt,
deposit_nonce,
deposit_receipt_version,
deposit_nonce: None,
deposit_receipt_version: None,
})),
}
}
@ -142,6 +120,7 @@ impl TryFrom<OpGethReceipt> for OpReceipt {
#[cfg(test)]
pub(crate) mod test {
use alloy_consensus::{Receipt, TxReceipt};
use alloy_primitives::{hex, LogData};
use super::*;
@ -156,12 +135,12 @@ pub(crate) mod test {
let receipt = receipt_block_1();
OpGethReceipt {
tx_type: receipt.receipt.tx_type as u8,
tx_type: receipt.receipt.tx_type() as u8,
post_state: Bytes::default(),
status: receipt.receipt.success as u64,
cumulative_gas_used: receipt.receipt.cumulative_gas_used,
status: receipt.receipt.status() as u64,
cumulative_gas_used: receipt.receipt.cumulative_gas_used(),
bloom: Bloom::from(hex!("00000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000400000000000100000000000000200000000002000000000000001000000000000000000004000000000000000000000000000040000400000100400000000000000100000000000000000000000000000020000000000000000000000000000000000000000000000001000000000000000000000100000000000000000000000000000000000000000000000000000000000000088000000080000000000010000000000000000000000000000800008000120000000000000000000000000000000002000")),
logs: receipt.receipt.logs,
logs: receipt.receipt.logs().to_vec(),
tx_hash: B256::from(hex!("5e77a04531c7c107af1882d76cbff9486d0a9aa53701c30888509d4f5f2b003a")), contract_address: Address::from(hex!("0000000000000000000000000000000000000000")), gas_used: 202813,
block_hash: B256::from(hex!("bee7192e575af30420cae0c7776304ac196077ee72b048970549e4f08e875453")),
block_number: receipt.number,
@ -173,7 +152,7 @@ pub(crate) mod test {
}
}
pub(crate) fn receipt_block_1() -> ReceiptWithBlockNumber {
pub(crate) fn receipt_block_1() -> ReceiptWithBlockNumber<OpReceipt> {
let log_1 = Log {
address: Address::from(hex!("8ce8c13d816fe6daf12d6fd9e4952e1fc88850af")),
data: LogData::new(
@ -233,20 +212,16 @@ pub(crate) mod test {
.unwrap(),
};
let mut receipt = Receipt {
tx_type: TxType::Legacy,
success: true,
let receipt = OpReceipt::Legacy(Receipt {
status: true.into(),
cumulative_gas_used: 202813,
..Default::default()
};
// #[allow(clippy::needless_update)] not recognised, ..Default::default() needed so optimism
// feature must not be brought into scope
receipt.logs = vec![log_1, log_2, log_3];
logs: vec![log_1, log_2, log_3],
});
ReceiptWithBlockNumber { receipt, number: 1 }
}
pub(crate) fn receipt_block_2() -> ReceiptWithBlockNumber {
pub(crate) fn receipt_block_2() -> ReceiptWithBlockNumber<OpReceipt> {
let log_1 = Log {
address: Address::from(hex!("8ce8c13d816fe6daf12d6fd9e4952e1fc88850af")),
data: LogData::new(
@ -285,20 +260,16 @@ pub(crate) mod test {
.unwrap(),
};
let mut receipt = Receipt {
tx_type: TxType::Legacy,
success: true,
let receipt = OpReceipt::Legacy(Receipt {
status: true.into(),
cumulative_gas_used: 116237,
..Default::default()
};
// #[allow(clippy::needless_update)] not recognised, ..Default::default() needed so optimism
// feature must not be brought into scope
receipt.logs = vec![log_1, log_2];
logs: vec![log_1, log_2],
});
ReceiptWithBlockNumber { receipt, number: 2 }
}
pub(crate) fn receipt_block_3() -> ReceiptWithBlockNumber {
pub(crate) fn receipt_block_3() -> ReceiptWithBlockNumber<OpReceipt> {
let log_1 = Log {
address: Address::from(hex!("8ce8c13d816fe6daf12d6fd9e4952e1fc88850af")),
data: LogData::new(
@ -337,15 +308,11 @@ pub(crate) mod test {
.unwrap(),
};
let mut receipt = Receipt {
tx_type: TxType::Legacy,
success: true,
let receipt = OpReceipt::Legacy(Receipt {
status: true.into(),
cumulative_gas_used: 116237,
..Default::default()
};
// #[allow(clippy::needless_update)] not recognised, ..Default::default() needed so optimism
// feature must not be brought into scope
receipt.logs = vec![log_1, log_2];
logs: vec![log_1, log_2],
});
ReceiptWithBlockNumber { receipt, number: 3 }
}

View File

@ -55,4 +55,4 @@ std = [
"alloy-trie/std",
"op-alloy-consensus/std",
]
optimism = ["reth-primitives/optimism", "reth-optimism-primitives/optimism"]
optimism = ["reth-optimism-primitives/optimism"]

View File

@ -78,7 +78,6 @@ std = [
"reth-consensus-common/std",
]
optimism = [
"reth-primitives/optimism",
"reth-execution-types/optimism",
"reth-optimism-consensus/optimism",
"revm/optimism",

View File

@ -312,7 +312,8 @@ mod tests {
use alloy_eips::eip2718::Decodable2718;
use reth_optimism_chainspec::OP_MAINNET;
use reth_optimism_forks::OpHardforks;
use reth_primitives::{Block, BlockBody, TransactionSigned};
use reth_optimism_primitives::OpTransactionSigned;
use reth_primitives::{Block, BlockBody};
use super::*;
@ -320,10 +321,9 @@ mod tests {
fn sanity_l1_block() {
use alloy_consensus::Header;
use alloy_primitives::{hex_literal::hex, Bytes};
use reth_primitives::TransactionSigned;
let bytes = Bytes::from_static(&hex!("7ef9015aa044bae9d41b8380d781187b426c6fe43df5fb2fb57bd4466ef6a701e1f01e015694deaddeaddeaddeaddeaddeaddeaddeaddead000194420000000000000000000000000000000000001580808408f0d18001b90104015d8eb900000000000000000000000000000000000000000000000000000000008057650000000000000000000000000000000000000000000000000000000063d96d10000000000000000000000000000000000000000000000000000000000009f35273d89754a1e0387b89520d989d3be9c37c1f32495a88faf1ea05c61121ab0d1900000000000000000000000000000000000000000000000000000000000000010000000000000000000000002d679b567db6187c0c8323fa982cfb88b74dbcc7000000000000000000000000000000000000000000000000000000000000083400000000000000000000000000000000000000000000000000000000000f4240"));
let l1_info_tx = TransactionSigned::decode_2718(&mut bytes.as_ref()).unwrap();
let l1_info_tx = OpTransactionSigned::decode_2718(&mut bytes.as_ref()).unwrap();
let mock_block = Block {
header: Header::default(),
body: BlockBody { transactions: vec![l1_info_tx], ..Default::default() },
@ -351,7 +351,7 @@ mod tests {
// https://optimistic.etherscan.io/getRawTx?tx=0x88501da5d5ca990347c2193be90a07037af1e3820bb40774c8154871c7669150
const TX: [u8; 251] = hex!("7ef8f8a0a539eb753df3b13b7e386e147d45822b67cb908c9ddc5618e3dbaa22ed00850b94deaddeaddeaddeaddeaddeaddeaddeaddead00019442000000000000000000000000000000000000158080830f424080b8a4440a5e2000000558000c5fc50000000000000000000000006605a89f00000000012a10d90000000000000000000000000000000000000000000000000000000af39ac3270000000000000000000000000000000000000000000000000000000d5ea528d24e582fa68786f080069bdbfe06a43f8e67bfd31b8e4d8a8837ba41da9a82a54a0000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f32985");
let tx = TransactionSigned::decode_2718(&mut TX.as_slice()).unwrap();
let tx = OpTransactionSigned::decode_2718(&mut TX.as_slice()).unwrap();
let block = Block {
body: BlockBody { transactions: vec![tx], ..Default::default() },
..Default::default()

View File

@ -89,7 +89,6 @@ futures.workspace = true
[features]
default = ["reth-codec"]
optimism = [
"reth-primitives/optimism",
"reth-provider/optimism",
"reth-optimism-evm/optimism",
"reth-optimism-payload-builder/optimism",

View File

@ -55,7 +55,6 @@ sha2.workspace = true
[features]
optimism = [
"reth-primitives/optimism",
"reth-provider/optimism",
"reth-optimism-evm/optimism",
"revm/optimism",

View File

@ -25,10 +25,9 @@ use reth_payload_builder_primitives::PayloadBuilderError;
use reth_payload_primitives::PayloadBuilderAttributes;
use reth_payload_util::{NoopPayloadTransactions, PayloadTransactions};
use reth_primitives::{
proofs, transaction::SignedTransactionIntoRecoveredExt, Block, BlockBody, RecoveredBlock,
SealedHeader, TxType,
proofs, transaction::SignedTransactionIntoRecoveredExt, Block, BlockBody, SealedHeader,
};
use reth_primitives_traits::block::Block as _;
use reth_primitives_traits::{block::Block as _, RecoveredBlock};
use reth_provider::{
HashedPostStateProvider, ProviderError, StateProofProvider, StateProviderFactory,
StateRootProvider,
@ -864,7 +863,7 @@ where
}
// A sequencer's block should never contain blob or deposit transactions from the pool.
if tx.is_eip4844() || tx.tx_type() == TxType::Deposit as u8 {
if tx.is_eip4844() || tx.tx_type() == OpTxType::Deposit {
best_txs.mark_invalid(tx.signer(), tx.nonce());
continue
}

View File

@ -49,6 +49,7 @@ rstest.workspace = true
arbitrary.workspace = true
secp256k1 = { workspace = true, features = ["rand"] }
proptest.workspace = true
rand.workspace = true
[features]
default = ["std"]

View File

@ -308,4 +308,197 @@ mod compact {
(receipt.into(), buf)
}
}
#[cfg(test)]
#[test]
fn test_ensure_backwards_compatibility() {
use reth_codecs::{test_utils::UnusedBits, validate_bitflag_backwards_compat};
assert_eq!(CompactOpReceipt::bitflag_encoded_bytes(), 2);
validate_bitflag_backwards_compat!(CompactOpReceipt<'_>, UnusedBits::NotZero);
}
}
#[cfg(test)]
mod tests {
use super::*;
use alloy_eips::eip2718::Encodable2718;
use alloy_primitives::{address, b256, bytes, hex_literal::hex, Bytes};
use alloy_rlp::Encodable;
use reth_codecs::Compact;
#[test]
fn test_decode_receipt() {
reth_codecs::test_utils::test_decode::<OpReceipt>(&hex!(
"c30328b52ffd23fc426961a00105007eb0042307705a97e503562eacf2b95060cce9de6de68386b6c155b73a9650021a49e2f8baad17f30faff5899d785c4c0873e45bc268bcf07560106424570d11f9a59e8f3db1efa4ceec680123712275f10d92c3411e1caaa11c7c5d591bc11487168e09934a9986848136da1b583babf3a7188e3aed007a1520f1cf4c1ca7d3482c6c28d37c298613c70a76940008816c4c95644579fd08471dc34732fd0f24"
));
}
// Test vector from: https://eips.ethereum.org/EIPS/eip-2481
#[test]
fn encode_legacy_receipt() {
let expected = hex!("f901668001b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f85ff85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff");
let mut data = Vec::with_capacity(expected.length());
let receipt = ReceiptWithBloom {
receipt: OpReceipt::Legacy(Receipt {
status: Eip658Value::Eip658(false),
cumulative_gas_used: 0x1,
logs: vec![Log::new_unchecked(
address!("0000000000000000000000000000000000000011"),
vec![
b256!("000000000000000000000000000000000000000000000000000000000000dead"),
b256!("000000000000000000000000000000000000000000000000000000000000beef"),
],
bytes!("0100ff"),
)],
}),
logs_bloom: [0; 256].into(),
};
receipt.encode(&mut data);
// check that the rlp length equals the length of the expected rlp
assert_eq!(receipt.length(), expected.len());
assert_eq!(data, expected);
}
// Test vector from: https://eips.ethereum.org/EIPS/eip-2481
#[test]
fn decode_legacy_receipt() {
let data = hex!("f901668001b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f85ff85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff");
// EIP658Receipt
let expected = ReceiptWithBloom {
receipt: OpReceipt::Legacy(Receipt {
status: Eip658Value::Eip658(false),
cumulative_gas_used: 0x1,
logs: vec![Log::new_unchecked(
address!("0000000000000000000000000000000000000011"),
vec![
b256!("000000000000000000000000000000000000000000000000000000000000dead"),
b256!("000000000000000000000000000000000000000000000000000000000000beef"),
],
bytes!("0100ff"),
)],
}),
logs_bloom: [0; 256].into(),
};
let receipt = ReceiptWithBloom::decode(&mut &data[..]).unwrap();
assert_eq!(receipt, expected);
}
#[test]
fn decode_deposit_receipt_regolith_roundtrip() {
let data = hex!("b901107ef9010c0182b741b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0833d3bbf");
// Deposit Receipt (post-regolith)
let expected = ReceiptWithBloom {
receipt: OpReceipt::Deposit(OpDepositReceipt {
inner: Receipt {
status: Eip658Value::Eip658(true),
cumulative_gas_used: 46913,
logs: vec![],
},
deposit_nonce: Some(4012991),
deposit_receipt_version: None,
}),
logs_bloom: [0; 256].into(),
};
let receipt = ReceiptWithBloom::decode(&mut &data[..]).unwrap();
assert_eq!(receipt, expected);
let mut buf = Vec::with_capacity(data.len());
receipt.encode(&mut buf);
assert_eq!(buf, &data[..]);
}
#[test]
fn decode_deposit_receipt_canyon_roundtrip() {
let data = hex!("b901117ef9010d0182b741b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0833d3bbf01");
// Deposit Receipt (post-regolith)
let expected = ReceiptWithBloom {
receipt: OpReceipt::Deposit(OpDepositReceipt {
inner: Receipt {
status: Eip658Value::Eip658(true),
cumulative_gas_used: 46913,
logs: vec![],
},
deposit_nonce: Some(4012991),
deposit_receipt_version: Some(1),
}),
logs_bloom: [0; 256].into(),
};
let receipt = ReceiptWithBloom::decode(&mut &data[..]).unwrap();
assert_eq!(receipt, expected);
let mut buf = Vec::with_capacity(data.len());
expected.encode(&mut buf);
assert_eq!(buf, &data[..]);
}
#[test]
fn gigantic_receipt() {
let receipt = OpReceipt::Legacy(Receipt {
status: Eip658Value::Eip658(true),
cumulative_gas_used: 16747627,
logs: vec![
Log::new_unchecked(
address!("4bf56695415f725e43c3e04354b604bcfb6dfb6e"),
vec![b256!("c69dc3d7ebff79e41f525be431d5cd3cc08f80eaf0f7819054a726eeb7086eb9")],
Bytes::from(vec![1; 0xffffff]),
),
Log::new_unchecked(
address!("faca325c86bf9c2d5b413cd7b90b209be92229c2"),
vec![b256!("8cca58667b1e9ffa004720ac99a3d61a138181963b294d270d91c53d36402ae2")],
Bytes::from(vec![1; 0xffffff]),
),
],
});
let mut data = vec![];
receipt.to_compact(&mut data);
let (decoded, _) = OpReceipt::from_compact(&data[..], data.len());
assert_eq!(decoded, receipt);
}
#[test]
fn test_encode_2718_length() {
let receipt = ReceiptWithBloom {
receipt: OpReceipt::Eip1559(Receipt {
status: Eip658Value::Eip658(true),
cumulative_gas_used: 21000,
logs: vec![],
}),
logs_bloom: Bloom::default(),
};
let encoded = receipt.encoded_2718();
assert_eq!(
encoded.len(),
receipt.encode_2718_len(),
"Encoded length should match the actual encoded data length"
);
// Test for legacy receipt as well
let legacy_receipt = ReceiptWithBloom {
receipt: OpReceipt::Legacy(Receipt {
status: Eip658Value::Eip658(true),
cumulative_gas_used: 21000,
logs: vec![],
}),
logs_bloom: Bloom::default(),
};
let legacy_encoded = legacy_receipt.encoded_2718();
assert_eq!(
legacy_encoded.len(),
legacy_receipt.encode_2718_len(),
"Encoded length for legacy receipt should match the actual encoded data length"
);
}
}

View File

@ -70,7 +70,6 @@ reth-optimism-chainspec.workspace = true
[features]
optimism = [
"reth-optimism-evm/optimism",
"reth-primitives/optimism",
"reth-provider/optimism",
"revm/optimism",
"reth-optimism-consensus/optimism",

View File

@ -21,7 +21,6 @@ reth-stages-types.workspace = true
[features]
optimism = [
"reth-primitives/optimism",
"reth-codecs/op",
"reth-db-api/optimism"
]

View File

@ -16,7 +16,7 @@ mod tests {
CompactClientVersion, CompactU256, CompactU64, StoredBlockBodyIndices,
StoredBlockWithdrawals,
};
use reth_primitives::{Account, Receipt};
use reth_primitives::Account;
use reth_prune_types::{PruneCheckpoint, PruneMode, PruneSegment};
use reth_stages_types::{
AccountHashingCheckpoint, CheckpointBlockRange, EntitiesCheckpoint, ExecutionCheckpoint,
@ -39,7 +39,6 @@ mod tests {
assert_eq!(PruneCheckpoint::bitflag_encoded_bytes(), 1);
assert_eq!(PruneMode::bitflag_encoded_bytes(), 1);
assert_eq!(PruneSegment::bitflag_encoded_bytes(), 1);
assert_eq!(Receipt::bitflag_encoded_bytes(), 2);
assert_eq!(StageCheckpoint::bitflag_encoded_bytes(), 1);
assert_eq!(StageUnitCheckpoint::bitflag_encoded_bytes(), 1);
assert_eq!(StoredBlockBodyIndices::bitflag_encoded_bytes(), 1);
@ -62,7 +61,6 @@ mod tests {
validate_bitflag_backwards_compat!(PruneCheckpoint, UnusedBits::NotZero);
validate_bitflag_backwards_compat!(PruneMode, UnusedBits::Zero);
validate_bitflag_backwards_compat!(PruneSegment, UnusedBits::Zero);
validate_bitflag_backwards_compat!(Receipt, UnusedBits::NotZero);
validate_bitflag_backwards_compat!(StageCheckpoint, UnusedBits::NotZero);
validate_bitflag_backwards_compat!(StageUnitCheckpoint, UnusedBits::Zero);
validate_bitflag_backwards_compat!(StoredBlockBodyIndices, UnusedBits::Zero);