Skip to content

Commit c5c1e22

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 fe5afc1 commit c5c1e22

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]
@@ -4293,7 +4297,17 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
42934297
let revokeable_redeemscript = chan_utils::get_revokeable_redeemscript(&revocation_pubkey,
42944298
self.counterparty_commitment_params.on_counterparty_tx_csv, &delayed_key);
42954299

4296-
let channel_parameters = &self.funding.channel_parameters;
4300+
let commitment_txid = &justice_tx.input[input_idx].previous_output.txid;
4301+
// Since there may be multiple counterparty commitment transactions for the same commitment
4302+
// number due to splicing, we have to locate the matching `FundingScope::channel_parameters`
4303+
// to provide the signer. Since this is intended to be called during
4304+
// `Persist::update_persisted_channel`, the monitor should have already had the update
4305+
// applied.
4306+
let channel_parameters = core::iter::once(&self.funding)
4307+
.chain(&self.pending_funding)
4308+
.find(|funding| funding.counterparty_claimable_outpoints.contains_key(commitment_txid))
4309+
.map(|funding| &funding.channel_parameters)
4310+
.ok_or(())?;
42974311
let sig = self.onchain_tx_handler.signer.sign_justice_revoked_output(
42984312
&channel_parameters, &justice_tx, input_idx, value, &per_commitment_key,
42994313
&self.onchain_tx_handler.secp_ctx,

0 commit comments

Comments
 (0)