@@ -1100,7 +1100,7 @@ fn sorted_vec_with_additions<T: Ord + Clone>(v_orig: &Vec<T>, extra_ts: &[&T]) -
11001100 v
11011101}
11021102
1103- fn do_test_revoked_counterparty_commitment_balances ( confirm_htlc_spend_first : bool ) {
1103+ fn do_test_revoked_counterparty_commitment_balances ( anchors : bool , confirm_htlc_spend_first : bool ) {
11041104 // Tests `get_claimable_balances` for revoked counterparty commitment transactions.
11051105 let mut chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
11061106 // We broadcast a second-to-latest commitment transaction, without providing the revocation
@@ -1109,7 +1109,12 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
11091109 // transaction which, from the point of view of our keys_manager, is revoked.
11101110 chanmon_cfgs[ 1 ] . keys_manager . disable_revocation_policy_check = true ;
11111111 let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1112- let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1112+ let mut user_config = test_default_channel_config ( ) ;
1113+ if anchors {
1114+ user_config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = true ;
1115+ user_config. manually_accept_inbound_channels = true ;
1116+ }
1117+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( user_config) , Some ( user_config) ] ) ;
11131118 let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
11141119
11151120 let ( _, _, chan_id, funding_tx) =
@@ -1219,16 +1224,23 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
12191224
12201225 // The following constants were determined experimentally
12211226 const BS_TO_SELF_CLAIM_EXP_WEIGHT : usize = 483 ;
1222- const OUTBOUND_HTLC_CLAIM_EXP_WEIGHT : usize = 571 ;
1223- const INBOUND_HTLC_CLAIM_EXP_WEIGHT : usize = 578 ;
1227+ let outbound_htlc_claim_exp_weight : usize = if anchors { 574 } else { 571 } ;
1228+ let inbound_htlc_claim_exp_weight : usize = if anchors { 582 } else { 578 } ;
12241229
12251230 // Check that the weight is close to the expected weight. Note that signature sizes vary
12261231 // somewhat so it may not always be exact.
1227- fuzzy_assert_eq ( claim_txn[ 0 ] . weight ( ) , OUTBOUND_HTLC_CLAIM_EXP_WEIGHT ) ;
1228- fuzzy_assert_eq ( claim_txn[ 1 ] . weight ( ) , INBOUND_HTLC_CLAIM_EXP_WEIGHT ) ;
1229- fuzzy_assert_eq ( claim_txn[ 2 ] . weight ( ) , INBOUND_HTLC_CLAIM_EXP_WEIGHT ) ;
1232+ fuzzy_assert_eq ( claim_txn[ 0 ] . weight ( ) , outbound_htlc_claim_exp_weight ) ;
1233+ fuzzy_assert_eq ( claim_txn[ 1 ] . weight ( ) , inbound_htlc_claim_exp_weight ) ;
1234+ fuzzy_assert_eq ( claim_txn[ 2 ] . weight ( ) , inbound_htlc_claim_exp_weight ) ;
12301235 fuzzy_assert_eq ( claim_txn[ 3 ] . weight ( ) , BS_TO_SELF_CLAIM_EXP_WEIGHT ) ;
12311236
1237+ let commitment_tx_fee = chan_feerate *
1238+ ( channel:: commitment_tx_base_weight ( & channel_type_features) + 3 * channel:: COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000 ;
1239+ let anchor_outputs_value = if anchors { channel:: ANCHOR_OUTPUT_VALUE_SATOSHI * 2 } else { 0 } ;
1240+ let inbound_htlc_claim_fee = chan_feerate * inbound_htlc_claim_exp_weight as u64 / 1000 ;
1241+ let outbound_htlc_claim_fee = chan_feerate * outbound_htlc_claim_exp_weight as u64 / 1000 ;
1242+ let to_self_claim_fee = chan_feerate * claim_txn[ 3 ] . weight ( ) as u64 / 1000 ;
1243+
12321244 // The expected balance for the next three checks, with the largest-HTLC and to_self output
12331245 // claim balances separated out.
12341246 let expected_balance = vec ! [ Balance :: ClaimableAwaitingConfirmations {
@@ -1242,8 +1254,7 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
12421254 } ] ;
12431255
12441256 let to_self_unclaimed_balance = Balance :: CounterpartyRevokedOutputClaimable {
1245- amount_satoshis : 1_000_000 - 100_000 - 3_000 - chan_feerate *
1246- ( channel:: commitment_tx_base_weight ( & channel_type_features) + 3 * channel:: COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000 ,
1257+ amount_satoshis : 1_000_000 - 100_000 - 3_000 - commitment_tx_fee - anchor_outputs_value,
12471258 } ;
12481259 let to_self_claimed_avail_height;
12491260 let largest_htlc_unclaimed_balance = Balance :: CounterpartyRevokedOutputClaimable {
@@ -1268,13 +1279,11 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
12681279 }
12691280
12701281 let largest_htlc_claimed_balance = Balance :: ClaimableAwaitingConfirmations {
1271- amount_satoshis : 5_000 - chan_feerate * INBOUND_HTLC_CLAIM_EXP_WEIGHT as u64 / 1000 ,
1282+ amount_satoshis : 5_000 - inbound_htlc_claim_fee ,
12721283 confirmation_height : largest_htlc_claimed_avail_height,
12731284 } ;
12741285 let to_self_claimed_balance = Balance :: ClaimableAwaitingConfirmations {
1275- amount_satoshis : 1_000_000 - 100_000 - 3_000 - chan_feerate *
1276- ( channel:: commitment_tx_base_weight ( & channel_type_features) + 3 * channel:: COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000
1277- - chan_feerate * claim_txn[ 3 ] . weight ( ) as u64 / 1000 ,
1286+ amount_satoshis : 1_000_000 - 100_000 - 3_000 - commitment_tx_fee - anchor_outputs_value - to_self_claim_fee,
12781287 confirmation_height : to_self_claimed_avail_height,
12791288 } ;
12801289
@@ -1304,18 +1313,16 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
13041313 amount_satoshis: 100_000 - 5_000 - 4_000 - 3 ,
13051314 confirmation_height: nodes[ 1 ] . best_block_info( ) . 1 + 1 ,
13061315 } , Balance :: ClaimableAwaitingConfirmations {
1307- amount_satoshis: 1_000_000 - 100_000 - 3_000 - chan_feerate *
1308- ( channel:: commitment_tx_base_weight( & channel_type_features) + 3 * channel:: COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000
1309- - chan_feerate * claim_txn[ 3 ] . weight( ) as u64 / 1000 ,
1316+ amount_satoshis: 1_000_000 - 100_000 - 3_000 - commitment_tx_fee - anchor_outputs_value - to_self_claim_fee,
13101317 confirmation_height: to_self_claimed_avail_height,
13111318 } , Balance :: ClaimableAwaitingConfirmations {
1312- amount_satoshis: 3_000 - chan_feerate * OUTBOUND_HTLC_CLAIM_EXP_WEIGHT as u64 / 1000 ,
1319+ amount_satoshis: 3_000 - outbound_htlc_claim_fee ,
13131320 confirmation_height: nodes[ 1 ] . best_block_info( ) . 1 + 4 ,
13141321 } , Balance :: ClaimableAwaitingConfirmations {
1315- amount_satoshis: 4_000 - chan_feerate * INBOUND_HTLC_CLAIM_EXP_WEIGHT as u64 / 1000 ,
1322+ amount_satoshis: 4_000 - inbound_htlc_claim_fee ,
13161323 confirmation_height: nodes[ 1 ] . best_block_info( ) . 1 + 5 ,
13171324 } , Balance :: ClaimableAwaitingConfirmations {
1318- amount_satoshis: 5_000 - chan_feerate * INBOUND_HTLC_CLAIM_EXP_WEIGHT as u64 / 1000 ,
1325+ amount_satoshis: 5_000 - inbound_htlc_claim_fee ,
13191326 confirmation_height: largest_htlc_claimed_avail_height,
13201327 } ] ) ,
13211328 sorted_vec( nodes[ 1 ] . chain_monitor. chain_monitor. get_monitor( funding_outpoint) . unwrap( ) . get_claimable_balances( ) ) ) ;
@@ -1352,8 +1359,10 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
13521359
13531360#[ test]
13541361fn test_revoked_counterparty_commitment_balances ( ) {
1355- do_test_revoked_counterparty_commitment_balances ( true ) ;
1356- do_test_revoked_counterparty_commitment_balances ( false ) ;
1362+ do_test_revoked_counterparty_commitment_balances ( false , true ) ;
1363+ do_test_revoked_counterparty_commitment_balances ( false , false ) ;
1364+ do_test_revoked_counterparty_commitment_balances ( true , true ) ;
1365+ do_test_revoked_counterparty_commitment_balances ( true , false ) ;
13571366}
13581367
13591368#[ test]
0 commit comments