| 682 | } |
| 683 | |
| 684 | void MinerTestingSetup::TestPrioritisedMining(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) |
| 685 | { |
| 686 | auto mining{MakeMining()}; |
| 687 | BOOST_REQUIRE(mining); |
| 688 | |
| 689 | BlockCreateOptions options{ |
| 690 | .coinbase_output_script = scriptPubKey, |
| 691 | }; |
| 692 | |
| 693 | CTxMemPool& tx_mempool{MakeMempool()}; |
| 694 | LOCK(tx_mempool.cs); |
| 695 | |
| 696 | TestMemPoolEntryHelper entry; |
| 697 | |
| 698 | // Test that a tx below min fee but prioritised is included |
| 699 | CMutableTransaction tx; |
| 700 | tx.vin.resize(1); |
| 701 | tx.vin[0].prevout.hash = txFirst[0]->GetHash(); |
| 702 | tx.vin[0].prevout.n = 0; |
| 703 | tx.vin[0].scriptSig = CScript() << OP_1; |
| 704 | tx.vout.resize(1); |
| 705 | tx.vout[0].nValue = 5000000000LL; // 0 fee |
| 706 | Txid hashFreePrioritisedTx = tx.GetHash(); |
| 707 | TryAddToMempool(tx_mempool, entry.Fee(0).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx)); |
| 708 | tx_mempool.PrioritiseTransaction(hashFreePrioritisedTx, 5 * COIN); |
| 709 | |
| 710 | tx.vin[0].prevout.hash = txFirst[1]->GetHash(); |
| 711 | tx.vin[0].prevout.n = 0; |
| 712 | tx.vout[0].nValue = 5000000000LL - 1000; |
| 713 | // This tx has a low fee: 1000 satoshis |
| 714 | Txid hashParentTx = tx.GetHash(); // save this txid for later use |
| 715 | TryAddToMempool(tx_mempool, entry.Fee(1000).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx)); |
| 716 | |
| 717 | // This tx has a medium fee: 10000 satoshis |
| 718 | tx.vin[0].prevout.hash = txFirst[2]->GetHash(); |
| 719 | tx.vout[0].nValue = 5000000000LL - 10000; |
| 720 | Txid hashMediumFeeTx = tx.GetHash(); |
| 721 | TryAddToMempool(tx_mempool, entry.Fee(10000).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx)); |
| 722 | tx_mempool.PrioritiseTransaction(hashMediumFeeTx, -5 * COIN); |
| 723 | |
| 724 | // This tx also has a low fee, but is prioritised |
| 725 | tx.vin[0].prevout.hash = hashParentTx; |
| 726 | tx.vout[0].nValue = 5000000000LL - 1000 - 1000; // 1000 satoshi fee |
| 727 | Txid hashPrioritsedChild = tx.GetHash(); |
| 728 | TryAddToMempool(tx_mempool, entry.Fee(1000).Time(Now<NodeSeconds>()).SpendsCoinbase(false).FromTx(tx)); |
| 729 | tx_mempool.PrioritiseTransaction(hashPrioritsedChild, 2 * COIN); |
| 730 | |
| 731 | // Test that transaction selection properly updates ancestor fee calculations as prioritised |
| 732 | // parents get included in a block. Create a transaction with two prioritised ancestors, each |
| 733 | // included by itself: FreeParent <- FreeChild <- FreeGrandchild. |
| 734 | // When FreeParent is added, a modified entry will be created for FreeChild + FreeGrandchild |
| 735 | // FreeParent's prioritisation should not be included in that entry. |
| 736 | // When FreeChild is included, FreeChild's prioritisation should also not be included. |
| 737 | tx.vin[0].prevout.hash = txFirst[3]->GetHash(); |
| 738 | tx.vout[0].nValue = 5000000000LL; // 0 fee |
| 739 | Txid hashFreeParent = tx.GetHash(); |
| 740 | TryAddToMempool(tx_mempool, entry.Fee(0).SpendsCoinbase(true).FromTx(tx)); |
| 741 | tx_mempool.PrioritiseTransaction(hashFreeParent, 10 * COIN); |
nothing calls this directly
no test coverage detected