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"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
2021-03-18 21:00:00 +00:00
|
|
|
)
|
|
|
|
|
2023-04-06 19:45:35 +00:00
|
|
|
var embeddedStates = map[string]*[]byte{}
|
2021-03-18 21:00:00 +00:00
|
|
|
|
|
|
|
// 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) {
|
2023-04-06 19:45:35 +00:00
|
|
|
sb, exists := embeddedStates[name]
|
|
|
|
if exists {
|
|
|
|
return load(*sb)
|
2021-03-18 21:00:00 +00:00
|
|
|
}
|
2023-04-06 19:45:35 +00:00
|
|
|
return nil, nil
|
2021-03-18 21:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|