@@ -574,7 +574,7 @@ pub fn get_revokeable_redeemscript(revocation_key: &RevocationKey, contest_delay
574574/// the channel type.
575575pub fn get_counterparty_payment_script ( channel_type_features : & ChannelTypeFeatures , payment_key : & PublicKey ) -> ScriptBuf {
576576 if channel_type_features. supports_anchors_zero_fee_htlc_tx ( ) {
577- get_to_countersignatory_with_anchors_redeemscript ( payment_key) . to_p2wsh ( )
577+ get_to_countersigner_keyed_anchor_redeemscript ( payment_key) . to_p2wsh ( )
578578 } else {
579579 ScriptBuf :: new_p2wpkh ( & WPubkeyHash :: hash ( & payment_key. serialize ( ) ) )
580580 }
@@ -838,7 +838,7 @@ pub(crate) fn legacy_deserialization_prevention_marker_for_channel_type_features
838838
839839/// Gets the witnessScript for the to_remote output when anchors are enabled.
840840#[ inline]
841- pub fn get_to_countersignatory_with_anchors_redeemscript ( payment_point : & PublicKey ) -> ScriptBuf {
841+ pub fn get_to_countersigner_keyed_anchor_redeemscript ( payment_point : & PublicKey ) -> ScriptBuf {
842842 Builder :: new ( )
843843 . push_slice ( payment_point. serialize ( ) )
844844 . push_opcode ( opcodes:: all:: OP_CHECKSIGVERIFY )
@@ -847,14 +847,20 @@ pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicK
847847 . into_script ( )
848848}
849849
850- /// Gets the witnessScript for an anchor output from the funding public key.
850+ /// Gets the script_pubkey for a shared anchor
851+ pub fn shared_anchor_script_pubkey ( ) -> ScriptBuf {
852+ Builder :: new ( ) . push_int ( 1 ) . push_slice ( & [ 0x4e , 0x73 ] ) . into_script ( )
853+ }
854+
855+ /// Gets the witnessScript for a keyed anchor (non-zero-fee-commitments) output from the funding
856+ /// public key.
857+ ///
851858/// The witness in the spending input must be:
852859/// <BIP 143 funding_signature>
853860/// After 16 blocks of confirmation, an alternative satisfying witness could be:
854861/// <>
855862/// (empty vector required to satisfy compliance with MINIMALIF-standard rule)
856- #[ inline]
857- pub fn get_anchor_redeemscript ( funding_pubkey : & PublicKey ) -> ScriptBuf {
863+ pub fn get_keyed_anchor_redeemscript ( funding_pubkey : & PublicKey ) -> ScriptBuf {
858864 Builder :: new ( ) . push_slice ( funding_pubkey. serialize ( ) )
859865 . push_opcode ( opcodes:: all:: OP_CHECKSIG )
860866 . push_opcode ( opcodes:: all:: OP_IFDUP )
@@ -865,17 +871,19 @@ pub fn get_anchor_redeemscript(funding_pubkey: &PublicKey) -> ScriptBuf {
865871 . into_script ( )
866872}
867873
868- /// Locates the output with an anchor script paying to `funding_pubkey` within `commitment_tx`.
869- pub ( crate ) fn get_anchor_output < ' a > ( commitment_tx : & ' a Transaction , funding_pubkey : & PublicKey ) -> Option < ( u32 , & ' a TxOut ) > {
870- let anchor_script = get_anchor_redeemscript ( funding_pubkey) . to_p2wsh ( ) ;
874+ /// Locates the output with a keyed anchor (non-zero-fee-commitments) script paying to
875+ /// `funding_pubkey` within `commitment_tx`.
876+ pub ( crate ) fn get_keyed_anchor_output < ' a > ( commitment_tx : & ' a Transaction , funding_pubkey : & PublicKey ) -> Option < ( u32 , & ' a TxOut ) > {
877+ let anchor_script = get_keyed_anchor_redeemscript ( funding_pubkey) . to_p2wsh ( ) ;
871878 commitment_tx. output . iter ( ) . enumerate ( )
872879 . find ( |( _, txout) | txout. script_pubkey == anchor_script)
873880 . map ( |( idx, txout) | ( idx as u32 , txout) )
874881}
875882
876- /// Returns the witness required to satisfy and spend an anchor input.
877- pub fn build_anchor_input_witness ( funding_key : & PublicKey , funding_sig : & Signature ) -> Witness {
878- let anchor_redeem_script = get_anchor_redeemscript ( funding_key) ;
883+ /// Returns the witness required to satisfy and spend a keyed anchor (non-zero-fee-commitments)
884+ /// input.
885+ pub fn build_keyed_anchor_input_witness ( funding_key : & PublicKey , funding_sig : & Signature ) -> Witness {
886+ let anchor_redeem_script = get_keyed_anchor_redeemscript ( funding_key) ;
879887 let mut ret = Witness :: new ( ) ;
880888 ret. push_ecdsa_signature ( & BitcoinSignature :: sighash_all ( * funding_sig) ) ;
881889 ret. push ( anchor_redeem_script. as_bytes ( ) ) ;
@@ -1117,7 +1125,7 @@ impl<'a> DirectedChannelTransactionParameters<'a> {
11171125 self . inner . funding_outpoint . unwrap ( ) . into_bitcoin_outpoint ( )
11181126 }
11191127
1120- /// Whether to use anchors for this channel
1128+ /// The type of channel these parameters are for
11211129 pub fn channel_type_features ( & self ) -> & ' a ChannelTypeFeatures {
11221130 & self . inner . channel_type_features
11231131 }
@@ -1574,7 +1582,7 @@ impl CommitmentTransaction {
15741582
15751583 if to_countersignatory_value_sat > Amount :: ZERO {
15761584 let script = if channel_parameters. channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
1577- get_to_countersignatory_with_anchors_redeemscript ( & countersignatory_pubkeys. payment_point ) . to_p2wsh ( )
1585+ get_to_countersigner_keyed_anchor_redeemscript ( & countersignatory_pubkeys. payment_point ) . to_p2wsh ( )
15781586 } else {
15791587 ScriptBuf :: new_p2wpkh ( & Hash160 :: hash ( & countersignatory_pubkeys. payment_point . serialize ( ) ) . into ( ) )
15801588 } ;
@@ -1604,7 +1612,7 @@ impl CommitmentTransaction {
16041612
16051613 if channel_parameters. channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
16061614 if to_broadcaster_value_sat > Amount :: ZERO || !htlcs_with_aux. is_empty ( ) {
1607- let anchor_script = get_anchor_redeemscript ( broadcaster_funding_key) ;
1615+ let anchor_script = get_keyed_anchor_redeemscript ( broadcaster_funding_key) ;
16081616 txouts. push ( (
16091617 TxOut {
16101618 script_pubkey : anchor_script. to_p2wsh ( ) ,
@@ -1615,7 +1623,7 @@ impl CommitmentTransaction {
16151623 }
16161624
16171625 if to_countersignatory_value_sat > Amount :: ZERO || !htlcs_with_aux. is_empty ( ) {
1618- let anchor_script = get_anchor_redeemscript ( countersignatory_funding_key) ;
1626+ let anchor_script = get_keyed_anchor_redeemscript ( countersignatory_funding_key) ;
16191627 txouts. push ( (
16201628 TxOut {
16211629 script_pubkey : anchor_script. to_p2wsh ( ) ,
@@ -1953,7 +1961,7 @@ pub fn get_commitment_transaction_number_obscure_factor(
19531961mod tests {
19541962 use super :: { CounterpartyCommitmentSecrets , ChannelPublicKeys } ;
19551963 use crate :: chain;
1956- use crate :: ln:: chan_utils:: { get_htlc_redeemscript, get_to_countersignatory_with_anchors_redeemscript , CommitmentTransaction , TxCreationKeys , ChannelTransactionParameters , CounterpartyChannelTransactionParameters , HTLCOutputInCommitment } ;
1964+ use crate :: ln:: chan_utils:: { get_htlc_redeemscript, get_to_countersigner_keyed_anchor_redeemscript , CommitmentTransaction , TxCreationKeys , ChannelTransactionParameters , CounterpartyChannelTransactionParameters , HTLCOutputInCommitment } ;
19571965 use bitcoin:: secp256k1:: { PublicKey , SecretKey , Secp256k1 } ;
19581966 use crate :: util:: test_utils;
19591967 use crate :: sign:: { ChannelSigner , SignerProvider } ;
@@ -2043,7 +2051,7 @@ mod tests {
20432051 builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies ( ) ;
20442052 let tx = builder. build ( 1000 , 2000 ) ;
20452053 assert_eq ! ( tx. built. transaction. output. len( ) , 4 ) ;
2046- assert_eq ! ( tx. built. transaction. output[ 3 ] . script_pubkey, get_to_countersignatory_with_anchors_redeemscript ( & builder. counterparty_pubkeys. payment_point) . to_p2wsh( ) ) ;
2054+ assert_eq ! ( tx. built. transaction. output[ 3 ] . script_pubkey, get_to_countersigner_keyed_anchor_redeemscript ( & builder. counterparty_pubkeys. payment_point) . to_p2wsh( ) ) ;
20472055
20482056 // Generate broadcaster output and anchor
20492057 let tx = builder. build ( 3000 , 0 ) ;
0 commit comments