Skip to content

Commit f638ba4

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

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

lightning/src/chain/onchaintx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,15 +1188,15 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
11881188
}
11891189

11901190
pub(crate) fn get_maybe_signed_holder_tx(&mut self, funding_redeemscript: &Script) -> MaybeSignedTransaction {
1191-
let tx = self.signer.sign_holder_commitment(&self.holder_commitment, &self.secp_ctx)
1191+
let tx = self.signer.sign_holder_commitment(&self.channel_transaction_parameters, &self.holder_commitment, &self.secp_ctx)
11921192
.map(|sig| self.holder_commitment.add_holder_sig(funding_redeemscript, sig))
11931193
.unwrap_or_else(|_| self.get_unsigned_holder_commitment_tx().clone());
11941194
MaybeSignedTransaction(tx)
11951195
}
11961196

11971197
#[cfg(any(test, feature="unsafe_revoked_tx_signing"))]
11981198
pub(crate) fn get_fully_signed_copy_holder_tx(&mut self, funding_redeemscript: &Script) -> Transaction {
1199-
let sig = self.signer.unsafe_sign_holder_commitment(&self.holder_commitment, &self.secp_ctx).expect("sign holder commitment");
1199+
let sig = self.signer.unsafe_sign_holder_commitment(&self.channel_transaction_parameters, &self.holder_commitment, &self.secp_ctx).expect("sign holder commitment");
12001200
self.holder_commitment.add_holder_sig(funding_redeemscript, sig)
12011201
}
12021202

lightning/src/ln/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11722,7 +11722,7 @@ mod tests {
1172211722
&chan.context.holder_signer.as_ref().pubkeys().funding_pubkey,
1172311723
chan.funding.counterparty_funding_pubkey()
1172411724
);
11725-
let holder_sig = signer.sign_holder_commitment(&holder_commitment_tx, &secp_ctx).unwrap();
11725+
let holder_sig = signer.sign_holder_commitment(&chan.funding.channel_transaction_parameters, &holder_commitment_tx, &secp_ctx).unwrap();
1172611726
assert_eq!(Signature::from_der(&<Vec<u8>>::from_hex($sig_hex).unwrap()[..]).unwrap(), holder_sig, "holder_sig");
1172711727

1172811728
let funding_redeemscript = chan.funding.get_funding_redeemscript();

lightning/src/sign/ecdsa.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ pub trait EcdsaChannelSigner: ChannelSigner {
7575
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
7676
/// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
7777
fn sign_holder_commitment(
78-
&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
78+
&self, channel_parameters: &ChannelTransactionParameters,
79+
commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
7980
) -> Result<Signature, ()>;
8081
/// Same as [`sign_holder_commitment`], but exists only for tests to get access to holder
8182
/// commitment transactions which will be broadcasted later, after the channel has moved on to a
@@ -85,7 +86,8 @@ pub trait EcdsaChannelSigner: ChannelSigner {
8586
/// This method is *not* async as it is intended only for testing purposes.
8687
#[cfg(any(test, feature = "unsafe_revoked_tx_signing"))]
8788
fn unsafe_sign_holder_commitment(
88-
&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
89+
&self, channel_parameters: &ChannelTransactionParameters,
90+
commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
8991
) -> Result<Signature, ()>;
9092
/// Create a signature for the given input in a transaction spending an HTLC transaction output
9193
/// or a commitment transaction `to_local` output when our counterparty broadcasts an old state.

lightning/src/sign/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,35 +1453,39 @@ impl EcdsaChannelSigner for InMemorySigner {
14531453
}
14541454

14551455
fn sign_holder_commitment(
1456-
&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
1456+
&self, channel_parameters: &ChannelTransactionParameters,
1457+
commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
14571458
) -> Result<Signature, ()> {
14581459
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
1459-
let counterparty_keys = self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
1460+
let counterparty_keys =
1461+
channel_parameters.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
14601462
let funding_redeemscript =
14611463
make_funding_redeemscript(&funding_pubkey, &counterparty_keys.funding_pubkey);
14621464
let trusted_tx = commitment_tx.trust();
14631465
Ok(trusted_tx.built_transaction().sign_holder_commitment(
14641466
&self.funding_key,
14651467
&funding_redeemscript,
1466-
self.channel_value_satoshis,
1468+
channel_parameters.channel_value_satoshis,
14671469
&self,
14681470
secp_ctx,
14691471
))
14701472
}
14711473

14721474
#[cfg(any(test, feature = "unsafe_revoked_tx_signing"))]
14731475
fn unsafe_sign_holder_commitment(
1474-
&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
1476+
&self, channel_parameters: &ChannelTransactionParameters,
1477+
commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
14751478
) -> Result<Signature, ()> {
14761479
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
1477-
let counterparty_keys = self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
1480+
let counterparty_keys =
1481+
channel_parameters.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
14781482
let funding_redeemscript =
14791483
make_funding_redeemscript(&funding_pubkey, &counterparty_keys.funding_pubkey);
14801484
let trusted_tx = commitment_tx.trust();
14811485
Ok(trusted_tx.built_transaction().sign_holder_commitment(
14821486
&self.funding_key,
14831487
&funding_redeemscript,
1484-
self.channel_value_satoshis,
1488+
channel_parameters.channel_value_satoshis,
14851489
&self,
14861490
secp_ctx,
14871491
))

lightning/src/util/test_channel_signer.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,15 @@ impl EcdsaChannelSigner for TestChannelSigner {
277277
}
278278

279279
fn sign_holder_commitment(
280-
&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
280+
&self, channel_parameters: &ChannelTransactionParameters,
281+
commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
281282
) -> Result<Signature, ()> {
282283
#[cfg(test)]
283284
if !self.is_signer_available(SignerOp::SignHolderCommitment) {
284285
return Err(());
285286
}
286-
let trusted_tx = self.verify_holder_commitment_tx(commitment_tx, secp_ctx);
287+
let trusted_tx =
288+
self.verify_holder_commitment_tx(channel_parameters, commitment_tx, secp_ctx);
287289
let state = self.state.lock().unwrap();
288290
let commitment_number = trusted_tx.commitment_number();
289291
if state.last_holder_revoked_commitment - 1 != commitment_number
@@ -294,14 +296,18 @@ impl EcdsaChannelSigner for TestChannelSigner {
294296
state.last_holder_revoked_commitment, commitment_number, self.inner.commitment_seed[0])
295297
}
296298
}
297-
Ok(self.inner.sign_holder_commitment(commitment_tx, secp_ctx).unwrap())
299+
Ok(self.inner.sign_holder_commitment(channel_parameters, commitment_tx, secp_ctx).unwrap())
298300
}
299301

300302
#[cfg(any(test, feature = "unsafe_revoked_tx_signing"))]
301303
fn unsafe_sign_holder_commitment(
302-
&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
304+
&self, channel_parameters: &ChannelTransactionParameters,
305+
commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
303306
) -> Result<Signature, ()> {
304-
Ok(self.inner.unsafe_sign_holder_commitment(commitment_tx, secp_ctx).unwrap())
307+
Ok(self
308+
.inner
309+
.unsafe_sign_holder_commitment(channel_parameters, commitment_tx, secp_ctx)
310+
.unwrap())
305311
}
306312

307313
fn sign_justice_revoked_output(
@@ -546,13 +552,14 @@ impl TestChannelSigner {
546552
}
547553

548554
fn verify_holder_commitment_tx<'a, T: secp256k1::Signing + secp256k1::Verification>(
549-
&self, commitment_tx: &'a CommitmentTransaction, secp_ctx: &Secp256k1<T>,
555+
&self, channel_parameters: &ChannelTransactionParameters,
556+
commitment_tx: &'a CommitmentTransaction, secp_ctx: &Secp256k1<T>,
550557
) -> TrustedCommitmentTransaction<'a> {
551558
commitment_tx
552559
.verify(
553-
&self.inner.get_channel_parameters().unwrap().as_holder_broadcastable(),
554-
self.inner.pubkeys(),
555-
self.inner.counterparty_pubkeys().unwrap(),
560+
&channel_parameters.as_holder_broadcastable(),
561+
&channel_parameters.holder_pubkeys,
562+
channel_parameters.counterparty_pubkeys().unwrap(),
556563
secp_ctx,
557564
)
558565
.expect("derived different per-tx keys or built transaction")

0 commit comments

Comments
 (0)