Commit c49ce57
committed
Add a new
`MonitorEvent`s aren't delivered to the `ChannelManager` in a
durable fasion - if the `ChannelManager` fetches the pending
`MonitorEvent`s, then the `ChannelMonitor` gets persisted (i.e. due
to a block update) then the node crashes, prior to persisting the
`ChannelManager` again, the `MonitorEvent` and its effects on the
`ChannelManger` will be lost. This isn't likely in a sync persist
environment, but in an async one this could be an issue.
Note that this is only an issue for closed channels -
`MonitorEvent`s only inform the `ChannelManager` that a channel is
closed (which the `ChannelManager` will learn on startup or when it
next tries to advance the channel state), that
`ChannelMonitorUpdate` writes completed (which the `ChannelManager`
will detect on startup), or that HTLCs resolved on-chain post
closure. Of the three, only the last is problematic to lose prior
to a reload.
In previous commits we ensured that HTLC resolutions which came to
`ChannelManager` via a `MonitorEvent` were replayed on startup if
the `MonitorEvent` was lost. However, in cases where the
`ChannelManager` was so stale that it didn't have the payment state
for an HTLC at all, we only re-add it in cases where
`ChannelMonitor::get_pending_or_resolved_outbound_htlcs` includes
it.
Because constantly re-adding a payment state and then failing it
would generate lots of noise for users on startup (not to mention
risk of confusing stale payment events for the latest state of a
payment when the `PaymentId` has been reused to retry a payment).
Thus, `get_pending_or_resolved_outbound_htlcs` does not include
state for HTLCs which were resolved on chain with a preimage or
HTLCs which were resolved on chain with a timeout after
`ANTI_REORG_DELAY` confirmations.
This critera matches the critera for generating a `MonitorEvent`,
and works great under the assumption that `MonitorEvent`s are
reliably delivered. However, if they are not, and our
`ChannelManager` is lost or substantially old (or, in a future
where we do not persist `ChannelManager` at all), we will not end
up seeing payment resolution events for an HTLC.
Instead, we really want to tell our `ChannelMonitor`s when the
resolution of an HTLC is complete. Note that we don't particularly
care about non-payment HTLCs, as there is no re-hydration of state
to do there - `ChannelManager` load ignores forwarded HTLCs coming
back from `get_pending_or_resolved_outbound_htlcs` as there's
nothing to do - we always attempt to replay the success/failure and
figure out if it mattered based on whether there was still an HTLC
to claim/fail.
Here we take the first step towards that notification, adding a new
`ChannelMonitorUpdateStep` for the completion notification, and
tracking HTLCs which make it to the `ChannelMonitor` in such
updates in a new map.ChannelMoniorUpdateStep::ReleasePaymentComplete
1 parent d16e65d commit c49ce57
1 file changed
+40
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
693 | 693 | | |
694 | 694 | | |
695 | 695 | | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
696 | 710 | | |
697 | 711 | | |
698 | 712 | | |
| |||
709 | 723 | | |
710 | 724 | | |
711 | 725 | | |
| 726 | + | |
712 | 727 | | |
713 | 728 | | |
714 | 729 | | |
| |||
747 | 762 | | |
748 | 763 | | |
749 | 764 | | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
750 | 768 | | |
751 | 769 | | |
752 | 770 | | |
| |||
1250 | 1268 | | |
1251 | 1269 | | |
1252 | 1270 | | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
1253 | 1279 | | |
1254 | 1280 | | |
1255 | 1281 | | |
| |||
1654 | 1680 | | |
1655 | 1681 | | |
1656 | 1682 | | |
| 1683 | + | |
1657 | 1684 | | |
1658 | 1685 | | |
1659 | 1686 | | |
| |||
1872 | 1899 | | |
1873 | 1900 | | |
1874 | 1901 | | |
| 1902 | + | |
1875 | 1903 | | |
1876 | 1904 | | |
1877 | 1905 | | |
| |||
4218 | 4246 | | |
4219 | 4247 | | |
4220 | 4248 | | |
| 4249 | + | |
| 4250 | + | |
| 4251 | + | |
| 4252 | + | |
4221 | 4253 | | |
4222 | 4254 | | |
4223 | 4255 | | |
| |||
4243 | 4275 | | |
4244 | 4276 | | |
4245 | 4277 | | |
4246 | | - | |
4247 | | - | |
4248 | | - | |
| 4278 | + | |
| 4279 | + | |
| 4280 | + | |
| 4281 | + | |
4249 | 4282 | | |
4250 | 4283 | | |
| 4284 | + | |
4251 | 4285 | | |
4252 | 4286 | | |
4253 | 4287 | | |
| |||
6324 | 6358 | | |
6325 | 6359 | | |
6326 | 6360 | | |
| 6361 | + | |
6327 | 6362 | | |
6328 | 6363 | | |
6329 | 6364 | | |
| |||
6357 | 6392 | | |
6358 | 6393 | | |
6359 | 6394 | | |
| 6395 | + | |
6360 | 6396 | | |
6361 | 6397 | | |
6362 | 6398 | | |
| |||
6516 | 6552 | | |
6517 | 6553 | | |
6518 | 6554 | | |
| 6555 | + | |
6519 | 6556 | | |
6520 | 6557 | | |
6521 | 6558 | | |
| |||
0 commit comments