Commit 8b637cc
committed
Prepare to provide 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 prepare to generate the new
`ChannelMonitorUpdateStep::ReleasePaymentComplete` updates, adding
a new `PaymentCompleteUpdate` struct to track the new update before
we generate the `ChannelMonitorUpdate` and passing through to the
right places in `ChannelManager`.
The only cases where we want to generate the new update is after a
`PaymentSent` or `PaymentFailed` event when the event was the
result of a `MonitorEvent` or the equivalent read during startup.ReleasePaymentComplete monitor updates1 parent c49ce57 commit 8b637cc
2 files changed
+90
-29
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1244 | 1244 | | |
1245 | 1245 | | |
1246 | 1246 | | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
1247 | 1262 | | |
1248 | 1263 | | |
1249 | 1264 | | |
| |||
3464 | 3479 | | |
3465 | 3480 | | |
3466 | 3481 | | |
3467 | | - | |
| 3482 | + | |
3468 | 3483 | | |
3469 | 3484 | | |
3470 | 3485 | | |
| |||
4137 | 4152 | | |
4138 | 4153 | | |
4139 | 4154 | | |
4140 | | - | |
| 4155 | + | |
| 4156 | + | |
4141 | 4157 | | |
4142 | 4158 | | |
4143 | 4159 | | |
| |||
4271 | 4287 | | |
4272 | 4288 | | |
4273 | 4289 | | |
4274 | | - | |
| 4290 | + | |
4275 | 4291 | | |
4276 | 4292 | | |
4277 | 4293 | | |
| |||
6288 | 6304 | | |
6289 | 6305 | | |
6290 | 6306 | | |
6291 | | - | |
| 6307 | + | |
| 6308 | + | |
6292 | 6309 | | |
6293 | 6310 | | |
6294 | 6311 | | |
| |||
6577 | 6594 | | |
6578 | 6595 | | |
6579 | 6596 | | |
| 6597 | + | |
6580 | 6598 | | |
6581 | 6599 | | |
6582 | 6600 | | |
| |||
7786 | 7804 | | |
7787 | 7805 | | |
7788 | 7806 | | |
7789 | | - | |
| 7807 | + | |
7790 | 7808 | | |
7791 | 7809 | | |
7792 | 7810 | | |
| |||
7852 | 7870 | | |
7853 | 7871 | | |
7854 | 7872 | | |
7855 | | - | |
| 7873 | + | |
7856 | 7874 | | |
7857 | 7875 | | |
7858 | 7876 | | |
| |||
7945 | 7963 | | |
7946 | 7964 | | |
7947 | 7965 | | |
7948 | | - | |
| 7966 | + | |
7949 | 7967 | | |
7950 | 7968 | | |
7951 | 7969 | | |
| |||
7954 | 7972 | | |
7955 | 7973 | | |
7956 | 7974 | | |
| 7975 | + | |
7957 | 7976 | | |
7958 | 7977 | | |
7959 | 7978 | | |
| |||
7985 | 8004 | | |
7986 | 8005 | | |
7987 | 8006 | | |
| 8007 | + | |
7988 | 8008 | | |
| 8009 | + | |
| 8010 | + | |
| 8011 | + | |
| 8012 | + | |
| 8013 | + | |
| 8014 | + | |
| 8015 | + | |
| 8016 | + | |
| 8017 | + | |
7989 | 8018 | | |
7990 | 8019 | | |
7991 | 8020 | | |
| |||
8123 | 8152 | | |
8124 | 8153 | | |
8125 | 8154 | | |
| 8155 | + | |
8126 | 8156 | | |
8127 | 8157 | | |
8128 | 8158 | | |
| |||
8269 | 8299 | | |
8270 | 8300 | | |
8271 | 8301 | | |
8272 | | - | |
| 8302 | + | |
8273 | 8303 | | |
8274 | 8304 | | |
8275 | 8305 | | |
| |||
8619 | 8649 | | |
8620 | 8650 | | |
8621 | 8651 | | |
8622 | | - | |
8623 | | - | |
8624 | | - | |
8625 | | - | |
8626 | | - | |
| 8652 | + | |
| 8653 | + | |
| 8654 | + | |
| 8655 | + | |
| 8656 | + | |
| 8657 | + | |
8627 | 8658 | | |
8628 | 8659 | | |
8629 | 8660 | | |
8630 | 8661 | | |
8631 | 8662 | | |
8632 | 8663 | | |
8633 | 8664 | | |
8634 | | - | |
| 8665 | + | |
8635 | 8666 | | |
8636 | 8667 | | |
8637 | 8668 | | |
| 8669 | + | |
| 8670 | + | |
| 8671 | + | |
| 8672 | + | |
| 8673 | + | |
| 8674 | + | |
| 8675 | + | |
| 8676 | + | |
| 8677 | + | |
| 8678 | + | |
| 8679 | + | |
| 8680 | + | |
8638 | 8681 | | |
8639 | 8682 | | |
8640 | 8683 | | |
| |||
10262 | 10305 | | |
10263 | 10306 | | |
10264 | 10307 | | |
10265 | | - | |
| 10308 | + | |
| 10309 | + | |
10266 | 10310 | | |
10267 | 10311 | | |
10268 | 10312 | | |
| |||
10739 | 10783 | | |
10740 | 10784 | | |
10741 | 10785 | | |
| 10786 | + | |
10742 | 10787 | | |
10743 | 10788 | | |
10744 | 10789 | | |
| |||
11332 | 11377 | | |
11333 | 11378 | | |
11334 | 11379 | | |
| 11380 | + | |
11335 | 11381 | | |
11336 | 11382 | | |
11337 | 11383 | | |
| |||
12810 | 12856 | | |
12811 | 12857 | | |
12812 | 12858 | | |
12813 | | - | |
12814 | | - | |
| 12859 | + | |
| 12860 | + | |
12815 | 12861 | | |
12816 | 12862 | | |
12817 | 12863 | | |
| |||
13660 | 13706 | | |
13661 | 13707 | | |
13662 | 13708 | | |
13663 | | - | |
| 13709 | + | |
13664 | 13710 | | |
13665 | 13711 | | |
13666 | 13712 | | |
| |||
15832 | 15878 | | |
15833 | 15879 | | |
15834 | 15880 | | |
15835 | | - | |
| 15881 | + | |
15836 | 15882 | | |
15837 | 15883 | | |
15838 | 15884 | | |
| |||
15876 | 15922 | | |
15877 | 15923 | | |
15878 | 15924 | | |
| 15925 | + | |
15879 | 15926 | | |
15880 | 15927 | | |
15881 | 15928 | | |
| |||
16575 | 16622 | | |
16576 | 16623 | | |
16577 | 16624 | | |
16578 | | - | |
| 16625 | + | |
16579 | 16626 | | |
16580 | 16627 | | |
16581 | 16628 | | |
16582 | 16629 | | |
16583 | 16630 | | |
16584 | 16631 | | |
16585 | | - | |
| 16632 | + | |
| 16633 | + | |
16586 | 16634 | | |
16587 | 16635 | | |
16588 | 16636 | | |
16589 | 16637 | | |
16590 | 16638 | | |
16591 | 16639 | | |
16592 | 16640 | | |
16593 | | - | |
| 16641 | + | |
16594 | 16642 | | |
16595 | 16643 | | |
16596 | 16644 | | |
| |||
16605 | 16653 | | |
16606 | 16654 | | |
16607 | 16655 | | |
| 16656 | + | |
| 16657 | + | |
| 16658 | + | |
| 16659 | + | |
| 16660 | + | |
| 16661 | + | |
| 16662 | + | |
16608 | 16663 | | |
16609 | 16664 | | |
16610 | 16665 | | |
16611 | 16666 | | |
16612 | 16667 | | |
16613 | 16668 | | |
| 16669 | + | |
16614 | 16670 | | |
16615 | 16671 | | |
16616 | 16672 | | |
| |||
17294 | 17350 | | |
17295 | 17351 | | |
17296 | 17352 | | |
17297 | | - | |
| 17353 | + | |
| 17354 | + | |
17298 | 17355 | | |
17299 | 17356 | | |
17300 | 17357 | | |
17301 | | - | |
| 17358 | + | |
| 17359 | + | |
17302 | 17360 | | |
17303 | 17361 | | |
17304 | 17362 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
2153 | 2155 | | |
2154 | 2156 | | |
2155 | 2157 | | |
2156 | | - | |
| 2158 | + | |
2157 | 2159 | | |
2158 | 2160 | | |
2159 | 2161 | | |
| |||
2174 | 2176 | | |
2175 | 2177 | | |
2176 | 2178 | | |
2177 | | - | |
| 2179 | + | |
2178 | 2180 | | |
2179 | 2181 | | |
2180 | 2182 | | |
| |||
2192 | 2194 | | |
2193 | 2195 | | |
2194 | 2196 | | |
2195 | | - | |
| 2197 | + | |
2196 | 2198 | | |
2197 | 2199 | | |
2198 | 2200 | | |
| |||
2321 | 2323 | | |
2322 | 2324 | | |
2323 | 2325 | | |
2324 | | - | |
| 2326 | + | |
2325 | 2327 | | |
2326 | 2328 | | |
2327 | 2329 | | |
| |||
2472 | 2474 | | |
2473 | 2475 | | |
2474 | 2476 | | |
| 2477 | + | |
2475 | 2478 | | |
2476 | 2479 | | |
2477 | 2480 | | |
| |||
0 commit comments