Skip to content

Commit 06bfe81

Browse files
committed
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.
1 parent 73d81c0 commit 06bfe81

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

lightning/src/ln/async_signer_tests.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,10 +1022,11 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
10221022

10231023
let per_peer_state = nodes[1].node.per_peer_state.read().unwrap();
10241024
let mut chan_lock = per_peer_state.get(&nodes[0].node.get_our_node_id()).unwrap().lock().unwrap();
1025-
let context = chan_lock.channel_by_id.get_mut(&chan_id).map(|chan| chan.context_mut()).unwrap();
1025+
let channel = chan_lock.channel_by_id.get_mut(&chan_id).unwrap();
1026+
let (funding, context) = channel.funding_and_context_mut();
10261027

10271028
let signer = context.get_mut_signer().as_mut_ecdsa().unwrap();
1028-
let signature = signer.sign_closing_transaction(&closing_tx_2, &Secp256k1::new()).unwrap();
1029+
let signature = signer.sign_closing_transaction(&funding.channel_transaction_parameters, &closing_tx_2, &Secp256k1::new()).unwrap();
10291030
node_1_closing_signed_2.signature = signature;
10301031
node_1_closing_signed_2
10311032
};

lightning/src/ln/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7265,7 +7265,7 @@ impl<SP: Deref> FundedChannel<SP> where
72657265
where L::Target: Logger
72667266
{
72677267
let sig = match &self.context.holder_signer {
7268-
ChannelSignerType::Ecdsa(ecdsa) => ecdsa.sign_closing_transaction(closing_tx, &self.context.secp_ctx).ok(),
7268+
ChannelSignerType::Ecdsa(ecdsa) => ecdsa.sign_closing_transaction(&self.funding.channel_transaction_parameters, closing_tx, &self.context.secp_ctx).ok(),
72697269
// TODO (taproot|arik)
72707270
#[cfg(taproot)]
72717271
_ => todo!()

lightning/src/sign/ecdsa.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ pub trait EcdsaChannelSigner: ChannelSigner {
209209
///
210210
/// [`ChannelManager::signer_unblocked`]: crate::ln::channelmanager::ChannelManager::signer_unblocked
211211
fn sign_closing_transaction(
212-
&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
212+
&self, channel_parameters: &ChannelTransactionParameters, closing_tx: &ClosingTransaction,
213+
secp_ctx: &Secp256k1<secp256k1::All>,
213214
) -> Result<Signature, ()>;
214215
/// Computes the signature for a commitment transaction's anchor output used as an
215216
/// input within `anchor_tx`, which spends the commitment transaction, at index `input`.

lightning/src/sign/mod.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,14 +1161,6 @@ impl InMemorySigner {
11611161
self.get_channel_parameters().map(|params| params.is_outbound_from_holder)
11621162
}
11631163

1164-
/// Funding outpoint
1165-
///
1166-
/// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1167-
/// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1168-
pub fn funding_outpoint(&self) -> Option<&OutPoint> {
1169-
self.get_channel_parameters().map(|params| params.funding_outpoint.as_ref()).flatten()
1170-
}
1171-
11721164
/// Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
11731165
/// building transactions.
11741166
///
@@ -1653,17 +1645,18 @@ impl EcdsaChannelSigner for InMemorySigner {
16531645
}
16541646

16551647
fn sign_closing_transaction(
1656-
&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
1648+
&self, channel_parameters: &ChannelTransactionParameters, closing_tx: &ClosingTransaction,
1649+
secp_ctx: &Secp256k1<secp256k1::All>,
16571650
) -> Result<Signature, ()> {
16581651
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
16591652
let counterparty_funding_key =
1660-
&self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR).funding_pubkey;
1653+
&channel_parameters.counterparty_pubkeys().expect(MISSING_PARAMS_ERR).funding_pubkey;
16611654
let channel_funding_redeemscript =
16621655
make_funding_redeemscript(&funding_pubkey, counterparty_funding_key);
16631656
Ok(closing_tx.trust().sign(
16641657
&self.funding_key,
16651658
&channel_funding_redeemscript,
1666-
self.channel_value_satoshis,
1659+
channel_parameters.channel_value_satoshis,
16671660
secp_ctx,
16681661
))
16691662
}

lightning/src/util/test_channel_signer.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,16 +434,17 @@ impl EcdsaChannelSigner for TestChannelSigner {
434434
}
435435

436436
fn sign_closing_transaction(
437-
&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
437+
&self, channel_parameters: &ChannelTransactionParameters, closing_tx: &ClosingTransaction,
438+
secp_ctx: &Secp256k1<secp256k1::All>,
438439
) -> Result<Signature, ()> {
439440
#[cfg(test)]
440441
if !self.is_signer_available(SignerOp::SignClosingTransaction) {
441442
return Err(());
442443
}
443444
closing_tx
444-
.verify(self.inner.funding_outpoint().unwrap().into_bitcoin_outpoint())
445+
.verify(channel_parameters.funding_outpoint.as_ref().unwrap().into_bitcoin_outpoint())
445446
.expect("derived different closing transaction");
446-
Ok(self.inner.sign_closing_transaction(closing_tx, secp_ctx).unwrap())
447+
Ok(self.inner.sign_closing_transaction(channel_parameters, closing_tx, secp_ctx).unwrap())
447448
}
448449

449450
fn sign_holder_anchor_input(

0 commit comments

Comments
 (0)