@@ -30,7 +30,7 @@ using node::CBlockTemplate;
30
30
31
31
namespace miner_tests {
32
32
struct 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);
34
34
void TestBasicMining (const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst, int baseheight) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs);
35
35
void TestPrioritisedMining (const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
36
36
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)
98
98
// Test suite for ancestor feerate transaction selection.
99
99
// Implemented as an additional function, rather than a separate test case,
100
100
// 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)
102
102
{
103
- CTxMemPool& tx_mempool{*m_node.mempool };
103
+ CTxMemPool& tx_mempool{MakeMempool ()};
104
+ LOCK (tx_mempool.cs );
104
105
// Test the ancestor feerate transaction selection.
105
106
TestMemPoolEntryHelper entry;
106
107
@@ -115,19 +116,19 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
115
116
tx.vout [0 ].nValue = 5000000000LL - 1000 ;
116
117
// This tx has a low fee: 1000 satoshis
117
118
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));
119
120
120
121
// This tx has a medium fee: 10000 satoshis
121
122
tx.vin [0 ].prevout .hash = txFirst[1 ]->GetHash ();
122
123
tx.vout [0 ].nValue = 5000000000LL - 10000 ;
123
124
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));
125
126
126
127
// This tx has a high fee, but depends on the first transaction
127
128
tx.vin [0 ].prevout .hash = hashParentTx;
128
129
tx.vout [0 ].nValue = 5000000000LL - 1000 - 50000 ; // 50k satoshi fee
129
130
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));
131
132
132
133
std::unique_ptr<CBlockTemplate> pblocktemplate = AssemblerForTest (tx_mempool).CreateNewBlock (scriptPubKey);
133
134
BOOST_REQUIRE_EQUAL (pblocktemplate->block .vtx .size (), 4U );
@@ -139,7 +140,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
139
140
tx.vin [0 ].prevout .hash = hashHighFeeTx;
140
141
tx.vout [0 ].nValue = 5000000000LL - 1000 - 50000 ; // 0 fee
141
142
uint256 hashFreeTx = tx.GetHash ();
142
- m_node. mempool -> addUnchecked (entry.Fee (0 ).FromTx (tx));
143
+ tx_mempool. addUnchecked (entry.Fee (0 ).FromTx (tx));
143
144
size_t freeTxSize = ::GetSerializeSize (tx, PROTOCOL_VERSION);
144
145
145
146
// Calculate a fee on child transaction that will put the package just
@@ -149,7 +150,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
149
150
tx.vin [0 ].prevout .hash = hashFreeTx;
150
151
tx.vout [0 ].nValue = 5000000000LL - 1000 - 50000 - feeToUse;
151
152
uint256 hashLowFeeTx = tx.GetHash ();
152
- m_node. mempool -> addUnchecked (entry.Fee (feeToUse).FromTx (tx));
153
+ tx_mempool. addUnchecked (entry.Fee (feeToUse).FromTx (tx));
153
154
pblocktemplate = AssemblerForTest (tx_mempool).CreateNewBlock (scriptPubKey);
154
155
// Verify that the free tx and the low fee tx didn't get selected
155
156
for (size_t i=0 ; i<pblocktemplate->block .vtx .size (); ++i) {
@@ -160,10 +161,10 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
160
161
// Test that packages above the min relay fee do get included, even if one
161
162
// of the transactions is below the min relay fee
162
163
// 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);
164
165
tx.vout [0 ].nValue -= 2 ; // Now we should be just over the min relay fee
165
166
hashLowFeeTx = tx.GetHash ();
166
- m_node. mempool -> addUnchecked (entry.Fee (feeToUse+ 2 ).FromTx (tx));
167
+ tx_mempool. addUnchecked (entry.Fee (feeToUse + 2 ).FromTx (tx));
167
168
pblocktemplate = AssemblerForTest (tx_mempool).CreateNewBlock (scriptPubKey);
168
169
BOOST_REQUIRE_EQUAL (pblocktemplate->block .vtx .size (), 6U );
169
170
BOOST_CHECK (pblocktemplate->block .vtx [4 ]->GetHash () == hashFreeTx);
@@ -177,15 +178,15 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
177
178
tx.vout [0 ].nValue = 5000000000LL - 100000000 ;
178
179
tx.vout [1 ].nValue = 100000000 ; // 1BTC output
179
180
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));
181
182
182
183
// This tx can't be mined by itself
183
184
tx.vin [0 ].prevout .hash = hashFreeTx2;
184
185
tx.vout .resize (1 );
185
186
feeToUse = blockMinFeeRate.GetFee (freeTxSize);
186
187
tx.vout [0 ].nValue = 5000000000LL - 100000000 - feeToUse;
187
188
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));
189
190
pblocktemplate = AssemblerForTest (tx_mempool).CreateNewBlock (scriptPubKey);
190
191
191
192
// Verify that this tx isn't selected.
@@ -198,7 +199,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
198
199
// as well.
199
200
tx.vin [0 ].prevout .n = 1 ;
200
201
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));
202
203
pblocktemplate = AssemblerForTest (tx_mempool).CreateNewBlock (scriptPubKey);
203
204
BOOST_REQUIRE_EQUAL (pblocktemplate->block .vtx .size (), 9U );
204
205
BOOST_CHECK (pblocktemplate->block .vtx [8 ]->GetHash () == hashLowFeeTx2);
@@ -612,9 +613,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
612
613
613
614
m_node.chainman ->ActiveChain ().Tip ()->nHeight --;
614
615
SetMockTime (0 );
615
- m_node.mempool ->clear ();
616
616
617
- TestPackageSelection (chainparams, scriptPubKey, txFirst);
617
+ TestPackageSelection (scriptPubKey, txFirst);
618
618
619
619
m_node.chainman ->ActiveChain ().Tip ()->nHeight --;
620
620
SetMockTime (0 );
0 commit comments