From 76757e0e4815a25e2eb3bb25bbb67fce1751381f Mon Sep 17 00:00:00 2001 From: anilCSE Date: Fri, 7 Feb 2020 23:56:15 +0530 Subject: [PATCH 01/52] Add protobuf def --- simapp/app.go | 2 +- simapp/codec.go | 12 +- types/proto.go | 2 +- x/slashing/alias.go | 3 + x/slashing/internal/keeper/keeper.go | 4 +- x/slashing/internal/types/codec.go | 24 +- x/slashing/internal/types/types.pb.go | 326 ++++++++++++++++++++++++++ x/slashing/internal/types/types.proto | 8 + 8 files changed, 367 insertions(+), 14 deletions(-) create mode 100644 x/slashing/internal/types/types.pb.go create mode 100644 x/slashing/internal/types/types.proto diff --git a/simapp/app.go b/simapp/app.go index 721c1ff6bd80..f115c93e19f6 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -183,7 +183,7 @@ func NewSimApp( app.SupplyKeeper, auth.FeeCollectorName, app.ModuleAccountAddrs(), ) app.SlashingKeeper = slashing.NewKeeper( - app.cdc, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], + appCodec.Slashing, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], ) app.CrisisKeeper = crisis.NewKeeper( app.subspaces[crisis.ModuleName], invCheckPeriod, app.SupplyKeeper, auth.FeeCollectorName, diff --git a/simapp/codec.go b/simapp/codec.go index 8f87e7e324b1..a31e9d6c3489 100644 --- a/simapp/codec.go +++ b/simapp/codec.go @@ -4,23 +4,25 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" + "github.com/cosmos/cosmos-sdk/x/slashing" "github.com/cosmos/cosmos-sdk/x/staking" ) // AppCodec defines the application-level codec. This codec contains all the // required module-specific codecs that are to be provided upon initialization. type AppCodec struct { - amino *codec.Codec - - Staking *staking.Codec + amino *codec.Codec + Staking *staking.Codec + Slashing *slashing.Codec } func NewAppCodec() *AppCodec { amino := MakeCodec() return &AppCodec{ - amino: amino, - Staking: staking.NewCodec(amino), + amino: amino, + Staking: staking.NewCodec(amino), + Slashing: slashing.NewCodec(amino), } } diff --git a/types/proto.go b/types/proto.go index e4cdbdc511c0..b6978c1eb9a5 100644 --- a/types/proto.go +++ b/types/proto.go @@ -1,7 +1,7 @@ package types import ( - _ "github.com/gogo/protobuf/gogoproto" // nolint + _ "github.com/gogo/protobuf/gogoproto" // nolint _ "github.com/regen-network/cosmos-proto" // nolint ) diff --git a/x/slashing/alias.go b/x/slashing/alias.go index 38d556a6e492..9e199645496d 100644 --- a/x/slashing/alias.go +++ b/x/slashing/alias.go @@ -34,6 +34,7 @@ const ( var ( // functions aliases + NewKeeper = keeper.NewKeeper NewQuerier = keeper.NewQuerier RegisterCodec = types.RegisterCodec @@ -62,6 +63,7 @@ var ( NewValidatorSigningInfo = types.NewValidatorSigningInfo // variable aliases + NewCodec = types.NewCodec ModuleCdc = types.ModuleCdc ValidatorSigningInfoKey = types.ValidatorSigningInfoKey ValidatorMissedBlockBitArrayKey = types.ValidatorMissedBlockBitArrayKey @@ -79,6 +81,7 @@ var ( type ( Hooks = keeper.Hooks Keeper = keeper.Keeper + Codec = types.Codec GenesisState = types.GenesisState MissedBlock = types.MissedBlock MsgUnjail = types.MsgUnjail diff --git a/x/slashing/internal/keeper/keeper.go b/x/slashing/internal/keeper/keeper.go index e725519314d1..ba1858cfe463 100644 --- a/x/slashing/internal/keeper/keeper.go +++ b/x/slashing/internal/keeper/keeper.go @@ -14,13 +14,13 @@ import ( // Keeper of the slashing store type Keeper struct { storeKey sdk.StoreKey - cdc *codec.Codec + cdc codec.Marshaler sk types.StakingKeeper paramspace types.ParamSubspace } // NewKeeper creates a slashing keeper -func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, sk types.StakingKeeper, paramspace types.ParamSubspace) Keeper { +func NewKeeper(cdc codec.Marshaler, key sdk.StoreKey, sk types.StakingKeeper, paramspace types.ParamSubspace) Keeper { return Keeper{ storeKey: key, cdc: cdc, diff --git a/x/slashing/internal/types/codec.go b/x/slashing/internal/types/codec.go index 34790d54d630..5d24296f6b13 100644 --- a/x/slashing/internal/types/codec.go +++ b/x/slashing/internal/types/codec.go @@ -10,11 +10,25 @@ func RegisterCodec(cdc *codec.Codec) { } // ModuleCdc defines the module codec -var ModuleCdc *codec.Codec +//var ModuleCdc *codec.Codec + +type Codec struct { + codec.Marshaler + // Keep reference to the amino codec to allow backwards compatibility along + // with type, and interface registration. + amino *codec.Codec +} + +func NewCodec(amino *codec.Codec) *Codec { + return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino} +} + +var ModuleCdc *Codec func init() { - ModuleCdc = codec.New() - RegisterCodec(ModuleCdc) - codec.RegisterCrypto(ModuleCdc) - ModuleCdc.Seal() + ModuleCdc = NewCodec(codec.New()) + //ModuleCdc = codec.New() + RegisterCodec(ModuleCdc.amino) + //codec.RegisterCrypto(ModuleCdc) + ModuleCdc.amino.Seal() } diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go new file mode 100644 index 000000000000..77c28bdb3b0a --- /dev/null +++ b/x/slashing/internal/types/types.pb.go @@ -0,0 +1,326 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: types.proto + +package cosmos_sdk_x_params_v1 + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/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.ProtoPackageIsVersion3 // please upgrade the proto package + +type MsgUnjail struct { + ValidatorAddr string `protobuf:"bytes,1,opt,name=ValidatorAddr,proto3" json:"ValidatorAddr,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *MsgUnjail) Reset() { *m = MsgUnjail{} } +func (m *MsgUnjail) String() string { return proto.CompactTextString(m) } +func (*MsgUnjail) ProtoMessage() {} +func (*MsgUnjail) Descriptor() ([]byte, []int) { + return fileDescriptor_d938547f84707355, []int{0} +} +func (m *MsgUnjail) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUnjail) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUnjail.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 *MsgUnjail) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUnjail.Merge(m, src) +} +func (m *MsgUnjail) XXX_Size() int { + return m.Size() +} +func (m *MsgUnjail) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUnjail.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUnjail proto.InternalMessageInfo + +func (m *MsgUnjail) GetValidatorAddr() string { + if m != nil { + return m.ValidatorAddr + } + return "" +} + +func init() { + proto.RegisterType((*MsgUnjail)(nil), "cosmos_sdk.x.params.v1.MsgUnjail") +} + +func init() { proto.RegisterFile("types.proto", fileDescriptor_d938547f84707355) } + +var fileDescriptor_d938547f84707355 = []byte{ + // 124 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2e, 0xa9, 0x2c, 0x48, + 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x4b, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0x8e, + 0x2f, 0x4e, 0xc9, 0xd6, 0xab, 0xd0, 0x2b, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x33, 0x54, + 0x32, 0xe4, 0xe2, 0xf4, 0x2d, 0x4e, 0x0f, 0xcd, 0xcb, 0x4a, 0xcc, 0xcc, 0x11, 0x52, 0xe1, 0xe2, + 0x0d, 0x4b, 0xcc, 0xc9, 0x4c, 0x49, 0x2c, 0xc9, 0x2f, 0x72, 0x4c, 0x49, 0x29, 0x92, 0x60, 0x54, + 0x60, 0xd4, 0xe0, 0x0c, 0x42, 0x15, 0x74, 0x12, 0x38, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, + 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x67, 0x3c, 0x96, 0x63, 0x48, 0x62, 0x03, 0xdb, 0x61, 0x0c, 0x08, + 0x00, 0x00, 0xff, 0xff, 0xe8, 0x59, 0x8c, 0x6b, 0x72, 0x00, 0x00, 0x00, +} + +func (m *MsgUnjail) 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 *MsgUnjail) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUnjail) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } + if len(m.ValidatorAddr) > 0 { + i -= len(m.ValidatorAddr) + copy(dAtA[i:], m.ValidatorAddr) + i = encodeVarintTypes(dAtA, i, uint64(len(m.ValidatorAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgUnjail) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddr) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgUnjail) 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 ErrIntOverflowTypes + } + 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: MsgUnjail: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUnjail: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTypes(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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrInvalidLengthTypes + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTypes + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTypes + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto new file mode 100644 index 000000000000..1ad352c36c1c --- /dev/null +++ b/x/slashing/internal/types/types.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; +package cosmos_sdk.x.slashing.v1; + + +message MsgUnjail { + string address = 1; + +} \ No newline at end of file From a0eaa7ad90855aa17a6d26808d61d3995a5321aa Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sat, 8 Feb 2020 00:50:50 +0530 Subject: [PATCH 02/52] Add proto msg type for MsgUnJail --- x/slashing/internal/types/msg.go | 8 +- x/slashing/internal/types/types.pb.go | 304 +++----------------------- x/slashing/internal/types/types.proto | 9 +- 3 files changed, 43 insertions(+), 278 deletions(-) diff --git a/x/slashing/internal/types/msg.go b/x/slashing/internal/types/msg.go index b2ccdce173ba..aaff6f5252a7 100644 --- a/x/slashing/internal/types/msg.go +++ b/x/slashing/internal/types/msg.go @@ -8,9 +8,9 @@ import ( var _ sdk.Msg = &MsgUnjail{} // MsgUnjail - struct for unjailing jailed validator -type MsgUnjail struct { - ValidatorAddr sdk.ValAddress `json:"address" yaml:"address"` // address of the validator operator -} +//type MsgUnjail struct { +// ValidatorAddr sdk.ValAddress `json:"address" yaml:"address"` // address of the validator operator +//} // NewMsgUnjail creates a new MsgUnjail instance func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail { @@ -19,7 +19,7 @@ func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail { } } -//nolint +// nolint func (msg MsgUnjail) Route() string { return RouterKey } func (msg MsgUnjail) Type() string { return "unjail" } func (msg MsgUnjail) GetSigners() []sdk.AccAddress { diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 77c28bdb3b0a..2573dbd70763 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -1,14 +1,13 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: types.proto +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: x/slashing/internal/types/types.proto -package cosmos_sdk_x_params_v1 +package types import ( fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/golang/protobuf/proto" - io "io" math "math" - math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -23,7 +22,7 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package type MsgUnjail struct { - ValidatorAddr string `protobuf:"bytes,1,opt,name=ValidatorAddr,proto3" json:"ValidatorAddr,omitempty"` + ValidatorAddr []byte `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3" json:"validator_addr,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -33,28 +32,20 @@ func (m *MsgUnjail) Reset() { *m = MsgUnjail{} } func (m *MsgUnjail) String() string { return proto.CompactTextString(m) } func (*MsgUnjail) ProtoMessage() {} func (*MsgUnjail) Descriptor() ([]byte, []int) { - return fileDescriptor_d938547f84707355, []int{0} + return fileDescriptor_2b882c3b0cdd6f57, []int{0} } + func (m *MsgUnjail) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) + return xxx_messageInfo_MsgUnjail.Unmarshal(m, b) } func (m *MsgUnjail) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgUnjail.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } + return xxx_messageInfo_MsgUnjail.Marshal(b, m, deterministic) } func (m *MsgUnjail) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgUnjail.Merge(m, src) } func (m *MsgUnjail) XXX_Size() int { - return m.Size() + return xxx_messageInfo_MsgUnjail.Size(m) } func (m *MsgUnjail) XXX_DiscardUnknown() { xxx_messageInfo_MsgUnjail.DiscardUnknown(m) @@ -62,265 +53,34 @@ func (m *MsgUnjail) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUnjail proto.InternalMessageInfo -func (m *MsgUnjail) GetValidatorAddr() string { +func (m *MsgUnjail) GetValidatorAddr() []byte { if m != nil { return m.ValidatorAddr } - return "" + return nil } func init() { - proto.RegisterType((*MsgUnjail)(nil), "cosmos_sdk.x.params.v1.MsgUnjail") -} - -func init() { proto.RegisterFile("types.proto", fileDescriptor_d938547f84707355) } - -var fileDescriptor_d938547f84707355 = []byte{ - // 124 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2e, 0xa9, 0x2c, 0x48, - 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x4b, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0x8e, - 0x2f, 0x4e, 0xc9, 0xd6, 0xab, 0xd0, 0x2b, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x33, 0x54, - 0x32, 0xe4, 0xe2, 0xf4, 0x2d, 0x4e, 0x0f, 0xcd, 0xcb, 0x4a, 0xcc, 0xcc, 0x11, 0x52, 0xe1, 0xe2, - 0x0d, 0x4b, 0xcc, 0xc9, 0x4c, 0x49, 0x2c, 0xc9, 0x2f, 0x72, 0x4c, 0x49, 0x29, 0x92, 0x60, 0x54, - 0x60, 0xd4, 0xe0, 0x0c, 0x42, 0x15, 0x74, 0x12, 0x38, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, - 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x67, 0x3c, 0x96, 0x63, 0x48, 0x62, 0x03, 0xdb, 0x61, 0x0c, 0x08, - 0x00, 0x00, 0xff, 0xff, 0xe8, 0x59, 0x8c, 0x6b, 0x72, 0x00, 0x00, 0x00, -} - -func (m *MsgUnjail) 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 + proto.RegisterType((*MsgUnjail)(nil), "cosmos_sdk.x.slashing.v1.MsgUnjail") } -func (m *MsgUnjail) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgUnjail) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.ValidatorAddr) > 0 { - i -= len(m.ValidatorAddr) - copy(dAtA[i:], m.ValidatorAddr) - i = encodeVarintTypes(dAtA, i, uint64(len(m.ValidatorAddr))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { - offset -= sovTypes(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *MsgUnjail) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ValidatorAddr) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovTypes(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTypes(x uint64) (n int) { - return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *MsgUnjail) 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 ErrIntOverflowTypes - } - 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: MsgUnjail: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUnjail: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddr", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ValidatorAddr = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipTypes(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, ErrIntOverflowTypes - } - 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, ErrIntOverflowTypes - } - 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, ErrIntOverflowTypes - } - 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, ErrInvalidLengthTypes - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupTypes - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthTypes - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF +func init() { + proto.RegisterFile("x/slashing/internal/types/types.proto", fileDescriptor_2b882c3b0cdd6f57) +} + +var fileDescriptor_2b882c3b0cdd6f57 = []byte{ + // 207 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0xad, 0xd0, 0x2f, 0xce, + 0x49, 0x2c, 0xce, 0xc8, 0xcc, 0x4b, 0xd7, 0xcf, 0xcc, 0x2b, 0x49, 0x2d, 0xca, 0x4b, 0xcc, 0xd1, + 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x12, 0xc9, + 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, 0x30, 0x1d, 0x7a, 0x65, + 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25, 0x95, 0xfa, 0x60, + 0xc5, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0xc4, 0x04, 0xa5, 0x72, 0x2e, 0x4e, 0xdf, 0xe2, + 0xf4, 0xd0, 0xbc, 0xac, 0xc4, 0xcc, 0x1c, 0xa1, 0x2c, 0x2e, 0xbe, 0xb2, 0xc4, 0x9c, 0xcc, 0x94, + 0xc4, 0x92, 0xfc, 0xa2, 0xf8, 0xc4, 0x94, 0x94, 0x22, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x1e, 0x27, + 0xe7, 0x4f, 0xf7, 0xe4, 0xf9, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, 0x40, 0xa2, 0xa9, 0xc5, 0xc5, + 0x4a, 0xbf, 0xee, 0xc9, 0xeb, 0xa6, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, + 0x43, 0xdc, 0x01, 0xa5, 0x74, 0x81, 0xce, 0x81, 0x3a, 0xd3, 0x31, 0x39, 0xd9, 0x11, 0xa2, 0x23, + 0x88, 0x17, 0x6e, 0x34, 0x48, 0xc4, 0x89, 0x3d, 0x8a, 0x15, 0xac, 0x24, 0x89, 0x0d, 0xec, 0x10, + 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x83, 0x86, 0x07, 0xe9, 0xf3, 0x00, 0x00, 0x00, } - -var ( - ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index 1ad352c36c1c..deaefe21cd52 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -1,8 +1,13 @@ syntax = "proto3"; package cosmos_sdk.x.slashing.v1; +option go_package = "types"; -message MsgUnjail { - string address = 1; +import "third_party/proto/gogoproto/gogo.proto"; +message MsgUnjail { + bytes validator_addr = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", + (gogoproto.moretags) = "yaml:\"address\"" + ]; } \ No newline at end of file From 0c6ca19fb6c2a48ad3cc04fdc1e8c12c46949119 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sat, 8 Feb 2020 00:52:01 +0530 Subject: [PATCH 03/52] gofmt --- x/slashing/internal/types/msg.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/x/slashing/internal/types/msg.go b/x/slashing/internal/types/msg.go index aaff6f5252a7..b99a8915fd41 100644 --- a/x/slashing/internal/types/msg.go +++ b/x/slashing/internal/types/msg.go @@ -7,11 +7,6 @@ import ( // verify interface at compile time var _ sdk.Msg = &MsgUnjail{} -// MsgUnjail - struct for unjailing jailed validator -//type MsgUnjail struct { -// ValidatorAddr sdk.ValAddress `json:"address" yaml:"address"` // address of the validator operator -//} - // NewMsgUnjail creates a new MsgUnjail instance func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail { return MsgUnjail{ @@ -19,7 +14,7 @@ func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail { } } -// nolint +//nolint func (msg MsgUnjail) Route() string { return RouterKey } func (msg MsgUnjail) Type() string { return "unjail" } func (msg MsgUnjail) GetSigners() []sdk.AccAddress { From e8617dc36080aae005968aabe5d3dd47bb2c8915 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sat, 8 Feb 2020 01:03:22 +0530 Subject: [PATCH 04/52] Remove ModuleCodec --- x/slashing/internal/types/codec.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/x/slashing/internal/types/codec.go b/x/slashing/internal/types/codec.go index 5d24296f6b13..dbb7a9d0b8b6 100644 --- a/x/slashing/internal/types/codec.go +++ b/x/slashing/internal/types/codec.go @@ -9,9 +9,6 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) } -// ModuleCdc defines the module codec -//var ModuleCdc *codec.Codec - type Codec struct { codec.Marshaler // Keep reference to the amino codec to allow backwards compatibility along From 89b5834f9349c6b5a35704d3cb2c72f1b175d3d1 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Tue, 11 Feb 2020 17:07:26 +0530 Subject: [PATCH 05/52] Add changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e7e6b943f3d..dad9530990f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,11 @@ for JSON encoding. * Every reference of `crypto.Pubkey` in context of a `Validator` is now of type string. `GetPubKeyFromBech32` must be used to get the `crypto.Pubkey`. * The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type provided is specified by `ModuleCdc`. +* (slashing) [\#5627](https://github.com/cosmos/cosmos-sdk/pull/5627) Migrate the `x/slashing` module to use Protocol Buffer for state +serialization instead of Amino. The exact codec used is `codec.HybridCodec` which utilizes Protobuf for binary encoding and Amino +for JSON encoding. + * The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type + provided is specified by `ModuleCdc`. ### Improvements From 1cb8cc8017cdf3bb5811ef6f6a2623821a28a818 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Tue, 11 Feb 2020 17:20:42 +0530 Subject: [PATCH 06/52] Fix naming --- x/slashing/internal/types/types.pb.go | 24 ++++++++++++------------ x/slashing/internal/types/types.proto | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 2573dbd70763..15b5c6047d6f 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -22,7 +22,7 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package type MsgUnjail struct { - ValidatorAddr []byte `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3" json:"validator_addr,omitempty"` + ValidatorAddress []byte `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -53,9 +53,9 @@ func (m *MsgUnjail) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUnjail proto.InternalMessageInfo -func (m *MsgUnjail) GetValidatorAddr() []byte { +func (m *MsgUnjail) GetValidatorAddress() []byte { if m != nil { - return m.ValidatorAddr + return m.ValidatorAddress } return nil } @@ -69,18 +69,18 @@ func init() { } var fileDescriptor_2b882c3b0cdd6f57 = []byte{ - // 207 bytes of a gzipped FileDescriptorProto + // 208 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0xad, 0xd0, 0x2f, 0xce, 0x49, 0x2c, 0xce, 0xc8, 0xcc, 0x4b, 0xd7, 0xcf, 0xcc, 0x2b, 0x49, 0x2d, 0xca, 0x4b, 0xcc, 0xd1, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x12, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, 0x30, 0x1d, 0x7a, 0x65, 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25, 0x95, 0xfa, 0x60, - 0xc5, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0xc4, 0x04, 0xa5, 0x72, 0x2e, 0x4e, 0xdf, 0xe2, - 0xf4, 0xd0, 0xbc, 0xac, 0xc4, 0xcc, 0x1c, 0xa1, 0x2c, 0x2e, 0xbe, 0xb2, 0xc4, 0x9c, 0xcc, 0x94, - 0xc4, 0x92, 0xfc, 0xa2, 0xf8, 0xc4, 0x94, 0x94, 0x22, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x1e, 0x27, - 0xe7, 0x4f, 0xf7, 0xe4, 0xf9, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, 0x40, 0xa2, 0xa9, 0xc5, 0xc5, - 0x4a, 0xbf, 0xee, 0xc9, 0xeb, 0xa6, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, - 0x43, 0xdc, 0x01, 0xa5, 0x74, 0x81, 0xce, 0x81, 0x3a, 0xd3, 0x31, 0x39, 0xd9, 0x11, 0xa2, 0x23, - 0x88, 0x17, 0x6e, 0x34, 0x48, 0xc4, 0x89, 0x3d, 0x8a, 0x15, 0xac, 0x24, 0x89, 0x0d, 0xec, 0x10, - 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x83, 0x86, 0x07, 0xe9, 0xf3, 0x00, 0x00, 0x00, + 0xc5, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0xc4, 0x04, 0xa5, 0x76, 0x46, 0x2e, 0x4e, 0xdf, + 0xe2, 0xf4, 0xd0, 0xbc, 0xac, 0xc4, 0xcc, 0x1c, 0xa1, 0x2a, 0x2e, 0xc1, 0xb2, 0xc4, 0x9c, 0xcc, + 0x94, 0xc4, 0x92, 0xfc, 0xa2, 0xf8, 0xc4, 0x94, 0x94, 0xa2, 0xd4, 0xe2, 0x62, 0x09, 0x46, 0x05, + 0x46, 0x0d, 0x1e, 0x27, 0xdf, 0x4f, 0xf7, 0xe4, 0x25, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, 0x30, + 0x94, 0x28, 0xfd, 0xba, 0x27, 0xaf, 0x9b, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, + 0xab, 0x0f, 0x71, 0x15, 0x94, 0xd2, 0x05, 0x3a, 0x0e, 0xea, 0xe8, 0xb0, 0xc4, 0x1c, 0x47, 0x88, + 0x8e, 0x20, 0x01, 0xb8, 0x21, 0x50, 0x11, 0x27, 0xf6, 0x28, 0x56, 0xb0, 0xaa, 0x24, 0x36, 0xb0, + 0xcb, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x40, 0xa7, 0xdc, 0x9f, 0x04, 0x01, 0x00, 0x00, } diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index deaefe21cd52..a7d242658d6d 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -6,8 +6,8 @@ option go_package = "types"; import "third_party/proto/gogoproto/gogo.proto"; message MsgUnjail { - bytes validator_addr = 1 [ - (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", - (gogoproto.moretags) = "yaml:\"address\"" + bytes validator_address = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress", + (gogoproto.moretags) = "yaml:\"validator_address\"" ]; } \ No newline at end of file From 2909f11983051aa1200c16ce7f1ecf7120bdc1e6 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Tue, 11 Feb 2020 18:29:47 +0530 Subject: [PATCH 07/52] Fix undefined errors --- x/slashing/handler.go | 2 +- x/slashing/internal/types/msg.go | 3 ++- x/slashing/internal/types/types.pb.go | 23 ++++++++++++----------- x/slashing/internal/types/types.proto | 5 +++-- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/x/slashing/handler.go b/x/slashing/handler.go index fe4ef7cb7c2e..cb6690716bcb 100644 --- a/x/slashing/handler.go +++ b/x/slashing/handler.go @@ -33,7 +33,7 @@ func handleMsgUnjail(ctx sdk.Context, msg MsgUnjail, k Keeper) (*sdk.Result, err sdk.NewEvent( sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttribute(sdk.AttributeKeySender, msg.ValidatorAddr.String()), + sdk.NewAttribute(sdk.AttributeKeySender, string(msg.ValidatorAddr)), ), ) diff --git a/x/slashing/internal/types/msg.go b/x/slashing/internal/types/msg.go index b99a8915fd41..49fd830d9615 100644 --- a/x/slashing/internal/types/msg.go +++ b/x/slashing/internal/types/msg.go @@ -29,8 +29,9 @@ func (msg MsgUnjail) GetSignBytes() []byte { // ValidateBasic validity check for the AnteHandler func (msg MsgUnjail) ValidateBasic() error { - if msg.ValidatorAddr.Empty() { + if len(msg.ValidatorAddr) < 1 { //if empty return ErrBadValidatorAddr } + return nil } diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 15b5c6047d6f..0c2e770d4a85 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -21,8 +21,9 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package +// MsgUnjail - struct for unjailing jailed validator type MsgUnjail struct { - ValidatorAddress []byte `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + ValidatorAddr []byte `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3" json:"validator_addr,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -53,9 +54,9 @@ func (m *MsgUnjail) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUnjail proto.InternalMessageInfo -func (m *MsgUnjail) GetValidatorAddress() []byte { +func (m *MsgUnjail) GetValidatorAddr() []byte { if m != nil { - return m.ValidatorAddress + return m.ValidatorAddr } return nil } @@ -75,12 +76,12 @@ var fileDescriptor_2b882c3b0cdd6f57 = []byte{ 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x12, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, 0x30, 0x1d, 0x7a, 0x65, 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x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+ 0x27, 0xdf, 0x4f, 0xf7, 0xe4, 0x25, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, 0x50, 0xe5, 0x53, 0x8b, + 0x8b, 0x95, 0x7e, 0xdd, 0x93, 0xd7, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, + 0xd5, 0x87, 0x38, 0x09, 0x4a, 0xe9, 0x02, 0x5d, 0x06, 0x75, 0x71, 0x58, 0x62, 0x8e, 0x23, 0x44, + 0x47, 0x10, 0x2f, 0xdc, 0x10, 0x90, 0x88, 0x13, 0x7b, 0x14, 0x2b, 0x58, 0x49, 0x12, 0x1b, 0xd8, + 0x4d, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0e, 0x44, 0xbf, 0xed, 0xfe, 0x00, 0x00, 0x00, } diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index a7d242658d6d..3c11cb236a0c 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -5,9 +5,10 @@ option go_package = "types"; import "third_party/proto/gogoproto/gogo.proto"; +// MsgUnjail - struct for unjailing jailed validator message MsgUnjail { - bytes validator_address = 1 [ + bytes validator_addr = 1 [ (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress", (gogoproto.moretags) = "yaml:\"validator_address\"" ]; -} \ No newline at end of file +} From c9ddfbd6d953a6824729ccad0dda676e132da91a Mon Sep 17 00:00:00 2001 From: anilCSE Date: Tue, 11 Feb 2020 19:39:38 +0530 Subject: [PATCH 08/52] Add ValidatorSigningInfo protobuf implementation --- x/slashing/internal/types/signing_info.go | 10 -- x/slashing/internal/types/types.pb.go | 126 +++++++++++++++++++--- x/slashing/internal/types/types.proto | 18 ++++ 3 files changed, 130 insertions(+), 24 deletions(-) diff --git a/x/slashing/internal/types/signing_info.go b/x/slashing/internal/types/signing_info.go index 431658c2241a..66870f3032a6 100644 --- a/x/slashing/internal/types/signing_info.go +++ b/x/slashing/internal/types/signing_info.go @@ -7,16 +7,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// ValidatorSigningInfo defines the signing info for a validator -type ValidatorSigningInfo struct { - Address sdk.ConsAddress `json:"address" yaml:"address"` // validator consensus address - StartHeight int64 `json:"start_height" yaml:"start_height"` // height at which validator was first a candidate OR was unjailed - IndexOffset int64 `json:"index_offset" yaml:"index_offset"` // index offset into signed block bit array - JailedUntil time.Time `json:"jailed_until" yaml:"jailed_until"` // timestamp validator cannot be unjailed until - Tombstoned bool `json:"tombstoned" yaml:"tombstoned"` // whether or not a validator has been tombstoned (killed out of validator set) - MissedBlocksCounter int64 `json:"missed_blocks_counter" yaml:"missed_blocks_counter"` // missed blocks counter (to avoid scanning the array every time) -} - // NewValidatorSigningInfo creates a new ValidatorSigningInfo instance func NewValidatorSigningInfo( condAddr sdk.ConsAddress, startHeight, indexOffset int64, diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 0c2e770d4a85..7abcbeeb58da 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -6,6 +6,7 @@ package types import ( fmt "fmt" _ "github.com/gogo/protobuf/gogoproto" + types "github.com/gogo/protobuf/types" proto "github.com/golang/protobuf/proto" math "math" ) @@ -61,8 +62,89 @@ func (m *MsgUnjail) GetValidatorAddr() []byte { return nil } +// ValidatorSigningInfo defines the signing info for a validator +type ValidatorSigningInfo struct { + Address []byte `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + StartHeight int64 `protobuf:"varint,2,opt,name=start_height,json=startHeight,proto3" json:"start_height,omitempty"` + IndexOffset int64 `protobuf:"varint,3,opt,name=index_offset,json=indexOffset,proto3" json:"index_offset,omitempty"` + JailedUntil *types.Timestamp `protobuf:"bytes,4,opt,name=jailed_until,json=jailedUntil,proto3" json:"jailed_until,omitempty"` + Tombstoned bool `protobuf:"varint,5,opt,name=tombstoned,proto3" json:"tombstoned,omitempty"` + MissedBlocksCounter int64 `protobuf:"varint,6,opt,name=missed_blocks_counter,json=missedBlocksCounter,proto3" json:"missed_blocks_counter,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ValidatorSigningInfo) Reset() { *m = ValidatorSigningInfo{} } +func (m *ValidatorSigningInfo) String() string { return proto.CompactTextString(m) } +func (*ValidatorSigningInfo) ProtoMessage() {} +func (*ValidatorSigningInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_2b882c3b0cdd6f57, []int{1} +} + +func (m *ValidatorSigningInfo) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ValidatorSigningInfo.Unmarshal(m, b) +} +func (m *ValidatorSigningInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ValidatorSigningInfo.Marshal(b, m, deterministic) +} +func (m *ValidatorSigningInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorSigningInfo.Merge(m, src) +} +func (m *ValidatorSigningInfo) XXX_Size() int { + return xxx_messageInfo_ValidatorSigningInfo.Size(m) +} +func (m *ValidatorSigningInfo) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorSigningInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorSigningInfo proto.InternalMessageInfo + +func (m *ValidatorSigningInfo) GetAddress() []byte { + if m != nil { + return m.Address + } + return nil +} + +func (m *ValidatorSigningInfo) GetStartHeight() int64 { + if m != nil { + return m.StartHeight + } + return 0 +} + +func (m *ValidatorSigningInfo) GetIndexOffset() int64 { + if m != nil { + return m.IndexOffset + } + return 0 +} + +func (m *ValidatorSigningInfo) GetJailedUntil() *types.Timestamp { + if m != nil { + return m.JailedUntil + } + return nil +} + +func (m *ValidatorSigningInfo) GetTombstoned() bool { + if m != nil { + return m.Tombstoned + } + return false +} + +func (m *ValidatorSigningInfo) GetMissedBlocksCounter() int64 { + if m != nil { + return m.MissedBlocksCounter + } + return 0 +} + func init() { proto.RegisterType((*MsgUnjail)(nil), "cosmos_sdk.x.slashing.v1.MsgUnjail") + proto.RegisterType((*ValidatorSigningInfo)(nil), "cosmos_sdk.x.slashing.v1.ValidatorSigningInfo") } func init() { @@ -70,18 +152,34 @@ func init() { } var fileDescriptor_2b882c3b0cdd6f57 = []byte{ - // 208 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0xad, 0xd0, 0x2f, 0xce, - 0x49, 0x2c, 0xce, 0xc8, 0xcc, 0x4b, 0xd7, 0xcf, 0xcc, 0x2b, 0x49, 0x2d, 0xca, 0x4b, 0xcc, 0xd1, - 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x12, 0xc9, - 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, 0x30, 0x1d, 0x7a, 0x65, - 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25, 0x95, 0xfa, 0x60, - 0xc5, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0xc4, 0x04, 0xa5, 0x46, 0x46, 0x2e, 0x4e, 0xdf, - 0xe2, 0xf4, 0xd0, 0xbc, 0xac, 0xc4, 0xcc, 0x1c, 0xa1, 0x12, 0x2e, 0xbe, 0xb2, 0xc4, 0x9c, 0xcc, - 0x94, 0xc4, 0x92, 0xfc, 0xa2, 0xf8, 0xc4, 0x94, 0x94, 0x22, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x1e, - 0x27, 0xdf, 0x4f, 0xf7, 0xe4, 0x25, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, 0x50, 0xe5, 0x53, 0x8b, - 0x8b, 0x95, 0x7e, 0xdd, 0x93, 0xd7, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, - 0xd5, 0x87, 0x38, 0x09, 0x4a, 0xe9, 0x02, 0x5d, 0x06, 0x75, 0x71, 0x58, 0x62, 0x8e, 0x23, 0x44, - 0x47, 0x10, 0x2f, 0xdc, 0x10, 0x90, 0x88, 0x13, 0x7b, 0x14, 0x2b, 0x58, 0x49, 0x12, 0x1b, 0xd8, - 0x4d, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0e, 0x44, 0xbf, 0xed, 0xfe, 0x00, 0x00, 0x00, + // 454 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x52, 0xcd, 0x6e, 0xd3, 0x40, + 0x10, 0x26, 0x84, 0xb6, 0xb0, 0x09, 0x95, 0x70, 0xa9, 0xb0, 0x22, 0x24, 0x57, 0x96, 0x40, 0x5c, + 0xba, 0x16, 0x20, 0x2e, 0xbd, 0xe1, 0x72, 0x80, 0x43, 0x85, 0x64, 0xda, 0x1e, 0x38, 0x60, 0xad, + 0xe3, 0xcd, 0x7a, 0xe9, 0x7a, 0x27, 0xf2, 0x4e, 0xaa, 0xe4, 0xc8, 0x1b, 0xf0, 0x58, 0xbc, 0x03, + 0x52, 0x78, 0x07, 0x8e, 0x9c, 0x58, 0xef, 0xc6, 0xc4, 0x20, 0x0e, 0xbd, 0xd8, 0x9e, 0x6f, 0xe6, + 0xfb, 0xbe, 0xf9, 0x31, 0x79, 0xb2, 0x4c, 0x8c, 0x62, 0xa6, 0x92, 0x5a, 0x24, 0x52, 0x23, 0x6f, + 0x34, 0x53, 0x09, 0xae, 0xe6, 0xdc, 0xf8, 0x27, 0x9d, 0x37, 0x80, 0x10, 0x84, 0x53, 0x30, 0x35, + 0x98, 0xd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, 0x38, 0x1b, 0xb9, 0xf0, 0xad, 0x8b, 0x5a, 0xae, + 0xd4, 0x25, 0x5f, 0xe6, 0x30, 0x9b, 0x19, 0x8e, 0xe1, 0xf0, 0x5f, 0x6e, 0x3f, 0x6b, 0xb9, 0x2e, + 0x7c, 0xef, 0x22, 0x3b, 0xd7, 0xb8, 0x5d, 0x37, 0x2f, 0xf3, 0x85, 0x46, 0xa9, 0xc2, 0x3b, 0x96, + 0x3b, 0x7a, 0x31, 0xa1, 0xfe, 0x58, 0xb4, 0x3b, 0x16, 0x3d, 0xef, 0x8e, 0x95, 0x46, 0xdf, 0xd6, + 0xd1, 0xad, 0xad, 0x76, 0x9f, 0x1d, 0x7f, 0xfd, 0x11, 0x0d, 0xb2, 0x91, 0x87, 0x2e, 0x5a, 0x24, + 0x78, 0x45, 0x08, 0x42, 0x5d, 0x18, 0x04, 0xcd, 0xcb, 0x70, 0xc7, 0xaa, 0xdf, 0x4d, 0x0f, 0x2d, + 0xfb, 0x81, 0x67, 0x6f, 0x73, 0x71, 0xd6, 0x2b, 0x0c, 0xce, 0xc9, 0x61, 0x2d, 0x8d, 0xb1, 0xc2, + 0x85, 0x82, 0xe9, 0x95, 0xc9, 0xa7, 0xb0, 0x68, 0x7f, 0xce, 0x70, 0xd7, 0xcd, 0x76, 0x64, 0x15, + 0x1e, 0x7b, 0x85, 0xff, 0x96, 0xc5, 0xd9, 0x81, 0xc7, 0x53, 0x07, 0x9f, 0x7a, 0x34, 0xdd, 0xfb, + 0xb8, 0xe3, 0x4e, 0x50, 0xec, 0xba, 0xb9, 0x5e, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x07, 0x25, + 0xe1, 0xf1, 0xfd, 0x02, 0x00, 0x00, } diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index 3c11cb236a0c..44c0cd435524 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -4,6 +4,7 @@ package cosmos_sdk.x.slashing.v1; option go_package = "types"; import "third_party/proto/gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; // MsgUnjail - struct for unjailing jailed validator message MsgUnjail { @@ -12,3 +13,20 @@ message MsgUnjail { (gogoproto.moretags) = "yaml:\"validator_address\"" ]; } + +// ValidatorSigningInfo defines the signing info for a validator +message ValidatorSigningInfo { + bytes address = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress", + (gogoproto.moretags) = "yaml:\"address\"" // validator consensus address + ]; + int64 start_height = 2 [(gogoproto.moretags) = "yaml:\"start_height\""]; // height at which validator was first a candidate OR was unjailed + int64 index_offset = 3 [(gogoproto.moretags) = "yaml:\"index_offset\""]; // index offset into signed block bit array + google.protobuf.Timestamp jailed_until = 4 [ + (gogoproto.moretags) = "yaml:\"jailed_until\"", + (gogoproto.nullable) = false, + (gogoproto.stdtime) = true + ]; // timestamp validator cannot be unjailed until + bool tombstoned = 5 [(gogoproto.moretags) = "yaml:\"tombstoned\""]; // whether or not a validator has been tombstoned (killed out of validator set) + int64 missed_blocks_counter = 6 [(gogoproto.moretags) = "yaml:\"missed_blocks_counter\""]; // missed blocks counter (to avoid scanning the array every time) +} \ No newline at end of file From d286da4fd9d901765d42d2cb89aad5011c5c297f Mon Sep 17 00:00:00 2001 From: anilCSE Date: Tue, 11 Feb 2020 21:07:17 +0530 Subject: [PATCH 09/52] Revert unnecessary codec migration --- x/slashing/internal/types/signing_info.go | 10 ++ x/slashing/internal/types/types.pb.go | 126 +++------------------- x/slashing/internal/types/types.proto | 18 ---- 3 files changed, 24 insertions(+), 130 deletions(-) diff --git a/x/slashing/internal/types/signing_info.go b/x/slashing/internal/types/signing_info.go index 66870f3032a6..431658c2241a 100644 --- a/x/slashing/internal/types/signing_info.go +++ b/x/slashing/internal/types/signing_info.go @@ -7,6 +7,16 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) +// ValidatorSigningInfo defines the signing info for a validator +type ValidatorSigningInfo struct { + Address sdk.ConsAddress `json:"address" yaml:"address"` // validator consensus address + StartHeight int64 `json:"start_height" yaml:"start_height"` // height at which validator was first a candidate OR was unjailed + IndexOffset int64 `json:"index_offset" yaml:"index_offset"` // index offset into signed block bit array + JailedUntil time.Time `json:"jailed_until" yaml:"jailed_until"` // timestamp validator cannot be unjailed until + Tombstoned bool `json:"tombstoned" yaml:"tombstoned"` // whether or not a validator has been tombstoned (killed out of validator set) + MissedBlocksCounter int64 `json:"missed_blocks_counter" yaml:"missed_blocks_counter"` // missed blocks counter (to avoid scanning the array every time) +} + // NewValidatorSigningInfo creates a new ValidatorSigningInfo instance func NewValidatorSigningInfo( condAddr sdk.ConsAddress, startHeight, indexOffset int64, diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 7abcbeeb58da..0c2e770d4a85 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -6,7 +6,6 @@ package types import ( fmt "fmt" _ "github.com/gogo/protobuf/gogoproto" - types "github.com/gogo/protobuf/types" proto "github.com/golang/protobuf/proto" math "math" ) @@ -62,89 +61,8 @@ func (m *MsgUnjail) GetValidatorAddr() []byte { return nil } -// ValidatorSigningInfo defines the signing info for a validator -type ValidatorSigningInfo struct { - Address []byte `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - StartHeight int64 `protobuf:"varint,2,opt,name=start_height,json=startHeight,proto3" json:"start_height,omitempty"` - IndexOffset int64 `protobuf:"varint,3,opt,name=index_offset,json=indexOffset,proto3" json:"index_offset,omitempty"` - JailedUntil *types.Timestamp `protobuf:"bytes,4,opt,name=jailed_until,json=jailedUntil,proto3" json:"jailed_until,omitempty"` - Tombstoned bool `protobuf:"varint,5,opt,name=tombstoned,proto3" json:"tombstoned,omitempty"` - MissedBlocksCounter int64 `protobuf:"varint,6,opt,name=missed_blocks_counter,json=missedBlocksCounter,proto3" json:"missed_blocks_counter,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ValidatorSigningInfo) Reset() { *m = ValidatorSigningInfo{} } -func (m *ValidatorSigningInfo) String() string { return proto.CompactTextString(m) } -func (*ValidatorSigningInfo) ProtoMessage() {} -func (*ValidatorSigningInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_2b882c3b0cdd6f57, []int{1} -} - -func (m *ValidatorSigningInfo) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ValidatorSigningInfo.Unmarshal(m, b) -} -func (m *ValidatorSigningInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ValidatorSigningInfo.Marshal(b, m, deterministic) -} -func (m *ValidatorSigningInfo) XXX_Merge(src proto.Message) { - xxx_messageInfo_ValidatorSigningInfo.Merge(m, src) -} -func (m *ValidatorSigningInfo) XXX_Size() int { - return xxx_messageInfo_ValidatorSigningInfo.Size(m) -} -func (m *ValidatorSigningInfo) XXX_DiscardUnknown() { - xxx_messageInfo_ValidatorSigningInfo.DiscardUnknown(m) -} - -var xxx_messageInfo_ValidatorSigningInfo proto.InternalMessageInfo - -func (m *ValidatorSigningInfo) GetAddress() []byte { - if m != nil { - return m.Address - } - return nil -} - -func (m *ValidatorSigningInfo) GetStartHeight() int64 { - if m != nil { - return m.StartHeight - } - return 0 -} - -func (m *ValidatorSigningInfo) GetIndexOffset() int64 { - if m != nil { - return m.IndexOffset - } - return 0 -} - -func (m *ValidatorSigningInfo) GetJailedUntil() *types.Timestamp { - if m != nil { - return m.JailedUntil - } - return nil -} - -func (m *ValidatorSigningInfo) GetTombstoned() bool { - if m != nil { - return m.Tombstoned - } - return false -} - -func (m *ValidatorSigningInfo) GetMissedBlocksCounter() int64 { - if m != nil { - return m.MissedBlocksCounter - } - return 0 -} - func init() { proto.RegisterType((*MsgUnjail)(nil), "cosmos_sdk.x.slashing.v1.MsgUnjail") - proto.RegisterType((*ValidatorSigningInfo)(nil), "cosmos_sdk.x.slashing.v1.ValidatorSigningInfo") } func init() { @@ -152,34 +70,18 @@ func init() { } var fileDescriptor_2b882c3b0cdd6f57 = []byte{ - // 454 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x52, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0x26, 0x84, 0xb6, 0xb0, 0x09, 0x95, 0x70, 0xa9, 0xb0, 0x22, 0x24, 0x57, 0x96, 0x40, 0x5c, - 0xba, 0x16, 0x20, 0x2e, 0xbd, 0xe1, 0x72, 0x80, 0x43, 0x85, 0x64, 0xda, 0x1e, 0x38, 0x60, 0xad, - 0xe3, 0xcd, 0x7a, 0xe9, 0x7a, 0x27, 0xf2, 0x4e, 0xaa, 0xe4, 0xc8, 0x1b, 0xf0, 0x58, 0xbc, 0x03, - 0x52, 0x78, 0x07, 0x8e, 0x9c, 0x58, 0xef, 0xc6, 0xc4, 0x20, 0x0e, 0xbd, 0xd8, 0x9e, 0x6f, 0xe6, - 0xfb, 0xbe, 0xf9, 0x31, 0x79, 0xb2, 0x4c, 0x8c, 0x62, 0xa6, 0x92, 0x5a, 0x24, 0x52, 0x23, 0x6f, - 0x34, 0x53, 0x09, 0xae, 0xe6, 0xdc, 0xf8, 0x27, 0x9d, 0x37, 0x80, 0x10, 0x84, 0x53, 0x30, 0x35, - 0x98, 0xdc, 0x94, 0x57, 0x74, 0x49, 0x3b, 0x06, 0xbd, 0x7e, 0x3e, 0x79, 0x8a, 0x95, 0x6c, 0xca, - 0x7c, 0xce, 0x1a, 0x5c, 0x25, 0xae, 0x38, 0x11, 0x20, 0x60, 0xfb, 0xe5, 0x15, 0x26, 0x91, 0x00, - 0x10, 0x8a, 0xfb, 0x92, 0x62, 0x31, 0x4b, 0x50, 0xd6, 0xdc, 0x20, 0xab, 0xe7, 0xbe, 0x20, 0xfe, - 0x32, 0x20, 0xf7, 0xce, 0x8c,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16, 0x3d, 0xef, 0x8e, 0x95, 0x46, 0xdf, 0xd6, - 0xd1, 0xad, 0xad, 0x76, 0x9f, 0x1d, 0x7f, 0xfd, 0x11, 0x0d, 0xb2, 0x91, 0x87, 0x2e, 0x5a, 0x24, - 0x78, 0x45, 0x08, 0x42, 0x5d, 0x18, 0x04, 0xcd, 0xcb, 0x70, 0xc7, 0xaa, 0xdf, 0x4d, 0x0f, 0x2d, - 0xfb, 0x81, 0x67, 0x6f, 0x73, 0x71, 0xd6, 0x2b, 0x0c, 0xce, 0xc9, 0x61, 0x2d, 0x8d, 0xb1, 0xc2, - 0x85, 0x82, 0xe9, 0x95, 0xc9, 0xa7, 0xb0, 0x68, 0x7f, 0xce, 0x70, 0xd7, 0xcd, 0x76, 0x64, 0x15, - 0x1e, 0x7b, 0x85, 0xff, 0x96, 0xc5, 0xd9, 0x81, 0xc7, 0x53, 0x07, 0x9f, 0x7a, 0x34, 0xdd, 0xfb, - 0xb8, 0xe3, 0x4e, 0x50, 0xec, 0xba, 0xb9, 0x5e, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x07, 0x25, - 0xe1, 0xf1, 0xfd, 0x02, 0x00, 0x00, + // 208 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0xad, 0xd0, 0x2f, 0xce, + 0x49, 0x2c, 0xce, 0xc8, 0xcc, 0x4b, 0xd7, 0xcf, 0xcc, 0x2b, 0x49, 0x2d, 0xca, 0x4b, 0xcc, 0xd1, + 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x12, 0xc9, + 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, 0x30, 0x1d, 0x7a, 0x65, + 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25, 0x95, 0xfa, 0x60, + 0xc5, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0xc4, 0x04, 0xa5, 0x46, 0x46, 0x2e, 0x4e, 0xdf, + 0xe2, 0xf4, 0xd0, 0xbc, 0xac, 0xc4, 0xcc, 0x1c, 0xa1, 0x12, 0x2e, 0xbe, 0xb2, 0xc4, 0x9c, 0xcc, + 0x94, 0xc4, 0x92, 0xfc, 0xa2, 0xf8, 0xc4, 0x94, 0x94, 0x22, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x1e, + 0x27, 0xdf, 0x4f, 0xf7, 0xe4, 0x25, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, 0x50, 0xe5, 0x53, 0x8b, + 0x8b, 0x95, 0x7e, 0xdd, 0x93, 0xd7, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, + 0xd5, 0x87, 0x38, 0x09, 0x4a, 0xe9, 0x02, 0x5d, 0x06, 0x75, 0x71, 0x58, 0x62, 0x8e, 0x23, 0x44, + 0x47, 0x10, 0x2f, 0xdc, 0x10, 0x90, 0x88, 0x13, 0x7b, 0x14, 0x2b, 0x58, 0x49, 0x12, 0x1b, 0xd8, + 0x4d, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0e, 0x44, 0xbf, 0xed, 0xfe, 0x00, 0x00, 0x00, } diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index 44c0cd435524..9a352d6d15c1 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -4,7 +4,6 @@ package cosmos_sdk.x.slashing.v1; option go_package = "types"; import "third_party/proto/gogoproto/gogo.proto"; -import "google/protobuf/timestamp.proto"; // MsgUnjail - struct for unjailing jailed validator message MsgUnjail { @@ -12,21 +11,4 @@ message MsgUnjail { (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress", (gogoproto.moretags) = "yaml:\"validator_address\"" ]; -} - -// ValidatorSigningInfo defines the signing info for a validator -message ValidatorSigningInfo { - bytes address = 1 [ - (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress", - (gogoproto.moretags) = "yaml:\"address\"" // validator consensus address - ]; - int64 start_height = 2 [(gogoproto.moretags) = "yaml:\"start_height\""]; // height at which validator was first a candidate OR was unjailed - int64 index_offset = 3 [(gogoproto.moretags) = "yaml:\"index_offset\""]; // index offset into signed block bit array - google.protobuf.Timestamp jailed_until = 4 [ - (gogoproto.moretags) = "yaml:\"jailed_until\"", - (gogoproto.nullable) = false, - (gogoproto.stdtime) = true - ]; // timestamp validator cannot be unjailed until - bool tombstoned = 5 [(gogoproto.moretags) = "yaml:\"tombstoned\""]; // whether or not a validator has been tombstoned (killed out of validator set) - int64 missed_blocks_counter = 6 [(gogoproto.moretags) = "yaml:\"missed_blocks_counter\""]; // missed blocks counter (to avoid scanning the array every time) } \ No newline at end of file From c601f0815436f8b8e010520e6e1392f95159748f Mon Sep 17 00:00:00 2001 From: anilCSE Date: Fri, 7 Feb 2020 23:56:15 +0530 Subject: [PATCH 10/52] Add protobuf def --- simapp/app.go | 2 +- simapp/codec.go | 12 +- types/proto.go | 2 +- x/slashing/alias.go | 3 + x/slashing/internal/keeper/keeper.go | 4 +- x/slashing/internal/types/codec.go | 24 +- x/slashing/internal/types/types.pb.go | 326 ++++++++++++++++++++++++++ x/slashing/internal/types/types.proto | 8 + 8 files changed, 367 insertions(+), 14 deletions(-) create mode 100644 x/slashing/internal/types/types.pb.go create mode 100644 x/slashing/internal/types/types.proto diff --git a/simapp/app.go b/simapp/app.go index 721c1ff6bd80..f115c93e19f6 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -183,7 +183,7 @@ func NewSimApp( app.SupplyKeeper, auth.FeeCollectorName, app.ModuleAccountAddrs(), ) app.SlashingKeeper = slashing.NewKeeper( - app.cdc, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], + appCodec.Slashing, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], ) app.CrisisKeeper = crisis.NewKeeper( app.subspaces[crisis.ModuleName], invCheckPeriod, app.SupplyKeeper, auth.FeeCollectorName, diff --git a/simapp/codec.go b/simapp/codec.go index 8f87e7e324b1..a31e9d6c3489 100644 --- a/simapp/codec.go +++ b/simapp/codec.go @@ -4,23 +4,25 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" + "github.com/cosmos/cosmos-sdk/x/slashing" "github.com/cosmos/cosmos-sdk/x/staking" ) // AppCodec defines the application-level codec. This codec contains all the // required module-specific codecs that are to be provided upon initialization. type AppCodec struct { - amino *codec.Codec - - Staking *staking.Codec + amino *codec.Codec + Staking *staking.Codec + Slashing *slashing.Codec } func NewAppCodec() *AppCodec { amino := MakeCodec() return &AppCodec{ - amino: amino, - Staking: staking.NewCodec(amino), + amino: amino, + Staking: staking.NewCodec(amino), + Slashing: slashing.NewCodec(amino), } } diff --git a/types/proto.go b/types/proto.go index e4cdbdc511c0..b6978c1eb9a5 100644 --- a/types/proto.go +++ b/types/proto.go @@ -1,7 +1,7 @@ package types import ( - _ "github.com/gogo/protobuf/gogoproto" // nolint + _ "github.com/gogo/protobuf/gogoproto" // nolint _ "github.com/regen-network/cosmos-proto" // nolint ) diff --git a/x/slashing/alias.go b/x/slashing/alias.go index 38d556a6e492..9e199645496d 100644 --- a/x/slashing/alias.go +++ b/x/slashing/alias.go @@ -34,6 +34,7 @@ const ( var ( // functions aliases + NewKeeper = keeper.NewKeeper NewQuerier = keeper.NewQuerier RegisterCodec = types.RegisterCodec @@ -62,6 +63,7 @@ var ( NewValidatorSigningInfo = types.NewValidatorSigningInfo // variable aliases + NewCodec = types.NewCodec ModuleCdc = types.ModuleCdc ValidatorSigningInfoKey = types.ValidatorSigningInfoKey ValidatorMissedBlockBitArrayKey = types.ValidatorMissedBlockBitArrayKey @@ -79,6 +81,7 @@ var ( type ( Hooks = keeper.Hooks Keeper = keeper.Keeper + Codec = types.Codec GenesisState = types.GenesisState MissedBlock = types.MissedBlock MsgUnjail = types.MsgUnjail diff --git a/x/slashing/internal/keeper/keeper.go b/x/slashing/internal/keeper/keeper.go index e725519314d1..ba1858cfe463 100644 --- a/x/slashing/internal/keeper/keeper.go +++ b/x/slashing/internal/keeper/keeper.go @@ -14,13 +14,13 @@ import ( // Keeper of the slashing store type Keeper struct { storeKey sdk.StoreKey - cdc *codec.Codec + cdc codec.Marshaler sk types.StakingKeeper paramspace types.ParamSubspace } // NewKeeper creates a slashing keeper -func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, sk types.StakingKeeper, paramspace types.ParamSubspace) Keeper { +func NewKeeper(cdc codec.Marshaler, key sdk.StoreKey, sk types.StakingKeeper, paramspace types.ParamSubspace) Keeper { return Keeper{ storeKey: key, cdc: cdc, diff --git a/x/slashing/internal/types/codec.go b/x/slashing/internal/types/codec.go index 34790d54d630..5d24296f6b13 100644 --- a/x/slashing/internal/types/codec.go +++ b/x/slashing/internal/types/codec.go @@ -10,11 +10,25 @@ func RegisterCodec(cdc *codec.Codec) { } // ModuleCdc defines the module codec -var ModuleCdc *codec.Codec +//var ModuleCdc *codec.Codec + +type Codec struct { + codec.Marshaler + // Keep reference to the amino codec to allow backwards compatibility along + // with type, and interface registration. + amino *codec.Codec +} + +func NewCodec(amino *codec.Codec) *Codec { + return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino} +} + +var ModuleCdc *Codec func init() { - ModuleCdc = codec.New() - RegisterCodec(ModuleCdc) - codec.RegisterCrypto(ModuleCdc) - ModuleCdc.Seal() + ModuleCdc = NewCodec(codec.New()) + //ModuleCdc = codec.New() + RegisterCodec(ModuleCdc.amino) + //codec.RegisterCrypto(ModuleCdc) + ModuleCdc.amino.Seal() } diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go new file mode 100644 index 000000000000..77c28bdb3b0a --- /dev/null +++ b/x/slashing/internal/types/types.pb.go @@ -0,0 +1,326 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: types.proto + +package cosmos_sdk_x_params_v1 + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/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.ProtoPackageIsVersion3 // please upgrade the proto package + +type MsgUnjail struct { + ValidatorAddr string `protobuf:"bytes,1,opt,name=ValidatorAddr,proto3" json:"ValidatorAddr,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *MsgUnjail) Reset() { *m = MsgUnjail{} } +func (m *MsgUnjail) String() string { return proto.CompactTextString(m) } +func (*MsgUnjail) ProtoMessage() {} +func (*MsgUnjail) Descriptor() ([]byte, []int) { + return fileDescriptor_d938547f84707355, []int{0} +} +func (m *MsgUnjail) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUnjail) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUnjail.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 *MsgUnjail) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUnjail.Merge(m, src) +} +func (m *MsgUnjail) XXX_Size() int { + return m.Size() +} +func (m *MsgUnjail) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUnjail.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUnjail proto.InternalMessageInfo + +func (m *MsgUnjail) GetValidatorAddr() string { + if m != nil { + return m.ValidatorAddr + } + return "" +} + +func init() { + proto.RegisterType((*MsgUnjail)(nil), "cosmos_sdk.x.params.v1.MsgUnjail") +} + +func init() { proto.RegisterFile("types.proto", fileDescriptor_d938547f84707355) } + +var fileDescriptor_d938547f84707355 = []byte{ + // 124 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2e, 0xa9, 0x2c, 0x48, + 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x4b, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0x8e, + 0x2f, 0x4e, 0xc9, 0xd6, 0xab, 0xd0, 0x2b, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x33, 0x54, + 0x32, 0xe4, 0xe2, 0xf4, 0x2d, 0x4e, 0x0f, 0xcd, 0xcb, 0x4a, 0xcc, 0xcc, 0x11, 0x52, 0xe1, 0xe2, + 0x0d, 0x4b, 0xcc, 0xc9, 0x4c, 0x49, 0x2c, 0xc9, 0x2f, 0x72, 0x4c, 0x49, 0x29, 0x92, 0x60, 0x54, + 0x60, 0xd4, 0xe0, 0x0c, 0x42, 0x15, 0x74, 0x12, 0x38, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, + 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x67, 0x3c, 0x96, 0x63, 0x48, 0x62, 0x03, 0xdb, 0x61, 0x0c, 0x08, + 0x00, 0x00, 0xff, 0xff, 0xe8, 0x59, 0x8c, 0x6b, 0x72, 0x00, 0x00, 0x00, +} + +func (m *MsgUnjail) 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 *MsgUnjail) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUnjail) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } + if len(m.ValidatorAddr) > 0 { + i -= len(m.ValidatorAddr) + copy(dAtA[i:], m.ValidatorAddr) + i = encodeVarintTypes(dAtA, i, uint64(len(m.ValidatorAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgUnjail) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddr) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgUnjail) 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 ErrIntOverflowTypes + } + 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: MsgUnjail: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUnjail: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTypes(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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrInvalidLengthTypes + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTypes + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTypes + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto new file mode 100644 index 000000000000..1ad352c36c1c --- /dev/null +++ b/x/slashing/internal/types/types.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; +package cosmos_sdk.x.slashing.v1; + + +message MsgUnjail { + string address = 1; + +} \ No newline at end of file From af6b87670c1be19ec3990a426afef6b54be593ee Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sat, 8 Feb 2020 00:50:50 +0530 Subject: [PATCH 11/52] Add proto msg type for MsgUnJail --- x/slashing/internal/types/msg.go | 8 +- x/slashing/internal/types/types.pb.go | 304 +++----------------------- x/slashing/internal/types/types.proto | 9 +- 3 files changed, 43 insertions(+), 278 deletions(-) diff --git a/x/slashing/internal/types/msg.go b/x/slashing/internal/types/msg.go index b2ccdce173ba..aaff6f5252a7 100644 --- a/x/slashing/internal/types/msg.go +++ b/x/slashing/internal/types/msg.go @@ -8,9 +8,9 @@ import ( var _ sdk.Msg = &MsgUnjail{} // MsgUnjail - struct for unjailing jailed validator -type MsgUnjail struct { - ValidatorAddr sdk.ValAddress `json:"address" yaml:"address"` // address of the validator operator -} +//type MsgUnjail struct { +// ValidatorAddr sdk.ValAddress `json:"address" yaml:"address"` // address of the validator operator +//} // NewMsgUnjail creates a new MsgUnjail instance func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail { @@ -19,7 +19,7 @@ func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail { } } -//nolint +// nolint func (msg MsgUnjail) Route() string { return RouterKey } func (msg MsgUnjail) Type() string { return "unjail" } func (msg MsgUnjail) GetSigners() []sdk.AccAddress { diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 77c28bdb3b0a..2573dbd70763 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -1,14 +1,13 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: types.proto +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: x/slashing/internal/types/types.proto -package cosmos_sdk_x_params_v1 +package types import ( fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/golang/protobuf/proto" - io "io" math "math" - math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -23,7 +22,7 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package type MsgUnjail struct { - ValidatorAddr string `protobuf:"bytes,1,opt,name=ValidatorAddr,proto3" json:"ValidatorAddr,omitempty"` + ValidatorAddr []byte `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3" json:"validator_addr,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -33,28 +32,20 @@ func (m *MsgUnjail) Reset() { *m = MsgUnjail{} } func (m *MsgUnjail) String() string { return proto.CompactTextString(m) } func (*MsgUnjail) ProtoMessage() {} func (*MsgUnjail) Descriptor() ([]byte, []int) { - return fileDescriptor_d938547f84707355, []int{0} + return fileDescriptor_2b882c3b0cdd6f57, []int{0} } + func (m *MsgUnjail) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) + return xxx_messageInfo_MsgUnjail.Unmarshal(m, b) } func (m *MsgUnjail) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgUnjail.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } + return xxx_messageInfo_MsgUnjail.Marshal(b, m, deterministic) } func (m *MsgUnjail) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgUnjail.Merge(m, src) } func (m *MsgUnjail) XXX_Size() int { - return m.Size() + return xxx_messageInfo_MsgUnjail.Size(m) } func (m *MsgUnjail) XXX_DiscardUnknown() { xxx_messageInfo_MsgUnjail.DiscardUnknown(m) @@ -62,265 +53,34 @@ func (m *MsgUnjail) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUnjail proto.InternalMessageInfo -func (m *MsgUnjail) GetValidatorAddr() string { +func (m *MsgUnjail) GetValidatorAddr() []byte { if m != nil { return m.ValidatorAddr } - return "" + return nil } func init() { - proto.RegisterType((*MsgUnjail)(nil), "cosmos_sdk.x.params.v1.MsgUnjail") -} - -func init() { proto.RegisterFile("types.proto", fileDescriptor_d938547f84707355) } - -var fileDescriptor_d938547f84707355 = []byte{ - // 124 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2e, 0xa9, 0x2c, 0x48, - 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x4b, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0x8e, - 0x2f, 0x4e, 0xc9, 0xd6, 0xab, 0xd0, 0x2b, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x33, 0x54, - 0x32, 0xe4, 0xe2, 0xf4, 0x2d, 0x4e, 0x0f, 0xcd, 0xcb, 0x4a, 0xcc, 0xcc, 0x11, 0x52, 0xe1, 0xe2, - 0x0d, 0x4b, 0xcc, 0xc9, 0x4c, 0x49, 0x2c, 0xc9, 0x2f, 0x72, 0x4c, 0x49, 0x29, 0x92, 0x60, 0x54, - 0x60, 0xd4, 0xe0, 0x0c, 0x42, 0x15, 0x74, 0x12, 0x38, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, - 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x67, 0x3c, 0x96, 0x63, 0x48, 0x62, 0x03, 0xdb, 0x61, 0x0c, 0x08, - 0x00, 0x00, 0xff, 0xff, 0xe8, 0x59, 0x8c, 0x6b, 0x72, 0x00, 0x00, 0x00, -} - -func (m *MsgUnjail) 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 + proto.RegisterType((*MsgUnjail)(nil), "cosmos_sdk.x.slashing.v1.MsgUnjail") } -func (m *MsgUnjail) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgUnjail) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.ValidatorAddr) > 0 { - i -= len(m.ValidatorAddr) - copy(dAtA[i:], m.ValidatorAddr) - i = encodeVarintTypes(dAtA, i, uint64(len(m.ValidatorAddr))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { - offset -= sovTypes(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *MsgUnjail) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ValidatorAddr) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovTypes(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTypes(x uint64) (n int) { - return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *MsgUnjail) 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 ErrIntOverflowTypes - } - 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: MsgUnjail: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUnjail: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddr", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ValidatorAddr = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipTypes(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, ErrIntOverflowTypes - } - 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, ErrIntOverflowTypes - } - 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, ErrIntOverflowTypes - } - 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, ErrInvalidLengthTypes - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupTypes - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthTypes - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF +func init() { + proto.RegisterFile("x/slashing/internal/types/types.proto", fileDescriptor_2b882c3b0cdd6f57) +} + +var fileDescriptor_2b882c3b0cdd6f57 = []byte{ + // 207 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b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8a, 0x15, 0xac, 0x24, 0x89, 0x0d, 0xec, 0x10, + 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x83, 0x86, 0x07, 0xe9, 0xf3, 0x00, 0x00, 0x00, } - -var ( - ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index 1ad352c36c1c..deaefe21cd52 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -1,8 +1,13 @@ syntax = "proto3"; package cosmos_sdk.x.slashing.v1; +option go_package = "types"; -message MsgUnjail { - string address = 1; +import "third_party/proto/gogoproto/gogo.proto"; +message MsgUnjail { + bytes validator_addr = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", + (gogoproto.moretags) = "yaml:\"address\"" + ]; } \ No newline at end of file From 5fb74421de29eb0c0ee5e393f3cd86acbcfdcf3a Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sat, 8 Feb 2020 00:52:01 +0530 Subject: [PATCH 12/52] gofmt --- x/slashing/internal/types/msg.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/x/slashing/internal/types/msg.go b/x/slashing/internal/types/msg.go index aaff6f5252a7..b99a8915fd41 100644 --- a/x/slashing/internal/types/msg.go +++ b/x/slashing/internal/types/msg.go @@ -7,11 +7,6 @@ import ( // verify interface at compile time var _ sdk.Msg = &MsgUnjail{} -// MsgUnjail - struct for unjailing jailed validator -//type MsgUnjail struct { -// ValidatorAddr sdk.ValAddress `json:"address" yaml:"address"` // address of the validator operator -//} - // NewMsgUnjail creates a new MsgUnjail instance func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail { return MsgUnjail{ @@ -19,7 +14,7 @@ func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail { } } -// nolint +//nolint func (msg MsgUnjail) Route() string { return RouterKey } func (msg MsgUnjail) Type() string { return "unjail" } func (msg MsgUnjail) GetSigners() []sdk.AccAddress { From 25f7f9791090dcc076f0236c22fb9537f76bfe67 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sat, 8 Feb 2020 01:03:22 +0530 Subject: [PATCH 13/52] Remove ModuleCodec --- x/slashing/internal/types/codec.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/x/slashing/internal/types/codec.go b/x/slashing/internal/types/codec.go index 5d24296f6b13..dbb7a9d0b8b6 100644 --- a/x/slashing/internal/types/codec.go +++ b/x/slashing/internal/types/codec.go @@ -9,9 +9,6 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) } -// ModuleCdc defines the module codec -//var ModuleCdc *codec.Codec - type Codec struct { codec.Marshaler // Keep reference to the amino codec to allow backwards compatibility along From 12111ae657b3d7d75a9e574bdd8c471a0dd6e7da Mon Sep 17 00:00:00 2001 From: anilCSE Date: Tue, 11 Feb 2020 17:07:26 +0530 Subject: [PATCH 14/52] Add changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e7e6b943f3d..dad9530990f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,11 @@ for JSON encoding. * Every reference of `crypto.Pubkey` in context of a `Validator` is now of type string. `GetPubKeyFromBech32` must be used to get the `crypto.Pubkey`. * The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type provided is specified by `ModuleCdc`. +* (slashing) [\#5627](https://github.com/cosmos/cosmos-sdk/pull/5627) Migrate the `x/slashing` module to use Protocol Buffer for state +serialization instead of Amino. The exact codec used is `codec.HybridCodec` which utilizes Protobuf for binary encoding and Amino +for JSON encoding. + * The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type + provided is specified by `ModuleCdc`. ### Improvements From af95b297f341779be5bae9f4cc6887a83675ec9a Mon Sep 17 00:00:00 2001 From: anilCSE Date: Tue, 11 Feb 2020 17:20:42 +0530 Subject: [PATCH 15/52] Fix naming --- x/slashing/internal/types/types.pb.go | 24 ++++++++++++------------ x/slashing/internal/types/types.proto | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 2573dbd70763..15b5c6047d6f 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -22,7 +22,7 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package type MsgUnjail struct { - ValidatorAddr []byte `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3" json:"validator_addr,omitempty"` + ValidatorAddress []byte `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -53,9 +53,9 @@ func (m *MsgUnjail) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUnjail proto.InternalMessageInfo -func (m *MsgUnjail) GetValidatorAddr() []byte { +func (m *MsgUnjail) GetValidatorAddress() []byte { if m != nil { - return m.ValidatorAddr + return m.ValidatorAddress } return nil } @@ -69,18 +69,18 @@ func init() { } var fileDescriptor_2b882c3b0cdd6f57 = []byte{ - // 207 bytes of a gzipped FileDescriptorProto + // 208 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0xad, 0xd0, 0x2f, 0xce, 0x49, 0x2c, 0xce, 0xc8, 0xcc, 0x4b, 0xd7, 0xcf, 0xcc, 0x2b, 0x49, 0x2d, 0xca, 0x4b, 0xcc, 0xd1, 0x2f, 0xa9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0x76, 0x46, 0x2e, 0x4e, 0xdf, + 0xe2, 0xf4, 0xd0, 0xbc, 0xac, 0xc4, 0xcc, 0x1c, 0xa1, 0x2a, 0x2e, 0xc1, 0xb2, 0xc4, 0x9c, 0xcc, + 0x94, 0xc4, 0x92, 0xfc, 0xa2, 0xf8, 0xc4, 0x94, 0x94, 0xa2, 0xd4, 0xe2, 0x62, 0x09, 0x46, 0x05, + 0x46, 0x0d, 0x1e, 0x27, 0xdf, 0x4f, 0xf7, 0xe4, 0x25, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, 0x30, + 0x94, 0x28, 0xfd, 0xba, 0x27, 0xaf, 0x9b, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, + 0xab, 0x0f, 0x71, 0x15, 0x94, 0xd2, 0x05, 0x3a, 0x0e, 0xea, 0xe8, 0xb0, 0xc4, 0x1c, 0x47, 0x88, + 0x8e, 0x20, 0x01, 0xb8, 0x21, 0x50, 0x11, 0x27, 0xf6, 0x28, 0x56, 0xb0, 0xaa, 0x24, 0x36, 0xb0, + 0xcb, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x40, 0xa7, 0xdc, 0x9f, 0x04, 0x01, 0x00, 0x00, } diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index deaefe21cd52..a7d242658d6d 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -6,8 +6,8 @@ option go_package = "types"; import "third_party/proto/gogoproto/gogo.proto"; message MsgUnjail { - bytes validator_addr = 1 [ - (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", - (gogoproto.moretags) = "yaml:\"address\"" + bytes validator_address = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress", + (gogoproto.moretags) = "yaml:\"validator_address\"" ]; } \ No newline at end of file From ba3ee92cbf7f5726415949b40ffcbcbe143b7bb6 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Tue, 11 Feb 2020 18:29:47 +0530 Subject: [PATCH 16/52] Fix undefined errors --- x/slashing/handler.go | 2 +- x/slashing/internal/types/msg.go | 3 ++- x/slashing/internal/types/types.pb.go | 23 ++++++++++++----------- x/slashing/internal/types/types.proto | 5 +++-- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/x/slashing/handler.go b/x/slashing/handler.go index fe4ef7cb7c2e..cb6690716bcb 100644 --- a/x/slashing/handler.go +++ b/x/slashing/handler.go @@ -33,7 +33,7 @@ func handleMsgUnjail(ctx sdk.Context, msg MsgUnjail, k Keeper) (*sdk.Result, err sdk.NewEvent( sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttribute(sdk.AttributeKeySender, msg.ValidatorAddr.String()), + sdk.NewAttribute(sdk.AttributeKeySender, string(msg.ValidatorAddr)), ), ) diff --git a/x/slashing/internal/types/msg.go b/x/slashing/internal/types/msg.go index b99a8915fd41..49fd830d9615 100644 --- a/x/slashing/internal/types/msg.go +++ b/x/slashing/internal/types/msg.go @@ -29,8 +29,9 @@ func (msg MsgUnjail) GetSignBytes() []byte { // ValidateBasic validity check for the AnteHandler func (msg MsgUnjail) ValidateBasic() error { - if msg.ValidatorAddr.Empty() { + if len(msg.ValidatorAddr) < 1 { //if empty return ErrBadValidatorAddr } + return nil } diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 15b5c6047d6f..0c2e770d4a85 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -21,8 +21,9 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package +// MsgUnjail - struct for unjailing jailed validator type MsgUnjail struct { - ValidatorAddress []byte `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + ValidatorAddr []byte `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3" json:"validator_addr,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -53,9 +54,9 @@ func (m *MsgUnjail) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUnjail proto.InternalMessageInfo -func (m *MsgUnjail) GetValidatorAddress() []byte { +func (m *MsgUnjail) GetValidatorAddr() []byte { if m != nil { - return m.ValidatorAddress + return m.ValidatorAddr } return nil } @@ -75,12 +76,12 @@ var fileDescriptor_2b882c3b0cdd6f57 = []byte{ 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x12, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, 0x30, 0x1d, 0x7a, 0x65, 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25, 0x95, 0xfa, 0x60, - 0xc5, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0xc4, 0x04, 0xa5, 0x76, 0x46, 0x2e, 0x4e, 0xdf, - 0xe2, 0xf4, 0xd0, 0xbc, 0xac, 0xc4, 0xcc, 0x1c, 0xa1, 0x2a, 0x2e, 0xc1, 0xb2, 0xc4, 0x9c, 0xcc, - 0x94, 0xc4, 0x92, 0xfc, 0xa2, 0xf8, 0xc4, 0x94, 0x94, 0xa2, 0xd4, 0xe2, 0x62, 0x09, 0x46, 0x05, - 0x46, 0x0d, 0x1e, 0x27, 0xdf, 0x4f, 0xf7, 0xe4, 0x25, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, 0x30, - 0x94, 0x28, 0xfd, 0xba, 0x27, 0xaf, 0x9b, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, - 0xab, 0x0f, 0x71, 0x15, 0x94, 0xd2, 0x05, 0x3a, 0x0e, 0xea, 0xe8, 0xb0, 0xc4, 0x1c, 0x47, 0x88, - 0x8e, 0x20, 0x01, 0xb8, 0x21, 0x50, 0x11, 0x27, 0xf6, 0x28, 0x56, 0xb0, 0xaa, 0x24, 0x36, 0xb0, - 0xcb, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x40, 0xa7, 0xdc, 0x9f, 0x04, 0x01, 0x00, 0x00, + 0xc5, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0xc4, 0x04, 0xa5, 0x46, 0x46, 0x2e, 0x4e, 0xdf, + 0xe2, 0xf4, 0xd0, 0xbc, 0xac, 0xc4, 0xcc, 0x1c, 0xa1, 0x12, 0x2e, 0xbe, 0xb2, 0xc4, 0x9c, 0xcc, + 0x94, 0xc4, 0x92, 0xfc, 0xa2, 0xf8, 0xc4, 0x94, 0x94, 0x22, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x1e, + 0x27, 0xdf, 0x4f, 0xf7, 0xe4, 0x25, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, 0x50, 0xe5, 0x53, 0x8b, + 0x8b, 0x95, 0x7e, 0xdd, 0x93, 0xd7, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, + 0xd5, 0x87, 0x38, 0x09, 0x4a, 0xe9, 0x02, 0x5d, 0x06, 0x75, 0x71, 0x58, 0x62, 0x8e, 0x23, 0x44, + 0x47, 0x10, 0x2f, 0xdc, 0x10, 0x90, 0x88, 0x13, 0x7b, 0x14, 0x2b, 0x58, 0x49, 0x12, 0x1b, 0xd8, + 0x4d, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0e, 0x44, 0xbf, 0xed, 0xfe, 0x00, 0x00, 0x00, } diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index a7d242658d6d..3c11cb236a0c 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -5,9 +5,10 @@ option go_package = "types"; import "third_party/proto/gogoproto/gogo.proto"; +// MsgUnjail - struct for unjailing jailed validator message MsgUnjail { - bytes validator_address = 1 [ + bytes validator_addr = 1 [ (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress", (gogoproto.moretags) = "yaml:\"validator_address\"" ]; -} \ No newline at end of file +} From d90bb3e497bbac0d2b7e6c13ee7ea24963a29609 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Tue, 11 Feb 2020 19:39:38 +0530 Subject: [PATCH 17/52] Add ValidatorSigningInfo protobuf implementation --- x/slashing/internal/types/signing_info.go | 10 -- x/slashing/internal/types/types.pb.go | 126 +++++++++++++++++++--- x/slashing/internal/types/types.proto | 18 ++++ 3 files changed, 130 insertions(+), 24 deletions(-) diff --git a/x/slashing/internal/types/signing_info.go b/x/slashing/internal/types/signing_info.go index 431658c2241a..66870f3032a6 100644 --- a/x/slashing/internal/types/signing_info.go +++ b/x/slashing/internal/types/signing_info.go @@ -7,16 +7,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// ValidatorSigningInfo defines the signing info for a validator -type ValidatorSigningInfo struct { - Address sdk.ConsAddress `json:"address" yaml:"address"` // validator consensus address - StartHeight int64 `json:"start_height" yaml:"start_height"` // height at which validator was first a candidate OR was unjailed - IndexOffset int64 `json:"index_offset" yaml:"index_offset"` // index offset into signed block bit array - JailedUntil time.Time `json:"jailed_until" yaml:"jailed_until"` // timestamp validator cannot be unjailed until - Tombstoned bool `json:"tombstoned" yaml:"tombstoned"` // whether or not a validator has been tombstoned (killed out of validator set) - MissedBlocksCounter int64 `json:"missed_blocks_counter" yaml:"missed_blocks_counter"` // missed blocks counter (to avoid scanning the array every time) -} - // NewValidatorSigningInfo creates a new ValidatorSigningInfo instance func NewValidatorSigningInfo( condAddr sdk.ConsAddress, startHeight, indexOffset int64, diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 0c2e770d4a85..7abcbeeb58da 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -6,6 +6,7 @@ package types import ( fmt "fmt" _ "github.com/gogo/protobuf/gogoproto" + types "github.com/gogo/protobuf/types" proto "github.com/golang/protobuf/proto" math "math" ) @@ -61,8 +62,89 @@ func (m *MsgUnjail) GetValidatorAddr() []byte { return nil } +// ValidatorSigningInfo defines the signing info for a validator +type ValidatorSigningInfo struct { + Address []byte `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + StartHeight int64 `protobuf:"varint,2,opt,name=start_height,json=startHeight,proto3" json:"start_height,omitempty"` + IndexOffset int64 `protobuf:"varint,3,opt,name=index_offset,json=indexOffset,proto3" json:"index_offset,omitempty"` + JailedUntil *types.Timestamp `protobuf:"bytes,4,opt,name=jailed_until,json=jailedUntil,proto3" json:"jailed_until,omitempty"` + Tombstoned bool `protobuf:"varint,5,opt,name=tombstoned,proto3" json:"tombstoned,omitempty"` + MissedBlocksCounter int64 `protobuf:"varint,6,opt,name=missed_blocks_counter,json=missedBlocksCounter,proto3" json:"missed_blocks_counter,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ValidatorSigningInfo) Reset() { *m = ValidatorSigningInfo{} } +func (m *ValidatorSigningInfo) String() string { return proto.CompactTextString(m) } +func (*ValidatorSigningInfo) ProtoMessage() {} +func (*ValidatorSigningInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_2b882c3b0cdd6f57, []int{1} +} + +func (m *ValidatorSigningInfo) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ValidatorSigningInfo.Unmarshal(m, b) +} +func (m *ValidatorSigningInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ValidatorSigningInfo.Marshal(b, m, deterministic) +} +func (m *ValidatorSigningInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorSigningInfo.Merge(m, src) +} +func (m *ValidatorSigningInfo) XXX_Size() int { + return xxx_messageInfo_ValidatorSigningInfo.Size(m) +} +func (m *ValidatorSigningInfo) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorSigningInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorSigningInfo proto.InternalMessageInfo + +func (m *ValidatorSigningInfo) GetAddress() []byte { + if m != nil { + return m.Address + } + return nil +} + +func (m *ValidatorSigningInfo) GetStartHeight() int64 { + if m != nil { + return m.StartHeight + } + return 0 +} + +func (m *ValidatorSigningInfo) GetIndexOffset() int64 { + if m != nil { + return m.IndexOffset + } + return 0 +} + +func (m *ValidatorSigningInfo) GetJailedUntil() *types.Timestamp { + if m != nil { + return m.JailedUntil + } + return nil +} + +func (m *ValidatorSigningInfo) GetTombstoned() bool { + if m != nil { + return m.Tombstoned + } + return false +} + +func (m *ValidatorSigningInfo) GetMissedBlocksCounter() int64 { + if m != nil { + return m.MissedBlocksCounter + } + return 0 +} + func init() { proto.RegisterType((*MsgUnjail)(nil), "cosmos_sdk.x.slashing.v1.MsgUnjail") + proto.RegisterType((*ValidatorSigningInfo)(nil), "cosmos_sdk.x.slashing.v1.ValidatorSigningInfo") } func init() { @@ -70,18 +152,34 @@ func init() { } var fileDescriptor_2b882c3b0cdd6f57 = []byte{ - // 208 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0xad, 0xd0, 0x2f, 0xce, - 0x49, 0x2c, 0xce, 0xc8, 0xcc, 0x4b, 0xd7, 0xcf, 0xcc, 0x2b, 0x49, 0x2d, 0xca, 0x4b, 0xcc, 0xd1, - 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x12, 0xc9, - 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, 0x30, 0x1d, 0x7a, 0x65, - 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25, 0x95, 0xfa, 0x60, - 0xc5, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0xc4, 0x04, 0xa5, 0x46, 0x46, 0x2e, 0x4e, 0xdf, - 0xe2, 0xf4, 0xd0, 0xbc, 0xac, 0xc4, 0xcc, 0x1c, 0xa1, 0x12, 0x2e, 0xbe, 0xb2, 0xc4, 0x9c, 0xcc, - 0x94, 0xc4, 0x92, 0xfc, 0xa2, 0xf8, 0xc4, 0x94, 0x94, 0x22, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x1e, - 0x27, 0xdf, 0x4f, 0xf7, 0xe4, 0x25, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, 0x50, 0xe5, 0x53, 0x8b, - 0x8b, 0x95, 0x7e, 0xdd, 0x93, 0xd7, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, - 0xd5, 0x87, 0x38, 0x09, 0x4a, 0xe9, 0x02, 0x5d, 0x06, 0x75, 0x71, 0x58, 0x62, 0x8e, 0x23, 0x44, - 0x47, 0x10, 0x2f, 0xdc, 0x10, 0x90, 0x88, 0x13, 0x7b, 0x14, 0x2b, 0x58, 0x49, 0x12, 0x1b, 0xd8, - 0x4d, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0e, 0x44, 0xbf, 0xed, 0xfe, 0x00, 0x00, 0x00, + // 454 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x52, 0xcd, 0x6e, 0xd3, 0x40, + 0x10, 0x26, 0x84, 0xb6, 0xb0, 0x09, 0x95, 0x70, 0xa9, 0xb0, 0x22, 0x24, 0x57, 0x96, 0x40, 0x5c, + 0xba, 0x16, 0x20, 0x2e, 0xbd, 0xe1, 0x72, 0x80, 0x43, 0x85, 0x64, 0xda, 0x1e, 0x38, 0x60, 0xad, + 0xe3, 0xcd, 0x7a, 0xe9, 0x7a, 0x27, 0xf2, 0x4e, 0xaa, 0xe4, 0xc8, 0x1b, 0xf0, 0x58, 0xbc, 0x03, + 0x52, 0x78, 0x07, 0x8e, 0x9c, 0x58, 0xef, 0xc6, 0xc4, 0x20, 0x0e, 0xbd, 0xd8, 0x9e, 0x6f, 0xe6, + 0xfb, 0xbe, 0xf9, 0x31, 0x79, 0xb2, 0x4c, 0x8c, 0x62, 0xa6, 0x92, 0x5a, 0x24, 0x52, 0x23, 0x6f, + 0x34, 0x53, 0x09, 0xae, 0xe6, 0xdc, 0xf8, 0x27, 0x9d, 0x37, 0x80, 0x10, 0x84, 0x53, 0x30, 0x35, + 0x98, 0xdc, 0x94, 0x57, 0x74, 0x49, 0x3b, 0x06, 0xbd, 0x7e, 0x3e, 0x79, 0x8a, 0x95, 0x6c, 0xca, + 0x7c, 0xce, 0x1a, 0x5c, 0x25, 0xae, 0x38, 0x11, 0x20, 0x60, 0xfb, 0xe5, 0x15, 0x26, 0x91, 0x00, + 0x10, 0x8a, 0xfb, 0x92, 0x62, 0x31, 0x4b, 0x50, 0xd6, 0xdc, 0x20, 0xab, 0xe7, 0xbe, 0x20, 0xfe, + 0x32, 0x20, 0xf7, 0xce, 0x8c, 0xb8, 0xd0, 0x9f, 0x99, 0x54, 0x01, 0x92, 0xfd, 0x6b, 0xa6, 0x64, + 0xc9, 0x10, 0x9a, 0x9c, 0x95, 0x65, 0x13, 0x0e, 0x8e, 0x06, 0xcf, 0xc6, 0xe9, 0xd9, 0xcf, 0x75, + 0x14, 0xae, 0x58, 0xad, 0x4e, 0xe2, 0xbf, 0xf3, 0xdc, 0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x4d, 0x0f, 0x2d, + 0xfb, 0x81, 0x67, 0x6f, 0x73, 0x71, 0xd6, 0x2b, 0x0c, 0xce, 0xc9, 0x61, 0x2d, 0x8d, 0xb1, 0xc2, + 0x85, 0x82, 0xe9, 0x95, 0xc9, 0xa7, 0xb0, 0x68, 0x7f, 0xce, 0x70, 0xd7, 0xcd, 0x76, 0x64, 0x15, + 0x1e, 0x7b, 0x85, 0xff, 0x96, 0xc5, 0xd9, 0x81, 0xc7, 0x53, 0x07, 0x9f, 0x7a, 0x34, 0xdd, 0xfb, + 0xb8, 0xe3, 0x4e, 0x50, 0xec, 0xba, 0xb9, 0x5e, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x07, 0x25, + 0xe1, 0xf1, 0xfd, 0x02, 0x00, 0x00, } diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index 3c11cb236a0c..44c0cd435524 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -4,6 +4,7 @@ package cosmos_sdk.x.slashing.v1; option go_package = "types"; import "third_party/proto/gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; // MsgUnjail - struct for unjailing jailed validator message MsgUnjail { @@ -12,3 +13,20 @@ message MsgUnjail { (gogoproto.moretags) = "yaml:\"validator_address\"" ]; } + +// ValidatorSigningInfo defines the signing info for a validator +message ValidatorSigningInfo { + bytes address = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress", + (gogoproto.moretags) = "yaml:\"address\"" // validator consensus address + ]; + int64 start_height = 2 [(gogoproto.moretags) = "yaml:\"start_height\""]; // height at which validator was first a candidate OR was unjailed + int64 index_offset = 3 [(gogoproto.moretags) = "yaml:\"index_offset\""]; // index offset into signed block bit array + google.protobuf.Timestamp jailed_until = 4 [ + (gogoproto.moretags) = "yaml:\"jailed_until\"", + (gogoproto.nullable) = false, + (gogoproto.stdtime) = true + ]; // timestamp validator cannot be unjailed until + bool tombstoned = 5 [(gogoproto.moretags) = "yaml:\"tombstoned\""]; // whether or not a validator has been tombstoned (killed out of validator set) + int64 missed_blocks_counter = 6 [(gogoproto.moretags) = "yaml:\"missed_blocks_counter\""]; // missed blocks counter (to avoid scanning the array every time) +} \ No newline at end of file From 2ca862fd847a183973d6715ce228765b080a9d03 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Tue, 11 Feb 2020 21:07:17 +0530 Subject: [PATCH 18/52] Revert unnecessary codec migration --- x/slashing/internal/types/signing_info.go | 10 ++ x/slashing/internal/types/types.pb.go | 126 +++------------------- x/slashing/internal/types/types.proto | 18 ---- 3 files changed, 24 insertions(+), 130 deletions(-) diff --git a/x/slashing/internal/types/signing_info.go b/x/slashing/internal/types/signing_info.go index 66870f3032a6..431658c2241a 100644 --- a/x/slashing/internal/types/signing_info.go +++ b/x/slashing/internal/types/signing_info.go @@ -7,6 +7,16 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) +// ValidatorSigningInfo defines the signing info for a validator +type ValidatorSigningInfo struct { + Address sdk.ConsAddress `json:"address" yaml:"address"` // validator consensus address + StartHeight int64 `json:"start_height" yaml:"start_height"` // height at which validator was first a candidate OR was unjailed + IndexOffset int64 `json:"index_offset" yaml:"index_offset"` // index offset into signed block bit array + JailedUntil time.Time `json:"jailed_until" yaml:"jailed_until"` // timestamp validator cannot be unjailed until + Tombstoned bool `json:"tombstoned" yaml:"tombstoned"` // whether or not a validator has been tombstoned (killed out of validator set) + MissedBlocksCounter int64 `json:"missed_blocks_counter" yaml:"missed_blocks_counter"` // missed blocks counter (to avoid scanning the array every time) +} + // NewValidatorSigningInfo creates a new ValidatorSigningInfo instance func NewValidatorSigningInfo( condAddr sdk.ConsAddress, startHeight, indexOffset int64, diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 7abcbeeb58da..0c2e770d4a85 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -6,7 +6,6 @@ package types import ( fmt "fmt" _ "github.com/gogo/protobuf/gogoproto" - types "github.com/gogo/protobuf/types" proto "github.com/golang/protobuf/proto" math "math" ) @@ -62,89 +61,8 @@ func (m *MsgUnjail) GetValidatorAddr() []byte { return nil } -// ValidatorSigningInfo defines the signing info for a validator -type ValidatorSigningInfo struct { - Address []byte `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - StartHeight int64 `protobuf:"varint,2,opt,name=start_height,json=startHeight,proto3" json:"start_height,omitempty"` - IndexOffset int64 `protobuf:"varint,3,opt,name=index_offset,json=indexOffset,proto3" json:"index_offset,omitempty"` - JailedUntil *types.Timestamp `protobuf:"bytes,4,opt,name=jailed_until,json=jailedUntil,proto3" json:"jailed_until,omitempty"` - Tombstoned bool `protobuf:"varint,5,opt,name=tombstoned,proto3" json:"tombstoned,omitempty"` - MissedBlocksCounter int64 `protobuf:"varint,6,opt,name=missed_blocks_counter,json=missedBlocksCounter,proto3" json:"missed_blocks_counter,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ValidatorSigningInfo) Reset() { *m = ValidatorSigningInfo{} } -func (m *ValidatorSigningInfo) String() string { return proto.CompactTextString(m) } -func (*ValidatorSigningInfo) ProtoMessage() {} -func (*ValidatorSigningInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_2b882c3b0cdd6f57, []int{1} -} - -func (m *ValidatorSigningInfo) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ValidatorSigningInfo.Unmarshal(m, b) -} -func (m *ValidatorSigningInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ValidatorSigningInfo.Marshal(b, m, deterministic) -} -func (m *ValidatorSigningInfo) XXX_Merge(src proto.Message) { - xxx_messageInfo_ValidatorSigningInfo.Merge(m, src) -} -func (m *ValidatorSigningInfo) XXX_Size() int { - return xxx_messageInfo_ValidatorSigningInfo.Size(m) -} -func (m *ValidatorSigningInfo) XXX_DiscardUnknown() { - xxx_messageInfo_ValidatorSigningInfo.DiscardUnknown(m) -} - -var xxx_messageInfo_ValidatorSigningInfo proto.InternalMessageInfo - -func (m *ValidatorSigningInfo) GetAddress() []byte { - if m != nil { - return m.Address - } - return nil -} - -func (m *ValidatorSigningInfo) GetStartHeight() int64 { - if m != nil { - return m.StartHeight - } - return 0 -} - -func (m *ValidatorSigningInfo) GetIndexOffset() int64 { - if m != nil { - return m.IndexOffset - } - return 0 -} - -func (m *ValidatorSigningInfo) GetJailedUntil() *types.Timestamp { - if m != nil { - return m.JailedUntil - } - return nil -} - -func (m *ValidatorSigningInfo) GetTombstoned() bool { - if m != nil { - return m.Tombstoned - } - return false -} - -func (m *ValidatorSigningInfo) GetMissedBlocksCounter() int64 { - if m != nil { - return m.MissedBlocksCounter - } - return 0 -} - func init() { proto.RegisterType((*MsgUnjail)(nil), "cosmos_sdk.x.slashing.v1.MsgUnjail") - proto.RegisterType((*ValidatorSigningInfo)(nil), "cosmos_sdk.x.slashing.v1.ValidatorSigningInfo") } func init() { @@ -152,34 +70,18 @@ func init() { } var fileDescriptor_2b882c3b0cdd6f57 = []byte{ - // 454 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x52, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0x26, 0x84, 0xb6, 0xb0, 0x09, 0x95, 0x70, 0xa9, 0xb0, 0x22, 0x24, 0x57, 0x96, 0x40, 0x5c, - 0xba, 0x16, 0x20, 0x2e, 0xbd, 0xe1, 0x72, 0x80, 0x43, 0x85, 0x64, 0xda, 0x1e, 0x38, 0x60, 0xad, - 0xe3, 0xcd, 0x7a, 0xe9, 0x7a, 0x27, 0xf2, 0x4e, 0xaa, 0xe4, 0xc8, 0x1b, 0xf0, 0x58, 0xbc, 0x03, - 0x52, 0x78, 0x07, 0x8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fb, - 0xb8, 0xe3, 0x4e, 0x50, 0xec, 0xba, 0xb9, 0x5e, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x07, 0x25, - 0xe1, 0xf1, 0xfd, 0x02, 0x00, 0x00, + // 208 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0xad, 0xd0, 0x2f, 0xce, + 0x49, 0x2c, 0xce, 0xc8, 0xcc, 0x4b, 0xd7, 0xcf, 0xcc, 0x2b, 0x49, 0x2d, 0xca, 0x4b, 0xcc, 0xd1, + 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x12, 0xc9, + 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, 0x30, 0x1d, 0x7a, 0x65, + 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25, 0x95, 0xfa, 0x60, + 0xc5, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0xc4, 0x04, 0xa5, 0x46, 0x46, 0x2e, 0x4e, 0xdf, + 0xe2, 0xf4, 0xd0, 0xbc, 0xac, 0xc4, 0xcc, 0x1c, 0xa1, 0x12, 0x2e, 0xbe, 0xb2, 0xc4, 0x9c, 0xcc, + 0x94, 0xc4, 0x92, 0xfc, 0xa2, 0xf8, 0xc4, 0x94, 0x94, 0x22, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x1e, + 0x27, 0xdf, 0x4f, 0xf7, 0xe4, 0x25, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, 0x50, 0xe5, 0x53, 0x8b, + 0x8b, 0x95, 0x7e, 0xdd, 0x93, 0xd7, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, + 0xd5, 0x87, 0x38, 0x09, 0x4a, 0xe9, 0x02, 0x5d, 0x06, 0x75, 0x71, 0x58, 0x62, 0x8e, 0x23, 0x44, + 0x47, 0x10, 0x2f, 0xdc, 0x10, 0x90, 0x88, 0x13, 0x7b, 0x14, 0x2b, 0x58, 0x49, 0x12, 0x1b, 0xd8, + 0x4d, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0e, 0x44, 0xbf, 0xed, 0xfe, 0x00, 0x00, 0x00, } diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index 44c0cd435524..9a352d6d15c1 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -4,7 +4,6 @@ package cosmos_sdk.x.slashing.v1; option go_package = "types"; import "third_party/proto/gogoproto/gogo.proto"; -import "google/protobuf/timestamp.proto"; // MsgUnjail - struct for unjailing jailed validator message MsgUnjail { @@ -12,21 +11,4 @@ message MsgUnjail { (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress", (gogoproto.moretags) = "yaml:\"validator_address\"" ]; -} - -// ValidatorSigningInfo defines the signing info for a validator -message ValidatorSigningInfo { - bytes address = 1 [ - (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress", - (gogoproto.moretags) = "yaml:\"address\"" // validator consensus address - ]; - int64 start_height = 2 [(gogoproto.moretags) = "yaml:\"start_height\""]; // height at which validator was first a candidate OR was unjailed - int64 index_offset = 3 [(gogoproto.moretags) = "yaml:\"index_offset\""]; // index offset into signed block bit array - google.protobuf.Timestamp jailed_until = 4 [ - (gogoproto.moretags) = "yaml:\"jailed_until\"", - (gogoproto.nullable) = false, - (gogoproto.stdtime) = true - ]; // timestamp validator cannot be unjailed until - bool tombstoned = 5 [(gogoproto.moretags) = "yaml:\"tombstoned\""]; // whether or not a validator has been tombstoned (killed out of validator set) - int64 missed_blocks_counter = 6 [(gogoproto.moretags) = "yaml:\"missed_blocks_counter\""]; // missed blocks counter (to avoid scanning the array every time) } \ No newline at end of file From 21b9cbad76a055feb3c821ba51f63c2847757b4d Mon Sep 17 00:00:00 2001 From: anilCSE Date: Tue, 11 Feb 2020 23:29:48 +0530 Subject: [PATCH 19/52] Add ValidatorSigningInfo proto codec --- x/slashing/internal/keeper/signing_info.go | 2 +- x/slashing/internal/types/signing_info.go | 10 - x/slashing/internal/types/types.pb.go | 726 ++++++++++++++++++++- x/slashing/internal/types/types.proto | 20 +- 4 files changed, 720 insertions(+), 38 deletions(-) diff --git a/x/slashing/internal/keeper/signing_info.go b/x/slashing/internal/keeper/signing_info.go index 1162c258f35a..769b3c2cf898 100644 --- a/x/slashing/internal/keeper/signing_info.go +++ b/x/slashing/internal/keeper/signing_info.go @@ -31,7 +31,7 @@ func (k Keeper) HasValidatorSigningInfo(ctx sdk.Context, consAddr sdk.ConsAddres // SetValidatorSigningInfo sets the validator signing info to a consensus address key func (k Keeper) SetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress, info types.ValidatorSigningInfo) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(info) + bz := k.cdc.MustMarshalBinaryLengthPrefixed(&info) store.Set(types.GetValidatorSigningInfoKey(address), bz) } diff --git a/x/slashing/internal/types/signing_info.go b/x/slashing/internal/types/signing_info.go index 431658c2241a..66870f3032a6 100644 --- a/x/slashing/internal/types/signing_info.go +++ b/x/slashing/internal/types/signing_info.go @@ -7,16 +7,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// ValidatorSigningInfo defines the signing info for a validator -type ValidatorSigningInfo struct { - Address sdk.ConsAddress `json:"address" yaml:"address"` // validator consensus address - StartHeight int64 `json:"start_height" yaml:"start_height"` // height at which validator was first a candidate OR was unjailed - IndexOffset int64 `json:"index_offset" yaml:"index_offset"` // index offset into signed block bit array - JailedUntil time.Time `json:"jailed_until" yaml:"jailed_until"` // timestamp validator cannot be unjailed until - Tombstoned bool `json:"tombstoned" yaml:"tombstoned"` // whether or not a validator has been tombstoned (killed out of validator set) - MissedBlocksCounter int64 `json:"missed_blocks_counter" yaml:"missed_blocks_counter"` // missed blocks counter (to avoid scanning the array every time) -} - // NewValidatorSigningInfo creates a new ValidatorSigningInfo instance func NewValidatorSigningInfo( condAddr sdk.ConsAddress, startHeight, indexOffset int64, diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 0c2e770d4a85..927afb77f438 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -1,32 +1,37 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. +// Code generated by protoc-gen-gogo. DO NOT EDIT. // source: x/slashing/internal/types/types.proto package types import ( + bytes "bytes" fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/golang/protobuf/proto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "github.com/golang/protobuf/ptypes/timestamp" + io "io" math "math" + math_bits "math/bits" + time "time" ) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf +var _ = time.Kitchen // 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.ProtoPackageIsVersion3 // please upgrade the proto package +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // MsgUnjail - struct for unjailing jailed validator type MsgUnjail struct { - ValidatorAddr []byte `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3" json:"validator_addr,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + ValidatorAddr github_com_cosmos_cosmos_sdk_types.ValAddress `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ValAddress" json:"validator_addr,omitempty" yaml:"validator_address"` } func (m *MsgUnjail) Reset() { *m = MsgUnjail{} } @@ -35,18 +40,26 @@ func (*MsgUnjail) ProtoMessage() {} func (*MsgUnjail) Descriptor() ([]byte, []int) { return fileDescriptor_2b882c3b0cdd6f57, []int{0} } - func (m *MsgUnjail) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_MsgUnjail.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *MsgUnjail) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_MsgUnjail.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_MsgUnjail.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 *MsgUnjail) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgUnjail.Merge(m, src) } func (m *MsgUnjail) XXX_Size() int { - return xxx_messageInfo_MsgUnjail.Size(m) + return m.Size() } func (m *MsgUnjail) XXX_DiscardUnknown() { xxx_messageInfo_MsgUnjail.DiscardUnknown(m) @@ -54,15 +67,100 @@ func (m *MsgUnjail) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUnjail proto.InternalMessageInfo -func (m *MsgUnjail) GetValidatorAddr() []byte { +func (m *MsgUnjail) GetValidatorAddr() github_com_cosmos_cosmos_sdk_types.ValAddress { if m != nil { return m.ValidatorAddr } return nil } +// ValidatorSigningInfo defines the signing info for a validator +type ValidatorSigningInfo struct { + Address github_com_cosmos_cosmos_sdk_types.ConsAddress `protobuf:"bytes,1,opt,name=address,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ConsAddress" json:"address,omitempty" yaml:"address"` + StartHeight int64 `protobuf:"varint,2,opt,name=start_height,json=startHeight,proto3" json:"start_height,omitempty" yaml:"start_height"` + IndexOffset int64 `protobuf:"varint,3,opt,name=index_offset,json=indexOffset,proto3" json:"index_offset,omitempty" yaml:"index_offset"` + JailedUntil time.Time `protobuf:"bytes,4,opt,name=jailed_until,json=jailedUntil,proto3,stdtime" json:"jailed_until"` + Tombstoned bool `protobuf:"varint,5,opt,name=tombstoned,proto3" json:"tombstoned,omitempty" yaml:"tombstoned"` + MissedBlocksCounter int64 `protobuf:"varint,6,opt,name=missed_blocks_counter,json=missedBlocksCounter,proto3" json:"missed_blocks_counter,omitempty" yaml:"missed_blocks_counter"` +} + +func (m *ValidatorSigningInfo) Reset() { *m = ValidatorSigningInfo{} } +func (*ValidatorSigningInfo) ProtoMessage() {} +func (*ValidatorSigningInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_2b882c3b0cdd6f57, []int{1} +} +func (m *ValidatorSigningInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorSigningInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorSigningInfo.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 *ValidatorSigningInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorSigningInfo.Merge(m, src) +} +func (m *ValidatorSigningInfo) XXX_Size() int { + return m.Size() +} +func (m *ValidatorSigningInfo) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorSigningInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorSigningInfo proto.InternalMessageInfo + +func (m *ValidatorSigningInfo) GetAddress() github_com_cosmos_cosmos_sdk_types.ConsAddress { + if m != nil { + return m.Address + } + return nil +} + +func (m *ValidatorSigningInfo) GetStartHeight() int64 { + if m != nil { + return m.StartHeight + } + return 0 +} + +func (m *ValidatorSigningInfo) GetIndexOffset() int64 { + if m != nil { + return m.IndexOffset + } + return 0 +} + +func (m *ValidatorSigningInfo) GetJailedUntil() time.Time { + if m != nil { + return m.JailedUntil + } + return time.Time{} +} + +func (m *ValidatorSigningInfo) GetTombstoned() bool { + if m != nil { + return m.Tombstoned + } + return false +} + +func (m *ValidatorSigningInfo) GetMissedBlocksCounter() int64 { + if m != nil { + return m.MissedBlocksCounter + } + return 0 +} + func init() { proto.RegisterType((*MsgUnjail)(nil), "cosmos_sdk.x.slashing.v1.MsgUnjail") + proto.RegisterType((*ValidatorSigningInfo)(nil), "cosmos_sdk.x.slashing.v1.ValidatorSigningInfo") } func init() { @@ -70,18 +168,594 @@ func init() { } var fileDescriptor_2b882c3b0cdd6f57 = []byte{ - // 208 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0xad, 0xd0, 0x2f, 0xce, - 0x49, 0x2c, 0xce, 0xc8, 0xcc, 0x4b, 0xd7, 0xcf, 0xcc, 0x2b, 0x49, 0x2d, 0xca, 0x4b, 0xcc, 0xd1, - 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x12, 0xc9, - 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, 0x30, 0x1d, 0x7a, 0x65, - 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25, 0x95, 0xfa, 0x60, - 0xc5, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0xc4, 0x04, 0xa5, 0x46, 0x46, 0x2e, 0x4e, 0xdf, - 0xe2, 0xf4, 0xd0, 0xbc, 0xac, 0xc4, 0xcc, 0x1c, 0xa1, 0x12, 0x2e, 0xbe, 0xb2, 0xc4, 0x9c, 0xcc, - 0x94, 0xc4, 0x92, 0xfc, 0xa2, 0xf8, 0xc4, 0x94, 0x94, 0x22, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x1e, - 0x27, 0xdf, 0x4f, 0xf7, 0xe4, 0x25, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, 0x50, 0xe5, 0x53, 0x8b, - 0x8b, 0x95, 0x7e, 0xdd, 0x93, 0xd7, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, - 0xd5, 0x87, 0x38, 0x09, 0x4a, 0xe9, 0x02, 0x5d, 0x06, 0x75, 0x71, 0x58, 0x62, 0x8e, 0x23, 0x44, - 0x47, 0x10, 0x2f, 0xdc, 0x10, 0x90, 0x88, 0x13, 0x7b, 0x14, 0x2b, 0x58, 0x49, 0x12, 0x1b, 0xd8, - 0x4d, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0e, 0x44, 0xbf, 0xed, 0xfe, 0x00, 0x00, 0x00, + // 496 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xb1, 0x6f, 0xd3, 0x4e, + 0x14, 0xce, 0xfd, 0xf2, 0x6b, 0x09, 0x97, 0x50, 0x09, 0x97, 0x0a, 0x2b, 0x42, 0xbe, 0xc8, 0x12, + 0x28, 0x4b, 0x6d, 0x01, 0x62, 0xc9, 0x86, 0x8b, 0x04, 0x0c, 0x15, 0x92, 0x69, 0x3b, 0x30, 0x60, + 0x9d, 0x73, 0x97, 0xf3, 0x11, 0xfb, 0x2e, 0xf2, 0x5d, 0xaa, 0x64, 0xe4, 0x3f, 0xe8, 0xc8, 0xd8, + 0x3f, 0xa7, 0x13, 0xea, 0xc8, 0x64, 0x50, 0xb2, 0x30, 0x7b, 0x64, 0x42, 0xf6, 0xc5, 0x34, 0x20, + 0x06, 0x16, 0xfb, 0xde, 0xf7, 0xbe, 0xef, 0x7d, 0xef, 0xdd, 0x3b,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0xeb, 0x95, 0x03, 0xbe, 0xad, 0x1c, 0x70, 0xb1, + 0x76, 0x5a, 0xd7, 0x6b, 0xa7, 0xf5, 0x65, 0xed, 0xb4, 0xde, 0xed, 0xd4, 0xdb, 0x88, 0x77, 0xeb, + 0x11, 0x9f, 0xfe, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x1d, 0xa4, 0xe7, 0x2b, 0x08, 0x03, 0x00, 0x00, } + +func (this *ValidatorSigningInfo) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorSigningInfo) + if !ok { + that2, ok := that.(ValidatorSigningInfo) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.Address, that1.Address) { + return false + } + if this.StartHeight != that1.StartHeight { + return false + } + if this.IndexOffset != that1.IndexOffset { + return false + } + if !this.JailedUntil.Equal(that1.JailedUntil) { + return false + } + if this.Tombstoned != that1.Tombstoned { + return false + } + if this.MissedBlocksCounter != that1.MissedBlocksCounter { + return false + } + return true +} +func (m *MsgUnjail) 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 *MsgUnjail) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUnjail) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ValidatorAddr) > 0 { + i -= len(m.ValidatorAddr) + copy(dAtA[i:], m.ValidatorAddr) + i = encodeVarintTypes(dAtA, i, uint64(len(m.ValidatorAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ValidatorSigningInfo) 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 *ValidatorSigningInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorSigningInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.MissedBlocksCounter != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.MissedBlocksCounter)) + i-- + dAtA[i] = 0x30 + } + if m.Tombstoned { + i-- + if m.Tombstoned { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x28 + } + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.JailedUntil, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.JailedUntil):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintTypes(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x22 + if m.IndexOffset != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.IndexOffset)) + i-- + dAtA[i] = 0x18 + } + if m.StartHeight != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.StartHeight)) + i-- + dAtA[i] = 0x10 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgUnjail) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddr) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *ValidatorSigningInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.StartHeight != 0 { + n += 1 + sovTypes(uint64(m.StartHeight)) + } + if m.IndexOffset != 0 { + n += 1 + sovTypes(uint64(m.IndexOffset)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.JailedUntil) + n += 1 + l + sovTypes(uint64(l)) + if m.Tombstoned { + n += 2 + } + if m.MissedBlocksCounter != 0 { + n += 1 + sovTypes(uint64(m.MissedBlocksCounter)) + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgUnjail) 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 ErrIntOverflowTypes + } + 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: MsgUnjail: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUnjail: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddr", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddr = append(m.ValidatorAddr[:0], dAtA[iNdEx:postIndex]...) + if m.ValidatorAddr == nil { + m.ValidatorAddr = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorSigningInfo) 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 ErrIntOverflowTypes + } + 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: ValidatorSigningInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorSigningInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = append(m.Address[:0], dAtA[iNdEx:postIndex]...) + if m.Address == nil { + m.Address = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StartHeight", wireType) + } + m.StartHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StartHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IndexOffset", wireType) + } + m.IndexOffset = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.IndexOffset |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field JailedUntil", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.JailedUntil, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Tombstoned", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Tombstoned = bool(v != 0) + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MissedBlocksCounter", wireType) + } + m.MissedBlocksCounter = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MissedBlocksCounter |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTypes(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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrInvalidLengthTypes + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTypes + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTypes + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index 9a352d6d15c1..0f0035b93480 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -4,6 +4,7 @@ package cosmos_sdk.x.slashing.v1; option go_package = "types"; import "third_party/proto/gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; // MsgUnjail - struct for unjailing jailed validator message MsgUnjail { @@ -11,4 +12,21 @@ message MsgUnjail { (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress", (gogoproto.moretags) = "yaml:\"validator_address\"" ]; -} \ No newline at end of file +} + +// ValidatorSigningInfo defines the signing info for a validator +message ValidatorSigningInfo { + option (gogoproto.equal) = true; + option (gogoproto.goproto_stringer) = false; + + bytes address = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress", + (gogoproto.moretags) = "yaml:\"address\"" // validator consensus address + ]; + int64 start_height = 2 [(gogoproto.moretags) = "yaml:\"start_height\""]; // height at which validator was first a candidate OR was unjailed + int64 index_offset = 3 [(gogoproto.moretags) = "yaml:\"index_offset\""]; // index offset into signed block bit array + google.protobuf.Timestamp jailed_until = 4 [(gogoproto.stdtime) = true, + (gogoproto.nullable) = false]; // timestamp validator cannot be unjailed until + bool tombstoned = 5 [(gogoproto.moretags) = "yaml:\"tombstoned\""]; // whether or not a validator has been tombstoned (killed out of validator set) + int64 missed_blocks_counter = 6 [(gogoproto.moretags) = "yaml:\"missed_blocks_counter\""]; // missed blocks counter (to avoid scanning the array every time) +} From 5a5fd73f157c80a0a67d1a7b56410b6e2182f0fd Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 00:17:18 +0530 Subject: [PATCH 20/52] Fix keeper init in tests --- x/slashing/internal/keeper/signing_info.go | 7 ++++--- x/slashing/internal/keeper/test_common.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/x/slashing/internal/keeper/signing_info.go b/x/slashing/internal/keeper/signing_info.go index 769b3c2cf898..22e1c5d86864 100644 --- a/x/slashing/internal/keeper/signing_info.go +++ b/x/slashing/internal/keeper/signing_info.go @@ -1,6 +1,7 @@ package keeper import ( + gogotypes "github.com/gogo/protobuf/types" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -61,7 +62,7 @@ func (k Keeper) GetValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.Con missed = false return } - k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &missed) + k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &gogotypes.BoolValue{Value: missed}) return } @@ -79,7 +80,7 @@ func (k Keeper) IterateValidatorMissedBlockBitArray(ctx sdk.Context, if bz == nil { continue } - k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &missed) + k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &gogotypes.BoolValue{Value: missed}) if handler(index, missed) { break } @@ -128,7 +129,7 @@ func (k Keeper) IsTombstoned(ctx sdk.Context, consAddr sdk.ConsAddress) bool { // missed a block in the current window func (k Keeper) SetValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64, missed bool) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(missed) + bz := k.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.BoolValue{Value: missed}) store.Set(types.GetValidatorMissedBlockBitArrayKey(address, index), bz) } diff --git a/x/slashing/internal/keeper/test_common.go b/x/slashing/internal/keeper/test_common.go index 128c7438a7f9..976c2e39d83c 100644 --- a/x/slashing/internal/keeper/test_common.go +++ b/x/slashing/internal/keeper/test_common.go @@ -121,7 +121,7 @@ func CreateTestInput(t *testing.T, defaults types.Params) (sdk.Context, bank.Kee } paramstore := paramsKeeper.Subspace(types.DefaultParamspace) - keeper := NewKeeper(cdc, keySlashing, &sk, paramstore) + keeper := NewKeeper(types.ModuleCdc, keySlashing, &sk, paramstore) keeper.SetParams(ctx, defaults) sk.SetHooks(keeper.Hooks()) From bdd9368a20f623cc3eea69eeeca1c31756580164 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 00:45:37 +0530 Subject: [PATCH 21/52] Add TODO --- x/slashing/internal/keeper/keeper.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x/slashing/internal/keeper/keeper.go b/x/slashing/internal/keeper/keeper.go index ba1858cfe463..1c11f90ed2fd 100644 --- a/x/slashing/internal/keeper/keeper.go +++ b/x/slashing/internal/keeper/keeper.go @@ -43,6 +43,8 @@ func (k Keeper) AddPubkey(ctx sdk.Context, pubkey crypto.PubKey) { // GetPubkey returns the pubkey from the adddress-pubkey relation func (k Keeper) GetPubkey(ctx sdk.Context, address crypto.Address) (crypto.PubKey, error) { store := ctx.KVStore(k.storeKey) + + //TODO change this to use protobuf var pubkey crypto.PubKey err := k.cdc.UnmarshalBinaryLengthPrefixed(store.Get(types.GetAddrPubkeyRelationKey(address)), &pubkey) if err != nil { From 525ad5238463ac082cc630a75dd48205f5155f96 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 02:47:51 +0530 Subject: [PATCH 22/52] Fix signing-info migration --- x/slashing/app_test.go | 2 +- x/slashing/internal/keeper/keeper.go | 28 ++++++++++++++++++---- x/slashing/internal/keeper/signing_info.go | 11 +++++---- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index b62d5dcb1385..c0121983e97e 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -56,7 +56,7 @@ func getMockApp(t *testing.T) (*mock.App, staking.Keeper, Keeper) { } supplyKeeper := supply.NewKeeper(mapp.Cdc, keySupply, mapp.AccountKeeper, mapp.BankKeeper, maccPerms) stakingKeeper := staking.NewKeeper(staking.ModuleCdc, keyStaking, mapp.BankKeeper, supplyKeeper, mapp.ParamsKeeper.Subspace(staking.DefaultParamspace)) - keeper := NewKeeper(mapp.Cdc, keySlashing, stakingKeeper, mapp.ParamsKeeper.Subspace(DefaultParamspace)) + keeper := NewKeeper(staking.ModuleCdc, keySlashing, stakingKeeper, mapp.ParamsKeeper.Subspace(DefaultParamspace)) mapp.Router().AddRoute(staking.RouterKey, staking.NewHandler(stakingKeeper)) mapp.Router().AddRoute(RouterKey, NewHandler(keeper)) diff --git a/x/slashing/internal/keeper/keeper.go b/x/slashing/internal/keeper/keeper.go index 1c11f90ed2fd..58a59999fb1e 100644 --- a/x/slashing/internal/keeper/keeper.go +++ b/x/slashing/internal/keeper/keeper.go @@ -2,6 +2,7 @@ package keeper import ( "fmt" + gogotypes "github.com/gogo/protobuf/types" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/libs/log" @@ -37,7 +38,14 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { // AddPubkey sets a address-pubkey relation func (k Keeper) AddPubkey(ctx sdk.Context, pubkey crypto.PubKey) { addr := pubkey.Address() - k.setAddrPubkeyRelation(ctx, addr, pubkey) + + pkStr, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pubkey) + + if err != nil { + panic(fmt.Errorf("error while setting address-pubkey relation: %s", addr)) + } + + k.setAddrPubkeyRelation(ctx, addr, pkStr) } // GetPubkey returns the pubkey from the adddress-pubkey relation @@ -45,12 +53,21 @@ func (k Keeper) GetPubkey(ctx sdk.Context, address crypto.Address) (crypto.PubKe store := ctx.KVStore(k.storeKey) //TODO change this to use protobuf - var pubkey crypto.PubKey + var pubkey gogotypes.StringValue err := k.cdc.UnmarshalBinaryLengthPrefixed(store.Get(types.GetAddrPubkeyRelationKey(address)), &pubkey) + if err != nil { return nil, fmt.Errorf("address %s not found", sdk.ConsAddress(address)) } - return pubkey, nil + + + pkStr, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, pubkey.Value) + + if err != nil { + return pkStr, err + } + + return pkStr, nil } // Slash attempts to slash a validator. The slash is delegated to the staking @@ -81,9 +98,10 @@ func (k Keeper) Jail(ctx sdk.Context, consAddr sdk.ConsAddress) { k.sk.Jail(ctx, consAddr) } -func (k Keeper) setAddrPubkeyRelation(ctx sdk.Context, addr crypto.Address, pubkey crypto.PubKey) { +func (k Keeper) setAddrPubkeyRelation(ctx sdk.Context, addr crypto.Address, pubkey string) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(pubkey) + + bz := k.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.StringValue{Value:pubkey}) store.Set(types.GetAddrPubkeyRelationKey(addr), bz) } diff --git a/x/slashing/internal/keeper/signing_info.go b/x/slashing/internal/keeper/signing_info.go index 22e1c5d86864..083b20a60a91 100644 --- a/x/slashing/internal/keeper/signing_info.go +++ b/x/slashing/internal/keeper/signing_info.go @@ -54,16 +54,17 @@ func (k Keeper) IterateValidatorSigningInfos(ctx sdk.Context, } // GetValidatorMissedBlockBitArray gets the bit for the missed blocks array -func (k Keeper) GetValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64) (missed bool) { +func (k Keeper) GetValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64) bool { store := ctx.KVStore(k.storeKey) bz := store.Get(types.GetValidatorMissedBlockBitArrayKey(address, index)) + var missed gogotypes.BoolValue if bz == nil { // lazy: treat empty key as not missed - missed = false - return + return false } - k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &gogotypes.BoolValue{Value: missed}) - return + k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &missed) + + return missed.Value } // IterateValidatorMissedBlockBitArray iterates over the signed blocks window From c6bb9aeb0404db16d89169ef35ff0154370772b0 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 03:01:18 +0530 Subject: [PATCH 23/52] Change query to use protobuf codec --- x/slashing/client/cli/query.go | 7 ++- x/slashing/internal/types/signing_info.go | 7 +++ x/slashing/internal/types/types.pb.go | 66 +++++++++++------------ x/slashing/internal/types/types.proto | 2 +- 4 files changed, 47 insertions(+), 35 deletions(-) diff --git a/x/slashing/client/cli/query.go b/x/slashing/client/cli/query.go index 71f404230758..aad4f8f3a71a 100644 --- a/x/slashing/client/cli/query.go +++ b/x/slashing/client/cli/query.go @@ -68,7 +68,12 @@ $ query slashing signing-info cosmosvalconspub1zcjduepqfhvwcmt7p06fvdge } var signingInfo types.ValidatorSigningInfo - cdc.MustUnmarshalBinaryLengthPrefixed(res, &signingInfo) + signingInfo, err = types.UnmarshalValSigningInfo(types.ModuleCdc, res) + + if err != nil { + return err + } + return cliCtx.PrintOutput(signingInfo) }, } diff --git a/x/slashing/internal/types/signing_info.go b/x/slashing/internal/types/signing_info.go index 66870f3032a6..3749ccc03aed 100644 --- a/x/slashing/internal/types/signing_info.go +++ b/x/slashing/internal/types/signing_info.go @@ -2,6 +2,7 @@ package types import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -35,3 +36,9 @@ func (i ValidatorSigningInfo) String() string { i.Address, i.StartHeight, i.IndexOffset, i.JailedUntil, i.Tombstoned, i.MissedBlocksCounter) } + +// unmarshal a validator signing info from a store value +func UnmarshalValSigningInfo(cdc codec.Marshaler, value []byte) (signingInfo ValidatorSigningInfo, err error) { + err = cdc.UnmarshalBinaryLengthPrefixed(value, &signingInfo) + return signingInfo, err +} diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 927afb77f438..b214da641db7 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -31,7 +31,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // MsgUnjail - struct for unjailing jailed validator type MsgUnjail struct { - ValidatorAddr github_com_cosmos_cosmos_sdk_types.ValAddress `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ValAddress" json:"validator_addr,omitempty" yaml:"validator_address"` + ValidatorAddr github_com_cosmos_cosmos_sdk_types.ValAddress `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ValAddress" json:"validator_addr,omitempty" yaml:"address"` } func (m *MsgUnjail) Reset() { *m = MsgUnjail{} } @@ -168,38 +168,38 @@ func init() { } var fileDescriptor_2b882c3b0cdd6f57 = []byte{ - // 496 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xb1, 0x6f, 0xd3, 0x4e, - 0x14, 0xce, 0xfd, 0xf2, 0x6b, 0x09, 0x97, 0x50, 0x09, 0x97, 0x0a, 0x2b, 0x42, 0xbe, 0xc8, 0x12, - 0x28, 0x4b, 0x6d, 0x01, 0x62, 0xc9, 0x86, 0x8b, 0x04, 0x0c, 0x15, 0x92, 0x69, 0x3b, 0x30, 0x60, - 0x9d, 0x73, 0x97, 0xf3, 0x11, 0xfb, 0x2e, 0xf2, 0x5d, 0xaa, 0x64, 0xe4, 0x3f, 0xe8, 0xc8, 0xd8, - 0x3f, 0xa7, 0x13, 0xea, 0xc8, 0x64, 0x50, 0xb2, 0x30, 0x7b, 0x64, 0x42, 0xf6, 0xc5, 0x34, 0x20, - 0x06, 0x16, 0xfb, 0xde, 0xf7, 0xbe, 0xef, 0x7d, 0xef, 0xdd, 0x3b, 0xf8, 0x70, 0xe1, 0xab, 0x14, - 0xab, 0x84, 0x0b, 0xe6, 0x73, 0xa1, 0x69, 0x2e, 0x70, 0xea, 0xeb, 0xe5, 0x8c, 0x2a, 0xf3, 0xf5, - 0x66, 0xb9, 0xd4, 0xd2, 0xb2, 0xc7, 0x52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0x00, 0x00, 0xff, 0xff, 0x1d, 0xa4, 0xe7, 0x2b, 0x08, 0x03, 0x00, 0x00, + // 488 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x31, 0x6f, 0xd3, 0x40, + 0x18, 0xcd, 0x11, 0x5a, 0xc2, 0x25, 0x54, 0xc2, 0xa5, 0xc2, 0x8a, 0x90, 0x2f, 0xb2, 0x04, 0xca, + 0x52, 0x5b, 0x80, 0x58, 0xb2, 0xe1, 0x20, 0x01, 0x03, 0x42, 0x32, 0x6d, 0x07, 0x06, 0xac, 0x73, + 0xee, 0x72, 0xbe, 0xc6, 0xbe, 0x8b, 0x7c, 0x97, 0x92, 0xfc, 0x8b, 0x8e, 0x8c, 0xfd, 0x39, 0x9d, + 0x50, 0x47, 0x26, 0x83, 0x92, 0x85, 0x39, 0x23, 0x13, 0xb2, 0x2f, 0xa6, 0x11, 0xea, 0xd0, 0xc5, + 0xf6, 0xf7, 0xbe, 0xf7, 0xbe, 0x77, 0x9f, 0xdf, 0xc1, 0xa7, 0x73, 0x5f, 0xa5, 0x58, 0x25, 0x5c, + 0x30, 0x9f, 0x0b, 0x4d, 0x73, 0x81, 0x53, 0x5f, 0x2f, 0xa6, 0x54, 0x99, 0xa7, 0x37, 0xcd, 0xa5, + 0x96, 0x96, 0x3d, 0x92, 0x2a, 0x93, 0x2a, 0x52, 0x64, 0xe2, 0xcd, 0xbd, 0x5a, 0xe1, 0x9d, 0x3d, + 0xef, 0x3e, 0xd3, 0x09, 0xcf, 0x49, 0x34, 0xc5, 0xb9, 0x5e, 0xf8, 0x15, 0xd9, 0x67, 0x92, 0xc9, + 0xeb, 0x2f, 0x33, 0xa1, 0x8b, 0x98, 0x94, 0x2c, 0xa5, 0x86, 0x12, 0xcf, 0xc6, 0xbe, 0xe6, 0x19, + 0x55, 0x1a, 0x67, 0x53, 0x43, 0x70, 0xbf, 0xc2,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42, 0xde, + 0x51, 0x9d, 0x50, 0xd0, 0xba, 0x2c, 0x50, 0xe3, 0xfc, 0x27, 0x02, 0x61, 0xdb, 0x28, 0x8f, 0x4b, + 0xa1, 0xf5, 0x0a, 0x42, 0x2d, 0xb3, 0x58, 0x69, 0x29, 0x28, 0xb1, 0x77, 0x7a, 0xa0, 0xdf, 0x0a, + 0x0e, 0xd6, 0x05, 0x7a, 0x68, 0x8e, 0x70, 0xdd, 0x73, 0xc3, 0x2d, 0xa2, 0x75, 0x04, 0x0f, 0x32, + 0xae, 0x14, 0x25, 0x51, 0x9c, 0xca, 0xd1, 0x44, 0x45, 0x23, 0x39, 0x2b, 0xaf, 0x9e, 0xbd, 0x5b, + 0x2d, 0xd1, 0x5b, 0x17, 0xe8, 0x89, 0x99, 0x70, 0x23, 0xcd, 0x0d, 0xf7, 0x0d, 0x1e, 0x54, 0xf0, + 0xd0, 0xa0, 0x83, 0xd6, 0xb7, 0x0b, 0xd4, 0xf8, 0x7d, 0x81, 0x40, 0x80, 0x2e, 0x97, 0x0e, 0xb8, + 0x5a, 0x3a, 0xe0, 0xd7, 0xd2, 0x01, 0xe7, 0x2b, 0xa7, 0x71, 0xb5, 0x72, 0x1a, 0x3f, 0x56, 0x4e, + 0xe3, 0xf3, 0x4e, 0x95, 0x46, 0xbc, 0x5b, 0xad, 0xf8, 0xf2, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x25, 0xd8, 0x25, 0xd1, 0xfd, 0x02, 0x00, 0x00, } func (this *ValidatorSigningInfo) Equal(that interface{}) bool { diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index 0f0035b93480..fa156b6ea482 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -10,7 +10,7 @@ import "google/protobuf/timestamp.proto"; message MsgUnjail { bytes validator_addr = 1 [ (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress", - (gogoproto.moretags) = "yaml:\"validator_address\"" + (gogoproto.moretags) = "yaml:\"address\"" ]; } From 486e7a14d3ac804d8877088b0b527e661c689e8b Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 03:09:07 +0530 Subject: [PATCH 24/52] Fix unjail testscript --- x/slashing/internal/types/msg_test.go | 2 +- x/slashing/internal/types/types.pb.go | 66 +++++++++++++-------------- x/slashing/internal/types/types.proto | 2 +- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/x/slashing/internal/types/msg_test.go b/x/slashing/internal/types/msg_test.go index 31f7a70e75db..80369d712004 100644 --- a/x/slashing/internal/types/msg_test.go +++ b/x/slashing/internal/types/msg_test.go @@ -14,7 +14,7 @@ func TestMsgUnjailGetSignBytes(t *testing.T) { bytes := msg.GetSignBytes() require.Equal( t, - `{"type":"cosmos-sdk/MsgUnjail","value":{"address":"cosmosvaloper1v93xxeqhg9nn6"}}`, + `{"type":"cosmos-sdk/MsgUnjail","value":{"validator_addr":"cosmosvaloper1v93xxeqhg9nn6"}}`, string(bytes), ) } diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index b214da641db7..927afb77f438 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -31,7 +31,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // MsgUnjail - struct for unjailing jailed validator type MsgUnjail struct { - ValidatorAddr github_com_cosmos_cosmos_sdk_types.ValAddress `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ValAddress" json:"validator_addr,omitempty" yaml:"address"` + ValidatorAddr github_com_cosmos_cosmos_sdk_types.ValAddress `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ValAddress" json:"validator_addr,omitempty" yaml:"validator_address"` } func (m *MsgUnjail) Reset() { *m = MsgUnjail{} } @@ -168,38 +168,38 @@ func init() { } var fileDescriptor_2b882c3b0cdd6f57 = []byte{ - // 488 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x31, 0x6f, 0xd3, 0x40, - 0x18, 0xcd, 0x11, 0x5a, 0xc2, 0x25, 0x54, 0xc2, 0xa5, 0xc2, 0x8a, 0x90, 0x2f, 0xb2, 0x04, 0xca, - 0x52, 0x5b, 0x80, 0x58, 0xb2, 0xe1, 0x20, 0x01, 0x03, 0x42, 0x32, 0x6d, 0x07, 0x06, 0xac, 0x73, - 0xee, 0x72, 0xbe, 0xc6, 0xbe, 0x8b, 0x7c, 0x97, 0x92, 0xfc, 0x8b, 0x8e, 0x8c, 0xfd, 0x39, 0x9d, - 0x50, 0x47, 0x26, 0x83, 0x92, 0x85, 0x39, 0x23, 0x13, 0xb2, 0x2f, 0xa6, 0x11, 0xea, 0xd0, 0xc5, - 0xf6, 0xf7, 0xbe, 0xf7, 0xbe, 0x77, 0x9f, 0xdf, 0xc1, 0xa7, 0x73, 0x5f, 0xa5, 0x58, 0x25, 0x5c, - 0x30, 0x9f, 0x0b, 0x4d, 0x73, 0x81, 0x53, 0x5f, 0x2f, 0xa6, 0x54, 0x99, 0xa7, 0x37, 0xcd, 0xa5, - 0x96, 0x96, 0x3d, 0x92, 0x2a, 0x93, 0x2a, 0x52, 0x64, 0xe2, 0xcd, 0xbd, 0x5a, 0xe1, 0x9d, 0x3d, - 0xef, 0x3e, 0xd3, 0x09, 0xcf, 0x49, 0x34, 0xc5, 0xb9, 0x5e, 0xf8, 0x15, 0xd9, 0x67, 0x92, 0xc9, - 0xeb, 0x2f, 0x33, 0xa1, 0x8b, 0x98, 0x94, 0x2c, 0xa5, 0x86, 0x12, 0xcf, 0xc6, 0xbe, 0xe6, 0x19, - 0x55, 0x1a, 0x67, 0x53, 0x43, 0x70, 0xbf, 0xc2, 0xfb, 0x1f, 0x14, 0x3b, 0x16,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0, 0xba, 0x2c, 0x50, 0xe3, 0xfc, 0x27, 0x02, 0x61, 0xdb, 0x28, 0x8f, 0x4b, - 0xa1, 0xf5, 0x0a, 0x42, 0x2d, 0xb3, 0x58, 0x69, 0x29, 0x28, 0xb1, 0x77, 0x7a, 0xa0, 0xdf, 0x0a, - 0x0e, 0xd6, 0x05, 0x7a, 0x68, 0x8e, 0x70, 0xdd, 0x73, 0xc3, 0x2d, 0xa2, 0x75, 0x04, 0x0f, 0x32, - 0xae, 0x14, 0x25, 0x51, 0x9c, 0xca, 0xd1, 0x44, 0x45, 0x23, 0x39, 0x2b, 0xaf, 0x9e, 0xbd, 0x5b, - 0x2d, 0xd1, 0x5b, 0x17, 0xe8, 0x89, 0x99, 0x70, 0x23, 0xcd, 0x0d, 0xf7, 0x0d, 0x1e, 0x54, 0xf0, - 0xd0, 0xa0, 0x83, 0xd6, 0xb7, 0x0b, 0xd4, 0xf8, 0x7d, 0x81, 0x40, 0x80, 0x2e, 0x97, 0x0e, 0xb8, - 0x5a, 0x3a, 0xe0, 0xd7, 0xd2, 0x01, 0xe7, 0x2b, 0xa7, 0x71, 0xb5, 0x72, 0x1a, 0x3f, 0x56, 0x4e, - 0xe3, 0xf3, 0x4e, 0x95, 0x46, 0xbc, 0x5b, 0xad, 0xf8, 0xf2, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x25, 0xd8, 0x25, 0xd1, 0xfd, 0x02, 0x00, 0x00, + // 496 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xb1, 0x6f, 0xd3, 0x4e, + 0x14, 0xce, 0xfd, 0xf2, 0x6b, 0x09, 0x97, 0x50, 0x09, 0x97, 0x0a, 0x2b, 0x42, 0xbe, 0xc8, 0x12, + 0x28, 0x4b, 0x6d, 0x01, 0x62, 0xc9, 0x86, 0x8b, 0x04, 0x0c, 0x15, 0x92, 0x69, 0x3b, 0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, 0xe2, 0x54, 0x8e, 0xa7, + 0x2a, 0x1a, 0xcb, 0x79, 0xf5, 0x0a, 0xed, 0xdd, 0x7a, 0x88, 0x41, 0x59, 0xa0, 0x07, 0xa6, 0xc2, + 0x5f, 0x69, 0x6e, 0xb8, 0x6f, 0xf0, 0xa0, 0x86, 0x8f, 0x0c, 0x3a, 0xea, 0x7c, 0xba, 0x44, 0xad, + 0xef, 0x97, 0x08, 0x04, 0xe8, 0x6a, 0xe5, 0x80, 0xeb, 0x95, 0x03, 0xbe, 0xad, 0x1c, 0x70, 0xb1, + 0x76, 0x5a, 0xd7, 0x6b, 0xa7, 0xf5, 0x65, 0xed, 0xb4, 0xde, 0xed, 0xd4, 0xdb, 0x88, 0x77, 0xeb, + 0x11, 0x9f, 0xfe, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x1d, 0xa4, 0xe7, 0x2b, 0x08, 0x03, 0x00, 0x00, } func (this *ValidatorSigningInfo) Equal(that interface{}) bool { diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index fa156b6ea482..0f0035b93480 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -10,7 +10,7 @@ import "google/protobuf/timestamp.proto"; message MsgUnjail { bytes validator_addr = 1 [ (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress", - (gogoproto.moretags) = "yaml:\"address\"" + (gogoproto.moretags) = "yaml:\"validator_address\"" ]; } From d035a18536d30269688c6e471e2633dce9f532ae Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 03:24:39 +0530 Subject: [PATCH 25/52] Fix go-imports --- x/slashing/internal/keeper/keeper.go | 5 ++--- x/slashing/internal/types/signing_info.go | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x/slashing/internal/keeper/keeper.go b/x/slashing/internal/keeper/keeper.go index 58a59999fb1e..676e6ba5dfe5 100644 --- a/x/slashing/internal/keeper/keeper.go +++ b/x/slashing/internal/keeper/keeper.go @@ -2,6 +2,7 @@ package keeper import ( "fmt" + gogotypes "github.com/gogo/protobuf/types" "github.com/tendermint/tendermint/crypto" @@ -52,7 +53,6 @@ func (k Keeper) AddPubkey(ctx sdk.Context, pubkey crypto.PubKey) { func (k Keeper) GetPubkey(ctx sdk.Context, address crypto.Address) (crypto.PubKey, error) { store := ctx.KVStore(k.storeKey) - //TODO change this to use protobuf var pubkey gogotypes.StringValue err := k.cdc.UnmarshalBinaryLengthPrefixed(store.Get(types.GetAddrPubkeyRelationKey(address)), &pubkey) @@ -60,7 +60,6 @@ func (k Keeper) GetPubkey(ctx sdk.Context, address crypto.Address) (crypto.PubKe return nil, fmt.Errorf("address %s not found", sdk.ConsAddress(address)) } - pkStr, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, pubkey.Value) if err != nil { @@ -101,7 +100,7 @@ func (k Keeper) Jail(ctx sdk.Context, consAddr sdk.ConsAddress) { func (k Keeper) setAddrPubkeyRelation(ctx sdk.Context, addr crypto.Address, pubkey string) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.StringValue{Value:pubkey}) + bz := k.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.StringValue{Value: pubkey}) store.Set(types.GetAddrPubkeyRelationKey(addr), bz) } diff --git a/x/slashing/internal/types/signing_info.go b/x/slashing/internal/types/signing_info.go index 3749ccc03aed..315cac792c56 100644 --- a/x/slashing/internal/types/signing_info.go +++ b/x/slashing/internal/types/signing_info.go @@ -2,9 +2,10 @@ package types import ( "fmt" - "github.com/cosmos/cosmos-sdk/codec" "time" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" ) From bb6d8c884fd6468defa8c4b8b7a04b80145a9612 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 04:12:18 +0530 Subject: [PATCH 26/52] Migrate all slashing queries to use protobuf --- x/slashing/client/rest/query.go | 9 +- x/slashing/internal/types/querier.go | 14 +- x/slashing/internal/types/signing_info.go | 5 +- x/slashing/internal/types/types.pb.go | 440 ++++++++++++++++++++-- x/slashing/internal/types/types.proto | 16 + 5 files changed, 432 insertions(+), 52 deletions(-) diff --git a/x/slashing/client/rest/query.go b/x/slashing/client/rest/query.go index 751fe648dc45..2aa8ee84a470 100644 --- a/x/slashing/client/rest/query.go +++ b/x/slashing/client/rest/query.go @@ -45,8 +45,8 @@ func signingInfoHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { } params := types.NewQuerySigningInfoParams(sdk.ConsAddress(pk.Address())) + bz, err := params.Marshal() - bz, err := cliCtx.Codec.MarshalJSON(params) if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return @@ -78,10 +78,11 @@ func signingInfoHandlerListFn(cliCtx context.CLIContext) http.HandlerFunc { return } - params := types.NewQuerySigningInfosParams(page, limit) - bz, err := cliCtx.Codec.MarshalJSON(params) + params := types.NewQuerySigningInfosParams(int32(page), int32(limit)) + bz, err := params.Marshal() + if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return } diff --git a/x/slashing/internal/types/querier.go b/x/slashing/internal/types/querier.go index b149886c321b..b2929b28df68 100644 --- a/x/slashing/internal/types/querier.go +++ b/x/slashing/internal/types/querier.go @@ -13,24 +13,12 @@ const ( QuerySigningInfos = "signingInfos" ) -// QuerySigningInfoParams defines the params for the following queries: -// - 'custom/slashing/signingInfo' -type QuerySigningInfoParams struct { - ConsAddress sdk.ConsAddress -} - // NewQuerySigningInfoParams creates a new QuerySigningInfoParams instance func NewQuerySigningInfoParams(consAddr sdk.ConsAddress) QuerySigningInfoParams { return QuerySigningInfoParams{consAddr} } -// QuerySigningInfosParams defines the params for the following queries: -// - 'custom/slashing/signingInfos' -type QuerySigningInfosParams struct { - Page, Limit int -} - // NewQuerySigningInfosParams creates a new QuerySigningInfosParams instance -func NewQuerySigningInfosParams(page, limit int) QuerySigningInfosParams { +func NewQuerySigningInfosParams(page, limit int32) QuerySigningInfosParams { return QuerySigningInfosParams{page, limit} } diff --git a/x/slashing/internal/types/signing_info.go b/x/slashing/internal/types/signing_info.go index 315cac792c56..27c0de2b8db1 100644 --- a/x/slashing/internal/types/signing_info.go +++ b/x/slashing/internal/types/signing_info.go @@ -2,9 +2,8 @@ package types import ( "fmt" - "time" - "github.com/cosmos/cosmos-sdk/codec" + "time" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -42,4 +41,4 @@ func (i ValidatorSigningInfo) String() string { func UnmarshalValSigningInfo(cdc codec.Marshaler, value []byte) (signingInfo ValidatorSigningInfo, err error) { err = cdc.UnmarshalBinaryLengthPrefixed(value, &signingInfo) return signingInfo, err -} +} \ No newline at end of file diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 927afb77f438..31bd260c314f 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -158,9 +158,111 @@ func (m *ValidatorSigningInfo) GetMissedBlocksCounter() int64 { return 0 } +// QuerySigningInfoParams defines the params for the following queries: +// - 'custom/slashing/signingInfo' +type QuerySigningInfoParams struct { + ConsAddress github_com_cosmos_cosmos_sdk_types.ConsAddress `protobuf:"bytes,1,opt,name=cons_address,json=consAddress,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ConsAddress" json:"cons_address,omitempty" yaml:"cons_address"` +} + +func (m *QuerySigningInfoParams) Reset() { *m = QuerySigningInfoParams{} } +func (m *QuerySigningInfoParams) String() string { return proto.CompactTextString(m) } +func (*QuerySigningInfoParams) ProtoMessage() {} +func (*QuerySigningInfoParams) Descriptor() ([]byte, []int) { + return fileDescriptor_2b882c3b0cdd6f57, []int{2} +} +func (m *QuerySigningInfoParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySigningInfoParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySigningInfoParams.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 *QuerySigningInfoParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySigningInfoParams.Merge(m, src) +} +func (m *QuerySigningInfoParams) XXX_Size() int { + return m.Size() +} +func (m *QuerySigningInfoParams) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySigningInfoParams.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySigningInfoParams proto.InternalMessageInfo + +func (m *QuerySigningInfoParams) GetConsAddress() github_com_cosmos_cosmos_sdk_types.ConsAddress { + if m != nil { + return m.ConsAddress + } + return nil +} + +// QuerySigningInfosParams defines the params for the following queries: +// - 'custom/slashing/signingInfos' +type QuerySigningInfosParams struct { + Page int32 `protobuf:"varint,1,opt,name=Page,proto3" json:"Page,omitempty"` + Limit int32 `protobuf:"varint,2,opt,name=Limit,proto3" json:"Limit,omitempty"` +} + +func (m *QuerySigningInfosParams) Reset() { *m = QuerySigningInfosParams{} } +func (m *QuerySigningInfosParams) String() string { return proto.CompactTextString(m) } +func (*QuerySigningInfosParams) ProtoMessage() {} +func (*QuerySigningInfosParams) Descriptor() ([]byte, []int) { + return fileDescriptor_2b882c3b0cdd6f57, []int{3} +} +func (m *QuerySigningInfosParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySigningInfosParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySigningInfosParams.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 *QuerySigningInfosParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySigningInfosParams.Merge(m, src) +} +func (m *QuerySigningInfosParams) XXX_Size() int { + return m.Size() +} +func (m *QuerySigningInfosParams) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySigningInfosParams.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySigningInfosParams proto.InternalMessageInfo + +func (m *QuerySigningInfosParams) GetPage() int32 { + if m != nil { + return m.Page + } + return 0 +} + +func (m *QuerySigningInfosParams) GetLimit() int32 { + if m != nil { + return m.Limit + } + return 0 +} + func init() { proto.RegisterType((*MsgUnjail)(nil), "cosmos_sdk.x.slashing.v1.MsgUnjail") proto.RegisterType((*ValidatorSigningInfo)(nil), "cosmos_sdk.x.slashing.v1.ValidatorSigningInfo") + proto.RegisterType((*QuerySigningInfoParams)(nil), "cosmos_sdk.x.slashing.v1.QuerySigningInfoParams") + proto.RegisterType((*QuerySigningInfosParams)(nil), "cosmos_sdk.x.slashing.v1.QuerySigningInfosParams") } func init() { @@ -168,38 +270,43 @@ func init() { } var fileDescriptor_2b882c3b0cdd6f57 = []byte{ - // 496 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xb1, 0x6f, 0xd3, 0x4e, - 0x14, 0xce, 0xfd, 0xf2, 0x6b, 0x09, 0x97, 0x50, 0x09, 0x97, 0x0a, 0x2b, 0x42, 0xbe, 0xc8, 0x12, - 0x28, 0x4b, 0x6d, 0x01, 0x62, 0xc9, 0x86, 0x8b, 0x04, 0x0c, 0x15, 0x92, 0x69, 0x3b, 0x30, 0x60, - 0x9d, 0x73, 0x97, 0xf3, 0x11, 0xfb, 0x2e, 0xf2, 0x5d, 0xaa, 0x64, 0xe4, 0x3f, 0xe8, 0xc8, 0xd8, - 0x3f, 0xa7, 0x13, 0xea, 0xc8, 0x64, 0x50, 0xb2, 0x30, 0x7b, 0x64, 0x42, 0xf6, 0xc5, 0x34, 0x20, - 0x06, 0x16, 0xfb, 0xde, 0xf7, 0xbe, 0xef, 0x7d, 0xef,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 0xe5, 0x80, 0xeb, 0x95, 0x03, 0xbe, 0xad, 0x1c, 0x70, 0xb1, - 0x76, 0x5a, 0xd7, 0x6b, 0xa7, 0xf5, 0x65, 0xed, 0xb4, 0xde, 0xed, 0xd4, 0xdb, 0x88, 0x77, 0xeb, - 0x11, 0x9f, 0xfe, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x1d, 0xa4, 0xe7, 0x2b, 0x08, 0x03, 0x00, 0x00, + // 563 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0x31, 0x6f, 0xd3, 0x40, + 0x18, 0xcd, 0xd1, 0xa6, 0x94, 0x4b, 0xa8, 0x84, 0xdb, 0x52, 0x2b, 0x42, 0xbe, 0xc8, 0x12, 0x28, + 0x4b, 0x6d, 0x01, 0x62, 0xc9, 0x86, 0x83, 0x04, 0x95, 0xa8, 0x28, 0xa6, 0xed, 0xc0, 0x80, 0x75, + 0xb1, 0x2f, 0xce, 0x11, 0xfb, 0x2e, 0xf2, 0x5d, 0xaa, 0x64, 0x64, 0x61, 0xee, 0xc8, 0xd8, 0x9f, + 0xd3, 0x09, 0x75, 0x64, 0x32, 0x28, 0x59, 0x98, 0x33, 0x32, 0xa1, 0xdc, 0xc5, 0xc4, 0xad, 0x18, + 0x10, 0x4b, 0xe2, 0xf7, 0x7d, 0xdf, 0xfb, 0xde, 0xbb, 0x7b, 0x07, 0x1f, 0x8e, 0x5d, 0x91, 0x60, + 0xd1, 0xa7, 0x2c, 0x76, 0x29, 0x93, 0x24, 0x63, 0x38, 0x71, 0xe5, 0x64, 0x48, 0x84, 0xfe, 0x75, + 0x86, 0x19, 0x97, 0xdc, 0x30, 0x43, 0x2e, 0x52, 0x2e, 0x02, 0x11, 0x0d, 0x9c, 0xb1, 0x53, 0x30, + 0x9c, 0xb3, 0xc7, 0x8d, 0x47, 0xb2, 0x4f, 0xb3, 0x28, 0x18, 0xe2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 0x50, 0xf5, 0xd5, 0xb7, 0xb1, 0x03, 0xab, 0xaf, 0x69, + 0x4a, 0xf5, 0x43, 0xa8, 0xfa, 0x1a, 0x78, 0xe8, 0x72, 0x6a, 0x81, 0xab, 0xa9, 0x05, 0x7e, 0x4c, + 0x2d, 0x70, 0x3e, 0xb3, 0x2a, 0x57, 0x33, 0xab, 0xf2, 0x6d, 0x66, 0x55, 0xde, 0x57, 0x95, 0x7c, + 0x77, 0x43, 0x05, 0xf6, 0xf4, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x12, 0xe8, 0xb0, 0x88, 0xd6, + 0x03, 0x00, 0x00, } func (this *ValidatorSigningInfo) Equal(that interface{}) bool { @@ -334,6 +441,69 @@ func (m *ValidatorSigningInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *QuerySigningInfoParams) 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 *QuerySigningInfoParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySigningInfoParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ConsAddress) > 0 { + i -= len(m.ConsAddress) + copy(dAtA[i:], m.ConsAddress) + i = encodeVarintTypes(dAtA, i, uint64(len(m.ConsAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QuerySigningInfosParams) 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 *QuerySigningInfosParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySigningInfosParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Limit != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Limit)) + i-- + dAtA[i] = 0x10 + } + if m.Page != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Page)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { offset -= sovTypes(v) base := offset @@ -385,6 +555,34 @@ func (m *ValidatorSigningInfo) Size() (n int) { return n } +func (m *QuerySigningInfoParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ConsAddress) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *QuerySigningInfosParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Page != 0 { + n += 1 + sovTypes(uint64(m.Page)) + } + if m.Limit != 0 { + n += 1 + sovTypes(uint64(m.Limit)) + } + return n +} + func sovTypes(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -675,6 +873,184 @@ func (m *ValidatorSigningInfo) Unmarshal(dAtA []byte) error { } return nil } +func (m *QuerySigningInfoParams) 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 ErrIntOverflowTypes + } + 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: QuerySigningInfoParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QuerySigningInfoParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsAddress", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConsAddress = append(m.ConsAddress[:0], dAtA[iNdEx:postIndex]...) + if m.ConsAddress == nil { + m.ConsAddress = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QuerySigningInfosParams) 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 ErrIntOverflowTypes + } + 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: QuerySigningInfosParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QuerySigningInfosParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Page", wireType) + } + m.Page = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Page |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Limit", wireType) + } + m.Limit = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Limit |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTypes(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index 0f0035b93480..8e10ba9df713 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -30,3 +30,19 @@ message ValidatorSigningInfo { bool tombstoned = 5 [(gogoproto.moretags) = "yaml:\"tombstoned\""]; // whether or not a validator has been tombstoned (killed out of validator set) int64 missed_blocks_counter = 6 [(gogoproto.moretags) = "yaml:\"missed_blocks_counter\""]; // missed blocks counter (to avoid scanning the array every time) } + +// QuerySigningInfoParams defines the params for the following queries: +// - 'custom/slashing/signingInfo' +message QuerySigningInfoParams { + bytes cons_address = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress", + (gogoproto.moretags) = "yaml:\"cons_address\"" // validator consensus address + ]; +} + +// QuerySigningInfosParams defines the params for the following queries: +// - 'custom/slashing/signingInfos' +message QuerySigningInfosParams { + int32 Page = 1; + int32 Limit = 2; +} \ No newline at end of file From 3dac3b6ab47dc0a1847200ca92d6278b06d3bce1 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 04:14:56 +0530 Subject: [PATCH 27/52] Fix typecast --- x/slashing/internal/keeper/querier.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/slashing/internal/keeper/querier.go b/x/slashing/internal/keeper/querier.go index 11b365e1ee1b..1f23cf0293e6 100644 --- a/x/slashing/internal/keeper/querier.go +++ b/x/slashing/internal/keeper/querier.go @@ -76,7 +76,7 @@ func querySigningInfos(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte return false }) - start, end := client.Paginate(len(signingInfos), params.Page, params.Limit, int(k.sk.MaxValidators(ctx))) + start, end := client.Paginate(len(signingInfos), int(params.Page), int(params.Limit), int(k.sk.MaxValidators(ctx))) if start < 0 || end < 0 { signingInfos = []types.ValidatorSigningInfo{} } else { From 6d62019020137077e589ab5ac0fcec8bb5253cb2 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 04:23:28 +0530 Subject: [PATCH 28/52] Fix gofmt --- x/slashing/internal/keeper/signing_info.go | 3 +- x/slashing/internal/types/signing_info.go | 2 +- x/slashing/internal/types/types.pb.go | 76 +++++++++++----------- x/slashing/internal/types/types.proto | 4 +- 4 files changed, 43 insertions(+), 42 deletions(-) diff --git a/x/slashing/internal/keeper/signing_info.go b/x/slashing/internal/keeper/signing_info.go index 083b20a60a91..2343318f9323 100644 --- a/x/slashing/internal/keeper/signing_info.go +++ b/x/slashing/internal/keeper/signing_info.go @@ -1,9 +1,10 @@ package keeper import ( - gogotypes "github.com/gogo/protobuf/types" "time" + gogotypes "github.com/gogo/protobuf/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" ) diff --git a/x/slashing/internal/types/signing_info.go b/x/slashing/internal/types/signing_info.go index 27c0de2b8db1..3749ccc03aed 100644 --- a/x/slashing/internal/types/signing_info.go +++ b/x/slashing/internal/types/signing_info.go @@ -41,4 +41,4 @@ func (i ValidatorSigningInfo) String() string { func UnmarshalValSigningInfo(cdc codec.Marshaler, value []byte) (signingInfo ValidatorSigningInfo, err error) { err = cdc.UnmarshalBinaryLengthPrefixed(value, &signingInfo) return signingInfo, err -} \ No newline at end of file +} diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 31bd260c314f..0c1ae551e2ae 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -207,8 +207,8 @@ func (m *QuerySigningInfoParams) GetConsAddress() github_com_cosmos_cosmos_sdk_t // QuerySigningInfosParams defines the params for the following queries: // - 'custom/slashing/signingInfos' type QuerySigningInfosParams struct { - Page int32 `protobuf:"varint,1,opt,name=Page,proto3" json:"Page,omitempty"` - Limit int32 `protobuf:"varint,2,opt,name=Limit,proto3" json:"Limit,omitempty"` + Page int32 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"` + Limit int32 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"` } func (m *QuerySigningInfosParams) Reset() { *m = QuerySigningInfosParams{} } @@ -270,43 +270,43 @@ func init() { } var fileDescriptor_2b882c3b0cdd6f57 = []byte{ - // 563 bytes of a gzipped FileDescriptorProto + // 561 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0x31, 0x6f, 0xd3, 0x40, - 0x18, 0xcd, 0xd1, 0xa6, 0x94, 0x4b, 0xa8, 0x84, 0xdb, 0x52, 0x2b, 0x42, 0xbe, 0xc8, 0x12, 0x28, - 0x4b, 0x6d, 0x01, 0x62, 0xc9, 0x86, 0x83, 0x04, 0x95, 0xa8, 0x28, 0xa6, 0xed, 0xc0, 0x80, 0x75, - 0xb1, 0x2f, 0xce, 0x11, 0xfb, 0x2e, 0xf2, 0x5d, 0xaa, 0x64, 0x64, 0x61, 0xee, 0xc8, 0xd8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 0xe8, + 0x0d, 0x7f, 0x1d, 0xb3, 0xfd, 0x1d, 0x5d, 0xf7, 0x54, 0xb9, 0xab, 0xab, 0x9d, 0xda, 0x97, 0x0b, + 0x54, 0xf9, 0x79, 0x81, 0x80, 0xfd, 0x19, 0xc0, 0xfb, 0x6f, 0xc7, 0x24, 0x9b, 0x96, 0xc2, 0x7c, + 0x83, 0x33, 0x9c, 0x0a, 0x23, 0x81, 0x8d, 0x90, 0x33, 0x11, 0x5c, 0xcf, 0xf5, 0x70, 0x7d, 0x6d, + 0xe5, 0xee, 0xff, 0x84, 0x5b, 0x0f, 0xd7, 0xc0, 0xee, 0xc2, 0xfd, 0x9b, 0x3e, 0xc4, 0xca, 0x88, + 0x01, 0x37, 0x47, 0x38, 0x26, 0xca, 0x40, 0xd5, 0x57, 0xdf, 0xc6, 0x2e, 0xac, 0x26, 0x34, 0xa5, + 0xfa, 0x21, 0x54, 0x7d, 0x0d, 0x3c, 0x74, 0x39, 0xb3, 0xc0, 0xd5, 0xcc, 0x02, 0x3f, 0x66, 0x16, + 0x38, 0x9f, 0x5b, 0x95, 0xab, 0xb9, 0x55, 0xf9, 0x36, 0xb7, 0x2a, 0xef, 0xab, 0x4a, 0xbe, 0xb7, + 0xa5, 0x02, 0x7b, 0xfa, 0x3b, 0x00, 0x00, 0xff, 0xff, 0x66, 0x38, 0xc5, 0x55, 0xd6, 0x03, 0x00, + 0x00, } func (this *ValidatorSigningInfo) Equal(that interface{}) bool { diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index 8e10ba9df713..7f259f4558a7 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -43,6 +43,6 @@ message QuerySigningInfoParams { // QuerySigningInfosParams defines the params for the following queries: // - 'custom/slashing/signingInfos' message QuerySigningInfosParams { - int32 Page = 1; - int32 Limit = 2; + int32 page = 1; + int32 limit = 2; } \ No newline at end of file From ef7cb62366122b5e403cc133effd7f1e89554e18 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 04:30:36 +0530 Subject: [PATCH 29/52] Gofmt --- x/slashing/internal/types/signing_info.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/slashing/internal/types/signing_info.go b/x/slashing/internal/types/signing_info.go index 3749ccc03aed..315cac792c56 100644 --- a/x/slashing/internal/types/signing_info.go +++ b/x/slashing/internal/types/signing_info.go @@ -2,9 +2,10 @@ package types import ( "fmt" - "github.com/cosmos/cosmos-sdk/codec" "time" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" ) From 9ce0db2566218d12861f3610d9de9a530b1a07b6 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 14:17:19 +0530 Subject: [PATCH 30/52] Use protobuf types --- x/slashing/simulation/decoder.go | 16 +++++++--------- x/slashing/simulation/decoder_test.go | 10 +++++++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/x/slashing/simulation/decoder.go b/x/slashing/simulation/decoder.go index 9aea5f701b15..daad8332d60b 100644 --- a/x/slashing/simulation/decoder.go +++ b/x/slashing/simulation/decoder.go @@ -3,12 +3,11 @@ package simulation import ( "bytes" "fmt" + "github.com/cosmos/cosmos-sdk/codec" + gogotypes "github.com/gogo/protobuf/types" - "github.com/tendermint/tendermint/crypto" tmkv "github.com/tendermint/tendermint/libs/kv" - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" ) @@ -22,18 +21,17 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { return fmt.Sprintf("%v\n%v", infoA, infoB) case bytes.Equal(kvA.Key[:1], types.ValidatorMissedBlockBitArrayKey): - var missedA, missedB bool + var missedA, missedB gogotypes.BoolValue cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &missedA) cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &missedB) - return fmt.Sprintf("missedA: %v\nmissedB: %v", missedA, missedB) + return fmt.Sprintf("missedA: %v missedB: %v\n", missedA.Value, missedB.Value) case bytes.Equal(kvA.Key[:1], types.AddrPubkeyRelationKey): - var pubKeyA, pubKeyB crypto.PubKey + var pubKeyA, pubKeyB gogotypes.StringValue cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &pubKeyA) cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &pubKeyB) - bechPKA := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKeyA) - bechPKB := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKeyB) - return fmt.Sprintf("PubKeyA: %s\nPubKeyB: %s", bechPKA, bechPKB) + + return fmt.Sprintf("PubKeyA: %s\nPubKeyB: %s", pubKeyA.Value, pubKeyB.Value) default: panic(fmt.Sprintf("invalid slashing key prefix %X", kvA.Key[:1])) diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index acd3be67c62f..1847da30e25a 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -2,6 +2,7 @@ package simulation import ( "fmt" + gogotypes "github.com/gogo/protobuf/types" "testing" "time" @@ -28,6 +29,7 @@ func makeTestCodec() (cdc *codec.Codec) { sdk.RegisterCodec(cdc) codec.RegisterCrypto(cdc) types.RegisterCodec(cdc) + return } @@ -36,12 +38,14 @@ func TestDecodeStore(t *testing.T) { info := types.NewValidatorSigningInfo(consAddr1, 0, 1, time.Now().UTC(), false, 0) bechPK := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, delPk1) - missed := true + + var missed gogotypes.BoolValue + missed.Value = true kvPairs := tmkv.Pairs{ tmkv.Pair{Key: types.GetValidatorSigningInfoKey(consAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(info)}, tmkv.Pair{Key: types.GetValidatorMissedBlockBitArrayKey(consAddr1, 6), Value: cdc.MustMarshalBinaryLengthPrefixed(missed)}, - tmkv.Pair{Key: types.GetAddrPubkeyRelationKey(delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(delPk1)}, + tmkv.Pair{Key: types.GetAddrPubkeyRelationKey(delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.StringValue{Value:bechPK})}, tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}}, } @@ -50,7 +54,7 @@ func TestDecodeStore(t *testing.T) { expectedLog string }{ {"ValidatorSigningInfo", fmt.Sprintf("%v\n%v", info, info)}, - {"ValidatorMissedBlockBitArray", fmt.Sprintf("missedA: %v\nmissedB: %v", missed, missed)}, + {"ValidatorMissedBlockBitArray", fmt.Sprintf("missedA: %v missedB: %v\n", missed.Value, missed.Value)}, {"AddrPubkeyRelation", fmt.Sprintf("PubKeyA: %s\nPubKeyB: %s", bechPK, bechPK)}, {"other", ""}, } From ae47cb74533cacc70ee6b4b6ff37c30511221a28 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 22:29:39 +0530 Subject: [PATCH 31/52] Revert --- x/slashing/simulation/decoder.go | 17 +++++++++-------- x/slashing/simulation/decoder_test.go | 9 +++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/x/slashing/simulation/decoder.go b/x/slashing/simulation/decoder.go index daad8332d60b..7b2f05050cba 100644 --- a/x/slashing/simulation/decoder.go +++ b/x/slashing/simulation/decoder.go @@ -3,11 +3,11 @@ package simulation import ( "bytes" "fmt" - "github.com/cosmos/cosmos-sdk/codec" - gogotypes "github.com/gogo/protobuf/types" - + "github.com/tendermint/tendermint/crypto" tmkv "github.com/tendermint/tendermint/libs/kv" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" ) @@ -21,17 +21,18 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { return fmt.Sprintf("%v\n%v", infoA, infoB) case bytes.Equal(kvA.Key[:1], types.ValidatorMissedBlockBitArrayKey): - var missedA, missedB gogotypes.BoolValue + var missedA, missedB bool cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &missedA) cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &missedB) - return fmt.Sprintf("missedA: %v missedB: %v\n", missedA.Value, missedB.Value) + return fmt.Sprintf("missedA: %v\nmissedB: %v", missedA, missedB) case bytes.Equal(kvA.Key[:1], types.AddrPubkeyRelationKey): - var pubKeyA, pubKeyB gogotypes.StringValue + var pubKeyA, pubKeyB crypto.PubKey cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &pubKeyA) cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &pubKeyB) - - return fmt.Sprintf("PubKeyA: %s\nPubKeyB: %s", pubKeyA.Value, pubKeyB.Value) + bechPKA := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKeyA) + bechPKB := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKeyB) + return fmt.Sprintf("PubKeyA: %s\nPubKeyB: %s", bechPKA, bechPKB) default: panic(fmt.Sprintf("invalid slashing key prefix %X", kvA.Key[:1])) diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index 1847da30e25a..ade58c6ebc8b 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -2,7 +2,6 @@ package simulation import ( "fmt" - gogotypes "github.com/gogo/protobuf/types" "testing" "time" @@ -29,7 +28,6 @@ func makeTestCodec() (cdc *codec.Codec) { sdk.RegisterCodec(cdc) codec.RegisterCrypto(cdc) types.RegisterCodec(cdc) - return } @@ -39,13 +37,12 @@ func TestDecodeStore(t *testing.T) { info := types.NewValidatorSigningInfo(consAddr1, 0, 1, time.Now().UTC(), false, 0) bechPK := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, delPk1) - var missed gogotypes.BoolValue - missed.Value = true + missed := true kvPairs := tmkv.Pairs{ tmkv.Pair{Key: types.GetValidatorSigningInfoKey(consAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(info)}, tmkv.Pair{Key: types.GetValidatorMissedBlockBitArrayKey(consAddr1, 6), Value: cdc.MustMarshalBinaryLengthPrefixed(missed)}, - tmkv.Pair{Key: types.GetAddrPubkeyRelationKey(delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.StringValue{Value:bechPK})}, + tmkv.Pair{Key: types.GetAddrPubkeyRelationKey(delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(delPk1)}, tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}}, } @@ -54,7 +51,7 @@ func TestDecodeStore(t *testing.T) { expectedLog string }{ {"ValidatorSigningInfo", fmt.Sprintf("%v\n%v", info, info)}, - {"ValidatorMissedBlockBitArray", fmt.Sprintf("missedA: %v missedB: %v\n", missed.Value, missed.Value)}, + {"ValidatorMissedBlockBitArray", fmt.Sprintf("missedA: %v\nmissedB: %v", missed, missed)}, {"AddrPubkeyRelation", fmt.Sprintf("PubKeyA: %s\nPubKeyB: %s", bechPK, bechPK)}, {"other", ""}, } From 30673c00a5e83162de67da6a4bb934f0dc829aaf Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 22:34:48 +0530 Subject: [PATCH 32/52] Revert query params --- x/slashing/internal/types/querier.go | 14 +- x/slashing/internal/types/types.pb.go | 440 ++------------------------ x/slashing/internal/types/types.proto | 16 - 3 files changed, 45 insertions(+), 425 deletions(-) diff --git a/x/slashing/internal/types/querier.go b/x/slashing/internal/types/querier.go index b2929b28df68..b149886c321b 100644 --- a/x/slashing/internal/types/querier.go +++ b/x/slashing/internal/types/querier.go @@ -13,12 +13,24 @@ const ( QuerySigningInfos = "signingInfos" ) +// QuerySigningInfoParams defines the params for the following queries: +// - 'custom/slashing/signingInfo' +type QuerySigningInfoParams struct { + ConsAddress sdk.ConsAddress +} + // NewQuerySigningInfoParams creates a new QuerySigningInfoParams instance func NewQuerySigningInfoParams(consAddr sdk.ConsAddress) QuerySigningInfoParams { return QuerySigningInfoParams{consAddr} } +// QuerySigningInfosParams defines the params for the following queries: +// - 'custom/slashing/signingInfos' +type QuerySigningInfosParams struct { + Page, Limit int +} + // NewQuerySigningInfosParams creates a new QuerySigningInfosParams instance -func NewQuerySigningInfosParams(page, limit int32) QuerySigningInfosParams { +func NewQuerySigningInfosParams(page, limit int) QuerySigningInfosParams { return QuerySigningInfosParams{page, limit} } diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 0c1ae551e2ae..927afb77f438 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -158,111 +158,9 @@ func (m *ValidatorSigningInfo) GetMissedBlocksCounter() int64 { return 0 } -// QuerySigningInfoParams defines the params for the following queries: -// - 'custom/slashing/signingInfo' -type QuerySigningInfoParams struct { - ConsAddress github_com_cosmos_cosmos_sdk_types.ConsAddress `protobuf:"bytes,1,opt,name=cons_address,json=consAddress,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ConsAddress" json:"cons_address,omitempty" yaml:"cons_address"` -} - -func (m *QuerySigningInfoParams) Reset() { *m = QuerySigningInfoParams{} } -func (m *QuerySigningInfoParams) String() string { return proto.CompactTextString(m) } -func (*QuerySigningInfoParams) ProtoMessage() {} -func (*QuerySigningInfoParams) Descriptor() ([]byte, []int) { - return fileDescriptor_2b882c3b0cdd6f57, []int{2} -} -func (m *QuerySigningInfoParams) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QuerySigningInfoParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QuerySigningInfoParams.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 *QuerySigningInfoParams) XXX_Merge(src proto.Message) { - xxx_messageInfo_QuerySigningInfoParams.Merge(m, src) -} -func (m *QuerySigningInfoParams) XXX_Size() int { - return m.Size() -} -func (m *QuerySigningInfoParams) XXX_DiscardUnknown() { - xxx_messageInfo_QuerySigningInfoParams.DiscardUnknown(m) -} - -var xxx_messageInfo_QuerySigningInfoParams proto.InternalMessageInfo - -func (m *QuerySigningInfoParams) GetConsAddress() github_com_cosmos_cosmos_sdk_types.ConsAddress { - if m != nil { - return m.ConsAddress - } - return nil -} - -// QuerySigningInfosParams defines the params for the following queries: -// - 'custom/slashing/signingInfos' -type QuerySigningInfosParams struct { - Page int32 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"` - Limit int32 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"` -} - -func (m *QuerySigningInfosParams) Reset() { *m = QuerySigningInfosParams{} } -func (m *QuerySigningInfosParams) String() string { return proto.CompactTextString(m) } -func (*QuerySigningInfosParams) ProtoMessage() {} -func (*QuerySigningInfosParams) Descriptor() ([]byte, []int) { - return fileDescriptor_2b882c3b0cdd6f57, []int{3} -} -func (m *QuerySigningInfosParams) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QuerySigningInfosParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QuerySigningInfosParams.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 *QuerySigningInfosParams) XXX_Merge(src proto.Message) { - xxx_messageInfo_QuerySigningInfosParams.Merge(m, src) -} -func (m *QuerySigningInfosParams) XXX_Size() int { - return m.Size() -} -func (m *QuerySigningInfosParams) XXX_DiscardUnknown() { - xxx_messageInfo_QuerySigningInfosParams.DiscardUnknown(m) -} - -var xxx_messageInfo_QuerySigningInfosParams proto.InternalMessageInfo - -func (m *QuerySigningInfosParams) GetPage() int32 { - if m != nil { - return m.Page - } - return 0 -} - -func (m *QuerySigningInfosParams) GetLimit() int32 { - if m != nil { - return m.Limit - } - return 0 -} - func init() { proto.RegisterType((*MsgUnjail)(nil), "cosmos_sdk.x.slashing.v1.MsgUnjail") proto.RegisterType((*ValidatorSigningInfo)(nil), "cosmos_sdk.x.slashing.v1.ValidatorSigningInfo") - proto.RegisterType((*QuerySigningInfoParams)(nil), "cosmos_sdk.x.slashing.v1.QuerySigningInfoParams") - proto.RegisterType((*QuerySigningInfosParams)(nil), "cosmos_sdk.x.slashing.v1.QuerySigningInfosParams") } func init() { @@ -270,43 +168,38 @@ func init() { } var fileDescriptor_2b882c3b0cdd6f57 = []byte{ - // 561 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0x31, 0x6f, 0xd3, 0x40, - 0x18, 0xcd, 0xd1, 0xa6, 0x84, 0x4b, 0xa8, 0x84, 0xdb, 0x52, 0x2b, 0x42, 0xbe, 0xc8, 0x12, 0x28, - 0x4b, 0x6d, 0x01, 0x62, 0xc9, 0x86, 0x83, 0x04, 0x1d, 0x2a, 0xc0, 0xb4, 0x1d, 0x18, 0xb0, 0x2e, - 0xf6, 0xc5, 0x39, 0x62, 0xdf, 0x45, 0xbe, 0x4b, 0x95, 0x8c, 0x2c, 0xcc, 0x1d, 0x19, 0xfb, 0x73, - 0x3a, 0xa1, 0x8e, 0x4c, 0x06, 0x25, 0x0b, 0x73, 0x46, 0x26, 0x94, 0xbb, 0x98, 0xb8, 0x15, 0x03, - 0x62, 0x49, 0xfc, 0xbe, 0xef, 0x7b, 0xdf, 0x7b, 0x77, 0xef, 0xe0, 0xc3, 0x89, 0x2b, 0x12, 0x2c, - 0x06, 0x94, 0xc5, 0x2e, 0x65, 0x92, 0x64, 0x0c, 0x27, 0xae, 0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 0xe2, 0x4c, 0x06, 0x03, 0x42, 0xe3, 0x81, 0x34, 0x6f, 0xb5, 0x40, 0x7b, 0xc3, 0xdb, 0x5f, 0xe4, - 0x68, 0x47, 0x8b, 0x94, 0xbb, 0xb6, 0x5f, 0x57, 0xf0, 0x95, 0x42, 0x4b, 0x2e, 0x65, 0x11, 0x99, - 0x04, 0xbc, 0xdf, 0x17, 0x44, 0x9a, 0x1b, 0x37, 0xb9, 0xe5, 0xae, 0xed, 0xd7, 0x15, 0x7c, 0xad, - 0x90, 0xf1, 0x12, 0x36, 0x96, 0xd7, 0x4d, 0xa2, 0x60, 0xcc, 0x24, 0x4d, 0xcc, 0xcd, 0x16, 0x68, - 0xd7, 0x9f, 0x34, 0x1d, 0x1d, 0x96, 0x53, 0x84, 0xe5, 0x1c, 0x17, 0x61, 0x79, 0xb5, 0xcb, 0x1c, - 0x55, 0xce, 0xbf, 0x23, 0xe0, 0xd7, 0x35, 0xf3, 0x64, 0x49, 0x34, 0x9e, 0x41, 0x28, 0x79, 0xda, - 0x13, 0x92, 0x33, 0x12, 0x99, 0xd5, 0x16, 0x68, 0xd7, 0xbc, 0xbd, 0x45, 0x8e, 0xee, 0x69, 0x0b, - 0xeb, 0x9e, 0xed, 0x97, 0x06, 0x8d, 0x63, 0xb8, 0x97, 0x52, 0x21, 0x48, 0x14, 0xf4, 0x12, 0x1e, - 0x0e, 0x45, 0x10, 0xf2, 0xf1, 0xf2, 0x15, 0x9a, 0x5b, 0xea, 0x10, 0xad, 0x45, 0x8e, 0x1e, 0xe8, - 0x0d, 0x7f, 0x1d, 0xb3, 0xfd, 0x1d, 0x5d, 0xf7, 0x54, 0xb9, 0xab, 0xab, 0x9d, 0xda, 0x97, 0x0b, - 0x54, 0xf9, 0x79, 0x81, 0x80, 0xfd, 0x19, 0xc0, 0xfb, 0x6f, 0xc7, 0x24, 0x9b, 0x96, 0xc2, 0x7c, - 0x83, 0x33, 0x9c, 0x0a, 0x23, 0x81, 0x8d, 0x90, 0x33, 0x11, 0x5c, 0xcf, 0xf5, 0x70, 0x7d, 0x6d, - 0xe5, 0xee, 0xff, 0x84, 0x5b, 0x0f, 0xd7, 0xc0, 0xee, 0xc2, 0xfd, 0x9b, 0x3e, 0xc4, 0xca, 0x88, - 0x01, 0x37, 0x47, 0x38, 0x26, 0xca, 0x40, 0xd5, 0x57, 0xdf, 0xc6, 0x2e, 0xac, 0x26, 0x34, 0xa5, - 0xfa, 0x21, 0x54, 0x7d, 0x0d, 0x3c, 0x74, 0x39, 0xb3, 0xc0, 0xd5, 0xcc, 0x02, 0x3f, 0x66, 0x16, - 0x38, 0x9f, 0x5b, 0x95, 0xab, 0xb9, 0x55, 0xf9, 0x36, 0xb7, 0x2a, 0xef, 0xab, 0x4a, 0xbe, 0xb7, - 0xa5, 0x02, 0x7b, 0xfa, 0x3b, 0x00, 0x00, 0xff, 0xff, 0x66, 0x38, 0xc5, 0x55, 0xd6, 0x03, 0x00, - 0x00, + // 496 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xb1, 0x6f, 0xd3, 0x4e, + 0x14, 0xce, 0xfd, 0xf2, 0x6b, 0x09, 0x97, 0x50, 0x09, 0x97, 0x0a, 0x2b, 0x42, 0xbe, 0xc8, 0x12, + 0x28, 0x4b, 0x6d, 0x01, 0x62, 0xc9, 0x86, 0x8b, 0x04, 0x0c, 0x15, 0x92, 0x69, 0x3b, 0x30, 0x60, + 0x9d, 0x73, 0x97, 0xf3, 0x11, 0xfb, 0x2e, 0xf2, 0x5d, 0xaa, 0x64, 0xe4, 0x3f, 0xe8, 0xc8, 0xd8, + 0x3f, 0xa7, 0x13, 0xea, 0xc8, 0x64, 0x50, 0xb2, 0x30, 0x7b, 0x64, 0x42, 0xf6, 0xc5, 0x34, 0x20, + 0x06, 0x16, 0xfb, 0xde, 0xf7, 0xbe, 0xef, 0x7d, 0xef, 0xdd, 0x3b, 0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eb, 0x95, 0x03, 0xbe, 0xad, 0x1c, 0x70, 0xb1, + 0x76, 0x5a, 0xd7, 0x6b, 0xa7, 0xf5, 0x65, 0xed, 0xb4, 0xde, 0xed, 0xd4, 0xdb, 0x88, 0x77, 0xeb, + 0x11, 0x9f, 0xfe, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x1d, 0xa4, 0xe7, 0x2b, 0x08, 0x03, 0x00, 0x00, } func (this *ValidatorSigningInfo) Equal(that interface{}) bool { @@ -441,69 +334,6 @@ func (m *ValidatorSigningInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QuerySigningInfoParams) 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 *QuerySigningInfoParams) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QuerySigningInfoParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.ConsAddress) > 0 { - i -= len(m.ConsAddress) - copy(dAtA[i:], m.ConsAddress) - i = encodeVarintTypes(dAtA, i, uint64(len(m.ConsAddress))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *QuerySigningInfosParams) 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 *QuerySigningInfosParams) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QuerySigningInfosParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Limit != 0 { - i = encodeVarintTypes(dAtA, i, uint64(m.Limit)) - i-- - dAtA[i] = 0x10 - } - if m.Page != 0 { - i = encodeVarintTypes(dAtA, i, uint64(m.Page)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { offset -= sovTypes(v) base := offset @@ -555,34 +385,6 @@ func (m *ValidatorSigningInfo) Size() (n int) { return n } -func (m *QuerySigningInfoParams) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ConsAddress) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - return n -} - -func (m *QuerySigningInfosParams) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Page != 0 { - n += 1 + sovTypes(uint64(m.Page)) - } - if m.Limit != 0 { - n += 1 + sovTypes(uint64(m.Limit)) - } - return n -} - func sovTypes(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -873,184 +675,6 @@ func (m *ValidatorSigningInfo) Unmarshal(dAtA []byte) error { } return nil } -func (m *QuerySigningInfoParams) 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 ErrIntOverflowTypes - } - 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: QuerySigningInfoParams: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QuerySigningInfoParams: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ConsAddress", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ConsAddress = append(m.ConsAddress[:0], dAtA[iNdEx:postIndex]...) - if m.ConsAddress == nil { - m.ConsAddress = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QuerySigningInfosParams) 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 ErrIntOverflowTypes - } - 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: QuerySigningInfosParams: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QuerySigningInfosParams: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Page", wireType) - } - m.Page = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Page |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Limit", wireType) - } - m.Limit = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Limit |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipTypes(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index 7f259f4558a7..1f7c6182adf2 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -29,20 +29,4 @@ message ValidatorSigningInfo { (gogoproto.nullable) = false]; // timestamp validator cannot be unjailed until bool tombstoned = 5 [(gogoproto.moretags) = "yaml:\"tombstoned\""]; // whether or not a validator has been tombstoned (killed out of validator set) int64 missed_blocks_counter = 6 [(gogoproto.moretags) = "yaml:\"missed_blocks_counter\""]; // missed blocks counter (to avoid scanning the array every time) -} - -// QuerySigningInfoParams defines the params for the following queries: -// - 'custom/slashing/signingInfo' -message QuerySigningInfoParams { - bytes cons_address = 1 [ - (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress", - (gogoproto.moretags) = "yaml:\"cons_address\"" // validator consensus address - ]; -} - -// QuerySigningInfosParams defines the params for the following queries: -// - 'custom/slashing/signingInfos' -message QuerySigningInfosParams { - int32 page = 1; - int32 limit = 2; } \ No newline at end of file From 1480c4616c16a3e67e8f9e3fe586a61b0b8910ab Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 22:45:49 +0530 Subject: [PATCH 33/52] Revert query, tx --- x/slashing/client/rest/query.go | 9 ++-- x/slashing/internal/types/codec.go | 3 +- x/slashing/internal/types/msg.go | 2 +- x/slashing/internal/types/types.pb.go | 72 +++++++++++++-------------- x/slashing/internal/types/types.proto | 14 +++--- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/x/slashing/client/rest/query.go b/x/slashing/client/rest/query.go index 2aa8ee84a470..751fe648dc45 100644 --- a/x/slashing/client/rest/query.go +++ b/x/slashing/client/rest/query.go @@ -45,8 +45,8 @@ func signingInfoHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { } params := types.NewQuerySigningInfoParams(sdk.ConsAddress(pk.Address())) - bz, err := params.Marshal() + bz, err := cliCtx.Codec.MarshalJSON(params) if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return @@ -78,11 +78,10 @@ func signingInfoHandlerListFn(cliCtx context.CLIContext) http.HandlerFunc { return } - params := types.NewQuerySigningInfosParams(int32(page), int32(limit)) - bz, err := params.Marshal() - + params := types.NewQuerySigningInfosParams(page, limit) + bz, err := cliCtx.Codec.MarshalJSON(params) if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return } diff --git a/x/slashing/internal/types/codec.go b/x/slashing/internal/types/codec.go index dbb7a9d0b8b6..e6c96440c542 100644 --- a/x/slashing/internal/types/codec.go +++ b/x/slashing/internal/types/codec.go @@ -13,6 +13,7 @@ type Codec struct { codec.Marshaler // Keep reference to the amino codec to allow backwards compatibility along // with type, and interface registration. + amino *codec.Codec } @@ -24,8 +25,6 @@ var ModuleCdc *Codec func init() { ModuleCdc = NewCodec(codec.New()) - //ModuleCdc = codec.New() RegisterCodec(ModuleCdc.amino) - //codec.RegisterCrypto(ModuleCdc) ModuleCdc.amino.Seal() } diff --git a/x/slashing/internal/types/msg.go b/x/slashing/internal/types/msg.go index 49fd830d9615..a9798615f6ad 100644 --- a/x/slashing/internal/types/msg.go +++ b/x/slashing/internal/types/msg.go @@ -29,7 +29,7 @@ func (msg MsgUnjail) GetSignBytes() []byte { // ValidateBasic validity check for the AnteHandler func (msg MsgUnjail) ValidateBasic() error { - if len(msg.ValidatorAddr) < 1 { //if empty + if msg.ValidatorAddr.Empty() { return ErrBadValidatorAddr } diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index 927afb77f438..b3dd9722e6c4 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -31,7 +31,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // MsgUnjail - struct for unjailing jailed validator type MsgUnjail struct { - ValidatorAddr github_com_cosmos_cosmos_sdk_types.ValAddress `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ValAddress" json:"validator_addr,omitempty" yaml:"validator_address"` + ValidatorAddr github_com_cosmos_cosmos_sdk_types.ValAddress `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ValAddress" json:"validator_addr,omitempty" yaml:"address"` } func (m *MsgUnjail) Reset() { *m = MsgUnjail{} } @@ -76,11 +76,11 @@ func (m *MsgUnjail) GetValidatorAddr() github_com_cosmos_cosmos_sdk_types.ValAdd // ValidatorSigningInfo defines the signing info for a validator type ValidatorSigningInfo struct { - Address github_com_cosmos_cosmos_sdk_types.ConsAddress `protobuf:"bytes,1,opt,name=address,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ConsAddress" json:"address,omitempty" yaml:"address"` + Address github_com_cosmos_cosmos_sdk_types.ConsAddress `protobuf:"bytes,1,opt,name=address,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ConsAddress" json:"address,omitempty"` StartHeight int64 `protobuf:"varint,2,opt,name=start_height,json=startHeight,proto3" json:"start_height,omitempty" yaml:"start_height"` IndexOffset int64 `protobuf:"varint,3,opt,name=index_offset,json=indexOffset,proto3" json:"index_offset,omitempty" yaml:"index_offset"` - JailedUntil time.Time `protobuf:"bytes,4,opt,name=jailed_until,json=jailedUntil,proto3,stdtime" json:"jailed_until"` - Tombstoned bool `protobuf:"varint,5,opt,name=tombstoned,proto3" json:"tombstoned,omitempty" yaml:"tombstoned"` + JailedUntil time.Time `protobuf:"bytes,4,opt,name=jailed_until,json=jailedUntil,proto3,stdtime" json:"jailed_until" yaml:"jailed_until"` + Tombstoned bool `protobuf:"varint,5,opt,name=tombstoned,proto3" json:"tombstoned,omitempty"` MissedBlocksCounter int64 `protobuf:"varint,6,opt,name=missed_blocks_counter,json=missedBlocksCounter,proto3" json:"missed_blocks_counter,omitempty" yaml:"missed_blocks_counter"` } @@ -168,38 +168,38 @@ func init() { } var fileDescriptor_2b882c3b0cdd6f57 = []byte{ - // 496 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xb1, 0x6f, 0xd3, 0x4e, - 0x14, 0xce, 0xfd, 0xf2, 0x6b, 0x09, 0x97, 0x50, 0x09, 0x97, 0x0a, 0x2b, 0x42, 0xbe, 0xc8, 0x12, - 0x28, 0x4b, 0x6d, 0x01, 0x62, 0xc9, 0x86, 0x8b, 0x04, 0x0c, 0x15, 0x92, 0x69, 0x3b, 0x30, 0x60, - 0x9d, 0x73, 0x97, 0xf3, 0x11, 0xfb, 0x2e, 0xf2, 0x5d, 0xaa, 0x64, 0xe4, 0x3f, 0xe8, 0xc8, 0xd8, - 0x3f, 0xa7, 0x13, 0xea, 0xc8, 0x64, 0x50, 0xb2, 0x30, 0x7b, 0x64, 0x42, 0xf6, 0xc5, 0x34, 0x20, - 0x06, 0x16, 0xfb, 0xde, 0xf7, 0xbe, 0xef, 0x7d, 0xef, 0xdd, 0x3b, 0xf8, 0x70, 0xe1, 0xab, 0x14, - 0xab, 0x84, 0x0b, 0xe6, 0x73, 0xa1, 0x69, 0x2e, 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 0xf5, 0x65, 0xed, 0xb4, 0xde, 0xed, 0xd4, 0xdb, 0x88, 0x77, 0xeb, - 0x11, 0x9f, 0xfe, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x1d, 0xa4, 0xe7, 0x2b, 0x08, 0x03, 0x00, 0x00, + // 482 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x31, 0x6f, 0xd3, 0x40, + 0x14, 0xc7, 0x7d, 0x94, 0x96, 0x72, 0x09, 0x1d, 0x5c, 0x10, 0x56, 0x84, 0x7c, 0x96, 0x25, 0x50, + 0x96, 0xda, 0xa2, 0x6c, 0xd9, 0x70, 0x16, 0x90, 0x40, 0x48, 0xa6, 0xed, 0xc0, 0x80, 0x75, 0xce, + 0x5d, 0xce, 0xd7, 0xd8, 0x77, 0x91, 0xef, 0x52, 0x92, 0x6f, 0xd1, 0x91, 0xb1, 0x1f, 0x84, 0x0f, + 0xd0, 0xb1, 0x23, 0x93, 0x41, 0xc9, 0xc2, 0x9c, 0xb1, 0x13, 0xb2, 0x2f, 0xa6, 0x11, 0x62, 0x60, + 0xb1, 0xfd, 0x7e, 0xf7, 0xfe, 0xef, 0xef, 0xe7, 0xbf, 0xe1, 0xf3, 0x79, 0xa8, 0x72, 0xac, 0x32, + 0x2e, 0x58, 0xc8, 0x85, 0xa6, 0xa5, 0xc0, 0x79, 0xa8, 0x17, 0x53, 0xaa, 0xcc, 0x35, 0x98, 0x96, + 0x52, 0x4b, 0xdb, 0x19, 0x49, 0x55, 0x48, 0x95, 0x28, 0x32, 0x09, 0xe6, 0x41, 0xab, 0x08, 0x2e, + 0x5e, 0xf6, 0x5e, 0xe8, 0x8c, 0x97, 0x24, 0x99, 0xe2, 0x52, 0x2f, 0xc2, 0xa6, 0x39, 0x64, 0x92, + 0xc9, 0xbb, 0x27, 0x33, 0xa1, 0x87, 0x98, 0x94, 0x2c, 0xa7, 0xa6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, 0x92, + 0x64, 0x26, 0x34, 0xcf, 0x9d, 0xfb, 0x1e, 0xe8, 0x77, 0x8e, 0x7b, 0x81, 0xc9, 0x23, 0x68, 0xf3, + 0x08, 0x4e, 0xda, 0x3c, 0x22, 0x74, 0x5d, 0x21, 0xeb, 0x6e, 0xf6, 0xb6, 0xda, 0xbf, 0xfc, 0x81, + 0x40, 0xdc, 0x31, 0xe8, 0xb4, 0x26, 0xb6, 0x0b, 0xa1, 0x96, 0x45, 0xaa, 0xb4, 0x14, 0x94, 0x38, + 0xbb, 0x1e, 0xe8, 0xef, 0xc7, 0x5b, 0xc4, 0x3e, 0x81, 0x4f, 0x0a, 0xae, 0x14, 0x25, 0x49, 0x9a, + 0xcb, 0xd1, 0x44, 0x25, 0x23, 0x39, 0xab, 0x7f, 0x34, 0x67, 0xaf, 0x59, 0xc2, 0x5b, 0x57, 0xe8, + 0x99, 0x31, 0xfa, 0x67, 0x9b, 0x1f, 0x1f, 0x1a, 0x1e, 0x35, 0x78, 0x68, 0xe8, 0x60, 0xff, 0xeb, + 0x15, 0xb2, 0x7e, 0x5d, 0x21, 0x10, 0xa1, 0xeb, 0xa5, 0x0b, 0x6e, 0x96, 0x2e, 0xf8, 0xb9, 0x74, + 0xc1, 0xe5, 0xca, 0xb5, 0x6e, 0x56, 0xae, 0xf5, 0x7d, 0xe5, 0x5a, 0x9f, 0x76, 0x9b, 0x34, 0xd2, + 0xbd, 0x66, 0xc5, 0x57, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0xbc, 0x6f, 0xa4, 0x75, 0xeb, 0x02, + 0x00, 0x00, } func (this *ValidatorSigningInfo) Equal(that interface{}) bool { diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index 1f7c6182adf2..d35444b9864e 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -10,7 +10,7 @@ import "google/protobuf/timestamp.proto"; message MsgUnjail { bytes validator_addr = 1 [ (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress", - (gogoproto.moretags) = "yaml:\"validator_address\"" + (gogoproto.moretags) = "yaml:\"address\"" ]; } @@ -20,13 +20,15 @@ message ValidatorSigningInfo { option (gogoproto.goproto_stringer) = false; bytes address = 1 [ - (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress", - (gogoproto.moretags) = "yaml:\"address\"" // validator consensus address + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress" // validator consensus address ]; int64 start_height = 2 [(gogoproto.moretags) = "yaml:\"start_height\""]; // height at which validator was first a candidate OR was unjailed int64 index_offset = 3 [(gogoproto.moretags) = "yaml:\"index_offset\""]; // index offset into signed block bit array - google.protobuf.Timestamp jailed_until = 4 [(gogoproto.stdtime) = true, - (gogoproto.nullable) = false]; // timestamp validator cannot be unjailed until - bool tombstoned = 5 [(gogoproto.moretags) = "yaml:\"tombstoned\""]; // whether or not a validator has been tombstoned (killed out of validator set) + google.protobuf.Timestamp jailed_until = 4 [ + (gogoproto.moretags) = "yaml:\"jailed_until\"", + (gogoproto.stdtime) = true, + (gogoproto.nullable) = false + ]; // timestamp validator cannot be unjailed until + bool tombstoned = 5; // whether or not a validator has been tombstoned (killed out of validator set) int64 missed_blocks_counter = 6 [(gogoproto.moretags) = "yaml:\"missed_blocks_counter\""]; // missed blocks counter (to avoid scanning the array every time) } \ No newline at end of file From 606dd29d2a19dc463f33f4fad26d0bf00a5157de Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 22:58:58 +0530 Subject: [PATCH 34/52] Fix lint issue --- simapp/codec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simapp/codec.go b/simapp/codec.go index 658e104ef19f..c12b70caf4f9 100644 --- a/simapp/codec.go +++ b/simapp/codec.go @@ -13,8 +13,8 @@ import ( // required module-specific codecs that are to be provided upon initialization. type AppCodec struct { amino *codec.Codec - Slashing *slashing.Codec + Slashing *slashing.Codec Staking *staking.Codec Distribution *distr.Codec } From 07815e16816a511bd68e7c5b7bf17e9afc9187ce Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 23:04:08 +0530 Subject: [PATCH 35/52] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0e73a23c420..689c4f5fcdc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,7 +76,7 @@ for JSON encoding. * Every reference of `crypto.Pubkey` in context of a `Validator` is now of type string. `GetPubKeyFromBech32` must be used to get the `crypto.Pubkey`. * The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type provided is specified by `ModuleCdc`. -* (slashing) [\#5627](https://github.com/cosmos/cosmos-sdk/pull/5627) Migrate the `x/slashing` module to use Protocol Buffer for state +* (x/slashing) [\#5627](https://github.com/cosmos/cosmos-sdk/pull/5627) Migrate the `x/slashing` module to use Protocol Buffer for state serialization instead of Amino. The exact codec used is `codec.HybridCodec` which utilizes Protobuf for binary encoding and Amino for JSON encoding. * The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type From 247af971d1ddba5127ca71c9272e1e2bf1c3da44 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 23:07:56 +0530 Subject: [PATCH 36/52] Fix lint issues --- x/slashing/internal/keeper/keeper.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/slashing/internal/keeper/keeper.go b/x/slashing/internal/keeper/keeper.go index 676e6ba5dfe5..88b9e5f8e966 100644 --- a/x/slashing/internal/keeper/keeper.go +++ b/x/slashing/internal/keeper/keeper.go @@ -41,7 +41,6 @@ func (k Keeper) AddPubkey(ctx sdk.Context, pubkey crypto.PubKey) { addr := pubkey.Address() pkStr, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pubkey) - if err != nil { panic(fmt.Errorf("error while setting address-pubkey relation: %s", addr)) } From 4628a98bfde3ad90a79b34134620054a11a67250 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 12 Feb 2020 23:17:10 +0530 Subject: [PATCH 37/52] Fix lint issues --- x/slashing/internal/keeper/keeper.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/x/slashing/internal/keeper/keeper.go b/x/slashing/internal/keeper/keeper.go index 88b9e5f8e966..47a1cb867f9d 100644 --- a/x/slashing/internal/keeper/keeper.go +++ b/x/slashing/internal/keeper/keeper.go @@ -54,13 +54,11 @@ func (k Keeper) GetPubkey(ctx sdk.Context, address crypto.Address) (crypto.PubKe var pubkey gogotypes.StringValue err := k.cdc.UnmarshalBinaryLengthPrefixed(store.Get(types.GetAddrPubkeyRelationKey(address)), &pubkey) - if err != nil { return nil, fmt.Errorf("address %s not found", sdk.ConsAddress(address)) } pkStr, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, pubkey.Value) - if err != nil { return pkStr, err } From b11138937dc3643c5cb114189dde2e7ae9c0ed09 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Wed, 12 Feb 2020 23:43:11 +0530 Subject: [PATCH 38/52] Removed new line --- x/slashing/client/cli/query.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/slashing/client/cli/query.go b/x/slashing/client/cli/query.go index aad4f8f3a71a..f8fc7d82d098 100644 --- a/x/slashing/client/cli/query.go +++ b/x/slashing/client/cli/query.go @@ -69,7 +69,6 @@ $ query slashing signing-info cosmosvalconspub1zcjduepqfhvwcmt7p06fvdge var signingInfo types.ValidatorSigningInfo signingInfo, err = types.UnmarshalValSigningInfo(types.ModuleCdc, res) - if err != nil { return err } From e3897cf5902bba566e751d622cc9f981af00eaf1 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Thu, 13 Feb 2020 00:43:31 +0530 Subject: [PATCH 39/52] Fix golint --- simapp/codec.go | 4 +- x/slashing/internal/types/types.pb.go | 66 +++++++++++++-------------- x/slashing/internal/types/types.proto | 3 +- x/slashing/simulation/decoder.go | 5 +- x/slashing/simulation/decoder_test.go | 7 +-- 5 files changed, 44 insertions(+), 41 deletions(-) diff --git a/simapp/codec.go b/simapp/codec.go index c12b70caf4f9..a353abd64e2f 100644 --- a/simapp/codec.go +++ b/simapp/codec.go @@ -12,9 +12,9 @@ import ( // AppCodec defines the application-level codec. This codec contains all the // required module-specific codecs that are to be provided upon initialization. type AppCodec struct { - amino *codec.Codec + amino *codec.Codec - Slashing *slashing.Codec + Slashing *slashing.Codec Staking *staking.Codec Distribution *distr.Codec } diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/internal/types/types.pb.go index b3dd9722e6c4..82791e7bcdcd 100644 --- a/x/slashing/internal/types/types.pb.go +++ b/x/slashing/internal/types/types.pb.go @@ -31,7 +31,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // MsgUnjail - struct for unjailing jailed validator type MsgUnjail struct { - ValidatorAddr github_com_cosmos_cosmos_sdk_types.ValAddress `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ValAddress" json:"validator_addr,omitempty" yaml:"address"` + ValidatorAddr github_com_cosmos_cosmos_sdk_types.ValAddress `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ValAddress" json:"address" yaml:"address"` } func (m *MsgUnjail) Reset() { *m = MsgUnjail{} } @@ -168,38 +168,38 @@ func init() { } var fileDescriptor_2b882c3b0cdd6f57 = []byte{ - // 482 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x31, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0x7d, 0x94, 0x96, 0x72, 0x09, 0x1d, 0x5c, 0x10, 0x56, 0x84, 0x7c, 0x96, 0x25, 0x50, - 0x96, 0xda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25, 0x49, 0x9a, - 0xcb, 0xd1, 0x44, 0x25, 0x23, 0x39, 0xab, 0x7f, 0x34, 0x67, 0xaf, 0x59, 0xc2, 0x5b, 0x57, 0xe8, - 0x99, 0x31, 0xfa, 0x67, 0x9b, 0x1f, 0x1f, 0x1a, 0x1e, 0x35, 0x78, 0x68, 0xe8, 0x60, 0xff, 0xeb, - 0x15, 0xb2, 0x7e, 0x5d, 0x21, 0x10, 0xa1, 0xeb, 0xa5, 0x0b, 0x6e, 0x96, 0x2e, 0xf8, 0xb9, 0x74, - 0xc1, 0xe5, 0xca, 0xb5, 0x6e, 0x56, 0xae, 0xf5, 0x7d, 0xe5, 0x5a, 0x9f, 0x76, 0x9b, 0x34, 0xd2, - 0xbd, 0x66, 0xc5, 0x57, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0xbc, 0x6f, 0xa4, 0x75, 0xeb, 0x02, - 0x00, 0x00, + // 491 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x3f, 0x6f, 0xd3, 0x4e, + 0x18, 0xc7, 0x73, 0xbf, 0xfc, 0x5a, 0xca, 0x25, 0x74, 0x70, 0x41, 0x58, 0x11, 0xf2, 0x59, 0x96, + 0x40, 0x59, 0x6a, 0x8b, 0xb2, 0x65, 0xc3, 0x5d, 0x40, 0xe2, 0x8f, 0x64, 0xda, 0x0e, 0x0c, 0x58, + 0xe7, 0xdc, 0xe5, 0x7c, 0xc4, 0xbe, 0x8b, 0x7c, 0xe7, 0x2a, 0x59, 0x79, 0x05, 0x1d, 0x19, 0xfb, + 0x42, 0x78, 0x01, 0x1d, 0x3b, 0x32, 0x19, 0x94, 0x2c, 0x88, 0x31, 0x63, 0x27, 0x64, 0x5f, 0x4c, + 0x23, 0xc4, 0xc0, 0x92, 0xf8, 0xfb, 0xb9, 0xe7, 0xfb, 0x7c, 0xef, 0xf1, 0x63, 0xf8, 0x78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, 0xac, 0x9c, 0xce, 0xf5, 0xca, 0xe9, + 0x7c, 0x5d, 0x39, 0x9d, 0xf7, 0x3b, 0xcd, 0x36, 0x92, 0xdd, 0x66, 0xc4, 0x67, 0xbf, 0x02, 0x00, + 0x00, 0xff, 0xff, 0x61, 0xf4, 0xaf, 0xf7, 0xf7, 0x02, 0x00, 0x00, } func (this *ValidatorSigningInfo) Equal(that interface{}) bool { diff --git a/x/slashing/internal/types/types.proto b/x/slashing/internal/types/types.proto index d35444b9864e..efce77fe9f1f 100644 --- a/x/slashing/internal/types/types.proto +++ b/x/slashing/internal/types/types.proto @@ -10,7 +10,8 @@ import "google/protobuf/timestamp.proto"; message MsgUnjail { bytes validator_addr = 1 [ (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress", - (gogoproto.moretags) = "yaml:\"address\"" + (gogoproto.moretags) = "yaml:\"address\"", + (gogoproto.jsontag) = "address" ]; } diff --git a/x/slashing/simulation/decoder.go b/x/slashing/simulation/decoder.go index 9aea5f701b15..0b4a36ed80f1 100644 --- a/x/slashing/simulation/decoder.go +++ b/x/slashing/simulation/decoder.go @@ -3,6 +3,7 @@ package simulation import ( "bytes" "fmt" + gogotypes "github.com/gogo/protobuf/types" "github.com/tendermint/tendermint/crypto" tmkv "github.com/tendermint/tendermint/libs/kv" @@ -22,10 +23,10 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { return fmt.Sprintf("%v\n%v", infoA, infoB) case bytes.Equal(kvA.Key[:1], types.ValidatorMissedBlockBitArrayKey): - var missedA, missedB bool + var missedA, missedB gogotypes.BoolValue cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &missedA) cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &missedB) - return fmt.Sprintf("missedA: %v\nmissedB: %v", missedA, missedB) + return fmt.Sprintf("missedA: %v\nmissedB: %v", missedA.Value, missedB.Value) case bytes.Equal(kvA.Key[:1], types.AddrPubkeyRelationKey): var pubKeyA, pubKeyB crypto.PubKey diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index acd3be67c62f..0ed78f2c3b88 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -2,6 +2,7 @@ package simulation import ( "fmt" + gogotypes "github.com/gogo/protobuf/types" "testing" "time" @@ -36,11 +37,11 @@ func TestDecodeStore(t *testing.T) { info := types.NewValidatorSigningInfo(consAddr1, 0, 1, time.Now().UTC(), false, 0) bechPK := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, delPk1) - missed := true + missed := gogotypes.BoolValue{Value: true} kvPairs := tmkv.Pairs{ tmkv.Pair{Key: types.GetValidatorSigningInfoKey(consAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(info)}, - tmkv.Pair{Key: types.GetValidatorMissedBlockBitArrayKey(consAddr1, 6), Value: cdc.MustMarshalBinaryLengthPrefixed(missed)}, + tmkv.Pair{Key: types.GetValidatorMissedBlockBitArrayKey(consAddr1, 6), Value: cdc.MustMarshalBinaryLengthPrefixed(&missed)}, tmkv.Pair{Key: types.GetAddrPubkeyRelationKey(delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(delPk1)}, tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}}, } @@ -50,7 +51,7 @@ func TestDecodeStore(t *testing.T) { expectedLog string }{ {"ValidatorSigningInfo", fmt.Sprintf("%v\n%v", info, info)}, - {"ValidatorMissedBlockBitArray", fmt.Sprintf("missedA: %v\nmissedB: %v", missed, missed)}, + {"ValidatorMissedBlockBitArray", fmt.Sprintf("missedA: %v\nmissedB: %v", missed.Value, missed.Value)}, {"AddrPubkeyRelation", fmt.Sprintf("PubKeyA: %s\nPubKeyB: %s", bechPK, bechPK)}, {"other", ""}, } From 8fbc4554a9a1bc654b8f68badccfce7ed2d97be2 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Thu, 13 Feb 2020 00:45:55 +0530 Subject: [PATCH 40/52] Fix use json and yaml tags the same as before --- x/slashing/internal/types/msg_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/slashing/internal/types/msg_test.go b/x/slashing/internal/types/msg_test.go index 80369d712004..31f7a70e75db 100644 --- a/x/slashing/internal/types/msg_test.go +++ b/x/slashing/internal/types/msg_test.go @@ -14,7 +14,7 @@ func TestMsgUnjailGetSignBytes(t *testing.T) { bytes := msg.GetSignBytes() require.Equal( t, - `{"type":"cosmos-sdk/MsgUnjail","value":{"validator_addr":"cosmosvaloper1v93xxeqhg9nn6"}}`, + `{"type":"cosmos-sdk/MsgUnjail","value":{"address":"cosmosvaloper1v93xxeqhg9nn6"}}`, string(bytes), ) } From 750e6132f6b9234b90ba7b514b91a5a3c6fbeda9 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Thu, 13 Feb 2020 00:59:34 +0530 Subject: [PATCH 41/52] Fix gofmt --- x/slashing/simulation/decoder_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index 0ed78f2c3b88..c2c2f448010a 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -2,10 +2,11 @@ package simulation import ( "fmt" - gogotypes "github.com/gogo/protobuf/types" "testing" "time" + gogotypes "github.com/gogo/protobuf/types" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/ed25519" From 5b9cc9fdff477f239cde0db1cba43e2ce2a8f8fb Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sun, 16 Feb 2020 23:42:20 +0530 Subject: [PATCH 42/52] Gofmt --- x/slashing/app_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index 4a13d99db4ae..1cb0fcd437a3 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -85,4 +85,4 @@ func TestSlashingMsgs(t *testing.T) { require.Error(t, err) require.Nil(t, res) require.True(t, errors.Is(slashing.ErrValidatorNotJailed, err)) -} \ No newline at end of file +} From ae52acead1c1a08eb9dcdbb167b5d6c6a5556dfb Mon Sep 17 00:00:00 2001 From: anilCSE Date: Sun, 16 Feb 2020 23:54:17 +0530 Subject: [PATCH 43/52] Fix test-sim-import-export issue --- x/slashing/internal/keeper/signing_info.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/x/slashing/internal/keeper/signing_info.go b/x/slashing/internal/keeper/signing_info.go index 2343318f9323..7afe299f1979 100644 --- a/x/slashing/internal/keeper/signing_info.go +++ b/x/slashing/internal/keeper/signing_info.go @@ -77,13 +77,14 @@ func (k Keeper) IterateValidatorMissedBlockBitArray(ctx sdk.Context, index := int64(0) // Array may be sparse for ; index < k.SignedBlocksWindow(ctx); index++ { - var missed bool + var missed gogotypes.BoolValue bz := store.Get(types.GetValidatorMissedBlockBitArrayKey(address, index)) if bz == nil { continue } - k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &gogotypes.BoolValue{Value: missed}) - if handler(index, missed) { + + k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &missed) + if handler(index, missed.Value) { break } } From 28e255634ba6e8e9956c3168567b6eabdac9ff61 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Mon, 17 Feb 2020 01:14:52 +0530 Subject: [PATCH 44/52] Fix gofmt --- x/slashing/internal/keeper/querier.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/slashing/internal/keeper/querier.go b/x/slashing/internal/keeper/querier.go index 1f23cf0293e6..11b365e1ee1b 100644 --- a/x/slashing/internal/keeper/querier.go +++ b/x/slashing/internal/keeper/querier.go @@ -76,7 +76,7 @@ func querySigningInfos(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte return false }) - start, end := client.Paginate(len(signingInfos), int(params.Page), int(params.Limit), int(k.sk.MaxValidators(ctx))) + start, end := client.Paginate(len(signingInfos), params.Page, params.Limit, int(k.sk.MaxValidators(ctx))) if start < 0 || end < 0 { signingInfos = []types.ValidatorSigningInfo{} } else { From e68f3f0a308bf2c85f70a4128b59fe9aa677670c Mon Sep 17 00:00:00 2001 From: anilCSE Date: Tue, 18 Feb 2020 19:53:34 +0530 Subject: [PATCH 45/52] - Rebase to cosmos:master - Bump types, keeper to root --- .github/CODEOWNERS | 11 +- CHANGELOG.md | 23 +- client/lcd/swagger-ui/swagger.yaml | 10 + docs/architecture/README.md | 1 + .../adr-019-protobuf-state-encoding.md | 248 +++ docs/architecture/adr-template.md | 2 +- docs/intro/overview.md | 4 +- go.mod | 2 +- go.sum | 7 +- simapp/app.go | 22 +- simapp/codec.go | 49 - simapp/codec/codec.go | 128 ++ simapp/codec/codec.pb.go | 1039 ++++++++++++ simapp/codec/codec.proto | 33 + simapp/export.go | 2 +- simapp/genesis.go | 6 +- simapp/sim_test.go | 2 +- simapp/utils_test.go | 3 +- types/errors/abci.go | 7 +- types/module/module.go | 31 +- types/rest/rest.go | 15 +- types/rest/rest_test.go | 7 + x/auth/alias.go | 11 +- x/auth/ante/basic.go | 8 +- x/auth/ante/sigverify.go | 10 +- x/auth/client/cli/query.go | 2 +- x/auth/client/cli/tx_multisign.go | 2 +- x/auth/client/cli/tx_sign.go | 2 +- x/auth/client/rest/query.go | 2 +- x/auth/client/tx.go | 22 +- x/auth/keeper/account.go | 20 +- x/auth/keeper/keeper.go | 36 +- x/auth/module.go | 16 +- x/auth/simulation/decoder.go | 2 + x/auth/simulation/genesis.go | 4 +- x/auth/types/account.go | 127 +- x/auth/types/account_retriever.go | 15 +- x/auth/types/account_retriever_test.go | 7 +- x/auth/types/account_test.go | 66 +- x/auth/types/codec.go | 37 +- x/auth/types/common_test.go | 11 + x/auth/types/errors.go | 8 +- x/auth/types/genesis.go | 5 +- x/auth/types/genesis_test.go | 36 +- x/auth/types/params.go | 34 +- x/auth/types/stdtx.go | 19 +- .../types/{test_common.go => test_utils.go} | 0 x/auth/types/types.pb.go | 1001 ++++++++++++ x/auth/types/types.proto | 49 + x/auth/vesting/alias.go | 11 +- x/auth/vesting/types/codec.go | 12 +- x/auth/vesting/types/common_test.go | 11 + x/auth/vesting/types/genesis_test.go | 4 +- x/auth/vesting/types/period.go | 13 +- x/auth/vesting/types/types.pb.go | 1404 +++++++++++++++++ x/auth/vesting/types/types.proto | 76 + x/auth/vesting/types/vesting_account.go | 118 +- x/auth/vesting/types/vesting_account_test.go | 273 ++-- x/bank/app_test.go | 2 +- x/bank/internal/keeper/keeper_test.go | 16 +- x/bank/internal/types/errors.go | 8 +- x/bank/module.go | 16 +- x/crisis/internal/types/codec.go | 38 +- x/crisis/internal/types/errors.go | 4 +- x/crisis/module.go | 16 +- x/distribution/alias.go | 2 - x/distribution/keeper/test_common.go | 9 +- x/distribution/module.go | 16 +- x/distribution/types/codec.go | 38 +- x/distribution/types/errors.go | 24 +- x/evidence/internal/types/errors.go | 8 +- x/evidence/module.go | 16 +- x/genutil/client/cli/gentx.go | 2 +- x/genutil/client/cli/init.go | 2 +- x/genutil/client/cli/validate_genesis.go | 2 +- x/genutil/module.go | 14 +- x/gov/genesis_test.go | 8 +- x/gov/keeper/test_common.go | 16 +- x/gov/module.go | 16 +- x/gov/types/errors.go | 16 +- x/mint/module.go | 16 +- x/params/module.go | 4 +- x/params/types/errors.go | 12 +- x/slashing/abci_test.go | 2 +- x/slashing/alias.go | 4 +- x/slashing/client/cli/query.go | 2 +- x/slashing/client/cli/tx.go | 2 +- x/slashing/client/rest/query.go | 2 +- x/slashing/client/rest/tx.go | 2 +- x/slashing/genesis.go | 2 +- x/slashing/handler.go | 2 +- x/slashing/handler_test.go | 4 +- x/slashing/{internal => }/keeper/hooks.go | 2 +- .../{internal => }/keeper/infractions.go | 2 +- x/slashing/{internal => }/keeper/keeper.go | 2 +- .../{internal => }/keeper/keeper_test.go | 2 +- x/slashing/{internal => }/keeper/params.go | 2 +- x/slashing/{internal => }/keeper/querier.go | 2 +- .../{internal => }/keeper/querier_test.go | 2 +- .../{internal => }/keeper/signing_info.go | 2 +- .../keeper/signing_info_test.go | 2 +- .../{internal => }/keeper/test_common.go | 12 +- x/slashing/{internal => }/keeper/unjail.go | 2 +- x/slashing/module.go | 16 +- x/slashing/simulation/decoder.go | 2 +- x/slashing/simulation/decoder_test.go | 2 +- x/slashing/simulation/genesis.go | 2 +- x/slashing/simulation/operations.go | 4 +- x/slashing/simulation/params.go | 2 +- x/slashing/{internal => }/types/codec.go | 0 x/slashing/{internal => }/types/errors.go | 14 +- x/slashing/{internal => }/types/events.go | 0 .../{internal => }/types/expected_keepers.go | 0 x/slashing/{internal => }/types/genesis.go | 0 x/slashing/{internal => }/types/keys.go | 0 x/slashing/{internal => }/types/msg.go | 0 x/slashing/{internal => }/types/msg_test.go | 0 x/slashing/{internal => }/types/params.go | 0 x/slashing/{internal => }/types/querier.go | 0 .../{internal => }/types/signing_info.go | 0 x/slashing/{internal => }/types/types.pb.go | 0 x/slashing/{internal => }/types/types.proto | 0 x/staking/alias.go | 2 - x/staking/keeper/test_common.go | 15 +- x/staking/module.go | 16 +- x/staking/types/codec.go | 39 +- x/staking/types/errors.go | 92 +- x/supply/alias.go | 13 +- x/supply/client/cli/query.go | 2 +- x/supply/client/rest/query.go | 2 +- x/supply/exported/exported.go | 9 +- x/supply/genesis.go | 2 +- x/supply/internal/keeper/integration_test.go | 35 - x/supply/internal/keeper/keeper_test.go | 38 - x/supply/internal/types/codec.go | 24 - x/supply/{internal => }/keeper/account.go | 2 +- x/supply/{internal => }/keeper/bank.go | 6 +- x/supply/{internal => }/keeper/bank_test.go | 66 +- x/supply/{internal => }/keeper/invariants.go | 2 +- x/supply/{internal => }/keeper/keeper.go | 36 +- x/supply/keeper/keeper_test.go | 55 + x/supply/{internal => }/keeper/key.go | 0 x/supply/{internal => }/keeper/querier.go | 2 +- .../{internal => }/keeper/querier_test.go | 13 +- x/supply/module.go | 18 +- x/supply/simulation/decoder.go | 5 +- x/supply/simulation/decoder_test.go | 4 +- x/supply/simulation/genesis.go | 2 +- x/supply/{internal => }/types/account.go | 21 +- x/supply/{internal => }/types/account_test.go | 6 +- x/supply/types/codec.go | 45 + .../{internal => }/types/expected_keepers.go | 0 x/supply/{internal => }/types/genesis.go | 0 x/supply/{internal => }/types/key.go | 0 x/supply/{internal => }/types/permissions.go | 0 .../{internal => }/types/permissions_test.go | 0 x/supply/{internal => }/types/querier.go | 0 x/supply/{internal => }/types/supply.go | 41 +- x/supply/{internal => }/types/supply_test.go | 2 +- x/supply/types/types.pb.go | 605 +++++++ x/supply/types/types.proto | 31 + x/upgrade/module.go | 10 +- 162 files changed, 5646 insertions(+), 1158 deletions(-) create mode 100644 docs/architecture/adr-019-protobuf-state-encoding.md delete mode 100644 simapp/codec.go create mode 100644 simapp/codec/codec.go create mode 100644 simapp/codec/codec.pb.go create mode 100644 simapp/codec/codec.proto create mode 100644 x/auth/types/common_test.go rename x/auth/types/{test_common.go => test_utils.go} (100%) create mode 100644 x/auth/types/types.pb.go create mode 100644 x/auth/types/types.proto create mode 100644 x/auth/vesting/types/common_test.go create mode 100644 x/auth/vesting/types/types.pb.go create mode 100644 x/auth/vesting/types/types.proto rename x/slashing/{internal => }/keeper/hooks.go (97%) rename x/slashing/{internal => }/keeper/infractions.go (98%) rename x/slashing/{internal => }/keeper/keeper.go (98%) rename x/slashing/{internal => }/keeper/keeper_test.go (99%) rename x/slashing/{internal => }/keeper/params.go (96%) rename x/slashing/{internal => }/keeper/querier.go (97%) rename x/slashing/{internal => }/keeper/querier_test.go (92%) rename x/slashing/{internal => }/keeper/signing_info.go (98%) rename x/slashing/{internal => }/keeper/signing_info_test.go (97%) rename x/slashing/{internal => }/keeper/test_common.go (93%) rename x/slashing/{internal => }/keeper/unjail.go (95%) rename x/slashing/{internal => }/types/codec.go (100%) rename x/slashing/{internal => }/types/errors.go (61%) rename x/slashing/{internal => }/types/events.go (100%) rename x/slashing/{internal => }/types/expected_keepers.go (100%) rename x/slashing/{internal => }/types/genesis.go (100%) rename x/slashing/{internal => }/types/keys.go (100%) rename x/slashing/{internal => }/types/msg.go (100%) rename x/slashing/{internal => }/types/msg_test.go (100%) rename x/slashing/{internal => }/types/params.go (100%) rename x/slashing/{internal => }/types/querier.go (100%) rename x/slashing/{internal => }/types/signing_info.go (100%) rename x/slashing/{internal => }/types/types.pb.go (100%) rename x/slashing/{internal => }/types/types.proto (100%) delete mode 100644 x/supply/internal/keeper/integration_test.go delete mode 100644 x/supply/internal/keeper/keeper_test.go delete mode 100644 x/supply/internal/types/codec.go rename x/supply/{internal => }/keeper/account.go (97%) rename x/supply/{internal => }/keeper/bank.go (97%) rename x/supply/{internal => }/keeper/bank_test.go (72%) rename x/supply/{internal => }/keeper/invariants.go (95%) rename x/supply/{internal => }/keeper/keeper.go (74%) create mode 100644 x/supply/keeper/keeper_test.go rename x/supply/{internal => }/keeper/key.go (100%) rename x/supply/{internal => }/keeper/querier.go (97%) rename x/supply/{internal => }/keeper/querier_test.go (89%) rename x/supply/{internal => }/types/account.go (85%) rename x/supply/{internal => }/types/account_test.go (99%) create mode 100644 x/supply/types/codec.go rename x/supply/{internal => }/types/expected_keepers.go (100%) rename x/supply/{internal => }/types/genesis.go (100%) rename x/supply/{internal => }/types/key.go (100%) rename x/supply/{internal => }/types/permissions.go (100%) rename x/supply/{internal => }/types/permissions_test.go (100%) rename x/supply/{internal => }/types/querier.go (100%) rename x/supply/{internal => }/types/supply.go (56%) rename x/supply/{internal => }/types/supply_test.go (94%) create mode 100644 x/supply/types/types.pb.go create mode 100644 x/supply/types/types.proto diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 1c7206ff75f8..ca82ba88da02 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,13 +1,4 @@ # CODEOWNERS: https://help.github.com/articles/about-codeowners/ # Primary repo maintainers -* @rigelrozanski @alexanderbez @jackzampolin @alessio @fedekunze - -############################################################################### -# Module Specific Ownership -# See CONTRIBUTING.md for further details -############################################################################### - -# The following contributors own all files in the x/nft directory at the root -# of the repository and any of its subdirectories. -x/nft @okwme @fedekunze +* @alexanderbez @jackzampolin @alessio @fedekunze diff --git a/CHANGELOG.md b/CHANGELOG.md index 99385df82259..0cb43bbda50c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,8 @@ flushed to disk or kept as a snapshot. Note, `KeepRecent` is automatically infer and provided directly the IAVL store. * (modules) [\#5555](https://github.com/cosmos/cosmos-sdk/pull/5555) Move x/auth/client/utils/ types and functions to x/auth/client/. * (modules) [\#5572](https://github.com/cosmos/cosmos-sdk/pull/5572) Move account balance logic and APIs from `x/auth` to `x/bank`. +* (types) [\#5533](https://github.com/cosmos/cosmos-sdk/pull/5533) Refactored `AppModuleBasic` and `AppModuleGenesis` +to now accept a `codec.JSONMarshaler` for modular serialization of genesis state. ### Bug Fixes @@ -72,7 +74,7 @@ and provided directly the IAVL store. * Callers to `NewBaseVestingAccount` are responsible for verifying account balance in relation to the original vesting amount. * The `SendKeeper` and `ViewKeeper` interfaces in `x/bank` have been modified to account for changes. -* (staking) [\#5600](https://github.com/cosmos/cosmos-sdk/pull/5600) Migrate the `x/staking` module to use Protocol Buffer for state +* (x/staking) [\#5600](https://github.com/cosmos/cosmos-sdk/pull/5600) Migrate the `x/staking` module to use Protocol Buffers for state serialization instead of Amino. The exact codec used is `codec.HybridCodec` which utilizes Protobuf for binary encoding and Amino for JSON encoding. * `BondStatus` is now of type `int32` instead of `byte`. @@ -86,6 +88,7 @@ for JSON encoding. * The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type provided is specified by `ModuleCdc`. * (distr) [\#5610](https://github.com/cosmos/cosmos-sdk/pull/5610) Migrate the `x/distribution` module to use Protocol Buffer for state +* (x/distribution) [\#5610](https://github.com/cosmos/cosmos-sdk/pull/5610) Migrate the `x/distribution` module to use Protocol Buffers for state serialization instead of Amino. The exact codec used is `codec.HybridCodec` which utilizes Protobuf for binary encoding and Amino for JSON encoding. * `ValidatorHistoricalRewards.ReferenceCount` is now of types `uint32` instead of `uint16`. @@ -94,6 +97,21 @@ for JSON encoding. * `ValidatorAccumulatedCommission` is now a struct with `commission`. * The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type provided is specified by `ModuleCdc`. +* (x/auth) [\#5533](https://github.com/cosmos/cosmos-sdk/pull/5533) Migrate the `x/auth` module to use Protocol Buffers for state +serialization instead of Amino. + * The `BaseAccount.PubKey` field is now represented as a Bech32 string instead of a `crypto.Pubkey`. + * `NewBaseAccountWithAddress` now returns a reference to a `BaseAccount`. + * The `x/auth` module now accepts a `Codec` interface which extends the `codec.Marshaler` interface by + requiring a concrete codec to know how to serialize accounts. + * The `AccountRetriever` type now accepts a `Codec` in its constructor in order to know how to + serialize accounts. +* (x/supply) [\#5533](https://github.com/cosmos/cosmos-sdk/pull/5533) Migrate the `x/supply` module to use Protocol Buffers for state +serialization instead of Amino. + * The `internal` sub-package has been removed in order to expose the types proto file. + * The `x/supply` module now accepts a `Codec` interface which extends the `codec.Marshaler` interface by + requiring a concrete codec to know how to serialize `SupplyI` types. + * The `SupplyI` interface has been modified to no longer return `SupplyI` on methods. Instead the + concrete type's receiver should modify the type. ### Improvements @@ -105,6 +123,9 @@ for JSON encoding. * (types) [\#5585](https://github.com/cosmos/cosmos-sdk/pull/5585) IBC additions: * `Coin` denomination max lenght has been increased to 32. * Added `CapabilityKey` alias for `StoreKey` to match IBC spec. +* (rest) [\#5648](https://github.com/cosmos/cosmos-sdk/pull/5648) Enhance /txs usability: + * Add `tx.minheight` key to filter transaction with an inclusive minimum block height + * Add `tx.maxheight` key to filter transaction with an inclusive maximum block height ## [v0.38.1] - 2020-02-11 diff --git a/client/lcd/swagger-ui/swagger.yaml b/client/lcd/swagger-ui/swagger.yaml index c802f42a8e92..0b246d4b466d 100644 --- a/client/lcd/swagger-ui/swagger.yaml +++ b/client/lcd/swagger-ui/swagger.yaml @@ -268,6 +268,16 @@ paths: description: Maximum number of items per page type: integer x-example: 1 + - in: query + name: tx.minheight + type: integer + description: "transactions on blocks with height greater or equal this value" + x-example: 25 + - in: query + name: tx.maxheight + type: integer + description: "transactions on blocks with height less than or equal this value" + x-example: 800000 responses: 200: description: All txs matching the provided events diff --git a/docs/architecture/README.md b/docs/architecture/README.md index afa60a75241a..09632c114eb6 100644 --- a/docs/architecture/README.md +++ b/docs/architecture/README.md @@ -43,3 +43,4 @@ Please add a entry below in your Pull Request for an ADR. - [ADR 016: Validator Consensus Key Rotation](./adr-016-validator-consensus-key-rotation.md) - [ADR 017: Historical Header Module](./adr-017-historical-header-module.md) - [ADR 018: Extendable Voting Periods](./adr-018-extendable-voting-period.md) +- [ADR 019: Protocol Buffer State Encoding](./adr-019-protobuf-state-encoding.md) diff --git a/docs/architecture/adr-019-protobuf-state-encoding.md b/docs/architecture/adr-019-protobuf-state-encoding.md new file mode 100644 index 000000000000..f43c53e8155c --- /dev/null +++ b/docs/architecture/adr-019-protobuf-state-encoding.md @@ -0,0 +1,248 @@ +# ADR 019: Protocol Buffer State Encoding + +## Changelog + +- 2020 Feb 15: Initial Draft + +## Status + +Accepted + +## Context + +Currently, the Cosmos SDK utilizes [go-amino](https://github.com/tendermint/go-amino/) for binary +and JSON object encoding over the wire bringing parity between logical objects and persistence objects. + +From the Amino docs: + +> Amino is an object encoding specification. It is a subset of Proto3 with an extension for interface +> support. See the [Proto3 spec](https://developers.google.com/protocol-buffers/docs/proto3) for more +> information on Proto3, which Amino is largely compatible with (but not with Proto2). +> +> The goal of the Amino encoding protocol is to bring parity into logic objects and persistence objects. + +Amino also aims to have the following goals (not a complete list): + +- Binary bytes must be decode-able with a schema. +- Schema must be upgradeable. +- The encoder and decoder logic must be reasonably simple. + +However, we believe that Amino does not fulfill these goals completely and does not fully meet the +needs of a truly flexible cross-language and multi-client compatible encoding protocol in the Cosmos SDK. +Namely, Amino has proven to be a big pain-point in regards to supporting object serialization across +clients written in various languages while providing virtually little in the way of true backwards +compatibility and upgradeability. Furthermore, through profiling and various benchmarks, Amino has +been shown to be an extremely large performance bottleneck in the Cosmos SDK 1. This is +largely reflected in the performance of simulations and application transaction throughput. + +Thus, we need to adopt an encoding protocol that meets the following criteria for state serialization: + +- Language agnostic +- Platform agnostic +- Rich client support and thriving ecosystem +- High performance +- Minimal encoded message size +- Codegen-based over reflection-based +- Supports backward and forward compatibility + +Note, migrating away from Amino should be viewed as a two-pronged approach, state and client encoding. +This ADR focuses on state serialization in the Cosmos SDK state machine. A corresponding ADR will be +made to address client-side encoding. + +## Decision + +We will adopt [Protocol Buffers](https://developers.google.com/protocol-buffers) for serializing +persisted structured data in the Cosmos SDK while providing a clean mechanism and developer UX for +applications wishing to continue to use Amino. We will provide this mechanism by updating modules to +accept a codec interface, `Marshaler`, instead of a concrete Amino codec. Furthermore, the Cosmos SDK +will provide three concrete implementations of the `Marshaler` interface: `AminoCodec`, `ProtoCodec`, +and `HybridCodec`. + +- `AminoCodec`: Uses Amino for both binary and JSON encoding. +- `ProtoCodec`: Uses Protobuf for or both binary and JSON encoding. +- `HybridCodec`: Uses Amino for JSON encoding and Protobuf for binary encoding. + +Until the client migration landscape is fully understood and designed, modules will use a `HybridCodec` +as the concrete codec it accepts and/or extends. This means that all client JSON encoding, including +genesis state, will still use Amino. The ultimate goal will be to replace Amino JSON encoding with +Protbuf encoding and thus have modules accept and/or extend `ProtoCodec`. + +### Module Design + +Modules that do not require the ability to work with and serialize interfaces, the path to Protobuf +migration is pretty straightforward. These modules are to simply migrate any existing types that +are encoded and persisted via their concrete Amino codec to Protobuf and have their keeper accept a +`Marshaler` that will be a `HybridCodec`. This migration is simple as things will just work as-is. + +Note, any business logic that needs to encode primitive types like `bool` or `int64` should use +[gogoprotobuf](https://github.com/gogo/protobuf) Value types. + +Example: + +```go + ts, err := gogotypes.TimestampProto(completionTime) + if err != nil { + // ... + } + + bz := cdc.MustMarshalBinaryLengthPrefixed(ts) +``` + +However, modules can vary greatly in purpose and design and so we must support the ability for modules +to be able to encode and work with interfaces (e.g. `Account` or `Content`). For these modules, they +must define their own codec interface that extends `Marshaler`. These specific interfaces are unique +to the module and will contain method contracts that know how to serialize the needed interfaces. + +Example: + +```go +// x/auth/types/codec.go + +type Codec interface { + codec.Marshaler + + MarshalAccount(acc exported.Account) ([]byte, error) + UnmarshalAccount(bz []byte) (exported.Account, error) + + MarshalAccountJSON(acc exported.Account) ([]byte, error) + UnmarshalAccountJSON(bz []byte) (exported.Account, error) +} +``` + +Note, concrete types implementing these interfaces can be defined outside the scope of the module +that defines the interface (e.g. `ModuleAccount` in `x/supply`). To handle these cases, a Protobuf +message must be defined at the application-level along with a single codec that will be passed to _all_ +modules using a `oneof` approach. + +Example: + +```protobuf +// app/codec/codec.proto + +import "third_party/proto/cosmos-proto/cosmos.proto"; +import "x/auth/types/types.proto"; +import "x/auth/vesting/types/types.proto"; +import "x/supply/types/types.proto"; + +message Account { + option (cosmos_proto.interface_type) = "*github.com/cosmos/cosmos-sdk/x/auth/exported.Account"; + + // sum defines a list of all acceptable concrete Account implementations. + oneof sum { + cosmos_sdk.x.auth.v1.BaseAccount base_account = 1; + cosmos_sdk.x.auth.vesting.v1.ContinuousVestingAccount continuous_vesting_account = 2; + cosmos_sdk.x.auth.vesting.v1.DelayedVestingAccount delayed_vesting_account = 3; + cosmos_sdk.x.auth.vesting.v1.PeriodicVestingAccount periodic_vesting_account = 4; + cosmos_sdk.x.supply.v1.ModuleAccount module_account = 5; + } + + // ... +} +``` + +```go +// app/codec/codec.go + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/x/auth" + "github.com/cosmos/cosmos-sdk/x/supply" + authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + // ... +) + +var ( + _ auth.Codec = (*Codec)(nil) + // ... +) + +type Codec struct { + codec.Marshaler + + + amino *codec.Codec +} + +func NewAppCodec(amino *codec.Codec) *Codec { + return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino} +} + +func (c *Codec) MarshalAccount(accI authexported.Account) ([]byte, error) { + acc := &Account{} + if err := acc.SetAccount(accI); err != nil { + return nil, err + } + + return c.Marshaler.MarshalBinaryLengthPrefixed(acc) +} + +func (c *Codec) UnmarshalAccount(bz []byte) (authexported.Account, error) { + acc := &Account{} + if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, acc); err != nil { + return nil, err + } + + return acc.GetAccount(), nil +} +``` + +Since the `Codec` implements `auth.Codec` (and all other required interfaces), it is passed to _all_ +the modules and satisfies all the interfaces. Now each module needing to work with interfaces will know +about all the required types. Note, the use of `interface_type` allows us to avoid a significant +amount of code boilerplate when implementing the `Codec`. + +A similar concept is to be applied for messages that contain interfaces fields. The module will +define a "base" concrete message type (e.g. `MsgSubmitProposalBase`) that the application-level codec +will extend via `oneof` (e.g. `MsgSubmitProposal`) that fulfills the required interface +(e.g. `MsgSubmitProposalI`). Note, however, the module's message handler must now switch on the +interface rather than the concrete type for this particular message. + +### Why Wasn't X Chosen Instead + +For a more complete comparison to alternative protocols, see [here](https://codeburst.io/json-vs-protocol-buffers-vs-flatbuffers-a4247f8bda6f). + +### Cap'n Proto + +While [Cap’n Proto](https://capnproto.org/) does seem like an advantageous alternative to Protobuf +due to it's native support for interfaces/generics and built in canonicalization, it does lack the +rich client ecosystem compared to Protobuf and is a bit less mature. + +### FlatBuffers + +[FlatBuffers](https://google.github.io/flatbuffers/) is also a potentially viable alternative, with the +primary difference being that FlatBuffers does not need a parsing/unpacking step to a secondary +representation before you can access data, often coupled with per-object memory allocation. + +However, it would require great efforts into research and full understanding the scope of the migration +and path forward -- which isn't immediately clear. In addition, FlatBuffers aren't designed for +untrusted inputs. + +## Future Improvements & Roadmap + +The landscape and roadmap to restructuring queriers and tx generation to fully support +Protobuf isn't fully understood yet. Once all modules are migrated, we will have a better +understanding on how to proceed with client improvements (e.g. gRPC) 2. + +## Consequences + +### Positive + +- Significant performance gains. +- Supports backward and forward type compatibility. +- Better support for cross-language clients. + +### Negative + +- Learning curve required to understand and implement Protobuf messages. +- Less flexibility in cross-module type registration. We now need to define types +at the application-level. +- Client business logic and tx generation may become a bit more complex. + +### Neutral + +{neutral consequences} + +## References + +1. https://github.com/cosmos/cosmos-sdk/issues/4977 +2. https://github.com/cosmos/cosmos-sdk/issues/5444 diff --git a/docs/architecture/adr-template.md b/docs/architecture/adr-template.md index 0638a71f4535..71b67a011c40 100644 --- a/docs/architecture/adr-template.md +++ b/docs/architecture/adr-template.md @@ -37,4 +37,4 @@ ## References -- {reference link} \ No newline at end of file +- {reference link} diff --git a/docs/intro/overview.md b/docs/intro/overview.md index f7e2242afcfa..b6f1ebce97c3 100644 --- a/docs/intro/overview.md +++ b/docs/intro/overview.md @@ -25,7 +25,7 @@ The Cosmos SDK is the most advanced framework for building custom application-sp - The default consensus engine available within the SDK is [Tendermint Core](https://github.com/tendermint/tendermint). Tendermint is the most (and only) mature BFT consensus engine in existence. It is widely used across the industry and is considered the gold standard consensus engine for building Proof-of-Stake systems. - The SDK is open source and designed to make it easy to build blockchains out of composable [modules](../../x/). As the ecosystem of open source SDK modules grows, it will become increasingly easier to build complex decentralised platforms with it. - The SDK is inspired by capabilities-based security, and informed by years of wrestling with blockchain state-machines. This makes the Cosmos SDK a very secure environment to build blockchains. -- Most importantly, the Cosmos SDK has already been used to build many application-specific blockchains that are already in production. Among others, we can cite [Cosmos Hub](https://hub.cosmos.network), [IRIS Hub](https://irisnet.org), [Binance Chain](https://docs.binance.org/), [Terra](https://terra.money/) or [Lino](https://lino.network/). [Many more](https://cosmos.network/ecosystem) are building on the Cosmos SDK. +- Most importantly, the Cosmos SDK has already been used to build many application-specific blockchains that are already in production. Among others, we can cite [Cosmos Hub](https://hub.cosmos.network), [IRIS Hub](https://irisnet.org), [Binance Chain](https://docs.binance.org/), [Terra](https://terra.money/) or [Kava](https://www.kava.io/). [Many more](https://cosmos.network/ecosystem) are building on the Cosmos SDK. ## Getting started with the Cosmos SDK @@ -34,4 +34,4 @@ The Cosmos SDK is the most advanced framework for building custom application-sp ## Next {hide} -Learn about [application-specific blockchains](./why-app-specific.md) {hide} \ No newline at end of file +Learn about [application-specific blockchains](./why-app-specific.md) {hide} diff --git a/go.mod b/go.mod index 47579d904e90..7d634c42c83b 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/pelletier/go-toml v1.6.0 github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.6 - github.com/regen-network/cosmos-proto v0.1.0 + github.com/regen-network/cosmos-proto v0.1.1-0.20200213154359-02baa11ea7c2 github.com/spf13/afero v1.2.1 // indirect github.com/spf13/cobra v0.0.5 github.com/spf13/jwalterweatherman v1.1.0 // indirect diff --git a/go.sum b/go.sum index 8177d91a3f08..1aa44bd73fe1 100644 --- a/go.sum +++ b/go.sum @@ -91,7 +91,6 @@ github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129/go.mod h1:sBzyDLLjw3 github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= @@ -196,8 +195,8 @@ github.com/rakyll/statik v0.1.6 h1:uICcfUXpgqtw2VopbIncslhAmE5hwc4g20TEyEENBNs= github.com/rakyll/statik v0.1.6/go.mod h1:OEi9wJV/fMUAGx1eNjq75DKDsJVuEv1U0oYdX6GX8Zs= github.com/rcrowley/go-metrics v0.0.0-20180503174638-e2704e165165 h1:nkcn14uNmFEuGCb2mBZbBb24RdNRL08b/wb+xBOYpuk= github.com/rcrowley/go-metrics v0.0.0-20180503174638-e2704e165165/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/regen-network/cosmos-proto v0.1.0 h1:gsV+YO2kMvY430zQn8ioPXRxEJgb/ms0iMPeWo3VEyY= -github.com/regen-network/cosmos-proto v0.1.0/go.mod h1:+r7jN10xXCypD4yBgzKOa+vgLz0riqYMHeDcKekxPvA= +github.com/regen-network/cosmos-proto v0.1.1-0.20200213154359-02baa11ea7c2 h1:jQK1YoH972Aptd22YKgtNu5jM2X2xMGkyIENOAc71to= +github.com/regen-network/cosmos-proto v0.1.1-0.20200213154359-02baa11ea7c2/go.mod h1:+r7jN10xXCypD4yBgzKOa+vgLz0riqYMHeDcKekxPvA= github.com/regen-network/protobuf v1.3.2-alpha.regen.1 h1:YdeZbBS0lG1D13COb7b57+nM/RGgIs8WF9DwitU6EBM= github.com/regen-network/protobuf v1.3.2-alpha.regen.1/go.mod h1:lye6mqhOn/GCw1zRl3uPD5VP8rC+LPMyTyPAyQV872U= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= @@ -253,7 +252,6 @@ github.com/tendermint/go-amino v0.15.1 h1:D2uk35eT4iTsvJd9jWIetzthE5C0/k2QmMFkCN github.com/tendermint/go-amino v0.15.1/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= github.com/tendermint/iavl v0.13.0 h1:r2sINvNFlJsLlLhGoqlqPlREWYkuK26BvMfkBt+XQnA= github.com/tendermint/iavl v0.13.0/go.mod h1:7nSUPdrsHEZ2nNZa+9gaIrcJciWd1jCQZXtcyARU82k= -github.com/tendermint/tendermint v0.33.0 h1:TW1g9sQs3YSqKM8o1+opL3/VmBy4Ke/VKV9MxYpqNbI= github.com/tendermint/tendermint v0.33.0/go.mod h1:s5UoymnPIY+GcA3mMte4P9gpMP8vS7UH7HBXikT1pHI= github.com/tendermint/tendermint v0.33.1 h1:8f68LUBz8yhISZvaLFP4siXXrLWsWeoYfelbdNtmvm4= github.com/tendermint/tendermint v0.33.1/go.mod h1:fBOKyrlXOETqQ+heL8x/TZgSdmItON54csyabvktBp0= @@ -341,7 +339,6 @@ google.golang.org/genproto v0.0.0-20200108215221-bd8f9a0ef82f/go.mod h1:n3cpQtvx google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk= google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= diff --git a/simapp/app.go b/simapp/app.go index b5b0460c3a42..33a5472ca523 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -11,6 +11,7 @@ import ( bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" @@ -78,7 +79,6 @@ var ( } ) -// Verify app interface at compile time var _ App = (*SimApp)(nil) // SimApp extends an ABCI application, but with most of its parameters exported. @@ -124,10 +124,10 @@ func NewSimApp( invCheckPeriod uint, baseAppOptions ...func(*bam.BaseApp), ) *SimApp { - appCodec := NewAppCodec() - // TODO: Remove cdc in favor of appCodec once all modules are migrated. - cdc := MakeCodec() + cdc := simappcodec.MakeCodec(ModuleBasics) + + appCodec := simappcodec.NewAppCodec(cdc) bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) @@ -150,7 +150,7 @@ func NewSimApp( } // init params keeper and subspaces - app.ParamsKeeper = params.NewKeeper(appCodec.Params, keys[params.StoreKey], tkeys[params.TStoreKey]) + app.ParamsKeeper = params.NewKeeper(appCodec, keys[params.StoreKey], tkeys[params.TStoreKey]) app.subspaces[auth.ModuleName] = app.ParamsKeeper.Subspace(auth.DefaultParamspace) app.subspaces[bank.ModuleName] = app.ParamsKeeper.Subspace(bank.DefaultParamspace) app.subspaces[staking.ModuleName] = app.ParamsKeeper.Subspace(staking.DefaultParamspace) @@ -163,27 +163,27 @@ func NewSimApp( // add keepers app.AccountKeeper = auth.NewAccountKeeper( - app.cdc, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount, + appCodec, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount, ) app.BankKeeper = bank.NewBaseKeeper( app.cdc, keys[bank.StoreKey], app.AccountKeeper, app.subspaces[bank.ModuleName], app.BlacklistedAccAddrs(), ) app.SupplyKeeper = supply.NewKeeper( - app.cdc, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms, + appCodec, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms, ) stakingKeeper := staking.NewKeeper( - appCodec.Staking, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName], + appCodec, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName], ) app.MintKeeper = mint.NewKeeper( app.cdc, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper, app.SupplyKeeper, auth.FeeCollectorName, ) app.DistrKeeper = distr.NewKeeper( - appCodec.Distribution, keys[distr.StoreKey], app.subspaces[distr.ModuleName], app.BankKeeper, &stakingKeeper, + appCodec, keys[distr.StoreKey], app.subspaces[distr.ModuleName], app.BankKeeper, &stakingKeeper, app.SupplyKeeper, auth.FeeCollectorName, app.ModuleAccountAddrs(), ) app.SlashingKeeper = slashing.NewKeeper( - appCodec.Slashing, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], + appCodec, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], ) app.CrisisKeeper = crisis.NewKeeper( app.subspaces[crisis.ModuleName], invCheckPeriod, app.SupplyKeeper, auth.FeeCollectorName, @@ -305,7 +305,7 @@ func (app *SimApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Re func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { var genesisState GenesisState app.cdc.MustUnmarshalJSON(req.AppStateBytes, &genesisState) - return app.mm.InitGenesis(ctx, genesisState) + return app.mm.InitGenesis(ctx, app.cdc, genesisState) } // LoadHeight loads a particular height diff --git a/simapp/codec.go b/simapp/codec.go deleted file mode 100644 index da1d7ac8233a..000000000000 --- a/simapp/codec.go +++ /dev/null @@ -1,49 +0,0 @@ -package simapp - -import ( - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/vesting" - distr "github.com/cosmos/cosmos-sdk/x/distribution" - "github.com/cosmos/cosmos-sdk/x/params" - "github.com/cosmos/cosmos-sdk/x/slashing" - "github.com/cosmos/cosmos-sdk/x/staking" -) - -// AppCodec defines the application-level codec. This codec contains all the -// required module-specific codecs that are to be provided upon initialization. -type AppCodec struct { - amino *codec.Codec - - Params *params.Codec - Slashing *slashing.Codec - Staking *staking.Codec - Distribution *distr.Codec -} - -func NewAppCodec() *AppCodec { - amino := MakeCodec() - - return &AppCodec{ - amino: amino, - Params: params.NewCodec(amino), - Staking: staking.NewCodec(amino), - Slashing: slashing.NewCodec(amino), - Distribution: distr.NewCodec(amino), - } -} - -// MakeCodec creates and returns a reference to an Amino codec that has all the -// necessary types and interfaces registered. This codec is provided to all the -// modules the application depends on. -// -// NOTE: This codec will be deprecated in favor of AppCodec once all modules are -// migrated. -func MakeCodec() *codec.Codec { - var cdc = codec.New() - ModuleBasics.RegisterCodec(cdc) - vesting.RegisterCodec(cdc) - sdk.RegisterCodec(cdc) - codec.RegisterCrypto(cdc) - return cdc -} diff --git a/simapp/codec/codec.go b/simapp/codec/codec.go new file mode 100644 index 000000000000..912bd355bc86 --- /dev/null +++ b/simapp/codec/codec.go @@ -0,0 +1,128 @@ +package codec + +import ( + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/auth" + authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" + "github.com/cosmos/cosmos-sdk/x/supply" + "github.com/cosmos/cosmos-sdk/x/supply/exported" +) + +var ( + _ auth.Codec = (*Codec)(nil) + _ supply.Codec = (*Codec)(nil) +) + +// Codec defines the application-level codec. This codec contains all the +// required module-specific codecs that are to be provided upon initialization. +type Codec struct { + codec.Marshaler + + // Keep reference to the amino codec to allow backwards compatibility along + // with type, and interface registration. + amino *codec.Codec +} + +func NewAppCodec(amino *codec.Codec) *Codec { + return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino} +} + +// MarshalAccount marshals an Account interface. If the given type implements +// the Marshaler interface, it is treated as a Proto-defined message and +// serialized that way. Otherwise, it falls back on the internal Amino codec. +func (c *Codec) MarshalAccount(accI authexported.Account) ([]byte, error) { + acc := &Account{} + if err := acc.SetAccount(accI); err != nil { + return nil, err + } + + return c.Marshaler.MarshalBinaryLengthPrefixed(acc) +} + +// UnmarshalAccount returns an Account interface from raw encoded account bytes +// of a Proto-based Account type. An error is returned upon decoding failure. +func (c *Codec) UnmarshalAccount(bz []byte) (authexported.Account, error) { + acc := &Account{} + if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, acc); err != nil { + return nil, err + } + + return acc.GetAccount(), nil +} + +// MarshalAccountJSON JSON encodes an account object implementing the Account +// interface. +func (c *Codec) MarshalAccountJSON(acc authexported.Account) ([]byte, error) { + return c.Marshaler.MarshalJSON(acc) +} + +// UnmarshalAccountJSON returns an Account from JSON encoded bytes. +func (c *Codec) UnmarshalAccountJSON(bz []byte) (authexported.Account, error) { + acc := &Account{} + if err := c.Marshaler.UnmarshalJSON(bz, acc); err != nil { + return nil, err + } + + return acc.GetAccount(), nil +} + +// MarshalSupply marshals a SupplyI interface. If the given type implements +// the Marshaler interface, it is treated as a Proto-defined message and +// serialized that way. Otherwise, it falls back on the internal Amino codec. +func (c *Codec) MarshalSupply(supplyI exported.SupplyI) ([]byte, error) { + supply := &Supply{} + if err := supply.SetSupplyI(supplyI); err != nil { + return nil, err + } + + return c.Marshaler.MarshalBinaryLengthPrefixed(supply) +} + +// UnmarshalSupply returns a SupplyI interface from raw encoded account bytes +// of a Proto-based SupplyI type. An error is returned upon decoding failure. +func (c *Codec) UnmarshalSupply(bz []byte) (exported.SupplyI, error) { + supply := &Supply{} + if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, supply); err != nil { + return nil, err + } + + return supply.GetSupplyI(), nil +} + +// MarshalSupplyJSON JSON encodes a supply object implementing the SupplyI +// interface. +func (c *Codec) MarshalSupplyJSON(supply exported.SupplyI) ([]byte, error) { + return c.Marshaler.MarshalJSON(supply) +} + +// UnmarshalSupplyJSON returns a SupplyI from JSON encoded bytes. +func (c *Codec) UnmarshalSupplyJSON(bz []byte) (exported.SupplyI, error) { + supply := &Supply{} + if err := c.Marshaler.UnmarshalJSON(bz, supply); err != nil { + return nil, err + } + + return supply.GetSupplyI(), nil +} + +// ---------------------------------------------------------------------------- + +// MakeCodec creates and returns a reference to an Amino codec that has all the +// necessary types and interfaces registered. This codec is provided to all the +// modules the application depends on. +// +// NOTE: This codec will be deprecated in favor of AppCodec once all modules are +// migrated. +func MakeCodec(bm module.BasicManager) *codec.Codec { + cdc := codec.New() + + bm.RegisterCodec(cdc) + vesting.RegisterCodec(cdc) + sdk.RegisterCodec(cdc) + codec.RegisterCrypto(cdc) + + return cdc +} diff --git a/simapp/codec/codec.pb.go b/simapp/codec/codec.pb.go new file mode 100644 index 000000000000..775948f5a35f --- /dev/null +++ b/simapp/codec/codec.pb.go @@ -0,0 +1,1039 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: simapp/codec/codec.proto + +package codec + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_x_auth_exported "github.com/cosmos/cosmos-sdk/x/auth/exported" + types "github.com/cosmos/cosmos-sdk/x/auth/types" + types1 "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + github_com_cosmos_cosmos_sdk_x_supply_exported "github.com/cosmos/cosmos-sdk/x/supply/exported" + types2 "github.com/cosmos/cosmos-sdk/x/supply/types" + proto "github.com/gogo/protobuf/proto" + _ "github.com/regen-network/cosmos-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 + +// Account defines the application-level Account type. +type Account struct { + // sum defines a list of all acceptable concrete Account implementations. + // + // Types that are valid to be assigned to Sum: + // *Account_BaseAccount + // *Account_ContinuousVestingAccount + // *Account_DelayedVestingAccount + // *Account_PeriodicVestingAccount + // *Account_ModuleAccount + Sum isAccount_Sum `protobuf_oneof:"sum"` +} + +func (m *Account) Reset() { *m = Account{} } +func (m *Account) String() string { return proto.CompactTextString(m) } +func (*Account) ProtoMessage() {} +func (*Account) Descriptor() ([]byte, []int) { + return fileDescriptor_3c6d4085e4065f5a, []int{0} +} +func (m *Account) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Account) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Account.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 *Account) XXX_Merge(src proto.Message) { + xxx_messageInfo_Account.Merge(m, src) +} +func (m *Account) XXX_Size() int { + return m.Size() +} +func (m *Account) XXX_DiscardUnknown() { + xxx_messageInfo_Account.DiscardUnknown(m) +} + +var xxx_messageInfo_Account proto.InternalMessageInfo + +type isAccount_Sum interface { + isAccount_Sum() + MarshalTo([]byte) (int, error) + Size() int +} + +type Account_BaseAccount struct { + BaseAccount *types.BaseAccount `protobuf:"bytes,1,opt,name=base_account,json=baseAccount,proto3,oneof" json:"base_account,omitempty"` +} +type Account_ContinuousVestingAccount struct { + ContinuousVestingAccount *types1.ContinuousVestingAccount `protobuf:"bytes,2,opt,name=continuous_vesting_account,json=continuousVestingAccount,proto3,oneof" json:"continuous_vesting_account,omitempty"` +} +type Account_DelayedVestingAccount struct { + DelayedVestingAccount *types1.DelayedVestingAccount `protobuf:"bytes,3,opt,name=delayed_vesting_account,json=delayedVestingAccount,proto3,oneof" json:"delayed_vesting_account,omitempty"` +} +type Account_PeriodicVestingAccount struct { + PeriodicVestingAccount *types1.PeriodicVestingAccount `protobuf:"bytes,4,opt,name=periodic_vesting_account,json=periodicVestingAccount,proto3,oneof" json:"periodic_vesting_account,omitempty"` +} +type Account_ModuleAccount struct { + ModuleAccount *types2.ModuleAccount `protobuf:"bytes,5,opt,name=module_account,json=moduleAccount,proto3,oneof" json:"module_account,omitempty"` +} + +func (*Account_BaseAccount) isAccount_Sum() {} +func (*Account_ContinuousVestingAccount) isAccount_Sum() {} +func (*Account_DelayedVestingAccount) isAccount_Sum() {} +func (*Account_PeriodicVestingAccount) isAccount_Sum() {} +func (*Account_ModuleAccount) isAccount_Sum() {} + +func (m *Account) GetSum() isAccount_Sum { + if m != nil { + return m.Sum + } + return nil +} + +func (m *Account) GetBaseAccount() *types.BaseAccount { + if x, ok := m.GetSum().(*Account_BaseAccount); ok { + return x.BaseAccount + } + return nil +} + +func (m *Account) GetContinuousVestingAccount() *types1.ContinuousVestingAccount { + if x, ok := m.GetSum().(*Account_ContinuousVestingAccount); ok { + return x.ContinuousVestingAccount + } + return nil +} + +func (m *Account) GetDelayedVestingAccount() *types1.DelayedVestingAccount { + if x, ok := m.GetSum().(*Account_DelayedVestingAccount); ok { + return x.DelayedVestingAccount + } + return nil +} + +func (m *Account) GetPeriodicVestingAccount() *types1.PeriodicVestingAccount { + if x, ok := m.GetSum().(*Account_PeriodicVestingAccount); ok { + return x.PeriodicVestingAccount + } + return nil +} + +func (m *Account) GetModuleAccount() *types2.ModuleAccount { + if x, ok := m.GetSum().(*Account_ModuleAccount); ok { + return x.ModuleAccount + } + return nil +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*Account) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*Account_BaseAccount)(nil), + (*Account_ContinuousVestingAccount)(nil), + (*Account_DelayedVestingAccount)(nil), + (*Account_PeriodicVestingAccount)(nil), + (*Account_ModuleAccount)(nil), + } +} + +// Supply defines the application-level Supply type. +type Supply struct { + // sum defines a list of all acceptable concrete Supply implementations. + // + // Types that are valid to be assigned to Sum: + // *Supply_Supply + Sum isSupply_Sum `protobuf_oneof:"sum"` +} + +func (m *Supply) Reset() { *m = Supply{} } +func (m *Supply) String() string { return proto.CompactTextString(m) } +func (*Supply) ProtoMessage() {} +func (*Supply) Descriptor() ([]byte, []int) { + return fileDescriptor_3c6d4085e4065f5a, []int{1} +} +func (m *Supply) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Supply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Supply.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 *Supply) XXX_Merge(src proto.Message) { + xxx_messageInfo_Supply.Merge(m, src) +} +func (m *Supply) XXX_Size() int { + return m.Size() +} +func (m *Supply) XXX_DiscardUnknown() { + xxx_messageInfo_Supply.DiscardUnknown(m) +} + +var xxx_messageInfo_Supply proto.InternalMessageInfo + +type isSupply_Sum interface { + isSupply_Sum() + MarshalTo([]byte) (int, error) + Size() int +} + +type Supply_Supply struct { + Supply *types2.Supply `protobuf:"bytes,1,opt,name=supply,proto3,oneof" json:"supply,omitempty"` +} + +func (*Supply_Supply) isSupply_Sum() {} + +func (m *Supply) GetSum() isSupply_Sum { + if m != nil { + return m.Sum + } + return nil +} + +func (m *Supply) GetSupply() *types2.Supply { + if x, ok := m.GetSum().(*Supply_Supply); ok { + return x.Supply + } + return nil +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*Supply) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*Supply_Supply)(nil), + } +} + +func init() { + proto.RegisterType((*Account)(nil), "cosmos_sdk.simapp.codec.v1.Account") + proto.RegisterType((*Supply)(nil), "cosmos_sdk.simapp.codec.v1.Supply") +} + +func init() { proto.RegisterFile("simapp/codec/codec.proto", fileDescriptor_3c6d4085e4065f5a) } + +var fileDescriptor_3c6d4085e4065f5a = []byte{ + // 444 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x93, 0x4f, 0x8b, 0xd3, 0x40, + 0x18, 0xc6, 0x13, 0x77, 0xb7, 0xc2, 0xac, 0x7a, 0x08, 0xa8, 0x21, 0x87, 0xb0, 0x2e, 0x08, 0xfe, + 0xa1, 0x13, 0xd6, 0xf5, 0xef, 0x7a, 0xb2, 0x15, 0xa9, 0x07, 0x45, 0x2a, 0x78, 0xf0, 0x12, 0x92, + 0x99, 0xa1, 0x0d, 0x6d, 0x32, 0x43, 0x66, 0x26, 0x24, 0x5f, 0xc0, 0xb3, 0x1f, 0xa6, 0x47, 0x3f, + 0x80, 0xf4, 0xd4, 0xa3, 0x47, 0x69, 0xbf, 0x88, 0x74, 0x66, 0x6c, 0x22, 0x49, 0xeb, 0x25, 0xf0, + 0xce, 0xf3, 0xbc, 0xcf, 0xef, 0x0d, 0xf3, 0x0e, 0x70, 0x79, 0x92, 0x46, 0x8c, 0x05, 0x88, 0x62, + 0x82, 0xf4, 0x17, 0xb2, 0x9c, 0x0a, 0xea, 0x78, 0x88, 0xf2, 0x94, 0xf2, 0x90, 0xe3, 0x19, 0xd4, + 0x26, 0xa8, 0xe5, 0xe2, 0xc2, 0x7b, 0x2c, 0xa6, 0x49, 0x8e, 0x43, 0x16, 0xe5, 0xa2, 0x0a, 0x94, + 0x3d, 0xd0, 0xee, 0x7e, 0xb3, 0xd0, 0x41, 0x9e, 0x5b, 0x06, 0x91, 0x14, 0xd3, 0x40, 0x54, 0x8c, + 0x70, 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24, 0x11, 0x53, 0x19, 0x43, 0x44, 0x53, 0xb3, 0x72, 0x7f, + 0xd7, 0x90, 0xe3, 0x59, 0x60, 0x96, 0x8b, 0x94, 0x8c, 0xe6, 0x82, 0x60, 0x68, 0x5a, 0x07, 0x27, + 0xe0, 0x88, 0xcb, 0xf4, 0xfc, 0x9b, 0x0d, 0x7a, 0x9f, 0x15, 0xce, 0x79, 0x09, 0x7a, 0x1a, 0x6c, + 0xf6, 0xc6, 0xdf, 0x37, 0x94, 0xf6, 0x8f, 0xac, 0xb1, 0xf1, 0x5f, 0xbd, 0x5e, 0x2e, 0xfa, 0x2f, + 0xfe, 0x37, 0x86, 0xd9, 0xe0, 0xdd, 0x20, 0x3a, 0xe5, 0xbd, 0x19, 0x64, 0x30, 0xfc, 0xb9, 0xf6, + 0xed, 0xd5, 0xda, 0xb7, 0x7f, 0xaf, 0x7d, 0xfb, 0xfb, 0xc6, 0xb7, 0x56, 0x1b, 0xdf, 0xfa, 0xb5, + 0xf1, 0xad, 0xaf, 0x0f, 0x0f, 0x06, 0x37, 0x5f, 0x6e, 0xdc, 0x53, 0x6f, 0xe2, 0xf2, 0x4f, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xdc, 0xbb, 0x4f, 0xcf, 0xd0, 0x03, 0x00, 0x00, +} + +func (this *Account) GetAccount() github_com_cosmos_cosmos_sdk_x_auth_exported.Account { + if x := this.GetBaseAccount(); x != nil { + return x + } + if x := this.GetContinuousVestingAccount(); x != nil { + return x + } + if x := this.GetDelayedVestingAccount(); x != nil { + return x + } + if x := this.GetPeriodicVestingAccount(); x != nil { + return x + } + if x := this.GetModuleAccount(); x != nil { + return x + } + return nil +} + +func (this *Account) SetAccount(value github_com_cosmos_cosmos_sdk_x_auth_exported.Account) error { + if value == nil { + this.Sum = nil + return nil + } + switch vt := value.(type) { + case *types.BaseAccount: + this.Sum = &Account_BaseAccount{vt} + return nil + case *types1.ContinuousVestingAccount: + this.Sum = &Account_ContinuousVestingAccount{vt} + return nil + case *types1.DelayedVestingAccount: + this.Sum = &Account_DelayedVestingAccount{vt} + return nil + case *types1.PeriodicVestingAccount: + this.Sum = &Account_PeriodicVestingAccount{vt} + return nil + case *types2.ModuleAccount: + this.Sum = &Account_ModuleAccount{vt} + return nil + } + return fmt.Errorf("can't encode value of type %T as message Account", value) +} + +func (this *Supply) GetSupplyI() github_com_cosmos_cosmos_sdk_x_supply_exported.SupplyI { + if x := this.GetSupply(); x != nil { + return x + } + return nil +} + +func (this *Supply) SetSupplyI(value github_com_cosmos_cosmos_sdk_x_supply_exported.SupplyI) error { + if value == nil { + this.Sum = nil + return nil + } + switch vt := value.(type) { + case *types2.Supply: + this.Sum = &Supply_Supply{vt} + return nil + } + return fmt.Errorf("can't encode value of type %T as message Supply", value) +} + +func (m *Account) 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 *Account) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Account) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sum != nil { + { + size := m.Sum.Size() + i -= size + if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } + return len(dAtA) - i, nil +} + +func (m *Account_BaseAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Account_BaseAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.BaseAccount != nil { + { + size, err := m.BaseAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} +func (m *Account_ContinuousVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Account_ContinuousVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.ContinuousVestingAccount != nil { + { + size, err := m.ContinuousVestingAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + return len(dAtA) - i, nil +} +func (m *Account_DelayedVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Account_DelayedVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.DelayedVestingAccount != nil { + { + size, err := m.DelayedVestingAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + return len(dAtA) - i, nil +} +func (m *Account_PeriodicVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Account_PeriodicVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.PeriodicVestingAccount != nil { + { + size, err := m.PeriodicVestingAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + return len(dAtA) - i, nil +} +func (m *Account_ModuleAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Account_ModuleAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.ModuleAccount != nil { + { + size, err := m.ModuleAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + return len(dAtA) - i, nil +} +func (m *Supply) 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 *Supply) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Supply) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sum != nil { + { + size := m.Sum.Size() + i -= size + if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } + return len(dAtA) - i, nil +} + +func (m *Supply_Supply) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Supply_Supply) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Supply != nil { + { + size, err := m.Supply.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} +func encodeVarintCodec(dAtA []byte, offset int, v uint64) int { + offset -= sovCodec(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Account) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sum != nil { + n += m.Sum.Size() + } + return n +} + +func (m *Account_BaseAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BaseAccount != nil { + l = m.BaseAccount.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *Account_ContinuousVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ContinuousVestingAccount != nil { + l = m.ContinuousVestingAccount.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *Account_DelayedVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.DelayedVestingAccount != nil { + l = m.DelayedVestingAccount.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *Account_PeriodicVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PeriodicVestingAccount != nil { + l = m.PeriodicVestingAccount.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *Account_ModuleAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ModuleAccount != nil { + l = m.ModuleAccount.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *Supply) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sum != nil { + n += m.Sum.Size() + } + return n +} + +func (m *Supply_Supply) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Supply != nil { + l = m.Supply.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} + +func sovCodec(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozCodec(x uint64) (n int) { + return sovCodec(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Account) 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 ErrIntOverflowCodec + } + 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: Account: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Account: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCodec + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCodec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &types.BaseAccount{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Account_BaseAccount{v} + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ContinuousVestingAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCodec + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCodec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &types1.ContinuousVestingAccount{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Account_ContinuousVestingAccount{v} + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelayedVestingAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCodec + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCodec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &types1.DelayedVestingAccount{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Account_DelayedVestingAccount{v} + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PeriodicVestingAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCodec + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCodec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &types1.PeriodicVestingAccount{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Account_PeriodicVestingAccount{v} + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ModuleAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCodec + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCodec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &types2.ModuleAccount{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Account_ModuleAccount{v} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCodec(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCodec + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCodec + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Supply) 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 ErrIntOverflowCodec + } + 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: Supply: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Supply: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Supply", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCodec + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCodec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &types2.Supply{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Supply_Supply{v} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCodec(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCodec + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCodec + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipCodec(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, ErrIntOverflowCodec + } + 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, ErrIntOverflowCodec + } + 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, ErrIntOverflowCodec + } + 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, ErrInvalidLengthCodec + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupCodec + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthCodec + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowCodec = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupCodec = fmt.Errorf("proto: unexpected end of group") +) diff --git a/simapp/codec/codec.proto b/simapp/codec/codec.proto new file mode 100644 index 000000000000..811e65d514b8 --- /dev/null +++ b/simapp/codec/codec.proto @@ -0,0 +1,33 @@ +syntax = "proto3"; +package cosmos_sdk.simapp.codec.v1; + +import "third_party/proto/cosmos-proto/cosmos.proto"; +import "x/auth/types/types.proto"; +import "x/auth/vesting/types/types.proto"; +import "x/supply/types/types.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/simapp/codec"; + +// Account defines the application-level Account type. +message Account { + option (cosmos_proto.interface_type) = "*github.com/cosmos/cosmos-sdk/x/auth/exported.Account"; + + // sum defines a list of all acceptable concrete Account implementations. + oneof sum { + cosmos_sdk.x.auth.v1.BaseAccount base_account = 1; + cosmos_sdk.x.auth.vesting.v1.ContinuousVestingAccount continuous_vesting_account = 2; + cosmos_sdk.x.auth.vesting.v1.DelayedVestingAccount delayed_vesting_account = 3; + cosmos_sdk.x.auth.vesting.v1.PeriodicVestingAccount periodic_vesting_account = 4; + cosmos_sdk.x.supply.v1.ModuleAccount module_account = 5; + } +} + +// Supply defines the application-level Supply type. +message Supply { + option (cosmos_proto.interface_type) = "*github.com/cosmos/cosmos-sdk/x/supply/exported.SupplyI"; + + // sum defines a list of all acceptable concrete Supply implementations. + oneof sum { + cosmos_sdk.x.supply.v1.Supply supply = 1; + } +} diff --git a/simapp/export.go b/simapp/export.go index 39cf18586f10..23a23527921d 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -27,7 +27,7 @@ func (app *SimApp) ExportAppStateAndValidators( app.prepForZeroHeightGenesis(ctx, jailWhiteList) } - genState := app.mm.ExportGenesis(ctx) + genState := app.mm.ExportGenesis(ctx, app.cdc) appState, err = codec.MarshalJSONIndent(app.cdc, genState) if err != nil { return nil, nil, err diff --git a/simapp/genesis.go b/simapp/genesis.go index d96c6feec954..1a760e3e49a6 100644 --- a/simapp/genesis.go +++ b/simapp/genesis.go @@ -2,6 +2,8 @@ package simapp import ( "encoding/json" + + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" ) // The genesis state of the blockchain is represented here as a map of raw json @@ -15,5 +17,7 @@ type GenesisState map[string]json.RawMessage // NewDefaultGenesisState generates the default state for the application. func NewDefaultGenesisState() GenesisState { - return ModuleBasics.DefaultGenesis() + cdc := simappcodec.MakeCodec(ModuleBasics) + + return ModuleBasics.DefaultGenesis(cdc) } diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 3d41fa3b8467..e10afad8a4a1 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -137,7 +137,7 @@ func TestAppImportExport(t *testing.T) { ctxA := app.NewContext(true, abci.Header{Height: app.LastBlockHeight()}) ctxB := newApp.NewContext(true, abci.Header{Height: app.LastBlockHeight()}) - newApp.mm.InitGenesis(ctxB, genesisState) + newApp.mm.InitGenesis(ctxB, app.Codec(), genesisState) fmt.Printf("comparing stores...\n") diff --git a/simapp/utils_test.go b/simapp/utils_test.go index 9cadfff0da40..b6d5fa1f358a 100644 --- a/simapp/utils_test.go +++ b/simapp/utils_test.go @@ -8,12 +8,13 @@ import ( tmkv "github.com/tendermint/tendermint/libs/kv" "github.com/cosmos/cosmos-sdk/codec" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" ) func TestGetSimulationLog(t *testing.T) { - cdc := MakeCodec() + cdc := simappcodec.MakeCodec(ModuleBasics) decoders := make(sdk.StoreDecoderRegistry) decoders[auth.StoreKey] = func(cdc *codec.Codec, kvAs, kvBs tmkv.Pair) string { return "10" } diff --git a/types/errors/abci.go b/types/errors/abci.go index cc5633543192..04ba8413d374 100644 --- a/types/errors/abci.go +++ b/types/errors/abci.go @@ -154,10 +154,9 @@ func errIsNil(err error) bool { return false } -// Redact replace all errors that do not initialize with a weave error with a -// generic internal error instance. This function is supposed to hide -// implementation details errors and leave only those that weave framework -// originates. +// Redact replaces an error that is not initialized as an ABCI Error with a +// generic internal error instance. If the error is an ABCI Error, that error is +// simply returned. func Redact(err error) error { if ErrPanic.Is(err) { return errors.New(internalABCILog) diff --git a/types/module/module.go b/types/module/module.go index 924c99834250..0b1633e3cd24 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -48,9 +48,8 @@ type AppModuleBasic interface { Name() string RegisterCodec(*codec.Codec) - // genesis - DefaultGenesis() json.RawMessage - ValidateGenesis(json.RawMessage) error + DefaultGenesis(codec.JSONMarshaler) json.RawMessage + ValidateGenesis(codec.JSONMarshaler, json.RawMessage) error // client functionality RegisterRESTRoutes(context.CLIContext, *mux.Router) @@ -78,21 +77,23 @@ func (bm BasicManager) RegisterCodec(cdc *codec.Codec) { } // DefaultGenesis provides default genesis information for all modules -func (bm BasicManager) DefaultGenesis() map[string]json.RawMessage { +func (bm BasicManager) DefaultGenesis(cdc codec.JSONMarshaler) map[string]json.RawMessage { genesis := make(map[string]json.RawMessage) for _, b := range bm { - genesis[b.Name()] = b.DefaultGenesis() + genesis[b.Name()] = b.DefaultGenesis(cdc) } + return genesis } // ValidateGenesis performs genesis state validation for all modules -func (bm BasicManager) ValidateGenesis(genesis map[string]json.RawMessage) error { +func (bm BasicManager) ValidateGenesis(cdc codec.JSONMarshaler, genesis map[string]json.RawMessage) error { for _, b := range bm { - if err := b.ValidateGenesis(genesis[b.Name()]); err != nil { + if err := b.ValidateGenesis(cdc, genesis[b.Name()]); err != nil { return err } } + return nil } @@ -126,8 +127,9 @@ func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command, cdc *codec. // AppModuleGenesis is the standard form for an application module genesis functions type AppModuleGenesis interface { AppModuleBasic - InitGenesis(sdk.Context, json.RawMessage) []abci.ValidatorUpdate - ExportGenesis(sdk.Context) json.RawMessage + + InitGenesis(sdk.Context, codec.JSONMarshaler, json.RawMessage) []abci.ValidatorUpdate + ExportGenesis(sdk.Context, codec.JSONMarshaler) json.RawMessage } // AppModule is the standard form for an application module @@ -256,13 +258,14 @@ func (m *Manager) RegisterRoutes(router sdk.Router, queryRouter sdk.QueryRouter) } // InitGenesis performs init genesis functionality for modules -func (m *Manager) InitGenesis(ctx sdk.Context, genesisData map[string]json.RawMessage) abci.ResponseInitChain { +func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, genesisData map[string]json.RawMessage) abci.ResponseInitChain { var validatorUpdates []abci.ValidatorUpdate for _, moduleName := range m.OrderInitGenesis { if genesisData[moduleName] == nil { continue } - moduleValUpdates := m.Modules[moduleName].InitGenesis(ctx, genesisData[moduleName]) + + moduleValUpdates := m.Modules[moduleName].InitGenesis(ctx, cdc, genesisData[moduleName]) // use these validator updates if provided, the module manager assumes // only one module will update the validator set @@ -273,17 +276,19 @@ func (m *Manager) InitGenesis(ctx sdk.Context, genesisData map[string]json.RawMe validatorUpdates = moduleValUpdates } } + return abci.ResponseInitChain{ Validators: validatorUpdates, } } // ExportGenesis performs export genesis functionality for modules -func (m *Manager) ExportGenesis(ctx sdk.Context) map[string]json.RawMessage { +func (m *Manager) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) map[string]json.RawMessage { genesisData := make(map[string]json.RawMessage) for _, moduleName := range m.OrderExportGenesis { - genesisData[moduleName] = m.Modules[moduleName].ExportGenesis(ctx) + genesisData[moduleName] = m.Modules[moduleName].ExportGenesis(ctx, cdc) } + return genesisData } diff --git a/types/rest/rest.go b/types/rest/rest.go index a58a56252553..a6339097e765 100644 --- a/types/rest/rest.go +++ b/types/rest/rest.go @@ -20,8 +20,10 @@ import ( ) const ( - DefaultPage = 1 - DefaultLimit = 30 // should be consistent with tendermint/tendermint/rpc/core/pipe.go:19 + DefaultPage = 1 + DefaultLimit = 30 // should be consistent with tendermint/tendermint/rpc/core/pipe.go:19 + TxMinHeightKey = "tx.minheight" // Inclusive minimum height filter + TxMaxHeightKey = "tx.maxheight" // Inclusive maximum height filter ) // ResponseWithHeight defines a response object type that wraps an original @@ -335,9 +337,14 @@ func ParseHTTPArgsWithLimit(r *http.Request, defaultLimit int) (tags []string, p } var tag string - if key == types.TxHeightKey { + switch key { + case types.TxHeightKey: tag = fmt.Sprintf("%s=%s", key, value) - } else { + case TxMinHeightKey: + tag = fmt.Sprintf("%s>=%s", types.TxHeightKey, value) + case TxMaxHeightKey: + tag = fmt.Sprintf("%s<=%s", types.TxHeightKey, value) + default: tag = fmt.Sprintf("%s='%s'", key, value) } tags = append(tags, tag) diff --git a/types/rest/rest_test.go b/types/rest/rest_test.go index 4c283a90e260..6088569c8f09 100644 --- a/types/rest/rest_test.go +++ b/types/rest/rest_test.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "net/http" "net/http/httptest" + "sort" "testing" "github.com/stretchr/testify/require" @@ -71,6 +72,8 @@ func TestParseHTTPArgs(t *testing.T) { reqE2 := mustNewRequest(t, "", "/?limit=-1", nil) req4 := mustNewRequest(t, "", "/?foo=faa", nil) + reqTxH := mustNewRequest(t, "", "/?tx.minheight=12&tx.maxheight=14", nil) + tests := []struct { name string req *http.Request @@ -89,11 +92,15 @@ func TestParseHTTPArgs(t *testing.T) { {"error limit 0", reqE2, httptest.NewRecorder(), []string{}, DefaultPage, DefaultLimit, true}, {"tags", req4, httptest.NewRecorder(), []string{"foo='faa'"}, DefaultPage, DefaultLimit, false}, + {"tags", reqTxH, httptest.NewRecorder(), []string{"tx.height<=14", "tx.height>=12"}, DefaultPage, DefaultLimit, false}, } for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { tags, page, limit, err := ParseHTTPArgs(tt.req) + + sort.Strings(tags) + if tt.err { require.NotNil(t, err) } else { diff --git a/x/auth/alias.go b/x/auth/alias.go index 01b20a68f3d7..b5d5516352e6 100644 --- a/x/auth/alias.go +++ b/x/auth/alias.go @@ -1,9 +1,3 @@ -// nolint -// autogenerated code using github.com/rigelrozanski/multitool -// aliases generated for the following subdirectories: -// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/ante -// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/keeper -// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/types package auth import ( @@ -12,6 +6,9 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/types" ) +// DONTCOVER +// nolint + const ( ModuleName = types.ModuleName StoreKey = types.StoreKey @@ -40,7 +37,6 @@ var ( NewBaseAccountWithAddress = types.NewBaseAccountWithAddress NewAccountRetriever = types.NewAccountRetriever RegisterCodec = types.RegisterCodec - RegisterAccountTypeCodec = types.RegisterAccountTypeCodec NewGenesisState = types.NewGenesisState DefaultGenesisState = types.DefaultGenesisState ValidateGenesis = types.ValidateGenesis @@ -89,4 +85,5 @@ type ( StdSignature = types.StdSignature TxBuilder = types.TxBuilder GenesisAccountIterator = types.GenesisAccountIterator + Codec = types.Codec ) diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 0e999a9d4781..05e570ca2854 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -1,6 +1,7 @@ package ante import ( + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" err "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -112,21 +113,24 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim if sigs[i] != nil { continue } - acc := cgts.ak.GetAccount(ctx, signer) var pubkey crypto.PubKey + acc := cgts.ak.GetAccount(ctx, signer) + // use placeholder simSecp256k1Pubkey if sig is nil if acc == nil || acc.GetPubKey() == nil { pubkey = simSecp256k1Pubkey } else { pubkey = acc.GetPubKey() } + // use stdsignature to mock the size of a full signature simSig := types.StdSignature{ Signature: simSecp256k1Sig[:], PubKey: pubkey, } - sigBz := types.ModuleCdc.MustMarshalBinaryLengthPrefixed(simSig) + + sigBz := codec.Cdc.MustMarshalBinaryLengthPrefixed(simSig) cost := sdk.Gas(len(sigBz) + 6) // If the pubkey is a multi-signature pubkey, then we estimate for the maximum diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 4498b432d73d..895be5373c61 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -299,6 +299,7 @@ func (vscd ValidateSigCountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim func DefaultSigVerificationGasConsumer( meter sdk.GasMeter, sig []byte, pubkey crypto.PubKey, params types.Params, ) error { + switch pubkey := pubkey.(type) { case ed25519.PubKeyEd25519: meter.ConsumeGas(params.SigVerifyCostED25519, "ante verify: ed25519") @@ -321,11 +322,13 @@ func DefaultSigVerificationGasConsumer( } // ConsumeMultisignatureVerificationGas consumes gas from a GasMeter for verifying a multisig pubkey signature -func ConsumeMultisignatureVerificationGas(meter sdk.GasMeter, - sig multisig.Multisignature, pubkey multisig.PubKeyMultisigThreshold, - params types.Params) { +func ConsumeMultisignatureVerificationGas( + meter sdk.GasMeter, sig multisig.Multisignature, pubkey multisig.PubKeyMultisigThreshold, params types.Params, +) { + size := sig.BitArray.Size() sigIndex := 0 + for i := 0; i < size; i++ { if sig.BitArray.GetIndex(i) { DefaultSigVerificationGasConsumer(meter, sig.Sigs[sigIndex], pubkey.PubKeys[i], params) @@ -340,5 +343,6 @@ func GetSignerAcc(ctx sdk.Context, ak keeper.AccountKeeper, addr sdk.AccAddress) if acc := ak.GetAccount(ctx, addr); acc != nil { return acc, nil } + return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr) } diff --git a/x/auth/client/cli/query.go b/x/auth/client/cli/query.go index af9f00b4ddc7..ebb5f3f508a8 100644 --- a/x/auth/client/cli/query.go +++ b/x/auth/client/cli/query.go @@ -50,7 +50,7 @@ func GetAccountCmd(cdc *codec.Codec) *cobra.Command { Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) - accGetter := types.NewAccountRetriever(cliCtx) + accGetter := types.NewAccountRetriever(authclient.Codec, cliCtx) key, err := sdk.AccAddressFromBech32(args[0]) if err != nil { diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index b46192925dbd..f1ea091d0b1e 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -86,7 +86,7 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) txBldr := types.NewTxBuilderFromCLI(inBuf) if !viper.GetBool(flagOffline) { - accnum, seq, err := types.NewAccountRetriever(cliCtx).GetAccountNumberSequence(multisigInfo.GetAddress()) + accnum, seq, err := types.NewAccountRetriever(client.Codec, cliCtx).GetAccountNumberSequence(multisigInfo.GetAddress()) if err != nil { return err } diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index ebbe936a78b4..a6434be7ef92 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -224,7 +224,7 @@ func printAndValidateSigs( // Validate the actual signature over the transaction bytes since we can // reach out to a full node to query accounts. if !offline && success { - acc, err := types.NewAccountRetriever(cliCtx).GetAccount(sigAddr) + acc, err := types.NewAccountRetriever(client.Codec, cliCtx).GetAccount(sigAddr) if err != nil { fmt.Printf("failed to get account: %s\n", sigAddr) return false diff --git a/x/auth/client/rest/query.go b/x/auth/client/rest/query.go index 44f1bbb5b0ef..6f245e40a2cf 100644 --- a/x/auth/client/rest/query.go +++ b/x/auth/client/rest/query.go @@ -33,7 +33,7 @@ func QueryAccountRequestHandlerFn(storeName string, cliCtx context.CLIContext) h return } - accGetter := types.NewAccountRetriever(cliCtx) + accGetter := types.NewAccountRetriever(client.Codec, cliCtx) account, height, err := accGetter.GetAccountWithHeight(addr) if err != nil { diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 12d50a65ab03..3c35aebe61c0 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -19,6 +19,15 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) +// Codec defines the x/auth account codec to be used for use with the +// AccountRetriever. The application must be sure to set this to their respective +// codec that implements the Codec interface and must be the same codec that +// passed to the x/auth module. +// +// TODO:/XXX: Using a package-level global isn't ideal and we should consider +// refactoring the module manager to allow passing in the correct module codec. +var Codec authtypes.Codec + // GasEstimateResponse defines a response definition for tx gas estimation. type GasEstimateResponse struct { GasEstimate uint64 `json:"gas_estimate" yaml:"gas_estimate"` @@ -198,9 +207,10 @@ func SignStdTx( // SignStdTxWithSignerAddress attaches a signature to a StdTx and returns a copy of a it. // Don't perform online validation or lookups if offline is true, else // populate account and sequence numbers from a foreign account. -func SignStdTxWithSignerAddress(txBldr authtypes.TxBuilder, cliCtx context.CLIContext, - addr sdk.AccAddress, name string, stdTx authtypes.StdTx, - offline bool) (signedStdTx authtypes.StdTx, err error) { +func SignStdTxWithSignerAddress( + txBldr authtypes.TxBuilder, cliCtx context.CLIContext, + addr sdk.AccAddress, name string, stdTx authtypes.StdTx, offline bool, +) (signedStdTx authtypes.StdTx, err error) { // check whether the address is a signer if !isTxSigner(addr, stdTx.GetSigners()) { @@ -242,7 +252,7 @@ func populateAccountFromState( txBldr authtypes.TxBuilder, cliCtx context.CLIContext, addr sdk.AccAddress, ) (authtypes.TxBuilder, error) { - num, seq, err := authtypes.NewAccountRetriever(cliCtx).GetAccountNumberSequence(addr) + num, seq, err := authtypes.NewAccountRetriever(Codec, cliCtx).GetAccountNumberSequence(addr) if err != nil { return txBldr, err } @@ -290,7 +300,7 @@ func parseQueryResponse(cdc *codec.Codec, rawRes []byte) (uint64, error) { func PrepareTxBuilder(txBldr authtypes.TxBuilder, cliCtx context.CLIContext) (authtypes.TxBuilder, error) { from := cliCtx.GetFromAddress() - accGetter := authtypes.NewAccountRetriever(cliCtx) + accGetter := authtypes.NewAccountRetriever(Codec, cliCtx) if err := accGetter.EnsureExists(from); err != nil { return txBldr, err } @@ -299,7 +309,7 @@ func PrepareTxBuilder(txBldr authtypes.TxBuilder, cliCtx context.CLIContext) (au // TODO: (ref #1903) Allow for user supplied account number without // automatically doing a manual lookup. if txbldrAccNum == 0 || txbldrAccSeq == 0 { - num, seq, err := authtypes.NewAccountRetriever(cliCtx).GetAccountNumberSequence(from) + num, seq, err := authtypes.NewAccountRetriever(Codec, cliCtx).GetAccountNumberSequence(from) if err != nil { return txBldr, err } diff --git a/x/auth/keeper/account.go b/x/auth/keeper/account.go index 8417a4a34d2b..f2e9292b47c1 100644 --- a/x/auth/keeper/account.go +++ b/x/auth/keeper/account.go @@ -13,6 +13,7 @@ func (ak AccountKeeper) NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddre if err != nil { panic(err) } + return ak.NewAccount(ctx, acc) } @@ -21,6 +22,7 @@ func (ak AccountKeeper) NewAccount(ctx sdk.Context, acc exported.Account) export if err := acc.SetAccountNumber(ak.GetNextAccountNumber(ctx)); err != nil { panic(err) } + return acc } @@ -31,17 +33,17 @@ func (ak AccountKeeper) GetAccount(ctx sdk.Context, addr sdk.AccAddress) exporte if bz == nil { return nil } - acc := ak.decodeAccount(bz) - return acc + + return ak.decodeAccount(bz) } // GetAllAccounts returns all accounts in the accountKeeper. func (ak AccountKeeper) GetAllAccounts(ctx sdk.Context) (accounts []exported.Account) { - ak.IterateAccounts(ctx, - func(acc exported.Account) (stop bool) { - accounts = append(accounts, acc) - return false - }) + ak.IterateAccounts(ctx, func(acc exported.Account) (stop bool) { + accounts = append(accounts, acc) + return false + }) + return accounts } @@ -49,10 +51,12 @@ func (ak AccountKeeper) GetAllAccounts(ctx sdk.Context) (accounts []exported.Acc func (ak AccountKeeper) SetAccount(ctx sdk.Context, acc exported.Account) { addr := acc.GetAddress() store := ctx.KVStore(ak.key) - bz, err := ak.cdc.MarshalBinaryBare(acc) + + bz, err := ak.cdc.MarshalAccount(acc) if err != nil { panic(err) } + store.Set(types.AddressStoreKey(addr), bz) } diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 244dec7c193b..18ecc0471119 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -3,10 +3,10 @@ package keeper import ( "fmt" + gogotypes "github.com/gogo/protobuf/types" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/libs/log" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/exported" @@ -17,23 +17,18 @@ import ( // AccountKeeper encodes/decodes accounts using the go-amino (binary) // encoding/decoding library. type AccountKeeper struct { - // The (unexposed) key used to access the store from the Context. - key sdk.StoreKey + key sdk.StoreKey + cdc types.Codec + paramSubspace subspace.Subspace // The prototypical Account constructor. proto func() exported.Account - - // The codec codec for binary encoding/decoding of accounts. - cdc *codec.Codec - - paramSubspace subspace.Subspace } // NewAccountKeeper returns a new sdk.AccountKeeper that uses go-amino to // (binary) encode and decode concrete sdk.Accounts. -// nolint func NewAccountKeeper( - cdc *codec.Codec, key sdk.StoreKey, paramstore subspace.Subspace, proto func() exported.Account, + cdc types.Codec, key sdk.StoreKey, paramstore subspace.Subspace, proto func() exported.Account, ) AccountKeeper { return AccountKeeper{ @@ -55,6 +50,7 @@ func (ak AccountKeeper) GetPubKey(ctx sdk.Context, addr sdk.AccAddress) (crypto. if acc == nil { return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr) } + return acc.GetPubKey(), nil } @@ -64,6 +60,7 @@ func (ak AccountKeeper) GetSequence(ctx sdk.Context, addr sdk.AccAddress) (uint6 if acc == nil { return 0, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr) } + return acc.GetSequence(), nil } @@ -72,30 +69,33 @@ func (ak AccountKeeper) GetSequence(ctx sdk.Context, addr sdk.AccAddress) (uint6 func (ak AccountKeeper) GetNextAccountNumber(ctx sdk.Context) uint64 { var accNumber uint64 store := ctx.KVStore(ak.key) + bz := store.Get(types.GlobalAccountNumberKey) if bz == nil { // initialize the account numbers accNumber = 0 } else { - err := ak.cdc.UnmarshalBinaryLengthPrefixed(bz, &accNumber) + val := gogotypes.UInt64Value{} + + err := ak.cdc.UnmarshalBinaryLengthPrefixed(bz, &val) if err != nil { panic(err) } + + accNumber = val.GetValue() } - bz = ak.cdc.MustMarshalBinaryLengthPrefixed(accNumber + 1) + bz = ak.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.UInt64Value{Value: accNumber + 1}) store.Set(types.GlobalAccountNumberKey, bz) return accNumber } -// ----------------------------------------------------------------------------- -// Misc. - -func (ak AccountKeeper) decodeAccount(bz []byte) (acc exported.Account) { - err := ak.cdc.UnmarshalBinaryBare(bz, &acc) +func (ak AccountKeeper) decodeAccount(bz []byte) exported.Account { + acc, err := ak.cdc.UnmarshalAccount(bz) if err != nil { panic(err) } - return + + return acc } diff --git a/x/auth/module.go b/x/auth/module.go index d3cf501e4f04..c5adc5811328 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -41,14 +41,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { // DefaultGenesis returns default genesis state as raw bytes for the auth // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return types.ModuleCdc.MustMarshalJSON(types.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the auth module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data types.GenesisState - if err := types.ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) } @@ -113,18 +113,18 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the auth module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - types.ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.accountKeeper, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the auth // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.accountKeeper) - return types.ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock returns the begin blocker for the auth module. diff --git a/x/auth/simulation/decoder.go b/x/auth/simulation/decoder.go index 725d82fc0a64..d157aab94349 100644 --- a/x/auth/simulation/decoder.go +++ b/x/auth/simulation/decoder.go @@ -19,11 +19,13 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { cdc.MustUnmarshalBinaryBare(kvA.Value, &accA) cdc.MustUnmarshalBinaryBare(kvB.Value, &accB) return fmt.Sprintf("%v\n%v", accA, accB) + case bytes.Equal(kvA.Key, types.GlobalAccountNumberKey): var globalAccNumberA, globalAccNumberB uint64 cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &globalAccNumberA) cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &globalAccNumberB) return fmt.Sprintf("GlobalAccNumberA: %d\nGlobalAccNumberB: %d", globalAccNumberA, globalAccNumberB) + default: panic(fmt.Sprintf("invalid account key %X", kvA.Key)) } diff --git a/x/auth/simulation/genesis.go b/x/auth/simulation/genesis.go index 94fd8ec5ff3d..f809042d1426 100644 --- a/x/auth/simulation/genesis.go +++ b/x/auth/simulation/genesis.go @@ -98,7 +98,7 @@ func RandomizedGenState(simState *module.SimulationState) { func RandomGenesisAccounts(simState *module.SimulationState) (genesisAccs exported.GenesisAccounts) { for i, acc := range simState.Accounts { bacc := types.NewBaseAccountWithAddress(acc.Address) - var gacc exported.GenesisAccount = &bacc + var gacc exported.GenesisAccount = bacc // Only consider making a vesting account once the initial bonded validator // set is exhausted due to needing to track DelegatedVesting. @@ -115,7 +115,7 @@ func RandomGenesisAccounts(simState *module.SimulationState) (genesisAccs export endTime = int64(simulation.RandIntBetween(simState.Rand, int(startTime)+1, int(startTime+(60*60*12)))) } - bva := vestingtypes.NewBaseVestingAccount(&bacc, initialVesting, endTime) + bva := vestingtypes.NewBaseVestingAccount(bacc, initialVesting, endTime) if simState.Rand.Intn(100) < 50 { gacc = vestingtypes.NewContinuousVestingAccountRaw(bva, startTime) diff --git a/x/auth/types/account.go b/x/auth/types/account.go index 643c33abd28a..1c2460166e22 100644 --- a/x/auth/types/account.go +++ b/x/auth/types/account.go @@ -2,7 +2,6 @@ package types import ( "bytes" - "encoding/json" "errors" "github.com/tendermint/tendermint/crypto" @@ -12,28 +11,19 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/exported" ) -//----------------------------------------------------------------------------- -// BaseAccount - var _ exported.Account = (*BaseAccount)(nil) var _ exported.GenesisAccount = (*BaseAccount)(nil) -// BaseAccount - a base account structure. -// This can be extended by embedding within in your AppAccount. -// However one doesn't have to use BaseAccount as long as your struct -// implements Account. -type BaseAccount struct { - Address sdk.AccAddress `json:"address" yaml:"address"` - PubKey crypto.PubKey `json:"public_key" yaml:"public_key"` - AccountNumber uint64 `json:"account_number" yaml:"account_number"` - Sequence uint64 `json:"sequence" yaml:"sequence"` -} - // NewBaseAccount creates a new BaseAccount object func NewBaseAccount(address sdk.AccAddress, pubKey crypto.PubKey, accountNumber, sequence uint64) *BaseAccount { + var pkStr string + if pubKey != nil { + pkStr = sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKey) + } + return &BaseAccount{ Address: address, - PubKey: pubKey, + PubKey: pkStr, AccountNumber: accountNumber, Sequence: sequence, } @@ -45,8 +35,8 @@ func ProtoBaseAccount() exported.Account { } // NewBaseAccountWithAddress - returns a new base account with a given address -func NewBaseAccountWithAddress(addr sdk.AccAddress) BaseAccount { - return BaseAccount{ +func NewBaseAccountWithAddress(addr sdk.AccAddress) *BaseAccount { + return &BaseAccount{ Address: addr, } } @@ -61,23 +51,33 @@ func (acc *BaseAccount) SetAddress(addr sdk.AccAddress) error { if len(acc.Address) != 0 { return errors.New("cannot override BaseAccount address") } + acc.Address = addr return nil } // GetPubKey - Implements sdk.Account. func (acc BaseAccount) GetPubKey() crypto.PubKey { - return acc.PubKey + if acc.PubKey == "" { + return nil + } + + return sdk.MustGetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, acc.PubKey) } // SetPubKey - Implements sdk.Account. func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error { - acc.PubKey = pubKey + pkStr, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKey) + if err != nil { + return err + } + + acc.PubKey = pkStr return nil } // GetAccountNumber - Implements Account -func (acc *BaseAccount) GetAccountNumber() uint64 { +func (acc BaseAccount) GetAccountNumber() uint64 { return acc.AccountNumber } @@ -88,7 +88,7 @@ func (acc *BaseAccount) SetAccountNumber(accNumber uint64) error { } // GetSequence - Implements sdk.Account. -func (acc *BaseAccount) GetSequence() uint64 { +func (acc BaseAccount) GetSequence() uint64 { return acc.Sequence } @@ -100,90 +100,15 @@ func (acc *BaseAccount) SetSequence(seq uint64) error { // Validate checks for errors on the account fields func (acc BaseAccount) Validate() error { - if acc.PubKey != nil && acc.Address != nil && - !bytes.Equal(acc.PubKey.Address().Bytes(), acc.Address.Bytes()) { + if acc.PubKey != "" && acc.Address != nil && + !bytes.Equal(acc.GetPubKey().Address().Bytes(), acc.Address.Bytes()) { return errors.New("pubkey and address pair is invalid") } return nil } -type baseAccountPretty struct { - Address sdk.AccAddress `json:"address" yaml:"address"` - PubKey string `json:"public_key" yaml:"public_key"` - AccountNumber uint64 `json:"account_number" yaml:"account_number"` - Sequence uint64 `json:"sequence" yaml:"sequence"` -} - func (acc BaseAccount) String() string { - out, _ := acc.MarshalYAML() - return out.(string) -} - -// MarshalYAML returns the YAML representation of an account. -func (acc BaseAccount) MarshalYAML() (interface{}, error) { - alias := baseAccountPretty{ - Address: acc.Address, - AccountNumber: acc.AccountNumber, - Sequence: acc.Sequence, - } - - if acc.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, acc.PubKey) - if err != nil { - return nil, err - } - - alias.PubKey = pks - } - - bz, err := yaml.Marshal(alias) - if err != nil { - return nil, err - } - - return string(bz), err -} - -// MarshalJSON returns the JSON representation of a BaseAccount. -func (acc BaseAccount) MarshalJSON() ([]byte, error) { - alias := baseAccountPretty{ - Address: acc.Address, - AccountNumber: acc.AccountNumber, - Sequence: acc.Sequence, - } - - if acc.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, acc.PubKey) - if err != nil { - return nil, err - } - - alias.PubKey = pks - } - - return json.Marshal(alias) -} - -// UnmarshalJSON unmarshals raw JSON bytes into a BaseAccount. -func (acc *BaseAccount) UnmarshalJSON(bz []byte) error { - var alias baseAccountPretty - if err := json.Unmarshal(bz, &alias); err != nil { - return err - } - - if alias.PubKey != "" { - pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, alias.PubKey) - if err != nil { - return err - } - - acc.PubKey = pk - } - - acc.Address = alias.Address - acc.AccountNumber = alias.AccountNumber - acc.Sequence = alias.Sequence - - return nil + out, _ := yaml.Marshal(acc) + return string(out) } diff --git a/x/auth/types/account_retriever.go b/x/auth/types/account_retriever.go index ab87e3259b95..65aa4297ed19 100644 --- a/x/auth/types/account_retriever.go +++ b/x/auth/types/account_retriever.go @@ -18,12 +18,13 @@ type NodeQuerier interface { // AccountRetriever defines the properties of a type that can be used to // retrieve accounts. type AccountRetriever struct { + codec Codec querier NodeQuerier } // NewAccountRetriever initialises a new AccountRetriever instance. -func NewAccountRetriever(querier NodeQuerier) AccountRetriever { - return AccountRetriever{querier: querier} +func NewAccountRetriever(codec Codec, querier NodeQuerier) AccountRetriever { + return AccountRetriever{codec: codec, querier: querier} } // GetAccount queries for an account given an address and a block height. An @@ -37,22 +38,22 @@ func (ar AccountRetriever) GetAccount(addr sdk.AccAddress) (exported.Account, er // height of the query with the account. An error is returned if the query // or decoding fails. func (ar AccountRetriever) GetAccountWithHeight(addr sdk.AccAddress) (exported.Account, int64, error) { - bs, err := ModuleCdc.MarshalJSON(NewQueryAccountParams(addr)) + bs, err := ar.codec.MarshalJSON(NewQueryAccountParams(addr)) if err != nil { return nil, 0, err } - res, height, err := ar.querier.QueryWithData(fmt.Sprintf("custom/%s/%s", QuerierRoute, QueryAccount), bs) + bz, height, err := ar.querier.QueryWithData(fmt.Sprintf("custom/%s/%s", QuerierRoute, QueryAccount), bs) if err != nil { return nil, height, err } - var account exported.Account - if err := ModuleCdc.UnmarshalJSON(res, &account); err != nil { + acc, err := ar.codec.UnmarshalAccountJSON(bz) + if err != nil { return nil, height, err } - return account, height, nil + return acc, height, nil } // EnsureExists returns an error if no account exists for the given address else nil. diff --git a/x/auth/types/account_retriever_test.go b/x/auth/types/account_retriever_test.go index 76126db115d3..0481e00b263b 100644 --- a/x/auth/types/account_retriever_test.go +++ b/x/auth/types/account_retriever_test.go @@ -1,4 +1,4 @@ -package types +package types_test import ( "errors" @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/tests/mocks" + "github.com/cosmos/cosmos-sdk/x/auth/types" ) var errFoo = errors.New("dummy") @@ -17,9 +18,9 @@ func TestAccountRetriever(t *testing.T) { defer mockCtrl.Finish() mockNodeQuerier := mocks.NewMockNodeQuerier(mockCtrl) - accRetr := NewAccountRetriever(mockNodeQuerier) + accRetr := types.NewAccountRetriever(appCodec, mockNodeQuerier) addr := []byte("test") - bs, err := ModuleCdc.MarshalJSON(NewQueryAccountParams(addr)) + bs, err := appCodec.MarshalJSON(types.NewQueryAccountParams(addr)) require.NoError(t, err) mockNodeQuerier.EXPECT().QueryWithData(gomock.Eq("custom/acc/account"), diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index 90a4dacb0c9f..e86f4b5940b1 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -1,22 +1,21 @@ -package types +package types_test import ( - "encoding/json" "errors" "testing" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/secp256k1" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/types" ) func TestBaseAddressPubKey(t *testing.T) { - _, pub1, addr1 := KeyTestPubAddr() - _, pub2, addr2 := KeyTestPubAddr() - acc := NewBaseAccountWithAddress(addr1) + _, pub1, addr1 := types.KeyTestPubAddr() + _, pub2, addr2 := types.KeyTestPubAddr() + acc := types.NewBaseAccountWithAddress(addr1) // check the address (set) and pubkey (not set) require.EqualValues(t, addr1, acc.GetAddress()) @@ -40,16 +39,15 @@ func TestBaseAddressPubKey(t *testing.T) { //------------------------------------ // can set address on empty account - acc2 := BaseAccount{} + acc2 := types.BaseAccount{} err = acc2.SetAddress(addr2) require.Nil(t, err) require.EqualValues(t, addr2, acc2.GetAddress()) } func TestBaseAccountSequence(t *testing.T) { - _, _, addr := KeyTestPubAddr() - acc := NewBaseAccountWithAddress(addr) - + _, _, addr := types.KeyTestPubAddr() + acc := types.NewBaseAccountWithAddress(addr) seq := uint64(7) err := acc.SetSequence(seq) @@ -58,9 +56,8 @@ func TestBaseAccountSequence(t *testing.T) { } func TestBaseAccountMarshal(t *testing.T) { - _, pub, addr := KeyTestPubAddr() - acc := NewBaseAccountWithAddress(addr) - + _, pub, addr := types.KeyTestPubAddr() + acc := types.NewBaseAccountWithAddress(addr) seq := uint64(7) // set everything on the account @@ -69,28 +66,23 @@ func TestBaseAccountMarshal(t *testing.T) { err = acc.SetSequence(seq) require.Nil(t, err) - // need a codec for marshaling - cdc := codec.New() - codec.RegisterCrypto(cdc) - - b, err := cdc.MarshalBinaryLengthPrefixed(acc) + bz, err := appCodec.MarshalAccount(acc) require.Nil(t, err) - acc2 := BaseAccount{} - err = cdc.UnmarshalBinaryLengthPrefixed(b, &acc2) + acc2, err := appCodec.UnmarshalAccount(bz) require.Nil(t, err) require.Equal(t, acc, acc2) // error on bad bytes - acc2 = BaseAccount{} - err = cdc.UnmarshalBinaryLengthPrefixed(b[:len(b)/2], &acc2) + _, err = appCodec.UnmarshalAccount(bz[:len(bz)/2]) require.NotNil(t, err) } func TestGenesisAccountValidate(t *testing.T) { pubkey := secp256k1.GenPrivKey().PubKey() addr := sdk.AccAddress(pubkey.Address()) - baseAcc := NewBaseAccount(addr, pubkey, 0, 0) + baseAcc := types.NewBaseAccount(addr, pubkey, 0, 0) + tests := []struct { name string acc exported.GenesisAccount @@ -103,39 +95,17 @@ func TestGenesisAccountValidate(t *testing.T) { }, { "invalid base valid account", - NewBaseAccount(addr, secp256k1.GenPrivKey().PubKey(), 0, 0), + types.NewBaseAccount(addr, secp256k1.GenPrivKey().PubKey(), 0, 0), errors.New("pubkey and address pair is invalid"), }, } + for _, tt := range tests { tt := tt + t.Run(tt.name, func(t *testing.T) { err := tt.acc.Validate() require.Equal(t, tt.expErr, err) }) } } - -func TestBaseAccountJSON(t *testing.T) { - pubkey := secp256k1.GenPrivKey().PubKey() - addr := sdk.AccAddress(pubkey.Address()) - baseAcc := NewBaseAccount(addr, pubkey, 10, 50) - - bz, err := json.Marshal(baseAcc) - require.NoError(t, err) - - bz1, err := baseAcc.MarshalJSON() - require.NoError(t, err) - require.Equal(t, string(bz1), string(bz)) - - var a BaseAccount - require.NoError(t, json.Unmarshal(bz, &a)) - require.Equal(t, baseAcc.String(), a.String()) - - bz, err = ModuleCdc.MarshalJSON(baseAcc) - require.NoError(t, err) - - var b BaseAccount - require.NoError(t, ModuleCdc.UnmarshalJSON(bz, &b)) - require.Equal(t, baseAcc.String(), b.String()) -} diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index c6be8883f7ad..be7f21b3f1d1 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -5,10 +5,20 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/exported" ) -// ModuleCdc auth module wide codec -var ModuleCdc = codec.New() +// Codec defines the interface needed to serialize x/auth state. It must be +// aware of all concrete account types. +type Codec interface { + codec.Marshaler -// RegisterCodec registers concrete types on the codec + MarshalAccount(acc exported.Account) ([]byte, error) + UnmarshalAccount(bz []byte) (exported.Account, error) + + MarshalAccountJSON(acc exported.Account) ([]byte, error) + UnmarshalAccountJSON(bz []byte) (exported.Account, error) +} + +// RegisterCodec registers the account interfaces and concrete types on the +// provided Amino codec. func RegisterCodec(cdc *codec.Codec) { cdc.RegisterInterface((*exported.GenesisAccount)(nil), nil) cdc.RegisterInterface((*exported.Account)(nil), nil) @@ -16,13 +26,20 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(StdTx{}, "cosmos-sdk/StdTx", nil) } -// RegisterAccountTypeCodec registers an external account type defined in -// another module for the internal ModuleCdc. -func RegisterAccountTypeCodec(o interface{}, name string) { - ModuleCdc.RegisterConcrete(o, name, nil) -} +var ( + amino = codec.New() + + // ModuleCdc references the global x/auth module codec. Note, the codec should + // ONLY be used in certain instances of tests and for JSON encoding as Amino is + // still used for that purpose. + // + // The actual codec used for serialization should be provided to x/auth and + // defined at the application level. + ModuleCdc = codec.NewHybridCodec(amino) +) func init() { - RegisterCodec(ModuleCdc) - codec.RegisterCrypto(ModuleCdc) + RegisterCodec(amino) + codec.RegisterCrypto(amino) + amino.Seal() } diff --git a/x/auth/types/common_test.go b/x/auth/types/common_test.go new file mode 100644 index 000000000000..02b80ac6aa6d --- /dev/null +++ b/x/auth/types/common_test.go @@ -0,0 +1,11 @@ +package types_test + +import ( + "github.com/cosmos/cosmos-sdk/simapp" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" +) + +var ( + app = simapp.Setup(false) + appCodec = simappcodec.NewAppCodec(app.Codec()) +) diff --git a/x/auth/types/errors.go b/x/auth/types/errors.go index 3333cc8a467a..8e765ceb9891 100644 --- a/x/auth/types/errors.go +++ b/x/auth/types/errors.go @@ -1,8 +1,10 @@ package types -import "errors" +import ( + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) var ( - ErrorInvalidSigner = errors.New("tx intended signer does not match the given signer") - ErrorInvalidGasAdjustment = errors.New("invalid gas adjustment") + ErrorInvalidSigner = sdkerrors.Register(ModuleName, 2, "tx intended signer does not match the given signer") + ErrorInvalidGasAdjustment = sdkerrors.Register(ModuleName, 3, "invalid gas adjustment") ) diff --git a/x/auth/types/genesis.go b/x/auth/types/genesis.go index 89999db447ca..1b83380e352e 100644 --- a/x/auth/types/genesis.go +++ b/x/auth/types/genesis.go @@ -5,7 +5,6 @@ import ( "fmt" "sort" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth/exported" ) @@ -30,7 +29,7 @@ func DefaultGenesisState() GenesisState { // GetGenesisStateFromAppState returns x/auth GenesisState given raw application // genesis state. -func GetGenesisStateFromAppState(cdc *codec.Codec, appState map[string]json.RawMessage) GenesisState { +func GetGenesisStateFromAppState(cdc Codec, appState map[string]json.RawMessage) GenesisState { var genesisState GenesisState if appState[ModuleName] != nil { cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState) @@ -86,7 +85,7 @@ type GenesisAccountIterator struct{} // appGenesis and invokes a callback on each genesis account. If any call // returns true, iteration stops. func (GenesisAccountIterator) IterateGenesisAccounts( - cdc *codec.Codec, appGenesis map[string]json.RawMessage, cb func(exported.Account) (stop bool), + cdc Codec, appGenesis map[string]json.RawMessage, cb func(exported.Account) (stop bool), ) { for _, genAcc := range GetGenesisStateFromAppState(cdc, appGenesis).Accounts { diff --git a/x/auth/types/genesis_test.go b/x/auth/types/genesis_test.go index 3b892f48038d..c5e482cf0356 100644 --- a/x/auth/types/genesis_test.go +++ b/x/auth/types/genesis_test.go @@ -1,4 +1,4 @@ -package types +package types_test import ( "encoding/json" @@ -9,21 +9,22 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/types" ) func TestSanitize(t *testing.T) { addr1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) - authAcc1 := NewBaseAccountWithAddress(addr1) + authAcc1 := types.NewBaseAccountWithAddress(addr1) authAcc1.SetAccountNumber(1) addr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) - authAcc2 := NewBaseAccountWithAddress(addr2) + authAcc2 := types.NewBaseAccountWithAddress(addr2) - genAccs := exported.GenesisAccounts{&authAcc1, &authAcc2} + genAccs := exported.GenesisAccounts{authAcc1, authAcc2} require.True(t, genAccs[0].GetAccountNumber() > genAccs[1].GetAccountNumber()) require.Equal(t, genAccs[1].GetAddress(), addr2) - genAccs = SanitizeGenesisAccounts(genAccs) + genAccs = types.SanitizeGenesisAccounts(genAccs) require.False(t, genAccs[0].GetAccountNumber() > genAccs[1].GetAccountNumber()) require.Equal(t, genAccs[1].GetAddress(), addr1) @@ -38,34 +39,33 @@ var ( // require duplicate accounts fails validation func TestValidateGenesisDuplicateAccounts(t *testing.T) { - acc1 := NewBaseAccountWithAddress(sdk.AccAddress(addr1)) + acc1 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr1)) genAccs := make(exported.GenesisAccounts, 2) - genAccs[0] = &acc1 - genAccs[1] = &acc1 + genAccs[0] = acc1 + genAccs[1] = acc1 - require.Error(t, ValidateGenAccounts(genAccs)) + require.Error(t, types.ValidateGenAccounts(genAccs)) } func TestGenesisAccountIterator(t *testing.T) { - acc1 := NewBaseAccountWithAddress(sdk.AccAddress(addr1)) + acc1 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr1)) + acc2 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr2)) - acc2 := NewBaseAccountWithAddress(sdk.AccAddress(addr2)) + genAccounts := exported.GenesisAccounts{acc1, acc2} - genAccounts := exported.GenesisAccounts{&acc1, &acc2} - - authGenState := DefaultGenesisState() + authGenState := types.DefaultGenesisState() authGenState.Accounts = genAccounts appGenesis := make(map[string]json.RawMessage) - authGenStateBz, err := ModuleCdc.MarshalJSON(authGenState) + authGenStateBz, err := appCodec.MarshalJSON(authGenState) require.NoError(t, err) - appGenesis[ModuleName] = authGenStateBz + appGenesis[types.ModuleName] = authGenStateBz var addresses []sdk.AccAddress - GenesisAccountIterator{}.IterateGenesisAccounts( - ModuleCdc, appGenesis, func(acc exported.Account) (stop bool) { + types.GenesisAccountIterator{}.IterateGenesisAccounts( + appCodec, appGenesis, func(acc exported.Account) (stop bool) { addresses = append(addresses, acc.GetAddress()) return false }, diff --git a/x/auth/types/params.go b/x/auth/types/params.go index 2f994ef7eecf..8ad49df1157b 100644 --- a/x/auth/types/params.go +++ b/x/auth/types/params.go @@ -1,12 +1,11 @@ package types import ( - "bytes" "fmt" - "strings" "github.com/cosmos/cosmos-sdk/x/params" "github.com/cosmos/cosmos-sdk/x/params/subspace" + yaml "gopkg.in/yaml.v2" ) // DefaultParamspace defines the default auth module parameter subspace @@ -32,18 +31,10 @@ var ( var _ subspace.ParamSet = &Params{} -// Params defines the parameters for the auth module. -type Params struct { - MaxMemoCharacters uint64 `json:"max_memo_characters" yaml:"max_memo_characters"` - TxSigLimit uint64 `json:"tx_sig_limit" yaml:"tx_sig_limit"` - TxSizeCostPerByte uint64 `json:"tx_size_cost_per_byte" yaml:"tx_size_cost_per_byte"` - SigVerifyCostED25519 uint64 `json:"sig_verify_cost_ed25519" yaml:"sig_verify_cost_ed25519"` - SigVerifyCostSecp256k1 uint64 `json:"sig_verify_cost_secp256k1" yaml:"sig_verify_cost_secp256k1"` -} - // NewParams creates a new Params object -func NewParams(maxMemoCharacters, txSigLimit, txSizeCostPerByte, - sigVerifyCostED25519, sigVerifyCostSecp256k1 uint64) Params { +func NewParams( + maxMemoCharacters, txSigLimit, txSizeCostPerByte, sigVerifyCostED25519, sigVerifyCostSecp256k1 uint64, +) Params { return Params{ MaxMemoCharacters: maxMemoCharacters, @@ -72,13 +63,6 @@ func (p *Params) ParamSetPairs() subspace.ParamSetPairs { } } -// Equal returns a boolean determining if two Params types are identical. -func (p Params) Equal(p2 Params) bool { - bz1 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&p) - bz2 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&p2) - return bytes.Equal(bz1, bz2) -} - // DefaultParams returns a default set of parameters. func DefaultParams() Params { return Params{ @@ -92,14 +76,8 @@ func DefaultParams() Params { // String implements the stringer interface. func (p Params) String() string { - var sb strings.Builder - sb.WriteString("Params: \n") - sb.WriteString(fmt.Sprintf("MaxMemoCharacters: %d\n", p.MaxMemoCharacters)) - sb.WriteString(fmt.Sprintf("TxSigLimit: %d\n", p.TxSigLimit)) - sb.WriteString(fmt.Sprintf("TxSizeCostPerByte: %d\n", p.TxSizeCostPerByte)) - sb.WriteString(fmt.Sprintf("SigVerifyCostED25519: %d\n", p.SigVerifyCostED25519)) - sb.WriteString(fmt.Sprintf("SigVerifyCostSecp256k1: %d\n", p.SigVerifyCostSecp256k1)) - return sb.String() + out, _ := yaml.Marshal(p) + return string(out) } func validateTxSigLimit(i interface{}) error { diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index a37408f9e9e6..a9a6cd3e9daf 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -163,16 +163,6 @@ func (tx StdTx) FeePayer() sdk.AccAddress { return sdk.AccAddress{} } -//__________________________________________________________ - -// StdFee includes the amount of coins paid in fees and the maximum -// gas to be used by the transaction. The ratio yields an effective "gasprice", -// which must be above some miminum to be accepted into the mempool. -type StdFee struct { - Amount sdk.Coins `json:"amount" yaml:"amount"` - Gas uint64 `json:"gas" yaml:"gas"` -} - // NewStdFee returns a new instance of StdFee func NewStdFee(gas uint64, amount sdk.Coins) StdFee { return StdFee{ @@ -190,10 +180,12 @@ func (fee StdFee) Bytes() []byte { if len(fee.Amount) == 0 { fee.Amount = sdk.NewCoins() } - bz, err := ModuleCdc.MarshalJSON(fee) // TODO + + bz, err := codec.Cdc.MarshalJSON(fee) // TODO if err != nil { panic(err) } + return bz } @@ -228,7 +220,8 @@ func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, ms for _, msg := range msgs { msgsBytes = append(msgsBytes, json.RawMessage(msg.GetSignBytes())) } - bz, err := ModuleCdc.MarshalJSON(StdSignDoc{ + + bz, err := codec.Cdc.MarshalJSON(StdSignDoc{ AccountNumber: accnum, ChainID: chainID, Fee: json.RawMessage(fee.Bytes()), @@ -236,9 +229,11 @@ func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, ms Msgs: msgsBytes, Sequence: sequence, }) + if err != nil { panic(err) } + return sdk.MustSortJSON(bz) } diff --git a/x/auth/types/test_common.go b/x/auth/types/test_utils.go similarity index 100% rename from x/auth/types/test_common.go rename to x/auth/types/test_utils.go diff --git a/x/auth/types/types.pb.go b/x/auth/types/types.pb.go new file mode 100644 index 000000000000..04705c07d3d3 --- /dev/null +++ b/x/auth/types/types.pb.go @@ -0,0 +1,1001 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/auth/types/types.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/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 + +// BaseAccount defines a base account type. It contains all the necessary fields +// for basic account functionality. Any custom account type should extend this +// type for additional functionality (e.g. vesting). +type BaseAccount struct { + Address github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=address,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"address,omitempty"` + PubKey string `protobuf:"bytes,2,opt,name=pub_key,json=pubKey,proto3" json:"pub_key,omitempty" yaml:"public_key"` + AccountNumber uint64 `protobuf:"varint,3,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty" yaml:"account_number"` + Sequence uint64 `protobuf:"varint,4,opt,name=sequence,proto3" json:"sequence,omitempty"` +} + +func (m *BaseAccount) Reset() { *m = BaseAccount{} } +func (*BaseAccount) ProtoMessage() {} +func (*BaseAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_2d526fa662daab74, []int{0} +} +func (m *BaseAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BaseAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BaseAccount.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 *BaseAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_BaseAccount.Merge(m, src) +} +func (m *BaseAccount) XXX_Size() int { + return m.Size() +} +func (m *BaseAccount) XXX_DiscardUnknown() { + xxx_messageInfo_BaseAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_BaseAccount proto.InternalMessageInfo + +// StdFee includes the amount of coins paid in fees and the maximum +// gas to be used by the transaction. The ratio yields an effective "gasprice", +// which must be above some miminum to be accepted into the mempool. +type StdFee struct { + Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"` + Gas uint64 `protobuf:"varint,2,opt,name=gas,proto3" json:"gas,omitempty"` +} + +func (m *StdFee) Reset() { *m = StdFee{} } +func (m *StdFee) String() string { return proto.CompactTextString(m) } +func (*StdFee) ProtoMessage() {} +func (*StdFee) Descriptor() ([]byte, []int) { + return fileDescriptor_2d526fa662daab74, []int{1} +} +func (m *StdFee) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StdFee) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StdFee.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 *StdFee) XXX_Merge(src proto.Message) { + xxx_messageInfo_StdFee.Merge(m, src) +} +func (m *StdFee) XXX_Size() int { + return m.Size() +} +func (m *StdFee) XXX_DiscardUnknown() { + xxx_messageInfo_StdFee.DiscardUnknown(m) +} + +var xxx_messageInfo_StdFee proto.InternalMessageInfo + +func (m *StdFee) GetAmount() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Amount + } + return nil +} + +func (m *StdFee) GetGas() uint64 { + if m != nil { + return m.Gas + } + return 0 +} + +// Params defines the parameters for the auth module. +type Params struct { + MaxMemoCharacters uint64 `protobuf:"varint,1,opt,name=max_memo_characters,json=maxMemoCharacters,proto3" json:"max_memo_characters,omitempty" yaml:"max_memo_characters"` + TxSigLimit uint64 `protobuf:"varint,2,opt,name=tx_sig_limit,json=txSigLimit,proto3" json:"tx_sig_limit,omitempty" yaml:"tx_sig_limit"` + TxSizeCostPerByte uint64 `protobuf:"varint,3,opt,name=tx_size_cost_per_byte,json=txSizeCostPerByte,proto3" json:"tx_size_cost_per_byte,omitempty" yaml:"tx_size_cost_per_byte"` + SigVerifyCostED25519 uint64 `protobuf:"varint,4,opt,name=sig_verify_cost_ed25519,json=sigVerifyCostEd25519,proto3" json:"sig_verify_cost_ed25519,omitempty" yaml:"sig_verify_cost_ed25519"` + SigVerifyCostSecp256k1 uint64 `protobuf:"varint,5,opt,name=sig_verify_cost_secp256k1,json=sigVerifyCostSecp256k1,proto3" json:"sig_verify_cost_secp256k1,omitempty" yaml:"sig_verify_cost_secp256k1"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_2d526fa662daab74, []int{2} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetMaxMemoCharacters() uint64 { + if m != nil { + return m.MaxMemoCharacters + } + return 0 +} + +func (m *Params) GetTxSigLimit() uint64 { + if m != nil { + return m.TxSigLimit + } + return 0 +} + +func (m *Params) GetTxSizeCostPerByte() uint64 { + if m != nil { + return m.TxSizeCostPerByte + } + return 0 +} + +func (m *Params) GetSigVerifyCostED25519() uint64 { + if m != nil { + return m.SigVerifyCostED25519 + } + return 0 +} + +func (m *Params) GetSigVerifyCostSecp256k1() uint64 { + if m != nil { + return m.SigVerifyCostSecp256k1 + } + return 0 +} + +func init() { + proto.RegisterType((*BaseAccount)(nil), "cosmos_sdk.x.auth.v1.BaseAccount") + proto.RegisterType((*StdFee)(nil), "cosmos_sdk.x.auth.v1.StdFee") + proto.RegisterType((*Params)(nil), "cosmos_sdk.x.auth.v1.Params") +} + +func init() { proto.RegisterFile("x/auth/types/types.proto", fileDescriptor_2d526fa662daab74) } + +var fileDescriptor_2d526fa662daab74 = []byte{ + // 610 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x3d, 0x6f, 0xd3, 0x4e, + 0x18, 0x8f, 0xff, 0xc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 0x39, 0x9b, 0xe8, 0xca, 0xb7, 0x89, 0xae, 0x7c, 0xba, 0xd0, 0x2b, + 0x67, 0x17, 0x7a, 0xe5, 0xeb, 0x85, 0x5e, 0x79, 0xf7, 0xe8, 0xaf, 0xf7, 0x67, 0xf6, 0xcd, 0xbb, + 0xf5, 0xf2, 0x75, 0x3e, 0xf9, 0x19, 0x00, 0x00, 0xff, 0xff, 0xd6, 0x52, 0x88, 0x39, 0x0a, 0x04, + 0x00, 0x00, +} + +func (this *Params) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Params) + if !ok { + that2, ok := that.(Params) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.MaxMemoCharacters != that1.MaxMemoCharacters { + return false + } + if this.TxSigLimit != that1.TxSigLimit { + return false + } + if this.TxSizeCostPerByte != that1.TxSizeCostPerByte { + return false + } + if this.SigVerifyCostED25519 != that1.SigVerifyCostED25519 { + return false + } + if this.SigVerifyCostSecp256k1 != that1.SigVerifyCostSecp256k1 { + return false + } + return true +} +func (m *BaseAccount) 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 *BaseAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BaseAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sequence != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x20 + } + if m.AccountNumber != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.AccountNumber)) + i-- + dAtA[i] = 0x18 + } + if len(m.PubKey) > 0 { + i -= len(m.PubKey) + copy(dAtA[i:], m.PubKey) + i = encodeVarintTypes(dAtA, i, uint64(len(m.PubKey))) + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *StdFee) 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 *StdFee) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StdFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Gas != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Gas)) + i-- + dAtA[i] = 0x10 + } + if len(m.Amount) > 0 { + for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.SigVerifyCostSecp256k1 != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.SigVerifyCostSecp256k1)) + i-- + dAtA[i] = 0x28 + } + if m.SigVerifyCostED25519 != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.SigVerifyCostED25519)) + i-- + dAtA[i] = 0x20 + } + if m.TxSizeCostPerByte != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.TxSizeCostPerByte)) + i-- + dAtA[i] = 0x18 + } + if m.TxSigLimit != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.TxSigLimit)) + i-- + dAtA[i] = 0x10 + } + if m.MaxMemoCharacters != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.MaxMemoCharacters)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *BaseAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.PubKey) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.AccountNumber != 0 { + n += 1 + sovTypes(uint64(m.AccountNumber)) + } + if m.Sequence != 0 { + n += 1 + sovTypes(uint64(m.Sequence)) + } + return n +} + +func (m *StdFee) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Amount) > 0 { + for _, e := range m.Amount { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + if m.Gas != 0 { + n += 1 + sovTypes(uint64(m.Gas)) + } + return n +} + +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.MaxMemoCharacters != 0 { + n += 1 + sovTypes(uint64(m.MaxMemoCharacters)) + } + if m.TxSigLimit != 0 { + n += 1 + sovTypes(uint64(m.TxSigLimit)) + } + if m.TxSizeCostPerByte != 0 { + n += 1 + sovTypes(uint64(m.TxSizeCostPerByte)) + } + if m.SigVerifyCostED25519 != 0 { + n += 1 + sovTypes(uint64(m.SigVerifyCostED25519)) + } + if m.SigVerifyCostSecp256k1 != 0 { + n += 1 + sovTypes(uint64(m.SigVerifyCostSecp256k1)) + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *BaseAccount) 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 ErrIntOverflowTypes + } + 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: BaseAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BaseAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = append(m.Address[:0], dAtA[iNdEx:postIndex]...) + if m.Address == nil { + m.Address = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PubKey", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PubKey = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AccountNumber", wireType) + } + m.AccountNumber = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AccountNumber |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) + } + m.Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *StdFee) 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 ErrIntOverflowTypes + } + 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: StdFee: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: StdFee: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Amount = append(m.Amount, types.Coin{}) + if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Gas", wireType) + } + m.Gas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Gas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Params) 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 ErrIntOverflowTypes + } + 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxMemoCharacters", wireType) + } + m.MaxMemoCharacters = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxMemoCharacters |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TxSigLimit", wireType) + } + m.TxSigLimit = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TxSigLimit |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TxSizeCostPerByte", wireType) + } + m.TxSizeCostPerByte = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TxSizeCostPerByte |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SigVerifyCostED25519", wireType) + } + m.SigVerifyCostED25519 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SigVerifyCostED25519 |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SigVerifyCostSecp256k1", wireType) + } + m.SigVerifyCostSecp256k1 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SigVerifyCostSecp256k1 |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTypes(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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrInvalidLengthTypes + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTypes + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTypes + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/auth/types/types.proto b/x/auth/types/types.proto new file mode 100644 index 000000000000..c707eb9c55ab --- /dev/null +++ b/x/auth/types/types.proto @@ -0,0 +1,49 @@ +syntax = "proto3"; +package cosmos_sdk.x.auth.v1; + +import "third_party/proto/gogoproto/gogo.proto"; +import "types/types.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/auth/types"; + +// BaseAccount defines a base account type. It contains all the necessary fields +// for basic account functionality. Any custom account type should extend this +// type for additional functionality (e.g. vesting). +message BaseAccount { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; + string pub_key = 2 [(gogoproto.moretags) = "yaml:\"public_key\""]; + uint64 account_number = 3 [(gogoproto.moretags) = "yaml:\"account_number\""]; + uint64 sequence = 4; +} + +// StdFee includes the amount of coins paid in fees and the maximum +// gas to be used by the transaction. The ratio yields an effective "gasprice", +// which must be above some miminum to be accepted into the mempool. +message StdFee { + repeated cosmos_sdk.v1.Coin amount = 1 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; + uint64 gas = 2; +} + +// Params defines the parameters for the auth module. +message Params { + option (gogoproto.equal) = true; + option (gogoproto.goproto_stringer) = false; + + uint64 max_memo_characters = 1 [(gogoproto.moretags) = "yaml:\"max_memo_characters\""]; + uint64 tx_sig_limit = 2 [(gogoproto.moretags) = "yaml:\"tx_sig_limit\""]; + uint64 tx_size_cost_per_byte = 3 [(gogoproto.moretags) = "yaml:\"tx_size_cost_per_byte\""]; + uint64 sig_verify_cost_ed25519 = 4 [ + (gogoproto.customname) = "SigVerifyCostED25519", + (gogoproto.moretags) = "yaml:\"sig_verify_cost_ed25519\"" + ]; + uint64 sig_verify_cost_secp256k1 = 5 [ + (gogoproto.customname) = "SigVerifyCostSecp256k1", + (gogoproto.moretags) = "yaml:\"sig_verify_cost_secp256k1\"" + ]; +} diff --git a/x/auth/vesting/alias.go b/x/auth/vesting/alias.go index 387ca51e51f4..9591aa12a0d9 100644 --- a/x/auth/vesting/alias.go +++ b/x/auth/vesting/alias.go @@ -1,15 +1,13 @@ -// nolint -// autogenerated code using github.com/rigelrozanski/multitool -// aliases generated for the following subdirectories: -// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/vesting/types/ package vesting +// DONTCOVER +// nolint + import ( "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" ) var ( - // functions aliases RegisterCodec = types.RegisterCodec NewBaseVestingAccount = types.NewBaseVestingAccount NewContinuousVestingAccountRaw = types.NewContinuousVestingAccountRaw @@ -18,9 +16,6 @@ var ( NewPeriodicVestingAccount = types.NewPeriodicVestingAccount NewDelayedVestingAccountRaw = types.NewDelayedVestingAccountRaw NewDelayedVestingAccount = types.NewDelayedVestingAccount - - // variable aliases - VestingCdc = types.VestingCdc ) type ( diff --git a/x/auth/vesting/types/codec.go b/x/auth/vesting/types/codec.go index 556e71117849..c0b938e2e1c3 100644 --- a/x/auth/vesting/types/codec.go +++ b/x/auth/vesting/types/codec.go @@ -5,7 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" ) -// RegisterCodec registers concrete types on the codec +// RegisterCodec registers the vesting interfaces and concrete types on the +// provided Amino codec. func RegisterCodec(cdc *codec.Codec) { cdc.RegisterInterface((*exported.VestingAccount)(nil), nil) cdc.RegisterConcrete(&BaseVestingAccount{}, "cosmos-sdk/BaseVestingAccount", nil) @@ -13,12 +14,3 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(&DelayedVestingAccount{}, "cosmos-sdk/DelayedVestingAccount", nil) cdc.RegisterConcrete(&PeriodicVestingAccount{}, "cosmos-sdk/PeriodicVestingAccount", nil) } - -// VestingCdc module wide codec -var VestingCdc *codec.Codec - -func init() { - VestingCdc = codec.New() - RegisterCodec(VestingCdc) - VestingCdc.Seal() -} diff --git a/x/auth/vesting/types/common_test.go b/x/auth/vesting/types/common_test.go new file mode 100644 index 000000000000..02b80ac6aa6d --- /dev/null +++ b/x/auth/vesting/types/common_test.go @@ -0,0 +1,11 @@ +package types_test + +import ( + "github.com/cosmos/cosmos-sdk/simapp" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" +) + +var ( + app = simapp.Setup(false) + appCodec = simappcodec.NewAppCodec(app.Codec()) +) diff --git a/x/auth/vesting/types/genesis_test.go b/x/auth/vesting/types/genesis_test.go index 7a9781eb7040..fb3fea0a2fdf 100644 --- a/x/auth/vesting/types/genesis_test.go +++ b/x/auth/vesting/types/genesis_test.go @@ -22,7 +22,7 @@ var ( func TestValidateGenesisInvalidAccounts(t *testing.T) { acc1 := authtypes.NewBaseAccountWithAddress(sdk.AccAddress(addr1)) acc1Balance := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 150)) - baseVestingAcc := NewBaseVestingAccount(&acc1, acc1Balance, 1548775410) + baseVestingAcc := NewBaseVestingAccount(acc1, acc1Balance, 1548775410) // invalid delegated vesting baseVestingAcc.DelegatedVesting = acc1Balance.Add(acc1Balance...) @@ -32,7 +32,7 @@ func TestValidateGenesisInvalidAccounts(t *testing.T) { genAccs := make([]exported.GenesisAccount, 2) genAccs[0] = baseVestingAcc - genAccs[1] = &acc2 + genAccs[1] = acc2 require.Error(t, authtypes.ValidateGenAccounts(genAccs)) baseVestingAcc.DelegatedVesting = acc1Balance diff --git a/x/auth/vesting/types/period.go b/x/auth/vesting/types/period.go index 1c4a5e2f4735..27b7a65c75be 100644 --- a/x/auth/vesting/types/period.go +++ b/x/auth/vesting/types/period.go @@ -4,22 +4,16 @@ import ( "fmt" "strings" - sdk "github.com/cosmos/cosmos-sdk/types" + "gopkg.in/yaml.v2" ) -// Period defines a length of time and amount of coins that will vest -type Period struct { - Length int64 `json:"length" yaml:"length"` // length of the period, in seconds - Amount sdk.Coins `json:"amount" yaml:"amount"` // amount of coins vesting during this period -} - // Periods stores all vesting periods passed as part of a PeriodicVestingAccount type Periods []Period // String Period implements stringer interface func (p Period) String() string { - return fmt.Sprintf(`Length: %d - Amount: %s`, p.Length, p.Amount) + out, _ := yaml.Marshal(p) + return string(out) } // String Periods implements stringer interface @@ -28,6 +22,7 @@ func (vp Periods) String() string { for _, period := range vp { periodsListString = append(periodsListString, period.String()) } + return strings.TrimSpace(fmt.Sprintf(`Vesting Periods: %s`, strings.Join(periodsListString, ", "))) } diff --git a/x/auth/vesting/types/types.pb.go b/x/auth/vesting/types/types.pb.go new file mode 100644 index 000000000000..adfa4af2ee88 --- /dev/null +++ b/x/auth/vesting/types/types.pb.go @@ -0,0 +1,1404 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/auth/vesting/types/types.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types1 "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/x/auth/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/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 + +// BaseVestingAccount implements the VestingAccount interface. It contains all +// the necessary fields needed for any vesting account implementation. +type BaseVestingAccount struct { + *types.BaseAccount `protobuf:"bytes,1,opt,name=base_account,json=baseAccount,proto3,embedded=base_account" json:"base_account,omitempty"` + OriginalVesting github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=original_vesting,json=originalVesting,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"original_vesting" yaml:"original_vesting"` + DelegatedFree github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=delegated_free,json=delegatedFree,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"delegated_free" yaml:"delegated_free"` + DelegatedVesting github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,4,rep,name=delegated_vesting,json=delegatedVesting,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"delegated_vesting" yaml:"delegated_vesting"` + EndTime int64 `protobuf:"varint,5,opt,name=end_time,json=endTime,proto3" json:"end_time,omitempty" yaml:"end_time"` +} + +func (m *BaseVestingAccount) Reset() { *m = BaseVestingAccount{} } +func (*BaseVestingAccount) ProtoMessage() {} +func (*BaseVestingAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_b7f744d63a45e116, []int{0} +} +func (m *BaseVestingAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BaseVestingAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BaseVestingAccount.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 *BaseVestingAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_BaseVestingAccount.Merge(m, src) +} +func (m *BaseVestingAccount) XXX_Size() int { + return m.Size() +} +func (m *BaseVestingAccount) XXX_DiscardUnknown() { + xxx_messageInfo_BaseVestingAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_BaseVestingAccount proto.InternalMessageInfo + +// ContinuousVestingAccount implements the VestingAccount interface. It +// continuously vests by unlocking coins linearly with respect to time. +type ContinuousVestingAccount struct { + *BaseVestingAccount `protobuf:"bytes,1,opt,name=base_vesting_account,json=baseVestingAccount,proto3,embedded=base_vesting_account" json:"base_vesting_account,omitempty"` + StartTime int64 `protobuf:"varint,2,opt,name=start_time,json=startTime,proto3" json:"start_time,omitempty" yaml:"start_time"` +} + +func (m *ContinuousVestingAccount) Reset() { *m = ContinuousVestingAccount{} } +func (*ContinuousVestingAccount) ProtoMessage() {} +func (*ContinuousVestingAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_b7f744d63a45e116, []int{1} +} +func (m *ContinuousVestingAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ContinuousVestingAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ContinuousVestingAccount.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 *ContinuousVestingAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_ContinuousVestingAccount.Merge(m, src) +} +func (m *ContinuousVestingAccount) XXX_Size() int { + return m.Size() +} +func (m *ContinuousVestingAccount) XXX_DiscardUnknown() { + xxx_messageInfo_ContinuousVestingAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_ContinuousVestingAccount proto.InternalMessageInfo + +// DelayedVestingAccount implements the VestingAccount interface. It vests all +// coins after a specific time, but non prior. In other words, it keeps them +// locked until a specified time. +type DelayedVestingAccount struct { + *BaseVestingAccount `protobuf:"bytes,1,opt,name=base_vesting_account,json=baseVestingAccount,proto3,embedded=base_vesting_account" json:"base_vesting_account,omitempty"` +} + +func (m *DelayedVestingAccount) Reset() { *m = DelayedVestingAccount{} } +func (*DelayedVestingAccount) ProtoMessage() {} +func (*DelayedVestingAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_b7f744d63a45e116, []int{2} +} +func (m *DelayedVestingAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DelayedVestingAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DelayedVestingAccount.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 *DelayedVestingAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_DelayedVestingAccount.Merge(m, src) +} +func (m *DelayedVestingAccount) XXX_Size() int { + return m.Size() +} +func (m *DelayedVestingAccount) XXX_DiscardUnknown() { + xxx_messageInfo_DelayedVestingAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_DelayedVestingAccount proto.InternalMessageInfo + +// Period defines a length of time and amount of coins that will vest +type Period struct { + Length int64 `protobuf:"varint,1,opt,name=length,proto3" json:"length,omitempty"` + Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"` +} + +func (m *Period) Reset() { *m = Period{} } +func (*Period) ProtoMessage() {} +func (*Period) Descriptor() ([]byte, []int) { + return fileDescriptor_b7f744d63a45e116, []int{3} +} +func (m *Period) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Period) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Period.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 *Period) XXX_Merge(src proto.Message) { + xxx_messageInfo_Period.Merge(m, src) +} +func (m *Period) XXX_Size() int { + return m.Size() +} +func (m *Period) XXX_DiscardUnknown() { + xxx_messageInfo_Period.DiscardUnknown(m) +} + +var xxx_messageInfo_Period proto.InternalMessageInfo + +func (m *Period) GetLength() int64 { + if m != nil { + return m.Length + } + return 0 +} + +func (m *Period) GetAmount() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Amount + } + return nil +} + +// PeriodicVestingAccount implements the VestingAccount interface. It +// periodically vests by unlocking coins during each specified period +type PeriodicVestingAccount struct { + *BaseVestingAccount `protobuf:"bytes,1,opt,name=base_vesting_account,json=baseVestingAccount,proto3,embedded=base_vesting_account" json:"base_vesting_account,omitempty"` + StartTime int64 `protobuf:"varint,2,opt,name=start_time,json=startTime,proto3" json:"start_time,omitempty" yaml:"start_time"` + VestingPeriods []Period `protobuf:"bytes,3,rep,name=vesting_periods,json=vestingPeriods,proto3" json:"vesting_periods" yaml:"vesting_periods"` +} + +func (m *PeriodicVestingAccount) Reset() { *m = PeriodicVestingAccount{} } +func (*PeriodicVestingAccount) ProtoMessage() {} +func (*PeriodicVestingAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_b7f744d63a45e116, []int{4} +} +func (m *PeriodicVestingAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PeriodicVestingAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PeriodicVestingAccount.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 *PeriodicVestingAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_PeriodicVestingAccount.Merge(m, src) +} +func (m *PeriodicVestingAccount) XXX_Size() int { + return m.Size() +} +func (m *PeriodicVestingAccount) XXX_DiscardUnknown() { + xxx_messageInfo_PeriodicVestingAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_PeriodicVestingAccount proto.InternalMessageInfo + +func init() { + proto.RegisterType((*BaseVestingAccount)(nil), "cosmos_sdk.x.auth.vesting.v1.BaseVestingAccount") + proto.RegisterType((*ContinuousVestingAccount)(nil), "cosmos_sdk.x.auth.vesting.v1.ContinuousVestingAccount") + proto.RegisterType((*DelayedVestingAccount)(nil), "cosmos_sdk.x.auth.vesting.v1.DelayedVestingAccount") + proto.RegisterType((*Period)(nil), "cosmos_sdk.x.auth.vesting.v1.Period") + proto.RegisterType((*PeriodicVestingAccount)(nil), "cosmos_sdk.x.auth.vesting.v1.PeriodicVestingAccount") +} + +func init() { proto.RegisterFile("x/auth/vesting/types/types.proto", fileDescriptor_b7f744d63a45e116) } + +var fileDescriptor_b7f744d63a45e116 = []byte{ + // 593 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x55, 0x4f, 0x8f, 0xd2, 0x40, + 0x1c, 0xed, 0x2c, 0x88, 0xeb, 0xa0, 0xcb, 0xd2, 0x15, 0x6c, 0x88, 0x69, 0xb1, 0x31, 0x86, 0x8b, + 0xd3, 0x65, 0xf5, 0xc4, 0xcd, 0xae, 0x31, 0xd1, 0xf5, 0x60, 0x1a, 0xe3, 0xc1, 0xc4, 0x34, 0x85, + 0x8e, 0x65, 0xb2, 0xb4, 0x43, 0x3a, 0x03, 0x59, 0x3e, 0xc0, 0x26, 0x26, 0x9b, 0x18, 0x8f, 0x1e, + 0xf7, 0xec, 0xcd, 0x8f, 0x60, 0xe2, 0x61, 0x8f, 0x1c, 0x3d, 0xa1, 0x81, 0x6f, 0xc0, 0x27, 0x30, + 0x74, 0x06, 0x58, 0xcb, 0x2e, 0xc9, 0x7a, 0x30, 0xf1, 0x02, 0x9d, 0x3f, 0xef, 0xfd, 0xde, 0xfb, + 0xcd, 0x9b, 0x16, 0x56, 0x8f, 0x2c, 0xaf, 0xc7, 0xdb, 0x56, 0x1f, 0x33, 0x4e, 0xa2, 0xc0, 0xe2, + 0x83, 0x2e, 0x66, 0xe2, 0x17, 0x75, 0x63, 0xca, 0xa9, 0x7a, 0xb7, 0x45, 0x59, 0x48, 0x99, 0xcb, + 0xfc, 0x43, 0x74, 0x84, 0x66, 0x9b, 0x91, 0xdc, 0x8c, 0xfa, 0xf5, 0xca, 0x03, 0xde, 0x26, 0xb1, + 0xef, 0x76, 0xbd, 0x98, 0x0f, 0xac, 0x04, 0x60, 0x05, 0x34, 0xa0, 0xcb, 0x27, 0xc1, 0x52, 0x29, + 0xae, 0x10, 0x57, 0x34, 0x59, 0x7a, 0x65, 0xc5, 0xfc, 0x96, 0x85, 0xaa, 0xed, 0x31, 0xfc, 0x46, + 0xd4, 0x79, 0xd2, 0x6a, 0xd1, 0x5e, 0xc4, 0xd5, 0x17, 0xf0, 0x66, 0xd3, 0x63, 0xd8, 0xf5, 0xc4, + 0x58, 0x03, 0x55, 0x50, 0xcb, 0xef, 0xdd, 0x43, 0x17, 0x08, 0xac, 0xa3, 0x19, 0x5e, 0x02, 0xed, + 0xec, 0x70, 0x64, 0x00, 0x27, 0xdf, 0x5c, 0x4e, 0xa9, 0x27, 0x00, 0x6e, 0xd3, 0x98, 0x04, 0x24, + 0xf2, 0x3a, 0xae, 0xf4, 0xa3, 0x6d, 0x54, 0x33, 0xb5, 0xfc, 0xde, 0xce, 0x79, 0xc2, 0x7e, 0x1d, + 0xed, 0x53, 0x12, 0xd9, 0x07, 0x67, 0x23, 0x43, 0x99, 0x8e, 0x8c, 0x3b, 0x03, 0x2f, 0xec, 0x34, + 0xcc, 0x34, 0xd4, 0xfc, 0xf2, 0xd3, 0xa8, 0x05, 0x84, 0xb7, 0x7b, 0x4d, 0xd4, 0xa2, 0xa1, 0x25, + 0x18, 0xe4, 0xdf, 0x43, 0xe6, 0x1f, 0x4a, 0x7f, 0x33, 0x2e, 0xe6, 0x14, 0xe6, 0x70, 0x69, 0x50, + 0x3d, 0x06, 0x70, 0xcb, 0xc7, 0x1d, 0x1c, 0x78, 0x1c, 0xfb, 0xee, 0xfb, 0x18, 0x63, 0x2d, 0x73, + 0xb9, 0x96, 0xe7, 0x52, 0x4b, 0x49, 0x68, 0xf9, 0x13, 0x78, 0x35, 0x25, 0xb7, 0x16, 0xe0, 0x67, + 0x31, 0xc6, 0xea, 0x47, 0x00, 0x8b, 0x4b, 0xba, 0x79, 0x5b, 0xb2, 0x97, 0x4b, 0x79, 0x29, 0xa5, + 0x68, 0x69, 0x29, 0x7f, 0xd5, 0x97, 0xed, 0x05, 0x7e, 0xde, 0x18, 0x04, 0x37, 0x71, 0xe4, 0xbb, + 0x9c, 0x84, 0x58, 0xbb, 0x56, 0x05, 0xb5, 0x8c, 0xbd, 0x33, 0x1d, 0x19, 0x05, 0x51, 0x6d, 0xbe, + 0x62, 0x3a, 0xd7, 0x71, 0xe4, 0xbf, 0x26, 0x21, 0x6e, 0x6c, 0x7e, 0x38, 0x35, 0x94, 0xcf, 0xa7, + 0x86, 0x62, 0x7e, 0x07, 0x50, 0xdb, 0xa7, 0x11, 0x27, 0x51, 0x8f, 0xf6, 0x58, 0x2a, 0x49, 0x6d, + 0x78, 0x3b, 0x49, 0x92, 0x54, 0x99, 0x4a, 0xd4, 0x2e, 0x5a, 0x17, 0x79, 0xb4, 0x9a, 0x4c, 0x19, + 0x30, 0xb5, 0xb9, 0x9a, 0xd9, 0xc7, 0x10, 0x32, 0xee, 0xc5, 0x5c, 0x58, 0xd8, 0x48, 0x2c, 0x94, + 0xa6, 0x23, 0xa3, 0x28, 0x2c, 0x2c, 0xd7, 0x4c, 0xe7, 0x46, 0x32, 0x48, 0xd9, 0x38, 0x01, 0xb0, + 0xf4, 0x14, 0x77, 0xbc, 0xc1, 0xa2, 0x27, 0xff, 0xdc, 0xc3, 0x39, 0x35, 0xc7, 0x00, 0xe6, 0x5e, + 0xe1, 0x98, 0x50, 0x5f, 0x2d, 0xc3, 0x5c, 0x07, 0x47, 0x01, 0x6f, 0x27, 0x05, 0x33, 0x8e, 0x1c, + 0xa9, 0xef, 0x60, 0xce, 0x0b, 0x13, 0x21, 0x6b, 0x6e, 0xd3, 0xee, 0x2c, 0x36, 0x57, 0x8a, 0x86, + 0x24, 0x6d, 0x64, 0x13, 0x1d, 0x5f, 0x37, 0x60, 0x59, 0xe8, 0x20, 0xad, 0xff, 0xeb, 0x68, 0xd5, + 0x10, 0x16, 0xe6, 0xd2, 0xba, 0x89, 0x03, 0x26, 0xaf, 0xfa, 0xfd, 0xf5, 0xd2, 0x84, 0x5d, 0x5b, + 0x97, 0x17, 0xae, 0x2c, 0x8a, 0xa4, 0xa8, 0x4c, 0x67, 0x4b, 0xce, 0x88, 0xed, 0x6c, 0x79, 0x76, + 0xf6, 0xc1, 0xd9, 0x58, 0x07, 0xc3, 0xb1, 0x0e, 0x7e, 0x8d, 0x75, 0xf0, 0x69, 0xa2, 0x2b, 0xc3, + 0x89, 0xae, 0xfc, 0x98, 0xe8, 0xca, 0xdb, 0xfa, 0xda, 0x53, 0xb8, 0xe8, 0x03, 0xd1, 0xcc, 0x25, + 0x2f, 0xea, 0x47, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x89, 0x54, 0xae, 0x4f, 0x3f, 0x06, 0x00, + 0x00, +} + +func (m *BaseVestingAccount) 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 *BaseVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BaseVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.EndTime != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.EndTime)) + i-- + dAtA[i] = 0x28 + } + if len(m.DelegatedVesting) > 0 { + for iNdEx := len(m.DelegatedVesting) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.DelegatedVesting[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if len(m.DelegatedFree) > 0 { + for iNdEx := len(m.DelegatedFree) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.DelegatedFree[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.OriginalVesting) > 0 { + for iNdEx := len(m.OriginalVesting) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.OriginalVesting[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if m.BaseAccount != nil { + { + size, err := m.BaseAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ContinuousVestingAccount) 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 *ContinuousVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ContinuousVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.StartTime != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.StartTime)) + i-- + dAtA[i] = 0x10 + } + if m.BaseVestingAccount != nil { + { + size, err := m.BaseVestingAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *DelayedVestingAccount) 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 *DelayedVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DelayedVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BaseVestingAccount != nil { + { + size, err := m.BaseVestingAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Period) 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 *Period) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Period) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Amount) > 0 { + for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if m.Length != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Length)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *PeriodicVestingAccount) 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 *PeriodicVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PeriodicVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.VestingPeriods) > 0 { + for iNdEx := len(m.VestingPeriods) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.VestingPeriods[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.StartTime != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.StartTime)) + i-- + dAtA[i] = 0x10 + } + if m.BaseVestingAccount != nil { + { + size, err := m.BaseVestingAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *BaseVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BaseAccount != nil { + l = m.BaseAccount.Size() + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.OriginalVesting) > 0 { + for _, e := range m.OriginalVesting { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + if len(m.DelegatedFree) > 0 { + for _, e := range m.DelegatedFree { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + if len(m.DelegatedVesting) > 0 { + for _, e := range m.DelegatedVesting { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + if m.EndTime != 0 { + n += 1 + sovTypes(uint64(m.EndTime)) + } + return n +} + +func (m *ContinuousVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BaseVestingAccount != nil { + l = m.BaseVestingAccount.Size() + n += 1 + l + sovTypes(uint64(l)) + } + if m.StartTime != 0 { + n += 1 + sovTypes(uint64(m.StartTime)) + } + return n +} + +func (m *DelayedVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BaseVestingAccount != nil { + l = m.BaseVestingAccount.Size() + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *Period) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Length != 0 { + n += 1 + sovTypes(uint64(m.Length)) + } + if len(m.Amount) > 0 { + for _, e := range m.Amount { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *PeriodicVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BaseVestingAccount != nil { + l = m.BaseVestingAccount.Size() + n += 1 + l + sovTypes(uint64(l)) + } + if m.StartTime != 0 { + n += 1 + sovTypes(uint64(m.StartTime)) + } + if len(m.VestingPeriods) > 0 { + for _, e := range m.VestingPeriods { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *BaseVestingAccount) 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 ErrIntOverflowTypes + } + 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: BaseVestingAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BaseVestingAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.BaseAccount == nil { + m.BaseAccount = &types.BaseAccount{} + } + if err := m.BaseAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OriginalVesting", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OriginalVesting = append(m.OriginalVesting, types1.Coin{}) + if err := m.OriginalVesting[len(m.OriginalVesting)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatedFree", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatedFree = append(m.DelegatedFree, types1.Coin{}) + if err := m.DelegatedFree[len(m.DelegatedFree)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatedVesting", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatedVesting = append(m.DelegatedVesting, types1.Coin{}) + if err := m.DelegatedVesting[len(m.DelegatedVesting)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EndTime", wireType) + } + m.EndTime = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EndTime |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ContinuousVestingAccount) 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 ErrIntOverflowTypes + } + 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: ContinuousVestingAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ContinuousVestingAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseVestingAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.BaseVestingAccount == nil { + m.BaseVestingAccount = &BaseVestingAccount{} + } + if err := m.BaseVestingAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) + } + m.StartTime = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StartTime |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DelayedVestingAccount) 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 ErrIntOverflowTypes + } + 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: DelayedVestingAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DelayedVestingAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseVestingAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.BaseVestingAccount == nil { + m.BaseVestingAccount = &BaseVestingAccount{} + } + if err := m.BaseVestingAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Period) 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 ErrIntOverflowTypes + } + 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: Period: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Period: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Length", wireType) + } + m.Length = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Length |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Amount = append(m.Amount, types1.Coin{}) + if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PeriodicVestingAccount) 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 ErrIntOverflowTypes + } + 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: PeriodicVestingAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PeriodicVestingAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseVestingAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.BaseVestingAccount == nil { + m.BaseVestingAccount = &BaseVestingAccount{} + } + if err := m.BaseVestingAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) + } + m.StartTime = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StartTime |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VestingPeriods", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.VestingPeriods = append(m.VestingPeriods, Period{}) + if err := m.VestingPeriods[len(m.VestingPeriods)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTypes(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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrInvalidLengthTypes + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTypes + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTypes + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/auth/vesting/types/types.proto b/x/auth/vesting/types/types.proto new file mode 100644 index 000000000000..7ce129553289 --- /dev/null +++ b/x/auth/vesting/types/types.proto @@ -0,0 +1,76 @@ +syntax = "proto3"; +package cosmos_sdk.x.auth.vesting.v1; + +import "third_party/proto/gogoproto/gogo.proto"; +import "types/types.proto"; +import "x/auth/types/types.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"; + +// BaseVestingAccount implements the VestingAccount interface. It contains all +// the necessary fields needed for any vesting account implementation. +message BaseVestingAccount { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + cosmos_sdk.x.auth.v1.BaseAccount base_account = 1 [(gogoproto.embed) = true]; + repeated cosmos_sdk.v1.Coin original_vesting = 2 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", + (gogoproto.moretags) = "yaml:\"original_vesting\"" + ]; + repeated cosmos_sdk.v1.Coin delegated_free = 3 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", + (gogoproto.moretags) = "yaml:\"delegated_free\"" + ]; + repeated cosmos_sdk.v1.Coin delegated_vesting = 4 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", + (gogoproto.moretags) = "yaml:\"delegated_vesting\"" + ]; + int64 end_time = 5 [(gogoproto.moretags) = "yaml:\"end_time\""]; +} + +// ContinuousVestingAccount implements the VestingAccount interface. It +// continuously vests by unlocking coins linearly with respect to time. +message ContinuousVestingAccount { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + BaseVestingAccount base_vesting_account = 1 [(gogoproto.embed) = true]; + int64 start_time = 2 [(gogoproto.moretags) = "yaml:\"start_time\""]; +} + +// DelayedVestingAccount implements the VestingAccount interface. It vests all +// coins after a specific time, but non prior. In other words, it keeps them +// locked until a specified time. +message DelayedVestingAccount { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + BaseVestingAccount base_vesting_account = 1 [(gogoproto.embed) = true]; +} + +// Period defines a length of time and amount of coins that will vest +message Period { + option (gogoproto.goproto_stringer) = false; + + int64 length = 1; + repeated cosmos_sdk.v1.Coin amount = 2 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} + +// PeriodicVestingAccount implements the VestingAccount interface. It +// periodically vests by unlocking coins during each specified period +message PeriodicVestingAccount { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + BaseVestingAccount base_vesting_account = 1 [(gogoproto.embed) = true]; + int64 start_time = 2 [(gogoproto.moretags) = "yaml:\"start_time\""]; + repeated Period vesting_periods = 3 + [(gogoproto.moretags) = "yaml:\"vesting_periods\"", (gogoproto.nullable) = false]; +} diff --git a/x/auth/vesting/types/vesting_account.go b/x/auth/vesting/types/vesting_account.go index 70efad2b33ef..cbbeffc03143 100644 --- a/x/auth/vesting/types/vesting_account.go +++ b/x/auth/vesting/types/vesting_account.go @@ -22,24 +22,8 @@ var ( _ vestexported.VestingAccount = (*DelayedVestingAccount)(nil) ) -// Register the vesting account types on the auth module codec -func init() { - authtypes.RegisterAccountTypeCodec(&BaseVestingAccount{}, "cosmos-sdk/BaseVestingAccount") - authtypes.RegisterAccountTypeCodec(&ContinuousVestingAccount{}, "cosmos-sdk/ContinuousVestingAccount") - authtypes.RegisterAccountTypeCodec(&DelayedVestingAccount{}, "cosmos-sdk/DelayedVestingAccount") - authtypes.RegisterAccountTypeCodec(&PeriodicVestingAccount{}, "cosmos-sdk/PeriodicVestingAccount") -} - -// BaseVestingAccount implements the VestingAccount interface. It contains all -// the necessary fields needed for any vesting account implementation. -type BaseVestingAccount struct { - *authtypes.BaseAccount - - OriginalVesting sdk.Coins `json:"original_vesting" yaml:"original_vesting"` // coins in account upon initialization - DelegatedFree sdk.Coins `json:"delegated_free" yaml:"delegated_free"` // coins that are vested and delegated - DelegatedVesting sdk.Coins `json:"delegated_vesting" yaml:"delegated_vesting"` // coins that vesting and delegated - EndTime int64 `json:"end_time" yaml:"end_time"` // when the coins become unlocked -} +//----------------------------------------------------------------------------- +// Base Vesting Account // NewBaseVestingAccount creates a new BaseVestingAccount object. It is the // callers responsibility to ensure the base account has sufficient funds with @@ -204,6 +188,7 @@ func (bva BaseVestingAccount) String() string { func (bva BaseVestingAccount) MarshalYAML() (interface{}, error) { alias := vestingAccountPretty{ Address: bva.Address, + PubKey: bva.PubKey, AccountNumber: bva.AccountNumber, Sequence: bva.Sequence, OriginalVesting: bva.OriginalVesting, @@ -212,15 +197,6 @@ func (bva BaseVestingAccount) MarshalYAML() (interface{}, error) { EndTime: bva.EndTime, } - if bva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, bva.PubKey) - if err != nil { - return nil, err - } - - alias.PubKey = pks - } - bz, err := yaml.Marshal(alias) if err != nil { return nil, err @@ -233,6 +209,7 @@ func (bva BaseVestingAccount) MarshalYAML() (interface{}, error) { func (bva BaseVestingAccount) MarshalJSON() ([]byte, error) { alias := vestingAccountPretty{ Address: bva.Address, + PubKey: bva.PubKey, AccountNumber: bva.AccountNumber, Sequence: bva.Sequence, OriginalVesting: bva.OriginalVesting, @@ -241,15 +218,6 @@ func (bva BaseVestingAccount) MarshalJSON() ([]byte, error) { EndTime: bva.EndTime, } - if bva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, bva.PubKey) - if err != nil { - return nil, err - } - - alias.PubKey = pks - } - return json.Marshal(alias) } @@ -287,14 +255,6 @@ func (bva *BaseVestingAccount) UnmarshalJSON(bz []byte) error { var _ vestexported.VestingAccount = (*ContinuousVestingAccount)(nil) var _ authexported.GenesisAccount = (*ContinuousVestingAccount)(nil) -// ContinuousVestingAccount implements the VestingAccount interface. It -// continuously vests by unlocking coins linearly with respect to time. -type ContinuousVestingAccount struct { - *BaseVestingAccount - - StartTime int64 `json:"start_time" yaml:"start_time"` // when the coins start to vest -} - // NewContinuousVestingAccountRaw creates a new ContinuousVestingAccount object from BaseVestingAccount func NewContinuousVestingAccountRaw(bva *BaseVestingAccount, startTime int64) *ContinuousVestingAccount { return &ContinuousVestingAccount{ @@ -386,6 +346,7 @@ func (cva ContinuousVestingAccount) String() string { func (cva ContinuousVestingAccount) MarshalYAML() (interface{}, error) { alias := vestingAccountPretty{ Address: cva.Address, + PubKey: cva.PubKey, AccountNumber: cva.AccountNumber, Sequence: cva.Sequence, OriginalVesting: cva.OriginalVesting, @@ -395,15 +356,6 @@ func (cva ContinuousVestingAccount) MarshalYAML() (interface{}, error) { StartTime: cva.StartTime, } - if cva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, cva.PubKey) - if err != nil { - return nil, err - } - - alias.PubKey = pks - } - bz, err := yaml.Marshal(alias) if err != nil { return nil, err @@ -416,6 +368,7 @@ func (cva ContinuousVestingAccount) MarshalYAML() (interface{}, error) { func (cva ContinuousVestingAccount) MarshalJSON() ([]byte, error) { alias := vestingAccountPretty{ Address: cva.Address, + PubKey: cva.PubKey, AccountNumber: cva.AccountNumber, Sequence: cva.Sequence, OriginalVesting: cva.OriginalVesting, @@ -425,15 +378,6 @@ func (cva ContinuousVestingAccount) MarshalJSON() ([]byte, error) { StartTime: cva.StartTime, } - if cva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, cva.PubKey) - if err != nil { - return nil, err - } - - alias.PubKey = pks - } - return json.Marshal(alias) } @@ -474,14 +418,6 @@ func (cva *ContinuousVestingAccount) UnmarshalJSON(bz []byte) error { var _ vestexported.VestingAccount = (*PeriodicVestingAccount)(nil) var _ authexported.GenesisAccount = (*PeriodicVestingAccount)(nil) -// PeriodicVestingAccount implements the VestingAccount interface. It -// periodically vests by unlocking coins during each specified period -type PeriodicVestingAccount struct { - *BaseVestingAccount - StartTime int64 `json:"start_time" yaml:"start_time"` // when the coins start to vest - VestingPeriods Periods `json:"vesting_periods" yaml:"vesting_periods"` // the vesting schedule -} - // NewPeriodicVestingAccountRaw creates a new PeriodicVestingAccount object from BaseVestingAccount func NewPeriodicVestingAccountRaw(bva *BaseVestingAccount, startTime int64, periods Periods) *PeriodicVestingAccount { return &PeriodicVestingAccount{ @@ -602,6 +538,7 @@ func (pva PeriodicVestingAccount) String() string { func (pva PeriodicVestingAccount) MarshalYAML() (interface{}, error) { alias := vestingAccountPretty{ Address: pva.Address, + PubKey: pva.PubKey, AccountNumber: pva.AccountNumber, Sequence: pva.Sequence, OriginalVesting: pva.OriginalVesting, @@ -612,15 +549,6 @@ func (pva PeriodicVestingAccount) MarshalYAML() (interface{}, error) { VestingPeriods: pva.VestingPeriods, } - if pva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pva.PubKey) - if err != nil { - return nil, err - } - - alias.PubKey = pks - } - bz, err := yaml.Marshal(alias) if err != nil { return nil, err @@ -633,6 +561,7 @@ func (pva PeriodicVestingAccount) MarshalYAML() (interface{}, error) { func (pva PeriodicVestingAccount) MarshalJSON() ([]byte, error) { alias := vestingAccountPretty{ Address: pva.Address, + PubKey: pva.PubKey, AccountNumber: pva.AccountNumber, Sequence: pva.Sequence, OriginalVesting: pva.OriginalVesting, @@ -643,15 +572,6 @@ func (pva PeriodicVestingAccount) MarshalJSON() ([]byte, error) { VestingPeriods: pva.VestingPeriods, } - if pva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pva.PubKey) - if err != nil { - return nil, err - } - - alias.PubKey = pks - } - return json.Marshal(alias) } @@ -693,13 +613,6 @@ func (pva *PeriodicVestingAccount) UnmarshalJSON(bz []byte) error { var _ vestexported.VestingAccount = (*DelayedVestingAccount)(nil) var _ authexported.GenesisAccount = (*DelayedVestingAccount)(nil) -// DelayedVestingAccount implements the VestingAccount interface. It vests all -// coins after a specific time, but non prior. In other words, it keeps them -// locked until a specified time. -type DelayedVestingAccount struct { - *BaseVestingAccount -} - // NewDelayedVestingAccountRaw creates a new DelayedVestingAccount object from BaseVestingAccount func NewDelayedVestingAccountRaw(bva *BaseVestingAccount) *DelayedVestingAccount { return &DelayedVestingAccount{ @@ -756,10 +669,16 @@ func (dva DelayedVestingAccount) Validate() error { return dva.BaseVestingAccount.Validate() } +func (dva DelayedVestingAccount) String() string { + out, _ := dva.MarshalYAML() + return out.(string) +} + // MarshalJSON returns the JSON representation of a DelayedVestingAccount. func (dva DelayedVestingAccount) MarshalJSON() ([]byte, error) { alias := vestingAccountPretty{ Address: dva.Address, + PubKey: dva.PubKey, AccountNumber: dva.AccountNumber, Sequence: dva.Sequence, OriginalVesting: dva.OriginalVesting, @@ -768,15 +687,6 @@ func (dva DelayedVestingAccount) MarshalJSON() ([]byte, error) { EndTime: dva.EndTime, } - if dva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, dva.PubKey) - if err != nil { - return nil, err - } - - alias.PubKey = pks - } - return json.Marshal(alias) } diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index 4555d329e625..e36661111fef 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -1,4 +1,4 @@ -package types +package types_test import ( "encoding/json" @@ -13,6 +13,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" ) var ( @@ -24,10 +25,10 @@ func TestGetVestedCoinsContVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) - cva := NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) // require no coins vested in the very beginning of the vesting schedule vestedCoins := cva.GetVestedCoins(now) @@ -50,10 +51,10 @@ func TestGetVestingCoinsContVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) - cva := NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) // require all coins vesting in the beginning of the vesting schedule vestingCoins := cva.GetVestingCoins(now) @@ -72,11 +73,11 @@ func TestSpendableCoinsContVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) - cva := NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) // require that all original coins are locked at the end of the vesting // schedule @@ -100,24 +101,24 @@ func TestTrackDelegationContVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require the ability to delegate all vesting coins - cva := NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) cva.TrackDelegation(now, origCoins, origCoins) require.Equal(t, origCoins, cva.DelegatedVesting) require.Nil(t, cva.DelegatedFree) // require the ability to delegate all vested coins - cva = NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) cva.TrackDelegation(endTime, origCoins, origCoins) require.Nil(t, cva.DelegatedVesting) require.Equal(t, origCoins, cva.DelegatedFree) // require the ability to delegate all vesting coins (50%) and all vested coins (50%) - cva = NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) cva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, cva.DelegatedVesting) require.Nil(t, cva.DelegatedFree) @@ -127,7 +128,7 @@ func TestTrackDelegationContVestingAcc(t *testing.T) { require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, cva.DelegatedFree) // require no modifications when delegation amount is zero or not enough funds - cva = NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) require.Panics(t, func() { cva.TrackDelegation(endTime, origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 1000000)}) }) @@ -139,19 +140,19 @@ func TestTrackUndelegationContVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require the ability to undelegate all vesting coins - cva := NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) cva.TrackDelegation(now, origCoins, origCoins) cva.TrackUndelegation(origCoins) require.Nil(t, cva.DelegatedFree) require.Nil(t, cva.DelegatedVesting) // require the ability to undelegate all vested coins - cva = NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) cva.TrackDelegation(endTime, origCoins, origCoins) cva.TrackUndelegation(origCoins) @@ -159,7 +160,7 @@ func TestTrackUndelegationContVestingAcc(t *testing.T) { require.Nil(t, cva.DelegatedVesting) // require no modifications when the undelegation amount is zero - cva = NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) require.Panics(t, func() { cva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 0)}) @@ -168,7 +169,7 @@ func TestTrackUndelegationContVestingAcc(t *testing.T) { require.Nil(t, cva.DelegatedVesting) // vest 50% and delegate to two validators - cva = NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) cva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) cva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) @@ -187,12 +188,12 @@ func TestGetVestedCoinsDelVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require no coins are vested until schedule maturation - dva := NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) vestedCoins := dva.GetVestedCoins(now) require.Nil(t, vestedCoins) @@ -205,12 +206,12 @@ func TestGetVestingCoinsDelVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require all coins vesting at the beginning of the schedule - dva := NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) vestingCoins := dva.GetVestingCoins(now) require.Equal(t, origCoins, vestingCoins) @@ -223,13 +224,13 @@ func TestSpendableCoinsDelVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require that all coins are locked in the beginning of the vesting // schedule - dva := NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) lockedCoins := dva.LockedCoins(now) require.True(t, lockedCoins.IsEqual(origCoins)) @@ -260,31 +261,31 @@ func TestTrackDelegationDelVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require the ability to delegate all vesting coins - dva := NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) dva.TrackDelegation(now, origCoins, origCoins) require.Equal(t, origCoins, dva.DelegatedVesting) require.Nil(t, dva.DelegatedFree) // require the ability to delegate all vested coins - dva = NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) dva.TrackDelegation(endTime, origCoins, origCoins) require.Nil(t, dva.DelegatedVesting) require.Equal(t, origCoins, dva.DelegatedFree) // require the ability to delegate all coins half way through the vesting // schedule - dva = NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) dva.TrackDelegation(now.Add(12*time.Hour), origCoins, origCoins) require.Equal(t, origCoins, dva.DelegatedVesting) require.Nil(t, dva.DelegatedFree) // require no modifications when delegation amount is zero or not enough funds - dva = NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) require.Panics(t, func() { dva.TrackDelegation(endTime, origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 1000000)}) @@ -297,26 +298,26 @@ func TestTrackUndelegationDelVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require the ability to undelegate all vesting coins - dva := NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) dva.TrackDelegation(now, origCoins, origCoins) dva.TrackUndelegation(origCoins) require.Nil(t, dva.DelegatedFree) require.Nil(t, dva.DelegatedVesting) // require the ability to undelegate all vested coins - dva = NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) dva.TrackDelegation(endTime, origCoins, origCoins) dva.TrackUndelegation(origCoins) require.Nil(t, dva.DelegatedFree) require.Nil(t, dva.DelegatedVesting) // require no modifications when the undelegation amount is zero - dva = NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) require.Panics(t, func() { dva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 0)}) @@ -325,7 +326,7 @@ func TestTrackUndelegationDelVestingAcc(t *testing.T) { require.Nil(t, dva.DelegatedVesting) // vest 50% and delegate to two validators - dva = NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) dva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) dva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) @@ -344,16 +345,16 @@ func TestTrackUndelegationDelVestingAcc(t *testing.T) { func TestGetVestedCoinsPeriodicVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - periods := Periods{ - Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + periods := types.Periods{ + types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, } - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) - pva := NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) // require no coins vested at the beginning of the vesting schedule vestedCoins := pva.GetVestedCoins(now) @@ -389,17 +390,17 @@ func TestGetVestedCoinsPeriodicVestingAcc(t *testing.T) { func TestGetVestingCoinsPeriodicVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - periods := Periods{ - Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + periods := types.Periods{ + types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, } - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{ sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) - pva := NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) // require all coins vesting at the beginning of the vesting schedule vestingCoins := pva.GetVestingCoins(now) @@ -429,17 +430,17 @@ func TestGetVestingCoinsPeriodicVestingAcc(t *testing.T) { func TestSpendableCoinsPeriodicVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - periods := Periods{ - Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + periods := types.Periods{ + types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, } - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{ sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) - pva := NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) // require that there exist no spendable coins at the beginning of the // vesting schedule @@ -464,44 +465,44 @@ func TestSpendableCoinsPeriodicVestingAcc(t *testing.T) { func TestTrackDelegationPeriodicVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - periods := Periods{ - Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + periods := types.Periods{ + types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, } - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require the ability to delegate all vesting coins - pva := NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(now, origCoins, origCoins) require.Equal(t, origCoins, pva.DelegatedVesting) require.Nil(t, pva.DelegatedFree) // require the ability to delegate all vested coins - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(endTime, origCoins, origCoins) require.Nil(t, pva.DelegatedVesting) require.Equal(t, origCoins, pva.DelegatedFree) // delegate half of vesting coins - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(now, origCoins, periods[0].Amount) // require that all delegated coins are delegated vesting require.Equal(t, pva.DelegatedVesting, periods[0].Amount) require.Nil(t, pva.DelegatedFree) // delegate 75% of coins, split between vested and vesting - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(now.Add(12*time.Hour), origCoins, periods[0].Amount.Add(periods[1].Amount...)) // require that the maximum possible amount of vesting coins are chosen for delegation. require.Equal(t, pva.DelegatedFree, periods[1].Amount) require.Equal(t, pva.DelegatedVesting, periods[0].Amount) // require the ability to delegate all vesting coins (50%) and all vested coins (50%) - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, pva.DelegatedVesting) require.Nil(t, pva.DelegatedFree) @@ -511,7 +512,7 @@ func TestTrackDelegationPeriodicVestingAcc(t *testing.T) { require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, pva.DelegatedFree) // require no modifications when delegation amount is zero or not enough funds - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) require.Panics(t, func() { pva.TrackDelegation(endTime, origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 1000000)}) }) @@ -522,25 +523,25 @@ func TestTrackDelegationPeriodicVestingAcc(t *testing.T) { func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - periods := Periods{ - Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + periods := types.Periods{ + types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, } - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require the ability to undelegate all vesting coins at the beginning of vesting - pva := NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(now, origCoins, origCoins) pva.TrackUndelegation(origCoins) require.Nil(t, pva.DelegatedFree) require.Nil(t, pva.DelegatedVesting) // require the ability to undelegate all vested coins at the end of vesting - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(endTime, origCoins, origCoins) pva.TrackUndelegation(origCoins) @@ -548,14 +549,14 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { require.Nil(t, pva.DelegatedVesting) // require the ability to undelegate half of coins - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(endTime, origCoins, periods[0].Amount) pva.TrackUndelegation(periods[0].Amount) require.Nil(t, pva.DelegatedFree) require.Nil(t, pva.DelegatedVesting) // require no modifications when the undelegation amount is zero - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) require.Panics(t, func() { pva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 0)}) @@ -564,7 +565,7 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { require.Nil(t, pva.DelegatedVesting) // vest 50% and delegate to two validators - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) pva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) @@ -579,42 +580,12 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 25)}, pva.DelegatedVesting) } -// TODO: Move test to bank -// func TestNewBaseVestingAccount(t *testing.T) { -// pubkey := secp256k1.GenPrivKey().PubKey() -// addr := sdk.AccAddress(pubkey.Address()) -// _, err := NewBaseVestingAccount( -// authtypes.NewBaseAccount(addr, sdk.NewCoins(), pubkey, 0, 0), -// sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}, 100, -// ) -// require.Equal(t, errors.New("vesting amount cannot be greater than total amount"), err) - -// _, err = NewBaseVestingAccount( -// authtypes.NewBaseAccount(addr, sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 10)), pubkey, 0, 0), -// sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}, 100, -// ) -// require.Equal(t, errors.New("vesting amount cannot be greater than total amount"), err) - -// _, err = NewBaseVestingAccount( -// authtypes.NewBaseAccount(addr, sdk.NewCoins(sdk.NewInt64Coin("uatom", 50), sdk.NewInt64Coin("eth", 50)), pubkey, 0, 0), -// sdk.NewCoins(sdk.NewInt64Coin("uatom", 100), sdk.NewInt64Coin("eth", 20)), 100, -// ) -// require.Equal(t, errors.New("vesting amount cannot be greater than total amount"), err) - -// _, err = NewBaseVestingAccount( -// authtypes.NewBaseAccount(addr, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}, pubkey, 0, 0), -// sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}, 100, -// ) -// require.NoError(t, err) - -// } - func TestGenesisAccountValidate(t *testing.T) { pubkey := secp256k1.GenPrivKey().PubKey() addr := sdk.AccAddress(pubkey.Address()) baseAcc := authtypes.NewBaseAccount(addr, pubkey, 0, 0) initialVesting := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)) - baseVestingWithCoins := NewBaseVestingAccount(baseAcc, initialVesting, 100) + baseVestingWithCoins := types.NewBaseVestingAccount(baseAcc, initialVesting, 100) tests := []struct { name string acc authexported.GenesisAccount @@ -637,31 +608,31 @@ func TestGenesisAccountValidate(t *testing.T) { }, { "valid continuous vesting account", - NewContinuousVestingAccount(baseAcc, initialVesting, 100, 200), + types.NewContinuousVestingAccount(baseAcc, initialVesting, 100, 200), nil, }, { "invalid vesting times", - NewContinuousVestingAccount(baseAcc, initialVesting, 1654668078, 1554668078), + types.NewContinuousVestingAccount(baseAcc, initialVesting, 1654668078, 1554668078), errors.New("vesting start-time cannot be before end-time"), }, { "valid periodic vesting account", - NewPeriodicVestingAccount(baseAcc, initialVesting, 0, Periods{Period{Length: int64(100), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}}}), + types.NewPeriodicVestingAccount(baseAcc, initialVesting, 0, types.Periods{types.Period{Length: int64(100), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}}}), nil, }, { "invalid vesting period lengths", - NewPeriodicVestingAccountRaw( + types.NewPeriodicVestingAccountRaw( baseVestingWithCoins, - 0, Periods{Period{Length: int64(50), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}}}), + 0, types.Periods{types.Period{Length: int64(50), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}}}), errors.New("vesting end time does not match length of all vesting periods"), }, { "invalid vesting period amounts", - NewPeriodicVestingAccountRaw( + types.NewPeriodicVestingAccountRaw( baseVestingWithCoins, - 0, Periods{Period{Length: int64(100), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 25)}}}), + 0, types.Periods{types.Period{Length: int64(100), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 25)}}}), errors.New("original vesting coins does not match the sum of all coins in vesting periods"), }, } @@ -680,7 +651,7 @@ func TestBaseVestingAccountJSON(t *testing.T) { coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5)) baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50) - acc := NewBaseVestingAccount(baseAcc, coins, time.Now().Unix()) + acc := types.NewBaseVestingAccount(baseAcc, coins, time.Now().Unix()) bz, err := json.Marshal(acc) require.NoError(t, err) @@ -689,19 +660,41 @@ func TestBaseVestingAccountJSON(t *testing.T) { require.NoError(t, err) require.Equal(t, string(bz1), string(bz)) - var a BaseVestingAccount + var a types.BaseVestingAccount require.NoError(t, json.Unmarshal(bz, &a)) require.Equal(t, acc.String(), a.String()) } +func TestContinuousVestingAccountMarshal(t *testing.T) { + pubkey := secp256k1.GenPrivKey().PubKey() + addr := sdk.AccAddress(pubkey.Address()) + coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5)) + baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50) + + baseVesting := types.NewBaseVestingAccount(baseAcc, coins, time.Now().Unix()) + acc := types.NewContinuousVestingAccountRaw(baseVesting, baseVesting.EndTime) + + bz, err := appCodec.MarshalAccount(acc) + require.Nil(t, err) + + acc2, err := appCodec.UnmarshalAccount(bz) + require.Nil(t, err) + require.IsType(t, &types.ContinuousVestingAccount{}, acc2) + require.Equal(t, acc.String(), acc2.String()) + + // error on bad bytes + _, err = appCodec.UnmarshalAccount(bz[:len(bz)/2]) + require.NotNil(t, err) +} + func TestContinuousVestingAccountJSON(t *testing.T) { pubkey := secp256k1.GenPrivKey().PubKey() addr := sdk.AccAddress(pubkey.Address()) coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5)) baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50) - baseVesting := NewBaseVestingAccount(baseAcc, coins, time.Now().Unix()) - acc := NewContinuousVestingAccountRaw(baseVesting, baseVesting.EndTime) + baseVesting := types.NewBaseVestingAccount(baseAcc, coins, time.Now().Unix()) + acc := types.NewContinuousVestingAccountRaw(baseVesting, baseVesting.EndTime) bz, err := json.Marshal(acc) require.NoError(t, err) @@ -710,18 +703,39 @@ func TestContinuousVestingAccountJSON(t *testing.T) { require.NoError(t, err) require.Equal(t, string(bz1), string(bz)) - var a ContinuousVestingAccount + var a types.ContinuousVestingAccount require.NoError(t, json.Unmarshal(bz, &a)) require.Equal(t, acc.String(), a.String()) } +func TestPeriodicVestingAccountMarshal(t *testing.T) { + pubkey := secp256k1.GenPrivKey().PubKey() + addr := sdk.AccAddress(pubkey.Address()) + coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5)) + baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50) + + acc := types.NewPeriodicVestingAccount(baseAcc, coins, time.Now().Unix(), types.Periods{types.Period{3600, coins}}) + + bz, err := appCodec.MarshalAccount(acc) + require.Nil(t, err) + + acc2, err := appCodec.UnmarshalAccount(bz) + require.Nil(t, err) + require.IsType(t, &types.PeriodicVestingAccount{}, acc2) + require.Equal(t, acc.String(), acc2.String()) + + // error on bad bytes + _, err = appCodec.UnmarshalAccount(bz[:len(bz)/2]) + require.NotNil(t, err) +} + func TestPeriodicVestingAccountJSON(t *testing.T) { pubkey := secp256k1.GenPrivKey().PubKey() addr := sdk.AccAddress(pubkey.Address()) coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5)) baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50) - acc := NewPeriodicVestingAccount(baseAcc, coins, time.Now().Unix(), Periods{Period{3600, coins}}) + acc := types.NewPeriodicVestingAccount(baseAcc, coins, time.Now().Unix(), types.Periods{types.Period{3600, coins}}) bz, err := json.Marshal(acc) require.NoError(t, err) @@ -730,18 +744,39 @@ func TestPeriodicVestingAccountJSON(t *testing.T) { require.NoError(t, err) require.Equal(t, string(bz1), string(bz)) - var a PeriodicVestingAccount + var a types.PeriodicVestingAccount require.NoError(t, json.Unmarshal(bz, &a)) require.Equal(t, acc.String(), a.String()) } +func TestDelayedVestingAccountMarshal(t *testing.T) { + pubkey := secp256k1.GenPrivKey().PubKey() + addr := sdk.AccAddress(pubkey.Address()) + coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5)) + baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50) + + acc := types.NewDelayedVestingAccount(baseAcc, coins, time.Now().Unix()) + + bz, err := appCodec.MarshalAccount(acc) + require.Nil(t, err) + + acc2, err := appCodec.UnmarshalAccount(bz) + require.Nil(t, err) + require.IsType(t, &types.DelayedVestingAccount{}, acc2) + require.Equal(t, acc.String(), acc2.String()) + + // error on bad bytes + _, err = appCodec.UnmarshalAccount(bz[:len(bz)/2]) + require.NotNil(t, err) +} + func TestDelayedVestingAccountJSON(t *testing.T) { pubkey := secp256k1.GenPrivKey().PubKey() addr := sdk.AccAddress(pubkey.Address()) coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5)) baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50) - acc := NewDelayedVestingAccount(baseAcc, coins, time.Now().Unix()) + acc := types.NewDelayedVestingAccount(baseAcc, coins, time.Now().Unix()) bz, err := json.Marshal(acc) require.NoError(t, err) @@ -750,7 +785,7 @@ func TestDelayedVestingAccountJSON(t *testing.T) { require.NoError(t, err) require.Equal(t, string(bz1), string(bz)) - var a DelayedVestingAccount + var a types.DelayedVestingAccount require.NoError(t, json.Unmarshal(bz, &a)) require.Equal(t, acc.String(), a.String()) } diff --git a/x/bank/app_test.go b/x/bank/app_test.go index e124baaeef7f..46a33d3f62f6 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -356,7 +356,7 @@ func TestMsgMultiSendDependent(t *testing.T) { err := acc2.SetAccountNumber(1) require.NoError(t, err) - genAccs := []authexported.GenesisAccount{&acc1, &acc2} + genAccs := []authexported.GenesisAccount{acc1, acc2} app := simapp.SetupWithGenesisAccounts(genAccs) ctx := app.BaseApp.NewContext(false, abci.Header{}) diff --git a/x/bank/internal/keeper/keeper_test.go b/x/bank/internal/keeper/keeper_test.go index fbe41870f7bd..d71f1274f1d2 100644 --- a/x/bank/internal/keeper/keeper_test.go +++ b/x/bank/internal/keeper/keeper_test.go @@ -171,7 +171,7 @@ func (suite *IntegrationTestSuite) TestValidateBalance() { suite.Require().NoError(app.BankKeeper.ValidateBalance(ctx, addr1)) bacc := auth.NewBaseAccountWithAddress(addr2) - vacc := vesting.NewContinuousVestingAccount(&bacc, balances.Add(balances...), now.Unix(), endTime.Unix()) + vacc := vesting.NewContinuousVestingAccount(bacc, balances.Add(balances...), now.Unix(), endTime.Unix()) app.AccountKeeper.SetAccount(ctx, vacc) suite.Require().NoError(app.BankKeeper.SetBalances(ctx, addr2, balances)) @@ -392,7 +392,7 @@ func (suite *IntegrationTestSuite) TestSpendableCoins() { macc := app.AccountKeeper.NewAccountWithAddress(ctx, addrModule) bacc := auth.NewBaseAccountWithAddress(addr1) - vacc := vesting.NewContinuousVestingAccount(&bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) + vacc := vesting.NewContinuousVestingAccount(bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr2) app.AccountKeeper.SetAccount(ctx, macc) @@ -421,7 +421,7 @@ func (suite *IntegrationTestSuite) TestVestingAccountSend() { addr2 := sdk.AccAddress([]byte("addr2")) bacc := auth.NewBaseAccountWithAddress(addr1) - vacc := vesting.NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + vacc := vesting.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) app.AccountKeeper.SetAccount(ctx, vacc) suite.Require().NoError(app.BankKeeper.SetBalances(ctx, addr1, origCoins)) @@ -454,7 +454,7 @@ func (suite *IntegrationTestSuite) TestPeriodicVestingAccountSend() { } bacc := auth.NewBaseAccountWithAddress(addr1) - vacc := vesting.NewPeriodicVestingAccount(&bacc, origCoins, ctx.BlockHeader().Time.Unix(), periods) + vacc := vesting.NewPeriodicVestingAccount(bacc, origCoins, ctx.BlockHeader().Time.Unix(), periods) app.AccountKeeper.SetAccount(ctx, vacc) suite.Require().NoError(app.BankKeeper.SetBalances(ctx, addr1, origCoins)) @@ -484,7 +484,7 @@ func (suite *IntegrationTestSuite) TestVestingAccountReceive() { addr2 := sdk.AccAddress([]byte("addr2")) bacc := auth.NewBaseAccountWithAddress(addr1) - vacc := vesting.NewContinuousVestingAccount(&bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) + vacc := vesting.NewContinuousVestingAccount(bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr2) app.AccountKeeper.SetAccount(ctx, vacc) @@ -523,7 +523,7 @@ func (suite *IntegrationTestSuite) TestPeriodicVestingAccountReceive() { vesting.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin("stake", 25)}}, } - vacc := vesting.NewPeriodicVestingAccount(&bacc, origCoins, ctx.BlockHeader().Time.Unix(), periods) + vacc := vesting.NewPeriodicVestingAccount(bacc, origCoins, ctx.BlockHeader().Time.Unix(), periods) acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr2) app.AccountKeeper.SetAccount(ctx, vacc) @@ -560,7 +560,7 @@ func (suite *IntegrationTestSuite) TestDelegateCoins() { macc := app.AccountKeeper.NewAccountWithAddress(ctx, addrModule) // we don't need to define an actual module account bc we just need the address for testing acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr2) bacc := auth.NewBaseAccountWithAddress(addr1) - vacc := vesting.NewContinuousVestingAccount(&bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) + vacc := vesting.NewContinuousVestingAccount(bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) app.AccountKeeper.SetAccount(ctx, vacc) app.AccountKeeper.SetAccount(ctx, acc) @@ -620,7 +620,7 @@ func (suite *IntegrationTestSuite) TestUndelegateCoins() { bacc := auth.NewBaseAccountWithAddress(addr1) macc := app.AccountKeeper.NewAccountWithAddress(ctx, addrModule) // we don't need to define an actual module account bc we just need the address for testing - vacc := vesting.NewContinuousVestingAccount(&bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) + vacc := vesting.NewContinuousVestingAccount(bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr2) app.AccountKeeper.SetAccount(ctx, vacc) diff --git a/x/bank/internal/types/errors.go b/x/bank/internal/types/errors.go index 157408c941b7..dce69d0ac6bf 100644 --- a/x/bank/internal/types/errors.go +++ b/x/bank/internal/types/errors.go @@ -6,8 +6,8 @@ import ( // x/bank module sentinel errors var ( - ErrNoInputs = sdkerrors.Register(ModuleName, 1, "no inputs to send transaction") - ErrNoOutputs = sdkerrors.Register(ModuleName, 2, "no outputs to send transaction") - ErrInputOutputMismatch = sdkerrors.Register(ModuleName, 3, "sum inputs != sum outputs") - ErrSendDisabled = sdkerrors.Register(ModuleName, 4, "send transactions are disabled") + ErrNoInputs = sdkerrors.Register(ModuleName, 2, "no inputs to send transaction") + ErrNoOutputs = sdkerrors.Register(ModuleName, 3, "no outputs to send transaction") + ErrInputOutputMismatch = sdkerrors.Register(ModuleName, 4, "sum inputs != sum outputs") + ErrSendDisabled = sdkerrors.Register(ModuleName, 5, "send transactions are disabled") ) diff --git a/x/bank/module.go b/x/bank/module.go index 72afda68622c..dfde67f4a85e 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -39,14 +39,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { RegisterCodec(cdc) } // DefaultGenesis returns default genesis state as raw bytes for the bank // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the bank module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -111,18 +111,18 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the bank module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.keeper, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the bank // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.keeper) - return ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock performs a no-op. diff --git a/x/crisis/internal/types/codec.go b/x/crisis/internal/types/codec.go index fc9178eb386b..b7906953cf69 100644 --- a/x/crisis/internal/types/codec.go +++ b/x/crisis/internal/types/codec.go @@ -4,32 +4,26 @@ import ( "github.com/cosmos/cosmos-sdk/codec" ) -type Codec struct { - codec.Marshaler - - // Keep reference to the amino codec to allow backwards compatibility along - // with type, and interface registration. - amino *codec.Codec -} - -func NewCodec(amino *codec.Codec) *Codec { - return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino} -} - -// ---------------------------------------------------------------------------- - -// RegisterCodec registers all the necessary crisis module concrete types and -// interfaces with the provided codec reference. +// RegisterCodec registers the necessary x/crisis interfaces and concrete types +// on the provided Amino codec. These types are used for Amino JSON serialization. func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgVerifyInvariant{}, "cosmos-sdk/MsgVerifyInvariant", nil) } -// ModuleCdc defines a crisis module global Amino codec. -var ModuleCdc *Codec +var ( + amino = codec.New() + + // ModuleCdc references the global x/crisis module codec. Note, the codec should + // ONLY be used in certain instances of tests and for JSON encoding as Amino is + // still used for that purpose. + // + // The actual codec used for serialization should be provided to x/crisis and + // defined at the application level. + ModuleCdc = codec.NewHybridCodec(amino) +) func init() { - ModuleCdc = NewCodec(codec.New()) - RegisterCodec(ModuleCdc.amino) - codec.RegisterCrypto(ModuleCdc.amino) - ModuleCdc.amino.Seal() + RegisterCodec(amino) + codec.RegisterCrypto(amino) + amino.Seal() } diff --git a/x/crisis/internal/types/errors.go b/x/crisis/internal/types/errors.go index ac63f3ff43de..cf8c4901b315 100644 --- a/x/crisis/internal/types/errors.go +++ b/x/crisis/internal/types/errors.go @@ -6,6 +6,6 @@ import ( // x/crisis module sentinel errors var ( - ErrNoSender = sdkerrors.Register(ModuleName, 1, "sender address is empty") - ErrUnknownInvariant = sdkerrors.Register(ModuleName, 2, "unknown invariant") + ErrNoSender = sdkerrors.Register(ModuleName, 2, "sender address is empty") + ErrUnknownInvariant = sdkerrors.Register(ModuleName, 3, "unknown invariant") ) diff --git a/x/crisis/module.go b/x/crisis/module.go index 1885f69ade9f..dd7ae3677217 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -38,14 +38,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { // DefaultGenesis returns default genesis state as raw bytes for the crisis // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return types.ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the crisis module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data types.GenesisState - if err := types.ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -109,9 +109,9 @@ func (AppModule) NewQuerierHandler() sdk.Querier { return nil } // InitGenesis performs genesis initialization for the crisis module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - types.ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, *am.keeper, genesisState) am.keeper.AssertInvariants(ctx) @@ -120,9 +120,9 @@ func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.Va // ExportGenesis returns the exported genesis state as raw bytes for the crisis // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, *am.keeper) - return types.ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock performs a no-op. diff --git a/x/distribution/alias.go b/x/distribution/alias.go index ba16c5f47f28..47143d995cbb 100644 --- a/x/distribution/alias.go +++ b/x/distribution/alias.go @@ -111,7 +111,6 @@ var ( ParamStoreKeyBonusProposerReward = types.ParamStoreKeyBonusProposerReward ParamStoreKeyWithdrawAddrEnabled = types.ParamStoreKeyWithdrawAddrEnabled ModuleCdc = types.ModuleCdc - NewCodec = types.NewCodec EventTypeSetWithdrawAddress = types.EventTypeSetWithdrawAddress EventTypeRewards = types.EventTypeRewards EventTypeCommission = types.EventTypeCommission @@ -156,5 +155,4 @@ type ( ValidatorSlashEvent = types.ValidatorSlashEvent ValidatorSlashEvents = types.ValidatorSlashEvents ValidatorOutstandingRewards = types.ValidatorOutstandingRewards - Codec = types.Codec ) diff --git a/x/distribution/keeper/test_common.go b/x/distribution/keeper/test_common.go index dca88dfd1671..811c46f553a1 100644 --- a/x/distribution/keeper/test_common.go +++ b/x/distribution/keeper/test_common.go @@ -12,15 +12,15 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/codec" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/params" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/supply" - - "github.com/cosmos/cosmos-sdk/x/distribution/types" ) //nolint:deadcode,unused @@ -126,10 +126,11 @@ func CreateTestInputAdvanced( blacklistedAddrs[distrAcc.GetAddress().String()] = true cdc := MakeTestCodec() + appCodec := simappcodec.NewAppCodec(cdc) pk := params.NewKeeper(params.ModuleCdc, keyParams, tkeyParams) ctx := sdk.NewContext(ms, abci.Header{ChainID: "foochainid"}, isCheckTx, log.NewNopLogger()) - accountKeeper := auth.NewAccountKeeper(cdc, keyAcc, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) + accountKeeper := auth.NewAccountKeeper(appCodec, keyAcc, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) bankKeeper := bank.NewBaseKeeper(cdc, keyBank, accountKeeper, pk.Subspace(bank.DefaultParamspace), blacklistedAddrs) maccPerms := map[string][]string{ auth.FeeCollectorName: nil, @@ -137,7 +138,7 @@ func CreateTestInputAdvanced( staking.NotBondedPoolName: {supply.Burner, supply.Staking}, staking.BondedPoolName: {supply.Burner, supply.Staking}, } - supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bankKeeper, maccPerms) + supplyKeeper := supply.NewKeeper(appCodec, keySupply, accountKeeper, bankKeeper, maccPerms) sk := staking.NewKeeper(staking.ModuleCdc, keyStaking, bankKeeper, supplyKeeper, pk.Subspace(staking.DefaultParamspace)) sk.SetParams(ctx, staking.DefaultParams()) diff --git a/x/distribution/module.go b/x/distribution/module.go index 631d9b956fe2..dfa1b10244e9 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -43,14 +43,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { // DefaultGenesis returns default genesis state as raw bytes for the distribution // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the distribution module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -132,18 +132,18 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the distribution module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.bankKeeper, am.supplyKeeper, am.keeper, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the distribution // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.keeper) - return ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock returns the begin blocker for the distribution module. diff --git a/x/distribution/types/codec.go b/x/distribution/types/codec.go index 85412d65c77e..0bc8316abf3b 100644 --- a/x/distribution/types/codec.go +++ b/x/distribution/types/codec.go @@ -4,22 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" ) -type Codec struct { - codec.Marshaler - - // Keep reference to the amino codec to allow backwards compatibility along - // with type, and interface registration. - amino *codec.Codec -} - -func NewCodec(amino *codec.Codec) *Codec { - return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino} -} - -// ---------------------------------------------------------------------------- - -// RegisterCodec registers all the necessary crisis module concrete types and -// interfaces with the provided codec reference. +// RegisterCodec registers the necessary x/distribution interfaces and concrete types +// on the provided Amino codec. These types are used for Amino JSON serialization. func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgWithdrawDelegatorReward{}, "cosmos-sdk/MsgWithdrawDelegationReward", nil) cdc.RegisterConcrete(MsgWithdrawValidatorCommission{}, "cosmos-sdk/MsgWithdrawValidatorCommission", nil) @@ -27,12 +13,20 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(CommunityPoolSpendProposal{}, "cosmos-sdk/CommunityPoolSpendProposal", nil) } -// generic sealed codec to be used throughout module -var ModuleCdc *Codec +var ( + amino = codec.New() + + // ModuleCdc references the global x/distribution module codec. Note, the codec + // should ONLY be used in certain instances of tests and for JSON encoding as Amino + // is still used for that purpose. + // + // The actual codec used for serialization should be provided to x/distribution and + // defined at the application level. + ModuleCdc = codec.NewHybridCodec(amino) +) func init() { - ModuleCdc = NewCodec(codec.New()) - RegisterCodec(ModuleCdc.amino) - codec.RegisterCrypto(ModuleCdc.amino) - ModuleCdc.amino.Seal() + RegisterCodec(amino) + codec.RegisterCrypto(amino) + amino.Seal() } diff --git a/x/distribution/types/errors.go b/x/distribution/types/errors.go index c06b731b6ee4..147cfd320341 100644 --- a/x/distribution/types/errors.go +++ b/x/distribution/types/errors.go @@ -6,16 +6,16 @@ import ( // x/distribution module sentinel errors var ( - ErrEmptyDelegatorAddr = sdkerrors.Register(ModuleName, 1, "delegator address is empty") - ErrEmptyWithdrawAddr = sdkerrors.Register(ModuleName, 2, "withdraw address is empty") - ErrEmptyValidatorAddr = sdkerrors.Register(ModuleName, 3, "validator address is empty") - ErrEmptyDelegationDistInfo = sdkerrors.Register(ModuleName, 4, "no delegation distribution info") - ErrNoValidatorDistInfo = sdkerrors.Register(ModuleName, 5, "no validator distribution info") - ErrNoValidatorCommission = sdkerrors.Register(ModuleName, 6, "no validator commission to withdraw") - ErrSetWithdrawAddrDisabled = sdkerrors.Register(ModuleName, 7, "set withdraw address disabled") - ErrBadDistribution = sdkerrors.Register(ModuleName, 8, "community pool does not have sufficient coins to distribute") - ErrInvalidProposalAmount = sdkerrors.Register(ModuleName, 9, "invalid community pool spend proposal amount") - ErrEmptyProposalRecipient = sdkerrors.Register(ModuleName, 10, "invalid community pool spend proposal recipient") - ErrNoValidatorExists = sdkerrors.Register(ModuleName, 11, "validator does not exist") - ErrNoDelegationExists = sdkerrors.Register(ModuleName, 12, "delegation does not exist") + ErrEmptyDelegatorAddr = sdkerrors.Register(ModuleName, 2, "delegator address is empty") + ErrEmptyWithdrawAddr = sdkerrors.Register(ModuleName, 3, "withdraw address is empty") + ErrEmptyValidatorAddr = sdkerrors.Register(ModuleName, 4, "validator address is empty") + ErrEmptyDelegationDistInfo = sdkerrors.Register(ModuleName, 5, "no delegation distribution info") + ErrNoValidatorDistInfo = sdkerrors.Register(ModuleName, 6, "no validator distribution info") + ErrNoValidatorCommission = sdkerrors.Register(ModuleName, 7, "no validator commission to withdraw") + ErrSetWithdrawAddrDisabled = sdkerrors.Register(ModuleName, 8, "set withdraw address disabled") + ErrBadDistribution = sdkerrors.Register(ModuleName, 9, "community pool does not have sufficient coins to distribute") + ErrInvalidProposalAmount = sdkerrors.Register(ModuleName, 10, "invalid community pool spend proposal amount") + ErrEmptyProposalRecipient = sdkerrors.Register(ModuleName, 11, "invalid community pool spend proposal recipient") + ErrNoValidatorExists = sdkerrors.Register(ModuleName, 12, "validator does not exist") + ErrNoDelegationExists = sdkerrors.Register(ModuleName, 13, "delegation does not exist") ) diff --git a/x/evidence/internal/types/errors.go b/x/evidence/internal/types/errors.go index 83ffe06002ae..f44802709149 100644 --- a/x/evidence/internal/types/errors.go +++ b/x/evidence/internal/types/errors.go @@ -7,8 +7,8 @@ import ( // x/evidence module sentinel errors var ( - ErrNoEvidenceHandlerExists = sdkerrors.Register(ModuleName, 1, "unregistered handler for evidence type") - ErrInvalidEvidence = sdkerrors.Register(ModuleName, 2, "invalid evidence") - ErrNoEvidenceExists = sdkerrors.Register(ModuleName, 3, "evidence does not exist") - ErrEvidenceExists = sdkerrors.Register(ModuleName, 4, "evidence already exists") + ErrNoEvidenceHandlerExists = sdkerrors.Register(ModuleName, 2, "unregistered handler for evidence type") + ErrInvalidEvidence = sdkerrors.Register(ModuleName, 3, "invalid evidence") + ErrNoEvidenceExists = sdkerrors.Register(ModuleName, 4, "evidence does not exist") + ErrEvidenceExists = sdkerrors.Register(ModuleName, 5, "evidence already exists") ) diff --git a/x/evidence/module.go b/x/evidence/module.go index 30b427a95c1d..87900aba30df 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -51,14 +51,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { } // DefaultGenesis returns the evidence module's default genesis state. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the evidence module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var gs GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &gs); err != nil { + if err := cdc.UnmarshalJSON(bz, &gs); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -140,9 +140,9 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {} // InitGenesis performs the evidence module's genesis initialization It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, bz json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, bz json.RawMessage) []abci.ValidatorUpdate { var gs GenesisState - err := ModuleCdc.UnmarshalJSON(bz, &gs) + err := cdc.UnmarshalJSON(bz, &gs) if err != nil { panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", ModuleName, err)) } @@ -152,8 +152,8 @@ func (am AppModule) InitGenesis(ctx sdk.Context, bz json.RawMessage) []abci.Vali } // ExportGenesis returns the evidence module's exported genesis state as raw JSON bytes. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { - return ModuleCdc.MustMarshalJSON(ExportGenesis(ctx, am.keeper)) +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(ExportGenesis(ctx, am.keeper)) } // BeginBlock executes all ABCI BeginBlock logic respective to the evidence module. diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index b992f446fe7b..641a6099907f 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -88,7 +88,7 @@ func GenTxCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager, sm return errors.Wrap(err, "failed to unmarshal genesis state") } - if err = mbm.ValidateGenesis(genesisState); err != nil { + if err = mbm.ValidateGenesis(cdc, genesisState); err != nil { return errors.Wrap(err, "failed to validate genesis state") } diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index 618f389da579..0f81c51f7700 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -87,7 +87,7 @@ func InitCmd(ctx *server.Context, cdc codec.JSONMarshaler, mbm module.BasicManag if !viper.GetBool(flagOverwrite) && tmos.FileExists(genFile) { return fmt.Errorf("genesis.json file already exists: %v", genFile) } - appState, err := codec.MarshalJSONIndent(cdc, mbm.DefaultGenesis()) + appState, err := codec.MarshalJSONIndent(cdc, mbm.DefaultGenesis(cdc)) if err != nil { return errors.Wrap(err, "Failed to marshall default genesis state") } diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index 6be33bdabf09..70e26f01ebbb 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -41,7 +41,7 @@ func ValidateGenesisCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicM return fmt.Errorf("error unmarshalling genesis doc %s: %s", genesis, err.Error()) } - if err = mbm.ValidateGenesis(genState); err != nil { + if err = mbm.ValidateGenesis(cdc, genState); err != nil { return fmt.Errorf("error validating genesis file %s: %s", genesis, err.Error()) } diff --git a/x/genutil/module.go b/x/genutil/module.go index 31ca1b463523..cedf7171f564 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -34,14 +34,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {} // DefaultGenesis returns default genesis state as raw bytes for the genutil // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(types.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the genutil module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -82,14 +82,14 @@ func NewAppModule(accountKeeper types.AccountKeeper, // InitGenesis performs genesis initialization for the genutil module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) return InitGenesis(ctx, ModuleCdc, am.stakingKeeper, am.deliverTx, genesisState) } // ExportGenesis returns the exported genesis state as raw bytes for the genutil // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(_ sdk.Context, _ codec.JSONMarshaler) json.RawMessage { return nil } diff --git a/x/gov/genesis_test.go b/x/gov/genesis_test.go index 5e86d71cf731..133c7c4f3ab3 100644 --- a/x/gov/genesis_test.go +++ b/x/gov/genesis_test.go @@ -52,19 +52,19 @@ func TestImportExportQueues(t *testing.T) { // export the state and import it into a new app govGenState := gov.ExportGenesis(ctx, app.GovKeeper) - - db := dbm.NewMemDB() - app2 := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, 0) genesisState := simapp.NewDefaultGenesisState() genesisState[auth.ModuleName] = app.Codec().MustMarshalJSON(authGenState) genesisState[gov.ModuleName] = app.Codec().MustMarshalJSON(govGenState) - stateBytes, err := codec.MarshalJSONIndent(app2.Codec(), genesisState) + stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState) if err != nil { panic(err) } + db := dbm.NewMemDB() + app2 := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, 0) + app2.InitChain( abci.RequestInitChain{ Validators: []abci.ValidatorUpdate{}, diff --git a/x/gov/keeper/test_common.go b/x/gov/keeper/test_common.go index 42fe87626bcf..13c6fc15da1d 100644 --- a/x/gov/keeper/test_common.go +++ b/x/gov/keeper/test_common.go @@ -1,6 +1,7 @@ -// nolint -package keeper // noalias +package keeper +// noalias +// nolint // DONTCOVER import ( @@ -9,16 +10,15 @@ import ( "testing" "github.com/stretchr/testify/require" - + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" - - abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" tmtypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/codec" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" @@ -125,7 +125,9 @@ func createTestInput( }, }, ) + cdc := makeTestCodec() + appCodec := simappcodec.NewAppCodec(cdc) maccPerms := map[string][]string{ auth.FeeCollectorName: nil, @@ -147,9 +149,9 @@ func createTestInput( blacklistedAddrs[bondPool.GetAddress().String()] = true pk := params.NewKeeper(params.ModuleCdc, keyParams, tkeyParams) - accountKeeper := auth.NewAccountKeeper(cdc, keyAcc, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) + accountKeeper := auth.NewAccountKeeper(appCodec, keyAcc, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) bankKeeper := bank.NewBaseKeeper(cdc, keyBank, accountKeeper, pk.Subspace(bank.DefaultParamspace), blacklistedAddrs) - supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bankKeeper, maccPerms) + supplyKeeper := supply.NewKeeper(appCodec, keySupply, accountKeeper, bankKeeper, maccPerms) sk := staking.NewKeeper(staking.ModuleCdc, keyStaking, bankKeeper, supplyKeeper, pk.Subspace(staking.DefaultParamspace)) sk.SetParams(ctx, staking.DefaultParams()) diff --git a/x/gov/module.go b/x/gov/module.go index bd2cabb97e78..5d07091fd1ab 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -54,14 +54,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { // DefaultGenesis returns default genesis state as raw bytes for the gov // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the gov module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) } @@ -149,18 +149,18 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the gov module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.bankKeeper, am.supplyKeeper, am.keeper, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the gov // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.keeper) - return ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock performs a no-op. diff --git a/x/gov/types/errors.go b/x/gov/types/errors.go index 2327a6f05b5e..96973f1751a2 100644 --- a/x/gov/types/errors.go +++ b/x/gov/types/errors.go @@ -6,12 +6,12 @@ import ( // x/gov module sentinel errors var ( - ErrUnknownProposal = sdkerrors.Register(ModuleName, 1, "unknown proposal") - ErrInactiveProposal = sdkerrors.Register(ModuleName, 2, "inactive proposal") - ErrAlreadyActiveProposal = sdkerrors.Register(ModuleName, 3, "proposal already active") - ErrInvalidProposalContent = sdkerrors.Register(ModuleName, 4, "invalid proposal content") - ErrInvalidProposalType = sdkerrors.Register(ModuleName, 5, "invalid proposal type") - ErrInvalidVote = sdkerrors.Register(ModuleName, 6, "invalid vote option") - ErrInvalidGenesis = sdkerrors.Register(ModuleName, 7, "invalid genesis state") - ErrNoProposalHandlerExists = sdkerrors.Register(ModuleName, 8, "no handler exists for proposal type") + ErrUnknownProposal = sdkerrors.Register(ModuleName, 2, "unknown proposal") + ErrInactiveProposal = sdkerrors.Register(ModuleName, 3, "inactive proposal") + ErrAlreadyActiveProposal = sdkerrors.Register(ModuleName, 4, "proposal already active") + ErrInvalidProposalContent = sdkerrors.Register(ModuleName, 5, "invalid proposal content") + ErrInvalidProposalType = sdkerrors.Register(ModuleName, 6, "invalid proposal type") + ErrInvalidVote = sdkerrors.Register(ModuleName, 7, "invalid vote option") + ErrInvalidGenesis = sdkerrors.Register(ModuleName, 8, "invalid genesis state") + ErrNoProposalHandlerExists = sdkerrors.Register(ModuleName, 9, "no handler exists for proposal type") ) diff --git a/x/mint/module.go b/x/mint/module.go index 95b171251ee1..53bd8fff13a6 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -41,14 +41,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {} // DefaultGenesis returns default genesis state as raw bytes for the mint // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the mint module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -111,18 +111,18 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the mint module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.keeper, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the mint // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.keeper) - return ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock returns the begin blocker for the mint module. diff --git a/x/params/module.go b/x/params/module.go index 5817b482b3b8..12005b8bc407 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -36,10 +36,10 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { // DefaultGenesis returns default genesis state as raw bytes for the params // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { return nil } +func (AppModuleBasic) DefaultGenesis(_ codec.JSONMarshaler) json.RawMessage { return nil } // ValidateGenesis performs genesis state validation for the params module. -func (AppModuleBasic) ValidateGenesis(_ json.RawMessage) error { return nil } +func (AppModuleBasic) ValidateGenesis(_ codec.JSONMarshaler, _ json.RawMessage) error { return nil } // RegisterRESTRoutes registers the REST routes for the params module. func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router) {} diff --git a/x/params/types/errors.go b/x/params/types/errors.go index 4b218d9444ee..0611a3de214b 100644 --- a/x/params/types/errors.go +++ b/x/params/types/errors.go @@ -6,10 +6,10 @@ import ( // x/params module sentinel errors var ( - ErrUnknownSubspace = sdkerrors.Register(ModuleName, 1, "unknown subspace") - ErrSettingParameter = sdkerrors.Register(ModuleName, 2, "failed to set parameter") - ErrEmptyChanges = sdkerrors.Register(ModuleName, 3, "submitted parameter changes are empty") - ErrEmptySubspace = sdkerrors.Register(ModuleName, 4, "parameter subspace is empty") - ErrEmptyKey = sdkerrors.Register(ModuleName, 5, "parameter key is empty") - ErrEmptyValue = sdkerrors.Register(ModuleName, 6, "parameter value is empty") + ErrUnknownSubspace = sdkerrors.Register(ModuleName, 2, "unknown subspace") + ErrSettingParameter = sdkerrors.Register(ModuleName, 3, "failed to set parameter") + ErrEmptyChanges = sdkerrors.Register(ModuleName, 4, "submitted parameter changes are empty") + ErrEmptySubspace = sdkerrors.Register(ModuleName, 5, "parameter subspace is empty") + ErrEmptyKey = sdkerrors.Register(ModuleName, 6, "parameter key is empty") + ErrEmptyValue = sdkerrors.Register(ModuleName, 7, "parameter value is empty") ) diff --git a/x/slashing/abci_test.go b/x/slashing/abci_test.go index a6a14c885b3d..c1b0f62fffb4 100644 --- a/x/slashing/abci_test.go +++ b/x/slashing/abci_test.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing" - slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/internal/keeper" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" "github.com/cosmos/cosmos-sdk/x/staking" ) diff --git a/x/slashing/alias.go b/x/slashing/alias.go index 9e199645496d..c34371067e1e 100644 --- a/x/slashing/alias.go +++ b/x/slashing/alias.go @@ -3,8 +3,8 @@ package slashing // nolint import ( - "github.com/cosmos/cosmos-sdk/x/slashing/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) const ( diff --git a/x/slashing/client/cli/query.go b/x/slashing/client/cli/query.go index f8fc7d82d098..c661b589f1d0 100644 --- a/x/slashing/client/cli/query.go +++ b/x/slashing/client/cli/query.go @@ -12,7 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // GetQueryCmd returns the cli query commands for this module diff --git a/x/slashing/client/cli/tx.go b/x/slashing/client/cli/tx.go index 117e216a957a..4233d5c7a072 100644 --- a/x/slashing/client/cli/tx.go +++ b/x/slashing/client/cli/tx.go @@ -12,7 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // GetTxCmd returns the transaction commands for this module diff --git a/x/slashing/client/rest/query.go b/x/slashing/client/rest/query.go index 751fe648dc45..2d3d9bfab798 100644 --- a/x/slashing/client/rest/query.go +++ b/x/slashing/client/rest/query.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) { diff --git a/x/slashing/client/rest/tx.go b/x/slashing/client/rest/tx.go index 1257b8e105a5..9498ea8ba5ff 100644 --- a/x/slashing/client/rest/tx.go +++ b/x/slashing/client/rest/tx.go @@ -10,7 +10,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) { diff --git a/x/slashing/genesis.go b/x/slashing/genesis.go index 8b959c8a0bac..a5d2eb0f1350 100644 --- a/x/slashing/genesis.go +++ b/x/slashing/genesis.go @@ -2,7 +2,7 @@ package slashing import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking/exported" ) diff --git a/x/slashing/handler.go b/x/slashing/handler.go index cb6690716bcb..ed89734faa20 100644 --- a/x/slashing/handler.go +++ b/x/slashing/handler.go @@ -3,7 +3,7 @@ package slashing import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // NewHandler creates an sdk.Handler for all the slashing type messages diff --git a/x/slashing/handler_test.go b/x/slashing/handler_test.go index c168f8052ffb..abd5e52559fd 100644 --- a/x/slashing/handler_test.go +++ b/x/slashing/handler_test.go @@ -11,8 +11,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing" - slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" ) diff --git a/x/slashing/internal/keeper/hooks.go b/x/slashing/keeper/hooks.go similarity index 97% rename from x/slashing/internal/keeper/hooks.go rename to x/slashing/keeper/hooks.go index a8ef6e093e15..e6374a87f990 100644 --- a/x/slashing/internal/keeper/hooks.go +++ b/x/slashing/keeper/hooks.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/crypto" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) func (k Keeper) AfterValidatorBonded(ctx sdk.Context, address sdk.ConsAddress, _ sdk.ValAddress) { diff --git a/x/slashing/internal/keeper/infractions.go b/x/slashing/keeper/infractions.go similarity index 98% rename from x/slashing/internal/keeper/infractions.go rename to x/slashing/keeper/infractions.go index a10b6f945b3a..a8e349b75be8 100644 --- a/x/slashing/internal/keeper/infractions.go +++ b/x/slashing/keeper/infractions.go @@ -6,7 +6,7 @@ import ( "github.com/tendermint/tendermint/crypto" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // HandleValidatorSignature handles a validator signature, must be called once per validator per block. diff --git a/x/slashing/internal/keeper/keeper.go b/x/slashing/keeper/keeper.go similarity index 98% rename from x/slashing/internal/keeper/keeper.go rename to x/slashing/keeper/keeper.go index 47a1cb867f9d..43f21a516edb 100644 --- a/x/slashing/internal/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // Keeper of the slashing store diff --git a/x/slashing/internal/keeper/keeper_test.go b/x/slashing/keeper/keeper_test.go similarity index 99% rename from x/slashing/internal/keeper/keeper_test.go rename to x/slashing/keeper/keeper_test.go index fdf50a261e27..4f4f555bbffc 100644 --- a/x/slashing/internal/keeper/keeper_test.go +++ b/x/slashing/keeper/keeper_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" ) diff --git a/x/slashing/internal/keeper/params.go b/x/slashing/keeper/params.go similarity index 96% rename from x/slashing/internal/keeper/params.go rename to x/slashing/keeper/params.go index 82fe991cccc1..8ece97a687ad 100644 --- a/x/slashing/internal/keeper/params.go +++ b/x/slashing/keeper/params.go @@ -4,7 +4,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // SignedBlocksWindow - sliding window for downtime slashing diff --git a/x/slashing/internal/keeper/querier.go b/x/slashing/keeper/querier.go similarity index 97% rename from x/slashing/internal/keeper/querier.go rename to x/slashing/keeper/querier.go index 11b365e1ee1b..1eab719a63f7 100644 --- a/x/slashing/internal/keeper/querier.go +++ b/x/slashing/keeper/querier.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // NewQuerier creates a new querier for slashing clients. diff --git a/x/slashing/internal/keeper/querier_test.go b/x/slashing/keeper/querier_test.go similarity index 92% rename from x/slashing/internal/keeper/querier_test.go rename to x/slashing/keeper/querier_test.go index ea4095dc61b1..fd924bc8e823 100644 --- a/x/slashing/internal/keeper/querier_test.go +++ b/x/slashing/keeper/querier_test.go @@ -7,7 +7,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) func TestNewQuerier(t *testing.T) { diff --git a/x/slashing/internal/keeper/signing_info.go b/x/slashing/keeper/signing_info.go similarity index 98% rename from x/slashing/internal/keeper/signing_info.go rename to x/slashing/keeper/signing_info.go index 7afe299f1979..0e1a82c62fa2 100644 --- a/x/slashing/internal/keeper/signing_info.go +++ b/x/slashing/keeper/signing_info.go @@ -6,7 +6,7 @@ import ( gogotypes "github.com/gogo/protobuf/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // GetValidatorSigningInfo retruns the ValidatorSigningInfo for a specific validator diff --git a/x/slashing/internal/keeper/signing_info_test.go b/x/slashing/keeper/signing_info_test.go similarity index 97% rename from x/slashing/internal/keeper/signing_info_test.go rename to x/slashing/keeper/signing_info_test.go index 7d9e7c56e526..ac8c5075276f 100644 --- a/x/slashing/internal/keeper/signing_info_test.go +++ b/x/slashing/keeper/signing_info_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) func TestGetSetValidatorSigningInfo(t *testing.T) { diff --git a/x/slashing/internal/keeper/test_common.go b/x/slashing/keeper/test_common.go similarity index 93% rename from x/slashing/internal/keeper/test_common.go rename to x/slashing/keeper/test_common.go index b3230f424fb9..316195b63d04 100644 --- a/x/slashing/internal/keeper/test_common.go +++ b/x/slashing/keeper/test_common.go @@ -1,7 +1,8 @@ +package keeper + // nolint:deadcode,unused // DONTCOVER // noalias -package keeper import ( "encoding/hex" @@ -9,7 +10,6 @@ import ( "time" "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" @@ -17,12 +17,13 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/codec" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/params" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/supply" ) @@ -80,6 +81,7 @@ func CreateTestInput(t *testing.T, defaults types.Params) (sdk.Context, bank.Kee ctx := sdk.NewContext(ms, abci.Header{Time: time.Unix(0, 0)}, false, log.NewNopLogger()) cdc := createTestCodec() + appCodec := simappcodec.NewAppCodec(cdc) feeCollectorAcc := supply.NewEmptyModuleAccount(auth.FeeCollectorName) notBondedPool := supply.NewEmptyModuleAccount(staking.NotBondedPoolName, supply.Burner, supply.Staking) @@ -91,7 +93,7 @@ func CreateTestInput(t *testing.T, defaults types.Params) (sdk.Context, bank.Kee blacklistedAddrs[bondPool.GetAddress().String()] = true paramsKeeper := params.NewKeeper(params.ModuleCdc, keyParams, tkeyParams) - accountKeeper := auth.NewAccountKeeper(cdc, keyAcc, paramsKeeper.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) + accountKeeper := auth.NewAccountKeeper(appCodec, keyAcc, paramsKeeper.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) bk := bank.NewBaseKeeper(cdc, keyBank, accountKeeper, paramsKeeper.Subspace(bank.DefaultParamspace), blacklistedAddrs) maccPerms := map[string][]string{ @@ -99,7 +101,7 @@ func CreateTestInput(t *testing.T, defaults types.Params) (sdk.Context, bank.Kee staking.NotBondedPoolName: {supply.Burner, supply.Staking}, staking.BondedPoolName: {supply.Burner, supply.Staking}, } - supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bk, maccPerms) + supplyKeeper := supply.NewKeeper(appCodec, keySupply, accountKeeper, bk, maccPerms) totalSupply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, InitTokens.MulRaw(int64(len(Addrs))))) supplyKeeper.SetSupply(ctx, supply.NewSupply(totalSupply)) diff --git a/x/slashing/internal/keeper/unjail.go b/x/slashing/keeper/unjail.go similarity index 95% rename from x/slashing/internal/keeper/unjail.go rename to x/slashing/keeper/unjail.go index 51fda4855382..cf57c1e71c4a 100644 --- a/x/slashing/internal/keeper/unjail.go +++ b/x/slashing/keeper/unjail.go @@ -2,7 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // Unjail calls the staking Unjail function to unjail a validator if the diff --git a/x/slashing/module.go b/x/slashing/module.go index 4b739ef217e0..b404b8c4ecde 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -17,8 +17,8 @@ import ( sim "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/cosmos/cosmos-sdk/x/slashing/client/cli" "github.com/cosmos/cosmos-sdk/x/slashing/client/rest" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" "github.com/cosmos/cosmos-sdk/x/slashing/simulation" + "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) @@ -45,14 +45,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { // DefaultGenesis returns default genesis state as raw bytes for the slashing // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the slashing module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) } @@ -127,7 +127,7 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the slashing module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState ModuleCdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.keeper, am.stakingKeeper, genesisState) @@ -136,9 +136,9 @@ func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.Va // ExportGenesis returns the exported genesis state as raw bytes for the slashing // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.keeper) - return ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock returns the begin blocker for the slashing module. diff --git a/x/slashing/simulation/decoder.go b/x/slashing/simulation/decoder.go index af844dd2d05f..48a12705a780 100644 --- a/x/slashing/simulation/decoder.go +++ b/x/slashing/simulation/decoder.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // DecodeStore unmarshals the KVPair's Value to the corresponding slashing type diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index c2c2f448010a..522bff74750d 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -14,7 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // nolint:deadcode,unused,varcheck diff --git a/x/slashing/simulation/genesis.go b/x/slashing/simulation/genesis.go index a26a626642b7..d9dae7cd3d7b 100644 --- a/x/slashing/simulation/genesis.go +++ b/x/slashing/simulation/genesis.go @@ -12,7 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // Simulation parameter constants diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 8b7124609c09..c0f0b94554f6 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -10,8 +10,8 @@ import ( simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) diff --git a/x/slashing/simulation/params.go b/x/slashing/simulation/params.go index 6679928d8fc4..72048f2264bd 100644 --- a/x/slashing/simulation/params.go +++ b/x/slashing/simulation/params.go @@ -7,7 +7,7 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) const ( diff --git a/x/slashing/internal/types/codec.go b/x/slashing/types/codec.go similarity index 100% rename from x/slashing/internal/types/codec.go rename to x/slashing/types/codec.go diff --git a/x/slashing/internal/types/errors.go b/x/slashing/types/errors.go similarity index 61% rename from x/slashing/internal/types/errors.go rename to x/slashing/types/errors.go index 290ed36cad66..daff6ecc04af 100644 --- a/x/slashing/internal/types/errors.go +++ b/x/slashing/types/errors.go @@ -6,11 +6,11 @@ import ( // x/slashing module sentinel errors var ( - ErrNoValidatorForAddress = sdkerrors.Register(ModuleName, 1, "address is not associated with any known validator") - ErrBadValidatorAddr = sdkerrors.Register(ModuleName, 2, "validator does not exist for that address") - ErrValidatorJailed = sdkerrors.Register(ModuleName, 3, "validator still jailed; cannot be unjailed") - ErrValidatorNotJailed = sdkerrors.Register(ModuleName, 4, "validator not jailed; cannot be unjailed") - ErrMissingSelfDelegation = sdkerrors.Register(ModuleName, 5, "validator has no self-delegation; cannot be unjailed") - ErrSelfDelegationTooLowToUnjail = sdkerrors.Register(ModuleName, 6, "validator's self delegation less than minimum; cannot be unjailed") - ErrNoSigningInfoFound = sdkerrors.Register(ModuleName, 7, "no validator signing info found") + ErrNoValidatorForAddress = sdkerrors.Register(ModuleName, 2, "address is not associated with any known validator") + ErrBadValidatorAddr = sdkerrors.Register(ModuleName, 3, "validator does not exist for that address") + ErrValidatorJailed = sdkerrors.Register(ModuleName, 4, "validator still jailed; cannot be unjailed") + ErrValidatorNotJailed = sdkerrors.Register(ModuleName, 5, "validator not jailed; cannot be unjailed") + ErrMissingSelfDelegation = sdkerrors.Register(ModuleName, 6, "validator has no self-delegation; cannot be unjailed") + ErrSelfDelegationTooLowToUnjail = sdkerrors.Register(ModuleName, 7, "validator's self delegation less than minimum; cannot be unjailed") + ErrNoSigningInfoFound = sdkerrors.Register(ModuleName, 8, "no validator signing info found") ) diff --git a/x/slashing/internal/types/events.go b/x/slashing/types/events.go similarity index 100% rename from x/slashing/internal/types/events.go rename to x/slashing/types/events.go diff --git a/x/slashing/internal/types/expected_keepers.go b/x/slashing/types/expected_keepers.go similarity index 100% rename from x/slashing/internal/types/expected_keepers.go rename to x/slashing/types/expected_keepers.go diff --git a/x/slashing/internal/types/genesis.go b/x/slashing/types/genesis.go similarity index 100% rename from x/slashing/internal/types/genesis.go rename to x/slashing/types/genesis.go diff --git a/x/slashing/internal/types/keys.go b/x/slashing/types/keys.go similarity index 100% rename from x/slashing/internal/types/keys.go rename to x/slashing/types/keys.go diff --git a/x/slashing/internal/types/msg.go b/x/slashing/types/msg.go similarity index 100% rename from x/slashing/internal/types/msg.go rename to x/slashing/types/msg.go diff --git a/x/slashing/internal/types/msg_test.go b/x/slashing/types/msg_test.go similarity index 100% rename from x/slashing/internal/types/msg_test.go rename to x/slashing/types/msg_test.go diff --git a/x/slashing/internal/types/params.go b/x/slashing/types/params.go similarity index 100% rename from x/slashing/internal/types/params.go rename to x/slashing/types/params.go diff --git a/x/slashing/internal/types/querier.go b/x/slashing/types/querier.go similarity index 100% rename from x/slashing/internal/types/querier.go rename to x/slashing/types/querier.go diff --git a/x/slashing/internal/types/signing_info.go b/x/slashing/types/signing_info.go similarity index 100% rename from x/slashing/internal/types/signing_info.go rename to x/slashing/types/signing_info.go diff --git a/x/slashing/internal/types/types.pb.go b/x/slashing/types/types.pb.go similarity index 100% rename from x/slashing/internal/types/types.pb.go rename to x/slashing/types/types.pb.go diff --git a/x/slashing/internal/types/types.proto b/x/slashing/types/types.proto similarity index 100% rename from x/slashing/internal/types/types.proto rename to x/slashing/types/types.proto diff --git a/x/staking/alias.go b/x/staking/alias.go index 445ead018e15..1b7c78772f73 100644 --- a/x/staking/alias.go +++ b/x/staking/alias.go @@ -176,7 +176,6 @@ var ( NewDescription = types.NewDescription // variable aliases - NewCodec = types.NewCodec ModuleCdc = types.ModuleCdc LastValidatorPowerKey = types.LastValidatorPowerKey LastTotalPowerKey = types.LastTotalPowerKey @@ -201,7 +200,6 @@ var ( type ( Keeper = keeper.Keeper - Codec = types.Codec Commission = types.Commission CommissionRates = types.CommissionRates DVPair = types.DVPair diff --git a/x/staking/keeper/test_common.go b/x/staking/keeper/test_common.go index 005cfbfb1ffa..9d97cc873266 100644 --- a/x/staking/keeper/test_common.go +++ b/x/staking/keeper/test_common.go @@ -1,4 +1,6 @@ -package keeper // noalias +package keeper + +// noalias import ( "bytes" @@ -16,6 +18,7 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/codec" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" @@ -105,7 +108,9 @@ func CreateTestInput(t *testing.T, isCheckTx bool, initPower int64) (sdk.Context }, }, ) + cdc := MakeTestCodec() + appCodec := simappcodec.NewAppCodec(cdc) feeCollectorAcc := supply.NewEmptyModuleAccount(auth.FeeCollectorName) notBondedPool := supply.NewEmptyModuleAccount(types.NotBondedPoolName, supply.Burner, supply.Staking) @@ -119,10 +124,10 @@ func CreateTestInput(t *testing.T, isCheckTx bool, initPower int64) (sdk.Context pk := params.NewKeeper(params.ModuleCdc, keyParams, tkeyParams) accountKeeper := auth.NewAccountKeeper( - cdc, // amino codec - keyAcc, // target store + appCodec, + keyAcc, pk.Subspace(auth.DefaultParamspace), - auth.ProtoBaseAccount, // prototype + auth.ProtoBaseAccount, ) bk := bank.NewBaseKeeper( @@ -138,7 +143,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, initPower int64) (sdk.Context types.NotBondedPoolName: {supply.Burner, supply.Staking}, types.BondedPoolName: {supply.Burner, supply.Staking}, } - supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bk, maccPerms) + supplyKeeper := supply.NewKeeper(appCodec, keySupply, accountKeeper, bk, maccPerms) initTokens := sdk.TokensFromConsensusPower(initPower) initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens)) diff --git a/x/staking/module.go b/x/staking/module.go index 0c7023a01957..33034842f75d 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -48,14 +48,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { // DefaultGenesis returns default genesis state as raw bytes for the staking // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the staking module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -154,17 +154,17 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the staking module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) return InitGenesis(ctx, am.keeper, am.accountKeeper, am.bankKeeper, am.supplyKeeper, genesisState) } // ExportGenesis returns the exported genesis state as raw bytes for the staking // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.keeper) - return ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock returns the begin blocker for the staking module. diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index 9832789b6971..940e5ac8a4a2 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -4,22 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" ) -type Codec struct { - codec.Marshaler - - // Keep reference to the amino codec to allow backwards compatibility along - // with type, and interface registration. - amino *codec.Codec -} - -func NewCodec(amino *codec.Codec) *Codec { - return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino} -} - -// ---------------------------------------------------------------------------- - -// RegisterCodec registers all the necessary staking module concrete types and -// interfaces with the provided codec reference. +// RegisterCodec registers the necessary x/staking interfaces and concrete types +// on the provided Amino codec. These types are used for Amino JSON serialization. func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator", nil) cdc.RegisterConcrete(MsgEditValidator{}, "cosmos-sdk/MsgEditValidator", nil) @@ -28,13 +14,20 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgBeginRedelegate{}, "cosmos-sdk/MsgBeginRedelegate", nil) } -// ModuleCdc defines a staking module global Amino codec. -var ModuleCdc *Codec +var ( + amino = codec.New() -func init() { - ModuleCdc = NewCodec(codec.New()) + // ModuleCdc references the global x/staking module codec. Note, the codec should + // ONLY be used in certain instances of tests and for JSON encoding as Amino is + // still used for that purpose. + // + // The actual codec used for serialization should be provided to x/staking and + // defined at the application level. + ModuleCdc = codec.NewHybridCodec(amino) +) - RegisterCodec(ModuleCdc.amino) - codec.RegisterCrypto(ModuleCdc.amino) - ModuleCdc.amino.Seal() +func init() { + RegisterCodec(amino) + codec.RegisterCrypto(amino) + amino.Seal() } diff --git a/x/staking/types/errors.go b/x/staking/types/errors.go index 62fdd0725b90..d6c31a15dc74 100644 --- a/x/staking/types/errors.go +++ b/x/staking/types/errors.go @@ -11,50 +11,50 @@ import ( // // REF: https://github.com/cosmos/cosmos-sdk/issues/5450 var ( - ErrEmptyValidatorAddr = sdkerrors.Register(ModuleName, 1, "empty validator address") - ErrBadValidatorAddr = sdkerrors.Register(ModuleName, 2, "validator address is invalid") - ErrNoValidatorFound = sdkerrors.Register(ModuleName, 3, "validator does not exist") - ErrValidatorOwnerExists = sdkerrors.Register(ModuleName, 4, "validator already exist for this operator address; must use new validator operator address") - ErrValidatorPubKeyExists = sdkerrors.Register(ModuleName, 5, "validator already exist for this pubkey; must use new validator pubkey") - ErrValidatorPubKeyTypeNotSupported = sdkerrors.Register(ModuleName, 6, "validator pubkey type is not supported") - ErrValidatorJailed = sdkerrors.Register(ModuleName, 7, "validator for this address is currently jailed") - ErrBadRemoveValidator = sdkerrors.Register(ModuleName, 8, "failed to remove validator") - ErrCommissionNegative = sdkerrors.Register(ModuleName, 9, "commission must be positive") - ErrCommissionHuge = sdkerrors.Register(ModuleName, 10, "commission cannot be more than 100%") - ErrCommissionGTMaxRate = sdkerrors.Register(ModuleName, 11, "commission cannot be more than the max rate") - ErrCommissionUpdateTime = sdkerrors.Register(ModuleName, 12, "commission cannot be changed more than once in 24h") - ErrCommissionChangeRateNegative = sdkerrors.Register(ModuleName, 13, "commission change rate must be positive") - ErrCommissionChangeRateGTMaxRate = sdkerrors.Register(ModuleName, 14, "commission change rate cannot be more than the max rate") - ErrCommissionGTMaxChangeRate = sdkerrors.Register(ModuleName, 15, "commission cannot be changed more than max change rate") - ErrSelfDelegationBelowMinimum = sdkerrors.Register(ModuleName, 16, "validator's self delegation must be greater than their minimum self delegation") - ErrMinSelfDelegationInvalid = sdkerrors.Register(ModuleName, 17, "minimum self delegation must be a positive integer") - ErrMinSelfDelegationDecreased = sdkerrors.Register(ModuleName, 18, "minimum self delegation cannot be decrease") - ErrEmptyDelegatorAddr = sdkerrors.Register(ModuleName, 19, "empty delegator address") - ErrBadDenom = sdkerrors.Register(ModuleName, 20, "invalid coin denomination") - ErrBadDelegationAddr = sdkerrors.Register(ModuleName, 21, "invalid address for (address, validator) tuple") - ErrBadDelegationAmount = sdkerrors.Register(ModuleName, 22, "invalid delegation amount") - ErrNoDelegation = sdkerrors.Register(ModuleName, 23, "no delegation for (address, validator) tuple") - ErrBadDelegatorAddr = sdkerrors.Register(ModuleName, 24, "delegator does not exist with address") - ErrNoDelegatorForAddress = sdkerrors.Register(ModuleName, 25, "delegator does not contain delegation") - ErrInsufficientShares = sdkerrors.Register(ModuleName, 26, "insufficient delegation shares") - ErrDelegationValidatorEmpty = sdkerrors.Register(ModuleName, 27, "cannot delegate to an empty validator") - ErrNotEnoughDelegationShares = sdkerrors.Register(ModuleName, 28, "not enough delegation shares") - ErrBadSharesAmount = sdkerrors.Register(ModuleName, 29, "invalid shares amount") - ErrBadSharesPercent = sdkerrors.Register(ModuleName, 30, "Invalid shares percent") - ErrNotMature = sdkerrors.Register(ModuleName, 31, "entry not mature") - ErrNoUnbondingDelegation = sdkerrors.Register(ModuleName, 32, "no unbonding delegation found") - ErrMaxUnbondingDelegationEntries = sdkerrors.Register(ModuleName, 33, "too many unbonding delegation entries for (delegator, validator) tuple") - ErrBadRedelegationAddr = sdkerrors.Register(ModuleName, 34, "invalid address for (address, src-validator, dst-validator) tuple") - ErrNoRedelegation = sdkerrors.Register(ModuleName, 35, "no redelegation found") - ErrSelfRedelegation = sdkerrors.Register(ModuleName, 36, "cannot redelegate to the same validator") - ErrTinyRedelegationAmount = sdkerrors.Register(ModuleName, 37, "too few tokens to redelegate (truncates to zero tokens)") - ErrBadRedelegationDst = sdkerrors.Register(ModuleName, 38, "redelegation destination validator not found") - ErrTransitiveRedelegation = sdkerrors.Register(ModuleName, 39, "redelegation to this validator already in progress; first redelegation to this validator must complete before next redelegation") - ErrMaxRedelegationEntries = sdkerrors.Register(ModuleName, 40, "too many redelegation entries for (delegator, src-validator, dst-validator) tuple") - ErrDelegatorShareExRateInvalid = sdkerrors.Register(ModuleName, 41, "cannot delegate to validators with invalid (zero) ex-rate") - ErrBothShareMsgsGiven = sdkerrors.Register(ModuleName, 42, "both shares amount and shares percent provided") - ErrNeitherShareMsgsGiven = sdkerrors.Register(ModuleName, 43, "neither shares amount nor shares percent provided") - ErrInvalidHistoricalInfo = sdkerrors.Register(ModuleName, 44, "invalid historical info") - ErrNoHistoricalInfo = sdkerrors.Register(ModuleName, 45, "no historical info found") - ErrEmptyValidatorPubKey = sdkerrors.Register(ModuleName, 46, "empty validator public key") + ErrEmptyValidatorAddr = sdkerrors.Register(ModuleName, 2, "empty validator address") + ErrBadValidatorAddr = sdkerrors.Register(ModuleName, 3, "validator address is invalid") + ErrNoValidatorFound = sdkerrors.Register(ModuleName, 4, "validator does not exist") + ErrValidatorOwnerExists = sdkerrors.Register(ModuleName, 5, "validator already exist for this operator address; must use new validator operator address") + ErrValidatorPubKeyExists = sdkerrors.Register(ModuleName, 6, "validator already exist for this pubkey; must use new validator pubkey") + ErrValidatorPubKeyTypeNotSupported = sdkerrors.Register(ModuleName, 7, "validator pubkey type is not supported") + ErrValidatorJailed = sdkerrors.Register(ModuleName, 8, "validator for this address is currently jailed") + ErrBadRemoveValidator = sdkerrors.Register(ModuleName, 9, "failed to remove validator") + ErrCommissionNegative = sdkerrors.Register(ModuleName, 10, "commission must be positive") + ErrCommissionHuge = sdkerrors.Register(ModuleName, 11, "commission cannot be more than 100%") + ErrCommissionGTMaxRate = sdkerrors.Register(ModuleName, 12, "commission cannot be more than the max rate") + ErrCommissionUpdateTime = sdkerrors.Register(ModuleName, 13, "commission cannot be changed more than once in 24h") + ErrCommissionChangeRateNegative = sdkerrors.Register(ModuleName, 14, "commission change rate must be positive") + ErrCommissionChangeRateGTMaxRate = sdkerrors.Register(ModuleName, 15, "commission change rate cannot be more than the max rate") + ErrCommissionGTMaxChangeRate = sdkerrors.Register(ModuleName, 16, "commission cannot be changed more than max change rate") + ErrSelfDelegationBelowMinimum = sdkerrors.Register(ModuleName, 17, "validator's self delegation must be greater than their minimum self delegation") + ErrMinSelfDelegationInvalid = sdkerrors.Register(ModuleName, 18, "minimum self delegation must be a positive integer") + ErrMinSelfDelegationDecreased = sdkerrors.Register(ModuleName, 19, "minimum self delegation cannot be decrease") + ErrEmptyDelegatorAddr = sdkerrors.Register(ModuleName, 20, "empty delegator address") + ErrBadDenom = sdkerrors.Register(ModuleName, 21, "invalid coin denomination") + ErrBadDelegationAddr = sdkerrors.Register(ModuleName, 22, "invalid address for (address, validator) tuple") + ErrBadDelegationAmount = sdkerrors.Register(ModuleName, 23, "invalid delegation amount") + ErrNoDelegation = sdkerrors.Register(ModuleName, 24, "no delegation for (address, validator) tuple") + ErrBadDelegatorAddr = sdkerrors.Register(ModuleName, 25, "delegator does not exist with address") + ErrNoDelegatorForAddress = sdkerrors.Register(ModuleName, 26, "delegator does not contain delegation") + ErrInsufficientShares = sdkerrors.Register(ModuleName, 27, "insufficient delegation shares") + ErrDelegationValidatorEmpty = sdkerrors.Register(ModuleName, 28, "cannot delegate to an empty validator") + ErrNotEnoughDelegationShares = sdkerrors.Register(ModuleName, 29, "not enough delegation shares") + ErrBadSharesAmount = sdkerrors.Register(ModuleName, 30, "invalid shares amount") + ErrBadSharesPercent = sdkerrors.Register(ModuleName, 31, "Invalid shares percent") + ErrNotMature = sdkerrors.Register(ModuleName, 32, "entry not mature") + ErrNoUnbondingDelegation = sdkerrors.Register(ModuleName, 33, "no unbonding delegation found") + ErrMaxUnbondingDelegationEntries = sdkerrors.Register(ModuleName, 34, "too many unbonding delegation entries for (delegator, validator) tuple") + ErrBadRedelegationAddr = sdkerrors.Register(ModuleName, 35, "invalid address for (address, src-validator, dst-validator) tuple") + ErrNoRedelegation = sdkerrors.Register(ModuleName, 36, "no redelegation found") + ErrSelfRedelegation = sdkerrors.Register(ModuleName, 37, "cannot redelegate to the same validator") + ErrTinyRedelegationAmount = sdkerrors.Register(ModuleName, 38, "too few tokens to redelegate (truncates to zero tokens)") + ErrBadRedelegationDst = sdkerrors.Register(ModuleName, 39, "redelegation destination validator not found") + ErrTransitiveRedelegation = sdkerrors.Register(ModuleName, 40, "redelegation to this validator already in progress; first redelegation to this validator must complete before next redelegation") + ErrMaxRedelegationEntries = sdkerrors.Register(ModuleName, 41, "too many redelegation entries for (delegator, src-validator, dst-validator) tuple") + ErrDelegatorShareExRateInvalid = sdkerrors.Register(ModuleName, 42, "cannot delegate to validators with invalid (zero) ex-rate") + ErrBothShareMsgsGiven = sdkerrors.Register(ModuleName, 43, "both shares amount and shares percent provided") + ErrNeitherShareMsgsGiven = sdkerrors.Register(ModuleName, 44, "neither shares amount nor shares percent provided") + ErrInvalidHistoricalInfo = sdkerrors.Register(ModuleName, 45, "invalid historical info") + ErrNoHistoricalInfo = sdkerrors.Register(ModuleName, 46, "no historical info found") + ErrEmptyValidatorPubKey = sdkerrors.Register(ModuleName, 47, "empty validator public key") ) diff --git a/x/supply/alias.go b/x/supply/alias.go index 1138f7c5eee2..40d9c2fbe192 100644 --- a/x/supply/alias.go +++ b/x/supply/alias.go @@ -1,13 +1,11 @@ -// nolint -// autogenerated code using github.com/rigelrozanski/multitool -// aliases generated for the following subdirectories: -// ALIASGEN: github.com/cosmos/cosmos-sdk/x/supply/internal/keeper -// ALIASGEN: github.com/cosmos/cosmos-sdk/x/supply/internal/types package supply +// DONTCOVER +// nolint + import ( - "github.com/cosmos/cosmos-sdk/x/supply/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/keeper" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) const ( @@ -46,4 +44,5 @@ type ( ModuleAccount = types.ModuleAccount GenesisState = types.GenesisState Supply = types.Supply + Codec = types.Codec ) diff --git a/x/supply/client/cli/query.go b/x/supply/client/cli/query.go index 26c4a77cd506..95dd5b7bc589 100644 --- a/x/supply/client/cli/query.go +++ b/x/supply/client/cli/query.go @@ -12,7 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // GetQueryCmd returns the cli query commands for this module diff --git a/x/supply/client/rest/query.go b/x/supply/client/rest/query.go index cea93b50b095..021159dfaf17 100644 --- a/x/supply/client/rest/query.go +++ b/x/supply/client/rest/query.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // RegisterRoutes registers staking-related REST handlers to a router diff --git a/x/supply/exported/exported.go b/x/supply/exported/exported.go index e872e1deabd1..cecfc8e20429 100644 --- a/x/supply/exported/exported.go +++ b/x/supply/exported/exported.go @@ -6,7 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/exported" ) -// ModuleAccountI defines an account interface for modules that hold tokens in an escrow +// ModuleAccountI defines an account interface for modules that hold tokens in +// an escrow. type ModuleAccountI interface { exported.Account @@ -19,10 +20,10 @@ type ModuleAccountI interface { // token supply. type SupplyI interface { GetTotal() sdk.Coins - SetTotal(total sdk.Coins) SupplyI + SetTotal(total sdk.Coins) - Inflate(amount sdk.Coins) SupplyI - Deflate(amount sdk.Coins) SupplyI + Inflate(amount sdk.Coins) + Deflate(amount sdk.Coins) String() string ValidateBasic() error diff --git a/x/supply/genesis.go b/x/supply/genesis.go index 17546515cf43..98f0e1f4f714 100644 --- a/x/supply/genesis.go +++ b/x/supply/genesis.go @@ -2,7 +2,7 @@ package supply import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // InitGenesis sets supply information for genesis. diff --git a/x/supply/internal/keeper/integration_test.go b/x/supply/internal/keeper/integration_test.go deleted file mode 100644 index be065ea16ae8..000000000000 --- a/x/supply/internal/keeper/integration_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package keeper_test - -import ( - abci "github.com/tendermint/tendermint/abci/types" - - "github.com/cosmos/cosmos-sdk/simapp" - sdk "github.com/cosmos/cosmos-sdk/types" - keep "github.com/cosmos/cosmos-sdk/x/supply/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" -) - -var ( - multiPerm = "multiple permissions account" - randomPerm = "random permission" - holder = "holder" -) - -// nolint:deadcode,unused -func createTestApp(isCheckTx bool) (*simapp.SimApp, sdk.Context) { - app := simapp.Setup(isCheckTx) - - // add module accounts to supply keeper - maccPerms := simapp.GetMaccPerms() - maccPerms[holder] = nil - maccPerms[types.Burner] = []string{types.Burner} - maccPerms[types.Minter] = []string{types.Minter} - maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} - maccPerms[randomPerm] = []string{"random"} - - ctx := app.BaseApp.NewContext(isCheckTx, abci.Header{}) - app.SupplyKeeper = keep.NewKeeper(app.Codec(), app.GetKey(types.StoreKey), app.AccountKeeper, app.BankKeeper, maccPerms) - app.SupplyKeeper.SetSupply(ctx, types.NewSupply(sdk.NewCoins())) - - return app, ctx -} diff --git a/x/supply/internal/keeper/keeper_test.go b/x/supply/internal/keeper/keeper_test.go deleted file mode 100644 index d4ff2849e4ca..000000000000 --- a/x/supply/internal/keeper/keeper_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package keeper_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" -) - -func TestSupply(t *testing.T) { - initialPower := int64(100) - initTokens := sdk.TokensFromConsensusPower(initialPower) - - app, ctx := createTestApp(false) - totalSupply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens)) - app.SupplyKeeper.SetSupply(ctx, types.NewSupply(totalSupply)) - - total := app.SupplyKeeper.GetSupply(ctx).GetTotal() - - require.Equal(t, totalSupply, total) -} - -func TestValidatePermissions(t *testing.T) { - app, _ := createTestApp(false) - - err := app.SupplyKeeper.ValidatePermissions(multiPermAcc) - require.NoError(t, err) - - err = app.SupplyKeeper.ValidatePermissions(randomPermAcc) - require.NoError(t, err) - - // unregistered permissions - otherAcc := types.NewEmptyModuleAccount("other", "other") - err = app.SupplyKeeper.ValidatePermissions(otherAcc) - require.Error(t, err) -} diff --git a/x/supply/internal/types/codec.go b/x/supply/internal/types/codec.go deleted file mode 100644 index 89bc9a2ffcf3..000000000000 --- a/x/supply/internal/types/codec.go +++ /dev/null @@ -1,24 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/supply/exported" -) - -// RegisterCodec registers the account types and interface -func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterInterface((*exported.ModuleAccountI)(nil), nil) - cdc.RegisterInterface((*exported.SupplyI)(nil), nil) - cdc.RegisterConcrete(&ModuleAccount{}, "cosmos-sdk/ModuleAccount", nil) - cdc.RegisterConcrete(&Supply{}, "cosmos-sdk/Supply", nil) -} - -// ModuleCdc generic sealed codec to be used throughout module -var ModuleCdc *codec.Codec - -func init() { - cdc := codec.New() - RegisterCodec(cdc) - codec.RegisterCrypto(cdc) - ModuleCdc = cdc.Seal() -} diff --git a/x/supply/internal/keeper/account.go b/x/supply/keeper/account.go similarity index 97% rename from x/supply/internal/keeper/account.go rename to x/supply/keeper/account.go index 312b039be2c5..685308cf6102 100644 --- a/x/supply/internal/keeper/account.go +++ b/x/supply/keeper/account.go @@ -3,7 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/supply/exported" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // GetModuleAddress returns an address based on the module name diff --git a/x/supply/internal/keeper/bank.go b/x/supply/keeper/bank.go similarity index 97% rename from x/supply/internal/keeper/bank.go rename to x/supply/keeper/bank.go index 9117286aaeb6..4213c8b0d8ee 100644 --- a/x/supply/internal/keeper/bank.go +++ b/x/supply/keeper/bank.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // SendCoinsFromModuleToAccount transfers coins from a ModuleAccount to an AccAddress. @@ -112,7 +112,7 @@ func (k Keeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) err // update total supply supply := k.GetSupply(ctx) - supply = supply.Inflate(amt) + supply.Inflate(amt) k.SetSupply(ctx, supply) @@ -141,7 +141,7 @@ func (k Keeper) BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) err // update total supply supply := k.GetSupply(ctx) - supply = supply.Deflate(amt) + supply.Deflate(amt) k.SetSupply(ctx, supply) logger := k.Logger(ctx) diff --git a/x/supply/internal/keeper/bank_test.go b/x/supply/keeper/bank_test.go similarity index 72% rename from x/supply/internal/keeper/bank_test.go rename to x/supply/keeper/bank_test.go index 5388dc804d49..cb6237147864 100644 --- a/x/supply/internal/keeper/bank_test.go +++ b/x/supply/keeper/bank_test.go @@ -4,13 +4,21 @@ import ( "testing" "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/cosmos/cosmos-sdk/simapp" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" sdk "github.com/cosmos/cosmos-sdk/types" - keep "github.com/cosmos/cosmos-sdk/x/supply/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + keep "github.com/cosmos/cosmos-sdk/x/supply/keeper" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) -const initialPower = int64(100) +const ( + initialPower = int64(100) + holder = "holder" + multiPerm = "multiple permissions account" + randomPerm = "random permission" +) // create module accounts for testing var ( @@ -36,8 +44,20 @@ func getCoinsByName(ctx sdk.Context, sk keep.Keeper, ak types.AccountKeeper, bk } func TestSendCoins(t *testing.T) { - app, ctx := createTestApp(false) - keeper := app.SupplyKeeper + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1}) + + // add module accounts to supply keeper + maccPerms := simapp.GetMaccPerms() + maccPerms[holder] = nil + maccPerms[types.Burner] = []string{types.Burner} + maccPerms[types.Minter] = []string{types.Minter} + maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} + maccPerms[randomPerm] = []string{"random"} + + appCodec := simappcodec.NewAppCodec(app.Codec()) + + keeper := keep.NewKeeper(appCodec, app.GetKey(types.StoreKey), app.AccountKeeper, app.BankKeeper, maccPerms) ak := app.AccountKeeper bk := app.BankKeeper @@ -85,8 +105,20 @@ func TestSendCoins(t *testing.T) { } func TestMintCoins(t *testing.T) { - app, ctx := createTestApp(false) - keeper := app.SupplyKeeper + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1}) + + // add module accounts to supply keeper + maccPerms := simapp.GetMaccPerms() + maccPerms[holder] = nil + maccPerms[types.Burner] = []string{types.Burner} + maccPerms[types.Minter] = []string{types.Minter} + maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} + maccPerms[randomPerm] = []string{"random"} + + appCodec := simappcodec.NewAppCodec(app.Codec()) + + keeper := keep.NewKeeper(appCodec, app.GetKey(types.StoreKey), app.AccountKeeper, app.BankKeeper, maccPerms) ak := app.AccountKeeper bk := app.BankKeeper @@ -121,8 +153,20 @@ func TestMintCoins(t *testing.T) { } func TestBurnCoins(t *testing.T) { - app, ctx := createTestApp(false) - keeper := app.SupplyKeeper + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1}) + + // add module accounts to supply keeper + maccPerms := simapp.GetMaccPerms() + maccPerms[holder] = nil + maccPerms[types.Burner] = []string{types.Burner} + maccPerms[types.Minter] = []string{types.Minter} + maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} + maccPerms[randomPerm] = []string{"random"} + + appCodec := simappcodec.NewAppCodec(app.Codec()) + + keeper := keep.NewKeeper(appCodec, app.GetKey(types.StoreKey), app.AccountKeeper, app.BankKeeper, maccPerms) ak := app.AccountKeeper bk := app.BankKeeper @@ -131,7 +175,7 @@ func TestBurnCoins(t *testing.T) { keeper.SetModuleAccount(ctx, burnerAcc) initialSupply := keeper.GetSupply(ctx) - initialSupply = initialSupply.Inflate(initCoins) + initialSupply.Inflate(initCoins) keeper.SetSupply(ctx, initialSupply) require.Panics(t, func() { keeper.BurnCoins(ctx, "", initCoins) }, "no module account") @@ -147,7 +191,7 @@ func TestBurnCoins(t *testing.T) { // test same functionality on module account with multiple permissions initialSupply = keeper.GetSupply(ctx) - initialSupply = initialSupply.Inflate(initCoins) + initialSupply.Inflate(initCoins) keeper.SetSupply(ctx, initialSupply) require.NoError(t, bk.SetBalances(ctx, multiPermAcc.GetAddress(), initCoins)) diff --git a/x/supply/internal/keeper/invariants.go b/x/supply/keeper/invariants.go similarity index 95% rename from x/supply/internal/keeper/invariants.go rename to x/supply/keeper/invariants.go index 0b5ca06694ed..d53b7637f1ef 100644 --- a/x/supply/internal/keeper/invariants.go +++ b/x/supply/keeper/invariants.go @@ -4,7 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // RegisterInvariants register all supply invariants diff --git a/x/supply/internal/keeper/keeper.go b/x/supply/keeper/keeper.go similarity index 74% rename from x/supply/internal/keeper/keeper.go rename to x/supply/keeper/keeper.go index b071f878db33..012a5cf284aa 100644 --- a/x/supply/internal/keeper/keeper.go +++ b/x/supply/keeper/keeper.go @@ -5,15 +5,14 @@ import ( "github.com/tendermint/tendermint/libs/log" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/supply/exported" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // Keeper of the supply store type Keeper struct { - cdc *codec.Codec + cdc types.Codec storeKey sdk.StoreKey ak types.AccountKeeper bk types.BankKeeper @@ -21,8 +20,11 @@ type Keeper struct { } // NewKeeper creates a new Keeper instance -func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, maccPerms map[string][]string) Keeper { - // set the addresses +func NewKeeper( + cdc types.Codec, key sdk.StoreKey, ak types.AccountKeeper, + bk types.BankKeeper, maccPerms map[string][]string, +) Keeper { + permAddrs := make(map[string]types.PermissionsForAddress) for name, perms := range maccPerms { permAddrs[name] = types.NewPermissionsForAddress(name, perms) @@ -43,21 +45,30 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { } // GetSupply retrieves the Supply from store -func (k Keeper) GetSupply(ctx sdk.Context) (supply exported.SupplyI) { +func (k Keeper) GetSupply(ctx sdk.Context) exported.SupplyI { store := ctx.KVStore(k.storeKey) - b := store.Get(SupplyKey) - if b == nil { + bz := store.Get(SupplyKey) + if bz == nil { panic("stored supply should not have been nil") } - k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &supply) - return + + supply, err := k.cdc.UnmarshalSupply(bz) + if err != nil { + panic(err) + } + + return supply } // SetSupply sets the Supply to store func (k Keeper) SetSupply(ctx sdk.Context, supply exported.SupplyI) { store := ctx.KVStore(k.storeKey) - b := k.cdc.MustMarshalBinaryLengthPrefixed(supply) - store.Set(SupplyKey, b) + bz, err := k.cdc.MarshalSupply(supply) + if err != nil { + panic(err) + } + + store.Set(SupplyKey, bz) } // ValidatePermissions validates that the module account has been granted @@ -69,5 +80,6 @@ func (k Keeper) ValidatePermissions(macc exported.ModuleAccountI) error { return fmt.Errorf("invalid module permission %s", perm) } } + return nil } diff --git a/x/supply/keeper/keeper_test.go b/x/supply/keeper/keeper_test.go new file mode 100644 index 000000000000..a81575914abc --- /dev/null +++ b/x/supply/keeper/keeper_test.go @@ -0,0 +1,55 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/simapp" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + keep "github.com/cosmos/cosmos-sdk/x/supply/keeper" + "github.com/cosmos/cosmos-sdk/x/supply/types" +) + +func TestSupply(t *testing.T) { + initialPower := int64(100) + initTokens := sdk.TokensFromConsensusPower(initialPower) + + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1}) + + totalSupply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens)) + app.SupplyKeeper.SetSupply(ctx, types.NewSupply(totalSupply)) + + total := app.SupplyKeeper.GetSupply(ctx).GetTotal() + + require.Equal(t, totalSupply, total) +} + +func TestValidatePermissions(t *testing.T) { + app := simapp.Setup(false) + + // add module accounts to supply keeper + maccPerms := simapp.GetMaccPerms() + maccPerms[holder] = nil + maccPerms[types.Burner] = []string{types.Burner} + maccPerms[types.Minter] = []string{types.Minter} + maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} + maccPerms[randomPerm] = []string{"random"} + + appCodec := simappcodec.NewAppCodec(app.Codec()) + keeper := keep.NewKeeper(appCodec, app.GetKey(types.StoreKey), app.AccountKeeper, app.BankKeeper, maccPerms) + + err := keeper.ValidatePermissions(multiPermAcc) + require.NoError(t, err) + + err = keeper.ValidatePermissions(randomPermAcc) + require.NoError(t, err) + + // unregistered permissions + otherAcc := types.NewEmptyModuleAccount("other", "other") + err = app.SupplyKeeper.ValidatePermissions(otherAcc) + require.Error(t, err) +} diff --git a/x/supply/internal/keeper/key.go b/x/supply/keeper/key.go similarity index 100% rename from x/supply/internal/keeper/key.go rename to x/supply/keeper/key.go diff --git a/x/supply/internal/keeper/querier.go b/x/supply/keeper/querier.go similarity index 97% rename from x/supply/internal/keeper/querier.go rename to x/supply/keeper/querier.go index 093edd2c6bea..1150fe3ad4f0 100644 --- a/x/supply/internal/keeper/querier.go +++ b/x/supply/keeper/querier.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // NewQuerier creates a querier for supply REST endpoints diff --git a/x/supply/internal/keeper/querier_test.go b/x/supply/keeper/querier_test.go similarity index 89% rename from x/supply/internal/keeper/querier_test.go rename to x/supply/keeper/querier_test.go index 92b0dcf32b15..e71fa664bbac 100644 --- a/x/supply/internal/keeper/querier_test.go +++ b/x/supply/keeper/querier_test.go @@ -7,13 +7,16 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" + "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - keep "github.com/cosmos/cosmos-sdk/x/supply/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + keep "github.com/cosmos/cosmos-sdk/x/supply/keeper" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) func TestNewQuerier(t *testing.T) { - app, ctx := createTestApp(false) + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1}) + keeper := app.SupplyKeeper cdc := app.Codec() @@ -59,7 +62,9 @@ func TestNewQuerier(t *testing.T) { } func TestQuerySupply(t *testing.T) { - app, ctx := createTestApp(false) + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1}) + keeper := app.SupplyKeeper cdc := app.Codec() diff --git a/x/supply/module.go b/x/supply/module.go index 73d05a772246..1a2531d99259 100644 --- a/x/supply/module.go +++ b/x/supply/module.go @@ -17,8 +17,8 @@ import ( sim "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/cosmos/cosmos-sdk/x/supply/client/cli" "github.com/cosmos/cosmos-sdk/x/supply/client/rest" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" "github.com/cosmos/cosmos-sdk/x/supply/simulation" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) var ( @@ -42,14 +42,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { // DefaultGenesis returns default genesis state as raw bytes for the supply // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the supply module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -120,18 +120,18 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the supply module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.keeper, am.bk, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the supply // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.keeper) - return ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock returns the begin blocker for the supply module. diff --git a/x/supply/simulation/decoder.go b/x/supply/simulation/decoder.go index 3337e4b0687f..b67e07651be4 100644 --- a/x/supply/simulation/decoder.go +++ b/x/supply/simulation/decoder.go @@ -7,8 +7,8 @@ import ( tmkv "github.com/tendermint/tendermint/libs/kv" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/supply/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/keeper" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // DecodeStore unmarshals the KVPair's Value to the corresponding supply type @@ -19,6 +19,7 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &supplyA) cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &supplyB) return fmt.Sprintf("%v\n%v", supplyB, supplyB) + default: panic(fmt.Sprintf("invalid supply key %X", kvA.Key)) } diff --git a/x/supply/simulation/decoder_test.go b/x/supply/simulation/decoder_test.go index f653632f168d..413e0a930e9d 100644 --- a/x/supply/simulation/decoder_test.go +++ b/x/supply/simulation/decoder_test.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/supply/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/keeper" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) func makeTestCodec() (cdc *codec.Codec) { diff --git a/x/supply/simulation/genesis.go b/x/supply/simulation/genesis.go index 53775fbc07d6..b261fa8aa884 100644 --- a/x/supply/simulation/genesis.go +++ b/x/supply/simulation/genesis.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // RandomizedGenState generates a random GenesisState for supply diff --git a/x/supply/internal/types/account.go b/x/supply/types/account.go similarity index 85% rename from x/supply/internal/types/account.go rename to x/supply/types/account.go index 533084d2b0bd..14b91bb234ea 100644 --- a/x/supply/internal/types/account.go +++ b/x/supply/types/account.go @@ -21,21 +21,6 @@ var ( _ exported.ModuleAccountI = (*ModuleAccount)(nil) ) -func init() { - // Register the ModuleAccount type as a GenesisAccount so that when no - // concrete GenesisAccount types exist and **default** genesis state is used, - // the genesis state will serialize correctly. - authtypes.RegisterAccountTypeCodec(&ModuleAccount{}, "cosmos-sdk/ModuleAccount") -} - -// ModuleAccount defines an account for modules that holds coins on a pool -type ModuleAccount struct { - *authtypes.BaseAccount - - Name string `json:"name" yaml:"name"` // name of the module - Permissions []string `json:"permissions" yaml:"permissions"` // permissions of module account -} - // NewModuleAddress creates an AccAddress from the hash of the module's name func NewModuleAddress(name string) sdk.AccAddress { return sdk.AccAddress(crypto.AddressHash([]byte(name))) @@ -51,16 +36,14 @@ func NewEmptyModuleAccount(name string, permissions ...string) *ModuleAccount { } return &ModuleAccount{ - BaseAccount: &baseAcc, + BaseAccount: baseAcc, Name: name, Permissions: permissions, } } // NewModuleAccount creates a new ModuleAccount instance -func NewModuleAccount(ba *authtypes.BaseAccount, - name string, permissions ...string) *ModuleAccount { - +func NewModuleAccount(ba *authtypes.BaseAccount, name string, permissions ...string) *ModuleAccount { if err := validatePermissions(permissions...); err != nil { panic(err) } diff --git a/x/supply/internal/types/account_test.go b/x/supply/types/account_test.go similarity index 99% rename from x/supply/internal/types/account_test.go rename to x/supply/types/account_test.go index a3ee01bf1afa..a93fa5c94929 100644 --- a/x/supply/internal/types/account_test.go +++ b/x/supply/types/account_test.go @@ -6,15 +6,13 @@ import ( "fmt" "testing" - yaml "gopkg.in/yaml.v2" - + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/secp256k1" + yaml "gopkg.in/yaml.v2" sdk "github.com/cosmos/cosmos-sdk/types" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - - "github.com/stretchr/testify/require" ) func TestModuleAccountMarshalYAML(t *testing.T) { diff --git a/x/supply/types/codec.go b/x/supply/types/codec.go new file mode 100644 index 000000000000..f452d4b5a987 --- /dev/null +++ b/x/supply/types/codec.go @@ -0,0 +1,45 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/x/supply/exported" +) + +// Codec defines the interface needed to serialize x/supply state. It must +// be aware of all concrete supply types. +type Codec interface { + codec.Marshaler + + MarshalSupply(supply exported.SupplyI) ([]byte, error) + UnmarshalSupply(bz []byte) (exported.SupplyI, error) + + MarshalSupplyJSON(supply exported.SupplyI) ([]byte, error) + UnmarshalSupplyJSON(bz []byte) (exported.SupplyI, error) +} + +// RegisterCodec registers the necessary x/supply interfaces and concrete types +// on the provided Amino codec. These types are used for Amino JSON serialization. +func RegisterCodec(cdc *codec.Codec) { + cdc.RegisterInterface((*exported.ModuleAccountI)(nil), nil) + cdc.RegisterInterface((*exported.SupplyI)(nil), nil) + cdc.RegisterConcrete(&ModuleAccount{}, "cosmos-sdk/ModuleAccount", nil) + cdc.RegisterConcrete(&Supply{}, "cosmos-sdk/Supply", nil) +} + +var ( + amino = codec.New() + + // ModuleCdc references the global x/supply module codec. Note, the codec should + // ONLY be used in certain instances of tests and for JSON encoding as Amino is + // still used for that purpose. + // + // The actual codec used for serialization should be provided to x/supply and + // defined at the application level. + ModuleCdc = codec.NewHybridCodec(amino) +) + +func init() { + RegisterCodec(amino) + codec.RegisterCrypto(amino) + amino.Seal() +} diff --git a/x/supply/internal/types/expected_keepers.go b/x/supply/types/expected_keepers.go similarity index 100% rename from x/supply/internal/types/expected_keepers.go rename to x/supply/types/expected_keepers.go diff --git a/x/supply/internal/types/genesis.go b/x/supply/types/genesis.go similarity index 100% rename from x/supply/internal/types/genesis.go rename to x/supply/types/genesis.go diff --git a/x/supply/internal/types/key.go b/x/supply/types/key.go similarity index 100% rename from x/supply/internal/types/key.go rename to x/supply/types/key.go diff --git a/x/supply/internal/types/permissions.go b/x/supply/types/permissions.go similarity index 100% rename from x/supply/internal/types/permissions.go rename to x/supply/types/permissions.go diff --git a/x/supply/internal/types/permissions_test.go b/x/supply/types/permissions_test.go similarity index 100% rename from x/supply/internal/types/permissions_test.go rename to x/supply/types/permissions_test.go diff --git a/x/supply/internal/types/querier.go b/x/supply/types/querier.go similarity index 100% rename from x/supply/internal/types/querier.go rename to x/supply/types/querier.go diff --git a/x/supply/internal/types/supply.go b/x/supply/types/supply.go similarity index 56% rename from x/supply/internal/types/supply.go rename to x/supply/types/supply.go index 92e4a3e5d2f5..de5a4d751f7a 100644 --- a/x/supply/internal/types/supply.go +++ b/x/supply/types/supply.go @@ -10,17 +10,21 @@ import ( ) // Implements Delegation interface -var _ exported.SupplyI = Supply{} +var _ exported.SupplyI = (*Supply)(nil) -// Supply represents a struct that passively keeps track of the total supply amounts in the network -type Supply struct { - Total sdk.Coins `json:"total" yaml:"total"` // total supply of tokens registered on the chain +// NewSupply creates a new Supply instance +func NewSupply(total sdk.Coins) *Supply { + return &Supply{total} +} + +// DefaultSupply creates an empty Supply +func DefaultSupply() *Supply { + return NewSupply(sdk.NewCoins()) } // SetTotal sets the total supply. -func (supply Supply) SetTotal(total sdk.Coins) exported.SupplyI { +func (supply *Supply) SetTotal(total sdk.Coins) { supply.Total = total - return supply } // GetTotal returns the supply total. @@ -28,35 +32,20 @@ func (supply Supply) GetTotal() sdk.Coins { return supply.Total } -// NewSupply creates a new Supply instance -func NewSupply(total sdk.Coins) exported.SupplyI { - return Supply{total} -} - -// DefaultSupply creates an empty Supply -func DefaultSupply() exported.SupplyI { - return NewSupply(sdk.NewCoins()) -} - // Inflate adds coins to the total supply -func (supply Supply) Inflate(amount sdk.Coins) exported.SupplyI { +func (supply *Supply) Inflate(amount sdk.Coins) { supply.Total = supply.Total.Add(amount...) - return supply } -// Deflate subtracts coins from the total supply -func (supply Supply) Deflate(amount sdk.Coins) exported.SupplyI { +// Deflate subtracts coins from the total supply. +func (supply *Supply) Deflate(amount sdk.Coins) { supply.Total = supply.Total.Sub(amount) - return supply } // String returns a human readable string representation of a supplier. func (supply Supply) String() string { - b, err := yaml.Marshal(supply) - if err != nil { - panic(err) - } - return string(b) + bz, _ := yaml.Marshal(supply) + return string(bz) } // ValidateBasic validates the Supply coins and returns error if invalid diff --git a/x/supply/internal/types/supply_test.go b/x/supply/types/supply_test.go similarity index 94% rename from x/supply/internal/types/supply_test.go rename to x/supply/types/supply_test.go index e99e1e5aea49..4af49d362fd1 100644 --- a/x/supply/internal/types/supply_test.go +++ b/x/supply/types/supply_test.go @@ -14,7 +14,7 @@ import ( func TestSupplyMarshalYAML(t *testing.T) { supply := DefaultSupply() coins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.OneInt())) - supply = supply.Inflate(coins) + supply.Inflate(coins) bz, err := yaml.Marshal(supply) require.NoError(t, err) diff --git a/x/supply/types/types.pb.go b/x/supply/types/types.pb.go new file mode 100644 index 000000000000..399056115635 --- /dev/null +++ b/x/supply/types/types.pb.go @@ -0,0 +1,605 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/supply/types/types.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types1 "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/x/auth/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/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 + +// ModuleAccount defines an account for modules that holds coins on a pool +type ModuleAccount struct { + *types.BaseAccount `protobuf:"bytes,1,opt,name=base_account,json=baseAccount,proto3,embedded=base_account" json:"base_account,omitempty" yaml:"base_account"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Permissions []string `protobuf:"bytes,3,rep,name=permissions,proto3" json:"permissions,omitempty"` +} + +func (m *ModuleAccount) Reset() { *m = ModuleAccount{} } +func (*ModuleAccount) ProtoMessage() {} +func (*ModuleAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_e14b855c341cf347, []int{0} +} +func (m *ModuleAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ModuleAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ModuleAccount.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 *ModuleAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_ModuleAccount.Merge(m, src) +} +func (m *ModuleAccount) XXX_Size() int { + return m.Size() +} +func (m *ModuleAccount) XXX_DiscardUnknown() { + xxx_messageInfo_ModuleAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_ModuleAccount proto.InternalMessageInfo + +// Supply represents a struct that passively keeps track of the total supply +// amounts in the network. +type Supply struct { + Total github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=total,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"total"` +} + +func (m *Supply) Reset() { *m = Supply{} } +func (*Supply) ProtoMessage() {} +func (*Supply) Descriptor() ([]byte, []int) { + return fileDescriptor_e14b855c341cf347, []int{1} +} +func (m *Supply) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Supply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Supply.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 *Supply) XXX_Merge(src proto.Message) { + xxx_messageInfo_Supply.Merge(m, src) +} +func (m *Supply) XXX_Size() int { + return m.Size() +} +func (m *Supply) XXX_DiscardUnknown() { + xxx_messageInfo_Supply.DiscardUnknown(m) +} + +var xxx_messageInfo_Supply proto.InternalMessageInfo + +func init() { + proto.RegisterType((*ModuleAccount)(nil), "cosmos_sdk.x.supply.v1.ModuleAccount") + proto.RegisterType((*Supply)(nil), "cosmos_sdk.x.supply.v1.Supply") +} + +func init() { proto.RegisterFile("x/supply/types/types.proto", fileDescriptor_e14b855c341cf347) } + +var fileDescriptor_e14b855c341cf347 = []byte{ + // 348 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xaa, 0xd0, 0x2f, 0x2e, + 0x2d, 0x28, 0xc8, 0xa9, 0xd4, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, + 0x25, 0xf9, 0x42, 0x62, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, + 0x7a, 0x10, 0x65, 0x7a, 0x65, 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, + 0x45, 0x25, 0x95, 0xfa, 0x60, 0xa5, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0x44, 0xbf, 0x94, + 0x20, 0x86, 0x91, 0x52, 0x12, 0x15, 0xfa, 0x89, 0xa5, 0x25, 0x19, 0x98, 0x96, 0x29, 0x6d, 0x62, + 0xe4, 0xe2, 0xf5, 0xcd, 0x4f, 0x29, 0xcd, 0x49, 0x75, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0x11, + 0x4a, 0xe4, 0xe2, 0x49, 0x4a, 0x2c, 0x4e, 0x8d, 0x4f, 0x84, 0xf0, 0x25, 0x18, 0x15, 0x18, 0x35, + 0xb8, 0x8d, 0x14, 0xf5, 0x50, 0x5c, 0x05, 0x32, 0x4d, 0xaf, 0xcc, 0x50, 0xcf, 0x29, 0xb1, 0x18, + 0xa6, 0xd1, 0x49, 0xfa, 0xc2, 0x3d, 0x79, 0xc6, 0x4f, 0xf7, 0xe4, 0x85, 0x2b, 0x13, 0x73, 0x73, + 0xac, 0x94, 0x90, 0x0d, 0x51, 0x0a, 0xe2, 0x4e, 0x42, 0xa8, 0x14, 0x12, 0xe2, 0x62, 0xc9, 0x4b, + 0xcc, 0x4d, 0x95, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x0c, 0x02, 0xb3, 0x85, 0x14, 0xb8, 0xb8, 0x0b, + 0x52, 0x8b, 0x72, 0x33, 0x8b, 0x8b, 0x33, 0xf3, 0xf3, 0x8a, 0x25, 0x98, 0x15, 0x98, 0x35, 0x38, + 0x83, 0x90, 0x85, 0xac, 0x38, 0x3a, 0x16, 0xc8, 0x33, 0xcc, 0x58, 0x20, 0xcf, 0xa0, 0x94, 0xcf, + 0xc5, 0x16, 0x0c, 0x0e, 0x16, 0xa1, 0x68, 0x2e, 0xd6, 0x92, 0xfc, 0x92, 0xc4, 0x1c, 0x09, 0x46, + 0x05, 0x66, 0x0d, 0x6e, 0x23, 0x61, 0x64, 0x57, 0x96, 0x19, 0xea, 0x39, 0xe7, 0x67, 0xe6, 0x39, + 0x19, 0x9c, 0xb8, 0x27, 0xcf, 0xb0, 0xea, 0xbe, 0xbc, 0x46, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, + 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0x44, 0x19, 0x94, 0xd2, 0x2d, 0x4e, 0xc9, 0x86, 0x06, 0x0a, 0x48, + 0x43, 0x71, 0x10, 0xc4, 0x4c, 0x84, 0x85, 0x4e, 0xae, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, + 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, + 0x2c, 0xc7, 0x10, 0xa5, 0x8d, 0xd7, 0x50, 0xd4, 0x58, 0x4e, 0x62, 0x03, 0x87, 0xb9, 0x31, 0x20, + 0x00, 0x00, 0xff, 0xff, 0x95, 0xfd, 0xe3, 0x40, 0xfe, 0x01, 0x00, 0x00, +} + +func (m *ModuleAccount) 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 *ModuleAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ModuleAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Permissions) > 0 { + for iNdEx := len(m.Permissions) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Permissions[iNdEx]) + copy(dAtA[i:], m.Permissions[iNdEx]) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Permissions[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x12 + } + if m.BaseAccount != nil { + { + size, err := m.BaseAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Supply) 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 *Supply) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Supply) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Total) > 0 { + for iNdEx := len(m.Total) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Total[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ModuleAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BaseAccount != nil { + l = m.BaseAccount.Size() + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.Permissions) > 0 { + for _, s := range m.Permissions { + l = len(s) + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *Supply) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Total) > 0 { + for _, e := range m.Total { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *ModuleAccount) 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 ErrIntOverflowTypes + } + 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: ModuleAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ModuleAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.BaseAccount == nil { + m.BaseAccount = &types.BaseAccount{} + } + if err := m.BaseAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Permissions", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Permissions = append(m.Permissions, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Supply) 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 ErrIntOverflowTypes + } + 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: Supply: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Supply: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Total", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Total = append(m.Total, types1.Coin{}) + if err := m.Total[len(m.Total)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTypes(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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrInvalidLengthTypes + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTypes + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTypes + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/supply/types/types.proto b/x/supply/types/types.proto new file mode 100644 index 000000000000..0c14740ea29d --- /dev/null +++ b/x/supply/types/types.proto @@ -0,0 +1,31 @@ +syntax = "proto3"; +package cosmos_sdk.x.supply.v1; + +import "third_party/proto/gogoproto/gogo.proto"; +import "types/types.proto"; +import "x/auth/types/types.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/supply/types"; + +// ModuleAccount defines an account for modules that holds coins on a pool +message ModuleAccount { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + cosmos_sdk.x.auth.v1.BaseAccount base_account = 1 + [(gogoproto.embed) = true, (gogoproto.moretags) = "yaml:\"base_account\""]; + string name = 2; + repeated string permissions = 3; +} + +// Supply represents a struct that passively keeps track of the total supply +// amounts in the network. +message Supply { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + repeated cosmos_sdk.v1.Coin total = 1 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 5605ca0b673e..f5a9b461ef8d 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -103,23 +103,23 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { } // InitGenesis is ignored, no sense in serializing future upgrades -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONMarshaler, _ json.RawMessage) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} } // DefaultGenesis is an empty object -func (AppModuleBasic) DefaultGenesis() json.RawMessage { +func (AppModuleBasic) DefaultGenesis(_ codec.JSONMarshaler) json.RawMessage { return []byte("{}") } // ValidateGenesis is always successful, as we ignore the value -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(_ codec.JSONMarshaler, _ json.RawMessage) error { return nil } // ExportGenesis is always empty, as InitGenesis does nothing either -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { - return am.DefaultGenesis() +func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { + return am.DefaultGenesis(cdc) } // BeginBlock calls the upgrade module hooks From 4360aee1d54461a92728040581fcc579f711f25f Mon Sep 17 00:00:00 2001 From: anilCSE Date: Tue, 18 Feb 2020 19:57:40 +0530 Subject: [PATCH 46/52] Fix typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cb43bbda50c..cd5d7052bc68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,7 +82,7 @@ for JSON encoding. * Every reference of `crypto.Pubkey` in context of a `Validator` is now of type string. `GetPubKeyFromBech32` must be used to get the `crypto.Pubkey`. * The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type provided is specified by `ModuleCdc`. -* (x/slashing) [\#5627](https://github.com/cosmos/cosmos-sdk/pull/5627) Migrate the `x/slashing` module to use Protocol Buffer for state +* (x/slashing) [\#5627](https://github.com/cosmos/cosmos-sdk/pull/5627) Migrate the `x/slashing` module to use Protocol Buffers for state serialization instead of Amino. The exact codec used is `codec.HybridCodec` which utilizes Protobuf for binary encoding and Amino for JSON encoding. * The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type From 85b3a20d99946740302f1e9859ea99d6d50fdd5f Mon Sep 17 00:00:00 2001 From: anilCSE Date: Tue, 18 Feb 2020 20:25:42 +0530 Subject: [PATCH 47/52] Revert str conv --- x/slashing/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/slashing/handler.go b/x/slashing/handler.go index ed89734faa20..629a92dde29e 100644 --- a/x/slashing/handler.go +++ b/x/slashing/handler.go @@ -33,7 +33,7 @@ func handleMsgUnjail(ctx sdk.Context, msg MsgUnjail, k Keeper) (*sdk.Result, err sdk.NewEvent( sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttribute(sdk.AttributeKeySender, string(msg.ValidatorAddr)), + sdk.NewAttribute(sdk.AttributeKeySender, msg.ValidatorAddr.String()), ), ) From 47c5fb5e83cae86f4461ffd890402652f59473e7 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Tue, 18 Feb 2020 20:28:21 +0530 Subject: [PATCH 48/52] Fix gofmt --- x/slashing/alias.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/slashing/alias.go b/x/slashing/alias.go index c34371067e1e..d2e532d94501 100644 --- a/x/slashing/alias.go +++ b/x/slashing/alias.go @@ -34,7 +34,6 @@ const ( var ( // functions aliases - NewKeeper = keeper.NewKeeper NewQuerier = keeper.NewQuerier RegisterCodec = types.RegisterCodec From 9e7b6ede973920e2ce5779c3d3962b86dc46815c Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 19 Feb 2020 20:34:53 +0530 Subject: [PATCH 49/52] Fix review changes --- CHANGELOG.md | 1 - x/slashing/types/codec.go | 28 +++++++++++++--------------- x/slashing/types/types.proto | 2 +- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd5d7052bc68..0e515c76f66f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,7 +87,6 @@ serialization instead of Amino. The exact codec used is `codec.HybridCodec` whic for JSON encoding. * The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type provided is specified by `ModuleCdc`. -* (distr) [\#5610](https://github.com/cosmos/cosmos-sdk/pull/5610) Migrate the `x/distribution` module to use Protocol Buffer for state * (x/distribution) [\#5610](https://github.com/cosmos/cosmos-sdk/pull/5610) Migrate the `x/distribution` module to use Protocol Buffers for state serialization instead of Amino. The exact codec used is `codec.HybridCodec` which utilizes Protobuf for binary encoding and Amino for JSON encoding. diff --git a/x/slashing/types/codec.go b/x/slashing/types/codec.go index e6c96440c542..04114f1465a1 100644 --- a/x/slashing/types/codec.go +++ b/x/slashing/types/codec.go @@ -9,22 +9,20 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) } -type Codec struct { - codec.Marshaler - // Keep reference to the amino codec to allow backwards compatibility along - // with type, and interface registration. +var ( + amino = codec.New() - amino *codec.Codec -} - -func NewCodec(amino *codec.Codec) *Codec { - return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino} -} - -var ModuleCdc *Codec + // ModuleCdc references the global x/slashing module codec. Note, the codec + // should ONLY be used in certain instances of tests and for JSON encoding as Amino + // is still used for that purpose. + // + // The actual codec used for serialization should be provided to x/slashing and + // defined at the application level. + ModuleCdc = codec.NewHybridCodec(amino) +) func init() { - ModuleCdc = NewCodec(codec.New()) - RegisterCodec(ModuleCdc.amino) - ModuleCdc.amino.Seal() + RegisterCodec(amino) + codec.RegisterCrypto(amino) + amino.Seal() } diff --git a/x/slashing/types/types.proto b/x/slashing/types/types.proto index efce77fe9f1f..9aafe07c3bf3 100644 --- a/x/slashing/types/types.proto +++ b/x/slashing/types/types.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package cosmos_sdk.x.slashing.v1; -option go_package = "types"; +option go_package = "github.com/cosmos/cosmos-sdk/x/slashing/types"; import "third_party/proto/gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto"; From db992df411190d785f79e2d86381d7eebc0d4ad8 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 19 Feb 2020 20:45:36 +0530 Subject: [PATCH 50/52] Remove unused codec alias --- x/slashing/alias.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/x/slashing/alias.go b/x/slashing/alias.go index d2e532d94501..9ebdd29edf35 100644 --- a/x/slashing/alias.go +++ b/x/slashing/alias.go @@ -62,7 +62,6 @@ var ( NewValidatorSigningInfo = types.NewValidatorSigningInfo // variable aliases - NewCodec = types.NewCodec ModuleCdc = types.ModuleCdc ValidatorSigningInfoKey = types.ValidatorSigningInfoKey ValidatorMissedBlockBitArrayKey = types.ValidatorMissedBlockBitArrayKey @@ -80,7 +79,6 @@ var ( type ( Hooks = keeper.Hooks Keeper = keeper.Keeper - Codec = types.Codec GenesisState = types.GenesisState MissedBlock = types.MissedBlock MsgUnjail = types.MsgUnjail From e5f10e1b137f286570bedaa376b62d360f16f7f1 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 19 Feb 2020 21:07:03 +0530 Subject: [PATCH 51/52] Revert --- x/slashing/types/types.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/slashing/types/types.proto b/x/slashing/types/types.proto index 9aafe07c3bf3..efce77fe9f1f 100644 --- a/x/slashing/types/types.proto +++ b/x/slashing/types/types.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package cosmos_sdk.x.slashing.v1; -option go_package = "github.com/cosmos/cosmos-sdk/x/slashing/types"; +option go_package = "types"; import "third_party/proto/gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto"; From 4c5e070c5937094613e59aff44f522f2cb77192b Mon Sep 17 00:00:00 2001 From: anilCSE Date: Wed, 19 Feb 2020 21:08:25 +0530 Subject: [PATCH 52/52] fix import --- x/slashing/types/types.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/slashing/types/types.proto b/x/slashing/types/types.proto index efce77fe9f1f..9aafe07c3bf3 100644 --- a/x/slashing/types/types.proto +++ b/x/slashing/types/types.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package cosmos_sdk.x.slashing.v1; -option go_package = "types"; +option go_package = "github.com/cosmos/cosmos-sdk/x/slashing/types"; import "third_party/proto/gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto";