mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
Compare commits
1 Commits
d869754e2e
...
versionRef
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd51e70b74 |
@@ -12,7 +12,6 @@ import (
|
||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/encoding/ssz/detect"
|
||||
"github.com/prysmaticlabs/prysm/io/file"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/mod/semver"
|
||||
@@ -56,7 +55,7 @@ func (o *OriginData) BlockBytes() []byte {
|
||||
}
|
||||
|
||||
func fname(prefix string, vu *detect.VersionedUnmarshaler, slot types.Slot, root [32]byte) string {
|
||||
return fmt.Sprintf("%s_%s_%s_%d-%#x.ssz", prefix, vu.Config.ConfigName, version.String(vu.Fork), slot, root)
|
||||
return fmt.Sprintf("%s_%s_%s_%d-%#x.ssz", prefix, vu.Config.ConfigName, vu.Fork.String(), slot, root)
|
||||
}
|
||||
|
||||
// DownloadFinalizedData downloads the most recently finalized state, and the block most recently applied to that state.
|
||||
@@ -70,7 +69,7 @@ func DownloadFinalizedData(ctx context.Context, client *Client) (*OriginData, er
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error detecting chain config for finalized state")
|
||||
}
|
||||
log.Printf("detected supported config in remote finalized state, name=%s, fork=%s", vu.Config.ConfigName, version.String(vu.Fork))
|
||||
log.Printf("detected supported config in remote finalized state, name=%s, fork=%s", vu.Config.ConfigName, vu.Fork.String())
|
||||
s, err := vu.UnmarshalBeaconState(sb)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error unmarshaling finalized state to correct version")
|
||||
@@ -194,7 +193,7 @@ func computeBackwardsCompatible(ctx context.Context, client *Client) (*WeakSubje
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error detecting chain config for beacon state")
|
||||
}
|
||||
log.Printf("detected supported config in checkpoint state, name=%s, fork=%s", vu.Config.ConfigName, version.String(vu.Fork))
|
||||
log.Printf("detected supported config in checkpoint state, name=%s, fork=%s", vu.Config.ConfigName, vu.Fork.String())
|
||||
|
||||
s, err := vu.UnmarshalBeaconState(sb)
|
||||
if err != nil {
|
||||
@@ -245,7 +244,7 @@ func getWeakSubjectivityEpochFromHead(ctx context.Context, client *Client) (type
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "error detecting chain config for beacon state")
|
||||
}
|
||||
log.Printf("detected supported config in remote head state, name=%s, fork=%s", vu.Config.ConfigName, version.String(vu.Fork))
|
||||
log.Printf("detected supported config in remote head state, name=%s, fork=%s", vu.Config.ConfigName, vu.Fork.String())
|
||||
headState, err := vu.UnmarshalBeaconState(headBytes)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "error unmarshaling state to correct version")
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.opencensus.io/trace"
|
||||
@@ -141,7 +142,7 @@ func (s *Service) getPayloadHash(ctx context.Context, root []byte) ([32]byte, er
|
||||
if err != nil {
|
||||
return [32]byte{}, err
|
||||
}
|
||||
if blocks.IsPreBellatrixVersion(blk.Block().Version()) {
|
||||
if blk.Block().Version().IsPreBellatrix() {
|
||||
return params.BeaconConfig().ZeroHash, nil
|
||||
}
|
||||
payload, err := blk.Block().Body().ExecutionPayload()
|
||||
@@ -153,14 +154,14 @@ func (s *Service) getPayloadHash(ctx context.Context, root []byte) ([32]byte, er
|
||||
|
||||
// notifyForkchoiceUpdate signals execution engine on a new payload.
|
||||
// It returns true if the EL has returned VALID for the block
|
||||
func (s *Service) notifyNewPayload(ctx context.Context, postStateVersion int,
|
||||
func (s *Service) notifyNewPayload(ctx context.Context, postStateVersion version.ForkVersion,
|
||||
postStateHeader *ethpb.ExecutionPayloadHeader, blk interfaces.SignedBeaconBlock) (bool, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "blockChain.notifyNewPayload")
|
||||
defer span.End()
|
||||
|
||||
// Execution payload is only supported in Bellatrix and beyond. Pre
|
||||
// merge blocks are never optimistic
|
||||
if blocks.IsPreBellatrixVersion(postStateVersion) {
|
||||
if postStateVersion.IsPreBellatrix() {
|
||||
return true, nil
|
||||
}
|
||||
if err := wrapper.BeaconBlockIsNil(blk); err != nil {
|
||||
|
||||
@@ -67,7 +67,7 @@ func logBlockSyncStatus(block interfaces.BeaconBlock, blockRoot [32]byte, justif
|
||||
log = log.WithField("justifiedEpoch", justified.Epoch)
|
||||
log = log.WithField("justifiedRoot", fmt.Sprintf("0x%s...", hex.EncodeToString(justified.Root)[:8]))
|
||||
log = log.WithField("parentRoot", fmt.Sprintf("0x%s...", hex.EncodeToString(block.ParentRoot())[:8]))
|
||||
log = log.WithField("version", version.String(block.Version()))
|
||||
log = log.WithField("version", block.Version().String())
|
||||
log = log.WithField("sinceSlotStartTime", prysmTime.Now().Sub(startTime))
|
||||
log = log.WithField("chainServiceProcessedTime", prysmTime.Now().Sub(receivedTime))
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -266,8 +265,8 @@ func reportEpochMetrics(ctx context.Context, postState, headState state.BeaconSt
|
||||
var b *precompute.Balance
|
||||
var v []*precompute.Validator
|
||||
var err error
|
||||
switch headState.Version() {
|
||||
case version.Phase0:
|
||||
switch {
|
||||
case headState.Version().IsPhase0Compatible():
|
||||
// Validator participation should be viewed on the canonical chain.
|
||||
v, b, err = precompute.New(ctx, headState)
|
||||
if err != nil {
|
||||
@@ -277,7 +276,7 @@ func reportEpochMetrics(ctx context.Context, postState, headState state.BeaconSt
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case version.Altair, version.Bellatrix:
|
||||
case headState.Version().IsParticipationBitsCompatible():
|
||||
v, b, err = altair.InitializePrecomputeValidators(ctx, headState)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -317,15 +317,15 @@ func (s *Service) onBlock(ctx context.Context, signed interfaces.SignedBeaconBlo
|
||||
return s.handleEpochBoundary(ctx, postState)
|
||||
}
|
||||
|
||||
func getStateVersionAndPayload(st state.BeaconState) (int, *ethpb.ExecutionPayloadHeader, error) {
|
||||
func getStateVersionAndPayload(st state.BeaconState) (version.ForkVersion, *ethpb.ExecutionPayloadHeader, error) {
|
||||
if st == nil {
|
||||
return 0, nil, errors.New("nil state")
|
||||
}
|
||||
var preStateHeader *ethpb.ExecutionPayloadHeader
|
||||
var err error
|
||||
preStateVersion := st.Version()
|
||||
switch preStateVersion {
|
||||
case version.Phase0, version.Altair:
|
||||
switch {
|
||||
case preStateVersion.IsPreBellatrix():
|
||||
default:
|
||||
preStateHeader, err = st.LatestExecutionPayloadHeader()
|
||||
if err != nil {
|
||||
@@ -378,7 +378,7 @@ func (s *Service) onBlockBatch(ctx context.Context, blks []interfaces.SignedBeac
|
||||
Messages: [][32]byte{},
|
||||
}
|
||||
type versionAndHeader struct {
|
||||
version int
|
||||
version version.ForkVersion
|
||||
header *ethpb.ExecutionPayloadHeader
|
||||
}
|
||||
preVersionAndHeaders := make([]*versionAndHeader, len(blks))
|
||||
@@ -684,9 +684,9 @@ func (s *Service) pruneCanonicalAttsFromPool(ctx context.Context, r [32]byte, b
|
||||
}
|
||||
|
||||
// validateMergeTransitionBlock validates the merge transition block.
|
||||
func (s *Service) validateMergeTransitionBlock(ctx context.Context, stateVersion int, stateHeader *ethpb.ExecutionPayloadHeader, blk interfaces.SignedBeaconBlock) error {
|
||||
func (s *Service) validateMergeTransitionBlock(ctx context.Context, stateVersion version.ForkVersion, stateHeader *ethpb.ExecutionPayloadHeader, blk interfaces.SignedBeaconBlock) error {
|
||||
// Skip validation if block is older than Bellatrix.
|
||||
if blocks.IsPreBellatrixVersion(blk.Block().Version()) {
|
||||
if blk.Block().Version().IsPreBellatrix() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -701,7 +701,7 @@ func (s *Service) validateMergeTransitionBlock(ctx context.Context, stateVersion
|
||||
|
||||
// Handle case where pre-state is Altair but block contains payload.
|
||||
// To reach here, the block must have contained a valid payload.
|
||||
if blocks.IsPreBellatrixVersion(stateVersion) {
|
||||
if stateVersion.IsPreBellatrix() {
|
||||
return s.validateMergeBlock(ctx, blk)
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ func (c *SyncCommitteeHeadStateCache) Put(slot types.Slot, st state.BeaconState)
|
||||
return ErrNilValueProvided
|
||||
}
|
||||
|
||||
if st.Version() == version.Phase0 {
|
||||
if st.Version().IsPhase0Compatible() {
|
||||
return ErrIncorrectType
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/attestation"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/slashings"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
)
|
||||
|
||||
@@ -79,11 +78,11 @@ func ProcessAttesterSlashing(
|
||||
cfg := params.BeaconConfig()
|
||||
var slashingQuotient uint64
|
||||
switch {
|
||||
case beaconState.Version() == version.Phase0:
|
||||
case beaconState.Version().IsPhase0Compatible():
|
||||
slashingQuotient = cfg.MinSlashingPenaltyQuotient
|
||||
case beaconState.Version() == version.Altair:
|
||||
case beaconState.Version().IsAltairCompatible():
|
||||
slashingQuotient = cfg.MinSlashingPenaltyQuotientAltair
|
||||
case beaconState.Version() == version.Bellatrix:
|
||||
case beaconState.Version().IsBellatrixCompatible():
|
||||
slashingQuotient = cfg.MinSlashingPenaltyQuotientBellatrix
|
||||
default:
|
||||
return nil, errors.New("unknown state version")
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
)
|
||||
|
||||
@@ -33,7 +32,7 @@ func IsMergeTransitionComplete(st state.BeaconState) (bool, error) {
|
||||
if st == nil {
|
||||
return false, errors.New("nil state")
|
||||
}
|
||||
if IsPreBellatrixVersion(st.Version()) {
|
||||
if st.Version().IsPreBellatrix() {
|
||||
return false, nil
|
||||
}
|
||||
h, err := st.LatestExecutionPayloadHeader()
|
||||
@@ -86,7 +85,7 @@ func IsExecutionEnabled(st state.BeaconState, body interfaces.BeaconBlockBody) (
|
||||
if st == nil || body == nil {
|
||||
return false, errors.New("nil state or block body")
|
||||
}
|
||||
if IsPreBellatrixVersion(st.Version()) {
|
||||
if st.Version().IsPreBellatrix() {
|
||||
return false, nil
|
||||
}
|
||||
header, err := st.LatestExecutionPayloadHeader()
|
||||
@@ -105,11 +104,6 @@ func IsExecutionEnabledUsingHeader(header *ethpb.ExecutionPayloadHeader, body in
|
||||
return IsExecutionBlock(body)
|
||||
}
|
||||
|
||||
// IsPreBellatrixVersion returns true if input version is before bellatrix fork.
|
||||
func IsPreBellatrixVersion(v int) bool {
|
||||
return v < version.Bellatrix
|
||||
}
|
||||
|
||||
// ValidatePayloadWhenMergeCompletes validates if payload is valid versus input beacon state.
|
||||
// These validation steps ONLY apply to post merge.
|
||||
//
|
||||
@@ -276,7 +270,7 @@ func ProcessPayloadHeader(st state.BeaconState, header *ethpb.ExecutionPayloadHe
|
||||
// GetBlockPayloadHash returns the hash of the execution payload of the block
|
||||
func GetBlockPayloadHash(blk interfaces.BeaconBlock) ([32]byte, error) {
|
||||
payloadHash := [32]byte{}
|
||||
if IsPreBellatrixVersion(blk.Version()) {
|
||||
if blk.Version().IsPreBellatrix() {
|
||||
return payloadHash, nil
|
||||
}
|
||||
payload, err := blk.Body().ExecutionPayload()
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@@ -77,11 +76,11 @@ func ProcessProposerSlashing(
|
||||
cfg := params.BeaconConfig()
|
||||
var slashingQuotient uint64
|
||||
switch {
|
||||
case beaconState.Version() == version.Phase0:
|
||||
case beaconState.Version().IsPhase0Compatible():
|
||||
slashingQuotient = cfg.MinSlashingPenaltyQuotient
|
||||
case beaconState.Version() == version.Altair:
|
||||
case beaconState.Version().IsAltairCompatible():
|
||||
slashingQuotient = cfg.MinSlashingPenaltyQuotientAltair
|
||||
case beaconState.Version() == version.Bellatrix:
|
||||
case beaconState.Version().IsBellatrixCompatible():
|
||||
slashingQuotient = cfg.MinSlashingPenaltyQuotientBellatrix
|
||||
default:
|
||||
return nil, errors.New("unknown state version")
|
||||
|
||||
@@ -171,7 +171,7 @@ func UpdateValidator(vp []*Validator, record *Validator, indices []uint64, a *et
|
||||
}
|
||||
|
||||
// UpdateBalance updates pre computed balance store.
|
||||
func UpdateBalance(vp []*Validator, bBal *Balance, stateVersion int) *Balance {
|
||||
func UpdateBalance(vp []*Validator, bBal *Balance, stateVersion version.ForkVersion) *Balance {
|
||||
for _, v := range vp {
|
||||
if !v.IsSlashed {
|
||||
if v.IsCurrentEpochAttester {
|
||||
@@ -180,10 +180,10 @@ func UpdateBalance(vp []*Validator, bBal *Balance, stateVersion int) *Balance {
|
||||
if v.IsCurrentEpochTargetAttester {
|
||||
bBal.CurrentEpochTargetAttested += v.CurrentEpochEffectiveBalance
|
||||
}
|
||||
if stateVersion == version.Phase0 && v.IsPrevEpochAttester {
|
||||
if stateVersion.IsPhase0Compatible() && v.IsPrevEpochAttester {
|
||||
bBal.PrevEpochAttested += v.CurrentEpochEffectiveBalance
|
||||
}
|
||||
if (stateVersion == version.Altair || stateVersion == version.Bellatrix) && v.IsPrevEpochSourceAttester {
|
||||
if stateVersion.IsHigherOrEqualToAltair() && v.IsPrevEpochSourceAttester {
|
||||
bBal.PrevEpochAttested += v.CurrentEpochEffectiveBalance
|
||||
}
|
||||
if v.IsPrevEpochTargetAttester {
|
||||
|
||||
@@ -9,7 +9,6 @@ go_library(
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
"//runtime/version:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
)
|
||||
|
||||
@@ -48,7 +47,7 @@ func NextEpoch(state state.ReadOnlyBeaconState) types.Epoch {
|
||||
|
||||
// HigherEqualThanAltairVersionAndEpoch returns if the input state `s` has a higher version number than Altair state and input epoch `e` is higher equal than fork epoch.
|
||||
func HigherEqualThanAltairVersionAndEpoch(s state.BeaconState, e types.Epoch) bool {
|
||||
return s.Version() >= version.Altair && e >= params.BeaconConfig().AltairForkEpoch
|
||||
return s.Version().IsHigherOrEqualToAltair() && e >= params.BeaconConfig().AltairForkEpoch
|
||||
}
|
||||
|
||||
// CanUpgradeToAltair returns true if the input `slot` can upgrade to Altair.
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/consensus-types/wrapper"
|
||||
"github.com/prysmaticlabs/prysm/math"
|
||||
"github.com/prysmaticlabs/prysm/monitoring/tracing"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
@@ -248,14 +247,14 @@ func ProcessSlots(ctx context.Context, state state.BeaconState, slot types.Slot)
|
||||
return nil, errors.Wrap(err, "could not process slot")
|
||||
}
|
||||
if time.CanProcessEpoch(state) {
|
||||
switch state.Version() {
|
||||
case version.Phase0:
|
||||
switch {
|
||||
case state.Version().IsPhase0Compatible():
|
||||
state, err = ProcessEpochPrecompute(ctx, state)
|
||||
if err != nil {
|
||||
tracing.AnnotateError(span, err)
|
||||
return nil, errors.Wrap(err, "could not process epoch with optimizations")
|
||||
}
|
||||
case version.Altair, version.Bellatrix:
|
||||
case state.Version().IsHigherOrEqualToAltair():
|
||||
state, err = altair.ProcessEpoch(ctx, state)
|
||||
if err != nil {
|
||||
tracing.AnnotateError(span, err)
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/consensus-types/wrapper"
|
||||
"github.com/prysmaticlabs/prysm/crypto/bls"
|
||||
"github.com/prysmaticlabs/prysm/monitoring/tracing"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
@@ -232,13 +231,13 @@ func ProcessOperationsNoVerifyAttsSigs(
|
||||
}
|
||||
|
||||
var err error
|
||||
switch signedBeaconBlock.Version() {
|
||||
case version.Phase0:
|
||||
switch {
|
||||
case signedBeaconBlock.Version().IsPhase0Compatible():
|
||||
state, err = phase0Operations(ctx, state, signedBeaconBlock)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case version.Altair, version.Bellatrix:
|
||||
case signedBeaconBlock.Version().IsHigherOrEqualToAltair():
|
||||
state, err = altairOperations(ctx, state, signedBeaconBlock)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -329,7 +328,7 @@ func ProcessBlockForStateRoot(
|
||||
return nil, errors.Wrap(err, "could not process block operation")
|
||||
}
|
||||
|
||||
if signed.Block().Version() == version.Phase0 {
|
||||
if signed.Block().Version().IsPhase0Compatible() {
|
||||
return state, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/container/slice"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
"go.opencensus.io/trace"
|
||||
@@ -794,14 +793,14 @@ func marshalBlock(_ context.Context, blk interfaces.SignedBeaconBlock) ([]byte,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch blk.Version() {
|
||||
case version.BellatrixBlind:
|
||||
switch {
|
||||
case blk.Version().IsBlindedBlockCompatible():
|
||||
return snappy.Encode(nil, append(bellatrixBlindKey, obj...)), nil
|
||||
case version.Bellatrix:
|
||||
case blk.Version().IsBellatrixCompatible():
|
||||
return snappy.Encode(nil, append(bellatrixKey, obj...)), nil
|
||||
case version.Altair:
|
||||
case blk.Version().IsAltairCompatible():
|
||||
return snappy.Encode(nil, append(altairKey, obj...)), nil
|
||||
case version.Phase0:
|
||||
case blk.Version().IsPhase0Compatible():
|
||||
return snappy.Encode(nil, obj), nil
|
||||
default:
|
||||
return nil, errors.New("Unknown block version")
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/encoding/ssz/detect"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
)
|
||||
|
||||
// SaveOrigin loads an ssz serialized Block & BeaconState from an io.Reader
|
||||
@@ -38,7 +37,7 @@ func (s *Store) SaveOrigin(ctx context.Context, serState, serBlock []byte) error
|
||||
return fmt.Errorf("config mismatch, beacon node configured to connect to %s, detected state is for %s", params.BeaconConfig().ConfigName, cf.Config.ConfigName)
|
||||
}
|
||||
|
||||
log.Infof("detected supported config for state & block version, config name=%s, fork name=%s", cf.Config.ConfigName, version.String(cf.Fork))
|
||||
log.Infof("detected supported config for state & block version, config name=%s, fork name=%s", cf.Config.ConfigName, cf.Fork.String())
|
||||
state, err := cf.UnmarshalBeaconState(serState)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to initialize origin state w/ bytes + config+fork")
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
ethpbv1 "github.com/prysmaticlabs/prysm/proto/eth/v1"
|
||||
ethpbv2 "github.com/prysmaticlabs/prysm/proto/eth/v2"
|
||||
"github.com/prysmaticlabs/prysm/proto/migration"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
"go.opencensus.io/trace"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -24,7 +23,7 @@ func (ds *Server) GetBeaconState(ctx context.Context, req *ethpbv1.StateRequest)
|
||||
return nil, helpers.PrepareStateFetchGRPCError(err)
|
||||
}
|
||||
|
||||
if beaconSt.Version() != version.Phase0 {
|
||||
if beaconSt.Version().IsHigherOrEqualToAltair() {
|
||||
return nil, status.Error(codes.Internal, "State has incorrect type")
|
||||
}
|
||||
protoSt, err := migration.BeaconStateToProto(beaconSt)
|
||||
@@ -69,8 +68,8 @@ func (ds *Server) GetBeaconStateV2(ctx context.Context, req *ethpbv2.StateReques
|
||||
return nil, status.Errorf(codes.Internal, "Could not check if slot's block is optimistic: %v", err)
|
||||
}
|
||||
|
||||
switch beaconSt.Version() {
|
||||
case version.Phase0:
|
||||
switch {
|
||||
case beaconSt.Version().IsAltairCompatible():
|
||||
protoSt, err := migration.BeaconStateToProto(beaconSt)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not convert state to proto: %v", err)
|
||||
@@ -82,7 +81,7 @@ func (ds *Server) GetBeaconStateV2(ctx context.Context, req *ethpbv2.StateReques
|
||||
},
|
||||
ExecutionOptimistic: isOptimistic,
|
||||
}, nil
|
||||
case version.Altair:
|
||||
case beaconSt.Version().IsAltairCompatible():
|
||||
protoState, err := migration.BeaconStateAltairToProto(beaconSt)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not convert state to proto: %v", err)
|
||||
@@ -94,7 +93,7 @@ func (ds *Server) GetBeaconStateV2(ctx context.Context, req *ethpbv2.StateReques
|
||||
},
|
||||
ExecutionOptimistic: isOptimistic,
|
||||
}, nil
|
||||
case version.Bellatrix:
|
||||
case beaconSt.Version().IsBellatrixCompatible():
|
||||
protoState, err := migration.BeaconStateBellatrixToProto(beaconSt)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not convert state to proto: %v", err)
|
||||
@@ -126,12 +125,12 @@ func (ds *Server) GetBeaconStateSSZV2(ctx context.Context, req *ethpbv2.StateReq
|
||||
return nil, status.Errorf(codes.Internal, "Could not marshal state into SSZ: %v", err)
|
||||
}
|
||||
var ver ethpbv2.Version
|
||||
switch st.Version() {
|
||||
case version.Phase0:
|
||||
switch {
|
||||
case st.Version().IsPhase0Compatible():
|
||||
ver = ethpbv2.Version_PHASE0
|
||||
case version.Altair:
|
||||
case st.Version().IsAltairCompatible():
|
||||
ver = ethpbv2.Version_ALTAIR
|
||||
case version.Bellatrix:
|
||||
case st.Version().IsBellatrixCompatible():
|
||||
ver = ethpbv2.Version_BELLATRIX
|
||||
default:
|
||||
return nil, status.Error(codes.Internal, "Unsupported state version")
|
||||
|
||||
@@ -13,6 +13,7 @@ go_library(
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//runtime/version:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
)
|
||||
|
||||
// BeaconState has read and write access to beacon state methods.
|
||||
@@ -59,7 +60,7 @@ type ReadOnlyBeaconState interface {
|
||||
FieldReferencesCount() map[string]uint64
|
||||
MarshalSSZ() ([]byte, error)
|
||||
IsNil() bool
|
||||
Version() int
|
||||
Version() version.ForkVersion
|
||||
LatestExecutionPayloadHeader() (*ethpb.ExecutionPayloadHeader, error)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,13 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
eth2types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
)
|
||||
|
||||
// BeaconState defines a struct containing utilities for the Ethereum Beacon Chain state, defining
|
||||
// getters and setters for its respective values and helpful functions such as HashTreeRoot().
|
||||
type BeaconState struct {
|
||||
version int
|
||||
version version.ForkVersion
|
||||
genesisTime uint64 `ssz-gen:"true"`
|
||||
genesisValidatorsRoot customtypes.Byte32 `ssz-gen:"true" ssz-size:"32"`
|
||||
slot eth2types.Slot `ssz-gen:"true"`
|
||||
|
||||
@@ -13,12 +13,13 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
eth2types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
)
|
||||
|
||||
// BeaconState defines a struct containing utilities for the Ethereum Beacon Chain state, defining
|
||||
// getters and setters for its respective values and helpful functions such as HashTreeRoot().
|
||||
type BeaconState struct {
|
||||
version int
|
||||
version version.ForkVersion
|
||||
genesisTime uint64 `ssz-gen:"true"`
|
||||
genesisValidatorsRoot customtypes.Byte32 `ssz-gen:"true" ssz-size:"32"`
|
||||
slot eth2types.Slot `ssz-gen:"true"`
|
||||
|
||||
@@ -2,12 +2,11 @@ package state_native
|
||||
|
||||
import (
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
)
|
||||
|
||||
// PreviousEpochAttestations corresponding to blocks on the beacon chain.
|
||||
func (b *BeaconState) PreviousEpochAttestations() ([]*ethpb.PendingAttestation, error) {
|
||||
if b.version != version.Phase0 {
|
||||
if !b.version.IsPhase0Compatible() {
|
||||
return nil, errNotSupported("PreviousEpochAttestations", b.version)
|
||||
}
|
||||
|
||||
@@ -29,7 +28,7 @@ func (b *BeaconState) previousEpochAttestationsVal() []*ethpb.PendingAttestation
|
||||
|
||||
// CurrentEpochAttestations corresponding to blocks on the beacon chain.
|
||||
func (b *BeaconState) CurrentEpochAttestations() ([]*ethpb.PendingAttestation, error) {
|
||||
if b.version != version.Phase0 {
|
||||
if !b.version.IsPhase0Compatible() {
|
||||
return nil, errNotSupported("CurrentEpochAttestations", b.version)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package state_native
|
||||
import (
|
||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
)
|
||||
|
||||
// GenesisTime of the beacon state as a uint64.
|
||||
@@ -24,7 +25,7 @@ func (b *BeaconState) GenesisValidatorsRoot() []byte {
|
||||
// Version of the beacon state. This method
|
||||
// is strictly meant to be used without a lock
|
||||
// internally.
|
||||
func (b *BeaconState) Version() int {
|
||||
func (b *BeaconState) Version() version.ForkVersion {
|
||||
return b.version
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,11 @@ package state_native
|
||||
import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/time"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
)
|
||||
|
||||
// CurrentEpochParticipation corresponding to participation bits on the beacon chain.
|
||||
func (b *BeaconState) CurrentEpochParticipation() ([]byte, error) {
|
||||
if b.version == version.Phase0 {
|
||||
if !b.version.IsParticipationBitsCompatible() {
|
||||
return nil, errNotSupported("CurrentEpochParticipation", b.version)
|
||||
}
|
||||
|
||||
@@ -24,7 +23,7 @@ func (b *BeaconState) CurrentEpochParticipation() ([]byte, error) {
|
||||
|
||||
// PreviousEpochParticipation corresponding to participation bits on the beacon chain.
|
||||
func (b *BeaconState) PreviousEpochParticipation() ([]byte, error) {
|
||||
if b.version == version.Phase0 {
|
||||
if !b.version.IsParticipationBitsCompatible() {
|
||||
return nil, errNotSupported("PreviousEpochParticipation", b.version)
|
||||
}
|
||||
|
||||
@@ -42,7 +41,7 @@ func (b *BeaconState) PreviousEpochParticipation() ([]byte, error) {
|
||||
// current epoch and target attested in previous epoch. This function is used to
|
||||
// compute the "unrealized justification" that a synced Beacon Block will have.
|
||||
func (b *BeaconState) UnrealizedCheckpointBalances() (uint64, uint64, uint64, error) {
|
||||
if b.version == version.Phase0 {
|
||||
if !b.version.IsParticipationBitsCompatible() {
|
||||
return 0, 0, 0, errNotSupported("UnrealizedCheckpointBalances", b.version)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,11 @@ package state_native
|
||||
|
||||
import (
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
)
|
||||
|
||||
// LatestExecutionPayloadHeader of the beacon state.
|
||||
func (b *BeaconState) LatestExecutionPayloadHeader() (*ethpb.ExecutionPayloadHeader, error) {
|
||||
if b.version == version.Phase0 || b.version == version.Altair {
|
||||
if !b.version.IsExecutionPayloadCompatible() {
|
||||
return nil, errNotSupported("LatestExecutionPayloadHeader", b.version)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ func (b *BeaconState) ToProtoUnsafe() interface{} {
|
||||
|
||||
gvrCopy := b.genesisValidatorsRoot
|
||||
|
||||
switch b.version {
|
||||
case version.Phase0:
|
||||
switch {
|
||||
case b.version.IsPhase0Compatible():
|
||||
return ðpb.BeaconState{
|
||||
GenesisTime: b.genesisTime,
|
||||
GenesisValidatorsRoot: gvrCopy[:],
|
||||
@@ -42,7 +42,7 @@ func (b *BeaconState) ToProtoUnsafe() interface{} {
|
||||
CurrentJustifiedCheckpoint: b.currentJustifiedCheckpoint,
|
||||
FinalizedCheckpoint: b.finalizedCheckpoint,
|
||||
}
|
||||
case version.Altair:
|
||||
case b.version.IsAltairCompatible():
|
||||
return ðpb.BeaconStateAltair{
|
||||
GenesisTime: b.genesisTime,
|
||||
GenesisValidatorsRoot: gvrCopy[:],
|
||||
@@ -69,7 +69,7 @@ func (b *BeaconState) ToProtoUnsafe() interface{} {
|
||||
CurrentSyncCommittee: b.currentSyncCommittee,
|
||||
NextSyncCommittee: b.nextSyncCommittee,
|
||||
}
|
||||
case version.Bellatrix:
|
||||
case b.version.IsBellatrixCompatible():
|
||||
return ðpb.BeaconStateBellatrix{
|
||||
GenesisTime: b.genesisTime,
|
||||
GenesisValidatorsRoot: gvrCopy[:],
|
||||
|
||||
@@ -31,6 +31,6 @@ func init() {
|
||||
// to its corresponding data type.
|
||||
var fieldMap map[nativetypes.FieldIndex]types.DataType
|
||||
|
||||
func errNotSupported(funcName string, ver int) error {
|
||||
return fmt.Errorf("%s is not supported for %s", funcName, version.String(ver))
|
||||
func errNotSupported(funcName string, ver version.ForkVersion) error {
|
||||
return fmt.Errorf("%s is not supported for %s", funcName, ver.String())
|
||||
}
|
||||
|
||||
@@ -5,5 +5,8 @@ go_library(
|
||||
srcs = ["types.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/state/state-native/types",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@com_github_pkg_errors//:go_default_library"],
|
||||
deps = [
|
||||
"//runtime/version:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@ package types
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
)
|
||||
|
||||
// FieldIndex represents the relevant field position in the
|
||||
@@ -9,7 +10,7 @@ import (
|
||||
type FieldIndex int
|
||||
|
||||
// String returns the name of the field index.
|
||||
func (f FieldIndex) String(_ int) string {
|
||||
func (f FieldIndex) String(_ version.ForkVersion) string {
|
||||
switch f {
|
||||
case GenesisTime:
|
||||
return "genesisTime"
|
||||
|
||||
@@ -211,7 +211,7 @@ func ReplayProcessSlots(ctx context.Context, state state.BeaconState, slot types
|
||||
return nil, errors.Wrap(err, "could not process epoch")
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported beacon state version: %s", version.String(state.Version()))
|
||||
return nil, fmt.Errorf("unsupported beacon state version: %s", state.Version().String())
|
||||
}
|
||||
}
|
||||
if err := state.SetSlot(state.Slot() + 1); err != nil {
|
||||
|
||||
@@ -27,14 +27,14 @@ const (
|
||||
|
||||
// BeaconStateField represents a field of the beacon state.
|
||||
type BeaconStateField interface {
|
||||
String(stateVersion int) string
|
||||
String(stateVersion version.ForkVersion) string
|
||||
RealPosition() int
|
||||
ElemsInChunk() (uint64, error)
|
||||
Native() bool
|
||||
}
|
||||
|
||||
// String returns the name of the field index.
|
||||
func (f FieldIndex) String(stateVersion int) string {
|
||||
func (f FieldIndex) String(stateVersion version.ForkVersion) string {
|
||||
switch f {
|
||||
case GenesisTime:
|
||||
return "genesisTime"
|
||||
@@ -67,12 +67,12 @@ func (f FieldIndex) String(stateVersion int) string {
|
||||
case Slashings:
|
||||
return "slashings"
|
||||
case PreviousEpochAttestations:
|
||||
if version.Altair == stateVersion || version.Bellatrix == stateVersion {
|
||||
if stateVersion.IsParticipationBitsCompatible() {
|
||||
return "previousEpochParticipationBits"
|
||||
}
|
||||
return "previousEpochAttestations"
|
||||
case CurrentEpochAttestations:
|
||||
if version.Altair == stateVersion || version.Bellatrix == stateVersion {
|
||||
if stateVersion.IsParticipationBitsCompatible() {
|
||||
return "currentEpochParticipationBits"
|
||||
}
|
||||
return "currentEpochAttestations"
|
||||
|
||||
@@ -63,7 +63,7 @@ func (b *BeaconState) genesisValidatorsRoot() []byte {
|
||||
// Version of the beacon state. This method
|
||||
// is strictly meant to be used without a lock
|
||||
// internally.
|
||||
func (_ *BeaconState) Version() int {
|
||||
func (_ *BeaconState) Version() version.ForkVersion {
|
||||
return version.Phase0
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ func (b *BeaconState) genesisValidatorsRoot() []byte {
|
||||
// Version of the beacon state. This method
|
||||
// is strictly meant to be used without a lock
|
||||
// internally.
|
||||
func (_ *BeaconState) Version() int {
|
||||
func (_ *BeaconState) Version() version.ForkVersion {
|
||||
return version.Altair
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ func (b *BeaconState) genesisValidatorsRoot() []byte {
|
||||
// Version of the beacon state. This method
|
||||
// is strictly meant to be used without a lock
|
||||
// internally.
|
||||
func (_ *BeaconState) Version() int {
|
||||
func (_ *BeaconState) Version() version.ForkVersion {
|
||||
return version.Bellatrix
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ package bellatrix
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
field_params "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/encoding/ssz"
|
||||
"github.com/prysmaticlabs/prysm/proto/engine/v1"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
|
||||
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
// PayloadToHeader converts `payload` into execution payload header format.
|
||||
|
||||
@@ -13,6 +13,7 @@ go_library(
|
||||
"//proto/engine/v1:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//proto/prysm/v1alpha1/validator-client:go_default_library",
|
||||
"//runtime/version:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@org_golang_google_protobuf//proto:go_default_library",
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
validatorpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -24,7 +25,7 @@ type SignedBeaconBlock interface {
|
||||
PbBlindedBellatrixBlock() (*ethpb.SignedBlindedBeaconBlockBellatrix, error)
|
||||
ssz.Marshaler
|
||||
ssz.Unmarshaler
|
||||
Version() int
|
||||
Version() version.ForkVersion
|
||||
Header() (*ethpb.SignedBeaconBlockHeader, error)
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ type BeaconBlock interface {
|
||||
ssz.Marshaler
|
||||
ssz.Unmarshaler
|
||||
ssz.HashRoot
|
||||
Version() int
|
||||
Version() version.ForkVersion
|
||||
AsSignRequestObject() validatorpb.SignRequestObject
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ func (altairSignedBeaconBlock) PbBlindedBellatrixBlock() (*eth.SignedBlindedBeac
|
||||
}
|
||||
|
||||
// Version of the underlying protobuf object.
|
||||
func (altairSignedBeaconBlock) Version() int {
|
||||
func (altairSignedBeaconBlock) Version() version.ForkVersion {
|
||||
return version.Altair
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ func (w altairBeaconBlock) Proto() proto.Message {
|
||||
}
|
||||
|
||||
// Version of the underlying protobuf object.
|
||||
func (altairBeaconBlock) Version() int {
|
||||
func (altairBeaconBlock) Version() version.ForkVersion {
|
||||
return version.Altair
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ func (bellatrixSignedBeaconBlock) PbAltairBlock() (*eth.SignedBeaconBlockAltair,
|
||||
}
|
||||
|
||||
// Version of the underlying protobuf object.
|
||||
func (bellatrixSignedBeaconBlock) Version() int {
|
||||
func (bellatrixSignedBeaconBlock) Version() version.ForkVersion {
|
||||
return version.Bellatrix
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ func (w bellatrixBeaconBlock) Proto() proto.Message {
|
||||
}
|
||||
|
||||
// Version of the underlying protobuf object.
|
||||
func (bellatrixBeaconBlock) Version() int {
|
||||
func (bellatrixBeaconBlock) Version() version.ForkVersion {
|
||||
return version.Bellatrix
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ func (Phase0SignedBeaconBlock) PbBlindedBellatrixBlock() (*eth.SignedBlindedBeac
|
||||
}
|
||||
|
||||
// Version of the underlying protobuf object.
|
||||
func (Phase0SignedBeaconBlock) Version() int {
|
||||
func (Phase0SignedBeaconBlock) Version() version.ForkVersion {
|
||||
return version.Phase0
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ func (w Phase0BeaconBlock) Proto() proto.Message {
|
||||
}
|
||||
|
||||
// Version of the underlying protobuf object.
|
||||
func (Phase0BeaconBlock) Version() int {
|
||||
func (Phase0BeaconBlock) Version() version.ForkVersion {
|
||||
return version.Phase0
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ func (signedBlindedBeaconBlockBellatrix) PbAltairBlock() (*eth.SignedBeaconBlock
|
||||
}
|
||||
|
||||
// Version of the underlying protobuf object.
|
||||
func (signedBlindedBeaconBlockBellatrix) Version() int {
|
||||
func (signedBlindedBeaconBlockBellatrix) Version() version.ForkVersion {
|
||||
return version.BellatrixBlind
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ func (w blindedBeaconBlockBellatrix) Proto() proto.Message {
|
||||
}
|
||||
|
||||
// Version of the underlying protobuf object.
|
||||
func (blindedBeaconBlockBellatrix) Version() int {
|
||||
func (blindedBeaconBlockBellatrix) Version() version.ForkVersion {
|
||||
return version.BellatrixBlind
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ func (_ MetadataV0) MetadataObjV1() *pb.MetaDataV1 {
|
||||
}
|
||||
|
||||
// Version returns the fork version of the underlying object.
|
||||
func (_ MetadataV0) Version() int {
|
||||
func (_ MetadataV0) Version() version.ForkVersion {
|
||||
return version.Phase0
|
||||
}
|
||||
|
||||
@@ -154,6 +154,6 @@ func (m MetadataV1) MetadataObjV1() *pb.MetaDataV1 {
|
||||
}
|
||||
|
||||
// Version returns the fork version of the underlying object.
|
||||
func (_ MetadataV1) Version() int {
|
||||
func (_ MetadataV1) Version() version.ForkVersion {
|
||||
return version.Altair
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func (m BlockMutator) Apply(b interfaces.SignedBeaconBlock) error {
|
||||
m.Bellatrix(bb)
|
||||
return nil
|
||||
}
|
||||
msg := fmt.Sprintf("version %d = %s", b.Version(), version.String(b.Version()))
|
||||
msg := fmt.Sprintf("version %d = %s", b.Version(), b.Version().String())
|
||||
return errors.Wrap(ErrUnsupportedSignedBeaconBlock, msg)
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
type VersionedUnmarshaler struct {
|
||||
Config *params.BeaconChainConfig
|
||||
// Fork aligns with the fork names in config/params/values.go
|
||||
Fork int
|
||||
Fork version.ForkVersion
|
||||
// Version corresponds to the Version type defined in the beacon-chain spec, aka a "fork version number":
|
||||
// https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#custom-types
|
||||
Version [fieldparams.VersionLength]byte
|
||||
@@ -60,7 +60,7 @@ func FromForkVersion(cv [fieldparams.VersionLength]byte) (*VersionedUnmarshaler,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var fork int
|
||||
var fork version.ForkVersion
|
||||
switch cv {
|
||||
case bytesutil.ToBytes4(cfg.GenesisForkVersion):
|
||||
fork = version.Phase0
|
||||
@@ -81,9 +81,10 @@ func FromForkVersion(cv [fieldparams.VersionLength]byte) (*VersionedUnmarshaler,
|
||||
// UnmarshalBeaconState uses internal knowledge in the VersionedUnmarshaler to pick the right concrete BeaconState type,
|
||||
// then Unmarshal()s the type and returns an instance of state.BeaconState if successful.
|
||||
func (cf *VersionedUnmarshaler) UnmarshalBeaconState(marshaled []byte) (s state.BeaconState, err error) {
|
||||
forkName := version.String(cf.Fork)
|
||||
switch fork := cf.Fork; fork {
|
||||
case version.Phase0:
|
||||
forkName := cf.Fork.String()
|
||||
fork := cf.Fork
|
||||
switch {
|
||||
case fork.IsPhase0Compatible():
|
||||
st := ðpb.BeaconState{}
|
||||
err = st.UnmarshalSSZ(marshaled)
|
||||
if err != nil {
|
||||
@@ -93,7 +94,7 @@ func (cf *VersionedUnmarshaler) UnmarshalBeaconState(marshaled []byte) (s state.
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to init state trie from state, detected fork=%s", forkName)
|
||||
}
|
||||
case version.Altair:
|
||||
case fork.IsAltairCompatible():
|
||||
st := ðpb.BeaconStateAltair{}
|
||||
err = st.UnmarshalSSZ(marshaled)
|
||||
if err != nil {
|
||||
@@ -103,7 +104,7 @@ func (cf *VersionedUnmarshaler) UnmarshalBeaconState(marshaled []byte) (s state.
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to init state trie from state, detected fork=%s", forkName)
|
||||
}
|
||||
case version.Bellatrix:
|
||||
case fork.IsBellatrixCompatible():
|
||||
st := ðpb.BeaconStateBellatrix{}
|
||||
err = st.UnmarshalSSZ(marshaled)
|
||||
if err != nil {
|
||||
@@ -158,7 +159,7 @@ func (cf *VersionedUnmarshaler) UnmarshalBeaconBlock(marshaled []byte) (interfac
|
||||
case version.Bellatrix:
|
||||
blk = ðpb.SignedBeaconBlockBellatrix{}
|
||||
default:
|
||||
forkName := version.String(cf.Fork)
|
||||
forkName := cf.Fork.String()
|
||||
return nil, fmt.Errorf("unable to initialize BeaconBlock for fork version=%s at slot=%d", forkName, slot)
|
||||
}
|
||||
err = blk.UnmarshalSSZ(marshaled)
|
||||
@@ -189,7 +190,7 @@ func (cf *VersionedUnmarshaler) UnmarshalBlindedBeaconBlock(marshaled []byte) (i
|
||||
case version.Bellatrix:
|
||||
blk = ðpb.SignedBlindedBeaconBlockBellatrix{}
|
||||
default:
|
||||
forkName := version.String(cf.Fork)
|
||||
forkName := cf.Fork.String()
|
||||
return nil, fmt.Errorf("unable to initialize BeaconBlock for fork version=%s at slot=%d", forkName, slot)
|
||||
}
|
||||
err = blk.UnmarshalSSZ(marshaled)
|
||||
|
||||
@@ -7,6 +7,7 @@ go_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//runtime/version:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
],
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
ssz "github.com/ferranbt/fastssz"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||
)
|
||||
|
||||
// Metadata returns the interface of a p2p metadata type.
|
||||
@@ -17,5 +18,5 @@ type Metadata interface {
|
||||
ssz.Unmarshaler
|
||||
MetadataObjV0() *pb.MetaDataV0
|
||||
MetadataObjV1() *pb.MetaDataV1
|
||||
Version() int
|
||||
Version() version.ForkVersion
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package version
|
||||
|
||||
type ForkVersion int
|
||||
|
||||
const (
|
||||
Phase0 = iota
|
||||
Phase0 ForkVersion = iota
|
||||
Altair
|
||||
Bellatrix
|
||||
BellatrixBlind
|
||||
)
|
||||
|
||||
func String(version int) string {
|
||||
switch version {
|
||||
func (v ForkVersion) String() string {
|
||||
switch v {
|
||||
case Phase0:
|
||||
return "phase0"
|
||||
case Altair:
|
||||
@@ -21,3 +23,39 @@ func String(version int) string {
|
||||
return "unknown version"
|
||||
}
|
||||
}
|
||||
|
||||
func (v ForkVersion) IsPhase0Compatible() bool {
|
||||
return v == Phase0
|
||||
}
|
||||
|
||||
func (v ForkVersion) IsAltairCompatible() bool {
|
||||
return v == Altair
|
||||
}
|
||||
|
||||
func (v ForkVersion) IsHigherOrEqualToAltair() bool {
|
||||
return v >= Altair
|
||||
}
|
||||
|
||||
func (v ForkVersion) IsPreBellatrix() bool {
|
||||
return v < Bellatrix
|
||||
}
|
||||
|
||||
func (v ForkVersion) IsBellatrixCompatible() bool {
|
||||
return v == Bellatrix || v == BellatrixBlind
|
||||
}
|
||||
|
||||
func (v ForkVersion) IsSyncCommitteeCompatible() bool {
|
||||
return v == Altair || v == Bellatrix || v == BellatrixBlind
|
||||
}
|
||||
|
||||
func (v ForkVersion) IsParticipationBitsCompatible() bool {
|
||||
return v == Altair || v == Bellatrix || v == BellatrixBlind
|
||||
}
|
||||
|
||||
func (v ForkVersion) IsExecutionPayloadCompatible() bool {
|
||||
return v.IsBellatrixCompatible()
|
||||
}
|
||||
|
||||
func (v ForkVersion) IsBlindedBlockCompatible() bool {
|
||||
return v == BellatrixBlind
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ func (v *validator) ProposeBlock(ctx context.Context, slot types.Slot, pubKey [f
|
||||
"numAttestations": len(blk.Block().Body().Attestations()),
|
||||
"numDeposits": len(blk.Block().Body().Deposits()),
|
||||
"graffiti": string(blk.Block().Body().Graffiti()),
|
||||
"fork": version.String(blk.Block().Version()),
|
||||
"fork": blk.Block().Version().String(),
|
||||
}).Info("Submitted new block")
|
||||
|
||||
if v.emitAccountMetrics {
|
||||
|
||||
Reference in New Issue
Block a user