Skip to content

Commit 110e424

Browse files
committed
Use FundingScope spent when signing watchtower justice transactions
Since there may be multiple counterparty commitment transactions for the same commitment number due to splicing, we have to locate the matching `FundingScope::channel_parameters` to provide the signer. Since this is intended to be called during `Persist::update_persisted_channel`, the monitor should have already had the update applied.
1 parent 36d1b99 commit 110e424

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,10 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
21252125
/// to the commitment transaction being revoked, this will return a signed transaction, but
21262126
/// the signature will not be valid.
21272127
///
2128+
/// Note that due to splicing, this can also return an `Err` when the counterparty commitment
2129+
/// this transaction is attempting to claim is no longer valid because the corresponding funding
2130+
/// transaction was spliced.
2131+
///
21282132
/// [`EcdsaChannelSigner::sign_justice_revoked_output`]: crate::sign::ecdsa::EcdsaChannelSigner::sign_justice_revoked_output
21292133
/// [`Persist`]: crate::chain::chainmonitor::Persist
21302134
#[rustfmt::skip]
@@ -4285,7 +4289,17 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
42854289
let revokeable_redeemscript = chan_utils::get_revokeable_redeemscript(&revocation_pubkey,
42864290
self.counterparty_commitment_params.on_counterparty_tx_csv, &delayed_key);
42874291

4288-
let channel_parameters = &self.funding.channel_parameters;
4292+
let commitment_txid = &justice_tx.input[input_idx].previous_output.txid;
4293+
// Since there may be multiple counterparty commitment transactions for the same commitment
4294+
// number due to splicing, we have to locate the matching `FundingScope::channel_parameters`
4295+
// to provide the signer. Since this is intended to be called during
4296+
// `Persist::update_persisted_channel`, the monitor should have already had the update
4297+
// applied.
4298+
let channel_parameters = core::iter::once(&self.funding)
4299+
.chain(&self.pending_funding)
4300+
.find(|funding| funding.counterparty_claimable_outpoints.contains_key(commitment_txid))
4301+
.map(|funding| &funding.channel_parameters)
4302+
.ok_or(())?;
42894303
let sig = self.onchain_tx_handler.signer.sign_justice_revoked_output(
42904304
&channel_parameters, &justice_tx, input_idx, value, &per_commitment_key,
42914305
&self.onchain_tx_handler.secp_ctx,

0 commit comments

Comments
 (0)