pub trait PoolTransaction:
Transaction
+ InMemorySize
+ Debug
+ Send
+ Sync
+ Clone {
type TryFromConsensusError: Display;
type Consensus: SignedTransaction + From<Self::Pooled>;
type Pooled: TryFrom<Self::Consensus, Error = Self::TryFromConsensusError> + SignedTransaction;
Show 13 methods
// Required methods
fn into_consensus(self) -> Recovered<Self::Consensus>;
fn from_pooled(pooled: Recovered<Self::Pooled>) -> Self;
fn hash(&self) -> &TxHash;
fn sender(&self) -> Address;
fn sender_ref(&self) -> &Address;
fn cost(&self) -> &U256;
fn encoded_length(&self) -> usize;
// Provided methods
fn try_from_consensus(
tx: Recovered<Self::Consensus>,
) -> Result<Self, Self::TryFromConsensusError> { ... }
fn clone_into_consensus(&self) -> Recovered<Self::Consensus> { ... }
fn into_consensus_with2718(self) -> WithEncoded<Recovered<Self::Consensus>> { ... }
fn try_into_pooled(
self,
) -> Result<Recovered<Self::Pooled>, Self::TryFromConsensusError> { ... }
fn pooled_into_consensus(tx: Self::Pooled) -> Self::Consensus { ... }
fn ensure_max_init_code_size(
&self,
max_init_code_size: usize,
) -> Result<(), InvalidPoolTransactionError> { ... }
}
Expand description
Trait for transaction types used inside the pool.
This supports two transaction formats
- Consensus format: the form the transaction takes when it is included in a block.
- Pooled format: the form the transaction takes when it is gossiping around the network.
This distinction is necessary for the EIP-4844 blob transactions, which require an additional
sidecar when they are gossiped around the network. It is expected that the Consensus
format is
a subset of the Pooled
format.
The assumption is that fallible conversion from Consensus
to Pooled
will encapsulate
handling of all valid Consensus
transactions that can’t be pooled (e.g Deposit transactions or
blob-less EIP-4844 transactions).
Required Associated Types§
Sourcetype TryFromConsensusError: Display
type TryFromConsensusError: Display
Associated error type for the try_from_consensus
method.
Sourcetype Consensus: SignedTransaction + From<Self::Pooled>
type Consensus: SignedTransaction + From<Self::Pooled>
Associated type representing the raw consensus variant of the transaction.
Sourcetype Pooled: TryFrom<Self::Consensus, Error = Self::TryFromConsensusError> + SignedTransaction
type Pooled: TryFrom<Self::Consensus, Error = Self::TryFromConsensusError> + SignedTransaction
Associated type representing the recovered pooled variant of the transaction.
Required Methods§
Sourcefn into_consensus(self) -> Recovered<Self::Consensus>
fn into_consensus(self) -> Recovered<Self::Consensus>
Define a method to convert from the Self
type to Consensus
Sourcefn from_pooled(pooled: Recovered<Self::Pooled>) -> Self
fn from_pooled(pooled: Recovered<Self::Pooled>) -> Self
Define a method to convert from the Pooled
type to Self
Sourcefn sender_ref(&self) -> &Address
fn sender_ref(&self) -> &Address
Reference to the Sender of the transaction.
Sourcefn cost(&self) -> &U256
fn cost(&self) -> &U256
Returns the cost that this transaction is allowed to consume:
For EIP-1559 transactions: max_fee_per_gas * gas_limit + tx_value
.
For legacy transactions: gas_price * gas_limit + tx_value
.
For EIP-4844 blob transactions: max_fee_per_gas * gas_limit + tx_value + max_blob_fee_per_gas * blob_gas_used
.
Sourcefn encoded_length(&self) -> usize
fn encoded_length(&self) -> usize
Returns the length of the rlp encoded transaction object
Note: Implementations should cache this value.
Provided Methods§
Sourcefn try_from_consensus(
tx: Recovered<Self::Consensus>,
) -> Result<Self, Self::TryFromConsensusError>
fn try_from_consensus( tx: Recovered<Self::Consensus>, ) -> Result<Self, Self::TryFromConsensusError>
Define a method to convert from the Consensus
type to Self
Note: this must fail on any transactions that cannot be pooled (e.g OP Deposit transactions).
Sourcefn clone_into_consensus(&self) -> Recovered<Self::Consensus>
fn clone_into_consensus(&self) -> Recovered<Self::Consensus>
Clone the transaction into a consensus variant.
This method is preferred when the PoolTransaction
already wraps the consensus variant.
Sourcefn into_consensus_with2718(self) -> WithEncoded<Recovered<Self::Consensus>>
fn into_consensus_with2718(self) -> WithEncoded<Recovered<Self::Consensus>>
Converts the transaction into consensus format while preserving the EIP-2718 encoded bytes. This is used to optimize transaction execution by reusing cached encoded bytes instead of re-encoding the transaction. The cached bytes are particularly useful in payload building where the same transaction may be executed multiple times.
Sourcefn try_into_pooled(
self,
) -> Result<Recovered<Self::Pooled>, Self::TryFromConsensusError>
fn try_into_pooled( self, ) -> Result<Recovered<Self::Pooled>, Self::TryFromConsensusError>
Tries to convert the Consensus
type into the Pooled
type.
Sourcefn pooled_into_consensus(tx: Self::Pooled) -> Self::Consensus
fn pooled_into_consensus(tx: Self::Pooled) -> Self::Consensus
Converts the Pooled
type into the Consensus
type.
Sourcefn ensure_max_init_code_size(
&self,
max_init_code_size: usize,
) -> Result<(), InvalidPoolTransactionError>
fn ensure_max_init_code_size( &self, max_init_code_size: usize, ) -> Result<(), InvalidPoolTransactionError>
Ensures that the transaction’s code size does not exceed the provided max_init_code_size
.
This is specifically relevant for contract creation transactions ([TxKind::Create
]),
where the input data contains the initialization code. If the input code size exceeds
the configured limit, an InvalidPoolTransactionError::ExceedsMaxInitCodeSize
error is
returned.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
Source§impl PoolTransaction for MockTransaction
Available on crate feature test-utils
only.
impl PoolTransaction for MockTransaction
test-utils
only.