added beacon state-transition first structure (#6105)

This commit is contained in:
Giulio rebuffo 2022-11-22 15:36:08 +01:00 committed by GitHub
parent f76736e14a
commit a1de39d25c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View File

@ -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
}

View File

@ -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,
}
}