@@ -346,122 +346,10 @@ fn sorted_vec<T: Ord>(mut v: Vec<T>) -> Vec<T> {
346
346
v
347
347
}
348
348
349
- fn verify_claimable_balances ( mut balances_1 : Vec < Balance > , mut balances_2 : Vec < Balance > , margin : u64 ) {
349
+ fn verify_claimable_balances ( mut balances_1 : Vec < Balance > , mut balances_2 : Vec < Balance > ) {
350
350
balances_1. sort ( ) ;
351
351
balances_2. sort ( ) ;
352
- assert_eq ! ( balances_1. len( ) , balances_2. len( ) ) ;
353
- for i in 0 ..balances_1. len ( ) {
354
- match ( balances_1. get ( i) . unwrap ( ) , balances_2. get ( i) . unwrap ( ) ) {
355
- (
356
- Balance :: ClaimableOnChannelClose {
357
- amount_satoshis : amount_satoshis_1,
358
- transaction_fee_satoshis : transaction_fee_satoshis_1,
359
- outbound_payment_htlc_rounded_msat : outbound_payment_htlc_rounded_msat_1,
360
- outbound_forwarded_htlc_rounded_msat : outbound_forwarded_htlc_rounded_msat_1,
361
- inbound_claiming_htlc_rounded_msat : inbound_claiming_htlc_rounded_msat_1,
362
- inbound_htlc_rounded_msat : inbound_htlc_rounded_msat_1,
363
- } ,
364
- Balance :: ClaimableOnChannelClose {
365
- amount_satoshis : amount_satoshis_2,
366
- transaction_fee_satoshis : transaction_fee_satoshis_2,
367
- outbound_payment_htlc_rounded_msat : outbound_payment_htlc_rounded_msat_2,
368
- outbound_forwarded_htlc_rounded_msat : outbound_forwarded_htlc_rounded_msat_2,
369
- inbound_claiming_htlc_rounded_msat : inbound_claiming_htlc_rounded_msat_2,
370
- inbound_htlc_rounded_msat : inbound_htlc_rounded_msat_2,
371
- } ,
372
- ) => {
373
- assert ! ( amount_satoshis_1. abs_diff( * amount_satoshis_2) <= margin) ;
374
- assert ! ( transaction_fee_satoshis_1. abs_diff( * transaction_fee_satoshis_2) <= margin) ;
375
- assert ! ( outbound_payment_htlc_rounded_msat_1. abs_diff( * outbound_payment_htlc_rounded_msat_2) <= margin) ;
376
- assert ! ( outbound_forwarded_htlc_rounded_msat_1. abs_diff( * outbound_forwarded_htlc_rounded_msat_2) <= margin) ;
377
- assert ! ( inbound_claiming_htlc_rounded_msat_1. abs_diff( * inbound_claiming_htlc_rounded_msat_2) <= margin) ;
378
- assert ! ( inbound_htlc_rounded_msat_1. abs_diff( * inbound_htlc_rounded_msat_2) <= margin) ;
379
- } ,
380
- (
381
- Balance :: ClaimableAwaitingConfirmations {
382
- amount_satoshis : amount_satoshis_1,
383
- confirmation_height : confirmation_height_1,
384
- source : source_1,
385
- } ,
386
- Balance :: ClaimableAwaitingConfirmations {
387
- amount_satoshis : amount_satoshis_2,
388
- confirmation_height : confirmation_height_2,
389
- source : source_2,
390
- } ,
391
- ) => {
392
- assert ! ( amount_satoshis_1. abs_diff( * amount_satoshis_2) <= margin) ;
393
- assert_eq ! ( confirmation_height_1, confirmation_height_2) ;
394
- assert_eq ! ( source_1, source_2) ;
395
- } ,
396
- (
397
- Balance :: ContentiousClaimable {
398
- amount_satoshis : amount_satoshis_1,
399
- timeout_height : timeout_height_1,
400
- payment_hash : payment_hash_1,
401
- payment_preimage : payment_preimage_1,
402
- } ,
403
- Balance :: ContentiousClaimable {
404
- amount_satoshis : amount_satoshis_2,
405
- timeout_height : timeout_height_2,
406
- payment_hash : payment_hash_2,
407
- payment_preimage : payment_preimage_2,
408
- } ,
409
- ) => {
410
- assert ! ( amount_satoshis_1. abs_diff( * amount_satoshis_2) <= margin) ;
411
- assert_eq ! ( timeout_height_1, timeout_height_2) ;
412
- assert_eq ! ( payment_hash_1, payment_hash_2) ;
413
- assert_eq ! ( payment_preimage_1, payment_preimage_2) ;
414
- } ,
415
- (
416
- Balance :: MaybeTimeoutClaimableHTLC {
417
- amount_satoshis : amount_satoshis_1,
418
- claimable_height : claimable_height_1,
419
- payment_hash : payment_hash_1,
420
- outbound_payment : outbound_payment_1,
421
- } ,
422
- Balance :: MaybeTimeoutClaimableHTLC {
423
- amount_satoshis : amount_satoshis_2,
424
- claimable_height : claimable_height_2,
425
- payment_hash : payment_hash_2,
426
- outbound_payment : outbound_payment_2,
427
- } ,
428
- ) => {
429
- assert ! ( amount_satoshis_1. abs_diff( * amount_satoshis_2) <= margin) ;
430
- assert_eq ! ( claimable_height_1, claimable_height_2) ;
431
- assert_eq ! ( payment_hash_1, payment_hash_2) ;
432
- assert_eq ! ( outbound_payment_1, outbound_payment_2) ;
433
- } ,
434
- (
435
- Balance :: MaybePreimageClaimableHTLC {
436
- amount_satoshis : amount_satoshis_1,
437
- expiry_height : expiry_height_1,
438
- payment_hash : payment_hash_1,
439
- } ,
440
- Balance :: MaybePreimageClaimableHTLC {
441
- amount_satoshis : amount_satoshis_2,
442
- expiry_height : expiry_height_2,
443
- payment_hash : payment_hash_2,
444
- } ,
445
- ) => {
446
- assert ! ( amount_satoshis_1. abs_diff( * amount_satoshis_2) <= margin) ;
447
- assert_eq ! ( expiry_height_1, expiry_height_2) ;
448
- assert_eq ! ( payment_hash_1, payment_hash_2) ;
449
- } ,
450
- (
451
- Balance :: CounterpartyRevokedOutputClaimable {
452
- amount_satoshis : amount_satoshis_1,
453
- } ,
454
- Balance :: CounterpartyRevokedOutputClaimable {
455
- amount_satoshis : amount_satoshis_2,
456
- } ,
457
- ) => {
458
- assert ! ( amount_satoshis_1. abs_diff( * amount_satoshis_2) <= margin) ;
459
- } ,
460
- _ => {
461
- panic ! ( "unexpected balance type" ) ;
462
- }
463
- }
464
- }
352
+ assert_eq ! ( balances_1, balances_2) ;
465
353
}
466
354
467
355
/// Asserts that `a` and `b` are close, but maybe off by up to 5.
@@ -1493,7 +1381,6 @@ fn do_test_revoked_counterparty_commitment_balances(anchors: bool, confirm_htlc_
1493
1381
outbound_payment: true ,
1494
1382
} ] ,
1495
1383
nodes[ 1 ] . chain_monitor . chain_monitor . get_monitor ( funding_outpoint) . unwrap ( ) . get_claimable_balances ( ) ,
1496
- 5 ,
1497
1384
) ;
1498
1385
1499
1386
mine_transaction ( & nodes[ 1 ] , & as_revoked_txn[ 0 ] ) ;
@@ -1513,8 +1400,14 @@ fn do_test_revoked_counterparty_commitment_balances(anchors: bool, confirm_htlc_
1513
1400
// somewhat so it may not always be exact.
1514
1401
fuzzy_assert_eq ( claim_txn[ 0 ] . weight ( ) . to_wu ( ) , pinnable_weight) ;
1515
1402
fuzzy_assert_eq ( claim_txn[ 1 ] . weight ( ) . to_wu ( ) , unpinnable_weight) ;
1516
- let pinnable_fee = chan_feerate * claim_txn[ 0 ] . weight ( ) . to_wu ( ) / 1000 ;
1517
- let unpinnable_fee = chan_feerate * claim_txn[ 1 ] . weight ( ) . to_wu ( ) / 1000 ;
1403
+ let pinnable_fee = claim_txn[ 0 ] . input . iter ( ) . map ( |txin| {
1404
+ assert_eq ! ( txin. previous_output. txid, as_revoked_txn[ 0 ] . compute_txid( ) ) ;
1405
+ as_revoked_txn[ 0 ] . output [ txin. previous_output . vout as usize ] . value . to_sat ( )
1406
+ } ) . sum :: < u64 > ( ) - claim_txn[ 0 ] . output . iter ( ) . map ( |txout| txout. value . to_sat ( ) ) . sum :: < u64 > ( ) ;
1407
+ let unpinnable_fee = claim_txn[ 1 ] . input . iter ( ) . map ( |txin| {
1408
+ assert_eq ! ( txin. previous_output. txid, as_revoked_txn[ 0 ] . compute_txid( ) ) ;
1409
+ as_revoked_txn[ 0 ] . output [ txin. previous_output . vout as usize ] . value . to_sat ( )
1410
+ } ) . sum :: < u64 > ( ) - claim_txn[ 1 ] . output . iter ( ) . map ( |txout| txout. value . to_sat ( ) ) . sum :: < u64 > ( ) ;
1518
1411
1519
1412
// The expected balances for the next three checks.
1520
1413
let to_remote_balance = Balance :: ClaimableAwaitingConfirmations {
@@ -1543,7 +1436,6 @@ fn do_test_revoked_counterparty_commitment_balances(anchors: bool, confirm_htlc_
1543
1436
htlc_unclaimed_balance( 5_000 ) ,
1544
1437
] ,
1545
1438
nodes[ 1 ] . chain_monitor . chain_monitor . get_monitor ( funding_outpoint) . unwrap ( ) . get_claimable_balances ( ) ,
1546
- 5 ,
1547
1439
) ;
1548
1440
1549
1441
if confirm_htlc_spend_first {
@@ -1558,7 +1450,7 @@ fn do_test_revoked_counterparty_commitment_balances(anchors: bool, confirm_htlc_
1558
1450
}
1559
1451
1560
1452
let pinnable_claimed_balance = Balance :: ClaimableAwaitingConfirmations {
1561
- amount_satoshis : 5_000 + 3_000 + 4_000 - pinnable_fee - if anchors { 3 } else { 2 } ,
1453
+ amount_satoshis : 5_000 + 3_000 + 4_000 - pinnable_fee,
1562
1454
confirmation_height : largest_htlc_claimed_avail_height,
1563
1455
source : BalanceSource :: CounterpartyForceClosed ,
1564
1456
} ;
@@ -1576,7 +1468,6 @@ fn do_test_revoked_counterparty_commitment_balances(anchors: bool, confirm_htlc_
1576
1468
to_self_unclaimed_balance. clone( ) ,
1577
1469
] ,
1578
1470
nodes[ 1 ] . chain_monitor . chain_monitor . get_monitor ( funding_outpoint) . unwrap ( ) . get_claimable_balances ( ) ,
1579
- 5 ,
1580
1471
) ;
1581
1472
} else {
1582
1473
verify_claimable_balances (
@@ -1588,7 +1479,6 @@ fn do_test_revoked_counterparty_commitment_balances(anchors: bool, confirm_htlc_
1588
1479
htlc_unclaimed_balance( 5_000 ) ,
1589
1480
] ,
1590
1481
nodes[ 1 ] . chain_monitor . chain_monitor . get_monitor ( funding_outpoint) . unwrap ( ) . get_claimable_balances ( ) ,
1591
- 5 ,
1592
1482
) ;
1593
1483
}
1594
1484
@@ -1604,7 +1494,6 @@ fn do_test_revoked_counterparty_commitment_balances(anchors: bool, confirm_htlc_
1604
1494
unpinnable_claimed_balance. clone( ) ,
1605
1495
] ,
1606
1496
nodes[ 1 ] . chain_monitor . chain_monitor . get_monitor ( funding_outpoint) . unwrap ( ) . get_claimable_balances ( ) ,
1607
- 5 ,
1608
1497
) ;
1609
1498
1610
1499
connect_blocks ( & nodes[ 1 ] , 3 ) ;
0 commit comments