@@ -1100,7 +1100,7 @@ fn sorted_vec_with_additions<T: Ord + Clone>(v_orig: &Vec<T>, extra_ts: &[&T]) -
1100
1100
v
1101
1101
}
1102
1102
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 ) {
1104
1104
// Tests `get_claimable_balances` for revoked counterparty commitment transactions.
1105
1105
let mut chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1106
1106
// 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
1109
1109
// transaction which, from the point of view of our keys_manager, is revoked.
1110
1110
chanmon_cfgs[ 1 ] . keys_manager . disable_revocation_policy_check = true ;
1111
1111
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) ] ) ;
1113
1118
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1114
1119
1115
1120
let ( _, _, chan_id, funding_tx) =
@@ -1219,16 +1224,23 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
1219
1224
1220
1225
// The following constants were determined experimentally
1221
1226
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 } ;
1224
1229
1225
1230
// Check that the weight is close to the expected weight. Note that signature sizes vary
1226
1231
// 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 ) ;
1230
1235
fuzzy_assert_eq ( claim_txn[ 3 ] . weight ( ) , BS_TO_SELF_CLAIM_EXP_WEIGHT ) ;
1231
1236
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
+
1232
1244
// The expected balance for the next three checks, with the largest-HTLC and to_self output
1233
1245
// claim balances separated out.
1234
1246
let expected_balance = vec ! [ Balance :: ClaimableAwaitingConfirmations {
@@ -1242,8 +1254,7 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
1242
1254
} ] ;
1243
1255
1244
1256
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,
1247
1258
} ;
1248
1259
let to_self_claimed_avail_height;
1249
1260
let largest_htlc_unclaimed_balance = Balance :: CounterpartyRevokedOutputClaimable {
@@ -1268,13 +1279,11 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
1268
1279
}
1269
1280
1270
1281
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 ,
1272
1283
confirmation_height : largest_htlc_claimed_avail_height,
1273
1284
} ;
1274
1285
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,
1278
1287
confirmation_height : to_self_claimed_avail_height,
1279
1288
} ;
1280
1289
@@ -1304,18 +1313,16 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
1304
1313
amount_satoshis: 100_000 - 5_000 - 4_000 - 3 ,
1305
1314
confirmation_height: nodes[ 1 ] . best_block_info( ) . 1 + 1 ,
1306
1315
} , 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,
1310
1317
confirmation_height: to_self_claimed_avail_height,
1311
1318
} , 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 ,
1313
1320
confirmation_height: nodes[ 1 ] . best_block_info( ) . 1 + 4 ,
1314
1321
} , 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 ,
1316
1323
confirmation_height: nodes[ 1 ] . best_block_info( ) . 1 + 5 ,
1317
1324
} , 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 ,
1319
1326
confirmation_height: largest_htlc_claimed_avail_height,
1320
1327
} ] ) ,
1321
1328
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
1352
1359
1353
1360
#[ test]
1354
1361
fn 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 ) ;
1357
1366
}
1358
1367
1359
1368
#[ test]
0 commit comments