From e771585b7723903c54c292d92b5cb72fe0190f86 Mon Sep 17 00:00:00 2001 From: terencechain Date: Thu, 12 May 2022 15:43:34 -0700 Subject: [PATCH] Fix `error.Is` ordering (#10685) * Fix error.is ordering for ErrUndefinedExecutionEngineError * Update BUILD.bazel --- beacon-chain/sync/BUILD.bazel | 1 + beacon-chain/sync/subscriber_beacon_blocks.go | 2 +- .../sync/subscriber_beacon_blocks_test.go | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index 7118016bf..e6149f374 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -223,6 +223,7 @@ go_test( "@com_github_libp2p_go_libp2p_pubsub//:go_default_library", "@com_github_libp2p_go_libp2p_pubsub//pb:go_default_library", "@com_github_patrickmn_go_cache//:go_default_library", + "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", "@com_github_sirupsen_logrus//hooks/test:go_default_library", diff --git a/beacon-chain/sync/subscriber_beacon_blocks.go b/beacon-chain/sync/subscriber_beacon_blocks.go index b12bc98ff..410b79d80 100644 --- a/beacon-chain/sync/subscriber_beacon_blocks.go +++ b/beacon-chain/sync/subscriber_beacon_blocks.go @@ -33,7 +33,7 @@ func (s *Service) beaconBlockSubscriber(ctx context.Context, msg proto.Message) } if err := s.cfg.chain.ReceiveBlock(ctx, signed, root); err != nil { - if !errors.Is(err, powchain.ErrHTTPTimeout) && !errors.Is(blockchain.ErrUndefinedExecutionEngineError, err) { + if !errors.Is(err, powchain.ErrHTTPTimeout) && !errors.Is(err, blockchain.ErrUndefinedExecutionEngineError) { interop.WriteBlockToDisk(signed, true /*failed*/) s.setBadBlock(ctx, root) } diff --git a/beacon-chain/sync/subscriber_beacon_blocks_test.go b/beacon-chain/sync/subscriber_beacon_blocks_test.go index e1285f3c6..98de24ede 100644 --- a/beacon-chain/sync/subscriber_beacon_blocks_test.go +++ b/beacon-chain/sync/subscriber_beacon_blocks_test.go @@ -4,7 +4,9 @@ import ( "context" "testing" + "github.com/pkg/errors" "github.com/prysmaticlabs/go-bitfield" + "github.com/prysmaticlabs/prysm/beacon-chain/blockchain" chainMock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" @@ -125,3 +127,21 @@ func TestService_BeaconBlockSubscribe_ExecutionEngineTimesOut(t *testing.T) { require.Equal(t, 0, len(s.badBlockCache.Keys())) require.Equal(t, 1, len(s.seenBlockCache.Keys())) } + +func TestService_BeaconBlockSubscribe_UndefinedEeError(t *testing.T) { + msg := "timeout" + err := errors.WithMessage(blockchain.ErrUndefinedExecutionEngineError, msg) + + s := &Service{ + cfg: &config{ + chain: &chainMock.ChainService{ + ReceiveBlockMockErr: err, + }, + }, + seenBlockCache: lruwrpr.New(10), + badBlockCache: lruwrpr.New(10), + } + require.ErrorIs(t, s.beaconBlockSubscriber(context.Background(), util.NewBeaconBlock()), blockchain.ErrUndefinedExecutionEngineError) + require.Equal(t, 0, len(s.badBlockCache.Keys())) + require.Equal(t, 1, len(s.seenBlockCache.Keys())) +}