Skip to content

Commit 18e0d6a

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 a3420d0 commit 18e0d6a

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
@@ -1610,25 +1610,27 @@ impl EcdsaChannelSigner for InMemorySigner {
16101610
}
16111611

16121612
fn sign_counterparty_htlc_transaction(
1613-
&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey,
1614-
htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>,
1613+
&self, channel_parameters: &ChannelTransactionParameters, htlc_tx: &Transaction,
1614+
input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment,
1615+
secp_ctx: &Secp256k1<secp256k1::All>,
16151616
) -> Result<Signature, ()> {
16161617
let htlc_key =
16171618
chan_utils::derive_private_key(&secp_ctx, &per_commitment_point, &self.htlc_base_key);
16181619
let revocation_pubkey = RevocationKey::from_basepoint(
16191620
&secp_ctx,
1620-
&self.pubkeys().revocation_basepoint,
1621+
&channel_parameters.holder_pubkeys.revocation_basepoint,
16211622
&per_commitment_point,
16221623
);
1623-
let counterparty_keys = self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
1624+
let counterparty_keys =
1625+
channel_parameters.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
16241626
let counterparty_htlcpubkey = HtlcKey::from_basepoint(
16251627
&secp_ctx,
16261628
&counterparty_keys.htlc_basepoint,
16271629
&per_commitment_point,
16281630
);
1629-
let htlc_basepoint = self.pubkeys().htlc_basepoint;
1631+
let htlc_basepoint = channel_parameters.holder_pubkeys.htlc_basepoint;
16301632
let htlcpubkey = HtlcKey::from_basepoint(&secp_ctx, &htlc_basepoint, &per_commitment_point);
1631-
let chan_type = self.channel_type_features().expect(MISSING_PARAMS_ERR);
1633+
let chan_type = &channel_parameters.channel_type_features;
16321634
let witness_script = chan_utils::get_htlc_redeemscript_with_explicit_keys(
16331635
&htlc,
16341636
chan_type,

lightning/src/util/test_channel_signer.rs

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

414414
fn sign_counterparty_htlc_transaction(
415-
&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey,
416-
htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>,
415+
&self, channel_parameters: &ChannelTransactionParameters, htlc_tx: &Transaction,
416+
input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment,
417+
secp_ctx: &Secp256k1<secp256k1::All>,
417418
) -> Result<Signature, ()> {
418419
#[cfg(test)]
419420
if !self.is_signer_available(SignerOp::SignCounterpartyHtlcTransaction) {
420421
return Err(());
421422
}
422423
Ok(EcdsaChannelSigner::sign_counterparty_htlc_transaction(
423424
&self.inner,
425+
channel_parameters,
424426
htlc_tx,
425427
input,
426428
amount,

0 commit comments

Comments
 (0)