Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(txpool): pendind pool reordering #3955

Merged
merged 6 commits into from
Jul 28, 2023
Merged

Conversation

rkrasiuk
Copy link
Member

@rkrasiuk rkrasiuk commented Jul 27, 2023

Replaces #3853

Description

Changes the intrinsics of the ordering function to account for sorting context (currently, only base_fee). Needed to determine the proper ordering of the transactions within the pool.

The pending pool is now re-sorted on each base fee update.

NOTE: This PR does not fix everything and requires follow ups, most importantly for the QueuedOrd.

@rkrasiuk rkrasiuk added C-bug An unexpected or incorrect behavior A-tx-pool Related to the transaction mempool labels Jul 27, 2023
@rkrasiuk rkrasiuk marked this pull request as ready for review July 27, 2023 11:55
@rkrasiuk rkrasiuk requested review from mattsse and gakonst as code owners July 27, 2023 11:55
@codecov
Copy link

codecov bot commented Jul 27, 2023

Codecov Report

Merging #3955 (c03882e) into main (a298756) will decrease coverage by 0.04%.
The diff coverage is 65.59%.

Impacted file tree graph

Files Changed Coverage Δ
crates/transaction-pool/src/lib.rs 32.31% <0.00%> (ø)
crates/transaction-pool/src/traits.rs 4.02% <0.00%> (ø)
crates/transaction-pool/src/validate/mod.rs 43.03% <0.00%> (-3.80%) ⬇️
crates/transaction-pool/src/pool/txpool.rs 59.09% <30.00%> (-0.25%) ⬇️
crates/transaction-pool/src/ordering.rs 25.00% <41.66%> (+25.00%) ⬆️
crates/transaction-pool/src/test_utils/mock.rs 58.01% <58.33%> (-3.63%) ⬇️
crates/transaction-pool/src/pool/pending.rs 78.36% <89.13%> (+2.48%) ⬆️
crates/transaction-pool/src/pool/best.rs 75.00% <100.00%> (ø)
crates/transaction-pool/src/pool/parked.rs 79.67% <100.00%> (ø)

... and 8 files with indirect coverage changes

Flag Coverage Δ
integration-tests 15.52% <0.00%> (-0.02%) ⬇️
unit-tests 64.47% <65.59%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
reth binary 27.16% <ø> (ø)
blockchain tree 83.04% <ø> (ø)
pipeline 89.82% <ø> (ø)
storage (db) 74.30% <ø> (ø)
trie 94.70% <ø> (ø)
txpool 45.49% <65.59%> (-0.28%) ⬇️
networking 77.67% <ø> (-0.05%) ⬇️
rpc 58.73% <ø> (-0.02%) ⬇️
consensus 64.46% <ø> (ø)
revm 33.68% <ø> (ø)
payload builder 6.61% <ø> (ø)
primitives 87.80% <ø> (ø)

///
/// NOTE: The implementation is incomplete for missing base fee.
fn priority(&self, transaction: &Self::Transaction, base_fee: u64) -> Self::Priority {
U256::from(transaction.effective_tip_per_gas(base_fee).expect("tx has been validated"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while this should be accurate for txs in the pending pool
I don't like that this panics for txs that don't meet the basefee

I'd rather use a new priority enum type that works like an option

Comment on lines 68 to 71
fn clear_transactions(&mut self) -> BTreeMap<TransactionId, Arc<PendingTransaction<T>>> {
self.independent_transactions.clear();
self.all.clear();
std::mem::take(&mut self.by_id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a note that it does not update size tracker

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

let mut removed = Vec::new();

// Drain and iterate over all transactions.
let mut transactions_iter = self.clear_transactions().into_iter().peekable();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we clear all lists?

we only need to rebuild the sorted list and only remove those that should be removed from the entire set?

Copy link
Member Author

@rkrasiuk rkrasiuk Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to update two sorted lists, but, yeah, no need to remove the map

Comment on lines 309 to 313
// TODO: temporary solution for ordering the queued pool.
impl<T: PoolTransaction> Ord for QueuedOrd<T> {
fn cmp(&self, other: &Self) -> Ordering {
// Higher cost is better
self.gas_cost().cmp(&other.gas_cost()).then_with(||
// Higher price is better
self.priority_fee_or_price().cmp(&self.priority_fee_or_price()).then_with(||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we also want to consider nonce gap and distance to basefee I think

@rkrasiuk rkrasiuk requested a review from mattsse July 27, 2023 15:39
@rkrasiuk rkrasiuk force-pushed the rkrasiuk/txpool-pending-reordering branch from bc70ef5 to 6c6c993 Compare July 27, 2023 17:06
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mattsse mattsse added this pull request to the merge queue Jul 28, 2023
Merged via the queue into main with commit 3601e7d Jul 28, 2023
@mattsse mattsse deleted the rkrasiuk/txpool-pending-reordering branch July 28, 2023 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tx-pool Related to the transaction mempool C-bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants