Exit Initial Sync Early (#12659)

* add check

* fix test
This commit is contained in:
Nishant Das 2023-07-26 08:38:25 +08:00 committed by GitHub
parent 2b40c44879
commit 113172d8aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -89,6 +89,12 @@ func (s *Service) Start() {
log.Debug("Exiting Initial Sync Service")
return
}
// Exit entering round-robin sync if we require 0 peers to sync.
if flags.Get().MinimumSyncPeers == 0 {
s.markSynced()
log.WithField("genesisTime", gt).Info("Due to number of peers required for sync being set at 0, entering regular sync immediately.")
return
}
if gt.After(prysmTime.Now()) {
s.markSynced()
log.WithField("genesisTime", gt).Info("Genesis time has not arrived - not syncing")

View File

@ -31,6 +31,14 @@ func TestService_Constants(t *testing.T) {
func TestService_InitStartStop(t *testing.T) {
hook := logTest.NewGlobal()
resetFlags := flags.Get()
flags.Init(&flags.GlobalFlags{
MinimumSyncPeers: 1,
})
defer func() {
flags.Init(resetFlags)
}()
tests := []struct {
name string
assert func()