Commit 181a6e0
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.
The flush() method takes an optional count parameter to flush only a
specific number of queued writes. The background processor captures
the queue size before persisting the channel manager, then flushes
exactly that many writes afterward. This prevents flushing monitor
updates that arrived after the manager state was captured.
Key changes:
- Add PendingWrite enum to represent queued write/remove operations
- Add pending_writes queue to MonitorUpdatingPersisterAsyncInner
- Add pending_write_count() and flush(count) 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 181a6e0
File tree
3 files changed
+242
-213
lines changed- lightning-background-processor/src
- lightning/src
- chain
- util
3 files changed
+242
-213
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1152 | 1152 | | |
1153 | 1153 | | |
1154 | 1154 | | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
1155 | 1160 | | |
1156 | 1161 | | |
1157 | 1162 | | |
| |||
1349 | 1354 | | |
1350 | 1355 | | |
1351 | 1356 | | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
1352 | 1365 | | |
1353 | 1366 | | |
1354 | 1367 | | |
| |||
1413 | 1426 | | |
1414 | 1427 | | |
1415 | 1428 | | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
1416 | 1435 | | |
1417 | 1436 | | |
1418 | 1437 | | |
| |||
1722 | 1741 | | |
1723 | 1742 | | |
1724 | 1743 | | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
1725 | 1747 | | |
1726 | 1748 | | |
1727 | 1749 | | |
| |||
1733 | 1755 | | |
1734 | 1756 | | |
1735 | 1757 | | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
1736 | 1765 | | |
1737 | 1766 | | |
1738 | 1767 | | |
| |||
1853 | 1882 | | |
1854 | 1883 | | |
1855 | 1884 | | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
1856 | 1891 | | |
1857 | 1892 | | |
1858 | 1893 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
198 | 199 | | |
199 | 200 | | |
200 | 201 | | |
201 | | - | |
202 | | - | |
| 202 | + | |
203 | 203 | | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
210 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
211 | 218 | | |
212 | 219 | | |
213 | 220 | | |
| |||
272 | 279 | | |
273 | 280 | | |
274 | 281 | | |
275 | | - | |
276 | 282 | | |
277 | 283 | | |
278 | 284 | | |
| |||
320 | 326 | | |
321 | 327 | | |
322 | 328 | | |
323 | | - | |
324 | | - | |
| 329 | + | |
325 | 330 | | |
326 | 331 | | |
327 | 332 | | |
328 | 333 | | |
329 | 334 | | |
330 | 335 | | |
331 | 336 | | |
332 | | - | |
333 | | - | |
| 337 | + | |
334 | 338 | | |
335 | 339 | | |
336 | 340 | | |
337 | 341 | | |
338 | 342 | | |
339 | 343 | | |
340 | 344 | | |
341 | | - | |
342 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
343 | 351 | | |
344 | 352 | | |
345 | 353 | | |
| |||
440 | 448 | | |
441 | 449 | | |
442 | 450 | | |
443 | | - | |
444 | 451 | | |
445 | 452 | | |
446 | 453 | | |
| |||
450 | 457 | | |
451 | 458 | | |
452 | 459 | | |
453 | | - | |
454 | | - | |
| 460 | + | |
| 461 | + | |
455 | 462 | | |
456 | 463 | | |
457 | 464 | | |
| |||
742 | 749 | | |
743 | 750 | | |
744 | 751 | | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
745 | 771 | | |
746 | 772 | | |
747 | 773 | | |
| |||
1497 | 1523 | | |
1498 | 1524 | | |
1499 | 1525 | | |
1500 | | - | |
1501 | | - | |
1502 | | - | |
1503 | 1526 | | |
1504 | 1527 | | |
1505 | 1528 | | |
| |||
0 commit comments