Skip to content

Commit 3e9ab72

Browse files
committed
Pass channel params to sign_justice_revoked_output
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 f638ba4 commit 3e9ab72

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3517,8 +3517,11 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
35173517
let revokeable_redeemscript = chan_utils::get_revokeable_redeemscript(&revocation_pubkey,
35183518
self.counterparty_commitment_params.on_counterparty_tx_csv, &delayed_key);
35193519

3520+
let channel_parameters = &self.onchain_tx_handler.channel_transaction_parameters;
35203521
let sig = self.onchain_tx_handler.signer.sign_justice_revoked_output(
3521-
&justice_tx, input_idx, value, &per_commitment_key, &self.onchain_tx_handler.secp_ctx)?;
3522+
&channel_parameters, &justice_tx, input_idx, value, &per_commitment_key,
3523+
&self.onchain_tx_handler.secp_ctx,
3524+
)?;
35223525
justice_tx.input[input_idx].witness.push_ecdsa_signature(&BitcoinSignature::sighash_all(sig));
35233526
justice_tx.input[input_idx].witness.push(&[1u8]);
35243527
justice_tx.input[input_idx].witness.push(revokeable_redeemscript.as_bytes());

lightning/src/chain/package.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,12 +602,13 @@ impl PackageSolvingData {
602602
}
603603
}
604604
fn finalize_input<Signer: EcdsaChannelSigner>(&self, bumped_tx: &mut Transaction, i: usize, onchain_handler: &mut OnchainTxHandler<Signer>) -> bool {
605+
let channel_parameters = &onchain_handler.channel_transaction_parameters;
605606
match self {
606607
PackageSolvingData::RevokedOutput(ref outp) => {
607608
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);
608609
let witness_script = chan_utils::get_revokeable_redeemscript(&chan_keys.revocation_key, outp.on_counterparty_tx_csv, &chan_keys.broadcaster_delayed_payment_key);
609610
//TODO: should we panic on signer failure ?
610-
if let Ok(sig) = onchain_handler.signer.sign_justice_revoked_output(&bumped_tx, i, outp.amount.to_sat(), &outp.per_commitment_key, &onchain_handler.secp_ctx) {
611+
if let Ok(sig) = onchain_handler.signer.sign_justice_revoked_output(channel_parameters, &bumped_tx, i, outp.amount.to_sat(), &outp.per_commitment_key, &onchain_handler.secp_ctx) {
611612
let mut ser_sig = sig.serialize_der().to_vec();
612613
ser_sig.push(EcdsaSighashType::All as u8);
613614
bumped_tx.input[i].witness.push(ser_sig);

lightning/src/sign/ecdsa.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ pub trait EcdsaChannelSigner: ChannelSigner {
112112
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
113113
/// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
114114
fn sign_justice_revoked_output(
115-
&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey,
115+
&self, channel_parameters: &ChannelTransactionParameters, justice_tx: &Transaction,
116+
input: usize, amount: u64, per_commitment_key: &SecretKey,
116117
secp_ctx: &Secp256k1<secp256k1::All>,
117118
) -> Result<Signature, ()>;
118119
/// Create a signature for the given input in a transaction spending a commitment transaction

lightning/src/sign/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,8 @@ impl EcdsaChannelSigner for InMemorySigner {
14921492
}
14931493

14941494
fn sign_justice_revoked_output(
1495-
&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey,
1495+
&self, channel_parameters: &ChannelTransactionParameters, justice_tx: &Transaction,
1496+
input: usize, amount: u64, per_commitment_key: &SecretKey,
14961497
secp_ctx: &Secp256k1<secp256k1::All>,
14971498
) -> Result<Signature, ()> {
14981499
let revocation_key = chan_utils::derive_private_revocation_key(
@@ -1503,13 +1504,13 @@ impl EcdsaChannelSigner for InMemorySigner {
15031504
let per_commitment_point = PublicKey::from_secret_key(secp_ctx, &per_commitment_key);
15041505
let revocation_pubkey = RevocationKey::from_basepoint(
15051506
&secp_ctx,
1506-
&self.pubkeys().revocation_basepoint,
1507+
&channel_parameters.holder_pubkeys.revocation_basepoint,
15071508
&per_commitment_point,
15081509
);
15091510
let witness_script = {
1510-
let counterparty_keys = self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
1511-
let holder_selected_contest_delay =
1512-
self.holder_selected_contest_delay().expect(MISSING_PARAMS_ERR);
1511+
let counterparty_keys =
1512+
channel_parameters.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
1513+
let holder_selected_contest_delay = channel_parameters.holder_selected_contest_delay;
15131514
let counterparty_delayedpubkey = DelayedPaymentKey::from_basepoint(
15141515
&secp_ctx,
15151516
&counterparty_keys.delayed_payment_basepoint,

lightning/src/util/test_channel_signer.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ impl EcdsaChannelSigner for TestChannelSigner {
311311
}
312312

313313
fn sign_justice_revoked_output(
314-
&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey,
314+
&self, channel_parameters: &ChannelTransactionParameters, justice_tx: &Transaction,
315+
input: usize, amount: u64, per_commitment_key: &SecretKey,
315316
secp_ctx: &Secp256k1<secp256k1::All>,
316317
) -> Result<Signature, ()> {
317318
#[cfg(test)]
@@ -320,6 +321,7 @@ impl EcdsaChannelSigner for TestChannelSigner {
320321
}
321322
Ok(EcdsaChannelSigner::sign_justice_revoked_output(
322323
&self.inner,
324+
channel_parameters,
323325
justice_tx,
324326
input,
325327
amount,

0 commit comments

Comments
 (0)