Fix error.Is ordering (#10685)

* Fix error.is ordering for ErrUndefinedExecutionEngineError

* Update BUILD.bazel
This commit is contained in:
terencechain 2022-05-12 15:43:34 -07:00 committed by GitHub
parent 98622a052f
commit e771585b77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -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",

View File

@ -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)
}

View File

@ -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()))
}