mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
tx-pool: rm into tx constraint for PoolTransaction (#10057)
Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
This commit is contained in:
@ -47,7 +47,9 @@ 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::{PooledTransactionsElement, TransactionSigned, TxHash, B256};
|
use reth_primitives::{
|
||||||
|
PooledTransactionsElement, TransactionSigned, TransactionSignedEcRecovered, TxHash, B256,
|
||||||
|
};
|
||||||
use reth_tokio_util::EventStream;
|
use reth_tokio_util::EventStream;
|
||||||
use reth_transaction_pool::{
|
use reth_transaction_pool::{
|
||||||
error::{PoolError, PoolResult},
|
error::{PoolError, PoolResult},
|
||||||
@ -1395,9 +1397,11 @@ impl PropagateTransaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new instance from a pooled transaction
|
/// Create a new instance from a pooled transaction
|
||||||
fn new<T: PoolTransaction>(tx: Arc<ValidPoolTransaction<T>>) -> Self {
|
fn new<T: PoolTransaction<Consensus = TransactionSignedEcRecovered>>(
|
||||||
|
tx: Arc<ValidPoolTransaction<T>>,
|
||||||
|
) -> Self {
|
||||||
let size = tx.encoded_length();
|
let size = tx.encoded_length();
|
||||||
let transaction = Arc::new(tx.transaction.clone().into().into_signed());
|
let transaction = Arc::new(tx.transaction.clone().into_consensus().into_signed());
|
||||||
Self { size, transaction }
|
Self { size, transaction }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -134,7 +134,7 @@ where
|
|||||||
let l1_block_info = self.block_info.l1_block_info.read().clone();
|
let l1_block_info = self.block_info.l1_block_info.read().clone();
|
||||||
|
|
||||||
let mut encoded = Vec::with_capacity(valid_tx.transaction().encoded_length());
|
let mut encoded = Vec::with_capacity(valid_tx.transaction().encoded_length());
|
||||||
valid_tx.transaction().clone().into().encode_enveloped(&mut encoded);
|
valid_tx.transaction().clone().into_consensus().encode_enveloped(&mut encoded);
|
||||||
|
|
||||||
let cost_addition = match l1_block_info.l1_tx_data_fee(
|
let cost_addition = match l1_block_info.l1_tx_data_fee(
|
||||||
&self.chain_spec(),
|
&self.chain_spec(),
|
||||||
|
|||||||
@ -607,7 +607,9 @@ pub trait LoadTransaction: SpawnBlocking {
|
|||||||
|
|
||||||
if resp.is_none() {
|
if resp.is_none() {
|
||||||
// tx not found on disk, check pool
|
// tx not found on disk, check pool
|
||||||
if let Some(tx) = self.pool().get(&hash).map(|tx| tx.transaction.clone().into()) {
|
if let Some(tx) =
|
||||||
|
self.pool().get(&hash).map(|tx| tx.transaction.clone().into_consensus())
|
||||||
|
{
|
||||||
resp = Some(TransactionSource::Pool(tx));
|
resp = Some(TransactionSource::Pool(tx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ use std::{
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use jsonrpsee::{core::RpcResult, server::IdProvider};
|
use jsonrpsee::{core::RpcResult, server::IdProvider};
|
||||||
use reth_chainspec::ChainInfo;
|
use reth_chainspec::ChainInfo;
|
||||||
use reth_primitives::{IntoRecoveredTransaction, TxHash};
|
use reth_primitives::{IntoRecoveredTransaction, TransactionSignedEcRecovered, TxHash};
|
||||||
use reth_provider::{BlockIdReader, BlockReader, EvmEnvProvider, ProviderError};
|
use reth_provider::{BlockIdReader, BlockReader, EvmEnvProvider, ProviderError};
|
||||||
use reth_rpc_eth_api::EthFilterApiServer;
|
use reth_rpc_eth_api::EthFilterApiServer;
|
||||||
use reth_rpc_eth_types::{
|
use reth_rpc_eth_types::{
|
||||||
@ -573,7 +573,10 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns all new pending transactions received since the last poll.
|
/// Returns all new pending transactions received since the last poll.
|
||||||
async fn drain(&self) -> FilterChanges {
|
async fn drain(&self) -> FilterChanges
|
||||||
|
where
|
||||||
|
T: PoolTransaction<Consensus = TransactionSignedEcRecovered>,
|
||||||
|
{
|
||||||
let mut pending_txs = Vec::new();
|
let mut pending_txs = Vec::new();
|
||||||
let mut prepared_stream = self.txs_stream.lock().await;
|
let mut prepared_stream = self.txs_stream.lock().await;
|
||||||
|
|
||||||
@ -595,7 +598,7 @@ trait FullTransactionsFilter: fmt::Debug + Send + Sync + Unpin + 'static {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<T> FullTransactionsFilter for FullTransactionsReceiver<T>
|
impl<T> FullTransactionsFilter for FullTransactionsReceiver<T>
|
||||||
where
|
where
|
||||||
T: PoolTransaction + 'static,
|
T: PoolTransaction<Consensus = TransactionSignedEcRecovered> + 'static,
|
||||||
{
|
{
|
||||||
async fn drain(&self) -> FilterChanges {
|
async fn drain(&self) -> FilterChanges {
|
||||||
Self::drain(self).await
|
Self::drain(self).await
|
||||||
|
|||||||
@ -32,13 +32,13 @@ where
|
|||||||
{
|
{
|
||||||
fn content(&self) -> TxpoolContent {
|
fn content(&self) -> TxpoolContent {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn insert<T: PoolTransaction>(
|
fn insert<T: PoolTransaction<Consensus = TransactionSignedEcRecovered>>(
|
||||||
tx: &T,
|
tx: &T,
|
||||||
content: &mut BTreeMap<Address, BTreeMap<String, Transaction>>,
|
content: &mut BTreeMap<Address, BTreeMap<String, Transaction>>,
|
||||||
) {
|
) {
|
||||||
content.entry(tx.sender()).or_default().insert(
|
content.entry(tx.sender()).or_default().insert(
|
||||||
tx.nonce().to_string(),
|
tx.nonce().to_string(),
|
||||||
reth_rpc_types_compat::transaction::from_recovered(tx.clone().into()),
|
reth_rpc_types_compat::transaction::from_recovered(tx.clone().into_consensus()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,12 +82,12 @@ where
|
|||||||
trace!(target: "rpc::eth", "Serving txpool_inspect");
|
trace!(target: "rpc::eth", "Serving txpool_inspect");
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn insert<T: PoolTransaction>(
|
fn insert<T: PoolTransaction<Consensus = TransactionSignedEcRecovered>>(
|
||||||
tx: &T,
|
tx: &T,
|
||||||
inspect: &mut BTreeMap<Address, BTreeMap<String, TxpoolInspectSummary>>,
|
inspect: &mut BTreeMap<Address, BTreeMap<String, TxpoolInspectSummary>>,
|
||||||
) {
|
) {
|
||||||
let entry = inspect.entry(tx.sender()).or_default();
|
let entry = inspect.entry(tx.sender()).or_default();
|
||||||
let tx: TransactionSignedEcRecovered = tx.clone().into();
|
let tx = tx.clone().into_consensus();
|
||||||
entry.insert(
|
entry.insert(
|
||||||
tx.nonce().to_string(),
|
tx.nonce().to_string(),
|
||||||
TxpoolInspectSummary {
|
TxpoolInspectSummary {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use crate::traits::PoolTransaction;
|
use crate::traits::PoolTransaction;
|
||||||
use reth_primitives::{PooledTransactionsElementEcRecovered, U256};
|
use reth_primitives::{PooledTransactionsElementEcRecovered, TransactionSignedEcRecovered, U256};
|
||||||
use std::{fmt, marker::PhantomData};
|
use std::{fmt, marker::PhantomData};
|
||||||
|
|
||||||
/// Priority of the transaction that can be missing.
|
/// Priority of the transaction that can be missing.
|
||||||
@ -31,7 +31,10 @@ pub trait TransactionOrdering: Send + Sync + 'static {
|
|||||||
type PriorityValue: Ord + Clone + Default + fmt::Debug + Send + Sync;
|
type PriorityValue: Ord + Clone + Default + fmt::Debug + Send + Sync;
|
||||||
|
|
||||||
/// The transaction type to determine the priority of.
|
/// The transaction type to determine the priority of.
|
||||||
type Transaction: PoolTransaction<Pooled = PooledTransactionsElementEcRecovered>;
|
type Transaction: PoolTransaction<
|
||||||
|
Pooled = PooledTransactionsElementEcRecovered,
|
||||||
|
Consensus = TransactionSignedEcRecovered,
|
||||||
|
>;
|
||||||
|
|
||||||
/// Returns the priority score for the given transaction.
|
/// Returns the priority score for the given transaction.
|
||||||
fn priority(
|
fn priority(
|
||||||
@ -51,7 +54,10 @@ pub struct CoinbaseTipOrdering<T>(PhantomData<T>);
|
|||||||
|
|
||||||
impl<T> TransactionOrdering for CoinbaseTipOrdering<T>
|
impl<T> TransactionOrdering for CoinbaseTipOrdering<T>
|
||||||
where
|
where
|
||||||
T: PoolTransaction<Pooled = PooledTransactionsElementEcRecovered> + 'static,
|
T: PoolTransaction<
|
||||||
|
Pooled = PooledTransactionsElementEcRecovered,
|
||||||
|
Consensus = TransactionSignedEcRecovered,
|
||||||
|
> + 'static,
|
||||||
{
|
{
|
||||||
type PriorityValue = U256;
|
type PriorityValue = U256;
|
||||||
type Transaction = T;
|
type Transaction = T;
|
||||||
|
|||||||
@ -562,6 +562,10 @@ impl PoolTransaction for MockTransaction {
|
|||||||
|
|
||||||
type Pooled = PooledTransactionsElementEcRecovered;
|
type Pooled = PooledTransactionsElementEcRecovered;
|
||||||
|
|
||||||
|
fn into_consensus(self) -> Self::Consensus {
|
||||||
|
self.into()
|
||||||
|
}
|
||||||
|
|
||||||
fn from_pooled(pooled: Self::Pooled) -> Self {
|
fn from_pooled(pooled: Self::Pooled) -> Self {
|
||||||
pooled.into()
|
pooled.into()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,10 @@ pub type PeerId = reth_primitives::B512;
|
|||||||
#[auto_impl::auto_impl(&, Arc)]
|
#[auto_impl::auto_impl(&, Arc)]
|
||||||
pub trait TransactionPool: Send + Sync + Clone {
|
pub trait TransactionPool: Send + Sync + Clone {
|
||||||
/// The transaction type of the pool
|
/// The transaction type of the pool
|
||||||
type Transaction: PoolTransaction<Pooled = PooledTransactionsElementEcRecovered>;
|
type Transaction: PoolTransaction<
|
||||||
|
Pooled = PooledTransactionsElementEcRecovered,
|
||||||
|
Consensus = TransactionSignedEcRecovered,
|
||||||
|
>;
|
||||||
|
|
||||||
/// Returns stats about the pool and all sub-pools.
|
/// Returns stats about the pool and all sub-pools.
|
||||||
fn pool_size(&self) -> PoolSize;
|
fn pool_size(&self) -> PoolSize;
|
||||||
@ -484,13 +487,13 @@ pub struct AllPoolTransactions<T: PoolTransaction> {
|
|||||||
|
|
||||||
impl<T: PoolTransaction> AllPoolTransactions<T> {
|
impl<T: PoolTransaction> AllPoolTransactions<T> {
|
||||||
/// Returns an iterator over all pending [`TransactionSignedEcRecovered`] transactions.
|
/// Returns an iterator over all pending [`TransactionSignedEcRecovered`] transactions.
|
||||||
pub fn pending_recovered(&self) -> impl Iterator<Item = TransactionSignedEcRecovered> + '_ {
|
pub fn pending_recovered(&self) -> impl Iterator<Item = T::Consensus> + '_ {
|
||||||
self.pending.iter().map(|tx| tx.transaction.clone().into())
|
self.pending.iter().map(|tx| tx.transaction.clone().into_consensus())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator over all queued [`TransactionSignedEcRecovered`] transactions.
|
/// Returns an iterator over all queued [`TransactionSignedEcRecovered`] transactions.
|
||||||
pub fn queued_recovered(&self) -> impl Iterator<Item = TransactionSignedEcRecovered> + '_ {
|
pub fn queued_recovered(&self) -> impl Iterator<Item = T::Consensus> + '_ {
|
||||||
self.queued.iter().map(|tx| tx.transaction.clone().into())
|
self.queued.iter().map(|tx| tx.transaction.clone().into_consensus())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -771,12 +774,7 @@ impl BestTransactionsAttributes {
|
|||||||
|
|
||||||
/// Trait for transaction types used inside the pool
|
/// Trait for transaction types used inside the pool
|
||||||
pub trait PoolTransaction:
|
pub trait PoolTransaction:
|
||||||
fmt::Debug
|
fmt::Debug + Send + Sync + Clone + TryFrom<TransactionSignedEcRecovered>
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ Clone
|
|
||||||
+ TryFrom<TransactionSignedEcRecovered>
|
|
||||||
+ Into<TransactionSignedEcRecovered>
|
|
||||||
{
|
{
|
||||||
/// Associated type representing the raw consensus variant of the transaction.
|
/// Associated type representing the raw consensus variant of the transaction.
|
||||||
type Consensus: From<Self> + TryInto<Self>;
|
type Consensus: From<Self> + TryInto<Self>;
|
||||||
@ -784,6 +782,9 @@ pub trait PoolTransaction:
|
|||||||
/// Associated type representing the recovered pooled variant of the transaction.
|
/// Associated type representing the recovered pooled variant of the transaction.
|
||||||
type Pooled: Into<Self>;
|
type Pooled: Into<Self>;
|
||||||
|
|
||||||
|
/// Define a method to convert from the `Self` type to `Consensus`
|
||||||
|
fn into_consensus(self) -> Self::Consensus;
|
||||||
|
|
||||||
/// Define a method to convert from the `Pooled` type to `Self`
|
/// Define a method to convert from the `Pooled` type to `Self`
|
||||||
fn from_pooled(pooled: Self::Pooled) -> Self;
|
fn from_pooled(pooled: Self::Pooled) -> Self;
|
||||||
|
|
||||||
@ -884,7 +885,10 @@ pub trait PoolTransaction:
|
|||||||
/// An extension trait that provides additional interfaces for the
|
/// An extension trait that provides additional interfaces for the
|
||||||
/// [`EthTransactionValidator`](crate::EthTransactionValidator).
|
/// [`EthTransactionValidator`](crate::EthTransactionValidator).
|
||||||
pub trait EthPoolTransaction:
|
pub trait EthPoolTransaction:
|
||||||
PoolTransaction<Pooled = PooledTransactionsElementEcRecovered>
|
PoolTransaction<
|
||||||
|
Pooled = PooledTransactionsElementEcRecovered,
|
||||||
|
Consensus = TransactionSignedEcRecovered,
|
||||||
|
>
|
||||||
{
|
{
|
||||||
/// Extracts the blob sidecar from the transaction.
|
/// Extracts the blob sidecar from the transaction.
|
||||||
fn take_blob(&mut self) -> EthBlobTransactionSidecar;
|
fn take_blob(&mut self) -> EthBlobTransactionSidecar;
|
||||||
@ -1024,6 +1028,10 @@ impl PoolTransaction for EthPooledTransaction {
|
|||||||
|
|
||||||
type Pooled = PooledTransactionsElementEcRecovered;
|
type Pooled = PooledTransactionsElementEcRecovered;
|
||||||
|
|
||||||
|
fn into_consensus(self) -> Self::Consensus {
|
||||||
|
self.into()
|
||||||
|
}
|
||||||
|
|
||||||
fn from_pooled(pooled: Self::Pooled) -> Self {
|
fn from_pooled(pooled: Self::Pooled) -> Self {
|
||||||
pooled.into()
|
pooled.into()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -154,7 +154,10 @@ impl<T: PoolTransaction> ValidTransaction<T> {
|
|||||||
/// Provides support for validating transaction at any given state of the chain
|
/// Provides support for validating transaction at any given state of the chain
|
||||||
pub trait TransactionValidator: Send + Sync {
|
pub trait TransactionValidator: Send + Sync {
|
||||||
/// The transaction type to validate.
|
/// The transaction type to validate.
|
||||||
type Transaction: PoolTransaction<Pooled = PooledTransactionsElementEcRecovered>;
|
type Transaction: PoolTransaction<
|
||||||
|
Pooled = PooledTransactionsElementEcRecovered,
|
||||||
|
Consensus = TransactionSignedEcRecovered,
|
||||||
|
>;
|
||||||
|
|
||||||
/// Validates the transaction and returns a [`TransactionValidationOutcome`] describing the
|
/// Validates the transaction and returns a [`TransactionValidationOutcome`] describing the
|
||||||
/// validity of the given transaction.
|
/// validity of the given transaction.
|
||||||
@ -377,14 +380,16 @@ impl<T: PoolTransaction> ValidPoolTransaction<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: PoolTransaction> IntoRecoveredTransaction for ValidPoolTransaction<T> {
|
impl<T: PoolTransaction<Consensus = TransactionSignedEcRecovered>> IntoRecoveredTransaction
|
||||||
|
for ValidPoolTransaction<T>
|
||||||
|
{
|
||||||
fn to_recovered_transaction(&self) -> TransactionSignedEcRecovered {
|
fn to_recovered_transaction(&self) -> TransactionSignedEcRecovered {
|
||||||
self.transaction.clone().into()
|
self.transaction.clone().into_consensus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl<T: PoolTransaction + Clone> Clone for ValidPoolTransaction<T> {
|
impl<T: PoolTransaction> Clone for ValidPoolTransaction<T> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
transaction: self.transaction.clone(),
|
transaction: self.transaction.clone(),
|
||||||
|
|||||||
Reference in New Issue
Block a user