Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into fgimenez/srt-wiring
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed Jan 6, 2025
2 parents ea49fb4 + 5e659b3 commit 1160991
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 97 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,8 @@ mod tests {
BasicBlockExecutorProvider, BatchExecutor, BlockExecutorProvider, Executor,
};
use reth_execution_types::BlockExecutionOutput;
use reth_primitives::{
public_key_to_address, Account, Block, BlockBody, BlockExt, Transaction,
};
use reth_primitives::{Account, Block, BlockBody, BlockExt, Transaction};
use reth_primitives_traits::crypto::secp256k1::public_key_to_address;
use reth_revm::{
database::StateProviderDatabase, test_utils::StateProviderTest, TransitionState,
};
Expand Down
23 changes: 0 additions & 23 deletions crates/ethereum/primitives/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use serde::{Deserialize, Serialize};
))]
pub struct Receipt {
/// Receipt type.
#[serde(with = "tx_type_serde")]
pub tx_type: TxType,
/// If transaction is executed successfully.
///
Expand Down Expand Up @@ -185,25 +184,3 @@ impl InMemorySize for Receipt {
}

impl reth_primitives_traits::Receipt for Receipt {}

/// TODO: Remove once <https://github.com/alloy-rs/alloy/pull/1780> is released.
mod tx_type_serde {
use alloy_primitives::{U64, U8};

use super::*;

pub(crate) fn serialize<S>(tx_type: &TxType, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let value: U8 = (*tx_type).into();
value.serialize(serializer)
}

pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result<TxType, D::Error>
where
D: serde::Deserializer<'de>,
{
U64::deserialize(deserializer)?.try_into().map_err(serde::de::Error::custom)
}
}
4 changes: 3 additions & 1 deletion crates/evm/execution-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ arbitrary.workspace = true
bincode.workspace = true
rand.workspace = true
reth-primitives = { workspace = true, features = ["arbitrary", "test-utils"] }
reth-ethereum-primitives.workspace = true

[features]
default = ["std"]
Expand Down Expand Up @@ -65,5 +66,6 @@ std = [
"reth-primitives-traits/std",
"alloy-consensus/std",
"serde_with?/std",
"reth-trie-common?/std"
"reth-trie-common?/std",
"reth-ethereum-primitives/std"
]
24 changes: 19 additions & 5 deletions crates/evm/execution-types/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,26 @@ pub(super) mod serde_bincode_compat {
#[cfg(test)]
mod tests {
use super::*;
use alloy_primitives::B256;
use alloy_consensus::TxType;
use alloy_primitives::{Address, B256};
use reth_ethereum_primitives::Receipt;
use reth_primitives::Receipts;
use revm::primitives::{AccountInfo, HashMap};

// TODO: this is temporary, until we fully switch over to `reth_ethereum_primitives` for the
// `Receipt` type in `EthPrimitives`.
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
struct TestPrimitives;

impl reth_primitives_traits::NodePrimitives for TestPrimitives {
type Block = reth_primitives::Block;
type BlockHeader = alloy_consensus::Header;
type BlockBody = reth_primitives::BlockBody;
type SignedTx = reth_primitives::TransactionSigned;
type Receipt = Receipt;
}

#[test]
fn chain_append() {
let block: SealedBlockWithSenders = Default::default();
Expand Down Expand Up @@ -828,10 +845,7 @@ mod tests {
}

#[test]
#[cfg(not(feature = "optimism"))]
fn receipts_by_block_hash() {
use reth_primitives::{Receipt, Receipts, TxType};

// Create a default SealedBlockWithSenders object
let block: SealedBlockWithSenders = Default::default();

Expand Down Expand Up @@ -878,7 +892,7 @@ mod tests {

// Create a Chain object with a BTreeMap of blocks mapped to their block numbers,
// including block1_hash and block2_hash, and the execution_outcome
let chain: Chain = Chain {
let chain: Chain<TestPrimitives> = Chain {
blocks: BTreeMap::from([(10, block1), (11, block2)]),
execution_outcome: execution_outcome.clone(),
..Default::default()
Expand Down
35 changes: 11 additions & 24 deletions crates/evm/execution-types/src/execution_outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,17 +381,11 @@ impl<T> From<(BlockExecutionOutput<T>, BlockNumber)> for ExecutionOutcome<T> {
#[cfg(test)]
mod tests {
use super::*;
#[cfg(not(feature = "optimism"))]
use alloy_primitives::bytes;
#[cfg(not(feature = "optimism"))]
use alloy_primitives::LogData;
use alloy_primitives::{Address, B256};
use alloy_consensus::TxType;
use alloy_primitives::{bytes, Address, LogData, B256};
use reth_primitives::Receipts;
#[cfg(not(feature = "optimism"))]
use reth_primitives::TxType;

#[test]
#[cfg(not(feature = "optimism"))]
fn test_initialisation() {
// Create a new BundleState object with initial data
let bundle = BundleState::new(
Expand All @@ -402,7 +396,7 @@ mod tests {

// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
receipt_vec: vec![vec![Some(reth_primitives::Receipt {
receipt_vec: vec![vec![Some(reth_ethereum_primitives::Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![],
Expand Down Expand Up @@ -460,11 +454,10 @@ mod tests {
}

#[test]
#[cfg(not(feature = "optimism"))]
fn test_block_number_to_index() {
// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
receipt_vec: vec![vec![Some(reth_primitives::Receipt {
receipt_vec: vec![vec![Some(reth_ethereum_primitives::Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![],
Expand Down Expand Up @@ -495,11 +488,10 @@ mod tests {
}

#[test]
#[cfg(not(feature = "optimism"))]
fn test_get_logs() {
// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
receipt_vec: vec![vec![Some(reth_primitives::Receipt {
receipt_vec: vec![vec![Some(reth_ethereum_primitives::Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
Expand Down Expand Up @@ -527,11 +519,10 @@ mod tests {
}

#[test]
#[cfg(not(feature = "optimism"))]
fn test_receipts_by_block() {
// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
receipt_vec: vec![vec![Some(reth_primitives::Receipt {
receipt_vec: vec![vec![Some(reth_ethereum_primitives::Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
Expand All @@ -557,7 +548,7 @@ mod tests {
// Assert that the receipts for block number 123 match the expected receipts
assert_eq!(
receipts_by_block,
vec![&Some(reth_primitives::Receipt {
vec![&Some(reth_ethereum_primitives::Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
Expand All @@ -567,11 +558,10 @@ mod tests {
}

#[test]
#[cfg(not(feature = "optimism"))]
fn test_receipts_len() {
// Create a Receipts object with a vector of receipt vectors
let receipts = Receipts {
receipt_vec: vec![vec![Some(reth_primitives::Receipt {
receipt_vec: vec![vec![Some(reth_ethereum_primitives::Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![Log::<LogData>::default()],
Expand Down Expand Up @@ -616,10 +606,9 @@ mod tests {
}

#[test]
#[cfg(not(feature = "optimism"))]
fn test_revert_to() {
// Create a random receipt object
let receipt = reth_primitives::Receipt {
let receipt = reth_ethereum_primitives::Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![],
Expand Down Expand Up @@ -665,10 +654,9 @@ mod tests {
}

#[test]
#[cfg(not(feature = "optimism"))]
fn test_extend_execution_outcome() {
// Create a Receipt object with specific attributes.
let receipt = reth_primitives::Receipt {
let receipt = reth_ethereum_primitives::Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![],
Expand Down Expand Up @@ -709,10 +697,9 @@ mod tests {
}

#[test]
#[cfg(not(feature = "optimism"))]
fn test_split_at_execution_outcome() {
// Create a random receipt object
let receipt = reth_primitives::Receipt {
let receipt = reth_ethereum_primitives::Receipt {
tx_type: TxType::Legacy,
cumulative_gas_used: 46913,
logs: vec![],
Expand Down
5 changes: 2 additions & 3 deletions crates/exex/exex/src/backfill/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,20 @@ impl<E, P> From<BackfillJob<E, P>> for SingleBlockBackfillJob<E, P> {

#[cfg(test)]
mod tests {
use std::sync::Arc;

use crate::{
backfill::test_utils::{blocks_and_execution_outputs, chain_spec, to_execution_outcome},
BackfillJobFactory,
};
use reth_blockchain_tree::noop::NoopBlockchainTree;
use reth_db_common::init::init_genesis;
use reth_evm_ethereum::execute::EthExecutorProvider;
use reth_primitives::public_key_to_address;
use reth_primitives_traits::crypto::secp256k1::public_key_to_address;
use reth_provider::{
providers::BlockchainProvider, test_utils::create_test_provider_factory_with_chain_spec,
};
use reth_testing_utils::generators;
use secp256k1::Keypair;
use std::sync::Arc;

#[test]
fn test_backfill() -> eyre::Result<()> {
Expand Down
5 changes: 2 additions & 3 deletions crates/exex/exex/src/backfill/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ where

#[cfg(test)]
mod tests {
use std::sync::Arc;

use crate::{
backfill::test_utils::{
blocks_and_execution_outcome, blocks_and_execution_outputs, chain_spec,
Expand All @@ -247,13 +245,14 @@ mod tests {
use reth_blockchain_tree::noop::NoopBlockchainTree;
use reth_db_common::init::init_genesis;
use reth_evm_ethereum::execute::EthExecutorProvider;
use reth_primitives::public_key_to_address;
use reth_primitives_traits::crypto::secp256k1::public_key_to_address;
use reth_provider::{
providers::BlockchainProvider, test_utils::create_test_provider_factory_with_chain_spec,
};
use reth_stages_api::ExecutionStageThresholds;
use reth_testing_utils::generators;
use secp256k1::Keypair;
use std::sync::Arc;

#[tokio::test]
async fn test_single_blocks() -> eyre::Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions crates/optimism/primitives/src/transaction/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use op_alloy_consensus::{OpPooledTransaction, OpTypedTransaction, TxDeposit};
#[cfg(any(test, feature = "reth-codec"))]
use proptest as _;
use reth_primitives_traits::{
crypto::secp256k1::{recover_signer, recover_signer_unchecked},
crypto::secp256k1::{recover_signer, recover_signer_unchecked, sign_message},
transaction::error::TransactionConversionError,
InMemorySize, SignedTransaction,
};
Expand Down Expand Up @@ -519,7 +519,7 @@ impl<'a> arbitrary::Arbitrary<'a> for OpTransactionSigned {

let secp = secp256k1::Secp256k1::new();
let key_pair = secp256k1::Keypair::new(&secp, &mut rand::thread_rng());
let signature = reth_primitives::transaction::util::secp256k1::sign_message(
let signature = sign_message(
B256::from_slice(&key_pair.secret_bytes()[..]),
signature_hash(&transaction),
)
Expand Down
3 changes: 3 additions & 0 deletions crates/primitives-traits/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub use alloy_consensus::transaction::{TransactionInfo, TransactionMeta};
use crate::{InMemorySize, MaybeCompact, MaybeSerde};
use core::{fmt, hash::Hash};

#[cfg(test)]
mod access_list;

/// Helper trait that unifies all behaviour required by transaction to support full node operations.
pub trait FullTransaction: Transaction + MaybeCompact {}

Expand Down
9 changes: 1 addition & 8 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,9 @@ pub use tx_type::TxType;
pub mod signature;
pub mod util;

pub(crate) mod access_list;
mod pooled;
mod tx_type;

#[cfg(any(test, feature = "reth-codec"))]
pub use tx_type::{
COMPACT_EXTENDED_IDENTIFIER_FLAG, COMPACT_IDENTIFIER_EIP1559, COMPACT_IDENTIFIER_EIP2930,
COMPACT_IDENTIFIER_LEGACY,
};

/// Expected number of transactions where we can expect a speed-up by recovering the senders in
/// parallel.
pub static PARALLEL_SENDER_RECOVERY_THRESHOLD: LazyLock<usize> =
Expand Down Expand Up @@ -1497,7 +1490,7 @@ impl<'a> arbitrary::Arbitrary<'a> for TransactionSigned {

let secp = secp256k1::Secp256k1::new();
let key_pair = secp256k1::Keypair::new(&secp, &mut rand::thread_rng());
let signature = crate::sign_message(
let signature = reth_primitives_traits::crypto::secp256k1::sign_message(
B256::from_slice(&key_pair.secret_bytes()[..]),
transaction.signature_hash(),
)
Expand Down
20 changes: 1 addition & 19 deletions crates/primitives/src/transaction/tx_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,6 @@ use derive_more::Display;
use reth_primitives_traits::InMemorySize;
use serde::{Deserialize, Serialize};

/// Identifier parameter for legacy transaction
#[cfg(any(test, feature = "reth-codec"))]
pub const COMPACT_IDENTIFIER_LEGACY: usize = 0;

/// Identifier parameter for EIP-2930 transaction
#[cfg(any(test, feature = "reth-codec"))]
pub const COMPACT_IDENTIFIER_EIP2930: usize = 1;

/// Identifier parameter for EIP-1559 transaction
#[cfg(any(test, feature = "reth-codec"))]
pub const COMPACT_IDENTIFIER_EIP1559: usize = 2;

/// For backwards compatibility purposes only 2 bits of the type are encoded in the identifier
/// parameter. In the case of a [`COMPACT_EXTENDED_IDENTIFIER_FLAG`], the full transaction type is
/// read from the buffer as a single byte.
#[cfg(any(test, feature = "reth-codec"))]
pub const COMPACT_EXTENDED_IDENTIFIER_FLAG: usize = 3;

/// Transaction Type
///
/// Currently being used as 2-bit type when encoding it to `reth_codecs::Compact` on
Expand Down Expand Up @@ -256,7 +238,7 @@ impl Decodable for TxType {
mod tests {
use super::*;
use alloy_primitives::hex;
use reth_codecs::Compact;
use reth_codecs::{txtype::*, Compact};
use rstest::rstest;

#[rstest]
Expand Down
3 changes: 2 additions & 1 deletion crates/transaction-pool/src/test_utils/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use alloy_eips::{eip1559::MIN_PROTOCOL_BASE_FEE, eip2718::Encodable2718, eip2930
use alloy_primitives::{Address, Bytes, TxKind, B256, U256};
use rand::Rng;
use reth_chainspec::MAINNET;
use reth_primitives::{sign_message, Transaction, TransactionSigned};
use reth_primitives::{Transaction, TransactionSigned};
use reth_primitives_traits::crypto::secp256k1::sign_message;

/// A generator for transactions for testing purposes.
#[derive(Debug)]
Expand Down
Loading

0 comments on commit 1160991

Please sign in to comment.