Skip to content

Commit

Permalink
refactor: avoid breaking change due to cosmos#16415 included in v0.50…
Browse files Browse the repository at this point in the history
… (backport cosmos#16430) (cosmos#16432)

Co-authored-by: Julien Robert <julien@rbrt.fr>
Co-authored-by: Facundo Medica <facundomedica@gmail.com>
  • Loading branch information
3 people authored and JeancarloBarrios committed Sep 28, 2024
1 parent 086573c commit 72cfa49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 2 additions & 4 deletions baseapp/circuit.go
Original file line number Diff line number Diff line change
@@ -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)
}
17 changes: 12 additions & 5 deletions baseapp/msg_service_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,21 @@ func (msr *MsgServiceRouter) registerMsgServiceHandler(sd *grpc.ServiceDesc, met
} 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)
Expand Down

0 comments on commit 72cfa49

Please sign in to comment.