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

feat(x/circuit): add autocli options for tx #17956

Merged
merged 11 commits into from
Oct 6, 2023
40 changes: 39 additions & 1 deletion x/circuit/autocli.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package circuit

import (
"fmt"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
circuitv1 "cosmossdk.io/api/cosmos/circuit/v1"

"github.com/cosmos/cosmos-sdk/version"
)

func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
@@ -29,7 +33,41 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
},
},
Tx: &autocliv1.ServiceCommandDescriptor{
Service: circuitv1.Query_ServiceDesc.ServiceName,
Service: circuitv1.Msg_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "AuthorizeCircuitBreaker",
Use: "authorize [grantee] [permissions_json] --from [granter]",
Short: "Authorize an account to trip the circuit breaker.",
Long: `Authorize an account to trip the circuit breaker.
"SOME_MSGS" = 1,
"ALL_MSGS" = 2,
"SUPER_ADMIN" = 3,`,
Example: fmt.Sprintf(`%s circuit authorize [address] '{"level":1,"limit_type_urls":["cosmos.bank.v1beta1.MsgSend,cosmos.bank.v1beta1.MsgMultiSend"]}'"`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "grantee"},
{ProtoField: "permissions"}, // TODO(@julienrbrt) Support flattening msg for setting each field as a positional arg
},
},
{
RpcMethod: "TripCircuitBreaker",
Use: "disable [msg_type_urls]",
Short: "Disable a message from being executed",
Example: fmt.Sprintf(`%s circuit disable "cosmos.bank.v1beta1.MsgSend cosmos.bank.v1beta1.MsgMultiSend"`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "msg_type_urls", Varargs: true},
},
},
{
RpcMethod: "ResetCircuitBreaker",
Use: "reset [msg_type_urls]",
Short: "Enable a message to be executed",
Example: fmt.Sprintf(`%s circuit reset "cosmos.bank.v1beta1.MsgSend cosmos.bank.v1beta1.MsgMultiSend"`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "msg_type_urls", Varargs: true},
},
},
},
},
}
}
140 changes: 0 additions & 140 deletions x/circuit/client/cli/tx.go

This file was deleted.

4 changes: 2 additions & 2 deletions x/circuit/go.mod
Original file line number Diff line number Diff line change
@@ -8,22 +8,21 @@ require (
cosmossdk.io/core v0.12.0
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/errors v1.0.0
cosmossdk.io/math v1.1.3-rc.1
cosmossdk.io/store v1.0.0-rc.0
github.com/cockroachdb/errors v1.11.1
github.com/cometbft/cometbft v0.38.0
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/gogoproto v1.4.11
github.com/golang/protobuf v1.5.3
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb
google.golang.org/grpc v1.58.2
)

require (
cosmossdk.io/log v1.2.1 // indirect
cosmossdk.io/math v1.1.3-rc.1 // indirect
cosmossdk.io/x/tx v0.10.0 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
@@ -123,6 +122,7 @@ require (
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.16.0 // indirect
4 changes: 4 additions & 0 deletions x/circuit/keeper/msg_server.go
Original file line number Diff line number Diff line change
@@ -37,6 +37,10 @@ func (srv msgServer) AuthorizeCircuitBreaker(ctx context.Context, msg *types.Msg
// Check that the authorizer has the permission level of "super admin"
perms, err := srv.Permissions.Get(ctx, address)
if err != nil {
if errorsmod.IsOf(err, collections.ErrNotFound) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error is quite ugly otherwise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought this was fixed? something was removed and this was removed from other places

Copy link
Member Author

@julienrbrt julienrbrt Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you are thinking of another fix on the walk iterator (#17289).
This quite makes sense to return not found. We have such checks at other places in the SDK (e.g.

ubd, err = k.UnbondingDelegations.Get(ctx, collections.Join(delAddr, valAddr))
if err != nil {
if errors.Is(err, collections.ErrNotFound) {
return types.UnbondingDelegation{}, types.ErrNoUnbondingDelegation
}
return types.UnbondingDelegation{}, err
), to return a better human-readable error instead.

return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "only super admins can authorize users")
}

return nil, err
}

7 changes: 0 additions & 7 deletions x/circuit/module.go
Original file line number Diff line number Diff line change
@@ -7,14 +7,12 @@ import (
"time"

gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"

modulev1 "cosmossdk.io/api/cosmos/circuit/module/v1"
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/store"
"cosmossdk.io/depinject"
"cosmossdk.io/x/circuit/client/cli"
"cosmossdk.io/x/circuit/keeper"
"cosmossdk.io/x/circuit/types"

@@ -74,11 +72,6 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *g
}
}

// GetTxCmd returns the root tx command for the circuit module.
func (AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}

// RegisterInterfaces registers interfaces and implementations of the circuit module.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)