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: minor improvements to pr #13031

Merged
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
78 changes: 36 additions & 42 deletions api/cosmos/consensus_param/v1/query.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions baseapp/grpcrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,5 @@ func (qrt *GRPCQueryRouter) SetInterfaceRegistry(interfaceRegistry codectypes.In
qrt.cdc = codec.NewProtoCodec(interfaceRegistry).GRPCCodec()
// Once we have an interface registry, we can register the interface
// registry reflection gRPC service.
reflection.RegisterReflectionServiceServer(
qrt,
reflection.NewReflectionServiceServer(interfaceRegistry),
)
reflection.RegisterReflectionServiceServer(qrt, reflection.NewReflectionServiceServer(interfaceRegistry))
}
7 changes: 4 additions & 3 deletions client/grpc/reflection/reflection.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions client/grpc/tmservice/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions proto/cosmos/consensus_param/v1/query.proto
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
syntax = "proto3";
package cosmos.consensus_param.v1;

import "cosmos/base/query/v1beta1/pagination.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "tendermint/types/params.proto";

Expand Down
5 changes: 3 additions & 2 deletions x/auth/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/cosmos/cosmos-sdk/x/auth/types"
"reflect"
)

// HandlerOptions are the options required for constructing a default SDK AnteHandler.
Expand All @@ -23,11 +24,11 @@ type HandlerOptions struct {
// numbers, checks signatures & account numbers, and deducts fees from the first
// signer.
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
if reflect.ValueOf(options.AccountKeeper).IsNil() || reflect.ValueOf(options.AccountKeeper).IsZero() {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder")
}

if options.BankKeeper == nil {
if reflect.ValueOf(options.BankKeeper).IsNil() || reflect.ValueOf(options.BankKeeper).IsZero() {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder")
}

Expand Down
24 changes: 17 additions & 7 deletions x/consensus_param/exported/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

// ProtocolVersionSetter defines the interface fulfilled by BaseApp
// which allows setting it's appVersion field.
type ConsensusParamSetter interface {
Get(ctx sdk.Context) (*tmproto.ConsensusParams, error)
Has(ctx sdk.Context) bool
Set(ctx sdk.Context, cp *tmproto.ConsensusParams)
}
type (
// Subspace defines an interface that implements the legacy x/params Subspace
// type.
//
// NOTE: This is used solely for migration of x/params managed parameters.
Subspace interface {
Get(ctx sdk.Context) (*tmproto.ConsensusParams, error)
}

// ConsensusParamSetter ProtocolVersionSetter defines the interface fulfilled by BaseApp
// which allows setting its appVersion field.
ConsensusParamSetter interface {
Get(ctx sdk.Context) (*tmproto.ConsensusParams, error)
Has(ctx sdk.Context) bool
Set(ctx sdk.Context, cp *tmproto.ConsensusParams)
}
)
4 changes: 3 additions & 1 deletion x/consensus_param/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ import (

var _ types.QueryServer = Querier{}

// Querier is used as Keeper will have duplicate methods if used directly, and gRPC names take precedence over keeper
type Querier struct {
Keeper
}

// NewQuerier constructor for the Querier struct
func NewQuerier(keeper Keeper) Querier {
return Querier{Keeper: keeper}
}

// Balance implements the Query/Balance gRPC method
// Params Balance implements the Query/Balance gRPC method
func (k Querier) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

Expand Down
4 changes: 3 additions & 1 deletion x/consensus_param/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (k *Keeper) GetAuthority() string {
return k.authority
}

// Get gets the consensus parameters
func (k *Keeper) Get(ctx sdk.Context) (*tmproto.ConsensusParams, error) {
store := ctx.KVStore(k.storeKey)

Expand All @@ -50,8 +51,9 @@ func (k *Keeper) Has(ctx sdk.Context) bool {
return store.Has(types.ParamStoreKeyConsensusParams)
}

// Set sets the consensus parameters
func (k *Keeper) Set(ctx sdk.Context, cp *tmproto.ConsensusParams) {
store := ctx.KVStore(k.storeKey)

store := ctx.KVStore(k.storeKey)
store.Set(types.ParamStoreKeyConsensusParams, k.cdc.MustMarshal(cp))
}
62 changes: 55 additions & 7 deletions x/consensus_param/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ package bank

import (
"context"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
"encoding/json"

"github.com/cosmos/cosmos-sdk/runtime"
store "github.com/cosmos/cosmos-sdk/store/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"
Expand All @@ -16,6 +21,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/consensus_param/exported"
"github.com/cosmos/cosmos-sdk/x/consensus_param/keeper"
"github.com/cosmos/cosmos-sdk/x/consensus_param/types"

modulev1 "cosmossdk.io/api/cosmos/consensus_param/module/v1"
)

// ConsensusVersion defines the current x/bank module consensus version.
Expand All @@ -26,18 +33,18 @@ var (
_ module.AppModuleBasic = AppModuleBasic{}
)

// AppModuleBasic defines the basic application module used by the bank module.
// AppModuleBasic defines the basic application module used by the consensus_param module.
type AppModuleBasic struct {
cdc codec.Codec
}

// Name returns the bank module's name.
// Name returns the consensus_param module's name.
func (AppModuleBasic) Name() string { return types.ModuleName }

// RegisterLegacyAminoCodec registers the bank module's types on the LegacyAmino codec.
// RegisterLegacyAminoCodec registers the consensus_param module's types on the LegacyAmino codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {}

// DefaultGenesis returns default genesis state as raw bytes for the bank
// DefaultGenesis returns default genesis state as raw bytes for the consensus_param
// module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return nil
Expand Down Expand Up @@ -96,10 +103,10 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ss exported.Subspace) A
}
}

// Name returns the bank module's name.
// Name returns the consensus_param module's name.
func (AppModule) Name() string { return types.ModuleName }

// InitGenesis is handled by for init genesis of consensus params
// InitGenesis is handled by for init genesis of consensus_param
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
return nil
}
Expand All @@ -112,3 +119,44 @@ func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }

// RegisterInvariants does nothing, there are no invariants to enforce
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {}

func init() {
appmodule.Register(
&modulev1.Module{},
appmodule.Provide(provideModuleBasic, provideModule),
)
}

func provideModuleBasic() runtime.AppModuleBasicWrapper {
return runtime.WrapAppModuleBasic(AppModuleBasic{})
}

type consensusParamInputs struct {
depinject.In

Cdc codec.Codec
Key *store.KVStoreKey
ModuleKey depinject.OwnModuleKey
Authority map[string]sdk.AccAddress `optional:"true"`

// LegacySubspace is used solely for migration of x/params managed parameters
LegacySubspace exported.Subspace
}

type consensusParamOutputs struct {
depinject.Out

consensusParamKeeper keeper.Keeper
Module runtime.AppModuleWrapper
}

func provideModule(in consensusParamInputs) consensusParamOutputs {
authority, ok := in.Authority[depinject.ModuleKey(in.ModuleKey).Name()]
if !ok {
// default to governance authority if not provided
authority = authtypes.NewModuleAddress(govtypes.ModuleName)
}
k := keeper.NewKeeper(in.Cdc, in.Key, authority.String())
m := NewAppModule(in.Cdc, k, in.LegacySubspace)
return consensusParamOutputs{consensusParamKeeper: k, Module: runtime.WrapAppModule(m)}
}
Loading