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)