Skip to content

Commit 740e014

Browse files
committed
Pass channel params to sign_counterparty_htlc_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 a70df34 commit 740e014

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

lightning/src/chain/package.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ impl PackageSolvingData {
632632
let chan_keys = TxCreationKeys::derive_new(&onchain_handler.secp_ctx, &outp.per_commitment_point, &outp.counterparty_delayed_payment_base_key, &outp.counterparty_htlc_base_key, &onchain_handler.signer.pubkeys().revocation_basepoint, &onchain_handler.signer.pubkeys().htlc_basepoint);
633633
let witness_script = chan_utils::get_htlc_redeemscript_with_explicit_keys(&outp.htlc, &onchain_handler.channel_type_features(), &chan_keys.broadcaster_htlc_key, &chan_keys.countersignatory_htlc_key, &chan_keys.revocation_key);
634634

635-
if let Ok(sig) = onchain_handler.signer.sign_counterparty_htlc_transaction(&bumped_tx, i, &outp.htlc.amount_msat / 1000, &outp.per_commitment_point, &outp.htlc, &onchain_handler.secp_ctx) {
635+
if let Ok(sig) = onchain_handler.signer.sign_counterparty_htlc_transaction(channel_parameters, &bumped_tx, i, &outp.htlc.amount_msat / 1000, &outp.per_commitment_point, &outp.htlc, &onchain_handler.secp_ctx) {
636636
let mut ser_sig = sig.serialize_der().to_vec();
637637
ser_sig.push(EcdsaSighashType::All as u8);
638638
bumped_tx.input[i].witness.push(ser_sig);
@@ -644,7 +644,7 @@ impl PackageSolvingData {
644644
let chan_keys = TxCreationKeys::derive_new(&onchain_handler.secp_ctx, &outp.per_commitment_point, &outp.counterparty_delayed_payment_base_key, &outp.counterparty_htlc_base_key, &onchain_handler.signer.pubkeys().revocation_basepoint, &onchain_handler.signer.pubkeys().htlc_basepoint);
645645
let witness_script = chan_utils::get_htlc_redeemscript_with_explicit_keys(&outp.htlc, &onchain_handler.channel_type_features(), &chan_keys.broadcaster_htlc_key, &chan_keys.countersignatory_htlc_key, &chan_keys.revocation_key);
646646

647-
if let Ok(sig) = onchain_handler.signer.sign_counterparty_htlc_transaction(&bumped_tx, i, &outp.htlc.amount_msat / 1000, &outp.per_commitment_point, &outp.htlc, &onchain_handler.secp_ctx) {
647+
if let Ok(sig) = onchain_handler.signer.sign_counterparty_htlc_transaction(channel_parameters, &bumped_tx, i, &outp.htlc.amount_msat / 1000, &outp.per_commitment_point, &outp.htlc, &onchain_handler.secp_ctx) {
648648
let mut ser_sig = sig.serialize_der().to_vec();
649649
ser_sig.push(EcdsaSighashType::All as u8);
650650
bumped_tx.input[i].witness.push(ser_sig);

lightning/src/sign/ecdsa.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,9 @@ pub trait EcdsaChannelSigner: ChannelSigner {
194194
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
195195
/// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
196196
fn sign_counterparty_htlc_transaction(
197-
&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey,
198-
htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>,
197+
&self, channel_parameters: &ChannelTransactionParameters, htlc_tx: &Transaction,
198+
input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment,
199+
secp_ctx: &Secp256k1<secp256k1::All>,
199200
) -> Result<Signature, ()>;
200201
/// Create a signature for a (proposed) closing transaction.
201202
///

lightning/src/sign/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,25 +1627,27 @@ impl EcdsaChannelSigner for InMemorySigner {
16271627
}
16281628

16291629
fn sign_counterparty_htlc_transaction(
1630-
&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey,
1631-
htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>,
1630+
&self, channel_parameters: &ChannelTransactionParameters, htlc_tx: &Transaction,
1631+
input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment,
1632+
secp_ctx: &Secp256k1<secp256k1::All>,
16321633
) -> Result<Signature, ()> {
16331634
let htlc_key =
16341635
chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, &self.htlc_base_key);
16351636
let revocation_pubkey = RevocationKey::from_basepoint(
16361637
&secp_ctx,
1637-
&self.pubkeys().revocation_basepoint,
1638+
&channel_parameters.holder_pubkeys.revocation_basepoint,
16381639
&per_commitment_point,
16391640
);
1640-
let counterparty_keys = self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
1641+
let counterparty_keys =
1642+
channel_parameters.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
16411643
let counterparty_htlcpubkey = HtlcKey::from_basepoint(
16421644
&secp_ctx,
16431645
&counterparty_keys.htlc_basepoint,
16441646
&per_commitment_point,
16451647
);
1646-
let htlc_basepoint = self.pubkeys().htlc_basepoint;
1648+
let htlc_basepoint = channel_parameters.holder_pubkeys.htlc_basepoint;
16471649
let htlcpubkey = HtlcKey::from_basepoint(&secp_ctx, &htlc_basepoint, &per_commitment_point);
1648-
let chan_type = self.channel_type_features().expect(MISSING_PARAMS_ERR);
1650+
let chan_type = &channel_parameters.channel_type_features;
16491651
let witness_script = chan_utils::get_htlc_redeemscript_with_explicit_keys(
16501652
&htlc,
16511653
chan_type,

lightning/src/util/test_channel_signer.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,15 +414,17 @@ impl EcdsaChannelSigner for TestChannelSigner {
414414
}
415415

416416
fn sign_counterparty_htlc_transaction(
417-
&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey,
418-
htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>,
417+
&self, channel_parameters: &ChannelTransactionParameters, htlc_tx: &Transaction,
418+
input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment,
419+
secp_ctx: &Secp256k1<secp256k1::All>,
419420
) -> Result<Signature, ()> {
420421
#[cfg(test)]
421422
if !self.is_signer_available(SignerOp::SignCounterpartyHtlcTransaction) {
422423
return Err(());
423424
}
424425
Ok(EcdsaChannelSigner::sign_counterparty_htlc_transaction(
425426
&self.inner,
427+
channel_parameters,
426428
htlc_tx,
427429
input,
428430
amount,

0 commit comments

Comments
 (0)