From a1de39d25c40a5e654db6fb9c2bf6b90c6558473 Mon Sep 17 00:00:00 2001 From: Giulio rebuffo Date: Tue, 22 Nov 2022 15:36:08 +0100 Subject: [PATCH] added beacon state-transition first structure (#6105) --- .../cl-core/transition/process_slots.go | 23 +++++++++++++++++++ .../cl-core/transition/state_transistor.go | 21 +++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 cmd/erigon-cl/cl-core/transition/process_slots.go create mode 100644 cmd/erigon-cl/cl-core/transition/state_transistor.go diff --git a/cmd/erigon-cl/cl-core/transition/process_slots.go b/cmd/erigon-cl/cl-core/transition/process_slots.go new file mode 100644 index 000000000..0e98458d9 --- /dev/null +++ b/cmd/erigon-cl/cl-core/transition/process_slots.go @@ -0,0 +1,23 @@ +package transition + +import ( + "github.com/ledgerwatch/erigon/cl/cltypes" +) + +// transitionSlot is called each time there is a new slot to process +func (s *StateTransistor) transitionSlot(state *cltypes.BeaconState) error { + previousStateRoot, err := state.HashTreeRoot() + if err != nil { + return err + } + state.StateRoots[state.Slot/s.beaconConfig.SlotsPerHistoricalRoot] = previousStateRoot + if state.LatestBlockHeader.Root == [32]byte{} { + state.LatestBlockHeader.Root = previousStateRoot + } + previousBlockRoot, err := state.LatestBlockHeader.HashTreeRoot() + if err != nil { + return err + } + state.BlockRoots[state.Slot/s.beaconConfig.SlotsPerHistoricalRoot] = previousBlockRoot + return nil +} diff --git a/cmd/erigon-cl/cl-core/transition/state_transistor.go b/cmd/erigon-cl/cl-core/transition/state_transistor.go new file mode 100644 index 000000000..74301c935 --- /dev/null +++ b/cmd/erigon-cl/cl-core/transition/state_transistor.go @@ -0,0 +1,21 @@ +package transition + +import ( + "github.com/ledgerwatch/erigon/cl/clparams" + "github.com/ledgerwatch/erigon/cl/cltypes" +) + +// StateTransistor takes care of state transition +type StateTransistor struct { + state *cltypes.BeaconState + beaconConfig *clparams.BeaconChainConfig + genesisConfig *clparams.GenesisConfig +} + +func New(state *cltypes.BeaconState, beaconConfig *clparams.BeaconChainConfig, genesisConfig *clparams.GenesisConfig) *StateTransistor { + return &StateTransistor{ + state: state, + beaconConfig: beaconConfig, + genesisConfig: genesisConfig, + } +}