Ignore nil node when saving orphaned atts (#10930)

* Ignore nil node when saving orphaned atts

* Just use ErrUnknownCommonAncestor
This commit is contained in:
terencechain
2022-06-24 11:07:31 -07:00
committed by GitHub
parent 2b6e86ec1b
commit b7463d0070
5 changed files with 9 additions and 9 deletions

View File

@@ -313,7 +313,7 @@ func (s *Service) notifyNewHeadEvent(
func (s *Service) saveOrphanedAtts(ctx context.Context, orphanedRoot [32]byte, newHeadRoot [32]byte) error {
commonAncestorRoot, err := s.ForkChoicer().CommonAncestorRoot(ctx, newHeadRoot, orphanedRoot)
switch {
// Exit early if there's no common ancestor as there would be nothing to save.
// Exit early if there's no common ancestor and root doesn't exist, there would be nothing to save.
case errors.Is(err, forkchoice.ErrUnknownCommonAncestor):
return nil
case err != nil:

View File

@@ -478,11 +478,11 @@ func (f *ForkChoice) CommonAncestorRoot(ctx context.Context, r1 [32]byte, r2 [32
n1, ok := f.store.nodeByRoot[r1]
if !ok || n1 == nil {
return [32]byte{}, errors.Wrap(ErrNilNode, "could not determine common ancestor root")
return [32]byte{}, forkchoice.ErrUnknownCommonAncestor
}
n2, ok := f.store.nodeByRoot[r2]
if !ok || n2 == nil {
return [32]byte{}, errors.Wrap(ErrNilNode, "could not determine common ancestor root")
return [32]byte{}, forkchoice.ErrUnknownCommonAncestor
}
for {

View File

@@ -535,9 +535,9 @@ func TestStore_CommonAncestor(t *testing.T) {
require.Equal(t, [32]byte{'a'}, r)
// Requesting unknown root
_, err = f.CommonAncestorRoot(ctx, [32]byte{'a'}, [32]byte{'z'})
require.ErrorIs(t, err, ErrNilNode)
require.ErrorIs(t, err, forkchoice.ErrUnknownCommonAncestor)
_, err = f.CommonAncestorRoot(ctx, [32]byte{'z'}, [32]byte{'a'})
require.ErrorIs(t, err, ErrNilNode)
require.ErrorIs(t, err, forkchoice.ErrUnknownCommonAncestor)
n := &Node{
slot: 100,
root: [32]byte{'y'},

View File

@@ -280,12 +280,12 @@ func (f *ForkChoice) CommonAncestorRoot(ctx context.Context, r1 [32]byte, r2 [32
i1, ok := f.store.nodesIndices[r1]
if !ok || i1 >= uint64(len(f.store.nodes)) {
return [32]byte{}, errInvalidNodeIndex
return [32]byte{}, forkchoice.ErrUnknownCommonAncestor
}
i2, ok := f.store.nodesIndices[r2]
if !ok || i2 >= uint64(len(f.store.nodes)) {
return [32]byte{}, errInvalidNodeIndex
return [32]byte{}, forkchoice.ErrUnknownCommonAncestor
}
for {

View File

@@ -802,9 +802,9 @@ func TestStore_CommonAncestor(t *testing.T) {
require.Equal(t, [32]byte{'a'}, r)
// Requesting unknown root
_, err = f.CommonAncestorRoot(ctx, [32]byte{'a'}, [32]byte{'z'})
require.ErrorIs(t, err, errInvalidNodeIndex)
require.ErrorIs(t, err, forkchoice.ErrUnknownCommonAncestor)
_, err = f.CommonAncestorRoot(ctx, [32]byte{'z'}, [32]byte{'a'})
require.ErrorIs(t, err, errInvalidNodeIndex)
require.ErrorIs(t, err, forkchoice.ErrUnknownCommonAncestor)
state, blkRoot, err = prepareForkchoiceState(ctx, 100, [32]byte{'y'}, [32]byte{'z'}, [32]byte{}, 1, 1)
require.NoError(t, err)
require.NoError(t, f.InsertNode(ctx, state, blkRoot))