@@ -30,6 +30,12 @@ def set_test_params(self):
3030 ]] * self .num_nodes
3131 self .supports_cli = False
3232
33+ def clear_prioritisation (self , node ):
34+ for txid , info in node .getprioritisedtransactions ().items ():
35+ delta = info ["fee_delta" ]
36+ node .prioritisetransaction (txid , 0 , - delta )
37+ assert_equal (node .getprioritisedtransactions (), {})
38+
3339 def test_replacement (self ):
3440 self .log .info ("Test tx prioritisation stays after a tx is replaced" )
3541 conflicting_input = self .wallet .get_utxo ()
@@ -108,6 +114,10 @@ def test_diamond(self):
108114 prioritisation_map_in_mempool = self .nodes [0 ].getprioritisedtransactions ()
109115 assert_equal (prioritisation_map_in_mempool [txid_b ], {"fee_delta" : fee_delta_b * COIN , "in_mempool" : True })
110116 assert_equal (prioritisation_map_in_mempool [txid_c ], {"fee_delta" : (fee_delta_c_1 + fee_delta_c_2 )* COIN , "in_mempool" : True })
117+ # Clear prioritisation, otherwise the transactions' fee deltas are persisted to mempool.dat and loaded again when the node
118+ # is restarted at the end of this subtest. Deltas are removed when a transaction is mined, but only at that time. We do
119+ # not check whether mapDeltas transactions were mined when loading from mempool.dat.
120+ self .clear_prioritisation (node = self .nodes [0 ])
111121
112122 self .log .info ("Test priority while txs are not in mempool" )
113123 self .restart_node (0 , extra_args = ["-nopersistmempool" ])
@@ -135,6 +145,7 @@ def test_diamond(self):
135145
136146 # Use default extra_args
137147 self .restart_node (0 )
148+ assert_equal (self .nodes [0 ].getprioritisedtransactions (), {})
138149
139150 def run_test (self ):
140151 self .wallet = MiniWallet (self .nodes [0 ])
@@ -202,10 +213,18 @@ def run_test(self):
202213 sizes [i ] += mempool [j ]['vsize' ]
203214 assert sizes [i ] > MAX_BLOCK_WEIGHT // 4 # Fail => raise utxo_count
204215
216+ assert_equal (self .nodes [0 ].getprioritisedtransactions (), {})
205217 # add a fee delta to something in the cheapest bucket and make sure it gets mined
206218 # also check that a different entry in the cheapest bucket is NOT mined
207219 self .nodes [0 ].prioritisetransaction (txid = txids [0 ][0 ], fee_delta = int (3 * base_fee * COIN ))
208- assert_equal (self .nodes [0 ].getprioritisedtransactions ()[txids [0 ][0 ]], { "fee_delta" : 3 * base_fee * COIN , "in_mempool" : True })
220+ assert_equal (self .nodes [0 ].getprioritisedtransactions (), {txids [0 ][0 ] : { "fee_delta" : 3 * base_fee * COIN , "in_mempool" : True }})
221+
222+ # Priority disappears when prioritisetransaction is called with an inverse value...
223+ self .nodes [0 ].prioritisetransaction (txid = txids [0 ][0 ], fee_delta = int (- 3 * base_fee * COIN ))
224+ assert txids [0 ][0 ] not in self .nodes [0 ].getprioritisedtransactions ()
225+ # ... and reappears when prioritisetransaction is called again.
226+ self .nodes [0 ].prioritisetransaction (txid = txids [0 ][0 ], fee_delta = int (3 * base_fee * COIN ))
227+ assert txids [0 ][0 ] in self .nodes [0 ].getprioritisedtransactions ()
209228
210229 self .generate (self .nodes [0 ], 1 )
211230
@@ -277,8 +296,8 @@ def run_test(self):
277296 template = self .nodes [0 ].getblocktemplate ({'rules' : ['segwit' ]})
278297 self .nodes [0 ].prioritisetransaction (txid = tx_id , fee_delta = - int (self .relayfee * COIN ))
279298
280- assert tx_id in self . nodes [ 0 ]. getprioritisedtransactions ()
281- assert_equal ( self .nodes [0 ].getprioritisedtransactions ()[ tx_id ][ "fee_delta" ], 0 )
299+ # Calling prioritisetransaction with the inverse amount should delete its prioritisation entry
300+ assert tx_id not in self .nodes [0 ].getprioritisedtransactions ()
282301
283302 self .nodes [0 ].setmocktime (mock_time + 10 )
284303 new_template = self .nodes [0 ].getblocktemplate ({'rules' : ['segwit' ]})
0 commit comments