@@ -925,8 +925,31 @@ pub trait ChannelSigner {
925925 }
926926 }
927927
928- /// Sweep a HTLC output on a counterparty commitment transaction. Sweep an offered htlc output if
929- /// the preimage is provided, otherwise, sweep a received htlc output.
928+ /// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
929+ /// transaction, either offered or received.
930+ ///
931+ /// Such a transaction may claim multiples offered outputs at same time if we know the
932+ /// preimage for each when we create it, but only the input at index `input` should be
933+ /// signed for here. It may be called multiple times for same output(s) if a fee-bump is
934+ /// needed with regards to an upcoming timelock expiration.
935+ ///
936+ /// `witness_script` is either an offered or received script as defined in BOLT3 for HTLC
937+ /// outputs.
938+ ///
939+ /// `amount` is value of the output spent by this input, committed to in the BIP 143 signature.
940+ ///
941+ /// `per_commitment_point` is the dynamic point corresponding to the channel state
942+ /// detected onchain. It has been generated by our counterparty and is used to derive
943+ /// channel state keys, which are then included in the witness script and committed to in the
944+ /// BIP 143 signature.
945+ ///
946+ /// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
947+ /// signature and should be retried later. Once the signer is ready to provide a signature after
948+ /// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
949+ /// monitor or [`ChainMonitor::signer_unblocked`] called to attempt unblocking all monitors.
950+ ///
951+ /// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
952+ /// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
930953 fn sweep_counterparty_htlc_output (
931954 & self , sweep_tx : & Transaction , input : usize , amount : u64 ,
932955 secp_ctx : & Secp256k1 < secp256k1:: All > , per_commitment_point : & PublicKey ,
@@ -1739,15 +1762,20 @@ impl ChannelSigner for InMemorySigner {
17391762 ) ;
17401763 let witness_script =
17411764 chan_utils:: get_htlc_redeemscript ( htlc, params. channel_type_features ( ) , & keys) ;
1742- let sig = EcdsaChannelSigner :: sign_counterparty_htlc_transaction (
1743- self ,
1744- sweep_tx,
1745- input,
1746- amount,
1747- per_commitment_point,
1748- htlc,
1749- secp_ctx,
1750- ) ?;
1765+ let htlc_key =
1766+ chan_utils:: derive_private_key ( & secp_ctx, & per_commitment_point, & self . htlc_base_key ) ;
1767+ let mut sighash_parts = sighash:: SighashCache :: new ( sweep_tx) ;
1768+ let sighash = hash_to_message ! (
1769+ & sighash_parts
1770+ . p2wsh_signature_hash(
1771+ input,
1772+ & witness_script,
1773+ Amount :: from_sat( amount) ,
1774+ EcdsaSighashType :: All
1775+ )
1776+ . unwrap( ) [ ..]
1777+ ) ;
1778+ let sig = sign_with_aux_rand ( secp_ctx, & sighash, & htlc_key, & self ) ;
17511779 let ecdsa_sig = EcdsaSignature :: sighash_all ( sig) ;
17521780 let element = match preimage {
17531781 Some ( ref p) => & p. 0 [ ..] ,
@@ -1904,47 +1932,6 @@ impl EcdsaChannelSigner for InMemorySigner {
19041932 Ok ( ( commitment_sig, htlc_sigs) )
19051933 }
19061934
1907- fn sign_counterparty_htlc_transaction (
1908- & self , htlc_tx : & Transaction , input : usize , amount : u64 , per_commitment_point : & PublicKey ,
1909- htlc : & HTLCOutputInCommitment , secp_ctx : & Secp256k1 < secp256k1:: All > ,
1910- ) -> Result < Signature , ( ) > {
1911- let htlc_key =
1912- chan_utils:: derive_private_key ( & secp_ctx, & per_commitment_point, & self . htlc_base_key ) ;
1913- let revocation_pubkey = RevocationKey :: from_basepoint (
1914- & secp_ctx,
1915- & self . pubkeys ( ) . revocation_basepoint ,
1916- & per_commitment_point,
1917- ) ;
1918- let counterparty_keys = self . counterparty_pubkeys ( ) . expect ( MISSING_PARAMS_ERR ) ;
1919- let counterparty_htlcpubkey = HtlcKey :: from_basepoint (
1920- & secp_ctx,
1921- & counterparty_keys. htlc_basepoint ,
1922- & per_commitment_point,
1923- ) ;
1924- let htlc_basepoint = self . pubkeys ( ) . htlc_basepoint ;
1925- let htlcpubkey = HtlcKey :: from_basepoint ( & secp_ctx, & htlc_basepoint, & per_commitment_point) ;
1926- let chan_type = self . channel_type_features ( ) . expect ( MISSING_PARAMS_ERR ) ;
1927- let witness_script = chan_utils:: get_htlc_redeemscript_with_explicit_keys (
1928- & htlc,
1929- chan_type,
1930- & counterparty_htlcpubkey,
1931- & htlcpubkey,
1932- & revocation_pubkey,
1933- ) ;
1934- let mut sighash_parts = sighash:: SighashCache :: new ( htlc_tx) ;
1935- let sighash = hash_to_message ! (
1936- & sighash_parts
1937- . p2wsh_signature_hash(
1938- input,
1939- & witness_script,
1940- Amount :: from_sat( amount) ,
1941- EcdsaSighashType :: All
1942- )
1943- . unwrap( ) [ ..]
1944- ) ;
1945- Ok ( sign_with_aux_rand ( secp_ctx, & sighash, & htlc_key, & self ) )
1946- }
1947-
19481935 fn sign_closing_transaction (
19491936 & self , closing_tx : & ClosingTransaction , secp_ctx : & Secp256k1 < secp256k1:: All > ,
19501937 ) -> Result < Signature , ( ) > {
0 commit comments