Skip to main content

Module chain_storage

Module chain_storage 

Source
Expand description

Pin the chain storage location once at boot, and guard it with a lock.

The kernel reads the chain checkpoint path in several places: boot (signing key, RVF restore, tree checkpoint), the daemon’s chain.verify RPC, and shutdown persistence. pin_chain_storage resolves the path a single time and writes it into the kernel config, so all of them agree even if the environment changes after boot.

Resolution, highest first:

  1. an explicit kernel.chain.checkpoint_path;
  2. chain.json under the runtime root (clawft_types::runtime_paths::RuntimePaths: $WEFTOS_RUNTIME_DIR, else the project’s .weftos/runtime, else legacy ~/.clawft);
  3. a project root with no chain yet, while ~/.clawft/chain.* exists (and no --new-chain): keep using the legacy chain and key. Booting a fresh genesis here would silently fork the operator’s history, so the legacy chain stays in use (WARN) until weaver migrate user-chain (ADR-103 Phase 1) moves it.

Once the legacy chain carries a MIGRATED-TO-WEFTOS.txt marker, a boot that would still land on it is refused (it would fork history) unless WEFTOS_RUNTIME_DIR isolates it or --adopt-legacy-chain is passed (with a WARN).

Whichever chain is in use is guarded by ChainLock (chain.lock beside it) for the kernel’s lifetime, so two kernels can never append to one chain. In this crate’s own unit tests the default is a fresh temp dir per boot, so cargo test never touches the operator chain.

Structs§

ChainChoice
Which chain a default-path boot should use.
ChainLock
Exclusive advisory lock on chain.lock beside the chain in use.
PinOutcome
What pin_chain_storage_noted decided.

Enums§

ChainLockError
Why ChainLock::try_acquire failed.

Constants§

LEGACY_ACTIVE_WINDOW
A legacy chain modified within this window may still have a live writer.

Functions§

boot_runtime_paths
The runtime paths this boot uses for every non-chain runtime file (cluster peers, apps, revoked hosts).
choose_default_chain
Choose the default chain for paths (see module docs, rule 2 and 3).
pin_chain_storage
Resolve the chain checkpoint path and pin it into kernel_config.chain.
pin_chain_storage_noted
pin_chain_storage plus the warning and refusal for the choice.
request_adopt_legacy_chain
Allow the next boot to adopt the legacy ~/.clawft chain for the first time (weaver kernel start --adopt-legacy-chain). Needed only while no chain.lock exists beside it, i.e. no lock-aware kernel has used it yet.
request_new_chain
Ask the next boot to start a fresh chain at the resolved path instead of adopting the legacy ~/.clawft chain (weaver kernel start --new-chain). Process-wide on purpose: it is an operator flag, not a config-file field.