forked from ChainSafe/lodestar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.ts
More file actions
90 lines (82 loc) · 3.29 KB
/
interface.ts
File metadata and controls
90 lines (82 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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 {CheckpointHex} from "../stateCache/index.js";
export enum RegenCaller {
getDuties = "getDuties",
processBlock = "processBlock",
produceBlock = "produceBlock",
validateGossipBlock = "validateGossipBlock",
validateGossipBlob = "validateGossipBlob",
validateGossipDataColumn = "validateGossipDataColumn",
precomputeEpoch = "precomputeEpoch",
predictProposerHead = "predictProposerHead",
produceAttestationData = "produceAttestationData",
processBlocksInEpoch = "processBlocksInEpoch",
validateGossipAggregateAndProof = "validateGossipAggregateAndProof",
validateGossipAttestation = "validateGossipAttestation",
validateGossipVoluntaryExit = "validateGossipVoluntaryExit",
onForkChoiceFinalized = "onForkChoiceFinalized",
restApi = "restApi",
}
export enum RegenFnName {
getBlockSlotState = "getBlockSlotState",
getState = "getState",
getPreState = "getPreState",
getCheckpointState = "getCheckpointState",
}
export type StateRegenerationOpts = {
dontTransferCache: boolean;
};
export interface IStateRegenerator extends IStateRegeneratorInternal {
dropCache(): void;
dumpCacheSummary(): routes.lodestar.StateCacheItem[];
getStateSync(stateRoot: RootHex): CachedBeaconStateAllForks | null;
getPreStateSync(block: BeaconBlock): CachedBeaconStateAllForks | null;
getCheckpointStateOrBytes(cp: CheckpointHex): Promise<CachedBeaconStateAllForks | Uint8Array | null>;
getCheckpointStateSync(cp: CheckpointHex): CachedBeaconStateAllForks | null;
getClosestHeadState(head: ProtoBlock): CachedBeaconStateAllForks | null;
pruneOnCheckpoint(finalizedEpoch: Epoch, justifiedEpoch: Epoch, headStateRoot: RootHex): void;
pruneOnFinalized(finalizedEpoch: Epoch): 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;
}
/**
* Regenerates states that have already been processed by the fork choice
*/
export interface IStateRegeneratorInternal {
/**
* Return a valid pre-state for a beacon block
* This will always return a state in the latest viable epoch
*/
getPreState(
block: BeaconBlock,
opts: StateRegenerationOpts,
rCaller: RegenCaller
): Promise<CachedBeaconStateAllForks>;
/**
* Return a valid checkpoint state
* This will always return a state with `state.slot % SLOTS_PER_EPOCH === 0`
*/
getCheckpointState(
cp: phase0.Checkpoint,
opts: StateRegenerationOpts,
rCaller: RegenCaller
): Promise<CachedBeaconStateAllForks>;
/**
* Return the state of `blockRoot` processed to slot `slot`
*/
getBlockSlotState(
blockRoot: RootHex,
slot: Slot,
opts: StateRegenerationOpts,
rCaller: RegenCaller
): Promise<CachedBeaconStateAllForks>;
/**
* Return the exact state with `stateRoot`
*/
getState(stateRoot: RootHex, rCaller: RegenCaller, opts?: StateRegenerationOpts): Promise<CachedBeaconStateAllForks>;
}