mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
Check if initial sync service has been initialized (#8214)
This commit is contained in:
parent
c354871762
commit
7135a8542f
@ -127,7 +127,7 @@ func (s *Service) Stop() error {
|
||||
|
||||
// Status of initial sync.
|
||||
func (s *Service) Status() error {
|
||||
if s.synced.IsNotSet() && s.chainStarted.IsSet() {
|
||||
if s.Syncing() {
|
||||
return errors.New("syncing")
|
||||
}
|
||||
return nil
|
||||
@ -138,6 +138,11 @@ func (s *Service) Syncing() bool {
|
||||
return s.synced.IsNotSet()
|
||||
}
|
||||
|
||||
// Initialized returns true if initial sync has been started.
|
||||
func (s *Service) Initialized() bool {
|
||||
return s.chainStarted.IsSet()
|
||||
}
|
||||
|
||||
// Resync allows a node to start syncing again if it has fallen
|
||||
// behind the current network head.
|
||||
func (s *Service) Resync() error {
|
||||
|
@ -327,8 +327,9 @@ func TestService_markSynced(t *testing.T) {
|
||||
assert.Equal(t, false, s.chainStarted.IsSet())
|
||||
assert.Equal(t, false, s.synced.IsSet())
|
||||
assert.Equal(t, true, s.Syncing())
|
||||
assert.NoError(t, s.Status())
|
||||
assert.ErrorContains(t, "syncing", s.Status())
|
||||
s.chainStarted.Set()
|
||||
assert.Equal(t, true, s.Syncing())
|
||||
assert.ErrorContains(t, "syncing", s.Status())
|
||||
|
||||
expectedGenesisTime := time.Unix(358544700, 0)
|
||||
@ -359,6 +360,7 @@ func TestService_markSynced(t *testing.T) {
|
||||
}
|
||||
assert.Equal(t, expectedGenesisTime, receivedGenesisTime)
|
||||
assert.Equal(t, false, s.Syncing())
|
||||
assert.NoError(t, s.Status())
|
||||
}
|
||||
|
||||
func TestService_Resync(t *testing.T) {
|
||||
@ -436,3 +438,11 @@ func TestService_Resync(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestService_Initialized(t *testing.T) {
|
||||
s := NewService(context.Background(), &Config{})
|
||||
s.chainStarted.Set()
|
||||
assert.Equal(t, true, s.Initialized())
|
||||
s.chainStarted.UnSet()
|
||||
assert.Equal(t, false, s.Initialized())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user