mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-14 07:06:42 +01:00
Pass channel params to sign_closing_transaction
Now that channel_value_satoshis has been moved to ChannelTransactionParameters, pass the entire parameters when calling each method on EcdsaChannelSigner. This will remove the need for ChannelSigner::provide_channel_parameters. Instead, the parameters from the FundingScope will be passed in to each method. This simplifies the interaction with a ChannelSigner when needing to be called for more than one FundingScope, which will be the case for pending splices and RBF attempts.
This commit is contained in:
parent
18e0d6aa7f
commit
8379161ad9
5 changed files with 14 additions and 18 deletions
|
@ -1022,10 +1022,11 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
|
|||
|
||||
let per_peer_state = nodes[1].node.per_peer_state.read().unwrap();
|
||||
let mut chan_lock = per_peer_state.get(&nodes[0].node.get_our_node_id()).unwrap().lock().unwrap();
|
||||
let context = chan_lock.channel_by_id.get_mut(&chan_id).map(|chan| chan.context_mut()).unwrap();
|
||||
let channel = chan_lock.channel_by_id.get_mut(&chan_id).unwrap();
|
||||
let (funding, context) = channel.funding_and_context_mut();
|
||||
|
||||
let signer = context.get_mut_signer().as_mut_ecdsa().unwrap();
|
||||
let signature = signer.sign_closing_transaction(&closing_tx_2, &Secp256k1::new()).unwrap();
|
||||
let signature = signer.sign_closing_transaction(&funding.channel_transaction_parameters, &closing_tx_2, &Secp256k1::new()).unwrap();
|
||||
node_1_closing_signed_2.signature = signature;
|
||||
node_1_closing_signed_2
|
||||
};
|
||||
|
|
|
@ -7292,7 +7292,7 @@ impl<SP: Deref> FundedChannel<SP> where
|
|||
where L::Target: Logger
|
||||
{
|
||||
let sig = match &self.context.holder_signer {
|
||||
ChannelSignerType::Ecdsa(ecdsa) => ecdsa.sign_closing_transaction(closing_tx, &self.context.secp_ctx).ok(),
|
||||
ChannelSignerType::Ecdsa(ecdsa) => ecdsa.sign_closing_transaction(&self.funding.channel_transaction_parameters, closing_tx, &self.context.secp_ctx).ok(),
|
||||
// TODO (taproot|arik)
|
||||
#[cfg(taproot)]
|
||||
_ => todo!()
|
||||
|
|
|
@ -209,7 +209,8 @@ pub trait EcdsaChannelSigner: ChannelSigner {
|
|||
///
|
||||
/// [`ChannelManager::signer_unblocked`]: crate::ln::channelmanager::ChannelManager::signer_unblocked
|
||||
fn sign_closing_transaction(
|
||||
&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
|
||||
&self, channel_parameters: &ChannelTransactionParameters, closing_tx: &ClosingTransaction,
|
||||
secp_ctx: &Secp256k1<secp256k1::All>,
|
||||
) -> Result<Signature, ()>;
|
||||
/// Computes the signature for a commitment transaction's anchor output used as an
|
||||
/// input within `anchor_tx`, which spends the commitment transaction, at index `input`.
|
||||
|
|
|
@ -1161,14 +1161,6 @@ impl InMemorySigner {
|
|||
self.get_channel_parameters().map(|params| params.is_outbound_from_holder)
|
||||
}
|
||||
|
||||
/// Funding outpoint
|
||||
///
|
||||
/// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
|
||||
/// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
|
||||
pub fn funding_outpoint(&self) -> Option<&OutPoint> {
|
||||
self.get_channel_parameters().map(|params| params.funding_outpoint.as_ref()).flatten()
|
||||
}
|
||||
|
||||
/// Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
|
||||
/// building transactions.
|
||||
///
|
||||
|
@ -1653,17 +1645,18 @@ impl EcdsaChannelSigner for InMemorySigner {
|
|||
}
|
||||
|
||||
fn sign_closing_transaction(
|
||||
&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
|
||||
&self, channel_parameters: &ChannelTransactionParameters, closing_tx: &ClosingTransaction,
|
||||
secp_ctx: &Secp256k1<secp256k1::All>,
|
||||
) -> Result<Signature, ()> {
|
||||
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
|
||||
let counterparty_funding_key =
|
||||
&self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR).funding_pubkey;
|
||||
&channel_parameters.counterparty_pubkeys().expect(MISSING_PARAMS_ERR).funding_pubkey;
|
||||
let channel_funding_redeemscript =
|
||||
make_funding_redeemscript(&funding_pubkey, counterparty_funding_key);
|
||||
Ok(closing_tx.trust().sign(
|
||||
&self.funding_key,
|
||||
&channel_funding_redeemscript,
|
||||
self.channel_value_satoshis,
|
||||
channel_parameters.channel_value_satoshis,
|
||||
secp_ctx,
|
||||
))
|
||||
}
|
||||
|
|
|
@ -434,16 +434,17 @@ impl EcdsaChannelSigner for TestChannelSigner {
|
|||
}
|
||||
|
||||
fn sign_closing_transaction(
|
||||
&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
|
||||
&self, channel_parameters: &ChannelTransactionParameters, closing_tx: &ClosingTransaction,
|
||||
secp_ctx: &Secp256k1<secp256k1::All>,
|
||||
) -> Result<Signature, ()> {
|
||||
#[cfg(test)]
|
||||
if !self.is_signer_available(SignerOp::SignClosingTransaction) {
|
||||
return Err(());
|
||||
}
|
||||
closing_tx
|
||||
.verify(self.inner.funding_outpoint().unwrap().into_bitcoin_outpoint())
|
||||
.verify(channel_parameters.funding_outpoint.as_ref().unwrap().into_bitcoin_outpoint())
|
||||
.expect("derived different closing transaction");
|
||||
Ok(self.inner.sign_closing_transaction(closing_tx, secp_ctx).unwrap())
|
||||
Ok(self.inner.sign_closing_transaction(channel_parameters, closing_tx, secp_ctx).unwrap())
|
||||
}
|
||||
|
||||
fn sign_holder_anchor_input(
|
||||
|
|
Loading…
Add table
Reference in a new issue