diff --git a/beacon-chain/powchain/log_processing.go b/beacon-chain/powchain/log_processing.go index fa01db583..86ec0ac20 100644 --- a/beacon-chain/powchain/log_processing.go +++ b/beacon-chain/powchain/log_processing.go @@ -458,9 +458,12 @@ func (s *Service) checkHeaderRange(start uint64, end uint64, } func (s *Service) checkForChainstart(blockHash [32]byte, blockNumber *big.Int, blockTime uint64) { + if s.preGenesisState.NumValidators() == 0 { + return + } valCount, err := helpers.ActiveValidatorCount(s.preGenesisState, 0) if err != nil { - log.WithError(err).Error("Could not determine active validator count from pref genesis state") + log.WithError(err).Error("Could not determine active validator count from pre genesis state") } triggered := state.IsValidGenesisState(valCount, s.createGenesisTime(blockTime)) if triggered { diff --git a/beacon-chain/powchain/log_processing_test.go b/beacon-chain/powchain/log_processing_test.go index 8368fcd71..908a2ae35 100644 --- a/beacon-chain/powchain/log_processing_test.go +++ b/beacon-chain/powchain/log_processing_test.go @@ -622,6 +622,16 @@ func TestConsistentGenesisState(t *testing.T) { cancel() } +func TestCheckForChainstart_NoValidator(t *testing.T) { + hook := logTest.NewGlobal() + testAcc, err := contracts.Setup() + require.NoError(t, err, "Unable to set up simulated backend") + beaconDB, _ := testDB.SetupDB(t) + s := newPowchainService(t, testAcc, beaconDB) + s.checkForChainstart([32]byte{}, nil, 0) + testutil.AssertLogsDoNotContain(t, hook, "Could not determine active validator count from pre genesis state") +} + func newPowchainService(t *testing.T, eth1Backend *contracts.TestAccount, beaconDB db.Database) *Service { depositCache, err := depositcache.NewDepositCache() require.NoError(t, err)