Skip to content

Commit ee72c4a

Browse files
committed
Pass channel params to sign_counterparty_commitment
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 dc995ea commit ee72c4a

File tree

6 files changed

+43
-23
lines changed

6 files changed

+43
-23
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,11 @@ impl ChannelTransactionParameters {
931931
}
932932
}
933933

934+
/// Returns the counterparty's pubkeys.
935+
pub fn counterparty_pubkeys(&self) -> Option<&ChannelPublicKeys> {
936+
self.counterparty_parameters.as_ref().map(|params| &params.pubkeys)
937+
}
938+
934939
#[cfg(test)]
935940
pub fn test_dummy(channel_value_satoshis: u64) -> Self {
936941
let dummy_keys = ChannelPublicKeys {

lightning/src/ln/channel.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4415,7 +4415,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
44154415

44164416
/// Only allowed after [`FundingScope::channel_transaction_parameters`] is set.
44174417
fn get_funding_signed_msg<L: Deref>(
4418-
&mut self, logger: &L, counterparty_initial_commitment_tx: CommitmentTransaction
4418+
&mut self, channel_parameters: &ChannelTransactionParameters, logger: &L,
4419+
counterparty_initial_commitment_tx: CommitmentTransaction,
44194420
) -> Option<msgs::FundingSigned> where L::Target: Logger {
44204421
let counterparty_trusted_tx = counterparty_initial_commitment_tx.trust();
44214422
let counterparty_initial_bitcoin_tx = counterparty_trusted_tx.built_transaction();
@@ -4426,7 +4427,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
44264427
let signature = match &self.holder_signer {
44274428
// TODO (arik): move match into calling method for Taproot
44284429
ChannelSignerType::Ecdsa(ecdsa) => ecdsa.sign_counterparty_commitment(
4429-
&counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx
4430+
channel_parameters, &counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx
44304431
).ok(),
44314432
// TODO (taproot|arik)
44324433
#[cfg(taproot)]
@@ -4515,7 +4516,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
45154516
match self.holder_signer {
45164517
// TODO (taproot|arik): move match into calling method for Taproot
45174518
ChannelSignerType::Ecdsa(ref ecdsa) => {
4518-
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx)
4519+
let channel_parameters = &funding.channel_transaction_parameters;
4520+
ecdsa.sign_counterparty_commitment(channel_parameters, &counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx)
45194521
.map(|(signature, _)| signature)
45204522
.map_err(|_| ChannelError::Close(
45214523
(
@@ -6592,7 +6594,7 @@ impl<SP: Deref> FundedChannel<SP> where
65926594
let funding_signed = if self.context.signer_pending_funding && !self.funding.is_outbound() {
65936595
let counterparty_keys = self.context.build_remote_transaction_keys(&self.funding);
65946596
let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(&self.funding, self.context.cur_counterparty_commitment_transaction_number + 1, &counterparty_keys, false, false, logger).tx;
6595-
self.context.get_funding_signed_msg(logger, counterparty_initial_commitment_tx)
6597+
self.context.get_funding_signed_msg(&self.funding.channel_transaction_parameters, logger, counterparty_initial_commitment_tx)
65966598
} else { None };
65976599
// Provide a `channel_ready` message if we need to, but only if we're _not_ still pending
65986600
// funding.
@@ -8572,6 +8574,7 @@ impl<SP: Deref> FundedChannel<SP> where
85728574
}
85738575

85748576
let res = ecdsa.sign_counterparty_commitment(
8577+
&self.funding.channel_transaction_parameters,
85758578
&commitment_stats.tx,
85768579
commitment_stats.inbound_htlc_preimages,
85778580
commitment_stats.outbound_htlc_preimages,
@@ -9045,7 +9048,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
90459048
let signature = match &self.context.holder_signer {
90469049
// TODO (taproot|arik): move match into calling method for Taproot
90479050
ChannelSignerType::Ecdsa(ecdsa) => {
9048-
ecdsa.sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.context.secp_ctx)
9051+
let channel_parameters = &self.funding.channel_transaction_parameters;
9052+
ecdsa.sign_counterparty_commitment(channel_parameters, &counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.context.secp_ctx)
90499053
.map(|(sig, _)| sig).ok()
90509054
},
90519055
// TODO (taproot|arik)
@@ -9496,7 +9500,9 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
94969500
Err(err) => return Err((self, err)),
94979501
};
94989502

9499-
let funding_signed = self.context.get_funding_signed_msg(logger, counterparty_initial_commitment_tx);
9503+
let funding_signed = self.context.get_funding_signed_msg(
9504+
&self.funding.channel_transaction_parameters, logger, counterparty_initial_commitment_tx
9505+
);
95009506

95019507
log_info!(logger, "{} funding_signed for peer for channel {}",
95029508
if funding_signed.is_some() { "Generated" } else { "Waiting for signature on" }, &self.context.channel_id());

lightning/src/ln/functional_tests.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,10 @@ fn test_update_fee_that_funder_cannot_afford() {
771771
&mut htlcs,
772772
&local_chan.funding.channel_transaction_parameters.as_counterparty_broadcastable()
773773
);
774-
local_chan_signer.as_ecdsa().unwrap().sign_counterparty_commitment(&commitment_tx, Vec::new(), Vec::new(), &secp_ctx).unwrap()
774+
local_chan_signer.as_ecdsa().unwrap().sign_counterparty_commitment(
775+
&local_chan.funding.channel_transaction_parameters, &commitment_tx, Vec::new(),
776+
Vec::new(), &secp_ctx,
777+
).unwrap()
775778
};
776779

777780
let commit_signed_msg = msgs::CommitmentSigned {
@@ -1514,7 +1517,10 @@ fn test_fee_spike_violation_fails_htlc() {
15141517
&mut vec![(accepted_htlc_info, ())],
15151518
&local_chan.funding.channel_transaction_parameters.as_counterparty_broadcastable()
15161519
);
1517-
local_chan_signer.as_ecdsa().unwrap().sign_counterparty_commitment(&commitment_tx, Vec::new(), Vec::new(), &secp_ctx).unwrap()
1520+
local_chan_signer.as_ecdsa().unwrap().sign_counterparty_commitment(
1521+
&local_chan.funding.channel_transaction_parameters, &commitment_tx, Vec::new(),
1522+
Vec::new(), &secp_ctx,
1523+
).unwrap()
15181524
};
15191525

15201526
let commit_signed_msg = msgs::CommitmentSigned {

lightning/src/sign/ecdsa.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::types::payment::PaymentPreimage;
1515
#[allow(unused_imports)]
1616
use crate::prelude::*;
1717

18-
use crate::sign::{ChannelSigner, HTLCDescriptor};
18+
use crate::sign::{ChannelSigner, ChannelTransactionParameters, HTLCDescriptor};
1919

2020
/// A trait to sign Lightning channel transactions as described in
2121
/// [BOLT 3](https://github.com/lightning/bolts/blob/master/03-transactions.md).
@@ -53,7 +53,8 @@ pub trait EcdsaChannelSigner: ChannelSigner {
5353
///
5454
/// [`ChannelManager::signer_unblocked`]: crate::ln::channelmanager::ChannelManager::signer_unblocked
5555
fn sign_counterparty_commitment(
56-
&self, commitment_tx: &CommitmentTransaction, inbound_htlc_preimages: Vec<PaymentPreimage>,
56+
&self, channel_parameters: &ChannelTransactionParameters,
57+
commitment_tx: &CommitmentTransaction, inbound_htlc_preimages: Vec<PaymentPreimage>,
5758
outbound_htlc_preimages: Vec<PaymentPreimage>, secp_ctx: &Secp256k1<secp256k1::All>,
5859
) -> Result<(Signature, Vec<Signature>), ()>;
5960
/// Creates a signature for a holder's commitment transaction.

lightning/src/sign/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,32 +1390,31 @@ const MISSING_PARAMS_ERR: &'static str =
13901390

13911391
impl EcdsaChannelSigner for InMemorySigner {
13921392
fn sign_counterparty_commitment(
1393-
&self, commitment_tx: &CommitmentTransaction,
1394-
_inbound_htlc_preimages: Vec<PaymentPreimage>,
1393+
&self, channel_parameters: &ChannelTransactionParameters,
1394+
commitment_tx: &CommitmentTransaction, _inbound_htlc_preimages: Vec<PaymentPreimage>,
13951395
_outbound_htlc_preimages: Vec<PaymentPreimage>, secp_ctx: &Secp256k1<secp256k1::All>,
13961396
) -> Result<(Signature, Vec<Signature>), ()> {
13971397
let trusted_tx = commitment_tx.trust();
13981398
let keys = trusted_tx.keys();
13991399

14001400
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
1401-
let counterparty_keys = self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
1401+
let counterparty_keys =
1402+
channel_parameters.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
14021403
let channel_funding_redeemscript =
14031404
make_funding_redeemscript(&funding_pubkey, &counterparty_keys.funding_pubkey);
14041405

14051406
let built_tx = trusted_tx.built_transaction();
14061407
let commitment_sig = built_tx.sign_counterparty_commitment(
14071408
&self.funding_key,
14081409
&channel_funding_redeemscript,
1409-
self.channel_value_satoshis,
1410+
channel_parameters.channel_value_satoshis,
14101411
secp_ctx,
14111412
);
14121413
let commitment_txid = built_tx.txid;
14131414

14141415
let mut htlc_sigs = Vec::with_capacity(commitment_tx.htlcs().len());
14151416
for htlc in commitment_tx.htlcs() {
1416-
let channel_parameters = self.get_channel_parameters().expect(MISSING_PARAMS_ERR);
1417-
let holder_selected_contest_delay =
1418-
self.holder_selected_contest_delay().expect(MISSING_PARAMS_ERR);
1417+
let holder_selected_contest_delay = channel_parameters.holder_selected_contest_delay;
14191418
let chan_type = &channel_parameters.channel_type_features;
14201419
let htlc_tx = chan_utils::build_htlc_transaction(
14211420
&commitment_txid,

lightning/src/util/test_channel_signer.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,11 @@ impl ChannelSigner for TestChannelSigner {
229229

230230
impl EcdsaChannelSigner for TestChannelSigner {
231231
fn sign_counterparty_commitment(
232-
&self, commitment_tx: &CommitmentTransaction, inbound_htlc_preimages: Vec<PaymentPreimage>,
232+
&self, channel_parameters: &ChannelTransactionParameters,
233+
commitment_tx: &CommitmentTransaction, inbound_htlc_preimages: Vec<PaymentPreimage>,
233234
outbound_htlc_preimages: Vec<PaymentPreimage>, secp_ctx: &Secp256k1<secp256k1::All>,
234235
) -> Result<(Signature, Vec<Signature>), ()> {
235-
self.verify_counterparty_commitment_tx(commitment_tx, secp_ctx);
236+
self.verify_counterparty_commitment_tx(channel_parameters, commitment_tx, secp_ctx);
236237

237238
{
238239
#[cfg(test)]
@@ -266,6 +267,7 @@ impl EcdsaChannelSigner for TestChannelSigner {
266267
Ok(self
267268
.inner
268269
.sign_counterparty_commitment(
270+
channel_parameters,
269271
commitment_tx,
270272
inbound_htlc_preimages,
271273
outbound_htlc_preimages,
@@ -530,13 +532,14 @@ impl TaprootChannelSigner for TestChannelSigner {
530532

531533
impl TestChannelSigner {
532534
fn verify_counterparty_commitment_tx<'a, T: secp256k1::Signing + secp256k1::Verification>(
533-
&self, commitment_tx: &'a CommitmentTransaction, secp_ctx: &Secp256k1<T>,
535+
&self, channel_parameters: &ChannelTransactionParameters,
536+
commitment_tx: &'a CommitmentTransaction, secp_ctx: &Secp256k1<T>,
534537
) -> TrustedCommitmentTransaction<'a> {
535538
commitment_tx
536539
.verify(
537-
&self.inner.get_channel_parameters().unwrap().as_counterparty_broadcastable(),
538-
self.inner.counterparty_pubkeys().unwrap(),
539-
self.inner.pubkeys(),
540+
&channel_parameters.as_counterparty_broadcastable(),
541+
channel_parameters.counterparty_pubkeys().unwrap(),
542+
&channel_parameters.holder_pubkeys,
540543
secp_ctx,
541544
)
542545
.expect("derived different per-tx keys or built transaction")

0 commit comments

Comments
 (0)