@@ -32,12 +32,21 @@ namespace miner_tests {
32
32
struct MinerTestingSetup : public TestingSetup {
33
33
void TestPackageSelection (const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs);
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
- 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);
36
36
bool TestSequenceLocks (const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs)
37
37
{
38
38
CCoinsViewMemPool view_mempool (&m_node.chainman ->ActiveChainstate ().CoinsTip (), *m_node.mempool );
39
39
return CheckSequenceLocksAtTip (m_node.chainman ->ActiveChain ().Tip (), view_mempool, tx);
40
40
}
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
+ }
41
50
BlockAssembler AssemblerForTest (CTxMemPool& tx_mempool);
42
51
};
43
52
} // namespace miner_tests
@@ -476,9 +485,10 @@ void MinerTestingSetup::TestBasicMining(const CChainParams& chainparams, const C
476
485
BOOST_CHECK_EQUAL (pblocktemplate->block .vtx .size (), 5U );
477
486
}
478
487
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)
480
489
{
481
- CTxMemPool& tx_mempool{*m_node.mempool };
490
+ CTxMemPool& tx_mempool{MakeMempool ()};
491
+ LOCK (tx_mempool.cs );
482
492
483
493
TestMemPoolEntryHelper entry;
484
494
@@ -491,29 +501,29 @@ void MinerTestingSetup::TestPrioritisedMining(const CChainParams& chainparams, c
491
501
tx.vout .resize (1 );
492
502
tx.vout [0 ].nValue = 5000000000LL ; // 0 fee
493
503
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);
496
506
497
507
tx.vin [0 ].prevout .hash = txFirst[1 ]->GetHash ();
498
508
tx.vin [0 ].prevout .n = 0 ;
499
509
tx.vout [0 ].nValue = 5000000000LL - 1000 ;
500
510
// This tx has a low fee: 1000 satoshis
501
511
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));
503
513
504
514
// This tx has a medium fee: 10000 satoshis
505
515
tx.vin [0 ].prevout .hash = txFirst[2 ]->GetHash ();
506
516
tx.vout [0 ].nValue = 5000000000LL - 10000 ;
507
517
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);
510
520
511
521
// This tx also has a low fee, but is prioritised
512
522
tx.vin [0 ].prevout .hash = hashParentTx;
513
523
tx.vout [0 ].nValue = 5000000000LL - 1000 - 1000 ; // 1000 satoshi fee
514
524
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);
517
527
518
528
// Test that transaction selection properly updates ancestor fee calculations as prioritised
519
529
// 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
524
534
tx.vin [0 ].prevout .hash = txFirst[3 ]->GetHash ();
525
535
tx.vout [0 ].nValue = 5000000000LL ; // 0 fee
526
536
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);
529
539
530
540
tx.vin [0 ].prevout .hash = hashFreeParent;
531
541
tx.vout [0 ].nValue = 5000000000LL ; // 0 fee
532
542
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);
535
545
536
546
tx.vin [0 ].prevout .hash = hashFreeChild;
537
547
tx.vout [0 ].nValue = 5000000000LL ; // 0 fee
538
548
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));
540
550
541
551
auto pblocktemplate = AssemblerForTest (tx_mempool).CreateNewBlock (scriptPubKey);
542
552
BOOST_REQUIRE_EQUAL (pblocktemplate->block .vtx .size (), 6U );
@@ -608,9 +618,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
608
618
609
619
m_node.chainman ->ActiveChain ().Tip ()->nHeight --;
610
620
SetMockTime (0 );
611
- m_node.mempool ->clear ();
612
621
613
- TestPrioritisedMining (chainparams, scriptPubKey, txFirst);
622
+ TestPrioritisedMining (scriptPubKey, txFirst);
614
623
}
615
624
616
625
BOOST_AUTO_TEST_SUITE_END ()
0 commit comments