Skip to content

Commit

Permalink
fix(dot/state) : Retrieve the parent header in case of KeyNotFound (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kishansagathiya committed Feb 27, 2023
1 parent 64dbba6 commit 2f5deb3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
3 changes: 1 addition & 2 deletions dot/state/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/ChainSafe/chaindb"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/blocktree"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/pkg/scale"
)
Expand Down Expand Up @@ -399,7 +398,7 @@ func (nem nextEpochMap[T]) Retrieve(blockState *BlockState, epoch uint64, header
// sometimes while moving to the next epoch is possible the header
// is not fully imported by the blocktree, in this case we will use
// its parent header which migth be already imported.
if errors.Is(err, blocktree.ErrEndNodeNotFound) {
if errors.Is(err, chaindb.ErrKeyNotFound) {
parentHeader, err := blockState.GetHeader(header.ParentHash)
if err != nil {
return nil, fmt.Errorf("cannot get parent header: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion dot/sync/chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (s *chainProcessor) processReadyBlocks() {

if err := s.processBlockData(*bd); err != nil {
// depending on the error, we might want to save this block for later
if !errors.Is(err, errFailedToGetParent) {
if !errors.Is(err, errFailedToGetParent) && !errors.Is(err, blocktree.ErrParentNotFound) {
logger.Errorf("block data processing for block with hash %s failed: %s", bd.Hash, err)
continue
}
Expand Down
1 change: 1 addition & 0 deletions lib/blocktree/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
// ErrEndNodeNotFound is returned if the end of a subchain does not exist
ErrEndNodeNotFound = errors.New("end node does not exist")

ErrKeyNotFound = errors.New("key not found")
// ErrNilDescendant is returned if calling subchain with a nil node
ErrNilDescendant = errors.New("descendant node is nil")

Expand Down
4 changes: 2 additions & 2 deletions lib/blocktree/leaves.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package blocktree

import (
"bytes"
"errors"
"fmt"
"sync"

"github.com/ChainSafe/gossamer/lib/common"
Expand Down Expand Up @@ -41,7 +41,7 @@ func (lm *leafMap) store(key Hash, value *node) {
func (lm *leafMap) load(key Hash) (*node, error) {
v, ok := lm.smap.Load(key)
if !ok {
return nil, errors.New("key not found")
return nil, fmt.Errorf("%w: %s", ErrKeyNotFound, key)
}

return v.(*node), nil
Expand Down

0 comments on commit 2f5deb3

Please sign in to comment.