@@ -253,12 +253,18 @@ def test_dust_to_fee(self, rbf_node, dest_address):
253
253
self .log .info ('Test that bumped output that is dust is dropped to fee' )
254
254
rbfid = spend_one_input (rbf_node , dest_address )
255
255
fulltx = rbf_node .getrawtransaction (rbfid , 1 )
256
- # size of transaction (p2wpkh, 1 input, 2 outputs): 141 vbytes
257
- assert_equal (fulltx ["vsize" ], 141 )
258
- # bump with fee_rate of 0.00350000 BTC per 1000 vbytes
259
- # expected bump fee of 141 vbytes * fee_rate 0.00350000 BTC / 1000 vbytes = 0.00049350 BTC
260
- # but dust is dropped, so actual bump fee is 0.00050000
261
- bumped_tx = rbf_node .bumpfee (rbfid , {"fee_rate" : 0.0035 })
256
+ # The DER formatting used by Bitcoin to serialize ECDSA signatures means that signatures can have a
257
+ # variable size of 70-72 bytes (or possibly even less), with most being 71 or 72 bytes. The signature
258
+ # in the witness is divided by 4 for the vsize, so this variance can take the weight across a 4-byte
259
+ # boundary. Thus expected transaction size (p2wpkh, 1 input, 2 outputs) is 140-141 vbytes, usually 141.
260
+ if not 140 <= fulltx ["vsize" ] <= 141 :
261
+ print ("Error: Invalid tx vsize of {} (140-141 expected), full tx: {}" .format (fulltx ["vsize" ], fulltx ))
262
+ raise AssertionError
263
+ # Bump with fee_rate of 0.00350250 BTC per 1000 vbytes to create dust.
264
+ # Expected fee is 141 vbytes * fee_rate 0.00350250 BTC / 1000 vbytes = 0.00049385 BTC.
265
+ # or occasionally 140 vbytes * fee_rate 0.00350250 BTC / 1000 vbytes = 0.00049035 BTC.
266
+ # Dust should be dropped to the fee, so actual bump fee is 0.00050000 BTC.
267
+ bumped_tx = rbf_node .bumpfee (rbfid , {"fee_rate" : 0.00350250 })
262
268
full_bumped_tx = rbf_node .getrawtransaction (bumped_tx ["txid" ], 1 )
263
269
assert_equal (bumped_tx ["fee" ], Decimal ("0.00050000" ))
264
270
assert_equal (len (fulltx ["vout" ]), 2 )
0 commit comments