Commit 66992c2
Pass a
On restart, LDK expects the chain to be replayed starting from
where it was when objects were last serialized. This is fine in the
normal case, but if there was a reorg and the node which we were
syncing from either resynced or was changed, the last block that we
were synced as of might no longer be available. As a result, it
becomes impossible to figure out where the fork point is, and thus
to replay the chain.
Luckily, changing the block source during a reorg isn't exactly
common, but we shouldn't end up with a bricked node.
To address this, `lightning-block-sync` allows the user to pass in
`Cache` which can be used to cache recent blocks and thus allow for
reorg handling in this case. However, serialization for, and a
reasonable default implementation of a `Cache` was never built.
Instead, here, we start taking a different approach. To avoid
developers having to persist yet another object, we move
`BestBlock` to storing some number of recent block hashes. This
allows us to find the fork point with just the serialized state.
In a previous commit, we moved deserialization of various structs
to return the `BestBlock` rather than a `BlockHash`. Here we move
to actually using it, taking a `BestBlock` in place of `BlockHash`
to `init::synchronize_listeners` and walking the `previous_blocks`
list to find the fork point rather than relying on the `Cache`.BestBlock to init::synchronize_listeners
1 parent b617fbf commit 66992c2
File tree
4 files changed
+93
-33
lines changed- lightning-block-sync/src
4 files changed
+93
-33
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
121 | | - | |
| 120 | + | |
| 121 | + | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | 153 | | |
166 | 154 | | |
167 | 155 | | |
168 | 156 | | |
169 | 157 | | |
170 | | - | |
| 158 | + | |
171 | 159 | | |
172 | 160 | | |
173 | 161 | | |
174 | 162 | | |
175 | 163 | | |
176 | | - | |
177 | | - | |
178 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
179 | 168 | | |
180 | 169 | | |
181 | 170 | | |
| |||
281 | 270 | | |
282 | 271 | | |
283 | 272 | | |
284 | | - | |
285 | | - | |
286 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
287 | 276 | | |
288 | 277 | | |
289 | 278 | | |
| |||
313 | 302 | | |
314 | 303 | | |
315 | 304 | | |
316 | | - | |
317 | | - | |
318 | | - | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
319 | 308 | | |
320 | 309 | | |
321 | 310 | | |
| |||
350 | 339 | | |
351 | 340 | | |
352 | 341 | | |
353 | | - | |
354 | | - | |
355 | | - | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
356 | 345 | | |
357 | 346 | | |
358 | 347 | | |
| |||
368 | 357 | | |
369 | 358 | | |
370 | 359 | | |
371 | | - | |
| 360 | + | |
372 | 361 | | |
373 | 362 | | |
374 | 363 | | |
375 | 364 | | |
376 | 365 | | |
377 | | - | |
| 366 | + | |
378 | 367 | | |
379 | 368 | | |
380 | 369 | | |
381 | 370 | | |
382 | | - | |
| 371 | + | |
383 | 372 | | |
384 | 373 | | |
385 | 374 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
340 | | - | |
| 340 | + | |
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
| |||
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
350 | 391 | | |
351 | 392 | | |
352 | 393 | | |
353 | 394 | | |
354 | | - | |
| 395 | + | |
355 | 396 | | |
356 | 397 | | |
357 | 398 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
| |||
258 | 263 | | |
259 | 264 | | |
260 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
261 | 274 | | |
262 | 275 | | |
263 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
107 | 119 | | |
108 | 120 | | |
109 | 121 | | |
| |||
123 | 135 | | |
124 | 136 | | |
125 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
126 | 143 | | |
127 | 144 | | |
128 | 145 | | |
| |||
0 commit comments