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