Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions crates/common/types/src/beacon/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ use crate::beacon::preset;
const LEAN_SNAPSHOT_INTERVAL: u64 = 1_024;

/// How many slots apart full state snapshots are written for the Beacon
/// Chain, in [`ForkName::snapshot_interval`]: one epoch, so a
/// reconstruction fold is bounded at one epoch of blocks plus a single
/// decode.
/// Chain, in [`ForkName::snapshot_interval`]: one epoch. A beacon read applies
/// one delta against its snapshot whatever the interval, so what this bounds
/// is how large a delta grows (it carries every change since its snapshot) and
/// how often a full snapshot is written.
const BEACON_SNAPSHOT_INTERVAL: u64 = preset::SLOTS_PER_EPOCH;

/// A named fork of the Beacon Chain, ordered oldest to newest, followed by
Expand Down Expand Up @@ -188,10 +189,11 @@ impl ForkName {
/// here rather than on `Config`: putting it in a config a chain agrees on
/// would imply the two had to agree on it.
///
/// Lean's interval does not survive contact with a ~350 MB beacon state,
/// since the reconstruction fold would apply that many deltas; beacon
/// takes an epoch, so the fold is bounded at one epoch of blocks plus a
/// single decode.
/// Lean's interval does not survive contact with a ~350 MB beacon state:
/// a beacon diff carries every change since its snapshot, so a long
/// interval lets deltas grow large, and a snapshot is a full copy of the
/// state. Beacon takes an epoch, which bounds both; a read applies a single
/// delta whatever the interval, and decodes once.
pub const fn snapshot_interval(self) -> u64 {
match self {
ForkName::Lean => LEAN_SNAPSHOT_INTERVAL,
Expand Down
8 changes: 5 additions & 3 deletions crates/storage/src/api/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ pub enum Table {
States,
/// State diffs: slot || root -> StateDiff
///
/// Parent-linked diff written for every non-anchor state, keyed like
/// `States`. Pruned below the finalized snapshot interval together with
/// `States`. See `get_state` for reconstruction.
/// Diff written for every non-anchor state, keyed like `States`. Lean's is
/// parent-linked; a beacon diff is taken against the nearest snapshot on
/// its branch, so a beacon state is one snapshot plus one delta. Pruned
/// below the finalized snapshot interval together with `States`. See
/// `get_state` for reconstruction.
StateDiffs,
/// Metadata: string keys -> various scalar values
Metadata,
Expand Down
10 changes: 8 additions & 2 deletions crates/storage/src/beacon_state_delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
//!
//! `insert_state`/`get_state` (in `store.rs`) call into this module for the
//! beacon arm: `insert_state` writes a snapshot at anchors and a
//! [`frame`]d [`encode`] otherwise, and `get_state` walks the resulting
//! chain and [`decode`]s it back, via [`unframe`].
//! [`frame`]d [`encode`] otherwise, and `get_state` follows the frame's base
//! and [`decode`]s it back, via [`unframe`].
//!
//! The base of a delta is the nearest snapshot on the state's branch, not its
//! parent. A read is then one snapshot plus one delta, whatever the state's
//! distance from the snapshot; the price is that a delta carries every change
//! since the snapshot, so it grows across the interval. The frame names its
//! own base, so the reader does not care which of the two a given frame uses.

use ethlambda_types::primitives::H256;

Expand Down
Loading
Loading