mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: merge signed tx traits (#14622)
This commit is contained in:
@ -24,10 +24,7 @@ use reth_execution_types::ExecutionOutcome;
|
|||||||
use reth_fs_util as fs;
|
use reth_fs_util as fs;
|
||||||
use reth_node_api::{BlockTy, EngineApiMessageVersion, PayloadBuilderAttributes};
|
use reth_node_api::{BlockTy, EngineApiMessageVersion, PayloadBuilderAttributes};
|
||||||
use reth_node_ethereum::{consensus::EthBeaconConsensus, EthEvmConfig, EthExecutorProvider};
|
use reth_node_ethereum::{consensus::EthBeaconConsensus, EthEvmConfig, EthExecutorProvider};
|
||||||
use reth_primitives_traits::{
|
use reth_primitives_traits::{Block as _, SealedBlock, SealedHeader, SignedTransaction};
|
||||||
transaction::signed::SignedTransactionIntoRecoveredExt, Block as _, SealedBlock, SealedHeader,
|
|
||||||
SignedTransaction,
|
|
||||||
};
|
|
||||||
use reth_provider::{
|
use reth_provider::{
|
||||||
providers::{BlockchainProvider, ProviderNodeTypes},
|
providers::{BlockchainProvider, ProviderNodeTypes},
|
||||||
BlockHashReader, BlockReader, BlockWriter, ChainSpecProvider, ProviderFactory,
|
BlockHashReader, BlockReader, BlockWriter, ChainSpecProvider, ProviderFactory,
|
||||||
|
|||||||
@ -18,8 +18,8 @@ use rand::{thread_rng, Rng};
|
|||||||
use reth_chainspec::{ChainSpec, EthereumHardfork, MIN_TRANSACTION_GAS};
|
use reth_chainspec::{ChainSpec, EthereumHardfork, MIN_TRANSACTION_GAS};
|
||||||
use reth_execution_types::{Chain, ExecutionOutcome};
|
use reth_execution_types::{Chain, ExecutionOutcome};
|
||||||
use reth_primitives::{
|
use reth_primitives::{
|
||||||
transaction::SignedTransactionIntoRecoveredExt, BlockBody, EthPrimitives, NodePrimitives,
|
transaction::SignedTransaction, BlockBody, EthPrimitives, NodePrimitives, Receipt, Recovered,
|
||||||
Receipt, Recovered, RecoveredBlock, SealedBlock, SealedHeader, Transaction, TransactionSigned,
|
RecoveredBlock, SealedBlock, SealedHeader, Transaction, TransactionSigned,
|
||||||
};
|
};
|
||||||
use reth_primitives_traits::{
|
use reth_primitives_traits::{
|
||||||
proofs::{calculate_receipt_root, calculate_transaction_root, calculate_withdrawals_root},
|
proofs::{calculate_receipt_root, calculate_transaction_root, calculate_withdrawals_root},
|
||||||
|
|||||||
@ -19,7 +19,7 @@ use reth_evm::{
|
|||||||
};
|
};
|
||||||
use reth_payload_primitives::EngineApiMessageVersion;
|
use reth_payload_primitives::EngineApiMessageVersion;
|
||||||
use reth_payload_validator::ExecutionPayloadValidator;
|
use reth_payload_validator::ExecutionPayloadValidator;
|
||||||
use reth_primitives::{transaction::SignedTransactionIntoRecoveredExt, Block, BlockBody, Receipt};
|
use reth_primitives::{Block, BlockBody, Receipt};
|
||||||
use reth_primitives_traits::{block::Block as _, proofs, SignedTransaction};
|
use reth_primitives_traits::{block::Block as _, proofs, SignedTransaction};
|
||||||
use reth_provider::{BlockReader, ExecutionOutcome, ProviderError, StateProviderFactory};
|
use reth_provider::{BlockReader, ExecutionOutcome, ProviderError, StateProviderFactory};
|
||||||
use reth_revm::{
|
use reth_revm::{
|
||||||
|
|||||||
@ -8,8 +8,8 @@ use alloy_primitives::{Address, BlockHash, BlockNumber, TxHash};
|
|||||||
use core::{fmt, ops::RangeInclusive};
|
use core::{fmt, ops::RangeInclusive};
|
||||||
use reth_execution_errors::{BlockExecutionError, InternalBlockExecutionError};
|
use reth_execution_errors::{BlockExecutionError, InternalBlockExecutionError};
|
||||||
use reth_primitives_traits::{
|
use reth_primitives_traits::{
|
||||||
transaction::signed::SignedTransactionIntoRecoveredExt, Block, BlockBody, NodePrimitives,
|
transaction::signed::SignedTransaction, Block, BlockBody, NodePrimitives, RecoveredBlock,
|
||||||
RecoveredBlock, SealedHeader, SignedTransaction,
|
SealedHeader,
|
||||||
};
|
};
|
||||||
use reth_trie_common::updates::TrieUpdates;
|
use reth_trie_common::updates::TrieUpdates;
|
||||||
use revm_database::BundleState;
|
use revm_database::BundleState;
|
||||||
|
|||||||
@ -49,7 +49,7 @@ use reth_network_p2p::{
|
|||||||
};
|
};
|
||||||
use reth_network_peers::PeerId;
|
use reth_network_peers::PeerId;
|
||||||
use reth_network_types::ReputationChangeKind;
|
use reth_network_types::ReputationChangeKind;
|
||||||
use reth_primitives::{transaction::SignedTransactionIntoRecoveredExt, TransactionSigned};
|
use reth_primitives::TransactionSigned;
|
||||||
use reth_primitives_traits::SignedTransaction;
|
use reth_primitives_traits::SignedTransaction;
|
||||||
use reth_tokio_util::EventStream;
|
use reth_tokio_util::EventStream;
|
||||||
use reth_transaction_pool::{
|
use reth_transaction_pool::{
|
||||||
|
|||||||
@ -31,9 +31,7 @@ use reth_optimism_storage::predeploys;
|
|||||||
use reth_payload_builder_primitives::PayloadBuilderError;
|
use reth_payload_builder_primitives::PayloadBuilderError;
|
||||||
use reth_payload_primitives::PayloadBuilderAttributes;
|
use reth_payload_primitives::PayloadBuilderAttributes;
|
||||||
use reth_payload_util::{BestPayloadTransactions, NoopPayloadTransactions, PayloadTransactions};
|
use reth_payload_util::{BestPayloadTransactions, NoopPayloadTransactions, PayloadTransactions};
|
||||||
use reth_primitives::{
|
use reth_primitives::{transaction::SignedTransaction, BlockBody, NodePrimitives, SealedHeader};
|
||||||
transaction::SignedTransactionIntoRecoveredExt, BlockBody, NodePrimitives, SealedHeader,
|
|
||||||
};
|
|
||||||
use reth_primitives_traits::{block::Block as _, proofs, RecoveredBlock};
|
use reth_primitives_traits::{block::Block as _, proofs, RecoveredBlock};
|
||||||
use reth_provider::{
|
use reth_provider::{
|
||||||
BlockExecutionResult, HashedPostStateProvider, ProviderError, StateProofProvider,
|
BlockExecutionResult, HashedPostStateProvider, ProviderError, StateProofProvider,
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
block::{error::SealedBlockRecoveryError, SealedBlock},
|
block::{error::SealedBlockRecoveryError, SealedBlock},
|
||||||
transaction::signed::{RecoveryError, SignedTransactionIntoRecoveredExt},
|
transaction::signed::{RecoveryError, SignedTransaction},
|
||||||
Block, BlockBody, InMemorySize, SealedHeader,
|
Block, BlockBody, InMemorySize, SealedHeader,
|
||||||
};
|
};
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|||||||
@ -99,6 +99,41 @@ pub trait SignedTransaction:
|
|||||||
fn recalculate_hash(&self) -> B256 {
|
fn recalculate_hash(&self) -> B256 {
|
||||||
keccak256(self.encoded_2718())
|
keccak256(self.encoded_2718())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Tries to recover signer and return [`Recovered`] by cloning the type.
|
||||||
|
#[auto_impl(keep_default_for(&, Arc))]
|
||||||
|
fn try_clone_into_recovered(&self) -> Result<Recovered<Self>, RecoveryError> {
|
||||||
|
self.recover_signer().map(|signer| Recovered::new_unchecked(self.clone(), signer))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Tries to recover signer and return [`Recovered`].
|
||||||
|
///
|
||||||
|
/// Returns `Err(Self)` if the transaction's signature is invalid, see also
|
||||||
|
/// [`SignedTransaction::recover_signer`].
|
||||||
|
#[auto_impl(keep_default_for(&, Arc))]
|
||||||
|
fn try_into_recovered(self) -> Result<Recovered<Self>, Self> {
|
||||||
|
match self.recover_signer() {
|
||||||
|
Ok(signer) => Ok(Recovered::new_unchecked(self, signer)),
|
||||||
|
Err(_) => Err(self),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Consumes the type, recover signer and return [`Recovered`] _without
|
||||||
|
/// ensuring that the signature has a low `s` value_ (EIP-2).
|
||||||
|
///
|
||||||
|
/// Returns `None` if the transaction's signature is invalid.
|
||||||
|
#[auto_impl(keep_default_for(&, Arc))]
|
||||||
|
fn into_recovered_unchecked(self) -> Result<Recovered<Self>, RecoveryError> {
|
||||||
|
self.recover_signer_unchecked().map(|signer| Recovered::new_unchecked(self, signer))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the [`Recovered`] transaction with the given sender.
|
||||||
|
///
|
||||||
|
/// Note: assumes the given signer is the signer of this transaction.
|
||||||
|
#[auto_impl(keep_default_for(&, Arc))]
|
||||||
|
fn with_signer(self, signer: Address) -> Recovered<Self> {
|
||||||
|
Recovered::new_unchecked(self, signer)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SignedTransaction for PooledTransaction {
|
impl SignedTransaction for PooledTransaction {
|
||||||
@ -183,42 +218,6 @@ impl SignedTransaction for op_alloy_consensus::OpPooledTransaction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extension trait for [`SignedTransaction`] to convert it into [`Recovered`].
|
|
||||||
pub trait SignedTransactionIntoRecoveredExt: SignedTransaction {
|
|
||||||
/// Tries to recover signer and return [`Recovered`] by cloning the type.
|
|
||||||
fn try_clone_into_recovered(&self) -> Result<Recovered<Self>, RecoveryError> {
|
|
||||||
self.recover_signer().map(|signer| Recovered::new_unchecked(self.clone(), signer))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Tries to recover signer and return [`Recovered`].
|
|
||||||
///
|
|
||||||
/// Returns `Err(Self)` if the transaction's signature is invalid, see also
|
|
||||||
/// [`SignedTransaction::recover_signer`].
|
|
||||||
fn try_into_recovered(self) -> Result<Recovered<Self>, Self> {
|
|
||||||
match self.recover_signer() {
|
|
||||||
Ok(signer) => Ok(Recovered::new_unchecked(self, signer)),
|
|
||||||
Err(_) => Err(self),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Consumes the type, recover signer and return [`Recovered`] _without
|
|
||||||
/// ensuring that the signature has a low `s` value_ (EIP-2).
|
|
||||||
///
|
|
||||||
/// Returns `None` if the transaction's signature is invalid.
|
|
||||||
fn into_recovered_unchecked(self) -> Result<Recovered<Self>, RecoveryError> {
|
|
||||||
self.recover_signer_unchecked().map(|signer| Recovered::new_unchecked(self, signer))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the [`Recovered`] transaction with the given sender.
|
|
||||||
///
|
|
||||||
/// Note: assumes the given signer is the signer of this transaction.
|
|
||||||
fn with_signer(self, signer: Address) -> Recovered<Self> {
|
|
||||||
Recovered::new_unchecked(self, signer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> SignedTransactionIntoRecoveredExt for T where T: SignedTransaction {}
|
|
||||||
|
|
||||||
/// Opaque error type for sender recovery.
|
/// Opaque error type for sender recovery.
|
||||||
#[derive(Debug, Default, thiserror::Error)]
|
#[derive(Debug, Default, thiserror::Error)]
|
||||||
#[error("Failed to recover the signer")]
|
#[error("Failed to recover the signer")]
|
||||||
|
|||||||
@ -11,7 +11,7 @@ pub use reth_primitives_traits::{
|
|||||||
error::{
|
error::{
|
||||||
InvalidTransactionError, TransactionConversionError, TryFromRecoveredTransactionError,
|
InvalidTransactionError, TransactionConversionError, TryFromRecoveredTransactionError,
|
||||||
},
|
},
|
||||||
signed::SignedTransactionIntoRecoveredExt,
|
signed::SignedTransaction,
|
||||||
},
|
},
|
||||||
FillTxEnv, WithEncoded,
|
FillTxEnv, WithEncoded,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -14,8 +14,7 @@ use alloy_primitives::{Address, Bytes, TxHash, B256};
|
|||||||
use alloy_rpc_types_eth::{transaction::TransactionRequest, BlockNumberOrTag, TransactionInfo};
|
use alloy_rpc_types_eth::{transaction::TransactionRequest, BlockNumberOrTag, TransactionInfo};
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use reth_node_api::BlockBody;
|
use reth_node_api::BlockBody;
|
||||||
use reth_primitives::{transaction::SignedTransactionIntoRecoveredExt, RecoveredBlock};
|
use reth_primitives::{transaction::SignedTransaction, RecoveredBlock};
|
||||||
use reth_primitives_traits::SignedTransaction;
|
|
||||||
use reth_provider::{
|
use reth_provider::{
|
||||||
BlockNumReader, BlockReaderIdExt, ProviderBlock, ProviderReceipt, ProviderTx, ReceiptProvider,
|
BlockNumReader, BlockReaderIdExt, ProviderBlock, ProviderReceipt, ProviderTx, ReceiptProvider,
|
||||||
TransactionsProvider,
|
TransactionsProvider,
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
//! Commonly used code snippets
|
//! Commonly used code snippets
|
||||||
|
|
||||||
use super::{EthApiError, EthResult};
|
use super::{EthApiError, EthResult};
|
||||||
use reth_primitives::{transaction::SignedTransactionIntoRecoveredExt, Recovered};
|
use reth_primitives::Recovered;
|
||||||
use reth_primitives_traits::SignedTransaction;
|
use reth_primitives_traits::SignedTransaction;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,7 @@ use reth_chain_state::CanonStateNotification;
|
|||||||
use reth_chainspec::{ChainSpecProvider, EthChainSpec};
|
use reth_chainspec::{ChainSpecProvider, EthChainSpec};
|
||||||
use reth_execution_types::ChangedAccount;
|
use reth_execution_types::ChangedAccount;
|
||||||
use reth_fs_util::FsPathError;
|
use reth_fs_util::FsPathError;
|
||||||
use reth_primitives::{transaction::SignedTransactionIntoRecoveredExt, SealedHeader};
|
use reth_primitives::SealedHeader;
|
||||||
use reth_primitives_traits::{NodePrimitives, SignedTransaction};
|
use reth_primitives_traits::{NodePrimitives, SignedTransaction};
|
||||||
use reth_storage_api::{errors::provider::ProviderError, BlockReaderIdExt, StateProviderFactory};
|
use reth_storage_api::{errors::provider::ProviderError, BlockReaderIdExt, StateProviderFactory};
|
||||||
use reth_tasks::TaskSpawner;
|
use reth_tasks::TaskSpawner;
|
||||||
|
|||||||
@ -4,9 +4,7 @@ use alloy_eips::{eip1559::MIN_PROTOCOL_BASE_FEE, eip2718::Encodable2718, eip2930
|
|||||||
use alloy_primitives::{Address, Bytes, TxKind, B256, U256};
|
use alloy_primitives::{Address, Bytes, TxKind, B256, U256};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use reth_chainspec::MAINNET;
|
use reth_chainspec::MAINNET;
|
||||||
use reth_primitives::{
|
use reth_primitives::{transaction::SignedTransaction, Transaction, TransactionSigned};
|
||||||
transaction::SignedTransactionIntoRecoveredExt, Transaction, TransactionSigned,
|
|
||||||
};
|
|
||||||
use reth_primitives_traits::crypto::secp256k1::sign_message;
|
use reth_primitives_traits::crypto::secp256k1::sign_message;
|
||||||
|
|
||||||
/// A generator for transactions for testing purposes.
|
/// A generator for transactions for testing purposes.
|
||||||
|
|||||||
@ -29,10 +29,7 @@ use rand::{
|
|||||||
prelude::Distribution,
|
prelude::Distribution,
|
||||||
};
|
};
|
||||||
use reth_primitives::{
|
use reth_primitives::{
|
||||||
transaction::{
|
transaction::{TransactionConversionError, TryFromRecoveredTransactionError},
|
||||||
SignedTransactionIntoRecoveredExt, TransactionConversionError,
|
|
||||||
TryFromRecoveredTransactionError,
|
|
||||||
},
|
|
||||||
PooledTransaction, Recovered, Transaction, TransactionSigned, TxType,
|
PooledTransaction, Recovered, Transaction, TransactionSigned, TxType,
|
||||||
};
|
};
|
||||||
use reth_primitives_traits::{InMemorySize, SignedTransaction};
|
use reth_primitives_traits::{InMemorySize, SignedTransaction};
|
||||||
|
|||||||
@ -17,9 +17,8 @@ use futures_util::{ready, Stream};
|
|||||||
use reth_eth_wire_types::HandleMempoolData;
|
use reth_eth_wire_types::HandleMempoolData;
|
||||||
use reth_execution_types::ChangedAccount;
|
use reth_execution_types::ChangedAccount;
|
||||||
use reth_primitives::{
|
use reth_primitives::{
|
||||||
kzg::KzgSettings,
|
kzg::KzgSettings, transaction::TransactionConversionError, PooledTransaction, Recovered,
|
||||||
transaction::{SignedTransactionIntoRecoveredExt, TransactionConversionError},
|
SealedBlock, TransactionSigned,
|
||||||
PooledTransaction, Recovered, SealedBlock, TransactionSigned,
|
|
||||||
};
|
};
|
||||||
use reth_primitives_traits::{Block, InMemorySize, SignedTransaction};
|
use reth_primitives_traits::{Block, InMemorySize, SignedTransaction};
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
|
|||||||
@ -924,7 +924,7 @@ mod tests {
|
|||||||
use alloy_consensus::Transaction;
|
use alloy_consensus::Transaction;
|
||||||
use alloy_eips::eip2718::Decodable2718;
|
use alloy_eips::eip2718::Decodable2718;
|
||||||
use alloy_primitives::{hex, U256};
|
use alloy_primitives::{hex, U256};
|
||||||
use reth_primitives::{transaction::SignedTransactionIntoRecoveredExt, PooledTransaction};
|
use reth_primitives::{transaction::SignedTransaction, PooledTransaction};
|
||||||
use reth_provider::test_utils::{ExtendedAccount, MockEthProvider};
|
use reth_provider::test_utils::{ExtendedAccount, MockEthProvider};
|
||||||
|
|
||||||
fn get_transaction() -> EthPooledTransaction {
|
fn get_transaction() -> EthPooledTransaction {
|
||||||
|
|||||||
Reference in New Issue
Block a user