Fix checkForChainStart pre-genesis state and 0 validator (#6739)

This commit is contained in:
terence tsao 2020-07-27 10:35:01 -07:00 committed by GitHub
parent 7fff4ec411
commit 905a57cbd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -458,9 +458,12 @@ func (s *Service) checkHeaderRange(start uint64, end uint64,
} }
func (s *Service) checkForChainstart(blockHash [32]byte, blockNumber *big.Int, blockTime 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) valCount, err := helpers.ActiveValidatorCount(s.preGenesisState, 0)
if err != nil { 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)) triggered := state.IsValidGenesisState(valCount, s.createGenesisTime(blockTime))
if triggered { if triggered {

View File

@ -622,6 +622,16 @@ func TestConsistentGenesisState(t *testing.T) {
cancel() 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 { func newPowchainService(t *testing.T, eth1Backend *contracts.TestAccount, beaconDB db.Database) *Service {
depositCache, err := depositcache.NewDepositCache() depositCache, err := depositcache.NewDepositCache()
require.NoError(t, err) require.NoError(t, err)