diff --git a/dot/digest/digest_test.go b/dot/digest/digest_test.go index d7bb59987d..256ff7fdda 100644 --- a/dot/digest/digest_test.go +++ b/dot/digest/digest_test.go @@ -176,6 +176,7 @@ func TestHandler_GrandpaPauseAndResume(t *testing.T) { require.NoError(t, err) nextPause, err := handler.grandpaState.(*state.GrandpaState).GetNextPause() require.NoError(t, err) + require.NotNil(t, nextPause) // ensure pause was found require.Equal(t, big.NewInt(int64(p.Delay)), nextPause) headers, _ := state.AddBlocksToState(t, handler.blockState.(*state.BlockState), 3, false) @@ -211,6 +212,7 @@ func TestHandler_GrandpaPauseAndResume(t *testing.T) { nextResume, err := handler.grandpaState.(*state.GrandpaState).GetNextResume() require.NoError(t, err) + require.NotNil(t, nextResume) // ensure resume was found require.Equal(t, big.NewInt(int64(r.Delay)+int64(p.Delay)), nextResume) } diff --git a/dot/state/grandpa.go b/dot/state/grandpa.go index 88c997ae74..0524801992 100644 --- a/dot/state/grandpa.go +++ b/dot/state/grandpa.go @@ -234,11 +234,14 @@ func (s *GrandpaState) SetNextPause(number *big.Int) error { } // GetNextPause returns the block number of the next grandpa pause. -// It returns an error on failure, which is contains the -// chaindb.ErrKeyNotFound error if the key is not found. +// If the key is not found in the database, a nil block number is returned +// to indicate there is no upcoming Grandpa pause. +// It returns an error on failure. func (s *GrandpaState) GetNextPause() (*big.Int, error) { num, err := s.db.Get(pauseKey) - if err != nil { + if errors.Is(err, chaindb.ErrKeyNotFound) { + return nil, nil //nolint:nilnil + } else if err != nil { return nil, err } @@ -251,11 +254,14 @@ func (s *GrandpaState) SetNextResume(number *big.Int) error { } // GetNextResume returns the block number of the next grandpa resume. -// It returns an error on failure, which is contains the -// chaindb.ErrKeyNotFound error if the key is not found. +// If the key is not found in the database, a nil block number is returned +// to indicate there is no upcoming Grandpa resume. +// It returns an error on failure. func (s *GrandpaState) GetNextResume() (*big.Int, error) { num, err := s.db.Get(resumeKey) - if err != nil { + if errors.Is(err, chaindb.ErrKeyNotFound) { + return nil, nil //nolint:nilnil + } else if err != nil { return nil, err }