Commit 4653568
feat(node): skip checkpoint sync when recent state data is in the db (#403)
When `--checkpoint-sync-url` is provided, the node currently always
downloads a fresh finalized state from the peer, even if a recent state
is already on disk. Skip the network round-trip when the persisted state
is fresh enough to resume from.
This PR introduces a state data freshness threshold -
`MAX_RESUMABLE_DB_STATE_AGE = 450` slots (~30 min at 4s/slot) - picked
conservatively considering the per-block backfill cost. I couldn't
identify in the specs a formal weak-subjectivity period or a method of
calculating it, so this is a judgement call; happy to take any
suggestions on the value or a better approach for it.
## What Changed
- `crates/storage/src/store.rs` — added `Store::from_db_state(backend,
expected_genesis_time)`, a no-write constructor that wraps an
already-initialized backend. Returns `None` if the backend is empty or
its persisted `genesis_time` doesn't match. Added the
`MAX_RESUMABLE_DB_STATE_AGE = 450` constant (~30 min at 4s/slot).
- `crates/storage/src/lib.rs` — re-exported
`MAX_RESUMABLE_DB_STATE_AGE`.
- `bin/ethlambda/src/main.rs` — in the checkpoint-sync branch of
`fetch_initial_state`, try `Store::from_db_state` first. If the
persisted finalized slot is within `MAX_RESUMABLE_DB_STATE_AGE` of
wall-clock, return the resumed store and skip checkpoint sync. Otherwise
warn and fall through to the existing sync path.
## Correctness / Behavior Guarantees
- New short-circuit fires only when: checkpoint URL provided AND DB
populated AND persisted `genesis_time` matches AND `current_slot -
latest_finalized.slot <= MAX_RESUMABLE_DB_STATE_AGE`. Everything else
remains unchanged.
- 30 min threshold is conservative for the current `BlocksByRoot`-only
backfill cost; can be increased once `BlocksByRange` long-range sync
(#351) is added.
## Tests Added / Run
Three unit tests in `crates/storage/src/store.rs` covering the
`from_db_state` contract:
- `from_db_state_returns_none_on_empty_backend`
- `from_db_state_returns_some_on_matching_genesis_time`
- `from_db_state_returns_none_on_genesis_time_mismatch`
## Related Issues / PRs
- Closes #121
- Related to #351 (BlocksByRange long-range sync — once landed,
`MAX_RESUMABLE_DB_STATE_AGE` can probably be raised toward
`STATES_TO_KEEP`)
## ✅ Verification Checklist
- [x] Ran `make fmt` — clean
- [x] Ran `make lint` (clippy with `-D warnings`) — clean
- [x] Ran `cargo test --workspace --release` — all passing
- [x] Local devnet test
---------
Co-authored-by: Pablo Deymonnaz <pdeymon@fi.uba.ar>1 parent ea08e26 commit 4653568
3 files changed
Lines changed: 111 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
39 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
| |||
635 | 639 | | |
636 | 640 | | |
637 | 641 | | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
638 | 666 | | |
639 | 667 | | |
640 | 668 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
108 | 111 | | |
109 | 112 | | |
110 | 113 | | |
| |||
550 | 553 | | |
551 | 554 | | |
552 | 555 | | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
553 | 591 | | |
554 | 592 | | |
555 | 593 | | |
| |||
2548 | 2586 | | |
2549 | 2587 | | |
2550 | 2588 | | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
| 2625 | + | |
| 2626 | + | |
| 2627 | + | |
| 2628 | + | |
| 2629 | + | |
| 2630 | + | |
2551 | 2631 | | |
0 commit comments