@@ -32,12 +32,21 @@ namespace miner_tests {
3232struct MinerTestingSetup : public TestingSetup {
3333 void TestPackageSelection (const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs);
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);
35- void TestPrioritisedMining (const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs );
35+ 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)
3737 {
3838 CCoinsViewMemPool view_mempool (&m_node.chainman ->ActiveChainstate ().CoinsTip (), *m_node.mempool );
3939 return CheckSequenceLocksAtTip (m_node.chainman ->ActiveChain ().Tip (), view_mempool, tx);
4040 }
41+ CTxMemPool& MakeMempool ()
42+ {
43+ // Delete the previous mempool to ensure with valgrind that the old
44+ // pointer is not accessed, when the new one should be accessed
45+ // instead.
46+ m_node.mempool .reset ();
47+ m_node.mempool = std::make_unique<CTxMemPool>(MemPoolOptionsForTest (m_node));
48+ return *m_node.mempool ;
49+ }
4150 BlockAssembler AssemblerForTest (CTxMemPool& tx_mempool);
4251};
4352} // namespace miner_tests
@@ -476,9 +485,10 @@ void MinerTestingSetup::TestBasicMining(const CChainParams& chainparams, const C
476485 BOOST_CHECK_EQUAL (pblocktemplate->block .vtx .size (), 5U );
477486}
478487
479- void MinerTestingSetup::TestPrioritisedMining (const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst)
488+ void MinerTestingSetup::TestPrioritisedMining (const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst)
480489{
481- CTxMemPool& tx_mempool{*m_node.mempool };
490+ CTxMemPool& tx_mempool{MakeMempool ()};
491+ LOCK (tx_mempool.cs );
482492
483493 TestMemPoolEntryHelper entry;
484494
@@ -491,29 +501,29 @@ void MinerTestingSetup::TestPrioritisedMining(const CChainParams& chainparams, c
491501 tx.vout .resize (1 );
492502 tx.vout [0 ].nValue = 5000000000LL ; // 0 fee
493503 uint256 hashFreePrioritisedTx = tx.GetHash ();
494- m_node. mempool -> addUnchecked (entry.Fee (0 ).Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
495- m_node. mempool -> PrioritiseTransaction (hashFreePrioritisedTx, 5 * COIN);
504+ tx_mempool. addUnchecked (entry.Fee (0 ).Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
505+ tx_mempool. PrioritiseTransaction (hashFreePrioritisedTx, 5 * COIN);
496506
497507 tx.vin [0 ].prevout .hash = txFirst[1 ]->GetHash ();
498508 tx.vin [0 ].prevout .n = 0 ;
499509 tx.vout [0 ].nValue = 5000000000LL - 1000 ;
500510 // This tx has a low fee: 1000 satoshis
501511 uint256 hashParentTx = tx.GetHash (); // save this txid for later use
502- m_node. mempool -> addUnchecked (entry.Fee (1000 ).Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
512+ tx_mempool. addUnchecked (entry.Fee (1000 ).Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
503513
504514 // This tx has a medium fee: 10000 satoshis
505515 tx.vin [0 ].prevout .hash = txFirst[2 ]->GetHash ();
506516 tx.vout [0 ].nValue = 5000000000LL - 10000 ;
507517 uint256 hashMediumFeeTx = tx.GetHash ();
508- m_node. mempool -> addUnchecked (entry.Fee (10000 ).Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
509- m_node. mempool -> PrioritiseTransaction (hashMediumFeeTx, -5 * COIN);
518+ tx_mempool. addUnchecked (entry.Fee (10000 ).Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
519+ tx_mempool. PrioritiseTransaction (hashMediumFeeTx, -5 * COIN);
510520
511521 // This tx also has a low fee, but is prioritised
512522 tx.vin [0 ].prevout .hash = hashParentTx;
513523 tx.vout [0 ].nValue = 5000000000LL - 1000 - 1000 ; // 1000 satoshi fee
514524 uint256 hashPrioritsedChild = tx.GetHash ();
515- m_node. mempool -> addUnchecked (entry.Fee (1000 ).Time (GetTime ()).SpendsCoinbase (false ).FromTx (tx));
516- m_node. mempool -> PrioritiseTransaction (hashPrioritsedChild, 2 * COIN);
525+ tx_mempool. addUnchecked (entry.Fee (1000 ).Time (GetTime ()).SpendsCoinbase (false ).FromTx (tx));
526+ tx_mempool. PrioritiseTransaction (hashPrioritsedChild, 2 * COIN);
517527
518528 // Test that transaction selection properly updates ancestor fee calculations as prioritised
519529 // parents get included in a block. Create a transaction with two prioritised ancestors, each
@@ -524,19 +534,19 @@ void MinerTestingSetup::TestPrioritisedMining(const CChainParams& chainparams, c
524534 tx.vin [0 ].prevout .hash = txFirst[3 ]->GetHash ();
525535 tx.vout [0 ].nValue = 5000000000LL ; // 0 fee
526536 uint256 hashFreeParent = tx.GetHash ();
527- m_node. mempool -> addUnchecked (entry.Fee (0 ).SpendsCoinbase (true ).FromTx (tx));
528- m_node. mempool -> PrioritiseTransaction (hashFreeParent, 10 * COIN);
537+ tx_mempool. addUnchecked (entry.Fee (0 ).SpendsCoinbase (true ).FromTx (tx));
538+ tx_mempool. PrioritiseTransaction (hashFreeParent, 10 * COIN);
529539
530540 tx.vin [0 ].prevout .hash = hashFreeParent;
531541 tx.vout [0 ].nValue = 5000000000LL ; // 0 fee
532542 uint256 hashFreeChild = tx.GetHash ();
533- m_node. mempool -> addUnchecked (entry.Fee (0 ).SpendsCoinbase (false ).FromTx (tx));
534- m_node. mempool -> PrioritiseTransaction (hashFreeChild, 1 * COIN);
543+ tx_mempool. addUnchecked (entry.Fee (0 ).SpendsCoinbase (false ).FromTx (tx));
544+ tx_mempool. PrioritiseTransaction (hashFreeChild, 1 * COIN);
535545
536546 tx.vin [0 ].prevout .hash = hashFreeChild;
537547 tx.vout [0 ].nValue = 5000000000LL ; // 0 fee
538548 uint256 hashFreeGrandchild = tx.GetHash ();
539- m_node. mempool -> addUnchecked (entry.Fee (0 ).SpendsCoinbase (false ).FromTx (tx));
549+ tx_mempool. addUnchecked (entry.Fee (0 ).SpendsCoinbase (false ).FromTx (tx));
540550
541551 auto pblocktemplate = AssemblerForTest (tx_mempool).CreateNewBlock (scriptPubKey);
542552 BOOST_REQUIRE_EQUAL (pblocktemplate->block .vtx .size (), 6U );
@@ -608,9 +618,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
608618
609619 m_node.chainman ->ActiveChain ().Tip ()->nHeight --;
610620 SetMockTime (0 );
611- m_node.mempool ->clear ();
612621
613- TestPrioritisedMining (chainparams, scriptPubKey, txFirst);
622+ TestPrioritisedMining (scriptPubKey, txFirst);
614623}
615624
616625BOOST_AUTO_TEST_SUITE_END ()
0 commit comments