mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: use highest known nonce (#11784)
This commit is contained in:
@ -110,13 +110,21 @@ impl<T: TransactionOrdering> TxPool<T> {
|
||||
|
||||
/// Returns the transaction with the highest nonce that is executable given the on chain nonce.
|
||||
///
|
||||
/// If the pool already tracks a higher nonce for the given sender, then this nonce is used
|
||||
/// instead.
|
||||
///
|
||||
/// Note: The next pending pooled transaction must have the on chain nonce.
|
||||
pub(crate) fn get_highest_consecutive_transaction_by_sender(
|
||||
&self,
|
||||
on_chain: TransactionId,
|
||||
mut on_chain: TransactionId,
|
||||
) -> Option<Arc<ValidPoolTransaction<T::Transaction>>> {
|
||||
let mut last_consecutive_tx = None;
|
||||
|
||||
// ensure this operates on the most recent
|
||||
if let Some(current) = self.sender_info.get(&on_chain.sender) {
|
||||
on_chain.nonce = on_chain.nonce.max(current.state_nonce);
|
||||
}
|
||||
|
||||
let mut next_expected_nonce = on_chain.nonce;
|
||||
for (id, tx) in self.all().descendant_txs_inclusive(&on_chain) {
|
||||
if next_expected_nonce != id.nonce {
|
||||
@ -2784,7 +2792,7 @@ mod tests {
|
||||
|
||||
// Create transactions with nonces 0, 1, 2, 4, 5.
|
||||
let sender = Address::random();
|
||||
let txs: Vec<_> = vec![0, 1, 2, 4, 5];
|
||||
let txs: Vec<_> = vec![0, 1, 2, 4, 5, 8, 9];
|
||||
for nonce in txs {
|
||||
let mut mock_tx = MockTransaction::eip1559();
|
||||
mock_tx.set_sender(sender);
|
||||
@ -2804,6 +2812,13 @@ mod tests {
|
||||
|
||||
let next_tx = pool.get_highest_consecutive_transaction_by_sender(sender_id.into_id(5));
|
||||
assert_eq!(next_tx.map(|tx| tx.nonce()), Some(5), "Expected nonce 5 for on-chain nonce 5");
|
||||
|
||||
// update the tracked nonce
|
||||
let mut info = SenderInfo::default();
|
||||
info.update(8, U256::ZERO);
|
||||
pool.sender_info.insert(sender_id, info);
|
||||
let next_tx = pool.get_highest_consecutive_transaction_by_sender(sender_id.into_id(5));
|
||||
assert_eq!(next_tx.map(|tx| tx.nonce()), Some(9), "Expected nonce 9 for on-chain nonce 8");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user