mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 15:02:20 +01:00
Merge pull request #2265 from wpaulino/channel-force-closed-update-err
Prevent ChannelForceClosed monitor update error after detecting spend
This commit is contained in:
commit
570db8b9e6
2 changed files with 16 additions and 3 deletions
|
@ -2339,8 +2339,16 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
|
|||
F::Target: FeeEstimator,
|
||||
L::Target: Logger,
|
||||
{
|
||||
log_info!(logger, "Applying update to monitor {}, bringing update_id from {} to {} with {} changes.",
|
||||
log_funding_info!(self), self.latest_update_id, updates.update_id, updates.updates.len());
|
||||
if self.latest_update_id == CLOSED_CHANNEL_UPDATE_ID && updates.update_id == CLOSED_CHANNEL_UPDATE_ID {
|
||||
log_info!(logger, "Applying post-force-closed update to monitor {} with {} change(s).",
|
||||
log_funding_info!(self), updates.updates.len());
|
||||
} else if updates.update_id == CLOSED_CHANNEL_UPDATE_ID {
|
||||
log_info!(logger, "Applying force close update to monitor {} with {} change(s).",
|
||||
log_funding_info!(self), updates.updates.len());
|
||||
} else {
|
||||
log_info!(logger, "Applying update to monitor {}, bringing update_id from {} to {} with {} change(s).",
|
||||
log_funding_info!(self), self.latest_update_id, updates.update_id, updates.updates.len());
|
||||
}
|
||||
// ChannelMonitor updates may be applied after force close if we receive a preimage for a
|
||||
// broadcasted commitment transaction HTLC output that we'd like to claim on-chain. If this
|
||||
// is the case, we no longer have guaranteed access to the monitor's update ID, so we use a
|
||||
|
@ -2407,6 +2415,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
|
|||
_ => false,
|
||||
}).is_some();
|
||||
if detected_funding_spend {
|
||||
log_trace!(logger, "Avoiding commitment broadcast, already detected confirmed spend onchain");
|
||||
continue;
|
||||
}
|
||||
self.broadcast_latest_holder_commitment_txn(broadcaster, logger);
|
||||
|
@ -2457,7 +2466,9 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
|
|||
|
||||
self.latest_update_id = updates.update_id;
|
||||
|
||||
if ret.is_ok() && self.funding_spend_seen {
|
||||
// Refuse updates after we've detected a spend onchain, but only if we haven't processed a
|
||||
// force closed monitor update yet.
|
||||
if ret.is_ok() && self.funding_spend_seen && self.latest_update_id != CLOSED_CHANNEL_UPDATE_ID {
|
||||
log_error!(logger, "Refusing Channel Monitor Update as counterparty attempted to update commitment after funding was spent");
|
||||
Err(())
|
||||
} else { ret }
|
||||
|
|
|
@ -7756,6 +7756,8 @@ where
|
|||
|
||||
for (funding_txo, _) in args.channel_monitors.iter() {
|
||||
if !funding_txo_set.contains(funding_txo) {
|
||||
log_info!(args.logger, "Queueing monitor update to ensure missing channel {} is force closed",
|
||||
log_bytes!(funding_txo.to_channel_id()));
|
||||
let monitor_update = ChannelMonitorUpdate {
|
||||
update_id: CLOSED_CHANNEL_UPDATE_ID,
|
||||
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast: true }],
|
||||
|
|
Loading…
Add table
Reference in a new issue