@@ -301,9 +301,18 @@ def feerate_from_psbt(bitcoind, node, psbt):
301
301
return fee / weight * 1000
302
302
303
303
304
+ # I wish we could force libwally to use different entropy and thus force it to
305
+ # create 71-byte sigs always!
306
+ def did_short_sig (node ):
307
+ # This can take a moment to appear in the log!
308
+ time .sleep (1 )
309
+ return node .daemon .is_in_log ('overgrind: short signature length' )
310
+
311
+
304
312
def test_txprepare (node_factory , bitcoind , chainparams ):
305
313
amount = 1000000
306
- l1 = node_factory .get_node (random_hsm = True )
314
+ l1 = node_factory .get_node (random_hsm = True , options = {'dev-warn-on-overgrind' : None },
315
+ broken_log = 'overgrind: short signature length' )
307
316
addr = chainparams ['example_addr' ]
308
317
309
318
# Add some funds to withdraw later
@@ -324,7 +333,8 @@ def test_txprepare(node_factory, bitcoind, chainparams):
324
333
assert len (decode ['vin' ]) == 4
325
334
assert len (decode ['vout' ]) == 2 if not chainparams ['feeoutput' ] else 3
326
335
# Feerate should be ~ as we asked for
327
- assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep ['psbt' ]) < normal_feerate_perkw + 1
336
+ if not did_short_sig (l1 ):
337
+ assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep ['psbt' ]) < normal_feerate_perkw + 1
328
338
329
339
# One output will be correct.
330
340
outnum = [i for i , o in enumerate (decode ['vout' ]) if o ['value' ] == Decimal (amount * 3 ) / 10 ** 8 ][0 ]
@@ -353,7 +363,8 @@ def test_txprepare(node_factory, bitcoind, chainparams):
353
363
assert decode ['vout' ][0 ]['scriptPubKey' ]['type' ] == 'witness_v0_keyhash'
354
364
assert scriptpubkey_addr (decode ['vout' ][0 ]['scriptPubKey' ]) == addr
355
365
# Feerate should be ~ as we asked for
356
- assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep2 ['psbt' ]) < normal_feerate_perkw + 1
366
+ if not did_short_sig (l1 ):
367
+ assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep2 ['psbt' ]) < normal_feerate_perkw + 1
357
368
358
369
# If I cancel the first one, I can get those first 4 outputs.
359
370
discard = l1 .rpc .txdiscard (prep ['txid' ])
@@ -373,7 +384,8 @@ def test_txprepare(node_factory, bitcoind, chainparams):
373
384
assert decode ['vout' ][0 ]['scriptPubKey' ]['type' ] == 'witness_v0_keyhash'
374
385
assert scriptpubkey_addr (decode ['vout' ][0 ]['scriptPubKey' ]) == addr
375
386
# Feerate should be ~ as we asked for
376
- assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep3 ['psbt' ]) < normal_feerate_perkw + 1
387
+ if not did_short_sig (l1 ):
388
+ assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep3 ['psbt' ]) < normal_feerate_perkw + 1
377
389
378
390
# Cannot discard twice.
379
391
with pytest .raises (RpcError , match = r'not an unreleased txid' ):
@@ -395,7 +407,8 @@ def test_txprepare(node_factory, bitcoind, chainparams):
395
407
assert decode ['vout' ][0 ]['scriptPubKey' ]['type' ] == 'witness_v0_keyhash'
396
408
assert scriptpubkey_addr (decode ['vout' ][0 ]['scriptPubKey' ]) == addr
397
409
# Feerate should be ~ as we asked for
398
- assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep4 ['psbt' ]) < normal_feerate_perkw + 1
410
+ if not did_short_sig (l1 ):
411
+ assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep4 ['psbt' ]) < normal_feerate_perkw + 1
399
412
l1 .rpc .txdiscard (prep4 ['txid' ])
400
413
401
414
# Try passing in a utxo set
@@ -404,7 +417,8 @@ def test_txprepare(node_factory, bitcoind, chainparams):
404
417
prep5 = l1 .rpc .txprepare ([{addr :
405
418
Millisatoshi (amount * 3.5 * 1000 )}], utxos = utxos )
406
419
# Feerate should be ~ as we asked for
407
- assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep3 ['psbt' ]) < normal_feerate_perkw + 1
420
+ if not did_short_sig (l1 ):
421
+ assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep3 ['psbt' ]) < normal_feerate_perkw + 1
408
422
409
423
# Try passing unconfirmed utxos
410
424
unconfirmed_utxo = l1 .rpc .withdraw (l1 .rpc .newaddr ()["bech32" ], 10 ** 5 )
@@ -445,15 +459,17 @@ def test_txprepare(node_factory, bitcoind, chainparams):
445
459
prep5 = l1 .rpc .txprepare ([{addr : Millisatoshi (amount * 3 * 1000 )},
446
460
{addr : 'all' }])
447
461
# Feerate should be ~ as we asked for
448
- assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep5 ['psbt' ]) < normal_feerate_perkw + 1
462
+ if not did_short_sig (l1 ):
463
+ assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep5 ['psbt' ]) < normal_feerate_perkw + 1
449
464
l1 .rpc .txdiscard (prep5 ['txid' ])
450
465
with pytest .raises (RpcError , match = r"'all'" ):
451
466
prep5 = l1 .rpc .txprepare ([{addr : 'all' }, {addr : 'all' }])
452
467
453
468
prep5 = l1 .rpc .txprepare ([{addr : Millisatoshi (amount * 3 * 500 + 100000 )},
454
469
{addr : Millisatoshi (amount * 3 * 500 - 100000 )}])
455
470
# Feerate should be ~ as we asked for
456
- assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep5 ['psbt' ]) < normal_feerate_perkw + 1
471
+ if not did_short_sig (l1 ):
472
+ assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep5 ['psbt' ]) < normal_feerate_perkw + 1
457
473
decode = bitcoind .rpc .decoderawtransaction (prep5 ['unsigned_tx' ])
458
474
assert decode ['txid' ] == prep5 ['txid' ]
459
475
# 4 inputs, 3 outputs(include change).
@@ -485,7 +501,8 @@ def test_txprepare(node_factory, bitcoind, chainparams):
485
501
486
502
def test_txprepare_feerate (node_factory , bitcoind ):
487
503
# Make sure it works at different feerates!
488
- l1 , l2 = node_factory .get_nodes (2 )
504
+ l1 , l2 = node_factory .get_nodes (2 , opts = {'dev-warn-on-overgrind' : None ,
505
+ 'broken_log' : 'overgrind: short signature length' })
489
506
490
507
# Add some funds to withdraw later
491
508
for i in range (20 ):
@@ -499,7 +516,8 @@ def test_txprepare_feerate(node_factory, bitcoind):
499
516
for addrtype in ('bech32' , 'p2tr' ):
500
517
for feerate in range (255 , 10000 , 250 ):
501
518
prep = l1 .rpc .txprepare ([{out_addrs [addrtype ]: Millisatoshi (9000 )}], f"{ feerate } perkw" )
502
- assert feerate - 1 < feerate_from_psbt (bitcoind , l1 , prep ['psbt' ]) < feerate + 1
519
+ if not did_short_sig (l1 ):
520
+ assert feerate - 1 < feerate_from_psbt (bitcoind , l1 , prep ['psbt' ]) < feerate + 1
503
521
l1 .rpc .txdiscard (prep6 ['txid' ])
504
522
505
523
0 commit comments