Skip to main content

Module compact

Module compact 

Source
Expand description

Compact sync for compact-storage qmdbs.

Compact sync does not transfer or reconstruct the full historical operation log. Instead, the source serves the minimum authenticated state needed to recreate the latest committed compact db state:

  • the total committed leaf count,
  • the compact frontier’s pinned nodes for that leaf count,
  • the final commit operation, and
  • a proof authenticating that final commit against the requested root.

§What compact dbs store

A compact db persists two pieces of state that must always describe the same committed tip:

  1. the compact Merkle frontier (persisted by crate::merkle::compact), and
  2. a db-level witness for the last commit (persisted by qmdb::compact::witness).

The witness exists because only the db layer knows how to encode and decode the typed commit operation. Without it, a compact db could recover its root and continue appending, but it could not serve compact sync to another node.

§When compact state changes

The servable compact state advances only on durable persistence:

  • sync verifies the final commit proof and compact frontier before database construction.
  • Database::from_validated_state reconstructs the already-validated state in memory only.
  • Compact db-local commits persist the frontier and witness together during sync/commit.
  • rewind restores both the frontier and the witness from the previous slot together.

Unsynced in-memory mutations are therefore intentionally not servable: current_target() and compact-state responses lag behind apply_batch() until the next durable sync.

§Safety and invariants

The compact path relies on these invariants:

  • the served commit proof must authenticate the final commit at leaf_count - 1,
  • the frontier pins and witness must move together in the same ping-pong slot,
  • reopen and rewind must re-verify the persisted witness against the root restored from that slot, and
  • reconstructed state must not be persisted until the db recomputes the requested root locally.

If those invariants are violated by missing or corrupted persisted data, compact db reopen fails with DataCorrupted rather than silently serving or restoring mismatched state.

Structs§

Config
Configuration for compact synchronization into a compact-storage database.
FetchResult
Result from a compact-state fetch.
State
Authenticated state for initializing a compact-storage database at a target root.
Target
Compact-sync target for a compact-storage database.
ValidatedState
Compact state that has been validated against a target root.

Enums§

ServeError
Resolver-side errors for compact state serving.

Traits§

CompactDbResolver
Marker trait for resolvers whose associated types match a specific compact-sync database.
Database
Database types that can be initialized directly from compact state.
Resolver
Trait for compact sync fetches from a source database.

Functions§

sync
Create/open a compact-storage database and initialize it from compact authenticated state.