Skip to content

Decouple beacon-node and state-transition #8650

@twoeths

Description

@twoeths

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 example TSBeaconStateView, based on an existing CachedBeaconStateAllForks and pass it everywhere
  • once it's done we populate TSBeaconStateView to state cache, changes all interface of regen + state cache to IBeaconStateView
  • once we have a binding for lodestar-z, we'll have another implementation, for example NativeBeaconStateView to 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 with IBeaconStateView
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    epicIssues used as milestones and tracking multiple issues.meta-feature-requestIssues to track feature requests.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions