Skip to content

Commit 8219ae2

Browse files
authored
Merge pull request #1327 from TheBlueMatt/2022-02-log-before-panic
2 parents 5208f0c + 040bf22 commit 8219ae2

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,19 @@ pub(crate) enum ChannelMonitorUpdateStep {
473473
},
474474
}
475475

476+
impl ChannelMonitorUpdateStep {
477+
fn variant_name(&self) -> &'static str {
478+
match self {
479+
ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo { .. } => "LatestHolderCommitmentTXInfo",
480+
ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo { .. } => "LatestCounterpartyCommitmentTXInfo",
481+
ChannelMonitorUpdateStep::PaymentPreimage { .. } => "PaymentPreimage",
482+
ChannelMonitorUpdateStep::CommitmentSecret { .. } => "CommitmentSecret",
483+
ChannelMonitorUpdateStep::ChannelForceClosed { .. } => "ChannelForceClosed",
484+
ChannelMonitorUpdateStep::ShutdownScript { .. } => "ShutdownScript",
485+
}
486+
}
487+
}
488+
476489
impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep,
477490
(0, LatestHolderCommitmentTXInfo) => {
478491
(0, commitment_tx, required),
@@ -1871,16 +1884,21 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
18711884
F::Target: FeeEstimator,
18721885
L::Target: Logger,
18731886
{
1887+
log_info!(logger, "Applying update to monitor {}, bringing update_id from {} to {} with {} changes.",
1888+
log_funding_info!(self), self.latest_update_id, updates.update_id, updates.updates.len());
18741889
// ChannelMonitor updates may be applied after force close if we receive a
18751890
// preimage for a broadcasted commitment transaction HTLC output that we'd
18761891
// like to claim on-chain. If this is the case, we no longer have guaranteed
18771892
// access to the monitor's update ID, so we use a sentinel value instead.
18781893
if updates.update_id == CLOSED_CHANNEL_UPDATE_ID {
1894+
assert_eq!(updates.updates.len(), 1);
18791895
match updates.updates[0] {
18801896
ChannelMonitorUpdateStep::PaymentPreimage { .. } => {},
1881-
_ => panic!("Attempted to apply post-force-close ChannelMonitorUpdate that wasn't providing a payment preimage"),
1897+
_ => {
1898+
log_error!(logger, "Attempted to apply post-force-close ChannelMonitorUpdate of type {}", updates.updates[0].variant_name());
1899+
panic!("Attempted to apply post-force-close ChannelMonitorUpdate that wasn't providing a payment preimage");
1900+
},
18821901
}
1883-
assert_eq!(updates.updates.len(), 1);
18841902
} else if self.latest_update_id + 1 != updates.update_id {
18851903
panic!("Attempted to apply ChannelMonitorUpdates out of order, check the update_id before passing an update to update_monitor!");
18861904
}

0 commit comments

Comments
 (0)