@@ -574,7 +574,7 @@ pub fn get_revokeable_redeemscript(revocation_key: &RevocationKey, contest_delay
574
574
/// the channel type.
575
575
pub fn get_counterparty_payment_script ( channel_type_features : & ChannelTypeFeatures , payment_key : & PublicKey ) -> ScriptBuf {
576
576
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 ( )
578
578
} else {
579
579
ScriptBuf :: new_p2wpkh ( & WPubkeyHash :: hash ( & payment_key. serialize ( ) ) )
580
580
}
@@ -838,7 +838,7 @@ pub(crate) fn legacy_deserialization_prevention_marker_for_channel_type_features
838
838
839
839
/// Gets the witnessScript for the to_remote output when anchors are enabled.
840
840
#[ 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 {
842
842
Builder :: new ( )
843
843
. push_slice ( payment_point. serialize ( ) )
844
844
. push_opcode ( opcodes:: all:: OP_CHECKSIGVERIFY )
@@ -847,14 +847,20 @@ pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicK
847
847
. into_script ( )
848
848
}
849
849
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
+ ///
851
858
/// The witness in the spending input must be:
852
859
/// <BIP 143 funding_signature>
853
860
/// After 16 blocks of confirmation, an alternative satisfying witness could be:
854
861
/// <>
855
862
/// (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 {
858
864
Builder :: new ( ) . push_slice ( funding_pubkey. serialize ( ) )
859
865
. push_opcode ( opcodes:: all:: OP_CHECKSIG )
860
866
. push_opcode ( opcodes:: all:: OP_IFDUP )
@@ -865,17 +871,19 @@ pub fn get_anchor_redeemscript(funding_pubkey: &PublicKey) -> ScriptBuf {
865
871
. into_script ( )
866
872
}
867
873
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 ( ) ;
871
878
commitment_tx. output . iter ( ) . enumerate ( )
872
879
. find ( |( _, txout) | txout. script_pubkey == anchor_script)
873
880
. map ( |( idx, txout) | ( idx as u32 , txout) )
874
881
}
875
882
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) ;
879
887
let mut ret = Witness :: new ( ) ;
880
888
ret. push_ecdsa_signature ( & BitcoinSignature :: sighash_all ( * funding_sig) ) ;
881
889
ret. push ( anchor_redeem_script. as_bytes ( ) ) ;
@@ -1117,7 +1125,7 @@ impl<'a> DirectedChannelTransactionParameters<'a> {
1117
1125
self . inner . funding_outpoint . unwrap ( ) . into_bitcoin_outpoint ( )
1118
1126
}
1119
1127
1120
- /// Whether to use anchors for this channel
1128
+ /// The type of channel these parameters are for
1121
1129
pub fn channel_type_features ( & self ) -> & ' a ChannelTypeFeatures {
1122
1130
& self . inner . channel_type_features
1123
1131
}
@@ -1574,7 +1582,7 @@ impl CommitmentTransaction {
1574
1582
1575
1583
if to_countersignatory_value_sat > Amount :: ZERO {
1576
1584
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 ( )
1578
1586
} else {
1579
1587
ScriptBuf :: new_p2wpkh ( & Hash160 :: hash ( & countersignatory_pubkeys. payment_point . serialize ( ) ) . into ( ) )
1580
1588
} ;
@@ -1604,7 +1612,7 @@ impl CommitmentTransaction {
1604
1612
1605
1613
if channel_parameters. channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
1606
1614
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) ;
1608
1616
txouts. push ( (
1609
1617
TxOut {
1610
1618
script_pubkey : anchor_script. to_p2wsh ( ) ,
@@ -1615,7 +1623,7 @@ impl CommitmentTransaction {
1615
1623
}
1616
1624
1617
1625
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) ;
1619
1627
txouts. push ( (
1620
1628
TxOut {
1621
1629
script_pubkey : anchor_script. to_p2wsh ( ) ,
@@ -1953,7 +1961,7 @@ pub fn get_commitment_transaction_number_obscure_factor(
1953
1961
mod tests {
1954
1962
use super :: { CounterpartyCommitmentSecrets , ChannelPublicKeys } ;
1955
1963
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 } ;
1957
1965
use bitcoin:: secp256k1:: { PublicKey , SecretKey , Secp256k1 } ;
1958
1966
use crate :: util:: test_utils;
1959
1967
use crate :: sign:: { ChannelSigner , SignerProvider } ;
@@ -2043,7 +2051,7 @@ mod tests {
2043
2051
builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies ( ) ;
2044
2052
let tx = builder. build ( 1000 , 2000 ) ;
2045
2053
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( ) ) ;
2047
2055
2048
2056
// Generate broadcaster output and anchor
2049
2057
let tx = builder. build ( 3000 , 0 ) ;
0 commit comments