Commit 226520b
committed
Stop re-hydrating pending payments once they are fully resolved
`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, finally, begin actually using the new
`ChannelMonitorUpdateStep::ReleasePaymentComplete` updates,
skipping re-hydration of pending payments once they have been fully
resolved through to a user `Event`.1 parent 71a364c commit 226520b
File tree
4 files changed
+55
-129
lines changed- lightning/src
- chain
- ln
4 files changed
+55
-129
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3031 | 3031 | | |
3032 | 3032 | | |
3033 | 3033 | | |
3034 | | - | |
3035 | | - | |
3036 | | - | |
3037 | | - | |
3038 | 3034 | | |
3039 | 3035 | | |
3040 | 3036 | | |
| |||
3047 | 3043 | | |
3048 | 3044 | | |
3049 | 3045 | | |
3050 | | - | |
3051 | | - | |
| 3046 | + | |
| 3047 | + | |
| 3048 | + | |
| 3049 | + | |
| 3050 | + | |
3052 | 3051 | | |
3053 | 3052 | | |
3054 | 3053 | | |
| |||
3104 | 3103 | | |
3105 | 3104 | | |
3106 | 3105 | | |
| 3106 | + | |
| 3107 | + | |
| 3108 | + | |
| 3109 | + | |
| 3110 | + | |
3107 | 3111 | | |
3108 | 3112 | | |
3109 | 3113 | | |
| |||
3176 | 3180 | | |
3177 | 3181 | | |
3178 | 3182 | | |
3179 | | - | |
3180 | | - | |
3181 | | - | |
3182 | | - | |
3183 | | - | |
3184 | | - | |
3185 | | - | |
3186 | | - | |
3187 | | - | |
3188 | | - | |
3189 | | - | |
3190 | | - | |
3191 | | - | |
3192 | | - | |
3193 | | - | |
3194 | | - | |
3195 | | - | |
3196 | | - | |
3197 | | - | |
3198 | | - | |
3199 | | - | |
3200 | | - | |
3201 | | - | |
3202 | | - | |
3203 | | - | |
3204 | | - | |
3205 | | - | |
3206 | | - | |
3207 | | - | |
3208 | | - | |
3209 | | - | |
3210 | | - | |
3211 | | - | |
3212 | | - | |
3213 | | - | |
3214 | | - | |
3215 | | - | |
3216 | | - | |
3217 | | - | |
3218 | | - | |
3219 | | - | |
3220 | | - | |
3221 | | - | |
3222 | | - | |
3223 | | - | |
3224 | | - | |
3225 | | - | |
3226 | | - | |
3227 | | - | |
3228 | | - | |
3229 | | - | |
3230 | | - | |
3231 | | - | |
3232 | | - | |
3233 | | - | |
3234 | | - | |
3235 | | - | |
3236 | | - | |
3237 | | - | |
3238 | | - | |
3239 | | - | |
3240 | | - | |
3241 | | - | |
3242 | | - | |
3243 | | - | |
3244 | | - | |
3245 | | - | |
3246 | | - | |
3247 | | - | |
3248 | | - | |
3249 | | - | |
3250 | | - | |
3251 | | - | |
3252 | | - | |
3253 | | - | |
3254 | | - | |
3255 | | - | |
3256 | | - | |
3257 | | - | |
3258 | | - | |
3259 | | - | |
3260 | | - | |
3261 | | - | |
3262 | | - | |
3263 | | - | |
3264 | | - | |
3265 | | - | |
3266 | | - | |
3267 | | - | |
3268 | | - | |
3269 | 3183 | | |
3270 | 3184 | | |
3271 | 3185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16600 | 16600 | | |
16601 | 16601 | | |
16602 | 16602 | | |
16603 | | - | |
16604 | | - | |
| 16603 | + | |
16605 | 16604 | | |
16606 | 16605 | | |
16607 | 16606 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2043 | 2043 | | |
2044 | 2044 | | |
2045 | 2045 | | |
| 2046 | + | |
| 2047 | + | |
2046 | 2048 | | |
2047 | 2049 | | |
2048 | 2050 | | |
| |||
2060 | 2062 | | |
2061 | 2063 | | |
2062 | 2064 | | |
2063 | | - | |
| 2065 | + | |
2064 | 2066 | | |
2065 | 2067 | | |
2066 | 2068 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1182 | 1182 | | |
1183 | 1183 | | |
1184 | 1184 | | |
1185 | | - | |
1186 | | - | |
1187 | | - | |
1188 | 1185 | | |
1189 | 1186 | | |
1190 | 1187 | | |
| |||
1217 | 1214 | | |
1218 | 1215 | | |
1219 | 1216 | | |
1220 | | - | |
1221 | | - | |
1222 | | - | |
1223 | 1217 | | |
1224 | 1218 | | |
1225 | 1219 | | |
| |||
1238 | 1232 | | |
1239 | 1233 | | |
1240 | 1234 | | |
1241 | | - | |
| 1235 | + | |
| 1236 | + | |
1242 | 1237 | | |
1243 | 1238 | | |
1244 | 1239 | | |
| |||
1338 | 1333 | | |
1339 | 1334 | | |
1340 | 1335 | | |
1341 | | - | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
1342 | 1340 | | |
1343 | 1341 | | |
1344 | 1342 | | |
1345 | 1343 | | |
1346 | 1344 | | |
1347 | 1345 | | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
1348 | 1351 | | |
1349 | 1352 | | |
1350 | 1353 | | |
1351 | 1354 | | |
1352 | 1355 | | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
1353 | 1360 | | |
1354 | 1361 | | |
1355 | 1362 | | |
1356 | 1363 | | |
1357 | 1364 | | |
1358 | 1365 | | |
1359 | | - | |
| 1366 | + | |
1360 | 1367 | | |
1361 | | - | |
| 1368 | + | |
1362 | 1369 | | |
1363 | | - | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
1364 | 1374 | | |
| 1375 | + | |
1365 | 1376 | | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
1366 | 1382 | | |
1367 | | - | |
1368 | | - | |
1369 | | - | |
1370 | | - | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
1371 | 1388 | | |
1372 | 1389 | | |
1373 | 1390 | | |
| |||
1381 | 1398 | | |
1382 | 1399 | | |
1383 | 1400 | | |
1384 | | - | |
1385 | | - | |
1386 | | - | |
1387 | | - | |
1388 | | - | |
1389 | | - | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
1390 | 1410 | | |
1391 | 1411 | | |
1392 | 1412 | | |
| |||
4140 | 4160 | | |
4141 | 4161 | | |
4142 | 4162 | | |
4143 | | - | |
4144 | | - | |
4145 | | - | |
4146 | | - | |
4147 | 4163 | | |
4148 | | - | |
4149 | 4164 | | |
4150 | 4165 | | |
4151 | | - | |
4152 | 4166 | | |
4153 | 4167 | | |
4154 | 4168 | | |
| |||
4167 | 4181 | | |
4168 | 4182 | | |
4169 | 4183 | | |
4170 | | - | |
4171 | | - | |
4172 | | - | |
4173 | 4184 | | |
4174 | 4185 | | |
4175 | 4186 | | |
| |||
0 commit comments