@@ -30,7 +30,7 @@ using node::CBlockTemplate;
3030
3131namespace miner_tests {
3232struct MinerTestingSetup : public TestingSetup {
33- void TestPackageSelection (const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs );
33+ void TestPackageSelection (const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
3434 void TestBasicMining (const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst, int baseheight) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs);
3535 void TestPrioritisedMining (const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
3636 bool TestSequenceLocks (const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs)
@@ -98,9 +98,10 @@ static CBlockIndex CreateBlockIndex(int nHeight, CBlockIndex* active_chain_tip)
9898// Test suite for ancestor feerate transaction selection.
9999// Implemented as an additional function, rather than a separate test case,
100100// to allow reusing the blockchain created in CreateNewBlock_validity.
101- void MinerTestingSetup::TestPackageSelection (const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst)
101+ void MinerTestingSetup::TestPackageSelection (const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst)
102102{
103- CTxMemPool& tx_mempool{*m_node.mempool };
103+ CTxMemPool& tx_mempool{MakeMempool ()};
104+ LOCK (tx_mempool.cs );
104105 // Test the ancestor feerate transaction selection.
105106 TestMemPoolEntryHelper entry;
106107
@@ -115,19 +116,19 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
115116 tx.vout [0 ].nValue = 5000000000LL - 1000 ;
116117 // This tx has a low fee: 1000 satoshis
117118 uint256 hashParentTx = tx.GetHash (); // save this txid for later use
118- m_node. mempool -> addUnchecked (entry.Fee (1000 ).Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
119+ tx_mempool. addUnchecked (entry.Fee (1000 ).Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
119120
120121 // This tx has a medium fee: 10000 satoshis
121122 tx.vin [0 ].prevout .hash = txFirst[1 ]->GetHash ();
122123 tx.vout [0 ].nValue = 5000000000LL - 10000 ;
123124 uint256 hashMediumFeeTx = tx.GetHash ();
124- m_node. mempool -> addUnchecked (entry.Fee (10000 ).Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
125+ tx_mempool. addUnchecked (entry.Fee (10000 ).Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
125126
126127 // This tx has a high fee, but depends on the first transaction
127128 tx.vin [0 ].prevout .hash = hashParentTx;
128129 tx.vout [0 ].nValue = 5000000000LL - 1000 - 50000 ; // 50k satoshi fee
129130 uint256 hashHighFeeTx = tx.GetHash ();
130- m_node. mempool -> addUnchecked (entry.Fee (50000 ).Time (GetTime ()).SpendsCoinbase (false ).FromTx (tx));
131+ tx_mempool. addUnchecked (entry.Fee (50000 ).Time (GetTime ()).SpendsCoinbase (false ).FromTx (tx));
131132
132133 std::unique_ptr<CBlockTemplate> pblocktemplate = AssemblerForTest (tx_mempool).CreateNewBlock (scriptPubKey);
133134 BOOST_REQUIRE_EQUAL (pblocktemplate->block .vtx .size (), 4U );
@@ -139,7 +140,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
139140 tx.vin [0 ].prevout .hash = hashHighFeeTx;
140141 tx.vout [0 ].nValue = 5000000000LL - 1000 - 50000 ; // 0 fee
141142 uint256 hashFreeTx = tx.GetHash ();
142- m_node. mempool -> addUnchecked (entry.Fee (0 ).FromTx (tx));
143+ tx_mempool. addUnchecked (entry.Fee (0 ).FromTx (tx));
143144 size_t freeTxSize = ::GetSerializeSize (tx, PROTOCOL_VERSION);
144145
145146 // Calculate a fee on child transaction that will put the package just
@@ -149,7 +150,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
149150 tx.vin [0 ].prevout .hash = hashFreeTx;
150151 tx.vout [0 ].nValue = 5000000000LL - 1000 - 50000 - feeToUse;
151152 uint256 hashLowFeeTx = tx.GetHash ();
152- m_node. mempool -> addUnchecked (entry.Fee (feeToUse).FromTx (tx));
153+ tx_mempool. addUnchecked (entry.Fee (feeToUse).FromTx (tx));
153154 pblocktemplate = AssemblerForTest (tx_mempool).CreateNewBlock (scriptPubKey);
154155 // Verify that the free tx and the low fee tx didn't get selected
155156 for (size_t i=0 ; i<pblocktemplate->block .vtx .size (); ++i) {
@@ -160,10 +161,10 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
160161 // Test that packages above the min relay fee do get included, even if one
161162 // of the transactions is below the min relay fee
162163 // Remove the low fee transaction and replace with a higher fee transaction
163- m_node. mempool -> removeRecursive (CTransaction (tx), MemPoolRemovalReason::REPLACED);
164+ tx_mempool. removeRecursive (CTransaction (tx), MemPoolRemovalReason::REPLACED);
164165 tx.vout [0 ].nValue -= 2 ; // Now we should be just over the min relay fee
165166 hashLowFeeTx = tx.GetHash ();
166- m_node. mempool -> addUnchecked (entry.Fee (feeToUse+ 2 ).FromTx (tx));
167+ tx_mempool. addUnchecked (entry.Fee (feeToUse + 2 ).FromTx (tx));
167168 pblocktemplate = AssemblerForTest (tx_mempool).CreateNewBlock (scriptPubKey);
168169 BOOST_REQUIRE_EQUAL (pblocktemplate->block .vtx .size (), 6U );
169170 BOOST_CHECK (pblocktemplate->block .vtx [4 ]->GetHash () == hashFreeTx);
@@ -177,15 +178,15 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
177178 tx.vout [0 ].nValue = 5000000000LL - 100000000 ;
178179 tx.vout [1 ].nValue = 100000000 ; // 1BTC output
179180 uint256 hashFreeTx2 = tx.GetHash ();
180- m_node. mempool -> addUnchecked (entry.Fee (0 ).SpendsCoinbase (true ).FromTx (tx));
181+ tx_mempool. addUnchecked (entry.Fee (0 ).SpendsCoinbase (true ).FromTx (tx));
181182
182183 // This tx can't be mined by itself
183184 tx.vin [0 ].prevout .hash = hashFreeTx2;
184185 tx.vout .resize (1 );
185186 feeToUse = blockMinFeeRate.GetFee (freeTxSize);
186187 tx.vout [0 ].nValue = 5000000000LL - 100000000 - feeToUse;
187188 uint256 hashLowFeeTx2 = tx.GetHash ();
188- m_node. mempool -> addUnchecked (entry.Fee (feeToUse).SpendsCoinbase (false ).FromTx (tx));
189+ tx_mempool. addUnchecked (entry.Fee (feeToUse).SpendsCoinbase (false ).FromTx (tx));
189190 pblocktemplate = AssemblerForTest (tx_mempool).CreateNewBlock (scriptPubKey);
190191
191192 // Verify that this tx isn't selected.
@@ -198,7 +199,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
198199 // as well.
199200 tx.vin [0 ].prevout .n = 1 ;
200201 tx.vout [0 ].nValue = 100000000 - 10000 ; // 10k satoshi fee
201- m_node. mempool -> addUnchecked (entry.Fee (10000 ).FromTx (tx));
202+ tx_mempool. addUnchecked (entry.Fee (10000 ).FromTx (tx));
202203 pblocktemplate = AssemblerForTest (tx_mempool).CreateNewBlock (scriptPubKey);
203204 BOOST_REQUIRE_EQUAL (pblocktemplate->block .vtx .size (), 9U );
204205 BOOST_CHECK (pblocktemplate->block .vtx [8 ]->GetHash () == hashLowFeeTx2);
@@ -612,9 +613,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
612613
613614 m_node.chainman ->ActiveChain ().Tip ()->nHeight --;
614615 SetMockTime (0 );
615- m_node.mempool ->clear ();
616616
617- TestPackageSelection (chainparams, scriptPubKey, txFirst);
617+ TestPackageSelection (scriptPubKey, txFirst);
618618
619619 m_node.chainman ->ActiveChain ().Tip ()->nHeight --;
620620 SetMockTime (0 );
0 commit comments