diff --git a/beacon-chain/blockchain/head.go b/beacon-chain/blockchain/head.go index 68f344b74ebe..7c70d0616908 100644 --- a/beacon-chain/blockchain/head.go +++ b/beacon-chain/blockchain/head.go @@ -59,7 +59,7 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error { // If the head state is not available, just return nil. // There's nothing to cache - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { if !s.stateGen.StateSummaryExists(ctx, headRoot) { return nil } @@ -81,7 +81,7 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error { // Get the new head state from cached state or DB. var newHeadState *state.BeaconState - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { newHeadState, err = s.stateGen.StateByRoot(ctx, headRoot) if err != nil { return errors.Wrap(err, "could not retrieve head state in DB") @@ -121,7 +121,7 @@ func (s *Service) saveHeadNoDB(ctx context.Context, b *ethpb.SignedBeaconBlock, var headState *state.BeaconState var err error - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { headState, err = s.stateGen.StateByRoot(ctx, r) if err != nil { return errors.Wrap(err, "could not retrieve head state in DB") diff --git a/beacon-chain/blockchain/process_attestation_helpers.go b/beacon-chain/blockchain/process_attestation_helpers.go index 80f8cd85e126..b9e9e97df600 100644 --- a/beacon-chain/blockchain/process_attestation_helpers.go +++ b/beacon-chain/blockchain/process_attestation_helpers.go @@ -32,7 +32,7 @@ func (s *Service) getAttPreState(ctx context.Context, c *ethpb.Checkpoint) (*sta } var baseState *stateTrie.BeaconState - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { if !s.stateGen.HasState(ctx, bytesutil.ToBytes32(c.Root)) { if err := s.beaconDB.SaveBlocks(ctx, s.getInitSyncBlocks()); err != nil { return nil, errors.Wrap(err, "could not save initial sync blocks") @@ -134,7 +134,7 @@ func (s *Service) verifyAttestation(ctx context.Context, baseState *stateTrie.Be // different seeds. var aState *stateTrie.BeaconState var err error - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { if !s.stateGen.HasState(ctx, bytesutil.ToBytes32(a.Data.BeaconBlockRoot)) { if err := s.beaconDB.SaveBlocks(ctx, s.getInitSyncBlocks()); err != nil { return nil, errors.Wrap(err, "could not save initial sync blocks") diff --git a/beacon-chain/blockchain/process_attestation_test.go b/beacon-chain/blockchain/process_attestation_test.go index bf0aa6f6d38c..a4b30a7369b5 100644 --- a/beacon-chain/blockchain/process_attestation_test.go +++ b/beacon-chain/blockchain/process_attestation_test.go @@ -114,7 +114,7 @@ func TestStore_OnAttestation(t *testing.T) { a: ðpb.Attestation{Data: ðpb.AttestationData{Target: ðpb.Checkpoint{Root: BlkWithOutStateRoot[:]}}}, s: &pb.BeaconState{}, wantErr: true, - wantErrString: "could not get pre state for slot 0: could not get ancestor state", + wantErrString: "pre state of target block 0 does not exist", }, { name: "process attestation doesn't match current epoch", diff --git a/beacon-chain/blockchain/process_block.go b/beacon-chain/blockchain/process_block.go index e3e75e0e9a02..8f84abaaedf1 100644 --- a/beacon-chain/blockchain/process_block.go +++ b/beacon-chain/blockchain/process_block.go @@ -92,7 +92,7 @@ func (s *Service) onBlock(ctx context.Context, signed *ethpb.SignedBeaconBlock) return nil, errors.Wrapf(err, "could not insert block %d to fork choice store", b.Slot) } - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { if err := s.stateGen.SaveState(ctx, root, postState); err != nil { return nil, errors.Wrap(err, "could not save state") } @@ -122,7 +122,7 @@ func (s *Service) onBlock(ctx context.Context, signed *ethpb.SignedBeaconBlock) return nil, errors.Wrap(err, "could not save finalized checkpoint") } - if featureconfig.Get().DisableNewStateMgmt { + if !featureconfig.Get().NewStateMgmt { startSlot := helpers.StartSlot(s.prevFinalizedCheckpt.Epoch) endSlot := helpers.StartSlot(s.finalizedCheckpt.Epoch) if endSlot > startSlot { @@ -147,7 +147,7 @@ func (s *Service) onBlock(ctx context.Context, signed *ethpb.SignedBeaconBlock) return nil, errors.Wrap(err, "could not save new justified") } - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { fRoot := bytesutil.ToBytes32(postState.FinalizedCheckpoint().Root) fBlock, err := s.beaconDB.Block(ctx, fRoot) if err != nil { @@ -233,7 +233,7 @@ func (s *Service) onBlockInitialSyncStateTransition(ctx context.Context, signed return errors.Wrapf(err, "could not insert block %d to fork choice store", b.Slot) } - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { if err := s.stateGen.SaveState(ctx, root, postState); err != nil { return errors.Wrap(err, "could not save state") } @@ -268,7 +268,7 @@ func (s *Service) onBlockInitialSyncStateTransition(ctx context.Context, signed // Update finalized check point. Prune the block cache and helper caches on every new finalized epoch. if postState.FinalizedCheckpointEpoch() > s.finalizedCheckpt.Epoch { - if featureconfig.Get().DisableNewStateMgmt { + if !featureconfig.Get().NewStateMgmt { startSlot := helpers.StartSlot(s.prevFinalizedCheckpt.Epoch) endSlot := helpers.StartSlot(s.finalizedCheckpt.Epoch) if endSlot > startSlot { @@ -301,7 +301,7 @@ func (s *Service) onBlockInitialSyncStateTransition(ctx context.Context, signed return errors.Wrap(err, "could not save new justified") } - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { fRoot := bytesutil.ToBytes32(postState.FinalizedCheckpoint().Root) fBlock, err := s.beaconDB.Block(ctx, fRoot) if err != nil { @@ -313,7 +313,7 @@ func (s *Service) onBlockInitialSyncStateTransition(ctx context.Context, signed } } - if featureconfig.Get().DisableNewStateMgmt { + if !featureconfig.Get().NewStateMgmt { numOfStates := len(s.boundaryRoots) if numOfStates > initialSyncCacheSize { if err = s.persistCachedStates(ctx, numOfStates); err != nil { @@ -338,7 +338,7 @@ func (s *Service) onBlockInitialSyncStateTransition(ctx context.Context, signed return err } - if featureconfig.Get().DisableNewStateMgmt && helpers.IsEpochStart(postState.Slot()) { + if !featureconfig.Get().NewStateMgmt && helpers.IsEpochStart(postState.Slot()) { if err := s.beaconDB.SaveState(ctx, postState, root); err != nil { return errors.Wrap(err, "could not save state") } diff --git a/beacon-chain/blockchain/process_block_helpers.go b/beacon-chain/blockchain/process_block_helpers.go index ee433ad3899f..7a793c1e3e74 100644 --- a/beacon-chain/blockchain/process_block_helpers.go +++ b/beacon-chain/blockchain/process_block_helpers.go @@ -65,7 +65,7 @@ func (s *Service) verifyBlkPreState(ctx context.Context, b *ethpb.BeaconBlock) ( ctx, span := trace.StartSpan(ctx, "chainService.verifyBlkPreState") defer span.End() - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { parentRoot := bytesutil.ToBytes32(b.ParentRoot) // Loosen the check to HasBlock because state summary gets saved in batches // during initial syncing. There's no risk given a state summary object is just a @@ -283,7 +283,7 @@ func (s *Service) updateJustified(ctx context.Context, state *stateTrie.BeaconSt s.justifiedCheckpt = cpt } - if featureconfig.Get().DisableNewStateMgmt { + if !featureconfig.Get().NewStateMgmt { justifiedRoot := bytesutil.ToBytes32(cpt.Root) justifiedState := s.initSyncState[justifiedRoot] diff --git a/beacon-chain/blockchain/process_block_test.go b/beacon-chain/blockchain/process_block_test.go index c81c6b09e506..0ac10eabc4ff 100644 --- a/beacon-chain/blockchain/process_block_test.go +++ b/beacon-chain/blockchain/process_block_test.go @@ -19,6 +19,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/bytesutil" + "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/testutil" @@ -88,7 +89,7 @@ func TestStore_OnBlock(t *testing.T) { name: "parent block root does not have a state", blk: ðpb.BeaconBlock{}, s: st.Copy(), - wantErrString: "could not reconstruct parent state", + wantErrString: "provided block root does not have block saved in the db", }, { name: "block is from the feature", @@ -300,6 +301,11 @@ func TestShouldUpdateJustified_ReturnFalse(t *testing.T) { } func TestCachedPreState_CanGetFromStateSummary(t *testing.T) { + config := &featureconfig.Flags{ + NewStateMgmt: true, + } + featureconfig.Init(config) + ctx := context.Background() db := testDB.SetupDB(t) defer testDB.TeardownDB(t, db) diff --git a/beacon-chain/blockchain/receive_attestation.go b/beacon-chain/blockchain/receive_attestation.go index 94fc60869e2c..81587c1007f4 100644 --- a/beacon-chain/blockchain/receive_attestation.go +++ b/beacon-chain/blockchain/receive_attestation.go @@ -91,7 +91,7 @@ func (s *Service) processAttestation(subscribedToStateEvents chan struct{}) { atts := s.attPool.ForkchoiceAttestations() for _, a := range atts { var hasState bool - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { hasState = s.stateGen.StateSummaryExists(ctx, bytesutil.ToBytes32(a.Data.BeaconBlockRoot)) } else { hasState = s.beaconDB.HasState(ctx, bytesutil.ToBytes32(a.Data.BeaconBlockRoot)) && s.beaconDB.HasState(ctx, bytesutil.ToBytes32(a.Data.Target.Root)) diff --git a/beacon-chain/blockchain/service.go b/beacon-chain/blockchain/service.go index 828c0322a2cf..e0a64f4e0587 100644 --- a/beacon-chain/blockchain/service.go +++ b/beacon-chain/blockchain/service.go @@ -140,7 +140,7 @@ func (s *Service) Start() { } if beaconState == nil { - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { beaconState, err = s.stateGen.StateByRoot(ctx, bytesutil.ToBytes32(cp.Root)) if err != nil { log.Fatalf("Could not fetch beacon state by root: %v", err) @@ -181,7 +181,7 @@ func (s *Service) Start() { s.prevFinalizedCheckpt = stateTrie.CopyCheckpoint(finalizedCheckpoint) s.resumeForkChoice(justifiedCheckpoint, finalizedCheckpoint) - if featureconfig.Get().DisableNewStateMgmt { + if !featureconfig.Get().NewStateMgmt { if finalizedCheckpoint.Epoch > 1 { if err := s.pruneGarbageState(ctx, helpers.StartSlot(finalizedCheckpoint.Epoch)-params.BeaconConfig().SlotsPerEpoch); err != nil { log.WithError(err).Warn("Could not prune old states") @@ -327,7 +327,7 @@ func (s *Service) saveGenesisData(ctx context.Context, genesisState *stateTrie.B if err := s.beaconDB.SaveBlock(ctx, genesisBlk); err != nil { return errors.Wrap(err, "could not save genesis block") } - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { if err := s.stateGen.SaveState(ctx, genesisBlkRoot, genesisState); err != nil { return errors.Wrap(err, "could not save genesis state") } @@ -415,7 +415,7 @@ func (s *Service) initializeChainInfo(ctx context.Context) error { } finalizedRoot := bytesutil.ToBytes32(finalized.Root) var finalizedState *stateTrie.BeaconState - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { finalizedRoot = s.beaconDB.LastArchivedIndexRoot(ctx) finalizedState, err = s.stateGen.Resume(ctx) if err != nil { diff --git a/beacon-chain/db/kv/blocks.go b/beacon-chain/db/kv/blocks.go index 16f7fca9155d..eb3907292f23 100644 --- a/beacon-chain/db/kv/blocks.go +++ b/beacon-chain/db/kv/blocks.go @@ -263,7 +263,7 @@ func (k *Store) SaveHeadBlockRoot(ctx context.Context, blockRoot [32]byte) error ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveHeadBlockRoot") defer span.End() return k.db.Update(func(tx *bolt.Tx) error { - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { hasStateSummaryInCache := k.stateSummaryCache.Has(blockRoot) hasStateSummaryInDB := tx.Bucket(stateSummaryBucket).Get(blockRoot[:]) != nil hasStateInDB := tx.Bucket(stateBucket).Get(blockRoot[:]) != nil diff --git a/beacon-chain/db/kv/check_historical_state.go b/beacon-chain/db/kv/check_historical_state.go index ef05d64465c7..c380171c62fc 100644 --- a/beacon-chain/db/kv/check_historical_state.go +++ b/beacon-chain/db/kv/check_historical_state.go @@ -13,7 +13,7 @@ var historicalStateDeletedKey = []byte("historical-states-deleted") // HistoricalStatesDeleted verifies historical states exist in DB. func (kv *Store) HistoricalStatesDeleted(ctx context.Context) error { - if featureconfig.Get().DisableNewStateMgmt { + if !featureconfig.Get().NewStateMgmt { return kv.db.Update(func(tx *bolt.Tx) error { bkt := tx.Bucket(newStateServiceCompatibleBucket) return bkt.Put(historicalStateDeletedKey, []byte{0x01}) diff --git a/beacon-chain/db/kv/checkpoint.go b/beacon-chain/db/kv/checkpoint.go index d5282364e924..982581e36c8b 100644 --- a/beacon-chain/db/kv/checkpoint.go +++ b/beacon-chain/db/kv/checkpoint.go @@ -65,7 +65,7 @@ func (k *Store) SaveJustifiedCheckpoint(ctx context.Context, checkpoint *ethpb.C } return k.db.Update(func(tx *bolt.Tx) error { bucket := tx.Bucket(checkpointBucket) - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { hasStateSummaryInDB := tx.Bucket(stateSummaryBucket).Get(checkpoint.Root) != nil hasStateSummaryInCache := k.stateSummaryCache.Has(bytesutil.ToBytes32(checkpoint.Root)) hasStateInDB := tx.Bucket(stateBucket).Get(checkpoint.Root) != nil @@ -96,7 +96,7 @@ func (k *Store) SaveFinalizedCheckpoint(ctx context.Context, checkpoint *ethpb.C } return k.db.Update(func(tx *bolt.Tx) error { bucket := tx.Bucket(checkpointBucket) - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { hasStateSummaryInDB := tx.Bucket(stateSummaryBucket).Get(checkpoint.Root) != nil hasStateSummaryInCache := k.stateSummaryCache.Has(bytesutil.ToBytes32(checkpoint.Root)) hasStateInDB := tx.Bucket(stateBucket).Get(checkpoint.Root) != nil diff --git a/beacon-chain/rpc/beacon/assignments.go b/beacon-chain/rpc/beacon/assignments.go index e98e18295bbc..fa813475ab75 100644 --- a/beacon-chain/rpc/beacon/assignments.go +++ b/beacon-chain/rpc/beacon/assignments.go @@ -32,7 +32,7 @@ func (bs *Server) ListValidatorAssignments( ) } - if featureconfig.Get().DisableNewStateMgmt { + if !featureconfig.Get().NewStateMgmt { return bs.listValidatorAssignmentsUsingOldArchival(ctx, req) } diff --git a/beacon-chain/rpc/beacon/assignments_test.go b/beacon-chain/rpc/beacon/assignments_test.go index 24c262cc8e67..31bb1c28a511 100644 --- a/beacon-chain/rpc/beacon/assignments_test.go +++ b/beacon-chain/rpc/beacon/assignments_test.go @@ -18,11 +18,17 @@ import ( dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/flags" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" + "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil" ) func TestServer_ListAssignments_CannotRequestFutureEpoch(t *testing.T) { + config := &featureconfig.Flags{ + NewStateMgmt: true, + } + featureconfig.Init(config) + db := dbTest.SetupDB(t) defer dbTest.TeardownDB(t, db) @@ -46,6 +52,11 @@ func TestServer_ListAssignments_CannotRequestFutureEpoch(t *testing.T) { } func TestServer_ListAssignments_NoResults(t *testing.T) { + config := &featureconfig.Flags{ + NewStateMgmt: true, + } + featureconfig.Init(config) + db := dbTest.SetupDB(t) defer dbTest.TeardownDB(t, db) @@ -94,6 +105,11 @@ func TestServer_ListAssignments_NoResults(t *testing.T) { } func TestServer_ListAssignments_Pagination_InputOutOfRange(t *testing.T) { + config := &featureconfig.Flags{ + NewStateMgmt: true, + } + featureconfig.Init(config) + db := dbTest.SetupDB(t) defer dbTest.TeardownDB(t, db) @@ -430,6 +446,11 @@ func TestServer_ListAssignments_FilterPubkeysIndices_NoPagination(t *testing.T) } func TestServer_ListAssignments_CanFilterPubkeysIndices_WithPagination(t *testing.T) { + config := &featureconfig.Flags{ + NewStateMgmt: true, + } + featureconfig.Init(config) + db := dbTest.SetupDB(t) defer dbTest.TeardownDB(t, db) diff --git a/beacon-chain/rpc/beacon/attestations.go b/beacon-chain/rpc/beacon/attestations.go index d325ab6b56c2..9bcf244d55d1 100644 --- a/beacon-chain/rpc/beacon/attestations.go +++ b/beacon-chain/rpc/beacon/attestations.go @@ -128,7 +128,7 @@ func (bs *Server) ListIndexedAttestations( default: return nil, status.Error(codes.InvalidArgument, "Must specify a filter criteria for fetching attestations") } - if featureconfig.Get().DisableNewStateMgmt { + if !featureconfig.Get().NewStateMgmt { return nil, status.Error(codes.Internal, "New state management must be turned on to support historic attestation. Please run without --disable-new-state-mgmt flag") } diff --git a/beacon-chain/rpc/beacon/attestations_test.go b/beacon-chain/rpc/beacon/attestations_test.go index 6717b235b4cf..cc1f825984dc 100644 --- a/beacon-chain/rpc/beacon/attestations_test.go +++ b/beacon-chain/rpc/beacon/attestations_test.go @@ -574,6 +574,11 @@ func TestServer_mapAttestationToTargetRoot(t *testing.T) { } func TestServer_ListIndexedAttestations_NewStateManagnmentDisabled(t *testing.T) { + config := &featureconfig.Flags{ + NewStateMgmt: false, + } + featureconfig.Init(config) + db := dbTest.SetupDB(t) defer dbTest.TeardownDB(t, db) params.OverrideBeaconConfig(params.MainnetConfig()) @@ -581,10 +586,7 @@ func TestServer_ListIndexedAttestations_NewStateManagnmentDisabled(t *testing.T) ctx := context.Background() numValidators := uint64(128) state, _ := testutil.DeterministicGenesisState(t, numValidators) - config := &featureconfig.Flags{ - DisableNewStateMgmt: true, - } - featureconfig.Init(config) + bs := &Server{ BeaconDB: db, GenesisTimeFetcher: &mock.ChainService{State: state}, @@ -1234,9 +1236,9 @@ func TestServer_StreamAttestations_OnSlotTick(t *testing.T) { // assertNewStateMgmtIsEnabled asserts that state management feature is enabled. func assertNewStateMgmtIsEnabled() *featureconfig.Flags { cfg := featureconfig.Get() - if cfg.DisableNewStateMgmt { + if cfg.NewStateMgmt { cfgUpd := cfg.Copy() - cfgUpd.DisableNewStateMgmt = false + cfgUpd.NewStateMgmt = true featureconfig.Init(cfgUpd) } return cfg diff --git a/beacon-chain/rpc/beacon/committees.go b/beacon-chain/rpc/beacon/committees.go index dcd9aff76d19..4110519f00d0 100644 --- a/beacon-chain/rpc/beacon/committees.go +++ b/beacon-chain/rpc/beacon/committees.go @@ -46,7 +46,7 @@ func (bs *Server) ListBeaconCommittees( committees := make(map[uint64]*ethpb.BeaconCommittees_CommitteesList) activeIndices := make([]uint64, 0) var err error - if featureconfig.Get().DisableNewStateMgmt { + if !featureconfig.Get().NewStateMgmt { committees, activeIndices, err = bs.retrieveCommitteesForEpochUsingOldArchival(ctx, requestedEpoch) if err != nil { return nil, status.Errorf( diff --git a/beacon-chain/rpc/beacon/committees_test.go b/beacon-chain/rpc/beacon/committees_test.go index 9d0d8541ba07..6a0cfa2eba2c 100644 --- a/beacon-chain/rpc/beacon/committees_test.go +++ b/beacon-chain/rpc/beacon/committees_test.go @@ -87,9 +87,10 @@ func TestServer_ListBeaconCommittees_CurrentEpoch(t *testing.T) { } func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) { - fc := featureconfig.Get() - fc.DisableNewStateMgmt = true - featureconfig.Init(fc) + config := &featureconfig.Flags{ + NewStateMgmt: false, + } + featureconfig.Init(config) db := dbTest.SetupDB(t) defer dbTest.TeardownDB(t, db) @@ -161,9 +162,10 @@ func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) { } func TestServer_ListBeaconCommittees_FromArchive(t *testing.T) { - fc := featureconfig.Get() - fc.DisableNewStateMgmt = true - featureconfig.Init(fc) + config := &featureconfig.Flags{ + NewStateMgmt: false, + } + featureconfig.Init(config) db := dbTest.SetupDB(t) defer dbTest.TeardownDB(t, db) diff --git a/beacon-chain/rpc/beacon/validators.go b/beacon-chain/rpc/beacon/validators.go index 6c8c3397ced9..0018ea5f7627 100644 --- a/beacon-chain/rpc/beacon/validators.go +++ b/beacon-chain/rpc/beacon/validators.go @@ -362,7 +362,7 @@ func (bs *Server) GetValidatorActiveSetChanges( ctx context.Context, req *ethpb.GetValidatorActiveSetChangesRequest, ) (*ethpb.ActiveSetChanges, error) { - if featureconfig.Get().DisableNewStateMgmt { + if !featureconfig.Get().NewStateMgmt { return bs.getValidatorActiveSetChangesUsingOldArchival(ctx, req) } @@ -552,7 +552,7 @@ func (bs *Server) GetValidatorParticipation( ctx context.Context, req *ethpb.GetValidatorParticipationRequest, ) (*ethpb.ValidatorParticipationResponse, error) { - if featureconfig.Get().DisableNewStateMgmt { + if !featureconfig.Get().NewStateMgmt { return bs.getValidatorParticipationUsingOldArchival(ctx, req) } diff --git a/beacon-chain/rpc/beacon/validators_test.go b/beacon-chain/rpc/beacon/validators_test.go index 2fb99a1cf76d..c515564e9971 100644 --- a/beacon-chain/rpc/beacon/validators_test.go +++ b/beacon-chain/rpc/beacon/validators_test.go @@ -1257,9 +1257,10 @@ func TestServer_GetValidatorActiveSetChanges(t *testing.T) { } func TestServer_GetValidatorActiveSetChanges_FromArchive(t *testing.T) { - fc := featureconfig.Get() - fc.DisableNewStateMgmt = true - featureconfig.Init(fc) + config := &featureconfig.Flags{ + NewStateMgmt: false, + } + featureconfig.Init(config) db := dbTest.SetupDB(t) defer dbTest.TeardownDB(t, db) @@ -1565,10 +1566,6 @@ func TestServer_GetValidatorQueue_PendingExit(t *testing.T) { } func TestServer_GetValidatorParticipation_CannotRequestCurrentEpoch(t *testing.T) { - fc := featureconfig.Get() - fc.DisableNewStateMgmt = true - featureconfig.Init(fc) - db := dbTest.SetupDB(t) defer dbTest.TeardownDB(t, db) @@ -1628,10 +1625,6 @@ func TestServer_GetValidatorParticipation_CannotRequestFutureEpoch(t *testing.T) } func TestServer_GetValidatorParticipation_FromArchive(t *testing.T) { - fc := featureconfig.Get() - fc.DisableNewStateMgmt = true - featureconfig.Init(fc) - db := dbTest.SetupDB(t) defer dbTest.TeardownDB(t, db) ctx := context.Background() @@ -1798,10 +1791,6 @@ func TestServer_GetValidatorParticipation_DoesntExist(t *testing.T) { } func TestServer_GetValidatorParticipation_FromArchive_FinalizedEpoch(t *testing.T) { - fc := featureconfig.Get() - fc.DisableNewStateMgmt = true - featureconfig.Init(fc) - db := dbTest.SetupDB(t) defer dbTest.TeardownDB(t, db) ctx := context.Background() diff --git a/beacon-chain/rpc/validator/attester.go b/beacon-chain/rpc/validator/attester.go index 7e692ebad6dc..cf38894246a3 100644 --- a/beacon-chain/rpc/validator/attester.go +++ b/beacon-chain/rpc/validator/attester.go @@ -82,7 +82,7 @@ func (vs *Server) GetAttestationData(ctx context.Context, req *ethpb.Attestation // processed, we walk up the chain until state.Slot <= req.Slot to prevent producing an // attestation that violates processing constraints. fetchState := vs.BeaconDB.State - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { fetchState = vs.StateGen.StateByRoot } for headState.Slot() > req.Slot { diff --git a/beacon-chain/rpc/validator/proposer.go b/beacon-chain/rpc/validator/proposer.go index 0cb8e275ab83..c716746c1f8a 100644 --- a/beacon-chain/rpc/validator/proposer.go +++ b/beacon-chain/rpc/validator/proposer.go @@ -236,7 +236,7 @@ func (vs *Server) randomETH1DataVote(ctx context.Context) (*ethpb.Eth1Data, erro func (vs *Server) computeStateRoot(ctx context.Context, block *ethpb.SignedBeaconBlock) ([]byte, error) { var beaconState *stateTrie.BeaconState var err error - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { beaconState, err = vs.StateGen.StateByRoot(ctx, bytesutil.ToBytes32(block.Block.ParentRoot)) if err != nil { return nil, errors.Wrap(err, "could not retrieve beacon state") diff --git a/beacon-chain/sync/pending_attestations_queue.go b/beacon-chain/sync/pending_attestations_queue.go index 28727535c196..b684e94d7f8d 100644 --- a/beacon-chain/sync/pending_attestations_queue.go +++ b/beacon-chain/sync/pending_attestations_queue.go @@ -63,7 +63,7 @@ func (s *Service) processPendingAtts(ctx context.Context) error { attestations := s.blkRootToPendingAtts[bRoot] s.pendingAttsLock.RUnlock() // Has the pending attestation's missing block arrived and the node processed block yet? - hasStateSummary := !featureconfig.Get().DisableNewStateMgmt && s.db.HasStateSummary(ctx, bRoot) || s.stateSummaryCache.Has(bRoot) + hasStateSummary := featureconfig.Get().NewStateMgmt && s.db.HasStateSummary(ctx, bRoot) || s.stateSummaryCache.Has(bRoot) if s.db.HasBlock(ctx, bRoot) && (s.db.HasState(ctx, bRoot) || hasStateSummary) { numberOfBlocksRecoveredFromAtt.Inc() for _, signedAtt := range attestations { diff --git a/beacon-chain/sync/validate_aggregate_proof.go b/beacon-chain/sync/validate_aggregate_proof.go index 7be744cc1803..30d553b51071 100644 --- a/beacon-chain/sync/validate_aggregate_proof.go +++ b/beacon-chain/sync/validate_aggregate_proof.go @@ -141,7 +141,7 @@ func (r *Service) validateBlockInAttestation(ctx context.Context, s *ethpb.Signe a := s.Message // Verify the block being voted and the processed state is in DB. The block should have passed validation if it's in the DB. blockRoot := bytesutil.ToBytes32(a.Aggregate.Data.BeaconBlockRoot) - hasStateSummary := !featureconfig.Get().DisableNewStateMgmt && r.db.HasStateSummary(ctx, blockRoot) || r.stateSummaryCache.Has(blockRoot) + hasStateSummary := featureconfig.Get().NewStateMgmt && r.db.HasStateSummary(ctx, blockRoot) || r.stateSummaryCache.Has(blockRoot) hasState := r.db.HasState(ctx, blockRoot) || hasStateSummary hasBlock := r.db.HasBlock(ctx, blockRoot) if !(hasState && hasBlock) { diff --git a/beacon-chain/sync/validate_aggregate_proof_test.go b/beacon-chain/sync/validate_aggregate_proof_test.go index 143265b211b8..342118e64edd 100644 --- a/beacon-chain/sync/validate_aggregate_proof_test.go +++ b/beacon-chain/sync/validate_aggregate_proof_test.go @@ -25,6 +25,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/attestationutil" "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/bytesutil" + "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil" ) @@ -336,7 +337,12 @@ func TestValidateAggregateAndProof_ExistedInPool(t *testing.T) { } } -func TestValidateAggregateAndProof_CanValidate(t *testing.T) { +func TestValidateAggregateAndProofWithNewStateMgmt_CanValidate(t *testing.T) { + config := &featureconfig.Flags{ + NewStateMgmt: true, + } + featureconfig.Init(config) + db := dbtest.SetupDB(t) defer dbtest.TeardownDB(t, db) p := p2ptest.NewTestP2P(t) diff --git a/beacon-chain/sync/validate_beacon_blocks.go b/beacon-chain/sync/validate_beacon_blocks.go index 87cf908977b7..aa333661c0e5 100644 --- a/beacon-chain/sync/validate_beacon_blocks.go +++ b/beacon-chain/sync/validate_beacon_blocks.go @@ -90,7 +90,7 @@ func (r *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms return false } - if !featureconfig.Get().DisableNewStateMgmt { + if featureconfig.Get().NewStateMgmt { hasStateSummaryDB := r.db.HasStateSummary(ctx, bytesutil.ToBytes32(blk.Block.ParentRoot)) hasStateSummaryCache := r.stateSummaryCache.Has(bytesutil.ToBytes32(blk.Block.ParentRoot)) if !hasStateSummaryDB && !hasStateSummaryCache { diff --git a/beacon-chain/sync/validate_committee_index_beacon_attestation.go b/beacon-chain/sync/validate_committee_index_beacon_attestation.go index 51143cbfbf7b..11b839d64207 100644 --- a/beacon-chain/sync/validate_committee_index_beacon_attestation.go +++ b/beacon-chain/sync/validate_committee_index_beacon_attestation.go @@ -85,7 +85,7 @@ func (s *Service) validateCommitteeIndexBeaconAttestation(ctx context.Context, p // Verify the block being voted and the processed state is in DB and. The block should have passed validation if it's in the DB. blockRoot := bytesutil.ToBytes32(att.Data.BeaconBlockRoot) - hasStateSummary := !featureconfig.Get().DisableNewStateMgmt && s.db.HasStateSummary(ctx, blockRoot) || s.stateSummaryCache.Has(blockRoot) + hasStateSummary := featureconfig.Get().NewStateMgmt && s.db.HasStateSummary(ctx, blockRoot) || s.stateSummaryCache.Has(blockRoot) hasState := s.db.HasState(ctx, blockRoot) || hasStateSummary hasBlock := s.db.HasBlock(ctx, blockRoot) if !(hasState && hasBlock) { diff --git a/shared/featureconfig/config.go b/shared/featureconfig/config.go index 124db05ae986..4a9b5b8cabbe 100644 --- a/shared/featureconfig/config.go +++ b/shared/featureconfig/config.go @@ -46,7 +46,7 @@ type Flags struct { CheckHeadState bool // CheckHeadState checks the current headstate before retrieving the desired state from the db. EnableNoise bool // EnableNoise enables the beacon node to use NOISE instead of SECIO when performing a handshake with another peer. DontPruneStateStartUp bool // DontPruneStateStartUp disables pruning state upon beacon node start up. - DisableNewStateMgmt bool // NewStateMgmt disables the new state mgmt service. + NewStateMgmt bool // NewStateMgmt enables the new state mgmt service. DisableInitSyncQueue bool // DisableInitSyncQueue disables the new initial sync implementation. EnableFieldTrie bool // EnableFieldTrie enables the state from using field specific tries when computing the root. EnableBlockHTR bool // EnableBlockHTR enables custom hashing of our beacon blocks. @@ -92,7 +92,7 @@ func (c *Flags) Copy() *Flags { MinimalConfig: c.MinimalConfig, WriteSSZStateTransitions: c.WriteSSZStateTransitions, InitSyncNoVerify: c.InitSyncNoVerify, - DisableDynamicCommitteeSubnets: c.DisableNewStateMgmt, + DisableDynamicCommitteeSubnets: c.DisableDynamicCommitteeSubnets, SkipBLSVerify: c.SkipBLSVerify, EnableBackupWebhook: c.EnableStateRefCopy, PruneEpochBoundaryStates: c.PruneEpochBoundaryStates, @@ -107,7 +107,7 @@ func (c *Flags) Copy() *Flags { CheckHeadState: c.CheckHeadState, EnableNoise: c.EnableNoise, DontPruneStateStartUp: c.DontPruneStateStartUp, - DisableNewStateMgmt: c.DisableNewStateMgmt, + NewStateMgmt: c.NewStateMgmt, DisableInitSyncQueue: c.DisableInitSyncQueue, EnableFieldTrie: c.EnableFieldTrie, EnableBlockHTR: c.EnableBlockHTR, @@ -215,9 +215,9 @@ func ConfigureBeaconChain(ctx *cli.Context) { log.Warn("Not enabling state pruning upon start up") cfg.DontPruneStateStartUp = true } - if ctx.Bool(disableNewStateMgmt.Name) { - log.Warn("Disabling state management service") - cfg.DisableNewStateMgmt = true + if ctx.Bool(enableNewStateMgmt.Name) { + log.Warn("Enabling state management service") + cfg.NewStateMgmt = true } if ctx.Bool(disableInitSyncQueue.Name) { log.Warn("Disabled initial sync queue") diff --git a/shared/featureconfig/flags.go b/shared/featureconfig/flags.go index 361262602c09..0ffbbf6511e9 100644 --- a/shared/featureconfig/flags.go +++ b/shared/featureconfig/flags.go @@ -122,9 +122,9 @@ var ( Name: "dont-prune-state-start-up", Usage: "Don't prune historical states upon start up", } - disableNewStateMgmt = &cli.BoolFlag{ - Name: "disable-new-state-mgmt", - Usage: "This disables the usage of state mgmt service across Prysm", + enableNewStateMgmt = &cli.BoolFlag{ + Name: "enable-new-state-mgmt", + Usage: "This enable the usage of state mgmt service across Prysm", } disableInitSyncQueue = &cli.BoolFlag{ Name: "disable-init-sync-queue", @@ -382,7 +382,7 @@ var BeaconChainFlags = append(deprecatedFlags, []cli.Flag{ enableNoiseHandshake, dontPruneStateStartUp, broadcastSlashingFlag, - disableNewStateMgmt, + enableNewStateMgmt, disableInitSyncQueue, enableFieldTrie, enableCustomBlockHTR, @@ -400,4 +400,5 @@ var E2EBeaconChainFlags = []string{ "--check-head-state", "--enable-state-field-trie", "--enable-state-ref-copy", + "--enable-new-state-mgmt", }