v30.3-roots.1 · Commit 31: [PATCH 31/68] 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 08fc1227939bb56871206d54d46dab78f4ca7a0c..3869aa2debba0b5d8aa563127fb0d31020fb38dd 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
|
@@ -40,6 +40,7 @@ using node::BlockAssembler;
|
|
|
40
40
|
namespace miner_tests {
|
|
41
41
|
struct MinerTestingSetup : public TestingSetup {
|
|
42
42
|
void TestPackageSelection(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
|
43
|
+
void TestPriorityPhaseStaleAncestors(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
|
43
44
|
void TestBasicMining(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst, int baseheight) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
|
44
45
|
void TestPrioritisedMining(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
|
45
46
|
bool TestSequenceLocks(const CTransaction& tx, CTxMemPool& tx_mempool) EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
|
|
@@ -692,6 +693,47 @@ void MinerTestingSetup::TestPrioritisedMining(const CScript& scriptPubKey, const
|
|
|
692
693
|
}
|
|
693
694
|
}
|
|
694
695
|
|
|
696
|
+
// A transaction added by the coin-age priority phase must not keep subsidising
|
|
697
|
+
// its descendants in the ancestor-feerate phase.
|
|
698
|
+
//
|
|
699
|
+
// Test entries have no coin-age priority, so the priority phase ranks them by
|
|
700
|
+
// fee score, adds the fee-paying parent (the child still depends on it), and
|
|
701
|
+
// then stops at MINIMUM_TX_PRIORITY. The child pays no fee and must not be
|
|
702
|
+
// selected on the strength of its already-included parent's fee.
|
|
703
|
+
void MinerTestingSetup::TestPriorityPhaseStaleAncestors(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst)
|
|
704
|
+
{
|
|
705
|
+
CTxMemPool& tx_mempool{MakeMempool()};
|
|
706
|
+
BlockAssembler::Options options;
|
|
707
|
+
options.coinbase_output_script = scriptPubKey;
|
|
708
|
+
gArgs.ForceSetArg("-blockprioritysize", "100000");
|
|
709
|
+
|
|
710
|
+
LOCK(tx_mempool.cs);
|
|
711
|
+
TestMemPoolEntryHelper entry;
|
|
712
|
+
|
|
713
|
+
CMutableTransaction tx;
|
|
714
|
+
tx.vin.resize(1);
|
|
715
|
+
tx.vin[0].scriptSig = CScript() << OP_1;
|
|
716
|
+
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
|
|
717
|
+
tx.vin[0].prevout.n = 0;
|
|
718
|
+
tx.vout.resize(1);
|
|
719
|
+
tx.vout[0].nValue = 5000000000LL - 100000;
|
|
720
|
+
const Txid parent_txid = tx.GetHash();
|
|
721
|
+
AddToMempool(tx_mempool, entry.Fee(100000).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
|
|
722
|
+
|
|
723
|
+
tx.vin[0].prevout.hash = parent_txid;
|
|
724
|
+
const Txid child_txid = tx.GetHash();
|
|
725
|
+
AddToMempool(tx_mempool, entry.Fee(0).SpendsCoinbase(false).FromTx(tx));
|
|
726
|
+
|
|
727
|
+
const auto block_template = BlockAssembler{m_node.chainman->ActiveChainstate(), &tx_mempool, options}.CreateNewBlock();
|
|
728
|
+
BOOST_REQUIRE(block_template);
|
|
729
|
+
const CBlock& block{block_template->block};
|
|
730
|
+
BOOST_CHECK_EQUAL(block.vtx.size(), 2U);
|
|
731
|
+
BOOST_CHECK(block.vtx[1]->GetHash() == parent_txid);
|
|
732
|
+
for (const auto& btx : block.vtx) BOOST_CHECK(btx->GetHash() != child_txid);
|
|
733
|
+
|
|
734
|
+
gArgs.ForceSetArg("-blockprioritysize", "0");
|
|
735
|
+
}
|
|
736
|
+
|
|
695
737
|
// NOTE: These tests rely on CreateNewBlock doing its own self-validation!
|
|
696
738
|
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
697
739
|
{
|
|
@@ -812,6 +854,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
|
812
854
|
SetMockTime(0);
|
|
813
855
|
|
|
814
856
|
TestPackageSelection(scriptPubKey, txFirst);
|
|
857
|
+
TestPriorityPhaseStaleAncestors(scriptPubKey, txFirst);
|
|
815
858
|
|
|
816
859
|
m_node.chainman->ActiveChain().Tip()->nHeight--;
|
|
817
860
|
SetMockTime(0);
|