@@ -53,7 +53,7 @@ use crate::ln::chan_utils::{
5353} ;
5454use crate :: ln:: channel:: ANCHOR_OUTPUT_VALUE_SATOSHI ;
5555use crate :: ln:: channel_keys:: {
56- add_public_key_tweak, DelayedPaymentBasepoint , DelayedPaymentKey , HtlcBasepoint , HtlcKey ,
56+ add_public_key_tweak, DelayedPaymentBasepoint , DelayedPaymentKey , HtlcBasepoint ,
5757 RevocationBasepoint , RevocationKey ,
5858} ;
5959use crate :: ln:: inbound_payment:: ExpandedKey ;
@@ -888,8 +888,31 @@ pub trait ChannelSigner {
888888 }
889889 }
890890
891- /// Sweep a HTLC output on a counterparty commitment transaction. Sweep an offered htlc output if
892- /// the preimage is provided, otherwise, sweep a received htlc output.
891+ /// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
892+ /// transaction, either offered or received.
893+ ///
894+ /// Such a transaction may claim multiples offered outputs at same time if we know the
895+ /// preimage for each when we create it, but only the input at index `input` should be
896+ /// signed for here. It may be called multiple times for same output(s) if a fee-bump is
897+ /// needed with regards to an upcoming timelock expiration.
898+ ///
899+ /// `witness_script` is either an offered or received script as defined in BOLT3 for HTLC
900+ /// outputs.
901+ ///
902+ /// `amount` is value of the output spent by this input, committed to in the BIP 143 signature.
903+ ///
904+ /// `per_commitment_point` is the dynamic point corresponding to the channel state
905+ /// detected onchain. It has been generated by our counterparty and is used to derive
906+ /// channel state keys, which are then included in the witness script and committed to in the
907+ /// BIP 143 signature.
908+ ///
909+ /// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
910+ /// signature and should be retried later. Once the signer is ready to provide a signature after
911+ /// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
912+ /// monitor or [`ChainMonitor::signer_unblocked`] called to attempt unblocking all monitors.
913+ ///
914+ /// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
915+ /// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
893916 fn sweep_counterparty_htlc_output (
894917 & self , sweep_tx : & Transaction , input : usize , amount : u64 ,
895918 secp_ctx : & Secp256k1 < secp256k1:: All > , per_commitment_point : & PublicKey ,
@@ -1702,15 +1725,20 @@ impl ChannelSigner for InMemorySigner {
17021725 ) ;
17031726 let witness_script =
17041727 chan_utils:: get_htlc_redeemscript ( htlc, params. channel_type_features ( ) , & keys) ;
1705- let sig = EcdsaChannelSigner :: sign_counterparty_htlc_transaction (
1706- self ,
1707- sweep_tx,
1708- input,
1709- amount,
1710- per_commitment_point,
1711- htlc,
1712- secp_ctx,
1713- ) ?;
1728+ let htlc_key =
1729+ chan_utils:: derive_private_key ( & secp_ctx, & per_commitment_point, & self . htlc_base_key ) ;
1730+ let mut sighash_parts = sighash:: SighashCache :: new ( sweep_tx) ;
1731+ let sighash = hash_to_message ! (
1732+ & sighash_parts
1733+ . p2wsh_signature_hash(
1734+ input,
1735+ & witness_script,
1736+ Amount :: from_sat( amount) ,
1737+ EcdsaSighashType :: All
1738+ )
1739+ . unwrap( ) [ ..]
1740+ ) ;
1741+ let sig = sign_with_aux_rand ( secp_ctx, & sighash, & htlc_key, & self ) ;
17141742 let ecdsa_sig = EcdsaSignature :: sighash_all ( sig) ;
17151743 let element = match preimage {
17161744 Some ( ref p) => & p. 0 [ ..] ,
@@ -1878,47 +1906,6 @@ impl EcdsaChannelSigner for InMemorySigner {
18781906 Ok ( ( commitment_sig, htlc_sigs) )
18791907 }
18801908
1881- fn sign_counterparty_htlc_transaction (
1882- & self , htlc_tx : & Transaction , input : usize , amount : u64 , per_commitment_point : & PublicKey ,
1883- htlc : & HTLCOutputInCommitment , secp_ctx : & Secp256k1 < secp256k1:: All > ,
1884- ) -> Result < Signature , ( ) > {
1885- let htlc_key =
1886- chan_utils:: derive_private_key ( & secp_ctx, & per_commitment_point, & self . htlc_base_key ) ;
1887- let revocation_pubkey = RevocationKey :: from_basepoint (
1888- & secp_ctx,
1889- & self . pubkeys ( ) . revocation_basepoint ,
1890- & per_commitment_point,
1891- ) ;
1892- let counterparty_keys = self . counterparty_pubkeys ( ) . expect ( MISSING_PARAMS_ERR ) ;
1893- let counterparty_htlcpubkey = HtlcKey :: from_basepoint (
1894- & secp_ctx,
1895- & counterparty_keys. htlc_basepoint ,
1896- & per_commitment_point,
1897- ) ;
1898- let htlc_basepoint = self . pubkeys ( ) . htlc_basepoint ;
1899- let htlcpubkey = HtlcKey :: from_basepoint ( & secp_ctx, & htlc_basepoint, & per_commitment_point) ;
1900- let chan_type = self . channel_type_features ( ) . expect ( MISSING_PARAMS_ERR ) ;
1901- let witness_script = chan_utils:: get_htlc_redeemscript_with_explicit_keys (
1902- & htlc,
1903- chan_type,
1904- & counterparty_htlcpubkey,
1905- & htlcpubkey,
1906- & revocation_pubkey,
1907- ) ;
1908- let mut sighash_parts = sighash:: SighashCache :: new ( htlc_tx) ;
1909- let sighash = hash_to_message ! (
1910- & sighash_parts
1911- . p2wsh_signature_hash(
1912- input,
1913- & witness_script,
1914- Amount :: from_sat( amount) ,
1915- EcdsaSighashType :: All
1916- )
1917- . unwrap( ) [ ..]
1918- ) ;
1919- Ok ( sign_with_aux_rand ( secp_ctx, & sighash, & htlc_key, & self ) )
1920- }
1921-
19221909 fn sign_closing_transaction (
19231910 & self , closing_tx : & ClosingTransaction , secp_ctx : & Secp256k1 < secp256k1:: All > ,
19241911 ) -> Result < Signature , ( ) > {
0 commit comments