Skip to content

Commit

Permalink
Deprecate native state flag (#11268)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkapka authored Sep 15, 2022
1 parent a27feb4 commit 0f0ab13
Show file tree
Hide file tree
Showing 152 changed files with 890 additions and 5,499 deletions.
4 changes: 4 additions & 0 deletions beacon-chain/core/altair/reward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/altair"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v3/config/params"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
Expand All @@ -13,6 +14,7 @@ import (
)

func Test_BaseReward(t *testing.T) {
helpers.ClearCache()
genState := func(valCount uint64) state.ReadOnlyBeaconState {
s, _ := util.DeterministicGenesisStateAltair(t, valCount)
return s
Expand Down Expand Up @@ -66,6 +68,7 @@ func Test_BaseReward(t *testing.T) {
}

func Test_BaseRewardWithTotalBalance(t *testing.T) {
helpers.ClearCache()
s, _ := util.DeterministicGenesisStateAltair(t, 1)
tests := []struct {
name string
Expand Down Expand Up @@ -137,6 +140,7 @@ func Test_BaseRewardWithTotalBalance(t *testing.T) {
}

func Test_BaseRewardPerIncrement(t *testing.T) {
helpers.ClearCache()
tests := []struct {
name string
activeBalance uint64
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/validators/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestSlashValidator_OK(t *testing.T) {
state, err := v1.InitializeFromProto(base)
require.NoError(t, err)

slashedIdx := types.ValidatorIndex(2)
slashedIdx := types.ValidatorIndex(3)

proposer, err := helpers.BeaconProposerIndex(context.Background(), state)
require.NoError(t, err, "Could not get proposer")
Expand Down
24 changes: 3 additions & 21 deletions beacon-chain/db/kv/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,7 @@ func (s *Store) saveStatesEfficientInternal(ctx context.Context, tx *bolt.Tx, bl
// look at issue https://github.com/prysmaticlabs/prysm/issues/9262.
switch rawType := states[i].InnerStateUnsafe().(type) {
case *ethpb.BeaconState:
var pbState *ethpb.BeaconState
var err error
if features.Get().EnableNativeState {
pbState, err = statenative.ProtobufBeaconStatePhase0(rawType)
} else {
pbState, err = v1.ProtobufBeaconState(rawType)
}
pbState, err := statenative.ProtobufBeaconStatePhase0(rawType)
if err != nil {
return err
}
Expand All @@ -260,13 +254,7 @@ func (s *Store) saveStatesEfficientInternal(ctx context.Context, tx *bolt.Tx, bl
return err
}
case *ethpb.BeaconStateAltair:
var pbState *ethpb.BeaconStateAltair
var err error
if features.Get().EnableNativeState {
pbState, err = statenative.ProtobufBeaconStateAltair(rawType)
} else {
pbState, err = v2.ProtobufBeaconState(rawType)
}
pbState, err := statenative.ProtobufBeaconStateAltair(rawType)
if err != nil {
return err
}
Expand All @@ -288,13 +276,7 @@ func (s *Store) saveStatesEfficientInternal(ctx context.Context, tx *bolt.Tx, bl
return err
}
case *ethpb.BeaconStateBellatrix:
var pbState *ethpb.BeaconStateBellatrix
var err error
if features.Get().EnableNativeState {
pbState, err = statenative.ProtobufBeaconStateBellatrix(rawType)
} else {
pbState, err = v3.ProtobufBeaconState(rawType)
}
pbState, err := statenative.ProtobufBeaconStateBellatrix(rawType)
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/execution/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ go_library(
"//beacon-chain/state/state-native:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//config/features:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//consensus-types/blocks:go_default_library",
Expand Down
10 changes: 1 addition & 9 deletions beacon-chain/execution/log_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers"
coreState "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition"
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
"github.com/prysmaticlabs/prysm/v3/config/features"
"github.com/prysmaticlabs/prysm/v3/config/params"
contracts "github.com/prysmaticlabs/prysm/v3/contracts/deposit"
"github.com/prysmaticlabs/prysm/v3/crypto/hash"
Expand Down Expand Up @@ -552,13 +550,7 @@ func (s *Service) processChainStartIfReady(ctx context.Context, blockHash [32]by

// savePowchainData saves all powchain related metadata to disk.
func (s *Service) savePowchainData(ctx context.Context) error {
var pbState *ethpb.BeaconState
var err error
if features.Get().EnableNativeState {
pbState, err = statenative.ProtobufBeaconStatePhase0(s.preGenesisState.InnerStateUnsafe())
} else {
pbState, err = v1.ProtobufBeaconState(s.preGenesisState.InnerStateUnsafe())
}
pbState, err := statenative.ProtobufBeaconStatePhase0(s.preGenesisState.InnerStateUnsafe())
if err != nil {
return err
}
Expand Down
15 changes: 2 additions & 13 deletions beacon-chain/execution/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
"github.com/prysmaticlabs/prysm/v3/config/features"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/prysmaticlabs/prysm/v3/container/trie"
contracts "github.com/prysmaticlabs/prysm/v3/contracts/deposit"
Expand Down Expand Up @@ -262,11 +261,7 @@ func (s *Service) Stop() error {
// ClearPreGenesisData clears out the stored chainstart deposits and beacon state.
func (s *Service) ClearPreGenesisData() {
s.chainStartData.ChainstartDeposits = []*ethpb.Deposit{}
if features.Get().EnableNativeState {
s.preGenesisState = &native.BeaconState{}
} else {
s.preGenesisState = &v1.BeaconState{}
}
s.preGenesisState = &native.BeaconState{}
}

// ChainStartEth1Data returns the eth1 data at chainstart.
Expand Down Expand Up @@ -784,13 +779,7 @@ func (s *Service) ensureValidPowchainData(ctx context.Context) error {
return errors.Wrap(err, "unable to retrieve eth1 data")
}
if eth1Data == nil || !eth1Data.ChainstartData.Chainstarted || !validateDepositContainers(eth1Data.DepositContainers) {
var pbState *ethpb.BeaconState
var err error
if features.Get().EnableNativeState {
pbState, err = native.ProtobufBeaconStatePhase0(s.preGenesisState.InnerStateUnsafe())
} else {
pbState, err = v1.ProtobufBeaconState(s.preGenesisState.InnerStateUnsafe())
}
pbState, err := native.ProtobufBeaconStatePhase0(s.preGenesisState.InnerStateUnsafe())
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/node/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ go_test(
"//beacon-chain/execution/testing:go_default_library",
"//cmd:go_default_library",
"//cmd/beacon-chain/flags:go_default_library",
"//config/features:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//consensus-types/primitives:go_default_library",
Expand Down
6 changes: 0 additions & 6 deletions beacon-chain/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
mockExecution "github.com/prysmaticlabs/prysm/v3/beacon-chain/execution/testing"
"github.com/prysmaticlabs/prysm/v3/cmd"
"github.com/prysmaticlabs/prysm/v3/cmd/beacon-chain/flags"
"github.com/prysmaticlabs/prysm/v3/config/features"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/config/params"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
Expand All @@ -34,7 +33,6 @@ var _ statefeed.Notifier = (*BeaconNode)(nil)
// Test that beacon chain node can close.
func TestNodeClose_OK(t *testing.T) {
hook := logTest.NewGlobal()
features.Init(&features.Flags{EnableNativeState: true})
tmp := fmt.Sprintf("%s/datadirtest2", t.TempDir())

app := cli.App{}
Expand All @@ -54,7 +52,6 @@ func TestNodeClose_OK(t *testing.T) {
node.Close()

require.LogsContain(t, hook, "Stopping beacon node")
features.Init(&features.Flags{EnableNativeState: false})
}

func TestNodeStart_Ok(t *testing.T) {
Expand All @@ -63,7 +60,6 @@ func TestNodeStart_Ok(t *testing.T) {
tmp := fmt.Sprintf("%s/datadirtest2", t.TempDir())
set := flag.NewFlagSet("test", 0)
set.String("datadir", tmp, "node data directory")
features.Init(&features.Flags{EnableNativeState: true})
ctx := cli.NewContext(&app, set, nil)
node, err := New(ctx, WithBlockchainFlagOptions([]blockchain.Option{}),
WithBuilderFlagOptions([]builder.Option{}),
Expand All @@ -80,7 +76,6 @@ func TestNodeStart_Ok(t *testing.T) {
}

func TestNodeStart_Ok_registerDeterministicGenesisService(t *testing.T) {
features.Init(&features.Flags{EnableNativeState: true})
numValidators := uint64(1)
hook := logTest.NewGlobal()
app := cli.App{}
Expand Down Expand Up @@ -124,7 +119,6 @@ func TestNodeStart_Ok_registerDeterministicGenesisService(t *testing.T) {
node.Close()
require.LogsContain(t, hook, "Starting beacon node")
require.NoError(t, os.Remove("genesis_ssz.json"))
features.Init(&features.Flags{EnableNativeState: false})
}

// TestClearDB tests clearing the database
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/rpc/eth/beacon/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ go_library(
"//beacon-chain/rpc/prysm/v1alpha1/validator:go_default_library",
"//beacon-chain/rpc/statefetcher:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/state-native:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//beacon-chain/sync:go_default_library",
Expand Down
3 changes: 2 additions & 1 deletion beacon-chain/rpc/eth/beacon/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
corehelpers "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/rpc/eth/helpers"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
"github.com/prysmaticlabs/prysm/v3/config/params"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
Expand Down Expand Up @@ -255,7 +256,7 @@ func valContainersByRequestIds(state state.BeaconState, validatorIds [][]byte) (
valIndex = types.ValidatorIndex(index)
}
validator, err := state.ValidatorAtIndex(valIndex)
if _, ok := err.(*v1.ValidatorIndexOutOfRangeError); ok {
if _, ok := err.(*statenative.ValidatorIndexOutOfRangeError); ok {
// Ignore well-formed yet unknown indexes.
continue
}
Expand Down
2 changes: 2 additions & 0 deletions beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ go_test(
"validators_test.go",
],
embed = [":go_default_library"],
eth_network = "minimal",
shard_count = 4,
tags = ["minimal"],
deps = [
"//beacon-chain/blockchain/testing:go_default_library",
"//beacon-chain/core/altair:go_default_library",
Expand Down
10 changes: 5 additions & 5 deletions beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func TestServer_mapAttestationToTargetRoot(t *testing.T) {

func TestServer_ListIndexedAttestations_GenesisEpoch(t *testing.T) {
params.SetupTestConfigCleanup(t)
params.OverrideBeaconConfig(params.MainnetConfig())
params.OverrideBeaconConfig(params.BeaconConfig())
db := dbTest.SetupDB(t)
helpers.ClearCache()
ctx := context.Background()
Expand Down Expand Up @@ -542,8 +542,8 @@ func TestServer_ListIndexedAttestations_GenesisEpoch(t *testing.T) {

}

// We setup 128 validators.
numValidators := uint64(128)
// We setup 512 validators so that committee size matches the length of attestations' aggregation bits.
numValidators := uint64(512)
state, _ := util.DeterministicGenesisState(t, numValidators)

// Next up we convert the test attestations to indexed form:
Expand Down Expand Up @@ -605,7 +605,7 @@ func TestServer_ListIndexedAttestations_GenesisEpoch(t *testing.T) {

func TestServer_ListIndexedAttestations_OldEpoch(t *testing.T) {
params.SetupTestConfigCleanup(t)
params.OverrideBeaconConfig(params.MainnetConfig())
params.OverrideBeaconConfig(params.BeaconConfig())
db := dbTest.SetupDB(t)
helpers.ClearCache()
ctx := context.Background()
Expand Down Expand Up @@ -852,7 +852,7 @@ func TestServer_StreamIndexedAttestations_ContextCanceled(t *testing.T) {

func TestServer_StreamIndexedAttestations_OK(t *testing.T) {
params.SetupTestConfigCleanup(t)
params.OverrideBeaconConfig(params.MainnetConfig())
params.OverrideBeaconConfig(params.BeaconConfig())
db := dbTest.SetupDB(t)
exitRoutine := make(chan bool)
ctrl := gomock.NewController(t)
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func TestServer_StreamBlocks_ContextCanceled(t *testing.T) {

func TestServer_StreamBlocks_OnHeadUpdated(t *testing.T) {
params.SetupTestConfigCleanup(t)
params.OverrideBeaconConfig(params.MainnetConfig())
params.OverrideBeaconConfig(params.BeaconConfig())

ctx := context.Background()
beaconState, privs := util.DeterministicGenesisState(t, 32)
Expand Down Expand Up @@ -421,7 +421,7 @@ func TestServer_StreamBlocks_OnHeadUpdated(t *testing.T) {

func TestServer_StreamBlocksVerified_OnHeadUpdated(t *testing.T) {
params.SetupTestConfigCleanup(t)
params.OverrideBeaconConfig(params.MainnetConfig())
params.OverrideBeaconConfig(params.BeaconConfig())

db := dbTest.SetupDB(t)
ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/rpc/prysm/v1alpha1/beacon/committees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func addDefaultReplayerBuilder(s *Server, h stategen.HistoryAccessor) {

func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) {
params.SetupTestConfigCleanup(t)
params.OverrideBeaconConfig(params.MainnetConfig())
params.OverrideBeaconConfig(params.BeaconConfig())
ctx := context.Background()

db := dbTest.SetupDB(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestInfostream_EpochToTimestamp(t *testing.T) {

func TestInfostream_HandleSetValidatorKeys(t *testing.T) {
params.SetupTestConfigCleanup(t)
params.OverrideBeaconConfig(params.MainnetConfig())
params.OverrideBeaconConfig(params.BeaconConfig())
tests := []struct {
name string
reqPubKeys [][]byte
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestInfostream_HandleSetValidatorKeys(t *testing.T) {

func TestInfostream_HandleAddValidatorKeys(t *testing.T) {
params.SetupTestConfigCleanup(t)
params.OverrideBeaconConfig(params.MainnetConfig())
params.OverrideBeaconConfig(params.BeaconConfig())
tests := []struct {
name string
initialPubKeys [][]byte
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestInfostream_HandleAddValidatorKeys(t *testing.T) {

func TestInfostream_HandleRemoveValidatorKeys(t *testing.T) {
params.SetupTestConfigCleanup(t)
params.OverrideBeaconConfig(params.MainnetConfig())
params.OverrideBeaconConfig(params.BeaconConfig())
tests := []struct {
name string
initialPubKeys [][]byte
Expand Down
Loading

0 comments on commit 0f0ab13

Please sign in to comment.