@@ -1074,7 +1074,7 @@ fn sorted_vec_with_additions<T: Ord + Clone>(v_orig: &Vec<T>, extra_ts: &[&T]) -
10741074 v
10751075}
10761076
1077- fn do_test_revoked_counterparty_commitment_balances ( confirm_htlc_spend_first : bool ) {
1077+ fn do_test_revoked_counterparty_commitment_balances ( anchors : bool , confirm_htlc_spend_first : bool ) {
10781078 // Tests `get_claimable_balances` for revoked counterparty commitment transactions.
10791079 let mut chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
10801080 // We broadcast a second-to-latest commitment transaction, without providing the revocation
@@ -1083,7 +1083,12 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
10831083 // transaction which, from the point of view of our keys_manager, is revoked.
10841084 chanmon_cfgs[ 1 ] . keys_manager . disable_revocation_policy_check = true ;
10851085 let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1086- let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1086+ let mut user_config = test_default_channel_config ( ) ;
1087+ if anchors {
1088+ user_config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = true ;
1089+ user_config. manually_accept_inbound_channels = true ;
1090+ }
1091+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( user_config) , Some ( user_config) ] ) ;
10871092 let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
10881093
10891094 let ( _, _, chan_id, funding_tx) =
@@ -1193,16 +1198,23 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
11931198
11941199 // The following constants were determined experimentally
11951200 const BS_TO_SELF_CLAIM_EXP_WEIGHT : usize = 483 ;
1196- const OUTBOUND_HTLC_CLAIM_EXP_WEIGHT : usize = 571 ;
1197- const INBOUND_HTLC_CLAIM_EXP_WEIGHT : usize = 578 ;
1201+ let outbound_htlc_claim_exp_weight : usize = if anchors { 574 } else { 571 } ;
1202+ let inbound_htlc_claim_exp_weight : usize = if anchors { 582 } else { 578 } ;
11981203
11991204 // Check that the weight is close to the expected weight. Note that signature sizes vary
12001205 // somewhat so it may not always be exact.
1201- fuzzy_assert_eq ( claim_txn[ 0 ] . weight ( ) , OUTBOUND_HTLC_CLAIM_EXP_WEIGHT ) ;
1202- fuzzy_assert_eq ( claim_txn[ 1 ] . weight ( ) , INBOUND_HTLC_CLAIM_EXP_WEIGHT ) ;
1203- fuzzy_assert_eq ( claim_txn[ 2 ] . weight ( ) , INBOUND_HTLC_CLAIM_EXP_WEIGHT ) ;
1206+ fuzzy_assert_eq ( claim_txn[ 0 ] . weight ( ) , outbound_htlc_claim_exp_weight ) ;
1207+ fuzzy_assert_eq ( claim_txn[ 1 ] . weight ( ) , inbound_htlc_claim_exp_weight ) ;
1208+ fuzzy_assert_eq ( claim_txn[ 2 ] . weight ( ) , inbound_htlc_claim_exp_weight ) ;
12041209 fuzzy_assert_eq ( claim_txn[ 3 ] . weight ( ) , BS_TO_SELF_CLAIM_EXP_WEIGHT ) ;
12051210
1211+ let commitment_tx_fee = chan_feerate *
1212+ ( channel:: commitment_tx_base_weight ( & channel_type_features) + 3 * channel:: COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000 ;
1213+ let anchor_outputs_value = if anchors { channel:: ANCHOR_OUTPUT_VALUE_SATOSHI * 2 } else { 0 } ;
1214+ let inbound_htlc_claim_fee = chan_feerate * inbound_htlc_claim_exp_weight as u64 / 1000 ;
1215+ let outbound_htlc_claim_fee = chan_feerate * outbound_htlc_claim_exp_weight as u64 / 1000 ;
1216+ let to_self_claim_fee = chan_feerate * claim_txn[ 3 ] . weight ( ) as u64 / 1000 ;
1217+
12061218 // The expected balance for the next three checks, with the largest-HTLC and to_self output
12071219 // claim balances separated out.
12081220 let expected_balance = vec ! [ Balance :: ClaimableAwaitingConfirmations {
@@ -1216,8 +1228,7 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
12161228 } ] ;
12171229
12181230 let to_self_unclaimed_balance = Balance :: CounterpartyRevokedOutputClaimable {
1219- amount_satoshis : 1_000_000 - 100_000 - 3_000 - chan_feerate *
1220- ( channel:: commitment_tx_base_weight ( & channel_type_features) + 3 * channel:: COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000 ,
1231+ amount_satoshis : 1_000_000 - 100_000 - 3_000 - commitment_tx_fee - anchor_outputs_value,
12211232 } ;
12221233 let to_self_claimed_avail_height;
12231234 let largest_htlc_unclaimed_balance = Balance :: CounterpartyRevokedOutputClaimable {
@@ -1242,13 +1253,11 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
12421253 }
12431254
12441255 let largest_htlc_claimed_balance = Balance :: ClaimableAwaitingConfirmations {
1245- amount_satoshis : 5_000 - chan_feerate * INBOUND_HTLC_CLAIM_EXP_WEIGHT as u64 / 1000 ,
1256+ amount_satoshis : 5_000 - inbound_htlc_claim_fee ,
12461257 confirmation_height : largest_htlc_claimed_avail_height,
12471258 } ;
12481259 let to_self_claimed_balance = Balance :: ClaimableAwaitingConfirmations {
1249- amount_satoshis : 1_000_000 - 100_000 - 3_000 - chan_feerate *
1250- ( channel:: commitment_tx_base_weight ( & channel_type_features) + 3 * channel:: COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000
1251- - chan_feerate * claim_txn[ 3 ] . weight ( ) as u64 / 1000 ,
1260+ amount_satoshis : 1_000_000 - 100_000 - 3_000 - commitment_tx_fee - anchor_outputs_value - to_self_claim_fee,
12521261 confirmation_height : to_self_claimed_avail_height,
12531262 } ;
12541263
@@ -1278,18 +1287,16 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
12781287 amount_satoshis: 100_000 - 5_000 - 4_000 - 3 ,
12791288 confirmation_height: nodes[ 1 ] . best_block_info( ) . 1 + 1 ,
12801289 } , Balance :: ClaimableAwaitingConfirmations {
1281- amount_satoshis: 1_000_000 - 100_000 - 3_000 - chan_feerate *
1282- ( channel:: commitment_tx_base_weight( & channel_type_features) + 3 * channel:: COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000
1283- - chan_feerate * claim_txn[ 3 ] . weight( ) as u64 / 1000 ,
1290+ amount_satoshis: 1_000_000 - 100_000 - 3_000 - commitment_tx_fee - anchor_outputs_value - to_self_claim_fee,
12841291 confirmation_height: to_self_claimed_avail_height,
12851292 } , Balance :: ClaimableAwaitingConfirmations {
1286- amount_satoshis: 3_000 - chan_feerate * OUTBOUND_HTLC_CLAIM_EXP_WEIGHT as u64 / 1000 ,
1293+ amount_satoshis: 3_000 - outbound_htlc_claim_fee ,
12871294 confirmation_height: nodes[ 1 ] . best_block_info( ) . 1 + 4 ,
12881295 } , Balance :: ClaimableAwaitingConfirmations {
1289- amount_satoshis: 4_000 - chan_feerate * INBOUND_HTLC_CLAIM_EXP_WEIGHT as u64 / 1000 ,
1296+ amount_satoshis: 4_000 - inbound_htlc_claim_fee ,
12901297 confirmation_height: nodes[ 1 ] . best_block_info( ) . 1 + 5 ,
12911298 } , Balance :: ClaimableAwaitingConfirmations {
1292- amount_satoshis: 5_000 - chan_feerate * INBOUND_HTLC_CLAIM_EXP_WEIGHT as u64 / 1000 ,
1299+ amount_satoshis: 5_000 - inbound_htlc_claim_fee ,
12931300 confirmation_height: largest_htlc_claimed_avail_height,
12941301 } ] ) ,
12951302 sorted_vec( nodes[ 1 ] . chain_monitor. chain_monitor. get_monitor( funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ) ;
@@ -1326,8 +1333,10 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
13261333
13271334#[ test]
13281335fn test_revoked_counterparty_commitment_balances ( ) {
1329- do_test_revoked_counterparty_commitment_balances ( true ) ;
1330- do_test_revoked_counterparty_commitment_balances ( false ) ;
1336+ do_test_revoked_counterparty_commitment_balances ( false , true ) ;
1337+ do_test_revoked_counterparty_commitment_balances ( false , false ) ;
1338+ do_test_revoked_counterparty_commitment_balances ( true , true ) ;
1339+ do_test_revoked_counterparty_commitment_balances ( true , false ) ;
13311340}
13321341
13331342#[ test]
0 commit comments