diff --git a/beacon-chain/blockchain/BUILD.bazel b/beacon-chain/blockchain/BUILD.bazel index b8297a34e..515518f14 100644 --- a/beacon-chain/blockchain/BUILD.bazel +++ b/beacon-chain/blockchain/BUILD.bazel @@ -84,6 +84,7 @@ go_test( "//beacon-chain/db/testing:go_default_library", "//beacon-chain/p2p:go_default_library", "//beacon-chain/powchain:go_default_library", + "//proto/beacon/db:go_default_library", "//proto/beacon/p2p/v1:go_default_library", "//shared/bytesutil:go_default_library", "//shared/event:go_default_library", diff --git a/beacon-chain/blockchain/service_test.go b/beacon-chain/blockchain/service_test.go index 5bed5533c..7238f5a43 100644 --- a/beacon-chain/blockchain/service_test.go +++ b/beacon-chain/blockchain/service_test.go @@ -26,6 +26,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/beacon-chain/powchain" beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state" + protodb "github.com/prysmaticlabs/prysm/proto/beacon/db" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/event" @@ -104,6 +105,25 @@ func setupBeaconChain(t *testing.T, beaconDB db.Database) *Service { ctx := context.Background() var web3Service *powchain.Service var err error + bState, _ := testutil.DeterministicGenesisState(t, 10) + err = beaconDB.SavePowchainData(ctx, &protodb.ETH1ChainData{ + BeaconState: bState.InnerStateUnsafe(), + Trie: &protodb.SparseMerkleTrie{}, + CurrentEth1Data: &protodb.LatestETH1Data{ + BlockHash: make([]byte, 32), + }, + ChainstartData: &protodb.ChainStartData{ + Eth1Data: ðpb.Eth1Data{ + DepositRoot: make([]byte, 32), + DepositCount: 0, + BlockHash: make([]byte, 32), + }, + }, + DepositContainers: []*protodb.DepositContainer{}, + }) + if err != nil { + t.Fatal(err) + } web3Service, err = powchain.NewService(ctx, &powchain.Web3ServiceConfig{ BeaconDB: beaconDB, ETH1Endpoint: endpoint, diff --git a/beacon-chain/core/helpers/BUILD.bazel b/beacon-chain/core/helpers/BUILD.bazel index fafc6022e..690074c84 100644 --- a/beacon-chain/core/helpers/BUILD.bazel +++ b/beacon-chain/core/helpers/BUILD.bazel @@ -27,7 +27,6 @@ go_library( "//proto/beacon/p2p/v1:go_default_library", "//shared/bls:go_default_library", "//shared/bytesutil:go_default_library", - "//shared/featureconfig:go_default_library", "//shared/hashutil:go_default_library", "//shared/params:go_default_library", "//shared/roughtime:go_default_library", diff --git a/beacon-chain/core/helpers/committee.go b/beacon-chain/core/helpers/committee.go index 61c2fac30..f4c7268a2 100644 --- a/beacon-chain/core/helpers/committee.go +++ b/beacon-chain/core/helpers/committee.go @@ -11,7 +11,6 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/cache" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/shared/bytesutil" - "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/sliceutil" @@ -429,9 +428,6 @@ func UpdateCommitteeCache(state *stateTrie.BeaconState, epoch uint64) error { // UpdateProposerIndicesInCache updates proposer indices entry of the committee cache. func UpdateProposerIndicesInCache(state *stateTrie.BeaconState, epoch uint64) error { - if !featureconfig.Get().EnableProposerIndexCache { - return nil - } indices, err := ActiveValidatorIndices(state, epoch) if err != nil { diff --git a/beacon-chain/core/helpers/validators.go b/beacon-chain/core/helpers/validators.go index f3fecbce7..629ed173e 100644 --- a/beacon-chain/core/helpers/validators.go +++ b/beacon-chain/core/helpers/validators.go @@ -7,7 +7,6 @@ import ( pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/bytesutil" - "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/params" ) @@ -150,21 +149,19 @@ func ValidatorChurnLimit(activeValidatorCount uint64) (uint64, error) { func BeaconProposerIndex(state *stateTrie.BeaconState) (uint64, error) { e := CurrentEpoch(state) - if featureconfig.Get().EnableProposerIndexCache { - seed, err := Seed(state, e, params.BeaconConfig().DomainBeaconAttester) - if err != nil { - return 0, errors.Wrap(err, "could not generate seed") - } - proposerIndices, err := committeeCache.ProposerIndices(seed) - if err != nil { - return 0, errors.Wrap(err, "could not interface with committee cache") - } - if proposerIndices != nil { - return proposerIndices[state.Slot()%params.BeaconConfig().SlotsPerEpoch], nil - } + seed, err := Seed(state, e, params.BeaconConfig().DomainBeaconAttester) + if err != nil { + return 0, errors.Wrap(err, "could not generate seed") + } + proposerIndices, err := committeeCache.ProposerIndices(seed) + if err != nil { + return 0, errors.Wrap(err, "could not interface with committee cache") + } + if proposerIndices != nil { + return proposerIndices[state.Slot()%params.BeaconConfig().SlotsPerEpoch], nil } - seed, err := Seed(state, e, params.BeaconConfig().DomainBeaconProposer) + seed, err = Seed(state, e, params.BeaconConfig().DomainBeaconProposer) if err != nil { return 0, errors.Wrap(err, "could not generate seed") } @@ -177,10 +174,8 @@ func BeaconProposerIndex(state *stateTrie.BeaconState) (uint64, error) { return 0, errors.Wrap(err, "could not get active indices") } - if featureconfig.Get().EnableProposerIndexCache { - if err := UpdateProposerIndicesInCache(state, CurrentEpoch(state)); err != nil { - return 0, errors.Wrap(err, "could not update committee cache") - } + if err := UpdateProposerIndicesInCache(state, CurrentEpoch(state)); err != nil { + return 0, errors.Wrap(err, "could not update committee cache") } return ComputeProposerIndex(state.Validators(), indices, seedWithSlotHash) diff --git a/beacon-chain/core/state/benchmarks_test.go b/beacon-chain/core/state/benchmarks_test.go index 5efcd066d..9ae0bfb24 100644 --- a/beacon-chain/core/state/benchmarks_test.go +++ b/beacon-chain/core/state/benchmarks_test.go @@ -53,8 +53,7 @@ func BenchmarkExecuteStateTransition_FullBlock(b *testing.B) { func BenchmarkExecuteStateTransition_WithCache(b *testing.B) { config := &featureconfig.Flags{ - EnableProposerIndexCache: true, - EnableAttestationCache: true, + EnableAttestationCache: true, } featureconfig.Init(config) benchutil.SetBenchmarkConfig() @@ -93,8 +92,7 @@ func BenchmarkExecuteStateTransition_WithCache(b *testing.B) { func BenchmarkProcessEpoch_2FullEpochs(b *testing.B) { config := &featureconfig.Flags{ - EnableProposerIndexCache: true, - EnableAttestationCache: true, + EnableAttestationCache: true, } featureconfig.Init(config) benchutil.SetBenchmarkConfig() diff --git a/beacon-chain/powchain/service.go b/beacon-chain/powchain/service.go index e37cd63a6..c52cdd9f7 100644 --- a/beacon-chain/powchain/service.go +++ b/beacon-chain/powchain/service.go @@ -423,6 +423,9 @@ func (s *Service) initDataFromContract() error { } func (s *Service) initDepositCaches(ctx context.Context, ctrs []*protodb.DepositContainer) error { + if ctrs == nil || len(ctrs) == 0 { + return nil + } s.depositCache.InsertDepositContainers(ctx, ctrs) currentState, err := s.beaconDB.HeadState(ctx) if err != nil { diff --git a/shared/featureconfig/config.go b/shared/featureconfig/config.go index 5f77e3ef2..7e0ee3b99 100644 --- a/shared/featureconfig/config.go +++ b/shared/featureconfig/config.go @@ -48,13 +48,12 @@ type Flags struct { DisableForkChoice bool // Cache toggles. - EnableAttestationCache bool // EnableAttestationCache; see https://github.com/prysmaticlabs/prysm/issues/3106. - EnableSSZCache bool // EnableSSZCache see https://github.com/prysmaticlabs/prysm/pull/4558. - EnableEth1DataVoteCache bool // EnableEth1DataVoteCache; see https://github.com/prysmaticlabs/prysm/issues/3106. - EnableSkipSlotsCache bool // EnableSkipSlotsCache caches the state in skipped slots. - EnableSlasherConnection bool // EnableSlasher enable retrieval of slashing events from a slasher instance. - EnableBlockTreeCache bool // EnableBlockTreeCache enable fork choice service to maintain latest filtered block tree. - EnableProposerIndexCache bool // EnableProposerIndexCache enable caching of proposer index. + EnableAttestationCache bool // EnableAttestationCache; see https://github.com/prysmaticlabs/prysm/issues/3106. + EnableSSZCache bool // EnableSSZCache see https://github.com/prysmaticlabs/prysm/pull/4558. + EnableEth1DataVoteCache bool // EnableEth1DataVoteCache; see https://github.com/prysmaticlabs/prysm/issues/3106. + EnableSkipSlotsCache bool // EnableSkipSlotsCache caches the state in skipped slots. + EnableSlasherConnection bool // EnableSlasher enable retrieval of slashing events from a slasher instance. + EnableBlockTreeCache bool // EnableBlockTreeCache enable fork choice service to maintain latest filtered block tree. } var featureConfig *Flags @@ -140,10 +139,6 @@ func ConfigureBeaconChain(ctx *cli.Context) { log.Warn("Enabled filtered block tree cache for fork choice.") cfg.EnableBlockTreeCache = true } - if ctx.GlobalBool(cacheProposerIndicesFlag.Name) { - log.Warn("Enabled proposer index caching.") - cfg.EnableProposerIndexCache = true - } if ctx.GlobalBool(protoArrayForkChoice.Name) { log.Warn("Enabled using proto array fork choice over spec fork choice.") cfg.ProtoArrayForkChoice = true diff --git a/shared/featureconfig/flags.go b/shared/featureconfig/flags.go index 92ae449e1..11bdb637c 100644 --- a/shared/featureconfig/flags.go +++ b/shared/featureconfig/flags.go @@ -80,10 +80,6 @@ var ( Usage: "Cache filtered block tree by maintaining it rather than continually recalculating on the fly, " + "this is used for fork choice.", } - cacheProposerIndicesFlag = cli.BoolFlag{ - Name: "cache-proposer-indices", - Usage: "Cache proposer indices on per epoch basis.", - } protectProposerFlag = cli.BoolFlag{ Name: "protect-proposer", Usage: "Prevent the validator client from signing and broadcasting 2 different block " + @@ -185,6 +181,11 @@ var ( Usage: deprecatedUsage, Hidden: true, } + deprecatedCacheProposerIndicesFlag = cli.BoolFlag{ + Name: "cache-proposer-indices", + Usage: deprecatedUsage, + Hidden: true, + } ) var deprecatedFlags = []cli.Flag{ @@ -204,6 +205,7 @@ var deprecatedFlags = []cli.Flag{ deprecatedNewCacheFlag, deprecatedEnableShuffledIndexCacheFlag, deprecatedSaveDepositDataFlag, + deprecatedCacheProposerIndicesFlag, } // ValidatorFlags contains a list of all the feature flags that apply to the validator client. @@ -236,7 +238,6 @@ var BeaconChainFlags = append(deprecatedFlags, []cli.Flag{ enableSkipSlotsCacheFlag, enableSlasherFlag, cacheFilteredBlockTreeFlag, - cacheProposerIndicesFlag, protoArrayForkChoice, }...)