mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-13 14:30:15 +00:00
added beacon state-transition first structure (#6105)
This commit is contained in:
parent
f76736e14a
commit
a1de39d25c
23
cmd/erigon-cl/cl-core/transition/process_slots.go
Normal file
23
cmd/erigon-cl/cl-core/transition/process_slots.go
Normal 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
|
||||
}
|
21
cmd/erigon-cl/cl-core/transition/state_transistor.go
Normal file
21
cmd/erigon-cl/cl-core/transition/state_transistor.go
Normal 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,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user