Typeberry by Fluffy Labs - v0.9.0
    Preparing search index...

    Interface StatesDb<T>

    Interface for accessing states stored in the database.

    NOTE that the design of this interface is heavily influenced by the LMDB implementation, so that we can implement it efficiently.

    See the documentation there for more detailed reasoning.

    interface StatesDb<T extends State = State> {
        close(): Promise<void>;
        commitFinalized(headers: (OpaqueHash & WithOpaque<"HeaderHash">)[]): void;
        diskSizeInBytes?(): number | null;
        getState(header: OpaqueHash & WithOpaque<"HeaderHash">): T | null;
        getStateRoot(state: T): Promise<OpaqueHash & WithOpaque<"StateRootHash">>;
        markUnused(header: OpaqueHash & WithOpaque<"HeaderHash">): void;
        updateAndSetState(
            header: OpaqueHash & WithOpaque<"HeaderHash">,
            state: T,
            update: Partial<State & ServicesUpdate>,
        ): Promise<Result<typeof OK, StateUpdateError>>;
    }

    Type Parameters

    Implemented by

    Index

    Methods

    • Notify the backend about newly finalized blocks, in ancestor-first order.

      Backends that share data between states (e.g. a content-addressed values DB) use this to move the blocks' references from speculative to finalized. MUST be called before markUnused of the same finality round, otherwise the newly finalized blocks would be treated as dead forks and values still referenced by the finalized state could be dropped.

      Parameters

      Returns void

    • Apparent on-disk size of the database in bytes, used for monitoring.

      Returns null when the size is unknown. Backends that are not persisted (e.g. in-memory) may omit the method entirely.

      Returns number | null