Skip to content

Commit 30a68d8

Browse files
committed
docs: add more comments to mempool iteration algorithm
1 parent 0db4115 commit 30a68d8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

stackslib/src/core/mempool.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,15 @@ impl MemPoolDB {
16161616
.query(NO_PARAMS)
16171617
.map_err(Error::SqliteError)?;
16181618

1619+
// Here we have a nested loop to walk the mempool.
1620+
//
1621+
// The `GlobalFeeRate` strategy includes all transactions, so we just
1622+
// query once and walk the full mempool in the inner loop.
1623+
//
1624+
// The `NextNonceWithHighestFeeRate` strategy only selects transactions
1625+
// that have the next expected nonce, so we need to re-query the
1626+
// mempool after one batch has been processed and the nonce table has
1627+
// been updated. This is handled in the outer loop.
16191628
let stop_reason = loop {
16201629
let mut state_changed = false;
16211630

@@ -1902,7 +1911,11 @@ impl MemPoolDB {
19021911
};
19031912

19041913
// If we've reached the end of the mempool, or if we've stopped
1905-
// iterating for some other reason, break out of the loop
1914+
// iterating for some other reason, break out of the loop. In the
1915+
// case of `NextNonceWithHighestFeeRate` we know we've reached the
1916+
// end of the mempool if the state has not changed. In the case of
1917+
// `GlobalFeeRate` we know we've reached the end of the mempool if
1918+
// the stop reason is `NoMoreCandidates`.
19061919
if settings.strategy != MemPoolWalkStrategy::NextNonceWithHighestFeeRate
19071920
|| stop_reason != MempoolIterationStopReason::NoMoreCandidates
19081921
|| !state_changed

0 commit comments

Comments
 (0)