Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251txids[i] = create_lots_of_big_transactions(252self.wallet,253self.nodes[0],254(i+1) * base_fee,255end_range - start_range,256self.txouts,257utxos[start_range:end_range])259# Make sure that the size of each group of transactions exceeds260# MAX_BLOCK_WEIGHT // 4 -- otherwise the test needs to be revised to261# create more transactions.262mempool = self.nodes[0].getrawmempool(True)263sizes = [0, 0, 0]264for i in range(3):265for j in txids[i]:266assert j in mempool267sizes[i] += mempool[j]['vsize']268assert sizes[i] > MAX_BLOCK_WEIGHT // 4 # Fail => raise utxo_count270assert_equal(self.nodes[0].getprioritisedtransactions(), {})271# add a fee delta to something in the cheapest bucket and make sure it gets mined272# also check that a different entry in the cheapest bucket is NOT mined273self.nodes[0].prioritisetransaction(txid=txids[0][0], fee_delta=int(3*base_fee*COIN))274assert_equal(self.nodes[0].getprioritisedtransactions(), {txids[0][0] : { "fee_delta" : 3*base_fee*COIN, "in_mempool" : True, "modified_fee": int(3*base_fee*COIN + COIN * 1 * base_fee)}})276# Priority disappears when prioritisetransaction is called with an inverse value...277self.nodes[0].prioritisetransaction(txid=txids[0][0], fee_delta=int(-3*base_fee*COIN))278assert txids[0][0] not in self.nodes[0].getprioritisedtransactions()279# ... and reappears when prioritisetransaction is called again.280self.nodes[0].prioritisetransaction(txid=txids[0][0], fee_delta=int(3*base_fee*COIN))281assert txids[0][0] in self.nodes[0].getprioritisedtransactions()283self.generate(self.nodes[0], 1)285mempool = self.nodes[0].getrawmempool()286self.log.info("Assert that prioritised transaction was mined")287assert txids[0][0] not in mempool288assert txids[0][1] in mempool290high_fee_tx = None291for x in txids[2]:292if x not in mempool:293high_fee_tx = x295# Something high-fee should have been mined!296assert high_fee_tx is not None298# Add a prioritisation before a tx is in the mempool (de-prioritising a299# high-fee transaction so that it's now low fee).300self.nodes[0].prioritisetransaction(txid=high_fee_tx, fee_delta=-int(2*base_fee*COIN))301assert_equal(self.nodes[0].getprioritisedtransactions()[high_fee_tx], { "fee_delta" : -2*base_fee*COIN, "in_mempool" : False})303# Add everything back to mempool304self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())306# Check to make sure our high fee rate tx is back in the mempool307mempool = self.nodes[0].getrawmempool()308assert high_fee_tx in mempool310# Now verify the modified-high feerate transaction isn't mined before311# the other high fee transactions. Keep mining until our mempool has312# decreased by all the high fee size that we calculated above.313while (self.nodes[0].getmempoolinfo()['bytes'] > sizes[0] + sizes[1]):314self.generate(self.nodes[0], 1, sync_fun=self.no_op)316# High fee transaction should not have been mined, but other high fee rate317# transactions should have been.318mempool = self.nodes[0].getrawmempool()319self.log.info("Assert that de-prioritised transaction is still in mempool")320assert high_fee_tx in mempool321assert_equal(self.nodes[0].getprioritisedtransactions()[high_fee_tx], { "fee_delta" : -2*base_fee*COIN, "in_mempool" : True, "modified_fee": int(-2*base_fee*COIN + COIN * 3 * base_fee)})322for x in txids[2]:323if (x != high_fee_tx):324assert x not in mempool327self.log.info("Assert that 0 delta is never added to mapDeltas")328tx_id_zero_del = self.wallet.create_self_transfer()['txid']329self.nodes[0].prioritisetransaction(txid=tx_id_zero_del, fee_delta=0)330assert tx_id_zero_del not in self.nodes[0].getprioritisedtransactions()332# Create a free transaction. Should be rejected.333tx_res = self.wallet.create_self_transfer(fee_rate=0)334tx_hex = tx_res['hex']335tx_id = tx_res['txid']337# This will raise an exception due to min relay fee not being met338assert_raises_rpc_error(-26, "min relay fee not met", self.nodes[0].sendrawtransaction, tx_hex)339assert tx_id not in self.nodes[0].getrawmempool()341# This is a less than 1000-byte transaction, so just set the fee342# to be the minimum for a 1000-byte transaction and check that it is343# accepted.344self.nodes[0].prioritisetransaction(txid=tx_id, fee_delta=int(self.relayfee*COIN))345assert_equal(self.nodes[0].getprioritisedtransactions()[tx_id], { "fee_delta" : self.relayfee*COIN, "in_mempool" : False})347self.log.info("Assert that prioritised free transaction is accepted to mempool")348assert_equal(self.nodes[0].sendrawtransaction(tx_hex), tx_id)349assert tx_id in self.nodes[0].getrawmempool()350assert_equal(self.nodes[0].getprioritisedtransactions()[tx_id], { "fee_delta" : self.relayfee*COIN, "in_mempool" : True, "modified_fee": int(self.relayfee*COIN + COIN * tx_res["fee"])})352# Test that calling prioritisetransaction is sufficient to trigger353# getblocktemplate to (eventually) return a new block.354mock_time = int(time.time())355self.nodes[0].setmocktime(mock_time)356template = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)357self.nodes[0].prioritisetransaction(txid=tx_id, fee_delta=-int(self.relayfee*COIN))359# Calling prioritisetransaction with the inverse amount should delete its prioritisation entry360assert tx_id not in self.nodes[0].getprioritisedtransactions()362self.nodes[0].setmocktime(mock_time+10)363new_template = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)365assert_not_equal(template, new_template)367if __name__ == '__main__':368PrioritiseTransactionTest(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.