Commit c8405e2
Defer MonitorUpdatingPersister writes to flush()
Update MonitorUpdatingPersister and MonitorUpdatingPersisterAsync to
queue persist operations in memory instead of writing immediately to
disk. The Persist trait methods now return ChannelMonitorUpdateStatus::
InProgress and the actual writes happen when flush() is called.
This fixes a race condition that could cause channel force closures:
previously, if the node crashed after writing channel monitors but
before writing the channel manager, the monitors would be ahead of
the manager on restart. By deferring monitor writes until after the
channel manager is persisted (via flush()), we ensure the manager is
always at least as up-to-date as the monitors.
Key changes:
- Add PendingWrite enum to represent queued write/remove operations
- Add pending_writes queue to MonitorUpdatingPersisterAsyncInner
- Add flush() to Persist trait and ChainMonitor
- ChainMonitor::flush() calls channel_monitor_updated for each completed write
- Update Persist impl to queue writes and return InProgress
- Call flush() in background processor after channel manager persistence
- Remove unused event_notifier from AsyncPersister
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>1 parent b4fb555 commit c8405e2
File tree
3 files changed
+202
-194
lines changed- lightning-background-processor/src
- lightning/src
- chain
- util
3 files changed
+202
-194
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1349 | 1349 | | |
1350 | 1350 | | |
1351 | 1351 | | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
1352 | 1357 | | |
1353 | 1358 | | |
1354 | 1359 | | |
| |||
1413 | 1418 | | |
1414 | 1419 | | |
1415 | 1420 | | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
1416 | 1427 | | |
1417 | 1428 | | |
1418 | 1429 | | |
| |||
1731 | 1742 | | |
1732 | 1743 | | |
1733 | 1744 | | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
1734 | 1750 | | |
1735 | 1751 | | |
1736 | 1752 | | |
| |||
1853 | 1869 | | |
1854 | 1870 | | |
1855 | 1871 | | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
1856 | 1878 | | |
1857 | 1879 | | |
1858 | 1880 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
208 | 209 | | |
209 | 210 | | |
210 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
211 | 221 | | |
212 | 222 | | |
213 | 223 | | |
| |||
272 | 282 | | |
273 | 283 | | |
274 | 284 | | |
275 | | - | |
276 | 285 | | |
277 | 286 | | |
278 | 287 | | |
| |||
320 | 329 | | |
321 | 330 | | |
322 | 331 | | |
323 | | - | |
324 | | - | |
| 332 | + | |
325 | 333 | | |
326 | 334 | | |
327 | 335 | | |
328 | 336 | | |
329 | 337 | | |
330 | 338 | | |
331 | 339 | | |
332 | | - | |
333 | | - | |
| 340 | + | |
334 | 341 | | |
335 | 342 | | |
336 | 343 | | |
| |||
341 | 348 | | |
342 | 349 | | |
343 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
344 | 355 | | |
345 | 356 | | |
346 | 357 | | |
| |||
440 | 451 | | |
441 | 452 | | |
442 | 453 | | |
443 | | - | |
444 | 454 | | |
445 | 455 | | |
446 | 456 | | |
| |||
450 | 460 | | |
451 | 461 | | |
452 | 462 | | |
453 | | - | |
454 | | - | |
| 463 | + | |
| 464 | + | |
455 | 465 | | |
456 | 466 | | |
457 | 467 | | |
| |||
742 | 752 | | |
743 | 753 | | |
744 | 754 | | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
745 | 771 | | |
746 | 772 | | |
747 | 773 | | |
| |||
0 commit comments