lodestar icon indicating copy to clipboard operation
lodestar copied to clipboard

Decouple beacon-node and state-transition

Open twoeths opened this issue 1 month ago • 1 comments

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

  • [ ] 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

twoeths avatar Dec 02 '25 06:12 twoeths

Image

Rough gantt chart of some of our goals. Subject to change as timelines are estimated.

philknows avatar Dec 03 '25 19:12 philknows

need to add eth1Data to IBeaconStateView also, it's needed to produce block, see https://github.com/ChainSafe/lodestar/pull/8692/changes#diff-c331f7b8e7121839c55f5f20f21d1efe1375b69c6fbbe5db12a4baf1ed4acf5dR673

twoeths avatar Dec 15 '25 03:12 twoeths