-
-
Notifications
You must be signed in to change notification settings - Fork 348
/
Copy pathinterface.ts
176 lines (152 loc) Β· 7.19 KB
/
interface.ts
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import {CompositeTypeAny, TreeView, Type} from "@chainsafe/ssz";
import {allForks, UintNum64, Root, phase0, Slot, RootHex, Epoch, ValidatorIndex, deneb, Wei} from "@lodestar/types";
import {
BeaconStateAllForks,
CachedBeaconStateAllForks,
Index2PubkeyCache,
PubkeyIndexMap,
} from "@lodestar/state-transition";
import {BeaconConfig} from "@lodestar/config";
import {Logger} from "@lodestar/utils";
import {IForkChoice, ProtoBlock} from "@lodestar/fork-choice";
import {IEth1ForBlockProduction} from "../eth1/index.js";
import {IExecutionEngine, IExecutionBuilder} from "../execution/index.js";
import {Metrics} from "../metrics/metrics.js";
import {IClock} from "../util/clock.js";
import {ChainEventEmitter} from "./emitter.js";
import {IStateRegenerator, RegenCaller} from "./regen/index.js";
import {IBlsVerifier} from "./bls/index.js";
import {
SeenAttesters,
SeenAggregators,
SeenBlockProposers,
SeenSyncCommitteeMessages,
SeenContributionAndProof,
} from "./seenCache/index.js";
import {AttestationPool, OpPool, SyncCommitteeMessagePool, SyncContributionAndProofPool} from "./opPools/index.js";
import {LightClientServer} from "./lightClient/index.js";
import {AggregatedAttestationPool} from "./opPools/aggregatedAttestationPool.js";
import {BlockInput, ImportBlockOpts} from "./blocks/types.js";
import {ReprocessController} from "./reprocess.js";
import {SeenAggregatedAttestations} from "./seenCache/seenAggregateAndProof.js";
import {BeaconProposerCache, ProposerPreparationData} from "./beaconProposerCache.js";
import {SeenBlockAttesters} from "./seenCache/seenBlockAttesters.js";
import {CheckpointBalancesCache} from "./balancesCache.js";
import {IChainOptions} from "./options.js";
import {AssembledBlockType, BlockAttributes, BlockType} from "./produceBlock/produceBlockBody.js";
import {SeenAttestationDatas} from "./seenCache/seenAttestationData.js";
import {ShufflingCache} from "./shufflingCache.js";
export {BlockType, AssembledBlockType};
export {ProposerPreparationData};
export type BlockHash = RootHex;
export type StateGetOpts = {
allowRegen: boolean;
};
/**
* The IBeaconChain service deals with processing incoming blocks, advancing a state transition
* and applying the fork choice rule to update the chain head
*/
export interface IBeaconChain {
readonly genesisTime: UintNum64;
readonly genesisValidatorsRoot: Root;
readonly eth1: IEth1ForBlockProduction;
readonly executionEngine: IExecutionEngine;
readonly executionBuilder?: IExecutionBuilder;
// Expose config for convenience in modularized functions
readonly config: BeaconConfig;
readonly logger: Logger;
readonly metrics: Metrics | null;
/** The initial slot that the chain is started with */
readonly anchorStateLatestBlockSlot: Slot;
readonly bls: IBlsVerifier;
readonly forkChoice: IForkChoice;
readonly clock: IClock;
readonly emitter: ChainEventEmitter;
readonly regen: IStateRegenerator;
readonly lightClientServer: LightClientServer;
readonly reprocessController: ReprocessController;
readonly pubkey2index: PubkeyIndexMap;
readonly index2pubkey: Index2PubkeyCache;
// Ops pool
readonly attestationPool: AttestationPool;
readonly aggregatedAttestationPool: AggregatedAttestationPool;
readonly syncCommitteeMessagePool: SyncCommitteeMessagePool;
readonly syncContributionAndProofPool: SyncContributionAndProofPool;
readonly opPool: OpPool;
// Gossip seen cache
readonly seenAttesters: SeenAttesters;
readonly seenAggregators: SeenAggregators;
readonly seenAggregatedAttestations: SeenAggregatedAttestations;
readonly seenBlockProposers: SeenBlockProposers;
readonly seenSyncCommitteeMessages: SeenSyncCommitteeMessages;
readonly seenContributionAndProof: SeenContributionAndProof;
readonly seenAttestationDatas: SeenAttestationDatas;
// Seen cache for liveness checks
readonly seenBlockAttesters: SeenBlockAttesters;
readonly beaconProposerCache: BeaconProposerCache;
readonly checkpointBalancesCache: CheckpointBalancesCache;
readonly shufflingCache: ShufflingCache;
readonly producedBlobSidecarsCache: Map<BlockHash, {blobSidecars: deneb.BlobSidecars; slot: Slot}>;
readonly producedBlindedBlobSidecarsCache: Map<BlockHash, {blobSidecars: deneb.BlindedBlobSidecars; slot: Slot}>;
readonly producedBlockRoot: Set<RootHex>;
readonly producedBlindedBlockRoot: Set<RootHex>;
readonly opts: IChainOptions;
/** Stop beacon chain processing */
close(): Promise<void>;
/** Populate in-memory caches with persisted data. Call at least once on startup */
loadFromDisk(): Promise<void>;
/** Persist in-memory data to the DB. Call at least once before stopping the process */
persistToDisk(): Promise<void>;
validatorSeenAtEpoch(index: ValidatorIndex, epoch: Epoch): boolean;
getHeadState(): CachedBeaconStateAllForks;
getHeadStateAtCurrentEpoch(regenCaller: RegenCaller): Promise<CachedBeaconStateAllForks>;
getHeadStateAtEpoch(epoch: Epoch, regenCaller: RegenCaller): Promise<CachedBeaconStateAllForks>;
/** Returns a local state canonical at `slot` */
getStateBySlot(
slot: Slot,
opts?: StateGetOpts
): Promise<{state: BeaconStateAllForks; executionOptimistic: boolean} | null>;
/** Returns a local state by state root */
getStateByStateRoot(
stateRoot: RootHex,
opts?: StateGetOpts
): Promise<{state: BeaconStateAllForks; executionOptimistic: boolean} | null>;
/**
* Since we can have multiple parallel chains,
* this methods returns blocks in current chain head according to
* forkchoice. Works for finalized slots as well
*/
getCanonicalBlockAtSlot(
slot: Slot
): Promise<{block: allForks.SignedBeaconBlock; executionOptimistic: boolean} | null>;
/**
* Get local block by root, does not fetch from the network
*/
getBlockByRoot(root: RootHex): Promise<{block: allForks.SignedBeaconBlock; executionOptimistic: boolean} | null>;
getBlobSidecars(beaconBlock: deneb.BeaconBlock): deneb.BlobSidecars;
produceBlock(blockAttributes: BlockAttributes): Promise<{block: allForks.BeaconBlock; blockValue: Wei}>;
produceBlindedBlock(blockAttributes: BlockAttributes): Promise<{block: allForks.BlindedBeaconBlock; blockValue: Wei}>;
/** Process a block until complete */
processBlock(block: BlockInput, opts?: ImportBlockOpts): Promise<void>;
/** Process a chain of blocks until complete */
processChainSegment(blocks: BlockInput[], opts?: ImportBlockOpts): Promise<void>;
getStatus(): phase0.Status;
recomputeForkChoiceHead(): ProtoBlock;
waitForBlock(slot: Slot, root: RootHex): Promise<boolean>;
updateBeaconProposerData(epoch: Epoch, proposers: ProposerPreparationData[]): Promise<void>;
persistInvalidSszValue<T>(type: Type<T>, sszObject: T | Uint8Array, suffix?: string): void;
persistInvalidSszBytes(type: string, sszBytes: Uint8Array, suffix?: string): void;
/** Persist bad items to persistInvalidSszObjectsDir dir, for example invalid state, attestations etc. */
persistInvalidSszView(view: TreeView<CompositeTypeAny>, suffix?: string): void;
updateBuilderStatus(clockSlot: Slot): void;
regenCanAcceptWork(): boolean;
blsThreadPoolCanAcceptWork(): boolean;
}
export type SSZObjectType =
| "state"
| "signedBlock"
| "block"
| "attestation"
| "signedAggregatedAndProof"
| "syncCommittee"
| "contributionAndProof";