Skip to content

Commit

Permalink
Return nil block number on Grandpa pause/resume not found
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Dec 6, 2021
1 parent 0330324 commit 4dddd84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions dot/digest/digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
18 changes: 12 additions & 6 deletions dot/state/grandpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 4dddd84

Please sign in to comment.