@@ -596,8 +596,8 @@ fn test_update_fee_that_funder_cannot_afford() {
596
596
let commitment_tx = get_local_commitment_txn ! ( nodes[ 1 ] , channel_id) [ 0 ] . clone ( ) ;
597
597
598
598
//We made sure neither party's funds are below the dust limit so -2 non-HTLC txns from number of outputs and -2 for anchor outputs
599
- let num_htlcs = commitment_tx. output . len ( ) - 2 ; //TODO: add +2 in next commit
600
- let mut total_fee: u64 = feerate as u64 * ( COMMITMENT_TX_BASE_WEIGHT + ( num_htlcs as u64 ) * COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000 ; //TODO: add anchor weight in next commit
599
+ let num_htlcs = commitment_tx. output . len ( ) - 4 ;
600
+ let mut total_fee: u64 = feerate as u64 * ( COMMITMENT_TX_BASE_WEIGHT + ( num_htlcs as u64 ) * COMMITMENT_TX_WEIGHT_PER_HTLC + 2 * COMMITMENT_TX_WEIGHT_PER_ANCHOR ) / 1000 ;
601
601
let mut actual_fee = commitment_tx. output . iter ( ) . fold ( 0 , |acc, output| acc + output. value ) ;
602
602
actual_fee = channel_value - actual_fee;
603
603
assert_eq ! ( total_fee, actual_fee) ;
@@ -1487,7 +1487,8 @@ fn test_duplicate_htlc_different_direction_onchain() {
1487
1487
// Broadcast node 1 commitment txn
1488
1488
let remote_txn = get_local_commitment_txn ! ( nodes[ 1 ] , chan_1. 2 ) ;
1489
1489
1490
- assert_eq ! ( remote_txn[ 0 ] . output. len( ) , 4 ) ; // 1 local, 1 remote, 1 htlc inbound, 1 htlc outbound
1490
+ assert_eq ! ( remote_txn[ 0 ] . output. len( ) , 6 ) ; // 1 local, 1 remote, 1 htlc inbound, 1 htlc outbound, 2 anchors
1491
+ check_anchor_output ( & remote_txn[ 0 ] , 2 ) ;
1491
1492
let mut has_both_htlcs = 0 ; // check htlcs match ones committed
1492
1493
for outp in remote_txn[ 0 ] . output . iter ( ) {
1493
1494
if outp. value == 800_000 / 1000 {
@@ -1617,21 +1618,21 @@ fn test_fee_spike_violation_fails_htlc() {
1617
1618
1618
1619
// Get the EnforcingChannelKeys for each channel, which will be used to (1) get the keys
1619
1620
// needed to sign the new commitment tx and (2) sign the new commitment tx.
1620
- let ( local_revocation_basepoint, local_htlc_basepoint, local_payment_point, local_secret, local_secret2) = {
1621
+ let ( local_revocation_basepoint, local_htlc_basepoint, local_payment_point, local_secret, local_secret2, local_funding_pubkey ) = {
1621
1622
let chan_lock = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
1622
1623
let local_chan = chan_lock. by_id . get ( & chan. 2 ) . unwrap ( ) ;
1623
1624
let chan_keys = local_chan. get_keys ( ) ;
1624
1625
let pubkeys = chan_keys. pubkeys ( ) ;
1625
1626
( pubkeys. revocation_basepoint , pubkeys. htlc_basepoint , pubkeys. payment_point ,
1626
- chan_keys. release_commitment_secret ( INITIAL_COMMITMENT_NUMBER ) , chan_keys. release_commitment_secret ( INITIAL_COMMITMENT_NUMBER - 2 ) )
1627
+ chan_keys. release_commitment_secret ( INITIAL_COMMITMENT_NUMBER ) , chan_keys. release_commitment_secret ( INITIAL_COMMITMENT_NUMBER - 2 ) , pubkeys . funding_pubkey )
1627
1628
} ;
1628
- let ( remote_delayed_payment_basepoint, remote_htlc_basepoint, remote_payment_point, remote_secret1) = {
1629
+ let ( remote_delayed_payment_basepoint, remote_htlc_basepoint, remote_payment_point, remote_secret1, remote_funding_pubkey ) = {
1629
1630
let chan_lock = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) ;
1630
1631
let remote_chan = chan_lock. by_id . get ( & chan. 2 ) . unwrap ( ) ;
1631
1632
let chan_keys = remote_chan. get_keys ( ) ;
1632
1633
let pubkeys = chan_keys. pubkeys ( ) ;
1633
1634
( pubkeys. delayed_payment_basepoint , pubkeys. htlc_basepoint , pubkeys. payment_point ,
1634
- chan_keys. release_commitment_secret ( INITIAL_COMMITMENT_NUMBER - 1 ) )
1635
+ chan_keys. release_commitment_secret ( INITIAL_COMMITMENT_NUMBER - 1 ) , pubkeys . funding_pubkey )
1635
1636
} ;
1636
1637
1637
1638
// Assemble the set of keys we can use for signatures for our commitment_signed message.
@@ -1642,7 +1643,7 @@ fn test_fee_spike_violation_fails_htlc() {
1642
1643
1643
1644
// Build the remote commitment transaction so we can sign it, and then later use the
1644
1645
// signature for the commitment_signed message.
1645
- let local_chan_balance = 2058 ;
1646
+ let local_chan_balance = 1311 ;
1646
1647
let static_payment_pk = local_payment_point. serialize ( ) ;
1647
1648
let remote_commit_tx_output = TxOut {
1648
1649
script_pubkey : Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 )
@@ -1663,7 +1664,17 @@ fn test_fee_spike_violation_fails_htlc() {
1663
1664
amount_msat : 3460001 ,
1664
1665
cltv_expiry : htlc_cltv,
1665
1666
payment_hash : payment_hash,
1666
- transaction_output_index : Some ( 1 ) ,
1667
+ transaction_output_index : Some ( 3 ) ,
1668
+ } ;
1669
+
1670
+ let local_anchor_output = TxOut {
1671
+ script_pubkey : chan_utils:: get_anchor_redeemscript ( & local_funding_pubkey) . to_v0_p2wsh ( ) ,
1672
+ value : 330 ,
1673
+ } ;
1674
+
1675
+ let remote_anchor_output = TxOut {
1676
+ script_pubkey : chan_utils:: get_anchor_redeemscript ( & remote_funding_pubkey) . to_v0_p2wsh ( ) ,
1677
+ value : 330 ,
1667
1678
} ;
1668
1679
1669
1680
let htlc_output = TxOut {
@@ -1699,8 +1710,11 @@ fn test_fee_spike_violation_fails_htlc() {
1699
1710
version : 2 ,
1700
1711
lock_time,
1701
1712
input : vec ! [ input] ,
1702
- output : vec ! [ remote_commit_tx_output, htlc_output, local_commit_tx_output] ,
1713
+ output : vec ! [ remote_anchor_output , local_anchor_output , remote_commit_tx_output, htlc_output, local_commit_tx_output] ,
1703
1714
} ;
1715
+ for outp in commit_tx. output . iter ( ) {
1716
+ println ! ( "Scriptpubkey {} value {}" , outp. script_pubkey, outp. value) ;
1717
+ }
1704
1718
let res = {
1705
1719
let local_chan_lock = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
1706
1720
let local_chan = local_chan_lock. by_id . get ( & chan. 2 ) . unwrap ( ) ;
@@ -2509,7 +2523,8 @@ fn test_justice_tx() {
2509
2523
assert_eq ! ( revoked_local_txn. len( ) , 2 ) ; // First commitment tx, then HTLC tx
2510
2524
assert_eq ! ( revoked_local_txn[ 0 ] . input. len( ) , 1 ) ;
2511
2525
assert_eq ! ( revoked_local_txn[ 0 ] . input[ 0 ] . previous_output. txid, chan_5. 3 . txid( ) ) ;
2512
- assert_eq ! ( revoked_local_txn[ 0 ] . output. len( ) , 2 ) ; // Only HTLC and output back to 0 are present
2526
+ assert_eq ! ( revoked_local_txn[ 0 ] . output. len( ) , 4 ) ; // Only HTLC and output back to 0 are present (+ 0's anchor)
2527
+ check_anchor_output ( & revoked_local_txn[ 0 ] , 2 ) ;
2513
2528
assert_eq ! ( revoked_local_txn[ 1 ] . input. len( ) , 1 ) ;
2514
2529
assert_eq ! ( revoked_local_txn[ 1 ] . input[ 0 ] . previous_output. txid, revoked_local_txn[ 0 ] . txid( ) ) ;
2515
2530
assert_eq ! ( revoked_local_txn[ 1 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , OFFERED_HTLC_SCRIPT_WEIGHT ) ; // HTLC-Timeout
@@ -2560,7 +2575,8 @@ fn test_justice_tx() {
2560
2575
assert_eq ! ( revoked_local_txn. len( ) , 1 ) ; // Only commitment tx
2561
2576
assert_eq ! ( revoked_local_txn[ 0 ] . input. len( ) , 1 ) ;
2562
2577
assert_eq ! ( revoked_local_txn[ 0 ] . input[ 0 ] . previous_output. txid, chan_6. 3 . txid( ) ) ;
2563
- assert_eq ! ( revoked_local_txn[ 0 ] . output. len( ) , 2 ) ; // Only HTLC and output back to A are present
2578
+ assert_eq ! ( revoked_local_txn[ 0 ] . output. len( ) , 4 ) ; // Only HTLC and output back to A are present (+ A's anchor)
2579
+ check_anchor_output ( & revoked_local_txn[ 0 ] , 2 ) ;
2564
2580
// Revoke the old state
2565
2581
claim_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , payment_preimage_4, 3_000_000 ) ;
2566
2582
{
@@ -2602,7 +2618,8 @@ fn revoked_output_claim() {
2602
2618
let revoked_local_txn = get_local_commitment_txn ! ( nodes[ 0 ] , chan_1. 2 ) ;
2603
2619
assert_eq ! ( revoked_local_txn. len( ) , 1 ) ;
2604
2620
// Only output is the full channel value back to nodes[0]:
2605
- assert_eq ! ( revoked_local_txn[ 0 ] . output. len( ) , 1 ) ;
2621
+ assert_eq ! ( revoked_local_txn[ 0 ] . output. len( ) , 2 ) ;
2622
+ check_anchor_output ( & revoked_local_txn[ 0 ] , 1 ) ;
2606
2623
// Send a payment through, updating everyone's latest commitment txn
2607
2624
send_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 5000000 , 5_000_000 ) ;
2608
2625
@@ -3141,7 +3158,8 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
3141
3158
let ( payment_preimage, _payment_hash) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , if no_to_remote { 10_000 } else { 3_000_000 } ) ;
3142
3159
// Get the will-be-revoked local txn from nodes[2]
3143
3160
let revoked_local_txn = get_local_commitment_txn ! ( nodes[ 2 ] , chan_2. 2 ) ;
3144
- assert_eq ! ( revoked_local_txn[ 0 ] . output. len( ) , if no_to_remote { 1 } else { 2 } ) ;
3161
+ assert_eq ! ( revoked_local_txn[ 0 ] . output. len( ) , if no_to_remote { 3 } else { 4 } ) ;
3162
+ check_anchor_output ( & revoked_local_txn[ 0 ] , 2 ) ;
3145
3163
// Revoke the old state
3146
3164
claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , payment_preimage, if no_to_remote { 10_000 } else { 3_000_000 } ) ;
3147
3165
@@ -4804,6 +4822,7 @@ fn test_claim_sizeable_push_msat() {
4804
4822
assert_eq ! ( node_txn. len( ) , 1 ) ;
4805
4823
check_spends ! ( node_txn[ 0 ] , chan. 3 ) ;
4806
4824
assert_eq ! ( node_txn[ 0 ] . output. len( ) , 2 ) ; // We can't force trimming of to_remote output as channel_reserve_satoshis block us to do so at channel opening
4825
+ check_anchor_output ( & node_txn[ 0 ] , 1 ) ;
4807
4826
4808
4827
let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
4809
4828
nodes[ 1 ] . block_notifier . block_connected ( & Block { header, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , 0 ) ;
@@ -4832,6 +4851,7 @@ fn test_claim_on_remote_sizeable_push_msat() {
4832
4851
assert_eq ! ( node_txn. len( ) , 1 ) ;
4833
4852
check_spends ! ( node_txn[ 0 ] , chan. 3 ) ;
4834
4853
assert_eq ! ( node_txn[ 0 ] . output. len( ) , 2 ) ; // We can't force trimming of to_remote output as channel_reserve_satoshis block us to do so at channel opening
4854
+ check_anchor_output ( & node_txn[ 0 ] , 1 ) ;
4835
4855
4836
4856
let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
4837
4857
nodes[ 1 ] . block_notifier . block_connected ( & Block { header, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , 0 ) ;
@@ -5415,7 +5435,8 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
5415
5435
// Rebalance and check output sanity...
5416
5436
send_payment ( & nodes[ 0 ] , & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 4 ] ] , 500000 , 500_000 ) ;
5417
5437
send_payment ( & nodes[ 1 ] , & [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 5 ] ] , 500000 , 500_000 ) ;
5418
- assert_eq ! ( get_local_commitment_txn!( nodes[ 3 ] , chan. 2 ) [ 0 ] . output. len( ) , 2 ) ;
5438
+ assert_eq ! ( get_local_commitment_txn!( nodes[ 3 ] , chan. 2 ) [ 0 ] . output. len( ) , 4 ) ;
5439
+ check_anchor_output ( & get_local_commitment_txn ! ( nodes[ 3 ] , chan. 2 ) [ 0 ] , 2 ) ;
5419
5440
5420
5441
let ds_dust_limit = nodes[ 3 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan. 2 ) . unwrap ( ) . holder_dust_limit_satoshis ;
5421
5442
// 0th HTLC:
@@ -5455,7 +5476,8 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
5455
5476
// We now have six HTLCs pending over the dust limit and six HTLCs under the dust limit (ie,
5456
5477
// with to_local and to_remote outputs, 8 outputs and 6 HTLCs not included).
5457
5478
assert_eq ! ( get_local_commitment_txn!( nodes[ 3 ] , chan. 2 ) . len( ) , 1 ) ;
5458
- assert_eq ! ( get_local_commitment_txn!( nodes[ 3 ] , chan. 2 ) [ 0 ] . output. len( ) , 8 ) ;
5479
+ assert_eq ! ( get_local_commitment_txn!( nodes[ 3 ] , chan. 2 ) [ 0 ] . output. len( ) , 10 ) ;
5480
+ check_anchor_output ( & get_local_commitment_txn ! ( nodes[ 3 ] , chan. 2 ) [ 0 ] , 2 ) ;
5459
5481
5460
5482
// Now fail back three of the over-dust-limit and three of the under-dust-limit payments in one go.
5461
5483
// Fail 0th below-dust, 4th above-dust, 8th above-dust, 10th below-dust HTLCs
@@ -7510,7 +7532,8 @@ fn test_data_loss_protect() {
7510
7532
let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
7511
7533
assert_eq ! ( node_txn. len( ) , 1 ) ;
7512
7534
check_spends ! ( node_txn[ 0 ] , chan. 3 ) ;
7513
- assert_eq ! ( node_txn[ 0 ] . output. len( ) , 2 ) ;
7535
+ assert_eq ! ( node_txn[ 0 ] . output. len( ) , 4 ) ;
7536
+ check_anchor_output ( & node_txn[ 0 ] , 2 ) ;
7514
7537
let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7515
7538
nodes[ 0 ] . block_notifier . block_connected ( & Block { header, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , 0 ) ;
7516
7539
connect_blocks ( & nodes[ 0 ] . block_notifier , ANTI_REORG_DELAY - 1 , 0 , true , header. block_hash ( ) ) ;
@@ -7648,7 +7671,8 @@ fn test_bump_penalty_txn_on_revoked_commitment() {
7648
7671
7649
7672
let revoked_txn = get_local_commitment_txn ! ( nodes[ 0 ] , chan. 2 ) ;
7650
7673
// Revoked commitment txn with 4 outputs : to_local, to_remote, 1 outgoing HTLC, 1 incoming HTLC
7651
- assert_eq ! ( revoked_txn[ 0 ] . output. len( ) , 4 ) ;
7674
+ assert_eq ! ( revoked_txn[ 0 ] . output. len( ) , 6 ) ;
7675
+ check_anchor_output ( & revoked_txn[ 0 ] , 2 ) ;
7652
7676
assert_eq ! ( revoked_txn[ 0 ] . input. len( ) , 1 ) ;
7653
7677
assert_eq ! ( revoked_txn[ 0 ] . input[ 0 ] . previous_output. txid, chan. 3 . txid( ) ) ;
7654
7678
let revoked_txid = revoked_txn[ 0 ] . txid ( ) ;
@@ -7873,7 +7897,8 @@ fn test_bump_penalty_txn_on_remote_commitment() {
7873
7897
7874
7898
// Remote commitment txn with 4 outputs : to_local, to_remote, 1 outgoing HTLC, 1 incoming HTLC
7875
7899
let remote_txn = get_local_commitment_txn ! ( nodes[ 0 ] , chan. 2 ) ;
7876
- assert_eq ! ( remote_txn[ 0 ] . output. len( ) , 4 ) ;
7900
+ assert_eq ! ( remote_txn[ 0 ] . output. len( ) , 6 ) ;
7901
+ check_anchor_output ( & remote_txn[ 0 ] , 2 ) ;
7877
7902
assert_eq ! ( remote_txn[ 0 ] . input. len( ) , 1 ) ;
7878
7903
assert_eq ! ( remote_txn[ 0 ] . input[ 0 ] . previous_output. txid, chan. 3 . txid( ) ) ;
7879
7904
@@ -7982,7 +8007,8 @@ fn test_set_outpoints_partial_claiming() {
7982
8007
// Remote commitment txn with 4 outputs: to_local, to_remote, 2 outgoing HTLC
7983
8008
let remote_txn = get_local_commitment_txn ! ( nodes[ 1 ] , chan. 2 ) ;
7984
8009
assert_eq ! ( remote_txn. len( ) , 3 ) ;
7985
- assert_eq ! ( remote_txn[ 0 ] . output. len( ) , 4 ) ;
8010
+ assert_eq ! ( remote_txn[ 0 ] . output. len( ) , 6 ) ;
8011
+ check_anchor_output ( & remote_txn[ 0 ] , 2 ) ;
7986
8012
assert_eq ! ( remote_txn[ 0 ] . input. len( ) , 1 ) ;
7987
8013
assert_eq ! ( remote_txn[ 0 ] . input[ 0 ] . previous_output. txid, chan. 3 . txid( ) ) ;
7988
8014
check_spends ! ( remote_txn[ 1 ] , remote_txn[ 0 ] ) ;
0 commit comments