@@ -69,10 +69,10 @@ pub fn max_htlcs(channel_type: &ChannelTypeFeatures) -> u16 {
69
69
483
70
70
}
71
71
}
72
- /// The weight of a BIP141 witnessScript for a BOLT3's "offered HTLC output" on a commitment transaction, non-anchor variant.
72
+ /// The weight of a BIP141 witnessScript for a BOLT3's "offered HTLC output" on a commitment transaction, non-anchor and p2a anchor variant.
73
73
pub const OFFERED_HTLC_SCRIPT_WEIGHT : usize = 133 ;
74
- /// The weight of a BIP141 witnessScript for a BOLT3's "offered HTLC output" on a commitment transaction, anchor variant.
75
- pub const OFFERED_HTLC_SCRIPT_WEIGHT_ANCHORS : usize = 136 ;
74
+ /// The weight of a BIP141 witnessScript for a BOLT3's "offered HTLC output" on a commitment transaction, keyed anchor variant.
75
+ pub const OFFERED_HTLC_SCRIPT_WEIGHT_KEYED_ANCHORS : usize = 136 ;
76
76
77
77
/// The weight of a BIP141 witnessScript for a BOLT3's "received HTLC output" can vary in function of its CLTV argument value.
78
78
/// We define a range that encompasses both its non-anchors and anchors variants.
@@ -95,12 +95,16 @@ pub const P2A_ANCHOR_INPUT_WITNESS_WEIGHT: u64 = 1;
95
95
/// The maximum value of a P2A anchor.
96
96
pub const P2A_MAX_VALUE : u64 = 240 ;
97
97
98
- /// The upper bound weight of an HTLC timeout input from a commitment transaction with anchor
99
- /// outputs.
100
- pub const HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT : u64 = 288 ;
101
- /// The upper bound weight of an HTLC success input from a commitment transaction with anchor
102
- /// outputs.
103
- pub const HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT : u64 = 327 ;
98
+ /// The upper bound weight of an HTLC timeout input from a commitment transaction with keyed anchor outputs.
99
+ pub const HTLC_TIMEOUT_INPUT_KEYED_ANCHOR_WITNESS_WEIGHT : u64 = 288 ;
100
+ /// The upper bound weight of an HTLC timeout input from a commitment transaction with a p2a anchor output.
101
+ /// Note the corresponding outputs no longer have the 1 CSV lock.
102
+ pub const HTLC_TIMEOUT_INPUT_P2A_ANCHOR_WITNESS_WEIGHT : u64 = 285 ;
103
+ /// The upper bound weight of an HTLC success input from a commitment transaction with keyed anchor outputs.
104
+ pub const HTLC_SUCCESS_INPUT_KEYED_ANCHOR_WITNESS_WEIGHT : u64 = 327 ;
105
+ /// The upper bound weight of an HTLC success input from a commitment transaction with a p2a anchor output.
106
+ /// Note the corresponding outputs no longer have the 1 CSV lock.
107
+ pub const HTLC_SUCCESS_INPUT_P2A_ANCHOR_WITNESS_WEIGHT : u64 = 324 ;
104
108
105
109
/// The size of the 2-of-2 multisig script
106
110
const MULTISIG_SCRIPT_SIZE : u64 = 1 + // OP_2
@@ -158,7 +162,7 @@ impl HTLCClaim {
158
162
/// Check if a given input witness attempts to claim a HTLC.
159
163
#[ rustfmt:: skip]
160
164
pub fn from_witness ( witness : & Witness ) -> Option < Self > {
161
- debug_assert_eq ! ( OFFERED_HTLC_SCRIPT_WEIGHT_ANCHORS , MIN_ACCEPTED_HTLC_SCRIPT_WEIGHT ) ;
165
+ debug_assert_eq ! ( OFFERED_HTLC_SCRIPT_WEIGHT_KEYED_ANCHORS , MIN_ACCEPTED_HTLC_SCRIPT_WEIGHT ) ;
162
166
if witness. len ( ) < 2 {
163
167
return None ;
164
168
}
@@ -177,7 +181,7 @@ impl HTLCClaim {
177
181
} else {
178
182
None
179
183
}
180
- } else if witness_script. len ( ) == OFFERED_HTLC_SCRIPT_WEIGHT_ANCHORS {
184
+ } else if witness_script. len ( ) == OFFERED_HTLC_SCRIPT_WEIGHT_KEYED_ANCHORS {
181
185
// It's possible for the weight of `offered_htlc_script` and `accepted_htlc_script` to
182
186
// match so we check for both here.
183
187
if witness. len ( ) == 3 && second_to_last. len ( ) == 33 {
@@ -2202,7 +2206,8 @@ mod tests {
2202
2206
use super :: { ChannelPublicKeys , CounterpartyCommitmentSecrets } ;
2203
2207
use crate :: chain;
2204
2208
use crate :: ln:: chan_utils:: {
2205
- get_htlc_redeemscript, get_to_countersigner_keyed_anchor_redeemscript,
2209
+ get_htlc_redeemscript, get_keyed_anchor_redeemscript,
2210
+ get_to_countersigner_keyed_anchor_redeemscript, shared_anchor_script_pubkey,
2206
2211
BuiltCommitmentTransaction , ChannelTransactionParameters , CommitmentTransaction ,
2207
2212
CounterpartyChannelTransactionParameters , HTLCOutputInCommitment ,
2208
2213
TrustedCommitmentTransaction ,
@@ -2250,7 +2255,7 @@ mod tests {
2250
2255
funding_outpoint : Some ( chain:: transaction:: OutPoint { txid : Txid :: all_zeros ( ) , index : 0 } ) ,
2251
2256
splice_parent_funding_txid : None ,
2252
2257
channel_type_features : ChannelTypeFeatures :: only_static_remote_key ( ) ,
2253
- channel_value_satoshis : 3000 ,
2258
+ channel_value_satoshis : 4000 ,
2254
2259
} ;
2255
2260
2256
2261
Self {
@@ -2293,14 +2298,42 @@ mod tests {
2293
2298
let tx = builder. build ( 1000 , 2000 , Vec :: new ( ) ) ;
2294
2299
assert_eq ! ( tx. built. transaction. output. len( ) , 4 ) ;
2295
2300
assert_eq ! ( tx. built. transaction. output[ 3 ] . script_pubkey, get_to_countersigner_keyed_anchor_redeemscript( & builder. counterparty_pubkeys. payment_point) . to_p2wsh( ) ) ;
2301
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, get_keyed_anchor_redeemscript( & builder. channel_parameters. holder_pubkeys. funding_pubkey) . to_p2wsh( ) ) ;
2302
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 330 ) ;
2303
+ assert_eq ! ( tx. built. transaction. output[ 1 ] . script_pubkey, get_keyed_anchor_redeemscript( & builder. counterparty_pubkeys. funding_pubkey) . to_p2wsh( ) ) ;
2304
+ assert_eq ! ( tx. built. transaction. output[ 1 ] . value. to_sat( ) , 330 ) ;
2296
2305
2297
2306
// Generate broadcaster output and anchor
2298
2307
let tx = builder. build ( 3000 , 0 , Vec :: new ( ) ) ;
2299
2308
assert_eq ! ( tx. built. transaction. output. len( ) , 2 ) ;
2309
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, get_keyed_anchor_redeemscript( & builder. channel_parameters. holder_pubkeys. funding_pubkey) . to_p2wsh( ) ) ;
2310
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 330 ) ;
2300
2311
2301
2312
// Generate counterparty output and anchor
2302
2313
let tx = builder. build ( 0 , 3000 , Vec :: new ( ) ) ;
2303
2314
assert_eq ! ( tx. built. transaction. output. len( ) , 2 ) ;
2315
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, get_keyed_anchor_redeemscript( & builder. counterparty_pubkeys. funding_pubkey) . to_p2wsh( ) ) ;
2316
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 330 ) ;
2317
+
2318
+ // Generate broadcaster and counterparty outputs as well as a single anchor
2319
+ builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: anchors_zero_fee_commitments ( ) ;
2320
+ let tx = builder. build ( 1000 , 2000 , Vec :: new ( ) ) ;
2321
+ assert_eq ! ( tx. built. transaction. output. len( ) , 3 ) ;
2322
+ assert_eq ! ( tx. built. transaction. output[ 2 ] . script_pubkey, bitcoin:: address:: Address :: p2wpkh( & CompressedPublicKey ( builder. counterparty_pubkeys. payment_point) , Network :: Testnet ) . script_pubkey( ) ) ;
2323
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, shared_anchor_script_pubkey( ) ) ;
2324
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 240 ) ; // remember total channel value is 4000sat
2325
+
2326
+ // Generate broadcaster output and anchor
2327
+ let tx = builder. build ( 3000 , 0 , Vec :: new ( ) ) ;
2328
+ assert_eq ! ( tx. built. transaction. output. len( ) , 2 ) ;
2329
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, shared_anchor_script_pubkey( ) ) ;
2330
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 240 ) ; // remember total channel value is 4000sat
2331
+
2332
+ // Generate counterparty output and anchor
2333
+ let tx = builder. build ( 0 , 3000 , Vec :: new ( ) ) ;
2334
+ assert_eq ! ( tx. built. transaction. output. len( ) , 2 ) ;
2335
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, shared_anchor_script_pubkey( ) ) ;
2336
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 240 ) ; // remember total channel value is 4000sat
2304
2337
2305
2338
let received_htlc = HTLCOutputInCommitment {
2306
2339
offered : false ,
@@ -2318,7 +2351,7 @@ mod tests {
2318
2351
transaction_output_index : None ,
2319
2352
} ;
2320
2353
2321
- // Generate broadcaster output and received and offered HTLC outputs, w/o anchors
2354
+ // Generate broadcaster output and received and offered HTLC outputs, w/o anchors
2322
2355
builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: only_static_remote_key ( ) ;
2323
2356
let tx = builder. build ( 3000 , 0 , vec ! [ received_htlc. clone( ) , offered_htlc. clone( ) ] ) ;
2324
2357
let keys = tx. trust ( ) . keys ( ) ;
@@ -2330,16 +2363,33 @@ mod tests {
2330
2363
assert_eq ! ( get_htlc_redeemscript( & offered_htlc, & ChannelTypeFeatures :: only_static_remote_key( ) , & keys) . to_p2wsh( ) . to_hex_string( ) ,
2331
2364
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d" ) ;
2332
2365
2333
- // Generate broadcaster output and received and offered HTLC outputs, with anchors
2366
+ // Generate broadcaster output and received and offered HTLC outputs, with keyed anchors
2334
2367
builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies ( ) ;
2335
2368
let tx = builder. build ( 3000 , 0 , vec ! [ received_htlc. clone( ) , offered_htlc. clone( ) ] ) ;
2336
2369
assert_eq ! ( tx. built. transaction. output. len( ) , 5 ) ;
2370
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, get_keyed_anchor_redeemscript( & builder. channel_parameters. holder_pubkeys. funding_pubkey) . to_p2wsh( ) ) ;
2371
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 330 ) ;
2372
+ assert_eq ! ( tx. built. transaction. output[ 1 ] . script_pubkey, get_keyed_anchor_redeemscript( & builder. counterparty_pubkeys. funding_pubkey) . to_p2wsh( ) ) ;
2373
+ assert_eq ! ( tx. built. transaction. output[ 1 ] . value. to_sat( ) , 330 ) ;
2337
2374
assert_eq ! ( tx. built. transaction. output[ 2 ] . script_pubkey, get_htlc_redeemscript( & received_htlc, & ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies( ) , & keys) . to_p2wsh( ) ) ;
2338
2375
assert_eq ! ( tx. built. transaction. output[ 3 ] . script_pubkey, get_htlc_redeemscript( & offered_htlc, & ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies( ) , & keys) . to_p2wsh( ) ) ;
2339
2376
assert_eq ! ( get_htlc_redeemscript( & received_htlc, & ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies( ) , & keys) . to_p2wsh( ) . to_hex_string( ) ,
2340
2377
"0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc" ) ;
2341
2378
assert_eq ! ( get_htlc_redeemscript( & offered_htlc, & ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies( ) , & keys) . to_p2wsh( ) . to_hex_string( ) ,
2342
2379
"002087a3faeb1950a469c0e2db4a79b093a41b9526e5a6fc6ef5cb949bde3be379c7" ) ;
2380
+
2381
+ // Generate broadcaster output and received and offered HTLC outputs, with P2A anchors
2382
+ builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: anchors_zero_fee_commitments ( ) ;
2383
+ let tx = builder. build ( 3000 , 0 , vec ! [ received_htlc. clone( ) , offered_htlc. clone( ) ] ) ;
2384
+ assert_eq ! ( tx. built. transaction. output. len( ) , 4 ) ;
2385
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, shared_anchor_script_pubkey( ) ) ;
2386
+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 0 ) ;
2387
+ assert_eq ! ( tx. built. transaction. output[ 1 ] . script_pubkey, get_htlc_redeemscript( & received_htlc, & ChannelTypeFeatures :: anchors_zero_fee_commitments( ) , & keys) . to_p2wsh( ) ) ;
2388
+ assert_eq ! ( tx. built. transaction. output[ 2 ] . script_pubkey, get_htlc_redeemscript( & offered_htlc, & ChannelTypeFeatures :: anchors_zero_fee_commitments( ) , & keys) . to_p2wsh( ) ) ;
2389
+ assert_eq ! ( get_htlc_redeemscript( & received_htlc, & ChannelTypeFeatures :: anchors_zero_fee_commitments( ) , & keys) . to_p2wsh( ) . to_hex_string( ) ,
2390
+ "0020e43a7c068553003fe68fcae424fb7b28ec5ce48cd8b6744b3945631389bad2fb" ) ;
2391
+ assert_eq ! ( get_htlc_redeemscript( & offered_htlc, & ChannelTypeFeatures :: anchors_zero_fee_commitments( ) , & keys) . to_p2wsh( ) . to_hex_string( ) ,
2392
+ "0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d" ) ;
2343
2393
}
2344
2394
2345
2395
#[ test]
0 commit comments