Skip to content

Commit

Permalink
Merge bitcoin#29013: test: doc: follow-up bitcoin#28368
Browse files Browse the repository at this point in the history
b1318dc test: change `m_submitted_in_package` input to fuzz data provider boolean (ismaelsadeeq)
5615e16 tx fees: update `m_from_disconnected_block` to `m_mempool_limit_bypassed` (ismaelsadeeq)
fcd4296 doc: fix typo and update incorrect comment (ismaelsadeeq)
562664d test: wait for fee estimator to catch up before estimating fees (ismaelsadeeq)

Pull request description:

  This is a simple PR that does two things
  1.   Fixes bitcoin#29000 by waiting for the fee estimator to catch up after `removeForBlock` calls before calling `estimateFee` in the `BlockPolicyEstimates` unit test.

  2. Addressed some outstanding review comments from bitcoin#28368
  - Updated `NewMempoolTransactionInfo::m_from_disconnected_block` to `NewMempoolTransactionInfo::m_mempool_limit_bypassed` which now correctly indicates what the boolean does.
  - Changed  input of `processTransaction`'s tx_info  `m_submitted_in_package` input from false to fuzz data provider boolean.
  - Fixed some typos, and update incorrect comment

ACKs for top commit:
  martinus:
    re-ACK b1318dc
  glozow:
    utACK b1318dc

Tree-SHA512: 45268729bc044da4748fe004524e0df696d2ec92c5bd053db9aad6e15675f3838429b2a7b9061a6b694be4dc319d1782a876b44df506ddd439d62ad07252d0e1
  • Loading branch information
glozow committed Jan 3, 2024
2 parents c3038bf + b1318dc commit 65c05db
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ void Shutdown(NodeContext& node)
DumpMempool(*node.mempool, MempoolPath(*node.args));
}

// Drop transactions we were still watching, record fee estimations and Unregister
// Drop transactions we were still watching, record fee estimations and unregister
// fee estimator from validation interface.
if (node.fee_estimator) {
node.fee_estimator->Flush();
Expand Down
6 changes: 3 additions & 3 deletions src/kernel/mempool_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ struct NewMempoolTransactionInfo {
* This boolean indicates whether the transaction was added
* without enforcing mempool fee limits.
*/
const bool m_from_disconnected_block;
const bool m_mempool_limit_bypassed;
/* This boolean indicates whether the transaction is part of a package. */
const bool m_submitted_in_package;
/*
Expand All @@ -239,11 +239,11 @@ struct NewMempoolTransactionInfo {

explicit NewMempoolTransactionInfo(const CTransactionRef& tx, const CAmount& fee,
const int64_t vsize, const unsigned int height,
const bool from_disconnected_block, const bool submitted_in_package,
const bool mempool_limit_bypassed, const bool submitted_in_package,
const bool chainstate_is_current,
const bool has_no_mempool_parents)
: info{tx, fee, vsize, height},
m_from_disconnected_block{from_disconnected_block},
m_mempool_limit_bypassed{mempool_limit_bypassed},
m_submitted_in_package{submitted_in_package},
m_chainstate_is_current{chainstate_is_current},
m_has_no_mempool_parents{has_no_mempool_parents} {}
Expand Down
2 changes: 1 addition & 1 deletion src/policy/fees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ void CBlockPolicyEstimator::processTransaction(const NewMempoolTransactionInfo&
// - the node is not behind
// - the transaction is not dependent on any other transactions in the mempool
// - it's not part of a package.
const bool validForFeeEstimation = !tx.m_from_disconnected_block && !tx.m_submitted_in_package && tx.m_chainstate_is_current && tx.m_has_no_mempool_parents;
const bool validForFeeEstimation = !tx.m_mempool_limit_bypassed && !tx.m_submitted_in_package && tx.m_chainstate_is_current && tx.m_has_no_mempool_parents;

// Only want to be updating estimates when our blockchain is synced,
// otherwise we'll miscalculate how many blocks its taking to get included.
Expand Down
10 changes: 6 additions & 4 deletions src/test/fuzz/policy_estimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ FUZZ_TARGET(policy_estimator, .init = initialize_policy_estimator)
}
const CTransaction tx{*mtx};
const CTxMemPoolEntry& entry = ConsumeTxMemPoolEntry(fuzzed_data_provider, tx);
const auto tx_submitted_in_package = fuzzed_data_provider.ConsumeBool();
const auto tx_has_mempool_parents = fuzzed_data_provider.ConsumeBool();
const auto tx_info = NewMempoolTransactionInfo(entry.GetSharedTx(), entry.GetFee(),
entry.GetTxSize(), entry.GetHeight(),
/* m_from_disconnected_block */ false,
/* m_submitted_in_package */ false,
/* m_chainstate_is_current */ true,
/* m_has_no_mempool_parents */ fuzzed_data_provider.ConsumeBool());
/*mempool_limit_bypassed=*/false,
tx_submitted_in_package,
/*chainstate_is_current=*/true,
tx_has_mempool_parents);
block_policy_estimator.processTransaction(tx_info);
if (fuzzed_data_provider.ConsumeBool()) {
(void)block_policy_estimator.removeTx(tx.GetHash());
Expand Down
27 changes: 15 additions & 12 deletions src/test/policyestimator_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
feeV[j],
virtual_size,
entry.nHeight,
/* m_from_disconnected_block */ false,
/* m_submitted_in_package */ false,
/* m_chainstate_is_current */ true,
/* m_has_no_mempool_parents */ true)};
/*mempool_limit_bypassed=*/false,
/*submitted_in_package=*/false,
/*chainstate_is_current=*/true,
/*has_no_mempool_parents=*/true)};
GetMainSignals().TransactionAddedToMempool(tx_info, mpool.GetAndIncrementSequence());
}
uint256 hash = tx.GetHash();
Expand Down Expand Up @@ -112,6 +112,9 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
}
}

// Wait for fee estimator to catch up
SyncWithValidationInterfaceQueue();

std::vector<CAmount> origFeeEst;
// Highest feerate is 10*baseRate and gets in all blocks,
// second highest feerate is 9*baseRate and gets in 9/10 blocks = 90%,
Expand Down Expand Up @@ -168,10 +171,10 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
feeV[j],
virtual_size,
entry.nHeight,
/* m_from_disconnected_block */ false,
/* m_submitted_in_package */ false,
/* m_chainstate_is_current */ true,
/* m_has_no_mempool_parents */ true)};
/*mempool_limit_bypassed=*/false,
/*submitted_in_package=*/false,
/*chainstate_is_current=*/true,
/*has_no_mempool_parents=*/true)};
GetMainSignals().TransactionAddedToMempool(tx_info, mpool.GetAndIncrementSequence());
}
uint256 hash = tx.GetHash();
Expand Down Expand Up @@ -232,10 +235,10 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
feeV[j],
virtual_size,
entry.nHeight,
/* m_from_disconnected_block */ false,
/* m_submitted_in_package */ false,
/* m_chainstate_is_current */ true,
/* m_has_no_mempool_parents */ true)};
/*mempool_limit_bypassed=*/false,
/*submitted_in_package=*/false,
/*chainstate_is_current=*/true,
/*has_no_mempool_parents=*/true)};
GetMainSignals().TransactionAddedToMempool(tx_info, mpool.GetAndIncrementSequence());
}
uint256 hash = tx.GetHash();
Expand Down
2 changes: 1 addition & 1 deletion src/validationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class CValidationInterface {
virtual void BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex) {}
/**
* Notifies listeners of a block being disconnected
* Provides the block that was connected.
* Provides the block that was disconnected.
*
* Called on a background thread. Only called for the active chainstate, since
* background chainstates should never disconnect blocks.
Expand Down

0 comments on commit 65c05db

Please sign in to comment.