erigon-pulse/cl/clparams/initial_state/initial_state.go
a 3ab373787e
[caplin] extracting beacon state interface (#7910)
we need to extract this interface from the struct. 

i need to also break down the interface more, to better show what parts
the caching is used, move some functions from the cache state to the
underlying.


don't merge
2023-07-20 00:20:33 +02:00

44 lines
1.1 KiB
Go

package initial_state
import (
_ "embed"
"fmt"
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
"github.com/ledgerwatch/erigon/cl/clparams"
)
//go:embed mainnet.state.ssz
var mainnetStateSSZ []byte
//go:embed sepolia.state.ssz
var sepoliaStateSSZ []byte
//go:embed goerli.state.ssz
var goerliStateSSZ []byte
// Return genesis state
func GetGenesisState(network clparams.NetworkType) (*state.CachingBeaconState, error) {
_, _, config := clparams.GetConfigsByNetwork(network)
returnState := state.New(config)
switch network {
case clparams.MainnetNetwork:
if err := returnState.DecodeSSZ(mainnetStateSSZ, int(clparams.Phase0Version)); err != nil {
return nil, err
}
case clparams.GoerliNetwork:
if err := returnState.DecodeSSZ(goerliStateSSZ, int(clparams.Phase0Version)); err != nil {
return nil, err
}
case clparams.SepoliaNetwork:
if err := returnState.DecodeSSZ(sepoliaStateSSZ, int(clparams.Phase0Version)); err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unsupported network for genesis fetching")
}
return returnState, nil
}