@@ -123,56 +123,67 @@ pub enum ChannelMonitorUpdateErr {
123
123
///
124
124
/// Such a failure will "freeze" a channel, preventing us from revoking old states or
125
125
/// submitting new commitment transactions to the counterparty. Once the update(s) which failed
126
- /// have been successfully applied, ChannelManager::channel_monitor_updated can be used to
126
+ /// have been successfully applied, [` ChannelManager::channel_monitor_updated`] can be used to
127
127
/// restore the channel to an operational state.
128
128
///
129
- /// Note that a given ChannelManager will *never* re-generate a given ChannelMonitorUpdate. If
130
- /// you return a TemporaryFailure you must ensure that it is written to disk safely before
131
- /// writing out the latest ChannelManager state.
129
+ /// Note that a given [` ChannelManager`] will *never* re-generate a [` ChannelMonitorUpdate`].
130
+ /// If you return this error you must ensure that it is written to disk safely before writing
131
+ /// the latest [` ChannelManager`] state, or you should return [`PermanentFailure`] instead .
132
132
///
133
- /// Even when a channel has been "frozen" updates to the ChannelMonitor can continue to occur
134
- /// (eg if an inbound HTLC which we forwarded was claimed upstream resulting in us attempting
135
- /// to claim it on this channel) and those updates must be applied wherever they can be. At
136
- /// least one such updated ChannelMonitor must be persisted otherwise PermanentFailure should
137
- /// be returned to get things on-chain ASAP using only the in-memory copy. Obviously updates to
138
- /// the channel which would invalidate previous ChannelMonitors are not made when a channel has
139
- /// been "frozen".
133
+ /// Even when a channel has been "frozen" updates to the [`ChannelMonitor`] can continue to
134
+ /// occur (e.g. if an inbound HTLC which we forwarded was claimed upstream resulting in us
135
+ /// attempting to claim it on this channel) and those updates must still be persisted.
140
136
///
141
- /// Note that even if updates made after TemporaryFailure succeed you must still call
142
- /// channel_monitor_updated to ensure you have the latest monitor and re-enable normal channel
143
- /// operation.
144
- ///
145
- /// Note that the update being processed here will not be replayed for you when you call
146
- /// ChannelManager::channel_monitor_updated, so you must store the update itself along
147
- /// with the persisted ChannelMonitor on your own local disk prior to returning a
148
- /// TemporaryFailure. You may, of course, employ a journaling approach, storing only the
149
- /// ChannelMonitorUpdate on disk without updating the monitor itself, replaying the journal at
150
- /// reload-time.
137
+ /// No updates to the channel will be made which could invalidate other [`ChannelMonitor`]s
138
+ /// until [`ChannelManager::channel_monitor_updated`] is called, even if you return no error on
139
+ /// a later monitor update for the same channel.
151
140
///
152
141
/// For deployments where a copy of ChannelMonitors and other local state are backed up in a
153
142
/// remote location (with local copies persisted immediately), it is anticipated that all
154
143
/// updates will return TemporaryFailure until the remote copies could be updated.
144
+ ///
145
+ /// [`PermanentFailure`]: ChannelMonitorUpdateErr::PermanentFailure
146
+ /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
147
+ /// [`ChannelManager::channel_monitor_updated`]: crate::ln::channelmanager::ChannelManager::channel_monitor_updated
155
148
TemporaryFailure ,
156
- /// Used to indicate no further channel monitor updates will be allowed (eg we've moved on to a
157
- /// different watchtower and cannot update with all watchtowers that were previously informed
158
- /// of this channel).
149
+ /// Used to indicate no further channel monitor updates will be allowed (likely a disk failure
150
+ /// or, e.g. we've moved on to a different watchtower and cannot update with all watchtowers
151
+ /// that were previously informed of this channel).
152
+ ///
153
+ /// When this is returned [`ChannelManager`] will force-close the channel but *not* broadcast
154
+ /// our current commitment transaction. This avoids a dangerous case where a local disk failure
155
+ /// (e.g. the Linux-default remounting of the disk as read-only) causes [`PermanentFailure`]s
156
+ /// for all monitor updates. If we were to broadcast our latest commitment transaction and then
157
+ /// restart, we could end up reading a previous [`ChannelMonitor`] and [`ChannelManager`],
158
+ /// revoking our now-broadcasted state before seeing it confirm and losing all our funds.
159
+ ///
160
+ /// Note that this is somewhat of a tradeoff - if the disk is really gone and we may have lost
161
+ /// the data permanently, we really should broadcast immediately. If the data can be recovered
162
+ /// with manual intervention, we'd rather close the channel, rejecting future updates to it,
163
+ /// and broadcast the latest state only if we have HTLCs to claim which are timing out (which
164
+ /// we do as long as blocks are connected).
159
165
///
160
- /// At reception of this error, ChannelManager will force-close the channel and return at
161
- /// least a final ChannelMonitorUpdate::ChannelForceClosed which must be delivered to at
162
- /// least one ChannelMonitor copy. Revocation secret MUST NOT be released and offchain channel
163
- /// update must be rejected.
166
+ /// In order to broadcast the latest local commitment transaction, you'll need to call
167
+ /// [`ChannelMonitor::get_latest_holder_commitment_txn`] once you've safely ensured no further
168
+ /// off-chain updates to the channel can occur.
164
169
///
165
- /// This failure may also signal a failure to update the local persisted copy of one of
166
- /// the channel monitor instance.
170
+ /// Note that at least one final [`ChannelMonitorUpdate`] may still be provided, which must
171
+ /// still be processed by a running [`ChannelMonitor`]. This final update will mark the
172
+ /// [`ChannelMonitor`] as finalized, ensuring no further updates (e.g. revocation of the latest
173
+ /// commitment transaction) are allowed.
167
174
///
168
- /// Note that even when you fail a holder commitment transaction update, you must store the
169
- /// update to ensure you can claim from it in case of a duplicate copy of this ChannelMonitor
170
- /// broadcasts it (e.g distributed channel-monitor deployment)
175
+ /// Note that even if you return a [`PermanentFailure`] due to unavailability of secondary
176
+ /// [`ChannelMonitor`] copies, you should still make an attempt to store the update where
177
+ /// possible to ensure you can claim HTLC outputs on the latest commitment transaction
178
+ /// broadcasted later.
171
179
///
172
180
/// In case of distributed watchtowers deployment, the new version must be written to disk, as
173
181
/// state may have been stored but rejected due to a block forcing a commitment broadcast. This
174
182
/// storage is used to claim outputs of rejected state confirmed onchain by another watchtower,
175
183
/// lagging behind on block processing.
184
+ ///
185
+ /// [`PermanentFailure`]: ChannelMonitorUpdateErr::PermanentFailure
186
+ /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
176
187
PermanentFailure ,
177
188
}
178
189
@@ -1203,14 +1214,18 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
1203
1214
}
1204
1215
1205
1216
/// Used by ChannelManager deserialization to broadcast the latest holder state if its copy of
1206
- /// the Channel was out-of-date. You may use it to get a broadcastable holder toxic tx in case of
1207
- /// fallen-behind, i.e when receiving a channel_reestablish with a proof that our counterparty side knows
1208
- /// a higher revocation secret than the holder commitment number we are aware of. Broadcasting these
1209
- /// transactions are UNSAFE, as they allow counterparty side to punish you. Nevertheless you may want to
1210
- /// broadcast them if counterparty don't close channel with his higher commitment transaction after a
1211
- /// substantial amount of time (a month or even a year) to get back funds. Best may be to contact
1212
- /// out-of-band the other node operator to coordinate with him if option is available to you.
1213
- /// In any-case, choice is up to the user.
1217
+ /// the Channel was out-of-date.
1218
+ ///
1219
+ /// You may also use this to broadcast the latest local commitment transaction, either because
1220
+ /// a monitor update failed with [`ChannelMonitorUpdateErr::PermanentFailure`] or because we've
1221
+ /// fallen behind (i.e we've received proof that our counterparty side knows a revocation
1222
+ /// secret we gave them that they shouldn't know).
1223
+ ///
1224
+ /// Broadcasting these transactions in the second case is UNSAFE, as they allow counterparty
1225
+ /// side to punish you. Nevertheless you may want to broadcast them if counterparty doesn't
1226
+ /// close channel with their commitment transaction after a substantial amount of time. Best
1227
+ /// may be to contact the other node operator out-of-band to coordinate other options available
1228
+ /// to you. In any-case, the choice is up to you.
1214
1229
pub fn get_latest_holder_commitment_txn < L : Deref > ( & self , logger : & L ) -> Vec < Transaction >
1215
1230
where L :: Target : Logger {
1216
1231
self . inner . lock ( ) . unwrap ( ) . get_latest_holder_commitment_txn ( logger)
@@ -1833,7 +1848,9 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1833
1848
if * should_broadcast {
1834
1849
self . broadcast_latest_holder_commitment_txn ( broadcaster, logger) ;
1835
1850
} else if !self . holder_tx_signed {
1836
- log_error ! ( logger, "You have a toxic holder commitment transaction avaible in channel monitor, read comment in ChannelMonitor::get_latest_holder_commitment_txn to be informed of manual action to take" ) ;
1851
+ log_error ! ( logger, "WARNING: You have a potentially-toxic holder commitment transaction avaible to broadcast" ) ;
1852
+ log_error ! ( logger, " in channel monitor for channel {}!" , log_bytes!( self . funding_info. 0 . to_channel_id( ) ) ) ;
1853
+ log_error ! ( logger, " Read the docs for ChannelMonitor::get_latest_holder_commitment_txn and take manual action!" ) ;
1837
1854
} else {
1838
1855
// If we generated a MonitorEvent::CommitmentTxConfirmed, the ChannelManager
1839
1856
// will still give us a ChannelForceClosed event with !should_broadcast, but we
0 commit comments