Skip to content

Commit 1f0e69d

Browse files
committed
Cancel claims signed by a remote ChannelMonitor when reorging
In `ChannelMonitorImpl::cancel_prev_commitment_claims` we need to cancel any claims against a removed commitment transaction. We were checking if `holder_tx_signed` before checking if either the current or previous holder commitment transaction had pending claims against it, but (a) there's no need to do this, there's not a big performance cost to just always trying to remove claims and (b) we can't actually rely on `holder_tx_signed`. `holder_tx_signed` being set doesn't necessarily imply that the `ChannelMonitor` was persisted (i.e. it may simply be lost in a poorly-timed restart) but we also (somewhat theoretically) allow for multiple copies of a `ChannelMonitor` to exist, and a different one could have signed the commitment transaction which was confirmed (and then unconfirmed). Thus, we simply remove the additional check here.
1 parent c9fd3a5 commit 1f0e69d

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3915,35 +3915,32 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39153915
}
39163916
}
39173917
}
3918-
if self.holder_tx_signed {
3919-
// If we've signed, we may have broadcast either commitment (prev or current), and
3920-
// attempted to claim from it immediately without waiting for a confirmation.
3921-
if self.current_holder_commitment_tx.txid != *confirmed_commitment_txid {
3918+
// Cancel any pending claims for any holder commitments in case they had previously
3919+
// confirmed or been signed (in which case we will start attempting to claim without
3920+
// waiting for confirmation).
3921+
if self.current_holder_commitment_tx.txid != *confirmed_commitment_txid {
3922+
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}",
3923+
self.current_holder_commitment_tx.txid);
3924+
let mut outpoint = BitcoinOutPoint { txid: self.current_holder_commitment_tx.txid, vout: 0 };
3925+
for (htlc, _, _) in &self.current_holder_commitment_tx.htlc_outputs {
3926+
if let Some(vout) = htlc.transaction_output_index {
3927+
outpoint.vout = vout;
3928+
self.onchain_tx_handler.abandon_claim(&outpoint);
3929+
}
3930+
}
3931+
}
3932+
if let Some(prev_holder_commitment_tx) = &self.prev_holder_signed_commitment_tx {
3933+
if prev_holder_commitment_tx.txid != *confirmed_commitment_txid {
39223934
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}",
3923-
self.current_holder_commitment_tx.txid);
3924-
let mut outpoint = BitcoinOutPoint { txid: self.current_holder_commitment_tx.txid, vout: 0 };
3925-
for (htlc, _, _) in &self.current_holder_commitment_tx.htlc_outputs {
3935+
prev_holder_commitment_tx.txid);
3936+
let mut outpoint = BitcoinOutPoint { txid: prev_holder_commitment_tx.txid, vout: 0 };
3937+
for (htlc, _, _) in &prev_holder_commitment_tx.htlc_outputs {
39263938
if let Some(vout) = htlc.transaction_output_index {
39273939
outpoint.vout = vout;
39283940
self.onchain_tx_handler.abandon_claim(&outpoint);
39293941
}
39303942
}
39313943
}
3932-
if let Some(prev_holder_commitment_tx) = &self.prev_holder_signed_commitment_tx {
3933-
if prev_holder_commitment_tx.txid != *confirmed_commitment_txid {
3934-
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}",
3935-
prev_holder_commitment_tx.txid);
3936-
let mut outpoint = BitcoinOutPoint { txid: prev_holder_commitment_tx.txid, vout: 0 };
3937-
for (htlc, _, _) in &prev_holder_commitment_tx.htlc_outputs {
3938-
if let Some(vout) = htlc.transaction_output_index {
3939-
outpoint.vout = vout;
3940-
self.onchain_tx_handler.abandon_claim(&outpoint);
3941-
}
3942-
}
3943-
}
3944-
}
3945-
} else {
3946-
// No previous claim.
39473944
}
39483945
}
39493946

0 commit comments

Comments
 (0)