@@ -194,61 +194,67 @@ pub enum ChannelMonitorUpdateErr {
194
194
/// our state failed, but is expected to succeed at some point in the future).
195
195
///
196
196
/// Such a failure will "freeze" a channel, preventing us from revoking old states or
197
- /// submitting new commitment transactions to the counterparty. Once the update(s) that failed
198
- /// have been successfully applied, a [`MonitorEvent::UpdateCompleted`] event should be returned
199
- /// via [`Watch::release_pending_monitor_events`] which will then restore the channel to an
200
- /// operational state.
197
+ /// submitting new commitment transactions to the counterparty. Once the update(s) which failed
198
+ /// have been successfully applied, a [`MonitorEvent::UpdateCompleted`] can be used to restore
199
+ /// the channel to an operational state.
201
200
///
202
- /// Note that a given ChannelManager will *never* re-generate a given ChannelMonitorUpdate. If
203
- /// you return a TemporaryFailure you must ensure that it is written to disk safely before
204
- /// writing out the latest ChannelManager state.
201
+ /// Note that a given [` ChannelManager`] will *never* re-generate a [` ChannelMonitorUpdate`].
202
+ /// If you return this error you must ensure that it is written to disk safely before writing
203
+ /// the latest [` ChannelManager`] state, or you should return [`PermanentFailure`] instead .
205
204
///
206
- /// Even when a channel has been "frozen" updates to the ChannelMonitor can continue to occur
207
- /// (eg if an inbound HTLC which we forwarded was claimed upstream resulting in us attempting
208
- /// to claim it on this channel) and those updates must be applied wherever they can be. At
209
- /// least one such updated ChannelMonitor must be persisted otherwise PermanentFailure should
210
- /// be returned to get things on-chain ASAP using only the in-memory copy. Obviously updates to
211
- /// the channel which would invalidate previous ChannelMonitors are not made when a channel has
212
- /// been "frozen".
205
+ /// Even when a channel has been "frozen", updates to the [`ChannelMonitor`] can continue to
206
+ /// occur (e.g. if an inbound HTLC which we forwarded was claimed upstream, resulting in us
207
+ /// attempting to claim it on this channel) and those updates must still be persisted.
213
208
///
214
- /// Note that even if updates made after TemporaryFailure succeed you must still provide a
215
- /// [`MonitorEvent::UpdateCompleted`] to ensure you have the latest monitor and re-enable
216
- /// normal channel operation. Note that this is normally generated through a call to
217
- /// [`ChainMonitor::channel_monitor_updated`].
218
- ///
219
- /// Note that the update being processed here will not be replayed for you when you return a
220
- /// [`MonitorEvent::UpdateCompleted`] event via [`Watch::release_pending_monitor_events`], so
221
- /// you must store the update itself on your own local disk prior to returning a
222
- /// TemporaryFailure. You may, of course, employ a journaling approach, storing only the
223
- /// ChannelMonitorUpdate on disk without updating the monitor itself, replaying the journal at
224
- /// reload-time.
209
+ /// No updates to the channel will be made which could invalidate other [`ChannelMonitor`]s
210
+ /// until a [`MonitorEvent::UpdateCompleted`] is provided, even if you return no error on a
211
+ /// later monitor update for the same channel.
225
212
///
226
213
/// For deployments where a copy of ChannelMonitors and other local state are backed up in a
227
214
/// remote location (with local copies persisted immediately), it is anticipated that all
228
215
/// updates will return TemporaryFailure until the remote copies could be updated.
229
216
///
230
- /// [`ChainMonitor::channel_monitor_updated`]: chainmonitor::ChainMonitor::channel_monitor_updated
217
+ /// [`PermanentFailure`]: ChannelMonitorUpdateErr::PermanentFailure
218
+ /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
231
219
TemporaryFailure ,
232
- /// Used to indicate no further channel monitor updates will be allowed (eg we've moved on to a
233
- /// different watchtower and cannot update with all watchtowers that were previously informed
234
- /// of this channel).
220
+ /// Used to indicate no further channel monitor updates will be allowed (likely a disk failure
221
+ /// or a remote copy of this [`ChannelMonitor`] is no longer reachable and thus not updatable).
222
+ ///
223
+ /// When this is returned, [`ChannelManager`] will force-close the channel but *not* broadcast
224
+ /// our current commitment transaction. This avoids a dangerous case where a local disk failure
225
+ /// (e.g. the Linux-default remounting of the disk as read-only) causes [`PermanentFailure`]s
226
+ /// for all monitor updates. If we were to broadcast our latest commitment transaction and then
227
+ /// restart, we could end up reading a previous [`ChannelMonitor`] and [`ChannelManager`],
228
+ /// revoking our now-broadcasted state before seeing it confirm and losing all our funds.
235
229
///
236
- /// At reception of this error, ChannelManager will force-close the channel and return at
237
- /// least a final ChannelMonitorUpdate::ChannelForceClosed which must be delivered to at
238
- /// least one ChannelMonitor copy. Revocation secret MUST NOT be released and offchain channel
239
- /// update must be rejected.
230
+ /// Note that this is somewhat of a tradeoff - if the disk is really gone and we may have lost
231
+ /// the data permanently, we really should broadcast immediately. If the data can be recovered
232
+ /// with manual intervention, we'd rather close the channel, rejecting future updates to it,
233
+ /// and broadcast the latest state only if we have HTLCs to claim which are timing out (which
234
+ /// we do as long as blocks are connected).
240
235
///
241
- /// This failure may also signal a failure to update the local persisted copy of one of
242
- /// the channel monitor instance.
236
+ /// In order to broadcast the latest local commitment transaction, you'll need to call
237
+ /// [`ChannelMonitor::get_latest_holder_commitment_txn`] and broadcast the resulting
238
+ /// transactions once you've safely ensured no further channel updates can be generated by your
239
+ /// [`ChannelManager`].
243
240
///
244
- /// Note that even when you fail a holder commitment transaction update, you must store the
245
- /// update to ensure you can claim from it in case of a duplicate copy of this ChannelMonitor
246
- /// broadcasts it (e.g distributed channel-monitor deployment)
241
+ /// Note that at least one final [`ChannelMonitorUpdate`] may still be provided, which must
242
+ /// still be processed by a running [`ChannelMonitor`]. This final update will mark the
243
+ /// [`ChannelMonitor`] as finalized, ensuring no further updates (e.g. revocation of the latest
244
+ /// commitment transaction) are allowed.
245
+ ///
246
+ /// Note that even if you return a [`PermanentFailure`] due to unavailability of secondary
247
+ /// [`ChannelMonitor`] copies, you should still make an attempt to store the update where
248
+ /// possible to ensure you can claim HTLC outputs on the latest commitment transaction
249
+ /// broadcasted later.
247
250
///
248
251
/// In case of distributed watchtowers deployment, the new version must be written to disk, as
249
252
/// state may have been stored but rejected due to a block forcing a commitment broadcast. This
250
253
/// storage is used to claim outputs of rejected state confirmed onchain by another watchtower,
251
254
/// lagging behind on block processing.
255
+ ///
256
+ /// [`PermanentFailure`]: ChannelMonitorUpdateErr::PermanentFailure
257
+ /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
252
258
PermanentFailure ,
253
259
}
254
260
@@ -278,7 +284,7 @@ pub trait Watch<ChannelSigner: Sign> {
278
284
/// with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means
279
285
/// calling [`block_connected`] and [`block_disconnected`] on the monitor.
280
286
///
281
- /// Note: this interface MUST error with `ChannelMonitorUpdateErr::PermanentFailure` if
287
+ /// Note: this interface MUST error with [ `ChannelMonitorUpdateErr::PermanentFailure`] if
282
288
/// the given `funding_txo` has previously been registered via `watch_channel`.
283
289
///
284
290
/// [`get_outputs_to_watch`]: channelmonitor::ChannelMonitor::get_outputs_to_watch
0 commit comments