mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 19:51:20 +00:00
Handle head state for init sync cache state (#4800)
* Don't save nil head state * Update head * Don't update head on new att * Handle initial sync state in DB can be nil * Don't update head if it's nil * Merge branch 'master' of git+ssh://github.com/prysmaticlabs/prysm into handle-init-sync-cache-state * Merge refs/heads/master into handle-init-sync-cache-state * Update beacon-chain/blockchain/head.go
This commit is contained in:
parent
7e0d0502aa
commit
bdcd06a708
@ -6,7 +6,9 @@ import (
|
|||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||||
|
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||||
|
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||||
"go.opencensus.io/trace"
|
"go.opencensus.io/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -50,6 +52,13 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the head state is not available, just return nil.
|
||||||
|
// There's nothing to cache
|
||||||
|
_, cached := s.initSyncState[headRoot]
|
||||||
|
if !cached && !s.beaconDB.HasState(ctx, headRoot) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Get the new head block from DB.
|
// Get the new head block from DB.
|
||||||
newHead, err := s.beaconDB.Block(ctx, headRoot)
|
newHead, err := s.beaconDB.Block(ctx, headRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -59,10 +68,28 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error {
|
|||||||
return errors.New("cannot save nil head block")
|
return errors.New("cannot save nil head block")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the new head state from DB.
|
// Get the new head state from cached state or DB.
|
||||||
headState, err := s.beaconDB.State(ctx, headRoot)
|
var headState *state.BeaconState
|
||||||
if err != nil {
|
var exists bool
|
||||||
return errors.Wrap(err, "could not retrieve head state in DB")
|
if featureconfig.Get().InitSyncCacheState {
|
||||||
|
headState, exists = s.initSyncState[headRoot]
|
||||||
|
if !exists {
|
||||||
|
headState, err = s.beaconDB.State(ctx, headRoot)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "could not retrieve head state in DB")
|
||||||
|
}
|
||||||
|
if headState == nil {
|
||||||
|
return errors.New("cannot save nil head state")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
headState, err = s.beaconDB.State(ctx, headRoot)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "could not retrieve head state in DB")
|
||||||
|
}
|
||||||
|
if headState == nil {
|
||||||
|
return errors.New("cannot save nil head state")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if headState == nil {
|
if headState == nil {
|
||||||
return errors.New("cannot save nil head state")
|
return errors.New("cannot save nil head state")
|
||||||
|
Loading…
Reference in New Issue
Block a user