UNPKG

@lodestar/beacon-node

Version:

A Typescript implementation of the beacon chain

81 lines 4.05 kB
import { routes } from "@lodestar/api"; import { ProtoBlock } from "@lodestar/fork-choice"; import { CachedBeaconStateAllForks } from "@lodestar/state-transition"; import { BeaconBlock, Epoch, RootHex, Slot, phase0 } from "@lodestar/types"; import { JobItemQueue } from "../../util/queue/index.js"; import { CheckpointHex } from "../stateCache/index.js"; import { IStateRegenerator, IStateRegeneratorInternal, RegenCaller, StateRegenerationOpts } from "./interface.js"; import { RegenModules } from "./regen.js"; type QueuedStateRegeneratorModules = RegenModules & { signal: AbortSignal; }; type RegenRequestKey = keyof IStateRegeneratorInternal; type RegenRequestByKey = { [K in RegenRequestKey]: { key: K; args: Parameters<IStateRegeneratorInternal[K]>; }; }; export type RegenRequest = RegenRequestByKey[RegenRequestKey]; /** * Regenerates states that have already been processed by the fork choice * * All requests are queued so that only a single state at a time may be regenerated at a time */ export declare class QueuedStateRegenerator implements IStateRegenerator { readonly jobQueue: JobItemQueue<[RegenRequest], CachedBeaconStateAllForks>; private readonly regen; private readonly forkChoice; private readonly blockStateCache; private readonly checkpointStateCache; private readonly metrics; private readonly logger; constructor(modules: QueuedStateRegeneratorModules); init(): Promise<void>; canAcceptWork(): boolean; dropCache(): void; dumpCacheSummary(): routes.lodestar.StateCacheItem[]; /** * Get a state from block state cache. * This is not for block processing so don't transfer cache */ getStateSync(stateRoot: RootHex): CachedBeaconStateAllForks | null; /** * Get state for block processing. * By default, do not transfer cache except for the block at clock slot * which is usually the gossip block. */ getPreStateSync(block: BeaconBlock, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null; getCheckpointStateOrBytes(cp: CheckpointHex): Promise<CachedBeaconStateAllForks | Uint8Array | null>; /** * Get checkpoint state from cache, this function is not for block processing so don't transfer cache */ getCheckpointStateSync(cp: CheckpointHex): CachedBeaconStateAllForks | null; /** * Get state closest to head, this function is not for block processing so don't transfer cache */ getClosestHeadState(head: ProtoBlock): CachedBeaconStateAllForks | null; pruneOnCheckpoint(finalizedEpoch: Epoch, justifiedEpoch: Epoch, headStateRoot: RootHex): void; pruneOnFinalized(finalizedEpoch: number): void; processState(blockRootHex: RootHex, postState: CachedBeaconStateAllForks): void; addCheckpointState(cp: phase0.Checkpoint, item: CachedBeaconStateAllForks): void; updateHeadState(newHead: ProtoBlock, maybeHeadState: CachedBeaconStateAllForks): void; updatePreComputedCheckpoint(rootHex: RootHex, epoch: Epoch): number | null; /** * Get the state to run with `block`. * - State after `block.parentRoot` dialed forward to block.slot */ getPreState(block: BeaconBlock, opts: StateRegenerationOpts, rCaller: RegenCaller): Promise<CachedBeaconStateAllForks>; getCheckpointState(cp: phase0.Checkpoint, opts: StateRegenerationOpts, rCaller: RegenCaller): Promise<CachedBeaconStateAllForks>; /** * Get state of provided `blockRoot` and dial forward to `slot` * Use this api with care because we don't want the queue to be busy * For the context, gossip block validation uses this api so we want it to be as fast as possible * @returns */ getBlockSlotState(blockRoot: RootHex, slot: Slot, opts: StateRegenerationOpts, rCaller: RegenCaller): Promise<CachedBeaconStateAllForks>; getState(stateRoot: RootHex, rCaller: RegenCaller, opts?: StateRegenerationOpts): Promise<CachedBeaconStateAllForks>; private jobQueueProcessor; } export {}; //# sourceMappingURL=queued.d.ts.map