Skip to content

Commit cc234be

Browse files
committed
Merge branch 'fix/mempool-query' into fix/mempool-query-errors
2 parents 2b79d70 + 30a68d8 commit cc234be

File tree

21 files changed

+292
-147
lines changed

21 files changed

+292
-147
lines changed

stacks-common/src/util/lru_cache.rs

Lines changed: 258 additions & 120 deletions
Large diffs are not rendered by default.

stackslib/src/chainstate/stacks/tests/block_construction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5031,7 +5031,7 @@ fn paramaterized_mempool_walk_test(
50315031
#[test]
50325032
/// Test that the mempool walk query ignores old nonces and prefers next possible nonces before higher global fees.
50335033
fn mempool_walk_test_next_nonce_with_highest_fee_rate_strategy() {
5034-
let key_address_pairs: Vec<(Secp256k1PrivateKey, StacksAddress)> = (0..7)
5034+
let key_address_pairs: Vec<_> = (0..7)
50355035
.map(|_user_index| {
50365036
let privk = StacksPrivateKey::random();
50375037
let addr = StacksAddress::from_public_keys(

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

stackslib/src/core/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ use crate::chainstate::burn::ConsensusHash;
3232
pub mod mempool;
3333
pub mod nonce_cache;
3434

35+
#[cfg(any(test, feature = "testing"))]
36+
pub mod test_util;
3537
#[cfg(test)]
3638
pub mod tests;
37-
#[cfg(any(test, feature = "testing"))]
38-
pub mod util;
3939

4040
use std::cmp::Ordering;
4141
pub type StacksEpoch = GenericStacksEpoch<ExecutionCost>;

stackslib/src/core/util.rs renamed to stackslib/src/core/test_util.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,7 @@ pub fn make_contract_publish_microblock_only(
266266
}
267267

268268
pub fn to_addr(sk: &StacksPrivateKey) -> StacksAddress {
269-
StacksAddress::from_public_keys(
270-
C32_ADDRESS_VERSION_TESTNET_SINGLESIG,
271-
&AddressHashMode::SerializeP2PKH,
272-
1,
273-
&vec![StacksPublicKey::from_private(sk)],
274-
)
275-
.unwrap()
269+
StacksAddress::p2pkh(false, &StacksPublicKey::from_private(sk))
276270
}
277271

278272
pub fn make_stacks_transfer(

stackslib/src/core/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ use crate::core::mempool::{
6565
db_get_all_nonces, MemPoolSyncData, MemPoolWalkSettings, MemPoolWalkTxTypes, TxTag,
6666
BLOOM_COUNTER_DEPTH, BLOOM_COUNTER_ERROR_RATE, MAX_BLOOM_COUNTER_TXS,
6767
};
68-
use crate::core::util::{insert_tx_in_mempool, make_stacks_transfer, to_addr};
68+
use crate::core::test_util::{insert_tx_in_mempool, make_stacks_transfer, to_addr};
6969
use crate::core::{FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH};
7070
use crate::net::Error as NetError;
7171
use crate::util_lib::bloom::test::setup_bloom_counter;

stackslib/src/net/tests/download/nakamoto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::chainstate::stacks::{
4343
TransactionPayload, TransactionVersion,
4444
};
4545
use crate::clarity::vm::types::StacksAddressExtensions;
46-
use crate::core::util::to_addr;
46+
use crate::core::test_util::to_addr;
4747
use crate::net::api::gettenureinfo::RPCGetTenureInfo;
4848
use crate::net::download::nakamoto::{TenureStartEnd, WantedTenure, *};
4949
use crate::net::inv::nakamoto::NakamotoTenureInv;

stackslib/src/net/tests/inv/nakamoto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::chainstate::stacks::{
4343
TransactionAuth, TransactionPayload, TransactionVersion,
4444
};
4545
use crate::clarity::vm::types::StacksAddressExtensions;
46-
use crate::core::util::to_addr;
46+
use crate::core::test_util::to_addr;
4747
use crate::core::StacksEpochExtension;
4848
use crate::net::inv::nakamoto::{InvGenerator, NakamotoInvStateMachine, NakamotoTenureInv};
4949
use crate::net::neighbors::comms::NeighborComms;

stackslib/src/net/tests/mempool/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::burnchains::*;
3232
use crate::chainstate::nakamoto::coordinator::tests::make_token_transfer;
3333
use crate::chainstate::stacks::test::*;
3434
use crate::chainstate::stacks::*;
35-
use crate::core::util::to_addr;
35+
use crate::core::test_util::to_addr;
3636
use crate::core::StacksEpochExtension;
3737
use crate::net::atlas::*;
3838
use crate::net::codec::*;

testnet/stacks-node/src/tests/epoch_205.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use stacks::chainstate::stacks::{
1414
StacksBlockHeader, StacksPrivateKey, StacksTransaction, TransactionPayload,
1515
};
1616
use stacks::config::{EventKeyType, InitialBalance};
17-
use stacks::core::util::{
17+
use stacks::core::test_util::{
1818
make_contract_call, make_contract_call_mblock_only, make_contract_publish,
1919
make_contract_publish_microblock_only, to_addr,
2020
};

0 commit comments

Comments
 (0)