feat(consensus): add consensus message (#19483)

Co-authored-by: Likhita Polavarapu <78951027+likhita-809@users.noreply.github.com>
This commit is contained in:
Marko 2024-02-23 15:09:58 +01:00 committed by GitHub
parent 6d96e1dec3
commit 6c9a7858e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 2340 additions and 5 deletions

View File

@ -53,6 +53,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* (types) [#18768](https://github.com/cosmos/cosmos-sdk/pull/18768) Add MustValAddressFromBech32 function.
* (gRPC) [#19049](https://github.com/cosmos/cosmos-sdk/pull/19049) Add debug log prints for each gRPC request.
* (server) [#19280](https://github.com/cosmos/cosmos-sdk/pull/19280) Adds in-place testnet CLI command.
* (x/consensus) [#19483](https://github.com/cosmos/cosmos-sdk/pull/19483) Add consensus messages registration to consensus module.
### Improvements

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,23 @@
// Since: cosmos-sdk 0.51
syntax = "proto3";
package cosmos.consensus.v1;
import "tendermint/types/params.proto";
option go_package = "github.com/cosmos/cosmos-sdk/x/consensus/types";
// ConsensusMsgParams is the Msg/Params request type. This is a consensus message that is sent from cometbft.
message ConsensusMsgParams {
// params defines the x/consensus parameters to be passed from comet.
//
// NOTE: All parameters must be supplied.
tendermint.types.VersionParams version = 1;
tendermint.types.BlockParams block = 2;
tendermint.types.EvidenceParams evidence = 3;
tendermint.types.ValidatorParams validator = 4;
tendermint.types.ABCIParams abci = 5;
}
// ConsensusMsgParamsResponse defines the response structure for executing a
// ConsensusMsgParams message.
message ConsensusMsgParamsResponse {}

View File

@ -4,4 +4,72 @@ sidebar_position: 1
# `x/consensus`
## Abstract
Functionality to modify CometBFT's ABCI consensus params.
## Contents
* [State](#state)
* [Params](#params)
* [Keepers](#keepers)
* [Messages](#messages)
* [Consensus Messages](#consensus-messages)
* [Events](#events)
* [Message Events](#message-events)
## State
The `x/consensus` module keeps state of the consensus params from cometbft.:
## Params
The consensus module stores it's params in state with the prefix of `0x05`,
it can be updated with governance or the address with authority.
* Params: `0x05 | ProtocolBuffer(cometbft.ConsensusParams)`
```protobuf reference
https://github.com/cosmos/cosmos-sdk/blob/381de6452693a9338371223c232fba0c42773a4b/proto/cosmos/consensus/v1/consensus.proto#L11-L18
```
## Keepers
The consensus module provides methods to Set and Get consensus params. It is recommended to use the `x/consensus` module keeper to get consensus params instead of accessing them through the context.
## Messages
### UpdateParams
Update consensus params.
```protobuf reference
https://github.com/cosmos/cosmos-sdk/blob/381de6452693a9338371223c232fba0c42773a4b/proto/cosmos/consensus/v1/tx.proto#L12-L47
```
The message will fail under the following conditions:
* The signer is not the set authority
* Not all values are set
## Consensus Messages
The consensus module has a consensus message that is used to set the consensus params when the chain initializes. It is similar to the `UpdateParams` message but it is only used once at the start of the chain.
```protobuf reference
https://github.com/cosmos/cosmos-sdk/blob/381de6452693a9338371223c232fba0c42773a4b/proto/cosmos/consensus/v1/consensus.proto#L9-L24
```
## Events
The consensus module emits the following events:
### Message Events
#### MsgUpdateParams
| Type | Attribute Key | Attribute Value |
|--------|---------------|---------------------|
| string | authority | msg.Signer |
| string | parameters | consensus Parmeters |

View File

@ -86,3 +86,21 @@ func (k Keeper) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*
return &types.MsgUpdateParamsResponse{}, nil
}
// SetParams sets the consensus parameters on init of a chain. This is a consensus message. It can only be called by the consensus server
// This is used in the consensus message handler set in module.go.
func (k Keeper) SetParams(ctx context.Context, req *types.ConsensusMsgParams) (*types.ConsensusMsgParamsResponse, error) {
consensusParams, err := req.ToProtoConsensusParams()
if err != nil {
return nil, err
}
if err := cmttypes.ConsensusParamsFromProto(consensusParams).ValidateBasic(); err != nil {
return nil, err
}
if err := k.ParamsStore.Set(ctx, consensusParams); err != nil {
return nil, err
}
return &types.ConsensusMsgParamsResponse{}, nil
}

View File

@ -69,6 +69,7 @@ func (s *KeeperTestSuite) TestGRPCQueryConsensusParams() {
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
Abci: defaultConsensusParams.Abci,
}
_, err := s.consensusParamsKeeper.UpdateParams(s.ctx, input)
s.Require().NoError(err)
@ -79,6 +80,7 @@ func (s *KeeperTestSuite) TestGRPCQueryConsensusParams() {
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
Version: defaultConsensusParams.Version,
Abci: defaultConsensusParams.Abci,
},
},
true,
@ -150,6 +152,7 @@ func (s *KeeperTestSuite) TestUpdateParams() {
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
Abci: defaultConsensusParams.Abci,
},
expErr: false,
expErrMsg: "",
@ -161,6 +164,7 @@ func (s *KeeperTestSuite) TestUpdateParams() {
Block: &cmtproto.BlockParams{MaxGas: -10, MaxBytes: -10},
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
Abci: defaultConsensusParams.Abci,
},
expErr: true,
expErrMsg: "block.MaxBytes must be -1 or greater than 0. Got -10",
@ -172,6 +176,7 @@ func (s *KeeperTestSuite) TestUpdateParams() {
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
Abci: defaultConsensusParams.Abci,
},
expErr: true,
expErrMsg: "invalid authority",
@ -183,6 +188,7 @@ func (s *KeeperTestSuite) TestUpdateParams() {
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: nil,
Abci: defaultConsensusParams.Abci,
},
expErr: true,
expErrMsg: "all parameters must be present",
@ -194,6 +200,7 @@ func (s *KeeperTestSuite) TestUpdateParams() {
Block: nil,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
Abci: defaultConsensusParams.Abci,
},
expErr: true,
expErrMsg: "all parameters must be present",
@ -205,6 +212,7 @@ func (s *KeeperTestSuite) TestUpdateParams() {
Block: defaultConsensusParams.Block,
Validator: nil,
Evidence: defaultConsensusParams.Evidence,
Abci: defaultConsensusParams.Abci,
},
expErr: true,
expErrMsg: "all parameters must be present",
@ -233,3 +241,109 @@ func (s *KeeperTestSuite) TestUpdateParams() {
})
}
}
func (s *KeeperTestSuite) TestSetParams() {
defaultConsensusParams := cmttypes.DefaultConsensusParams().ToProto()
testCases := []struct {
name string
input *types.ConsensusMsgParams
expErr bool
expErrMsg string
}{
{
name: "valid params",
input: &types.ConsensusMsgParams{
Abci: defaultConsensusParams.Abci,
Version: &cmtproto.VersionParams{App: 1},
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
},
expErr: false,
expErrMsg: "",
},
{
name: "invalid params",
input: &types.ConsensusMsgParams{
Abci: defaultConsensusParams.Abci,
Version: &cmtproto.VersionParams{App: 1},
Block: &cmtproto.BlockParams{MaxGas: -10, MaxBytes: -10},
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
},
expErr: true,
expErrMsg: "block.MaxBytes must be -1 or greater than 0. Got -10",
},
{
name: "nil version params",
input: &types.ConsensusMsgParams{
Abci: defaultConsensusParams.Abci,
Version: nil,
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
},
expErr: true,
expErrMsg: "all parameters must be present",
},
{
name: "nil evidence params",
input: &types.ConsensusMsgParams{
Abci: defaultConsensusParams.Abci,
Version: &cmtproto.VersionParams{App: 1},
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: nil,
},
expErr: true,
expErrMsg: "all parameters must be present",
},
{
name: "nil block params",
input: &types.ConsensusMsgParams{
Abci: defaultConsensusParams.Abci,
Version: &cmtproto.VersionParams{App: 1},
Block: nil,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
},
expErr: true,
expErrMsg: "all parameters must be present",
},
{
name: "nil validator params",
input: &types.ConsensusMsgParams{
Abci: defaultConsensusParams.Abci,
Version: &cmtproto.VersionParams{App: 1},
Block: defaultConsensusParams.Block,
Validator: nil,
Evidence: defaultConsensusParams.Evidence,
},
expErr: true,
expErrMsg: "all parameters must be present",
},
}
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
s.SetupTest()
_, err := s.consensusParamsKeeper.SetParams(s.ctx, tc.input)
if tc.expErr {
s.Require().Error(err)
s.Require().Contains(err.Error(), tc.expErrMsg)
} else {
s.Require().NoError(err)
res, err := s.consensusParamsKeeper.Params(s.ctx, &types.QueryParamsRequest{})
s.Require().NoError(err)
s.Require().Equal(tc.input.Abci, res.Params.Abci)
s.Require().Equal(tc.input.Block, res.Params.Block)
s.Require().Equal(tc.input.Evidence, res.Params.Evidence)
s.Require().Equal(tc.input.Validator, res.Params.Validator)
s.Require().Equal(tc.input.Version, res.Params.Version)
}
})
}
}

View File

@ -74,3 +74,8 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
// ConsensusVersion implements HasConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
// RegisterConsensusMessages registers the consensus module's messages.
func (am AppModule) RegisterConsensusMessages(builder any) {
// std.RegisterConsensusHandler(builder ,am.keeper.SetParams) // TODO uncomment when api is available
}

View File

@ -0,0 +1,42 @@
package types
import (
"errors"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmttypes "github.com/cometbft/cometbft/types"
)
func (msg ConsensusMsgParams) ToProtoConsensusParams() (cmtproto.ConsensusParams, error) {
if msg.Evidence == nil || msg.Block == nil || msg.Validator == nil || msg.Version == nil {
return cmtproto.ConsensusParams{}, errors.New("all parameters must be present")
}
cp := cmtproto.ConsensusParams{
Block: &cmtproto.BlockParams{
MaxBytes: msg.Block.MaxBytes,
MaxGas: msg.Block.MaxGas,
},
Evidence: &cmtproto.EvidenceParams{
MaxAgeNumBlocks: msg.Evidence.MaxAgeNumBlocks,
MaxAgeDuration: msg.Evidence.MaxAgeDuration,
MaxBytes: msg.Evidence.MaxBytes,
},
Validator: &cmtproto.ValidatorParams{
PubKeyTypes: msg.Validator.PubKeyTypes,
},
Version: cmttypes.DefaultConsensusParams().ToProto().Version, // Version is stored in x/upgrade
}
if msg.Abci != nil {
cp.Abci = &cmtproto.ABCIParams{
VoteExtensionsEnableHeight: msg.Abci.VoteExtensionsEnableHeight,
}
}
if msg.Version != nil {
cp.Version.App = msg.Version.App
}
return cp, nil
}

View File

@ -0,0 +1,701 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: cosmos/consensus/v1/consensus.proto
package types
import (
fmt "fmt"
types "github.com/cometbft/cometbft/proto/tendermint/types"
proto "github.com/cosmos/gogoproto/proto"
io "io"
math "math"
math_bits "math/bits"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
// ConsensusMsgParams is the Msg/Params request type. This is a consensus message that is sent from cometbft.
type ConsensusMsgParams struct {
// params defines the x/consensus parameters to be passed from comet.
//
// NOTE: All parameters must be supplied.
Version *types.VersionParams `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"`
Block *types.BlockParams `protobuf:"bytes,2,opt,name=block,proto3" json:"block,omitempty"`
Evidence *types.EvidenceParams `protobuf:"bytes,3,opt,name=evidence,proto3" json:"evidence,omitempty"`
Validator *types.ValidatorParams `protobuf:"bytes,4,opt,name=validator,proto3" json:"validator,omitempty"`
Abci *types.ABCIParams `protobuf:"bytes,5,opt,name=abci,proto3" json:"abci,omitempty"`
}
func (m *ConsensusMsgParams) Reset() { *m = ConsensusMsgParams{} }
func (m *ConsensusMsgParams) String() string { return proto.CompactTextString(m) }
func (*ConsensusMsgParams) ProtoMessage() {}
func (*ConsensusMsgParams) Descriptor() ([]byte, []int) {
return fileDescriptor_7ed86dd7d42fb61b, []int{0}
}
func (m *ConsensusMsgParams) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *ConsensusMsgParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_ConsensusMsgParams.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *ConsensusMsgParams) XXX_Merge(src proto.Message) {
xxx_messageInfo_ConsensusMsgParams.Merge(m, src)
}
func (m *ConsensusMsgParams) XXX_Size() int {
return m.Size()
}
func (m *ConsensusMsgParams) XXX_DiscardUnknown() {
xxx_messageInfo_ConsensusMsgParams.DiscardUnknown(m)
}
var xxx_messageInfo_ConsensusMsgParams proto.InternalMessageInfo
func (m *ConsensusMsgParams) GetVersion() *types.VersionParams {
if m != nil {
return m.Version
}
return nil
}
func (m *ConsensusMsgParams) GetBlock() *types.BlockParams {
if m != nil {
return m.Block
}
return nil
}
func (m *ConsensusMsgParams) GetEvidence() *types.EvidenceParams {
if m != nil {
return m.Evidence
}
return nil
}
func (m *ConsensusMsgParams) GetValidator() *types.ValidatorParams {
if m != nil {
return m.Validator
}
return nil
}
func (m *ConsensusMsgParams) GetAbci() *types.ABCIParams {
if m != nil {
return m.Abci
}
return nil
}
// ConsensusMsgParamsResponse defines the response structure for executing a
// ConsensusMsgParams message.
type ConsensusMsgParamsResponse struct {
}
func (m *ConsensusMsgParamsResponse) Reset() { *m = ConsensusMsgParamsResponse{} }
func (m *ConsensusMsgParamsResponse) String() string { return proto.CompactTextString(m) }
func (*ConsensusMsgParamsResponse) ProtoMessage() {}
func (*ConsensusMsgParamsResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_7ed86dd7d42fb61b, []int{1}
}
func (m *ConsensusMsgParamsResponse) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *ConsensusMsgParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_ConsensusMsgParamsResponse.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *ConsensusMsgParamsResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_ConsensusMsgParamsResponse.Merge(m, src)
}
func (m *ConsensusMsgParamsResponse) XXX_Size() int {
return m.Size()
}
func (m *ConsensusMsgParamsResponse) XXX_DiscardUnknown() {
xxx_messageInfo_ConsensusMsgParamsResponse.DiscardUnknown(m)
}
var xxx_messageInfo_ConsensusMsgParamsResponse proto.InternalMessageInfo
func init() {
proto.RegisterType((*ConsensusMsgParams)(nil), "cosmos.consensus.v1.ConsensusMsgParams")
proto.RegisterType((*ConsensusMsgParamsResponse)(nil), "cosmos.consensus.v1.ConsensusMsgParamsResponse")
}
func init() {
proto.RegisterFile("cosmos/consensus/v1/consensus.proto", fileDescriptor_7ed86dd7d42fb61b)
}
var fileDescriptor_7ed86dd7d42fb61b = []byte{
// 306 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0xd1, 0xcf, 0x4a, 0xc3, 0x30,
0x1c, 0xc0, 0xf1, 0x76, 0x6e, 0xfe, 0x89, 0xb7, 0x78, 0x29, 0x63, 0x8b, 0x73, 0x5e, 0xbc, 0x98,
0x38, 0x77, 0x12, 0x04, 0xb1, 0x43, 0xd0, 0x83, 0x20, 0x3b, 0x78, 0xf0, 0xd6, 0xa6, 0x61, 0x86,
0xad, 0x49, 0x69, 0xb2, 0xa2, 0x6f, 0xe1, 0xcb, 0xf8, 0x0e, 0x1e, 0x77, 0xf4, 0x28, 0xed, 0x8b,
0x48, 0xd3, 0x74, 0x15, 0xea, 0xa9, 0x34, 0xf9, 0x7e, 0xd2, 0x92, 0x1f, 0x38, 0xa5, 0x52, 0xc5,
0x52, 0x11, 0x2a, 0x85, 0x62, 0x42, 0xad, 0x15, 0xc9, 0x26, 0xcd, 0x0b, 0x4e, 0x52, 0xa9, 0x25,
0x3c, 0xaa, 0x22, 0xdc, 0xac, 0x67, 0x93, 0xfe, 0x50, 0x33, 0x11, 0xb1, 0x34, 0xe6, 0x42, 0x13,
0xfd, 0x9e, 0x30, 0x45, 0x92, 0x20, 0x0d, 0x62, 0x6b, 0xc6, 0x9f, 0x1d, 0x00, 0x67, 0x75, 0xff,
0xa8, 0x16, 0x4f, 0x66, 0x13, 0x5e, 0x81, 0xbd, 0x8c, 0xa5, 0x8a, 0x4b, 0xe1, 0xb9, 0x23, 0xf7,
0xec, 0xf0, 0xf2, 0x18, 0x37, 0xe7, 0x60, 0x73, 0x0e, 0x7e, 0xae, 0x82, 0x4a, 0xcc, 0xeb, 0x1e,
0x4e, 0x41, 0x2f, 0x5c, 0x49, 0xba, 0xf4, 0x3a, 0x06, 0x0e, 0xdb, 0xd0, 0x2f, 0xb7, 0x2d, 0xab,
0x5a, 0x78, 0x0d, 0xf6, 0x59, 0xc6, 0x23, 0x26, 0x28, 0xf3, 0x76, 0x8c, 0x1b, 0xb5, 0xdd, 0x9d,
0x2d, 0x2c, 0xdd, 0x0a, 0x78, 0x03, 0x0e, 0xb2, 0x60, 0xc5, 0xa3, 0x40, 0xcb, 0xd4, 0xeb, 0x1a,
0x7e, 0xf2, 0xcf, 0xff, 0xd6, 0x89, 0xf5, 0x8d, 0x81, 0x17, 0xa0, 0x1b, 0x84, 0x94, 0x7b, 0x3d,
0x63, 0x07, 0x6d, 0x7b, 0xeb, 0xcf, 0x1e, 0x2c, 0x33, 0xe5, 0x78, 0x00, 0xfa, 0xed, 0x6b, 0x9b,
0x33, 0x95, 0x94, 0x8b, 0xfe, 0xfd, 0x57, 0x8e, 0xdc, 0x4d, 0x8e, 0xdc, 0x9f, 0x1c, 0xb9, 0x1f,
0x05, 0x72, 0x36, 0x05, 0x72, 0xbe, 0x0b, 0xe4, 0xbc, 0xe0, 0x05, 0xd7, 0xaf, 0xeb, 0x10, 0x53,
0x19, 0x93, 0xed, 0x4c, 0xcb, 0xc7, 0xb9, 0x8a, 0x96, 0xe4, 0xed, 0xcf, 0x80, 0xcd, 0x87, 0xc3,
0x5d, 0x33, 0xa6, 0xe9, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x66, 0x95, 0x46, 0x47, 0x01, 0x02,
0x00, 0x00,
}
func (m *ConsensusMsgParams) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *ConsensusMsgParams) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *ConsensusMsgParams) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.Abci != nil {
{
size, err := m.Abci.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintConsensus(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x2a
}
if m.Validator != nil {
{
size, err := m.Validator.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintConsensus(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x22
}
if m.Evidence != nil {
{
size, err := m.Evidence.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintConsensus(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x1a
}
if m.Block != nil {
{
size, err := m.Block.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintConsensus(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x12
}
if m.Version != nil {
{
size, err := m.Version.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintConsensus(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func (m *ConsensusMsgParamsResponse) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *ConsensusMsgParamsResponse) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *ConsensusMsgParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
return len(dAtA) - i, nil
}
func encodeVarintConsensus(dAtA []byte, offset int, v uint64) int {
offset -= sovConsensus(v)
base := offset
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return base
}
func (m *ConsensusMsgParams) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.Version != nil {
l = m.Version.Size()
n += 1 + l + sovConsensus(uint64(l))
}
if m.Block != nil {
l = m.Block.Size()
n += 1 + l + sovConsensus(uint64(l))
}
if m.Evidence != nil {
l = m.Evidence.Size()
n += 1 + l + sovConsensus(uint64(l))
}
if m.Validator != nil {
l = m.Validator.Size()
n += 1 + l + sovConsensus(uint64(l))
}
if m.Abci != nil {
l = m.Abci.Size()
n += 1 + l + sovConsensus(uint64(l))
}
return n
}
func (m *ConsensusMsgParamsResponse) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
return n
}
func sovConsensus(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
func sozConsensus(x uint64) (n int) {
return sovConsensus(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *ConsensusMsgParams) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowConsensus
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: ConsensusMsgParams: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: ConsensusMsgParams: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowConsensus
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthConsensus
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthConsensus
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.Version == nil {
m.Version = &types.VersionParams{}
}
if err := m.Version.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Block", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowConsensus
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthConsensus
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthConsensus
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.Block == nil {
m.Block = &types.BlockParams{}
}
if err := m.Block.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Evidence", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowConsensus
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthConsensus
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthConsensus
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.Evidence == nil {
m.Evidence = &types.EvidenceParams{}
}
if err := m.Evidence.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Validator", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowConsensus
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthConsensus
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthConsensus
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.Validator == nil {
m.Validator = &types.ValidatorParams{}
}
if err := m.Validator.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 5:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Abci", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowConsensus
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthConsensus
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthConsensus
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.Abci == nil {
m.Abci = &types.ABCIParams{}
}
if err := m.Abci.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipConsensus(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthConsensus
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *ConsensusMsgParamsResponse) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowConsensus
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: ConsensusMsgParamsResponse: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: ConsensusMsgParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
default:
iNdEx = preIndex
skippy, err := skipConsensus(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthConsensus
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipConsensus(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
depth := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowConsensus
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
wireType := int(wire & 0x7)
switch wireType {
case 0:
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowConsensus
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
iNdEx++
if dAtA[iNdEx-1] < 0x80 {
break
}
}
case 1:
iNdEx += 8
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowConsensus
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
length |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if length < 0 {
return 0, ErrInvalidLengthConsensus
}
iNdEx += length
case 3:
depth++
case 4:
if depth == 0 {
return 0, ErrUnexpectedEndOfGroupConsensus
}
depth--
case 5:
iNdEx += 4
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
if iNdEx < 0 {
return 0, ErrInvalidLengthConsensus
}
if depth == 0 {
return iNdEx, nil
}
}
return 0, io.ErrUnexpectedEOF
}
var (
ErrInvalidLengthConsensus = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowConsensus = fmt.Errorf("proto: integer overflow")
ErrUnexpectedEndOfGroupConsensus = fmt.Errorf("proto: unexpected end of group")
)

View File

@ -5,14 +5,10 @@ import (
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmttypes "github.com/cometbft/cometbft/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
var _ sdk.Msg = &MsgUpdateParams{}
func (msg MsgUpdateParams) ToProtoConsensusParams() (cmtproto.ConsensusParams, error) {
if msg.Evidence == nil || msg.Block == nil || msg.Validator == nil {
if msg.Evidence == nil || msg.Block == nil || msg.Validator == nil || msg.Abci == nil {
return cmtproto.ConsensusParams{}, errors.New("all parameters must be present")
}