From 9f29107abb15b64d45843204e2e0fb32c65a5233 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Tue, 12 Nov 2024 12:11:37 +0100 Subject: [PATCH] chore(sdk): add `NodePrimitives::TxType` (#12332) --- crates/ethereum/node/src/node.rs | 3 ++- crates/optimism/node/src/node.rs | 3 ++- crates/primitives-traits/src/lib.rs | 2 +- crates/primitives-traits/src/node.rs | 10 ++++++++-- crates/primitives-traits/src/tx_type.rs | 7 +++++++ 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/crates/ethereum/node/src/node.rs b/crates/ethereum/node/src/node.rs index 68ed879d2..b37d0227a 100644 --- a/crates/ethereum/node/src/node.rs +++ b/crates/ethereum/node/src/node.rs @@ -25,7 +25,7 @@ use reth_node_builder::{ BuilderContext, Node, NodeAdapter, NodeComponentsBuilder, PayloadBuilderConfig, PayloadTypes, }; use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService}; -use reth_primitives::{Block, Header, Receipt, TransactionSigned}; +use reth_primitives::{Block, Header, Receipt, TransactionSigned, TxType}; use reth_provider::CanonStateSubscriptions; use reth_rpc::EthApi; use reth_tracing::tracing::{debug, info}; @@ -44,6 +44,7 @@ pub struct EthPrimitives; impl NodePrimitives for EthPrimitives { type Block = Block; type SignedTx = TransactionSigned; + type TxType = TxType; type Receipt = Receipt; } diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 323148e27..e97924d4b 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -24,7 +24,7 @@ use reth_optimism_evm::{OpEvmConfig, OpExecutionStrategyFactory}; use reth_optimism_payload_builder::builder::OpPayloadTransactions; use reth_optimism_rpc::OpEthApi; use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService, PayloadStore}; -use reth_primitives::{Block, Header, Receipt, TransactionSigned}; +use reth_primitives::{Block, Header, Receipt, TransactionSigned, TxType}; use reth_provider::CanonStateSubscriptions; use reth_tracing::tracing::{debug, info}; use reth_transaction_pool::{ @@ -47,6 +47,7 @@ pub struct OpPrimitives; impl NodePrimitives for OpPrimitives { type Block = Block; type SignedTx = TransactionSigned; + type TxType = TxType; type Receipt = Receipt; } diff --git a/crates/primitives-traits/src/lib.rs b/crates/primitives-traits/src/lib.rs index babc0f42e..afcc74a89 100644 --- a/crates/primitives-traits/src/lib.rs +++ b/crates/primitives-traits/src/lib.rs @@ -54,7 +54,7 @@ pub use storage::StorageEntry; /// Transaction types pub mod tx_type; -pub use tx_type::TxType; +pub use tx_type::{FullTxType, TxType}; /// Common header types pub mod header; diff --git a/crates/primitives-traits/src/node.rs b/crates/primitives-traits/src/node.rs index 921942841..cebbbe202 100644 --- a/crates/primitives-traits/src/node.rs +++ b/crates/primitives-traits/src/node.rs @@ -1,6 +1,6 @@ use core::fmt; -use crate::{BlockBody, FullBlock, FullReceipt, FullSignedTx}; +use crate::{BlockBody, FullBlock, FullReceipt, FullSignedTx, FullTxType}; /// Configures all the primitive types of the node. pub trait NodePrimitives: Send + Sync + Unpin + Clone + Default + fmt::Debug { @@ -8,6 +8,8 @@ pub trait NodePrimitives: Send + Sync + Unpin + Clone + Default + fmt::Debug { type Block: Send + Sync + Unpin + Clone + Default + fmt::Debug + 'static; /// Signed version of the transaction type. type SignedTx: Send + Sync + Unpin + Clone + Default + fmt::Debug + 'static; + /// Transaction envelope type ID. + type TxType: Send + Sync + Unpin + Clone + Default + fmt::Debug + 'static; /// A receipt. type Receipt: Send + Sync + Unpin + Clone + Default + fmt::Debug + 'static; } @@ -15,6 +17,7 @@ pub trait NodePrimitives: Send + Sync + Unpin + Clone + Default + fmt::Debug { impl NodePrimitives for () { type Block = (); type SignedTx = (); + type TxType = (); type Receipt = (); } @@ -24,15 +27,18 @@ pub trait FullNodePrimitives: Send + Sync + Unpin + Clone + Default + fmt::Debug type Block: FullBlock>; /// Signed version of the transaction type. type SignedTx: FullSignedTx; + /// Transaction envelope type ID. + type TxType: FullTxType; /// A receipt. type Receipt: FullReceipt; } impl NodePrimitives for T where - T: FullNodePrimitives, + T: FullNodePrimitives, { type Block = T::Block; type SignedTx = T::SignedTx; + type TxType = T::TxType; type Receipt = T::Receipt; } diff --git a/crates/primitives-traits/src/tx_type.rs b/crates/primitives-traits/src/tx_type.rs index 6ca558794..e0bf28d2a 100644 --- a/crates/primitives-traits/src/tx_type.rs +++ b/crates/primitives-traits/src/tx_type.rs @@ -3,6 +3,13 @@ use core::fmt; use alloy_eips::eip2718::Eip2718Error; use alloy_primitives::{U64, U8}; use alloy_rlp::{Decodable, Encodable}; +use reth_codecs::Compact; + +/// Helper trait that unifies all behaviour required by transaction type ID to support full node +/// operations. +pub trait FullTxType: TxType + Compact {} + +impl FullTxType for T where T: TxType + Compact {} /// Trait representing the behavior of a transaction type. pub trait TxType: