From 7ee780988b78c7de9b9d751128eec5615e0d0953 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 6 Jun 2023 18:50:35 +0200 Subject: [PATCH] refactor: avoid breaking change due to #16415 included in v0.50 (backport #16430) (#16432) Co-authored-by: Julien Robert Co-authored-by: Facundo Medica --- baseapp/circuit.go | 6 ++---- baseapp/msg_service_router.go | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/baseapp/circuit.go b/baseapp/circuit.go index 022ee6632c2e..3db0bc1bdcda 100644 --- a/baseapp/circuit.go +++ b/baseapp/circuit.go @@ -1,10 +1,8 @@ package baseapp -import ( - sdk "github.com/cosmos/cosmos-sdk/types" -) +import "context" // CircuitBreaker is an interface that defines the methods for a circuit breaker. type CircuitBreaker interface { - IsAllowed(ctx sdk.Context, typeURL string) bool + IsAllowed(ctx context.Context, typeURL string) (bool, error) } diff --git a/baseapp/msg_service_router.go b/baseapp/msg_service_router.go index a6494eebc6d1..b70864ddd287 100644 --- a/baseapp/msg_service_router.go +++ b/baseapp/msg_service_router.go @@ -125,14 +125,21 @@ func (msr *MsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler inter } else { return nil, err } + } - if msr.circuitBreaker != nil { - msgURL := sdk.MsgTypeURL(req) - if !msr.circuitBreaker.IsAllowed(ctx, msgURL) { - return nil, fmt.Errorf("circuit breaker disables execution of this message: %s", msgURL) - } + if msr.circuitBreaker != nil { + msgURL := sdk.MsgTypeURL(req) + + isAllowed, err := msr.circuitBreaker.IsAllowed(ctx, msgURL) + if err != nil { + return nil, err + } + + if !isAllowed { + return nil, fmt.Errorf("circuit breaker disables execution of this message: %s", msgURL) } } + // Call the method handler from the service description with the handler object. // We don't do any decoding here because the decoding was already done. res, err := methodHandler(handler, sdk.WrapSDKContext(ctx), noopDecoder, interceptor)