reth_snap_sync/lib.rs
1//! snap/2 state synchronization for [EIP-8189](https://eips.ethereum.org/EIPS/eip-8189).
2//!
3//! Coordinates a state bootstrap that starts from a recent pivot block, downloads accounts, storage
4//! and bytecode authenticated against that pivot's state root, and advances the pivot with
5//! [EIP-7928 block access lists](https://eips.ethereum.org/EIPS/eip-7928) as the chain moves past
6//! it.
7//!
8//! This crate owns download progress only. Authenticated downloads come from
9//! `reth-downloaders`, and verified state is handed back to node integration once its trie root
10//! matches the target header.
11//!
12//! Downloaded state goes into the hashed state tables, owned by an attempt record that commits
13//! with it. Scheduling, in-flight requests and cancellation stay in memory.
14//!
15//! ```
16//! use reth_snap_sync::SnapPivotPolicy;
17//!
18//! let policy = SnapPivotPolicy::default();
19//! // Without a finalized block, anchor at the EIP's example distance.
20//! assert_eq!(policy.pivot_block(1_000, None), Some(936));
21//! // A recent finalized block is anchored to directly.
22//! assert_eq!(policy.pivot_block(1_000, Some(950)), Some(950));
23//! // Stalled finality falls back to the example distance.
24//! assert_eq!(policy.pivot_block(1_000, Some(500)), Some(936));
25//! // A chain shorter than the head distance has no pivot yet.
26//! assert_eq!(policy.pivot_block(4, None), None);
27//! ```
28
29#![doc(
30 html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
31 html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
32 issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
33)]
34#![cfg_attr(not(test), warn(unused_crate_dependencies))]
35
36mod attempt;
37mod error;
38mod generation;
39mod pivot;
40mod session;
41
42#[cfg(test)]
43mod test_utils;
44
45pub use attempt::{SnapAttemptStore, SnapWrite};
46pub use error::SnapSyncError;
47pub use generation::{SnapGeneration, SnapPhase};
48pub use pivot::SnapPivotPolicy;
49pub use session::{SnapSyncSession, SnapSyncSessionState};