From 576d8607890f8587eac269c15c701da2e1512a73 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 6 Jun 2023 16:29:25 +0200 Subject: [PATCH] refactor: avoid breaking change due to #16415 included in v0.50 (#16430) --- baseapp/circuit.go | 6 ++---- baseapp/msg_service_router.go | 8 +++++++- 2 files changed, 9 insertions(+), 5 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 ff448086b8bd..ec68ffd4c419 100644 --- a/baseapp/msg_service_router.go +++ b/baseapp/msg_service_router.go @@ -124,7 +124,13 @@ func (msr *MsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler inter if msr.circuitBreaker != nil { msgURL := sdk.MsgTypeURL(req) - if !msr.circuitBreaker.IsAllowed(ctx, msgURL) { + + 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) } }