Decouple beacon-node and state-transition
Problem description
right now beacon-node and state-transition both stay on typescript in the near future, beacon-node stays on typescript while state transition is siwtched to native (zig) in lodestar-z so we need to prepare for that
Solution description
avoid having CachedBeaconStateAllForks in all function parameters of beacon node. Instead of that, we need to implement a light version of BeaconState, for example
export interface IBeaconStateView {
slot: Slot;
root: Bytes32;
rootHex: RootHex;
epoch: Epoch;
genesisTime: number;
latestExecutionPayloadBlockHash: Bytes32;
previousDecisionRoot: RootHex;
currentDecisionRoot: RootHex;
nextDecisionRoot: RootHex;
effectiveBalanceIncrements: Uint16Array;
previousJustifiedCheckpoint: Checkpoint;
currentJustifiedCheckpoint: Checkpoint;
finalizedCheckpoint: Checkpoint;
getRandaoMix(epoch: Epoch): Bytes32;
getProposerIndex(slot: Slot): number;
getBlockRootAtSlot(slot: Slot): Root;
getValidator(index: number): phase0.Validator;
}
- for now, in each consumer flow we create an implementation of
IBeaconStateView, for exampleTSBeaconStateView, based on an existingCachedBeaconStateAllForksand pass it everywhere - once it's done we populate
TSBeaconStateViewto state cache, changes all interface of regen + state cache toIBeaconStateView - once we have a binding for lodestar-z, we'll have another implementation, for example
NativeBeaconStateViewto lazy load and cache above data from native, then populate regen + state cache with it. All consumer codes of state cache + regen are unchanged because they work withIBeaconStateView - this provides way to have a feature flag to switch it on and off. Once it's stable we'll turn it on by default, like what we did in worker thread
also need to avoid using EpochCache data/functions
Tracked issues
- [ ] https://github.com/ChainSafe/lodestar/issues/8652
- [ ] https://github.com/ChainSafe/lodestar/issues/8651
- [ ] https://github.com/ChainSafe/lodestar/issues/8653
- [ ] https://github.com/ChainSafe/lodestar/issues/8654
- [ ] https://github.com/ChainSafe/lodestar/issues/8655
- [ ] https://github.com/ChainSafe/lodestar/issues/8657
- [ ] https://github.com/ChainSafe/lodestar/issues/8658
- [ ] https://github.com/ChainSafe/lodestar/issues/8659
- [ ] https://github.com/ChainSafe/lodestar/issues/8663
Rough gantt chart of some of our goals. Subject to change as timelines are estimated.
need to add eth1Data to IBeaconStateView also, it's needed to produce block, see https://github.com/ChainSafe/lodestar/pull/8692/changes#diff-c331f7b8e7121839c55f5f20f21d1efe1375b69c6fbbe5db12a4baf1ed4acf5dR673