Skip to content

Commit 63611a5

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 740e014 commit 63611a5

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
@@ -7122,7 +7122,7 @@ impl<SP: Deref> FundedChannel<SP> where
71227122
where L::Target: Logger
71237123
{
71247124
let sig = match &self.context.holder_signer {
7125-
ChannelSignerType::Ecdsa(ecdsa) => ecdsa.sign_closing_transaction(closing_tx, &self.context.secp_ctx).ok(),
7125+
ChannelSignerType::Ecdsa(ecdsa) => ecdsa.sign_closing_transaction(&self.funding.channel_transaction_parameters, closing_tx, &self.context.secp_ctx).ok(),
71267126
// TODO (taproot|arik)
71277127
#[cfg(taproot)]
71287128
_ => 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
@@ -1178,14 +1178,6 @@ impl InMemorySigner {
11781178
self.get_channel_parameters().map(|params| params.is_outbound_from_holder)
11791179
}
11801180

1181-
/// Funding outpoint
1182-
///
1183-
/// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1184-
/// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1185-
pub fn funding_outpoint(&self) -> Option<&OutPoint> {
1186-
self.get_channel_parameters().map(|params| params.funding_outpoint.as_ref()).flatten()
1187-
}
1188-
11891181
/// Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
11901182
/// building transactions.
11911183
///
@@ -1670,17 +1662,18 @@ impl EcdsaChannelSigner for InMemorySigner {
16701662
}
16711663

16721664
fn sign_closing_transaction(
1673-
&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
1665+
&self, channel_parameters: &ChannelTransactionParameters, closing_tx: &ClosingTransaction,
1666+
secp_ctx: &Secp256k1<secp256k1::All>,
16741667
) -> Result<Signature, ()> {
16751668
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
16761669
let counterparty_funding_key =
1677-
&self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR).funding_pubkey;
1670+
&channel_parameters.counterparty_pubkeys().expect(MISSING_PARAMS_ERR).funding_pubkey;
16781671
let channel_funding_redeemscript =
16791672
make_funding_redeemscript(&funding_pubkey, counterparty_funding_key);
16801673
Ok(closing_tx.trust().sign(
16811674
&self.funding_key,
16821675
&channel_funding_redeemscript,
1683-
self.channel_value_satoshis,
1676+
channel_parameters.channel_value_satoshis,
16841677
secp_ctx,
16851678
))
16861679
}

lightning/src/util/test_channel_signer.rs

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

438438
fn sign_closing_transaction(
439-
&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
439+
&self, channel_parameters: &ChannelTransactionParameters, closing_tx: &ClosingTransaction,
440+
secp_ctx: &Secp256k1<secp256k1::All>,
440441
) -> Result<Signature, ()> {
441442
#[cfg(test)]
442443
if !self.is_signer_available(SignerOp::SignClosingTransaction) {
443444
return Err(());
444445
}
445446
closing_tx
446-
.verify(self.inner.funding_outpoint().unwrap().into_bitcoin_outpoint())
447+
.verify(channel_parameters.funding_outpoint.as_ref().unwrap().into_bitcoin_outpoint())
447448
.expect("derived different closing transaction");
448-
Ok(self.inner.sign_closing_transaction(closing_tx, secp_ctx).unwrap())
449+
Ok(self.inner.sign_closing_transaction(channel_parameters, closing_tx, secp_ctx).unwrap())
449450
}
450451

451452
fn sign_holder_anchor_input(

0 commit comments

Comments
 (0)