Module Normal.Registry

include Octez_riscv_nds_common.Intf.REGISTRY
type t
val hash : t -> bytes

hash registry computes the Merkle root hash of registry, derived from the root hashes of all its databases. Normal and Prove return bytes directly from the Rust binding; Verify converts a verification_error return into a raised Nds_errors.Verification_failed, so the signature stays bytes across modes. Catch the exception at the Nds.with_verification boundary rather than at individual call sites.

val size : t -> int64

size registry returns the number of databases currently held in registry. Same exception convention as hash: Normal/Prove return int64 directly, Verify raises Nds_errors.Verification_failed on a proof mismatch.

val resize : t -> int64 -> (unit, Octez_riscv_nds_common.Nds_errors.invalid_argument_error) Stdlib.result

resize registry n adjusts registry to contain exactly n databases. The size can only change by one at a time; call this function in a loop for larger adjustments. Growing appends a new empty database; shrinking drops the last database. Returns an error if |current_size - n| > 1.

val copy_database : t -> src:int64 -> dst:int64 -> (unit, Octez_riscv_nds_common.Nds_errors.invalid_argument_error) Stdlib.result

copy_database registry ~src ~dst duplicates all contents of the database at index src into index dst, completely replacing the previous contents of dst. The source database is unchanged. Copying to the same index is a no-op. Returns an error if src or dst is out of bounds.

val move_database : t -> src:int64 -> dst:int64 -> (unit, Octez_riscv_nds_common.Nds_errors.invalid_argument_error) Stdlib.result

move_database registry ~src ~dst transfers the database at index src to index dst, completely replacing the previous contents of dst. The source is replaced with a fresh empty database. Moving to the same index is a no-op. Returns an error if src or dst is out of bounds.

val clear : t -> int64 -> (unit, Octez_riscv_nds_common.Nds_errors.invalid_argument_error) Stdlib.result

clear registry db_index replaces the database at db_index with a fresh empty database. Returns an error if db_index is out of bounds.

val create : Repo.t -> t

create repo creates a new, empty registry backed by repo.

val commit : t -> bytes

commit registry persists the current state and returns a commit identifier that can be used with checkout.

val checkout : Repo.t -> bytes -> t

checkout repo commit_id restores the registry to the state recorded at commit_id.

type imm

Immutable snapshot of a registry. Only obtainable through to_imm; carries no operations of its own.

val to_imm : t -> imm

to_imm registry captures the current contents of registry — including operations not yet committed — as an immutable snapshot. Mutations to registry after the call are not observable through the snapshot. Copy-on-write of the in-memory state: eager (one copy now) if registry holds unshared state, free if it is already shared with another handle, after which the next mutation on either side pays the copy. Nothing is written to the repository.

val from_imm : imm -> t

from_imm imm recovers a live registry from a snapshot, backed by the same repository. The returned registry is independent of every other registry recovered from the same snapshot (copy-on-write, as to_imm).

val duplicate : t -> t

duplicate registry is from_imm (to_imm registry): an independent registry holding the same contents, backed by the same repository. Mutations to either handle are invisible to the other. Copies the in-memory state up to twice for unshared state (once in to_imm, once on the duplicate's first mutation); acceptable here as this is not a hot path.