@@ -69,10 +69,10 @@ pub fn max_htlcs(channel_type: &ChannelTypeFeatures) -> u16 {
6969 483
7070 }
7171}
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.
7373pub 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 ;
7676
7777/// The weight of a BIP141 witnessScript for a BOLT3's "received HTLC output" can vary in function of its CLTV argument value.
7878/// 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;
9595/// The maximum value of a P2A anchor.
9696pub const P2A_MAX_VALUE : u64 = 240 ;
9797
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 ;
104108
105109/// The size of the 2-of-2 multisig script
106110const MULTISIG_SCRIPT_SIZE : u64 = 1 + // OP_2
@@ -158,7 +162,7 @@ impl HTLCClaim {
158162 /// Check if a given input witness attempts to claim a HTLC.
159163 #[ rustfmt:: skip]
160164 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 ) ;
162166 if witness. len ( ) < 2 {
163167 return None ;
164168 }
@@ -177,7 +181,7 @@ impl HTLCClaim {
177181 } else {
178182 None
179183 }
180- } else if witness_script. len ( ) == OFFERED_HTLC_SCRIPT_WEIGHT_ANCHORS {
184+ } else if witness_script. len ( ) == OFFERED_HTLC_SCRIPT_WEIGHT_KEYED_ANCHORS {
181185 // It's possible for the weight of `offered_htlc_script` and `accepted_htlc_script` to
182186 // match so we check for both here.
183187 if witness. len ( ) == 3 && second_to_last. len ( ) == 33 {
@@ -2202,7 +2206,8 @@ mod tests {
22022206 use super :: { ChannelPublicKeys , CounterpartyCommitmentSecrets } ;
22032207 use crate :: chain;
22042208 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,
22062211 BuiltCommitmentTransaction , ChannelTransactionParameters , CommitmentTransaction ,
22072212 CounterpartyChannelTransactionParameters , HTLCOutputInCommitment ,
22082213 TrustedCommitmentTransaction ,
@@ -2250,7 +2255,7 @@ mod tests {
22502255 funding_outpoint : Some ( chain:: transaction:: OutPoint { txid : Txid :: all_zeros ( ) , index : 0 } ) ,
22512256 splice_parent_funding_txid : None ,
22522257 channel_type_features : ChannelTypeFeatures :: only_static_remote_key ( ) ,
2253- channel_value_satoshis : 3000 ,
2258+ channel_value_satoshis : 4000 ,
22542259 } ;
22552260
22562261 Self {
@@ -2293,14 +2298,42 @@ mod tests {
22932298 let tx = builder. build ( 1000 , 2000 , Vec :: new ( ) ) ;
22942299 assert_eq ! ( tx. built. transaction. output. len( ) , 4 ) ;
22952300 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 ) ;
22962305
22972306 // Generate broadcaster output and anchor
22982307 let tx = builder. build ( 3000 , 0 , Vec :: new ( ) ) ;
22992308 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 ) ;
23002311
23012312 // Generate counterparty output and anchor
23022313 let tx = builder. build ( 0 , 3000 , Vec :: new ( ) ) ;
23032314 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
23042337
23052338 let received_htlc = HTLCOutputInCommitment {
23062339 offered : false ,
@@ -2318,7 +2351,7 @@ mod tests {
23182351 transaction_output_index : None ,
23192352 } ;
23202353
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
23222355 builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: only_static_remote_key ( ) ;
23232356 let tx = builder. build ( 3000 , 0 , vec ! [ received_htlc. clone( ) , offered_htlc. clone( ) ] ) ;
23242357 let keys = tx. trust ( ) . keys ( ) ;
@@ -2330,16 +2363,33 @@ mod tests {
23302363 assert_eq ! ( get_htlc_redeemscript( & offered_htlc, & ChannelTypeFeatures :: only_static_remote_key( ) , & keys) . to_p2wsh( ) . to_hex_string( ) ,
23312364 "0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d" ) ;
23322365
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
23342367 builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies ( ) ;
23352368 let tx = builder. build ( 3000 , 0 , vec ! [ received_htlc. clone( ) , offered_htlc. clone( ) ] ) ;
23362369 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 ) ;
23372374 assert_eq ! ( tx. built. transaction. output[ 2 ] . script_pubkey, get_htlc_redeemscript( & received_htlc, & ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies( ) , & keys) . to_p2wsh( ) ) ;
23382375 assert_eq ! ( tx. built. transaction. output[ 3 ] . script_pubkey, get_htlc_redeemscript( & offered_htlc, & ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies( ) , & keys) . to_p2wsh( ) ) ;
23392376 assert_eq ! ( get_htlc_redeemscript( & received_htlc, & ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies( ) , & keys) . to_p2wsh( ) . to_hex_string( ) ,
23402377 "0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc" ) ;
23412378 assert_eq ! ( get_htlc_redeemscript( & offered_htlc, & ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies( ) , & keys) . to_p2wsh( ) . to_hex_string( ) ,
23422379 "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" ) ;
23432393 }
23442394
23452395 #[ test]
0 commit comments