2021-03-18 21:00:00 +00:00
|
|
|
package genesis
|
|
|
|
|
|
|
|
import (
|
|
|
|
_ "embed"
|
|
|
|
|
|
|
|
"github.com/golang/snappy"
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state"
|
|
|
|
state_native "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/config/params"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
2021-03-18 21:00:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
//go:embed mainnet.ssz.snappy
|
|
|
|
mainnetRawSSZCompressed []byte // 1.8Mb
|
|
|
|
)
|
|
|
|
|
|
|
|
// State returns a copy of the genesis state from a hardcoded value.
|
2022-02-08 09:30:06 +00:00
|
|
|
func State(name string) (state.BeaconState, error) {
|
2021-03-18 21:00:00 +00:00
|
|
|
switch name {
|
2022-05-06 21:42:27 +00:00
|
|
|
case params.MainnetName:
|
2021-03-18 21:00:00 +00:00
|
|
|
return load(mainnetRawSSZCompressed)
|
|
|
|
default:
|
|
|
|
// No state found.
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// load a compressed ssz state file into a beacon state struct.
|
2022-02-08 09:30:06 +00:00
|
|
|
func load(b []byte) (state.BeaconState, error) {
|
2021-07-29 21:45:17 +00:00
|
|
|
st := ðpb.BeaconState{}
|
2021-03-18 21:00:00 +00:00
|
|
|
b, err := snappy.Decode(nil /*dst*/, b)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := st.UnmarshalSSZ(b); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-09-16 22:17:46 +00:00
|
|
|
return state_native.InitializeFromProtoUnsafePhase0(st)
|
2021-03-18 21:00:00 +00:00
|
|
|
}
|