Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: avoid breaking change due to #16415 included in v0.50 (backport #16430) #16432

Merged
merged 4 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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)
Expand Down