16
16
#include < txmempool.h>
17
17
#include < uint256.h>
18
18
#include < util/check.h>
19
+ #include < util/feefrac.h>
19
20
#include < util/strencodings.h>
20
21
#include < util/time.h>
21
22
#include < util/translation.h>
25
26
#include < test/util/setup_common.h>
26
27
27
28
#include < memory>
29
+ #include < vector>
28
30
29
31
#include < boost/test/unit_test.hpp>
30
32
@@ -123,19 +125,22 @@ void MinerTestingSetup::TestPackageSelection(const CScript& scriptPubKey, const
123
125
tx.vout [0 ].nValue = 5000000000LL - 1000 ;
124
126
// This tx has a low fee: 1000 satoshis
125
127
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);
127
130
128
131
// This tx has a medium fee: 10000 satoshis
129
132
tx.vin [0 ].prevout .hash = txFirst[1 ]->GetHash ();
130
133
tx.vout [0 ].nValue = 5000000000LL - 10000 ;
131
134
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);
133
137
134
138
// This tx has a high fee, but depends on the first transaction
135
139
tx.vin [0 ].prevout .hash = hashParentTx;
136
140
tx.vout [0 ].nValue = 5000000000LL - 1000 - 50000 ; // 50k satoshi fee
137
141
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);
139
144
140
145
std::unique_ptr<BlockTemplate> block_template = mining->createNewBlock (options);
141
146
BOOST_REQUIRE (block_template);
@@ -145,6 +150,21 @@ void MinerTestingSetup::TestPackageSelection(const CScript& scriptPubKey, const
145
150
BOOST_CHECK (block.vtx [2 ]->GetHash () == hashHighFeeTx);
146
151
BOOST_CHECK (block.vtx [3 ]->GetHash () == hashMediumFeeTx);
147
152
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
+
148
168
// Test that a package below the block min tx fee doesn't get included
149
169
tx.vin [0 ].prevout .hash = hashHighFeeTx;
150
170
tx.vout [0 ].nValue = 5000000000LL - 1000 - 50000 ; // 0 fee
0 commit comments