You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ensure monitors are not archived if they have a preimage we need
When a `ChannelMonitor` sees a payment preimage on chain for an
outbound HTLC, it creates a `MonitorEvent` containing the preimage
to pass to the inbound edge. The inclusion of the transaction
containing the payment preimage (plus six confirmations) also
results in the corresponding `Balance` being removed from the live
balance set, allowing the `ChannelMonitor` to be pruned (after a
further 4032 blocks).
While `MonitorEvent`s should always be processed in a timely
manner, if a node is suffering from a bug where they are not, its
possible for 4038 blocks to pass with the preimage-containing
`MonitorEvent` still pending. If that happens, its possible the
`ChannelMonitor` is archived even though the preimage in it is
needed in another channel (or `ChannelMonitor`), causing funds
loss.
Luckily the fix is simple - check for pending events before
allowing a `ChannelMonitor` to be archived.
Fixes#2153
// previously assumed we claimed all funds, but we have new funds to claim.
2023
-
// Should not happen in practice.
2024
-
debug_assert!(false,"Thought we were done claiming funds, but claimable_balances now has entries");
2029
+
(Some(_),false, _)|(Some(_), _,false) => {
2030
+
// previously assumed we claimed all funds, but we have new funds to claim or
2031
+
// preimages are suddenly needed (because of a duplicate-hash HTLC).
2032
+
// This should never happen as once the `Balance`s and preimages are clear, we
2033
+
// should never create new ones.
2034
+
debug_assert!(false,
2035
+
"Thought we were done claiming funds, but claimable_balances now has entries");
2025
2036
log_error!(logger,
2026
2037
"WARNING: LDK thought it was done claiming all the available funds in the ChannelMonitor for channel {}, but later decided it had more to claim. This is potentially an important bug in LDK, please report it at https://github.com/lightningdevkit/rust-lightning/issues/new",
2027
2038
inner.get_funding_txo().0);
2028
2039
inner.balances_empty_height = None;
2029
2040
(false,true)
2030
2041
},
2031
-
(None,true) => {
2032
-
// Claimed all funds but `balances_empty_height` is None. It is set to the
2033
-
// current block height.
2042
+
(None,true,true) => {
2043
+
// Claimed all funds and preimages can be deleted, but `balances_empty_height` is
2044
+
// None. It is set to the current block height.
2034
2045
log_debug!(logger,
2035
2046
"ChannelMonitor funded at {} is now fully resolved. It will become archivable in {} blocks",
0 commit comments