@@ -1074,7 +1074,7 @@ fn sorted_vec_with_additions<T: Ord + Clone>(v_orig: &Vec<T>, extra_ts: &[&T]) -
1074
1074
v
1075
1075
}
1076
1076
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 ) {
1078
1078
// Tests `get_claimable_balances` for revoked counterparty commitment transactions.
1079
1079
let mut chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1080
1080
// 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
1083
1083
// transaction which, from the point of view of our keys_manager, is revoked.
1084
1084
chanmon_cfgs[ 1 ] . keys_manager . disable_revocation_policy_check = true ;
1085
1085
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) ] ) ;
1087
1092
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1088
1093
1089
1094
let ( _, _, chan_id, funding_tx) =
@@ -1193,16 +1198,23 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
1193
1198
1194
1199
// The following constants were determined experimentally
1195
1200
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 } ;
1198
1203
1199
1204
// Check that the weight is close to the expected weight. Note that signature sizes vary
1200
1205
// 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 ) ;
1204
1209
fuzzy_assert_eq ( claim_txn[ 3 ] . weight ( ) , BS_TO_SELF_CLAIM_EXP_WEIGHT ) ;
1205
1210
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
+
1206
1218
// The expected balance for the next three checks, with the largest-HTLC and to_self output
1207
1219
// claim balances separated out.
1208
1220
let expected_balance = vec ! [ Balance :: ClaimableAwaitingConfirmations {
@@ -1216,8 +1228,7 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
1216
1228
} ] ;
1217
1229
1218
1230
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,
1221
1232
} ;
1222
1233
let to_self_claimed_avail_height;
1223
1234
let largest_htlc_unclaimed_balance = Balance :: CounterpartyRevokedOutputClaimable {
@@ -1242,13 +1253,11 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
1242
1253
}
1243
1254
1244
1255
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 ,
1246
1257
confirmation_height : largest_htlc_claimed_avail_height,
1247
1258
} ;
1248
1259
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,
1252
1261
confirmation_height : to_self_claimed_avail_height,
1253
1262
} ;
1254
1263
@@ -1278,18 +1287,16 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
1278
1287
amount_satoshis: 100_000 - 5_000 - 4_000 - 3 ,
1279
1288
confirmation_height: nodes[ 1 ] . best_block_info( ) . 1 + 1 ,
1280
1289
} , 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,
1284
1291
confirmation_height: to_self_claimed_avail_height,
1285
1292
} , 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 ,
1287
1294
confirmation_height: nodes[ 1 ] . best_block_info( ) . 1 + 4 ,
1288
1295
} , 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 ,
1290
1297
confirmation_height: nodes[ 1 ] . best_block_info( ) . 1 + 5 ,
1291
1298
} , 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 ,
1293
1300
confirmation_height: largest_htlc_claimed_avail_height,
1294
1301
} ] ) ,
1295
1302
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
1326
1333
1327
1334
#[ test]
1328
1335
fn 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 ) ;
1331
1340
}
1332
1341
1333
1342
#[ test]
0 commit comments