1616#include < txmempool.h>
1717#include < uint256.h>
1818#include < util/check.h>
19+ #include < util/feefrac.h>
1920#include < util/strencodings.h>
2021#include < util/time.h>
2122#include < util/translation.h>
2526#include < test/util/setup_common.h>
2627
2728#include < memory>
29+ #include < vector>
2830
2931#include < boost/test/unit_test.hpp>
3032
@@ -123,19 +125,22 @@ void MinerTestingSetup::TestPackageSelection(const CScript& scriptPubKey, const
123125 tx.vout [0 ].nValue = 5000000000LL - 1000 ;
124126 // This tx has a low fee: 1000 satoshis
125127 Txid hashParentTx = tx.GetHash (); // save this txid for later use
126- AddToMempool (tx_mempool, entry.Fee (1000 ).Time (Now<NodeSeconds>()).SpendsCoinbase (true ).FromTx (tx));
128+ const auto parent_tx{entry.Fee (1000 ).Time (Now<NodeSeconds>()).SpendsCoinbase (true ).FromTx (tx)};
129+ AddToMempool (tx_mempool, parent_tx);
127130
128131 // This tx has a medium fee: 10000 satoshis
129132 tx.vin [0 ].prevout .hash = txFirst[1 ]->GetHash ();
130133 tx.vout [0 ].nValue = 5000000000LL - 10000 ;
131134 Txid hashMediumFeeTx = tx.GetHash ();
132- AddToMempool (tx_mempool, entry.Fee (10000 ).Time (Now<NodeSeconds>()).SpendsCoinbase (true ).FromTx (tx));
135+ const auto medium_fee_tx{entry.Fee (10000 ).Time (Now<NodeSeconds>()).SpendsCoinbase (true ).FromTx (tx)};
136+ AddToMempool (tx_mempool, medium_fee_tx);
133137
134138 // This tx has a high fee, but depends on the first transaction
135139 tx.vin [0 ].prevout .hash = hashParentTx;
136140 tx.vout [0 ].nValue = 5000000000LL - 1000 - 50000 ; // 50k satoshi fee
137141 Txid hashHighFeeTx = tx.GetHash ();
138- AddToMempool (tx_mempool, entry.Fee (50000 ).Time (Now<NodeSeconds>()).SpendsCoinbase (false ).FromTx (tx));
142+ const auto high_fee_tx{entry.Fee (50000 ).Time (Now<NodeSeconds>()).SpendsCoinbase (false ).FromTx (tx)};
143+ AddToMempool (tx_mempool, high_fee_tx);
139144
140145 std::unique_ptr<BlockTemplate> block_template = mining->createNewBlock (options);
141146 BOOST_REQUIRE (block_template);
@@ -145,6 +150,21 @@ void MinerTestingSetup::TestPackageSelection(const CScript& scriptPubKey, const
145150 BOOST_CHECK (block.vtx [2 ]->GetHash () == hashHighFeeTx);
146151 BOOST_CHECK (block.vtx [3 ]->GetHash () == hashMediumFeeTx);
147152
153+ // Test the inclusion of package feerates in the block template and ensure they are sequential.
154+ const auto block_package_feerates = BlockAssembler{m_node.chainman ->ActiveChainstate (), &tx_mempool, options}.CreateNewBlock ()->m_package_feerates ;
155+ BOOST_CHECK (block_package_feerates.size () == 2 );
156+
157+ // parent_tx and high_fee_tx are added to the block as a package.
158+ const auto combined_txs_fee = parent_tx.GetFee () + high_fee_tx.GetFee ();
159+ const auto combined_txs_size = parent_tx.GetTxSize () + high_fee_tx.GetTxSize ();
160+ FeeFrac package_feefrac{combined_txs_fee, combined_txs_size};
161+ // The package should be added first.
162+ BOOST_CHECK (block_package_feerates[0 ] == package_feefrac);
163+
164+ // The medium_fee_tx should be added next.
165+ FeeFrac medium_tx_feefrac{medium_fee_tx.GetFee (), medium_fee_tx.GetTxSize ()};
166+ BOOST_CHECK (block_package_feerates[1 ] == medium_tx_feefrac);
167+
148168 // Test that a package below the block min tx fee doesn't get included
149169 tx.vin [0 ].prevout .hash = hashHighFeeTx;
150170 tx.vout [0 ].nValue = 5000000000LL - 1000 - 50000 ; // 0 fee
0 commit comments