From aa868e5e8ca3dbf3b33608fe32b0750eb22bc025 Mon Sep 17 00:00:00 2001 From: james-prysm <90280386+james-prysm@users.noreply.github.com> Date: Mon, 22 Jul 2024 09:39:48 -0500 Subject: [PATCH] remove eip6110flag for validator index cache (#14173) * using fork instead of eip6110flag for validator index cache * updating validator indicies on initialize from poroto unsafe * fixing bad version check * attempting to fix unit test * reverting test changes * changing incorrect initialization * updating comment * radek's comment' --- beacon-chain/blockchain/receive_block_test.go | 8 +-- beacon-chain/blockchain/service_test.go | 7 +- .../state/state-native/getters_validator.go | 2 +- .../state/state-native/setters_misc.go | 3 +- beacon-chain/state/state-native/state_trie.go | 66 ++++++++++--------- config/features/config.go | 10 +-- config/features/flags.go | 6 -- 7 files changed, 44 insertions(+), 58 deletions(-) diff --git a/beacon-chain/blockchain/receive_block_test.go b/beacon-chain/blockchain/receive_block_test.go index f6ec1745c9f..1fdcb196e45 100644 --- a/beacon-chain/blockchain/receive_block_test.go +++ b/beacon-chain/blockchain/receive_block_test.go @@ -12,7 +12,6 @@ import ( statefeed "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed/state" "github.com/prysmaticlabs/prysm/v5/beacon-chain/das" "github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/voluntaryexits" - "github.com/prysmaticlabs/prysm/v5/config/features" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" @@ -421,14 +420,9 @@ func Test_sendNewFinalizedEvent(t *testing.T) { } func Test_executePostFinalizationTasks(t *testing.T) { - resetFn := features.InitWithReset(&features.Flags{ - EIP6110ValidatorIndexCache: true, - }) - defer resetFn() - logHook := logTest.NewGlobal() - headState, err := util.NewBeaconState() + headState, err := util.NewBeaconStateElectra() require.NoError(t, err) finalizedStRoot, err := headState.HashTreeRoot(context.Background()) require.NoError(t, err) diff --git a/beacon-chain/blockchain/service_test.go b/beacon-chain/blockchain/service_test.go index 73be76f80e4..a2bf18ac148 100644 --- a/beacon-chain/blockchain/service_test.go +++ b/beacon-chain/blockchain/service_test.go @@ -503,16 +503,15 @@ func TestChainService_EverythingOptimistic(t *testing.T) { func TestStartFromSavedState_ValidatorIndexCacheUpdated(t *testing.T) { resetFn := features.InitWithReset(&features.Flags{ - EnableStartOptimistic: true, - EIP6110ValidatorIndexCache: true, + EnableStartOptimistic: true, }) defer resetFn() - genesis := util.NewBeaconBlock() + genesis := util.NewBeaconBlockElectra() genesisRoot, err := genesis.Block.HashTreeRoot() require.NoError(t, err) finalizedSlot := params.BeaconConfig().SlotsPerEpoch*2 + 1 - headBlock := util.NewBeaconBlock() + headBlock := util.NewBeaconBlockElectra() headBlock.Block.Slot = finalizedSlot headBlock.Block.ParentRoot = bytesutil.PadTo(genesisRoot[:], 32) headState, err := util.NewBeaconState() diff --git a/beacon-chain/state/state-native/getters_validator.go b/beacon-chain/state/state-native/getters_validator.go index 12bd1c45bb9..6acac610004 100644 --- a/beacon-chain/state/state-native/getters_validator.go +++ b/beacon-chain/state/state-native/getters_validator.go @@ -180,7 +180,7 @@ func (b *BeaconState) ValidatorIndexByPubkey(key [fieldparams.BLSPubkeyLength]by b.lock.RLock() defer b.lock.RUnlock() - if features.Get().EIP6110ValidatorIndexCache { + if b.Version() >= version.Electra { return b.getValidatorIndex(key) } diff --git a/beacon-chain/state/state-native/setters_misc.go b/beacon-chain/state/state-native/setters_misc.go index 77d346fb4fc..affd7ef520b 100644 --- a/beacon-chain/state/state-native/setters_misc.go +++ b/beacon-chain/state/state-native/setters_misc.go @@ -4,7 +4,6 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native/types" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/stateutil" - "github.com/prysmaticlabs/prysm/v5/config/features" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/container/slice" @@ -110,7 +109,7 @@ func (b *BeaconState) SetHistoricalRoots(val [][]byte) error { // SaveValidatorIndices save validator indices of beacon chain to cache func (b *BeaconState) SaveValidatorIndices() { - if !features.Get().EIP6110ValidatorIndexCache { + if b.Version() < version.Electra { return } diff --git a/beacon-chain/state/state-native/state_trie.go b/beacon-chain/state/state-native/state_trie.go index c1c052ed3fb..e4b3e29fdc1 100644 --- a/beacon-chain/state/state-native/state_trie.go +++ b/beacon-chain/state/state-native/state_trie.go @@ -189,11 +189,12 @@ func InitializeFromProtoUnsafePhase0(st *ethpb.BeaconState) (state.BeaconState, id: types.Enumerator.Inc(), - dirtyFields: make(map[types.FieldIndex]bool, fieldCount), - dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount), - stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount), - rebuildTrie: make(map[types.FieldIndex]bool, fieldCount), - valMapHandler: stateutil.NewValMapHandler(st.Validators), + dirtyFields: make(map[types.FieldIndex]bool, fieldCount), + dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount), + stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount), + rebuildTrie: make(map[types.FieldIndex]bool, fieldCount), + valMapHandler: stateutil.NewValMapHandler(st.Validators), + validatorIndexCache: newFinalizedValidatorIndexCache(), } if features.Get().EnableExperimentalState { @@ -295,11 +296,12 @@ func InitializeFromProtoUnsafeAltair(st *ethpb.BeaconStateAltair) (state.BeaconS id: types.Enumerator.Inc(), - dirtyFields: make(map[types.FieldIndex]bool, fieldCount), - dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount), - stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount), - rebuildTrie: make(map[types.FieldIndex]bool, fieldCount), - valMapHandler: stateutil.NewValMapHandler(st.Validators), + dirtyFields: make(map[types.FieldIndex]bool, fieldCount), + dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount), + stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount), + rebuildTrie: make(map[types.FieldIndex]bool, fieldCount), + valMapHandler: stateutil.NewValMapHandler(st.Validators), + validatorIndexCache: newFinalizedValidatorIndexCache(), } if features.Get().EnableExperimentalState { @@ -405,11 +407,12 @@ func InitializeFromProtoUnsafeBellatrix(st *ethpb.BeaconStateBellatrix) (state.B id: types.Enumerator.Inc(), - dirtyFields: make(map[types.FieldIndex]bool, fieldCount), - dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount), - stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount), - rebuildTrie: make(map[types.FieldIndex]bool, fieldCount), - valMapHandler: stateutil.NewValMapHandler(st.Validators), + dirtyFields: make(map[types.FieldIndex]bool, fieldCount), + dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount), + stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount), + rebuildTrie: make(map[types.FieldIndex]bool, fieldCount), + valMapHandler: stateutil.NewValMapHandler(st.Validators), + validatorIndexCache: newFinalizedValidatorIndexCache(), } if features.Get().EnableExperimentalState { @@ -519,11 +522,12 @@ func InitializeFromProtoUnsafeCapella(st *ethpb.BeaconStateCapella) (state.Beaco id: types.Enumerator.Inc(), - dirtyFields: make(map[types.FieldIndex]bool, fieldCount), - dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount), - stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount), - rebuildTrie: make(map[types.FieldIndex]bool, fieldCount), - valMapHandler: stateutil.NewValMapHandler(st.Validators), + dirtyFields: make(map[types.FieldIndex]bool, fieldCount), + dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount), + stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount), + rebuildTrie: make(map[types.FieldIndex]bool, fieldCount), + valMapHandler: stateutil.NewValMapHandler(st.Validators), + validatorIndexCache: newFinalizedValidatorIndexCache(), } if features.Get().EnableExperimentalState { @@ -632,11 +636,12 @@ func InitializeFromProtoUnsafeDeneb(st *ethpb.BeaconStateDeneb) (state.BeaconSta nextWithdrawalValidatorIndex: st.NextWithdrawalValidatorIndex, historicalSummaries: st.HistoricalSummaries, - dirtyFields: make(map[types.FieldIndex]bool, fieldCount), - dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount), - stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount), - rebuildTrie: make(map[types.FieldIndex]bool, fieldCount), - valMapHandler: stateutil.NewValMapHandler(st.Validators), + dirtyFields: make(map[types.FieldIndex]bool, fieldCount), + dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount), + stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount), + rebuildTrie: make(map[types.FieldIndex]bool, fieldCount), + valMapHandler: stateutil.NewValMapHandler(st.Validators), + validatorIndexCache: newFinalizedValidatorIndexCache(), } if features.Get().EnableExperimentalState { @@ -754,11 +759,12 @@ func InitializeFromProtoUnsafeElectra(st *ethpb.BeaconStateElectra) (state.Beaco pendingPartialWithdrawals: st.PendingPartialWithdrawals, pendingConsolidations: st.PendingConsolidations, - dirtyFields: make(map[types.FieldIndex]bool, fieldCount), - dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount), - stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount), - rebuildTrie: make(map[types.FieldIndex]bool, fieldCount), - valMapHandler: stateutil.NewValMapHandler(st.Validators), + dirtyFields: make(map[types.FieldIndex]bool, fieldCount), + dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount), + stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount), + rebuildTrie: make(map[types.FieldIndex]bool, fieldCount), + valMapHandler: stateutil.NewValMapHandler(st.Validators), + validatorIndexCache: newFinalizedValidatorIndexCache(), //only used in post-electra and only populates when finalizing, otherwise it falls back to processing the full validator set } if features.Get().EnableExperimentalState { diff --git a/config/features/config.go b/config/features/config.go index 3926af4a2f0..98ae1ed49eb 100644 --- a/config/features/config.go +++ b/config/features/config.go @@ -74,9 +74,8 @@ type Flags struct { // BlobSaveFsync requires blob saving to block on fsync to ensure blobs are durably persisted before passing DA. BlobSaveFsync bool - SaveInvalidBlock bool // SaveInvalidBlock saves invalid block to temp. - SaveInvalidBlob bool // SaveInvalidBlob saves invalid blob to temp. - EIP6110ValidatorIndexCache bool // EIP6110ValidatorIndexCache specifies whether to use the new validator index cache. + SaveInvalidBlock bool // SaveInvalidBlock saves invalid block to temp. + SaveInvalidBlob bool // SaveInvalidBlob saves invalid blob to temp. // KeystoreImportDebounceInterval specifies the time duration the validator waits to reload new keys if they have // changed on disk. This feature is for advanced use cases only. @@ -256,11 +255,6 @@ func ConfigureBeaconChain(ctx *cli.Context) error { cfg.EnableQUIC = true } - if ctx.IsSet(eip6110ValidatorCache.Name) { - logEnabled(eip6110ValidatorCache) - cfg.EIP6110ValidatorIndexCache = true - } - cfg.AggregateIntervals = [3]time.Duration{aggregateFirstInterval.Value, aggregateSecondInterval.Value, aggregateThirdInterval.Value} Init(cfg) return nil diff --git a/config/features/flags.go b/config/features/flags.go index 3c731470443..af97adaaab8 100644 --- a/config/features/flags.go +++ b/config/features/flags.go @@ -166,11 +166,6 @@ var ( Name: "enable-quic", Usage: "Enables connection using the QUIC protocol for peers which support it.", } - // eip6110ValidatorCache is a flag for enabling the EIP-6110 validator cache. - eip6110ValidatorCache = &cli.BoolFlag{ - Name: "eip6110-validator-cache", - Usage: "Enables the EIP-6110 validator cache.", - } ) // devModeFlags holds list of flags that are set when development mode is on. @@ -228,7 +223,6 @@ var BeaconChainFlags = append(deprecatedBeaconFlags, append(deprecatedFlags, []c EnableLightClient, BlobSaveFsync, EnableQUIC, - eip6110ValidatorCache, }...)...) // E2EBeaconChainFlags contains a list of the beacon chain feature flags to be tested in E2E.