mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: use primitive transaction as PoolTransaction::Consensus (#13086)
This commit is contained in:
@ -7,12 +7,15 @@ use reth_primitives::RecoveredTx;
|
||||
/// Can include transactions from the pool and other sources (alternative pools,
|
||||
/// sequencer-originated transactions, etc.).
|
||||
pub trait PayloadTransactions {
|
||||
/// The transaction type this iterator yields.
|
||||
type Transaction;
|
||||
|
||||
/// Returns the next transaction to include in the block.
|
||||
fn next(
|
||||
&mut self,
|
||||
// In the future, `ctx` can include access to state for block building purposes.
|
||||
ctx: (),
|
||||
) -> Option<RecoveredTx>;
|
||||
) -> Option<RecoveredTx<Self::Transaction>>;
|
||||
|
||||
/// Exclude descendants of the transaction with given sender and nonce from the iterator,
|
||||
/// because this transaction won't be included in the block.
|
||||
|
||||
@ -26,8 +26,10 @@ impl<T> PayloadTransactionsFixed<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl PayloadTransactions for PayloadTransactionsFixed<RecoveredTx> {
|
||||
fn next(&mut self, _ctx: ()) -> Option<RecoveredTx> {
|
||||
impl<T: Clone> PayloadTransactions for PayloadTransactionsFixed<RecoveredTx<T>> {
|
||||
type Transaction = T;
|
||||
|
||||
fn next(&mut self, _ctx: ()) -> Option<RecoveredTx<T>> {
|
||||
(self.index < self.transactions.len()).then(|| {
|
||||
let tx = self.transactions[self.index].clone();
|
||||
self.index += 1;
|
||||
@ -87,20 +89,22 @@ impl<B: PayloadTransactions, A: PayloadTransactions> PayloadTransactionsChain<B,
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, A> PayloadTransactions for PayloadTransactionsChain<B, A>
|
||||
impl<A, B> PayloadTransactions for PayloadTransactionsChain<A, B>
|
||||
where
|
||||
B: PayloadTransactions,
|
||||
A: PayloadTransactions,
|
||||
A: PayloadTransactions<Transaction: Transaction>,
|
||||
B: PayloadTransactions<Transaction = A::Transaction>,
|
||||
{
|
||||
fn next(&mut self, ctx: ()) -> Option<RecoveredTx> {
|
||||
type Transaction = A::Transaction;
|
||||
|
||||
fn next(&mut self, ctx: ()) -> Option<RecoveredTx<Self::Transaction>> {
|
||||
while let Some(tx) = self.before.next(ctx) {
|
||||
if let Some(before_max_gas) = self.before_max_gas {
|
||||
if self.before_gas + tx.transaction.gas_limit() <= before_max_gas {
|
||||
self.before_gas += tx.transaction.gas_limit();
|
||||
if self.before_gas + tx.as_signed().gas_limit() <= before_max_gas {
|
||||
self.before_gas += tx.as_signed().gas_limit();
|
||||
return Some(tx);
|
||||
}
|
||||
self.before.mark_invalid(tx.signer(), tx.transaction.nonce());
|
||||
self.after.mark_invalid(tx.signer(), tx.transaction.nonce());
|
||||
self.before.mark_invalid(tx.signer(), tx.as_signed().nonce());
|
||||
self.after.mark_invalid(tx.signer(), tx.as_signed().nonce());
|
||||
} else {
|
||||
return Some(tx);
|
||||
}
|
||||
@ -108,11 +112,11 @@ where
|
||||
|
||||
while let Some(tx) = self.after.next(ctx) {
|
||||
if let Some(after_max_gas) = self.after_max_gas {
|
||||
if self.after_gas + tx.transaction.gas_limit() <= after_max_gas {
|
||||
self.after_gas += tx.transaction.gas_limit();
|
||||
if self.after_gas + tx.as_signed().gas_limit() <= after_max_gas {
|
||||
self.after_gas += tx.as_signed().gas_limit();
|
||||
return Some(tx);
|
||||
}
|
||||
self.after.mark_invalid(tx.signer(), tx.transaction.nonce());
|
||||
self.after.mark_invalid(tx.signer(), tx.as_signed().nonce());
|
||||
} else {
|
||||
return Some(tx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user