v29.4-roots.4 · Commit 31: [PATCH 31/37] fix(mining): account for priority-selected ancestors
src/test/miner_tests.cpp
Before: src/test/miner_tests.cpp · After: src/test/miner_tests.cpp
File metadata
index 8a8b9344957722e887c034f8c53952ad51651581..d84cb97e2465dc55ac32a5929bae5b76ee4f7b6b 100644
Download original patch · Release notes
Diff rows 1–61 of 61. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
src/test/miner_tests.cpp
CHANGED
|
@@ -39,6 +39,7 @@ using node::BlockAssembler;
|
|
|
39
39
|
namespace miner_tests {
|
|
40
40
|
struct MinerTestingSetup : public TestingSetup {
|
|
41
41
|
void TestPackageSelection(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
|
42
|
+
void TestPriorityPhaseStaleAncestors(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
|
42
43
|
void TestBasicMining(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst, int baseheight) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
|
43
44
|
void TestPrioritisedMining(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
|
44
45
|
bool TestSequenceLocks(const CTransaction& tx, CTxMemPool& tx_mempool) EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
|
|
@@ -665,6 +666,47 @@ void MinerTestingSetup::TestPrioritisedMining(const CScript& scriptPubKey, const
|
|
|
665
666
|
}
|
|
666
667
|
}
|
|
667
668
|
|
|
669
|
+
// A transaction added by the coin-age priority phase must not keep subsidising
|
|
670
|
+
// its descendants in the ancestor-feerate phase.
|
|
671
|
+
//
|
|
672
|
+
// Test entries have no coin-age priority, so the priority phase ranks them by
|
|
673
|
+
// fee score, adds the fee-paying parent (the child still depends on it), and
|
|
674
|
+
// then stops at MINIMUM_TX_PRIORITY. The child pays no fee and must not be
|
|
675
|
+
// selected on the strength of its already-included parent's fee.
|
|
676
|
+
void MinerTestingSetup::TestPriorityPhaseStaleAncestors(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst)
|
|
677
|
+
{
|
|
678
|
+
CTxMemPool& tx_mempool{MakeMempool()};
|
|
679
|
+
BlockAssembler::Options options;
|
|
680
|
+
options.coinbase_output_script = scriptPubKey;
|
|
681
|
+
gArgs.ForceSetArg("-blockprioritysize", "100000");
|
|
682
|
+
|
|
683
|
+
LOCK(tx_mempool.cs);
|
|
684
|
+
TestMemPoolEntryHelper entry;
|
|
685
|
+
|
|
686
|
+
CMutableTransaction tx;
|
|
687
|
+
tx.vin.resize(1);
|
|
688
|
+
tx.vin[0].scriptSig = CScript() << OP_1;
|
|
689
|
+
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
|
|
690
|
+
tx.vin[0].prevout.n = 0;
|
|
691
|
+
tx.vout.resize(1);
|
|
692
|
+
tx.vout[0].nValue = 5000000000LL - 100000;
|
|
693
|
+
const Txid parent_txid = tx.GetHash();
|
|
694
|
+
AddToMempool(tx_mempool, entry.Fee(100000).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
|
|
695
|
+
|
|
696
|
+
tx.vin[0].prevout.hash = parent_txid;
|
|
697
|
+
const Txid child_txid = tx.GetHash();
|
|
698
|
+
AddToMempool(tx_mempool, entry.Fee(0).SpendsCoinbase(false).FromTx(tx));
|
|
699
|
+
|
|
700
|
+
const auto block_template = BlockAssembler{m_node.chainman->ActiveChainstate(), &tx_mempool, options}.CreateNewBlock();
|
|
701
|
+
BOOST_REQUIRE(block_template);
|
|
702
|
+
const CBlock& block{block_template->block};
|
|
703
|
+
BOOST_CHECK_EQUAL(block.vtx.size(), 2U);
|
|
704
|
+
BOOST_CHECK(block.vtx[1]->GetHash() == parent_txid);
|
|
705
|
+
for (const auto& btx : block.vtx) BOOST_CHECK(btx->GetHash() != child_txid);
|
|
706
|
+
|
|
707
|
+
gArgs.ForceSetArg("-blockprioritysize", "0");
|
|
708
|
+
}
|
|
709
|
+
|
|
668
710
|
// NOTE: These tests rely on CreateNewBlock doing its own self-validation!
|
|
669
711
|
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
670
712
|
{
|
|
@@ -737,6 +779,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
|
737
779
|
SetMockTime(0);
|
|
738
780
|
|
|
739
781
|
TestPackageSelection(scriptPubKey, txFirst);
|
|
782
|
+
TestPriorityPhaseStaleAncestors(scriptPubKey, txFirst);
|
|
740
783
|
|
|
741
784
|
m_node.chainman->ActiveChain().Tip()->nHeight--;
|
|
742
785
|
SetMockTime(0);
|