refactor: migrate consensus to collections (#15553)

This commit is contained in:
Marko 2023-03-28 22:41:12 +02:00 committed by GitHub
parent 58634628b3
commit a5ad307ae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 278 additions and 361 deletions

View File

@ -96,6 +96,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (baseapp) [#15023](https://github.com/cosmos/cosmos-sdk/pull/15023) & [#15213](https://github.com/cosmos/cosmos-sdk/pull/15213) Add `MessageRouter` interface to baseapp and pass it to authz, gov and groups instead of concrete type.
* (simtestutil) [#15305](https://github.com/cosmos/cosmos-sdk/pull/15305) Add `AppStateFnWithExtendedCb` with callback function to extend rawState.
* (x/distribution) [#15462](https://github.com/cosmos/cosmos-sdk/pull/15462) Add delegator address to the event for withdrawing delegation rewards
* (x/consensus) [#15553](https://github.com/cosmos/cosmos-sdk/pull/15553) Migrate consensus module to use collections
### State Machine Breaking

View File

@ -902,29 +902,29 @@ var file_cosmos_consensus_v1_query_proto_rawDesc = []byte{
0x12, 0x39, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x21, 0x2e, 0x74, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x74, 0x2e, 0x74, 0x79,
0x70, 0x65, 0x73, 0x2e, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x50, 0x61, 0x72,
0x61, 0x6d, 0x73, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x32, 0x8a, 0x01, 0x0a, 0x05,
0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x80, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73,
0x12, 0x27, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e,
0x73, 0x75, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61,
0x6d, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, 0x2e, 0x63, 0x6f, 0x73, 0x6d,
0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2e, 0x76, 0x31, 0x2e,
0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x22, 0x23, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1d, 0x12, 0x1b, 0x2f, 0x63, 0x6f,
0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2f, 0x76,
0x31, 0x2f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x42, 0xc5, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d,
0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75,
0x73, 0x2e, 0x76, 0x31, 0x42, 0x0a, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x6f, 0x74, 0x6f,
0x50, 0x01, 0x5a, 0x30, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f,
0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x6e, 0x73,
0x65, 0x6e, 0x73, 0x75, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73,
0x75, 0x73, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x43, 0x58, 0xaa, 0x02, 0x13, 0x43, 0x6f, 0x73,
0x6d, 0x6f, 0x73, 0x2e, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2e, 0x56, 0x31,
0xca, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e,
0x73, 0x75, 0x73, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1f, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c,
0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42,
0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x15, 0x43, 0x6f, 0x73, 0x6d, 0x6f,
0x73, 0x3a, 0x3a, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x3a, 0x3a, 0x56, 0x31,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x61, 0x6d, 0x73, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x32, 0x8d, 0x01, 0x0a, 0x05,
0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x83, 0x01, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x50, 0x61, 0x72,
0x61, 0x6d, 0x73, 0x12, 0x27, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e,
0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50,
0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, 0x2e, 0x63,
0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2e,
0x76, 0x31, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x23, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1d, 0x12, 0x1b,
0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75,
0x73, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x42, 0xc5, 0x01, 0x0a, 0x17,
0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x65,
0x6e, 0x73, 0x75, 0x73, 0x2e, 0x76, 0x31, 0x42, 0x0a, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72,
0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x30, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b,
0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63,
0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x63, 0x6f, 0x6e, 0x73,
0x65, 0x6e, 0x73, 0x75, 0x73, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x43, 0x58, 0xaa, 0x02, 0x13,
0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73,
0x2e, 0x56, 0x31, 0xca, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x43, 0x6f, 0x6e,
0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1f, 0x43, 0x6f, 0x73, 0x6d,
0x6f, 0x73, 0x5c, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x5c, 0x56, 0x31, 0x5c,
0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x15, 0x43, 0x6f,
0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x3a,
0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -947,8 +947,8 @@ var file_cosmos_consensus_v1_query_proto_goTypes = []interface{}{
}
var file_cosmos_consensus_v1_query_proto_depIdxs = []int32{
2, // 0: cosmos.consensus.v1.QueryParamsResponse.params:type_name -> tendermint.types.ConsensusParams
0, // 1: cosmos.consensus.v1.Query.Params:input_type -> cosmos.consensus.v1.QueryParamsRequest
1, // 2: cosmos.consensus.v1.Query.Params:output_type -> cosmos.consensus.v1.QueryParamsResponse
0, // 1: cosmos.consensus.v1.Query.GetParams:input_type -> cosmos.consensus.v1.QueryParamsRequest
1, // 2: cosmos.consensus.v1.Query.GetParams:output_type -> cosmos.consensus.v1.QueryParamsResponse
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name

View File

@ -21,7 +21,7 @@ import (
const _ = grpc.SupportPackageIsVersion7
const (
Query_Params_FullMethodName = "/cosmos.consensus.v1.Query/Params"
Query_GetParams_FullMethodName = "/cosmos.consensus.v1.Query/GetParams"
)
// QueryClient is the client API for Query service.
@ -29,7 +29,7 @@ const (
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type QueryClient interface {
// Params queries the parameters of x/consensus_param module.
Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error)
GetParams(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error)
}
type queryClient struct {
@ -40,9 +40,9 @@ func NewQueryClient(cc grpc.ClientConnInterface) QueryClient {
return &queryClient{cc}
}
func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) {
func (c *queryClient) GetParams(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) {
out := new(QueryParamsResponse)
err := c.cc.Invoke(ctx, Query_Params_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, Query_GetParams_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
@ -54,7 +54,7 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts .
// for forward compatibility
type QueryServer interface {
// Params queries the parameters of x/consensus_param module.
Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error)
GetParams(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error)
mustEmbedUnimplementedQueryServer()
}
@ -62,8 +62,8 @@ type QueryServer interface {
type UnimplementedQueryServer struct {
}
func (UnimplementedQueryServer) Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Params not implemented")
func (UnimplementedQueryServer) GetParams(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetParams not implemented")
}
func (UnimplementedQueryServer) mustEmbedUnimplementedQueryServer() {}
@ -78,20 +78,20 @@ func RegisterQueryServer(s grpc.ServiceRegistrar, srv QueryServer) {
s.RegisterService(&Query_ServiceDesc, srv)
}
func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
func _Query_GetParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(QueryParamsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(QueryServer).Params(ctx, in)
return srv.(QueryServer).GetParams(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Query_Params_FullMethodName,
FullMethod: Query_GetParams_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest))
return srv.(QueryServer).GetParams(ctx, req.(*QueryParamsRequest))
}
return interceptor(ctx, in, info, handler)
}
@ -104,8 +104,8 @@ var Query_ServiceDesc = grpc.ServiceDesc{
HandlerType: (*QueryServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Params",
Handler: _Query_Params_Handler,
MethodName: "GetParams",
Handler: _Query_GetParams_Handler,
},
},
Streams: []grpc.StreamDesc{},

View File

@ -67,7 +67,7 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC
// done after the deliver state and context have been set as it's persisted
// to state.
if req.ConsensusParams != nil {
err := app.StoreConsensusParams(app.deliverState.ctx, req.ConsensusParams)
err := app.StoreConsensusParams(app.deliverState.ctx, *req.ConsensusParams)
if err != nil {
panic(err)
}
@ -239,9 +239,8 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc
res.Events = sdk.MarkEventsToIndex(res.Events, app.indexEvents)
}
if cp := app.GetConsensusParams(app.deliverState.ctx); cp != nil {
res.ConsensusParamUpdates = cp
}
cp := app.GetConsensusParams(app.deliverState.ctx)
res.ConsensusParamUpdates = &cp
// call the streaming service hook with the EndBlock messages
for _, abciListener := range app.streamingManager.ABCIListeners {
@ -880,7 +879,7 @@ func (app *BaseApp) GetBlockRetentionHeight(commitHeight int64) int64 {
// on the unbonding period and block commitment time as the two should be
// equivalent.
cp := app.GetConsensusParams(app.deliverState.ctx)
if cp != nil && cp.Evidence != nil && cp.Evidence.MaxAgeNumBlocks > 0 {
if cp.Evidence != nil && cp.Evidence.MaxAgeNumBlocks > 0 {
retentionHeight = commitHeight - cp.Evidence.MaxAgeNumBlocks
}

View File

@ -434,29 +434,25 @@ func (app *BaseApp) setState(mode runTxMode, header cmtproto.Header) {
// GetConsensusParams returns the current consensus parameters from the BaseApp's
// ParamStore. If the BaseApp has no ParamStore defined, nil is returned.
func (app *BaseApp) GetConsensusParams(ctx sdk.Context) *cmtproto.ConsensusParams {
func (app *BaseApp) GetConsensusParams(ctx sdk.Context) cmtproto.ConsensusParams {
if app.paramStore == nil {
return nil
return cmtproto.ConsensusParams{}
}
cp, err := app.paramStore.Get(ctx)
if err != nil {
panic(err)
panic(fmt.Errorf("consensus key is nil: %w", err))
}
return cp
}
// StoreConsensusParams sets the consensus parameters to the baseapp's param store.
func (app *BaseApp) StoreConsensusParams(ctx sdk.Context, cp *cmtproto.ConsensusParams) error {
func (app *BaseApp) StoreConsensusParams(ctx sdk.Context, cp cmtproto.ConsensusParams) error {
if app.paramStore == nil {
panic("cannot store consensus params with no params store set")
}
if cp == nil {
return nil
}
return app.paramStore.Set(ctx, cp)
// We're explicitly not storing the CometBFT app_version in the param store. It's
// stored instead in the x/upgrade store, with its own bump logic.
@ -474,7 +470,7 @@ func (app *BaseApp) AddRunTxRecoveryHandler(handlers ...RecoveryHandler) {
// one.
func (app *BaseApp) GetMaximumBlockGas(ctx sdk.Context) uint64 {
cp := app.GetConsensusParams(ctx)
if cp == nil || cp.Block == nil {
if cp.Block == nil {
return 0
}

View File

@ -67,7 +67,7 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite
app.SetInterfaceRegistry(cdc.InterfaceRegistry())
app.MsgServiceRouter().SetInterfaceRegistry(cdc.InterfaceRegistry())
app.MountStores(capKey1, capKey2)
app.SetParamStore(&paramStore{db: dbm.NewMemDB()})
app.SetParamStore(paramStore{db: dbm.NewMemDB()})
app.SetTxDecoder(txConfig.TxDecoder())
app.SetTxEncoder(txConfig.TxEncoder())
@ -587,16 +587,16 @@ func TestGetMaximumBlockGas(t *testing.T) {
suite.baseApp.InitChain(abci.RequestInitChain{})
ctx := suite.baseApp.NewContext(true, cmtproto.Header{})
suite.baseApp.StoreConsensusParams(ctx, &cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: 0}})
suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: 0}})
require.Equal(t, uint64(0), suite.baseApp.GetMaximumBlockGas(ctx))
suite.baseApp.StoreConsensusParams(ctx, &cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: -1}})
suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: -1}})
require.Equal(t, uint64(0), suite.baseApp.GetMaximumBlockGas(ctx))
suite.baseApp.StoreConsensusParams(ctx, &cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: 5000000}})
suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: 5000000}})
require.Equal(t, uint64(5000000), suite.baseApp.GetMaximumBlockGas(ctx))
suite.baseApp.StoreConsensusParams(ctx, &cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: -5000000}})
suite.baseApp.StoreConsensusParams(ctx, cmtproto.ConsensusParams{Block: &cmtproto.BlockParams{MaxGas: -5000000}})
require.Panics(t, func() { suite.baseApp.GetMaximumBlockGas(ctx) })
}

View File

@ -9,7 +9,7 @@ import (
// ParamStore defines the interface the parameter store used by the BaseApp must
// fulfill.
type ParamStore interface {
Get(ctx context.Context) (*cmtproto.ConsensusParams, error)
Get(ctx context.Context) (cmtproto.ConsensusParams, error)
Has(ctx context.Context) (bool, error)
Set(ctx context.Context, cp *cmtproto.ConsensusParams) error
Set(ctx context.Context, cp cmtproto.ConsensusParams) error
}

View File

@ -138,10 +138,13 @@ func GetConsensusParams(ctx sdk.Context, paramStore LegacyParamStore) *cmtproto.
return cp
}
func MigrateParams(ctx sdk.Context, lps LegacyParamStore, ps ParamStore) {
func MigrateParams(ctx sdk.Context, lps LegacyParamStore, ps ParamStore) error {
if cp := GetConsensusParams(ctx, lps); cp != nil {
ps.Set(ctx, cp)
if err := ps.Set(ctx, *cp); err != nil {
return err
}
} else {
ctx.Logger().Info("warning: consensus parameters are undefined; skipping migration")
}
return nil
}

View File

@ -241,7 +241,7 @@ type paramStore struct {
var _ baseapp.ParamStore = (*paramStore)(nil)
func (ps *paramStore) Set(_ context.Context, value *cmtproto.ConsensusParams) error {
func (ps paramStore) Set(_ context.Context, value cmtproto.ConsensusParams) error {
bz, err := json.Marshal(value)
if err != nil {
return err
@ -250,26 +250,26 @@ func (ps *paramStore) Set(_ context.Context, value *cmtproto.ConsensusParams) er
return ps.db.Set(ParamStoreKey, bz)
}
func (ps *paramStore) Has(_ context.Context) (bool, error) {
func (ps paramStore) Has(_ context.Context) (bool, error) {
return ps.db.Has(ParamStoreKey)
}
func (ps paramStore) Get(ctx context.Context) (*cmtproto.ConsensusParams, error) {
func (ps paramStore) Get(_ context.Context) (cmtproto.ConsensusParams, error) {
bz, err := ps.db.Get(ParamStoreKey)
if err != nil {
return nil, err
return cmtproto.ConsensusParams{}, err
}
if len(bz) == 0 {
return nil, errors.New("params not found")
return cmtproto.ConsensusParams{}, errors.New("params not found")
}
var params cmtproto.ConsensusParams
if err := json.Unmarshal(bz, &params); err != nil {
return nil, err
return cmtproto.ConsensusParams{}, err
}
return &params, nil
return params, nil
}
func setTxSignature(t *testing.T, builder client.TxBuilder, nonce uint64) {

View File

@ -10,16 +10,16 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/consensus/types";
// Query defines the gRPC querier service.
service Query {
// Params queries the parameters of x/consensus_param module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
rpc GetParams(QueryGetParamsRequest) returns (QueryGetParamsResponse) {
option (google.api.http).get = "/cosmos/consensus/v1/params";
}
}
// QueryParamsRequest defines the request type for querying x/consensus parameters.
message QueryParamsRequest {}
message QueryGetParamsRequest {}
// QueryParamsResponse defines the response type for querying x/consensus parameters.
message QueryParamsResponse {
message QueryGetParamsResponse {
// params are the tendermint consensus params stored in the consensus module.
// Please note that `params.version` is not populated in this response, it is
// tracked separately in the x/upgrade module.

View File

@ -101,7 +101,7 @@ func isZeroExportedApp(a types.ExportedApp) bool {
return a.AppState == nil &&
len(a.Validators) == 0 &&
a.Height == 0 &&
a.ConsensusParams == nil
a.ConsensusParams == cmtproto.ConsensusParams{}
}
// mockExporter provides an Export method matching server/types.AppExporter,
@ -127,7 +127,7 @@ type mockExporter struct {
// when e.Export is called.
func (e *mockExporter) SetDefaultExportApp() {
e.ExportApp = types.ExportedApp{
ConsensusParams: &cmtproto.ConsensusParams{
ConsensusParams: cmtproto.ConsensusParams{
Block: &cmtproto.BlockParams{
MaxBytes: 5 * 1024 * 1024,
MaxGas: -1,

View File

@ -5,12 +5,11 @@ import (
"testing"
"time"
"cosmossdk.io/log"
abci "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/stretchr/testify/require"
"cosmossdk.io/log"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
)

View File

@ -73,7 +73,7 @@ type (
// Height is the app's latest block height.
Height int64
// ConsensusParams are the exported consensus params for ABCI.
ConsensusParams *cmtproto.ConsensusParams
ConsensusParams cmtproto.ConsensusParams
}
// AppExporter is a function that dumps all app state to

View File

@ -286,7 +286,7 @@ func NewSimApp(
// set the BaseApp's parameter store
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName).String())
bApp.SetParamStore(&app.ConsensusParamsKeeper)
bApp.SetParamStore(app.ConsensusParamsKeeper.Params)
// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String())

View File

@ -64,7 +64,9 @@ func (app SimApp) RegisterUpgradeHandlers() {
UpgradeName,
func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// Migrate CometBFT consensus parameters from x/params module to a dedicated x/consensus module.
baseapp.MigrateParams(ctx, baseAppLegacySS, &app.ConsensusParamsKeeper)
if err := baseapp.MigrateParams(ctx, baseAppLegacySS, app.ConsensusParamsKeeper.Params); err != nil {
return nil, err
}
// Note: this migration is optional,
// You can include x/gov proposal migration documented in [UPGRADING.md](https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md)

View File

@ -35,7 +35,7 @@ type Context struct {
checkTx bool
recheckTx bool // if recheckTx == true, then checkTx must also be true
minGasPrice DecCoins
consParams *cmtproto.ConsensusParams
consParams cmtproto.ConsensusParams
eventManager EventManagerI
priority int64 // The tx priority, only relevant in CheckTx
kvGasConfig storetypes.GasConfig
@ -79,8 +79,8 @@ func (c Context) HeaderHash() []byte {
return hash
}
func (c Context) ConsensusParams() *cmtproto.ConsensusParams {
return proto.Clone(c.consParams).(*cmtproto.ConsensusParams)
func (c Context) ConsensusParams() cmtproto.ConsensusParams {
return c.consParams
}
func (c Context) Deadline() (deadline time.Time, ok bool) {
@ -239,7 +239,7 @@ func (c Context) WithMinGasPrices(gasPrices DecCoins) Context {
}
// WithConsensusParams returns a Context with an updated consensus params
func (c Context) WithConsensusParams(params *cmtproto.ConsensusParams) Context {
func (c Context) WithConsensusParams(params cmtproto.ConsensusParams) Context {
c.consParams = params
return c
}

View File

@ -134,8 +134,8 @@ func (s *contextTestSuite) TestContextWithCustom() {
s.Require().True(ctx.IsReCheckTx())
// test consensus param
s.Require().Nil(ctx.ConsensusParams())
cp := &cmtproto.ConsensusParams{}
s.Require().Equal(cmtproto.ConsensusParams{}, ctx.ConsensusParams())
cp := cmtproto.ConsensusParams{}
s.Require().Equal(cp, ctx.WithConsensusParams(cp).ConsensusParams())
// test inner context

View File

@ -1,35 +0,0 @@
package keeper
import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/consensus/types"
)
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}
}
// Params queries params of consensus module
func (k Querier) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
params, err := k.Keeper.Get(sdkCtx)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &types.QueryParamsResponse{Params: params}, nil
}

View File

@ -1,61 +0,0 @@
package keeper_test
import (
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmttypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/x/consensus/types"
)
func (s *KeeperTestSuite) TestGRPCQueryConsensusParams() {
defaultConsensusParams := cmttypes.DefaultConsensusParams().ToProto()
testCases := []struct {
msg string
req types.QueryParamsRequest
malleate func()
response types.QueryParamsResponse
expPass bool
}{
{
"success",
types.QueryParamsRequest{},
func() {
input := &types.MsgUpdateParams{
Authority: s.consensusParamsKeeper.GetAuthority(),
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
}
s.msgServer.UpdateParams(s.ctx, input)
},
types.QueryParamsResponse{
Params: &cmtproto.ConsensusParams{
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
Version: defaultConsensusParams.Version,
},
},
true,
},
}
for _, tc := range testCases {
s.Run(tc.msg, func() {
s.SetupTest() // reset
tc.malleate()
res, err := s.queryClient.Params(s.ctx, &tc.req)
if tc.expPass {
s.Require().NoError(err)
s.Require().NotNil(res)
s.Require().Equal(tc.response.Params, res.Params)
} else {
s.Require().Error(err)
s.Require().Nil(res)
}
})
}
}

View File

@ -3,29 +3,34 @@ package keeper
import (
"context"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"cosmossdk.io/collections"
storetypes "cosmossdk.io/core/store"
"cosmossdk.io/errors"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmttypes "github.com/cometbft/cometbft/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/consensus/exported"
"github.com/cosmos/cosmos-sdk/x/consensus/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
var _ exported.ConsensusParamSetter = (*Keeper)(nil)
var StoreKey = "Consensus"
type Keeper struct {
storeService storetypes.KVStoreService
cdc codec.BinaryCodec
authority string
Params collections.Item[cmtproto.ConsensusParams]
}
func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, authority string) Keeper {
sb := collections.NewSchemaBuilder(storeService)
return Keeper{
storeService: storeService,
cdc: cdc,
authority: authority,
Params: collections.NewItem(sb, collections.NewPrefix("Consensus"), "params", codec.CollValue[cmtproto.ConsensusParams](cdc)),
}
}
@ -33,30 +38,37 @@ func (k *Keeper) GetAuthority() string {
return k.authority
}
// Get gets the consensus parameters
func (k *Keeper) Get(ctx context.Context) (*cmtproto.ConsensusParams, error) {
store := k.storeService.OpenKVStore(ctx)
// Querier
bz, err := store.Get(types.ParamStoreKeyConsensusParams)
var _ types.QueryServer = Keeper{}
// Params queries params of consensus module
func (k Keeper) GetParams(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
params, err := k.Params.Get(ctx)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &types.QueryParamsResponse{Params: &params}, nil
}
// MsgServer
var _ types.MsgServer = Keeper{}
func (k Keeper) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.GetAuthority() != req.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority)
}
consensusParams := req.ToProtoConsensusParams()
if err := cmttypes.ConsensusParamsFromProto(consensusParams).ValidateBasic(); err != nil {
return nil, err
}
cp := &cmtproto.ConsensusParams{}
if err := k.cdc.Unmarshal(bz, cp); err != nil {
if err := k.Params.Set(ctx, consensusParams); err != nil {
return nil, err
}
return cp, nil
}
func (k *Keeper) Has(ctx context.Context) (bool, error) {
store := k.storeService.OpenKVStore(ctx)
return store.Has(types.ParamStoreKeyConsensusParams)
}
// Set sets the consensus parameters
func (k *Keeper) Set(ctx context.Context, cp *cmtproto.ConsensusParams) error {
store := k.storeService.OpenKVStore(ctx)
return store.Set(types.ParamStoreKeyConsensusParams, k.cdc.MustMarshal(cp))
return &types.MsgUpdateParamsResponse{}, nil
}

View File

@ -4,6 +4,7 @@ import (
"testing"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmttypes "github.com/cometbft/cometbft/types"
"github.com/stretchr/testify/suite"
storetypes "cosmossdk.io/store/types"
@ -15,7 +16,7 @@ import (
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
"github.com/cosmos/cosmos-sdk/x/consensus/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
@ -24,12 +25,11 @@ type KeeperTestSuite struct {
ctx sdk.Context
consensusParamsKeeper *consensusparamkeeper.Keeper
queryClient consensusparamtypes.QueryClient
msgServer consensusparamtypes.MsgServer
queryClient types.QueryClient
}
func (s *KeeperTestSuite) SetupTest() {
key := storetypes.NewKVStoreKey(consensusparamtypes.StoreKey)
key := storetypes.NewKVStoreKey(consensusparamkeeper.StoreKey)
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{})
encCfg := moduletestutil.MakeTestEncodingConfig()
@ -40,13 +40,123 @@ func (s *KeeperTestSuite) SetupTest() {
s.ctx = ctx
s.consensusParamsKeeper = &keeper
consensusparamtypes.RegisterInterfaces(encCfg.InterfaceRegistry)
types.RegisterInterfaces(encCfg.InterfaceRegistry)
queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry)
consensusparamtypes.RegisterQueryServer(queryHelper, consensusparamkeeper.NewQuerier(keeper))
s.queryClient = consensusparamtypes.NewQueryClient(queryHelper)
s.msgServer = consensusparamkeeper.NewMsgServerImpl(keeper)
types.RegisterQueryServer(queryHelper, keeper)
s.queryClient = types.NewQueryClient(queryHelper)
}
func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}
func (s *KeeperTestSuite) TestGRPCQueryConsensusParams() {
defaultConsensusParams := cmttypes.DefaultConsensusParams().ToProto()
testCases := []struct {
msg string
req types.QueryParamsRequest
malleate func()
response types.QueryParamsResponse
expPass bool
}{
{
"success",
types.QueryParamsRequest{},
func() {
input := &types.MsgUpdateParams{
Authority: s.consensusParamsKeeper.GetAuthority(),
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
}
s.consensusParamsKeeper.UpdateParams(s.ctx, input)
},
types.QueryParamsResponse{
Params: &cmtproto.ConsensusParams{
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
Version: defaultConsensusParams.Version,
},
},
true,
},
}
for _, tc := range testCases {
s.Run(tc.msg, func() {
s.SetupTest() // reset
tc.malleate()
res, err := s.consensusParamsKeeper.GetParams(s.ctx, &tc.req)
if tc.expPass {
s.Require().NoError(err)
s.Require().NotNil(res)
s.Require().Equal(tc.response.Params, res.Params)
} else {
s.Require().Error(err)
s.Require().Nil(res)
}
})
}
}
func (s *KeeperTestSuite) TestUpdateParams() {
defaultConsensusParams := cmttypes.DefaultConsensusParams().ToProto()
testCases := []struct {
name string
input *types.MsgUpdateParams
expErr bool
expErrMsg string
}{
{
name: "valid params",
input: &types.MsgUpdateParams{
Authority: s.consensusParamsKeeper.GetAuthority(),
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
},
expErr: false,
expErrMsg: "",
},
{
name: "invalid params",
input: &types.MsgUpdateParams{
Authority: s.consensusParamsKeeper.GetAuthority(),
Block: &cmtproto.BlockParams{MaxGas: -10, MaxBytes: -10},
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
},
expErr: true,
expErrMsg: "block.MaxBytes must be greater than 0. Got -10",
},
{
name: "invalid authority",
input: &types.MsgUpdateParams{
Authority: "invalid",
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
},
expErr: true,
expErrMsg: "invalid authority",
},
}
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
s.SetupTest()
_, err := s.consensusParamsKeeper.UpdateParams(s.ctx, tc.input)
if tc.expErr {
s.Require().Error(err)
s.Require().Contains(err.Error(), tc.expErrMsg)
} else {
s.Require().NoError(err)
}
})
}
}

View File

@ -1,42 +0,0 @@
package keeper
import (
"context"
cmttypes "github.com/cometbft/cometbft/types"
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/consensus/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
type msgServer struct {
Keeper
}
var _ types.MsgServer = msgServer{}
// NewMsgServerImpl returns an implementation of the bank MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
return &msgServer{Keeper: keeper}
}
func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.GetAuthority() != req.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority)
}
ctx := sdk.UnwrapSDKContext(goCtx)
consensusParams := req.ToProtoConsensusParams()
if err := cmttypes.ConsensusParamsFromProto(consensusParams).ValidateBasic(); err != nil {
return nil, err
}
k.Set(ctx, &consensusParams)
return &types.MsgUpdateParamsResponse{}, nil
}

View File

@ -1,65 +0,0 @@
package keeper_test
import (
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmttypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/x/consensus/types"
)
func (s *KeeperTestSuite) TestUpdateParams() {
defaultConsensusParams := cmttypes.DefaultConsensusParams().ToProto()
testCases := []struct {
name string
input *types.MsgUpdateParams
expErr bool
expErrMsg string
}{
{
name: "valid params",
input: &types.MsgUpdateParams{
Authority: s.consensusParamsKeeper.GetAuthority(),
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
},
expErr: false,
expErrMsg: "",
},
{
name: "invalid params",
input: &types.MsgUpdateParams{
Authority: s.consensusParamsKeeper.GetAuthority(),
Block: &cmtproto.BlockParams{MaxGas: -10, MaxBytes: -10},
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
},
expErr: true,
expErrMsg: "block.MaxBytes must be greater than 0. Got -10",
},
{
name: "invalid authority",
input: &types.MsgUpdateParams{
Authority: "invalid",
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
},
expErr: true,
expErrMsg: "invalid authority",
},
}
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
s.SetupTest()
_, err := s.msgServer.UpdateParams(s.ctx, tc.input)
if tc.expErr {
s.Require().Error(err)
s.Require().Contains(err.Error(), tc.expErrMsg)
} else {
s.Require().NoError(err)
}
})
}
}

View File

@ -102,8 +102,8 @@ func (am AppModule) IsAppModule() {}
// RegisterServices registers module services.
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(registrar, keeper.NewQuerier(am.keeper))
types.RegisterMsgServer(registrar, am.keeper)
types.RegisterQueryServer(registrar, am.keeper)
return nil
}
@ -168,7 +168,7 @@ func ProvideModule(in ConsensusInputs) ConsensusOutputs {
k := keeper.NewKeeper(in.Cdc, in.StoreService, authority.String())
m := NewAppModule(in.Cdc, k)
baseappOpt := func(app *baseapp.BaseApp) {
app.SetParamStore(&k)
app.SetParamStore(k.Params)
}
return ConsensusOutputs{

View File

@ -7,5 +7,3 @@ const (
// StoreKey defines the module's store key.
StoreKey = ModuleName
)
var ParamStoreKeyConsensusParams = []byte("Consensus")

View File

@ -122,7 +122,7 @@ func init() {
func init() { proto.RegisterFile("cosmos/consensus/v1/query.proto", fileDescriptor_bf54d1e5df04cee9) }
var fileDescriptor_bf54d1e5df04cee9 = []byte{
// 279 bytes of a gzipped FileDescriptorProto
// 282 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4f, 0xce, 0x2f, 0xce,
0xcd, 0x2f, 0xd6, 0x4f, 0xce, 0xcf, 0x2b, 0x4e, 0xcd, 0x2b, 0x2e, 0x2d, 0xd6, 0x2f, 0x33, 0xd4,
0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0x28, 0xd0,
@ -133,14 +133,14 @@ var fileDescriptor_bf54d1e5df04cee9 = []byte{
0x08, 0x00, 0x0b, 0x06, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x28, 0x05, 0x70, 0x09, 0xa3, 0x88,
0x16, 0x17, 0x80, 0x2c, 0x14, 0xb2, 0xe4, 0x62, 0x83, 0x68, 0x96, 0x60, 0x54, 0x60, 0xd4, 0xe0,
0x36, 0x52, 0xd4, 0x43, 0x18, 0xae, 0x07, 0x36, 0x5c, 0xcf, 0x19, 0xe6, 0x32, 0xa8, 0x56, 0xa8,
0x06, 0xa3, 0x2e, 0x46, 0x2e, 0x56, 0xb0, 0x91, 0x42, 0x0d, 0x8c, 0x5c, 0x6c, 0x10, 0x49, 0x21,
0x75, 0x3d, 0x2c, 0xfe, 0xd1, 0xc3, 0x74, 0x8f, 0x94, 0x06, 0x61, 0x85, 0x10, 0x27, 0x2a, 0x29,
0x37, 0x5d, 0x7e, 0x32, 0x99, 0x49, 0x56, 0x48, 0x5a, 0x1f, 0x5b, 0x58, 0x42, 0x1c, 0xe3, 0xe4,
0x71, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c,
0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x7a, 0xe9, 0x99, 0x25, 0x19,
0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0x08, 0x03, 0x40, 0x94, 0x6e, 0x71, 0x4a, 0xb6, 0x7e, 0x05,
0x92, 0x69, 0x60, 0xef, 0x26, 0xb1, 0x81, 0x43, 0xd1, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x1b,
0xa2, 0x35, 0xa1, 0xba, 0x01, 0x00, 0x00,
0x06, 0xa3, 0x5e, 0x46, 0x2e, 0x56, 0xb0, 0x91, 0x42, 0xcd, 0x8c, 0x5c, 0x9c, 0xee, 0xa9, 0x25,
0x10, 0x79, 0x21, 0x75, 0x3d, 0x2c, 0x5e, 0xd2, 0xc3, 0x74, 0x92, 0x94, 0x06, 0x61, 0x85, 0x10,
0x57, 0x2a, 0x29, 0x37, 0x5d, 0x7e, 0x32, 0x99, 0x49, 0x56, 0x48, 0x5a, 0x1f, 0x5b, 0x70, 0x42,
0xdc, 0xe3, 0xe4, 0x71, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31,
0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x7a, 0xe9,
0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0x08, 0x03, 0x40, 0x94, 0x6e, 0x71, 0x4a,
0xb6, 0x7e, 0x05, 0x92, 0x69, 0x60, 0x1f, 0x27, 0xb1, 0x81, 0x03, 0xd2, 0x18, 0x10, 0x00, 0x00,
0xff, 0xff, 0xbd, 0x10, 0x4d, 0x37, 0xbd, 0x01, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
@ -156,7 +156,7 @@ const _ = grpc.SupportPackageIsVersion4
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type QueryClient interface {
// Params queries the parameters of x/consensus_param module.
Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error)
GetParams(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error)
}
type queryClient struct {
@ -167,9 +167,9 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient {
return &queryClient{cc}
}
func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) {
func (c *queryClient) GetParams(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) {
out := new(QueryParamsResponse)
err := c.cc.Invoke(ctx, "/cosmos.consensus.v1.Query/Params", in, out, opts...)
err := c.cc.Invoke(ctx, "/cosmos.consensus.v1.Query/GetParams", in, out, opts...)
if err != nil {
return nil, err
}
@ -179,35 +179,35 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts .
// QueryServer is the server API for Query service.
type QueryServer interface {
// Params queries the parameters of x/consensus_param module.
Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error)
GetParams(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error)
}
// UnimplementedQueryServer can be embedded to have forward compatible implementations.
type UnimplementedQueryServer struct {
}
func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Params not implemented")
func (*UnimplementedQueryServer) GetParams(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetParams not implemented")
}
func RegisterQueryServer(s grpc1.Server, srv QueryServer) {
s.RegisterService(&_Query_serviceDesc, srv)
}
func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
func _Query_GetParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(QueryParamsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(QueryServer).Params(ctx, in)
return srv.(QueryServer).GetParams(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/cosmos.consensus.v1.Query/Params",
FullMethod: "/cosmos.consensus.v1.Query/GetParams",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest))
return srv.(QueryServer).GetParams(ctx, req.(*QueryParamsRequest))
}
return interceptor(ctx, in, info, handler)
}
@ -217,8 +217,8 @@ var _Query_serviceDesc = grpc.ServiceDesc{
HandlerType: (*QueryServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Params",
Handler: _Query_Params_Handler,
MethodName: "GetParams",
Handler: _Query_GetParams_Handler,
},
},
Streams: []grpc.StreamDesc{},

View File

@ -33,20 +33,20 @@ var _ = utilities.NewDoubleArray
var _ = descriptor.ForMessage
var _ = metadata.Join
func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
func request_Query_GetParams_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryParamsRequest
var metadata runtime.ServerMetadata
msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
msg, err := client.GetParams(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
func local_request_Query_GetParams_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryParamsRequest
var metadata runtime.ServerMetadata
msg, err := server.Params(ctx, &protoReq)
msg, err := server.GetParams(ctx, &protoReq)
return msg, metadata, err
}
@ -57,7 +57,7 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead.
func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error {
mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
mux.Handle("GET", pattern_Query_GetParams_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
@ -68,7 +68,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams)
resp, md, err := local_request_Query_GetParams_0(rctx, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
@ -76,7 +76,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv
return
}
forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
forward_Query_GetParams_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
@ -121,7 +121,7 @@ func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc
// "QueryClient" to call the correct interceptors.
func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error {
mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
mux.Handle("GET", pattern_Query_GetParams_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
@ -130,14 +130,14 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams)
resp, md, err := request_Query_GetParams_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
forward_Query_GetParams_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
@ -145,9 +145,9 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie
}
var (
pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "consensus", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false)))
pattern_Query_GetParams_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "consensus", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false)))
)
var (
forward_Query_Params_0 = runtime.ForwardResponseMessage
forward_Query_GetParams_0 = runtime.ForwardResponseMessage
)

View File

@ -50,7 +50,7 @@ func (k Keeper) handleEquivocationEvidence(ctx sdk.Context, evidence *types.Equi
// if the difference in time and number of blocks is greater than the allowed
// parameters defined.
cp := ctx.ConsensusParams()
if cp != nil && cp.Evidence != nil {
if cp.Evidence != nil {
if ageDuration > cp.Evidence.MaxAgeDuration && ageBlocks > cp.Evidence.MaxAgeNumBlocks {
logger.Info(
"ignored equivocation; evidence too old",

View File

@ -142,7 +142,7 @@ type ConsensusGenesis struct {
// NewConsensusGenesis returns a ConsensusGenesis with given values.
// It takes a proto consensus params so it can called from server export command.
func NewConsensusGenesis(params *cmtproto.ConsensusParams, validators []cmttypes.GenesisValidator) *ConsensusGenesis {
func NewConsensusGenesis(params cmtproto.ConsensusParams, validators []cmttypes.GenesisValidator) *ConsensusGenesis {
return &ConsensusGenesis{
Params: &cmttypes.ConsensusParams{
Block: cmttypes.BlockParams{

View File

@ -70,7 +70,7 @@ func (k msgServer) CreateValidator(goCtx context.Context, msg *types.MsgCreateVa
}
cp := ctx.ConsensusParams()
if cp != nil && cp.Validator != nil {
if cp.Validator != nil {
pkType := pk.Type()
hasKeyType := false
for _, keyType := range cp.Validator.PubKeyTypes {

View File

@ -38,7 +38,7 @@ func BeginBlocker(k *keeper.Keeper, ctx sdk.Context) {
var appVersion uint64
cp := ctx.ConsensusParams()
if cp != nil && cp.Version != nil {
if cp.Version != nil {
appVersion = cp.Version.App
}