From e8a72b9b798f912d755166cb778c168bdc517601 Mon Sep 17 00:00:00 2001 From: rustdev Date: Mon, 18 Dec 2023 23:29:02 +0000 Subject: [PATCH 01/13] add delegation store to custom staking middleware --- .../stakingmiddleware/v1beta1/genesis.proto | 5 + .../v1beta1/stakingmiddleware.proto | 26 ++ x/stakingmiddleware/types/genesis.pb.go | 88 +++- .../types/stakingmiddleware.pb.go | 418 ++++++++++++++++++ 4 files changed, 527 insertions(+), 10 deletions(-) create mode 100644 proto/centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto create mode 100644 x/stakingmiddleware/types/stakingmiddleware.pb.go diff --git a/proto/centauri/stakingmiddleware/v1beta1/genesis.proto b/proto/centauri/stakingmiddleware/v1beta1/genesis.proto index 2a5012761..f19819e39 100644 --- a/proto/centauri/stakingmiddleware/v1beta1/genesis.proto +++ b/proto/centauri/stakingmiddleware/v1beta1/genesis.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package centauri.stakingmiddleware.v1beta1; import "gogoproto/gogo.proto"; +import "centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto"; +import "amino/amino.proto"; option go_package = "x/stakingmiddleware/types"; @@ -14,4 +16,7 @@ message GenesisState { (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; + + // delegations defines the delegations active at genesis. + repeated Delegation delegations = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; } diff --git a/proto/centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto b/proto/centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto new file mode 100644 index 000000000..124d47f71 --- /dev/null +++ b/proto/centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto @@ -0,0 +1,26 @@ +syntax = "proto3"; +package centauri.stakingmiddleware.v1beta1; + +option go_package = "x/stakingmiddleware/types"; + +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "cosmos/base/v1beta1/coin.proto"; + +import "amino/amino.proto"; +import "cosmos/msg/v1/msg.proto"; + + +// MsgDelegate defines a SDK message for performing a delegation of coins +// from a delegator to a validator. +message Delegation { + option (cosmos.msg.v1.signer) = "delegator_address"; + option (amino.name) = "cosmos-sdk/MsgDelegate"; + + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; +} \ No newline at end of file diff --git a/x/stakingmiddleware/types/genesis.pb.go b/x/stakingmiddleware/types/genesis.pb.go index 5aad5c330..bea8aead4 100644 --- a/x/stakingmiddleware/types/genesis.pb.go +++ b/x/stakingmiddleware/types/genesis.pb.go @@ -6,6 +6,7 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" io "io" @@ -29,6 +30,8 @@ type GenesisState struct { // last_total_power tracks the total amounts of bonded tokens recorded during // the previous end block. LastTotalPower github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=last_total_power,json=lastTotalPower,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"last_total_power"` + // delegations defines the delegations active at genesis. + Delegations []Delegation `protobuf:"bytes,2,rep,name=delegations,proto3" json:"delegations"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -64,6 +67,13 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo +func (m *GenesisState) GetDelegations() []Delegation { + if m != nil { + return m.Delegations + } + return nil +} + func init() { proto.RegisterType((*GenesisState)(nil), "centauri.stakingmiddleware.v1beta1.GenesisState") } @@ -73,22 +83,26 @@ func init() { } var fileDescriptor_1aa0bd912277c095 = []byte{ - // 229 bytes of a gzipped FileDescriptorProto + // 293 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x48, 0x4e, 0xcd, 0x2b, 0x49, 0x2c, 0x2d, 0xca, 0xd4, 0x2f, 0x2e, 0x49, 0xcc, 0xce, 0xcc, 0x4b, 0xcf, 0xcd, 0x4c, 0x49, 0xc9, 0x49, 0x2d, 0x4f, 0x2c, 0x4a, 0xd5, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x82, 0xe9, 0xd0, 0xc3, 0xd0, 0xa1, 0x07, 0xd5, 0x21, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xae, 0x0f, - 0x62, 0x41, 0x74, 0x2a, 0x65, 0x70, 0xf1, 0xb8, 0x43, 0x8c, 0x0a, 0x2e, 0x49, 0x2c, 0x49, 0x15, - 0x8a, 0xe0, 0x12, 0xc8, 0x49, 0x2c, 0x2e, 0x89, 0x2f, 0xc9, 0x2f, 0x49, 0xcc, 0x89, 0x2f, 0xc8, - 0x2f, 0x4f, 0x2d, 0x92, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x71, 0xd2, 0x3b, 0x71, 0x4f, 0x9e, 0xe1, - 0xd6, 0x3d, 0x79, 0xb5, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xe4, - 0xfc, 0xe2, 0xdc, 0xfc, 0x62, 0x28, 0xa5, 0x5b, 0x9c, 0x92, 0xad, 0x5f, 0x52, 0x59, 0x90, 0x5a, - 0xac, 0xe7, 0x99, 0x57, 0x12, 0xc4, 0x07, 0x32, 0x27, 0x04, 0x64, 0x4c, 0x00, 0xc8, 0x14, 0x27, + 0x62, 0x41, 0x74, 0x4a, 0x59, 0x11, 0x61, 0x17, 0xa6, 0x99, 0x10, 0xbd, 0x82, 0x89, 0xb9, 0x99, + 0x79, 0xf9, 0xfa, 0x60, 0x12, 0x22, 0xa4, 0x74, 0x94, 0x91, 0x8b, 0xc7, 0x1d, 0xe2, 0xb4, 0xe0, + 0x92, 0xc4, 0x92, 0x54, 0xa1, 0x08, 0x2e, 0x81, 0x9c, 0xc4, 0xe2, 0x92, 0xf8, 0x92, 0xfc, 0x92, + 0xc4, 0x9c, 0xf8, 0x82, 0xfc, 0xf2, 0xd4, 0x22, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x1e, 0x27, 0xbd, + 0x13, 0xf7, 0xe4, 0x19, 0x6e, 0xdd, 0x93, 0x57, 0x4b, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, + 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0x86, 0x52, 0xba, 0xc5, 0x29, 0xd9, 0xfa, + 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x7a, 0x9e, 0x79, 0x25, 0x41, 0x7c, 0x20, 0x73, 0x42, 0x40, 0xc6, + 0x04, 0x80, 0x4c, 0x11, 0x8a, 0xe6, 0xe2, 0x4e, 0x49, 0xcd, 0x49, 0x4d, 0x4f, 0x2c, 0xc9, 0xcc, + 0xcf, 0x2b, 0x96, 0x60, 0x52, 0x60, 0xd6, 0xe0, 0x36, 0xd2, 0xd3, 0x23, 0x1c, 0x12, 0x7a, 0x2e, + 0x70, 0x6d, 0x4e, 0x9c, 0x20, 0x47, 0xac, 0x78, 0xbe, 0x41, 0x8b, 0x31, 0x08, 0xd9, 0x34, 0x27, 0xe3, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, - 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x92, 0xac, 0xc0, 0xe2, 0x51, - 0xb0, 0x41, 0x49, 0x6c, 0x60, 0x57, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x11, 0xb1, 0xd1, - 0x9a, 0x13, 0x01, 0x00, 0x00, + 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x92, 0xac, 0xc0, 0x12, 0x52, + 0x60, 0x57, 0x26, 0xb1, 0x81, 0xc3, 0xc0, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x7c, 0x15, + 0x09, 0xc0, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -111,6 +125,20 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Delegations) > 0 { + for iNdEx := len(m.Delegations) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Delegations[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } { size := m.LastTotalPower.Size() i -= size @@ -143,6 +171,12 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.LastTotalPower.Size() n += 1 + l + sovGenesis(uint64(l)) + if len(m.Delegations) > 0 { + for _, e := range m.Delegations { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } return n } @@ -214,6 +248,40 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Delegations", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Delegations = append(m.Delegations, Delegation{}) + if err := m.Delegations[len(m.Delegations)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/stakingmiddleware/types/stakingmiddleware.pb.go b/x/stakingmiddleware/types/stakingmiddleware.pb.go new file mode 100644 index 000000000..144e5dc44 --- /dev/null +++ b/x/stakingmiddleware/types/stakingmiddleware.pb.go @@ -0,0 +1,418 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgDelegate defines a SDK message for performing a delegation of coins +// from a delegator to a validator. +type Delegation struct { + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` + ValidatorAddress string `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + Amount types.Coin `protobuf:"bytes,3,opt,name=amount,proto3" json:"amount"` +} + +func (m *Delegation) Reset() { *m = Delegation{} } +func (m *Delegation) String() string { return proto.CompactTextString(m) } +func (*Delegation) ProtoMessage() {} +func (*Delegation) Descriptor() ([]byte, []int) { + return fileDescriptor_b3eb4aece69e048d, []int{0} +} +func (m *Delegation) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Delegation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Delegation.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 *Delegation) XXX_Merge(src proto.Message) { + xxx_messageInfo_Delegation.Merge(m, src) +} +func (m *Delegation) XXX_Size() int { + return m.Size() +} +func (m *Delegation) XXX_DiscardUnknown() { + xxx_messageInfo_Delegation.DiscardUnknown(m) +} + +var xxx_messageInfo_Delegation proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Delegation)(nil), "centauri.stakingmiddleware.v1beta1.Delegation") +} + +func init() { + proto.RegisterFile("centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto", fileDescriptor_b3eb4aece69e048d) +} + +var fileDescriptor_b3eb4aece69e048d = []byte{ + // 344 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xb2, 0x4a, 0x4e, 0xcd, 0x2b, + 0x49, 0x2c, 0x2d, 0xca, 0xd4, 0x2f, 0x2e, 0x49, 0xcc, 0xce, 0xcc, 0x4b, 0xcf, 0xcd, 0x4c, 0x49, + 0xc9, 0x49, 0x2d, 0x4f, 0x2c, 0x4a, 0xd5, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xc4, 0x94, + 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x82, 0xe9, 0xd5, 0xc3, 0x54, 0x01, 0xd5, 0x2b, + 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xae, 0x0f, 0x62, 0x41, 0x74, 0x4a, 0x49, 0x26, 0xe7, + 0x17, 0xe7, 0xe6, 0x17, 0xc7, 0x43, 0x24, 0x20, 0x1c, 0xa8, 0x94, 0x1c, 0x84, 0xa7, 0x9f, 0x94, + 0x58, 0x8c, 0x70, 0x41, 0x72, 0x7e, 0x66, 0x1e, 0x54, 0x5e, 0x30, 0x31, 0x37, 0x33, 0x2f, 0x5f, + 0x1f, 0x4c, 0x42, 0x85, 0xc4, 0xa1, 0x5a, 0x72, 0x8b, 0xd3, 0xf5, 0xcb, 0x0c, 0x41, 0x14, 0x44, + 0x42, 0x69, 0x32, 0x13, 0x17, 0x97, 0x4b, 0x6a, 0x4e, 0x6a, 0x7a, 0x62, 0x49, 0x66, 0x7e, 0x9e, + 0x90, 0x2b, 0x97, 0x60, 0x0a, 0x84, 0x97, 0x5f, 0x14, 0x9f, 0x98, 0x92, 0x52, 0x94, 0x5a, 0x5c, + 0x2c, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0xe9, 0x24, 0x71, 0x69, 0x8b, 0xae, 0x08, 0xd4, 0x1d, 0x8e, + 0x10, 0x99, 0xe0, 0x92, 0xa2, 0xcc, 0xbc, 0xf4, 0x20, 0x01, 0xb8, 0x16, 0xa8, 0x38, 0xc8, 0x98, + 0xb2, 0xc4, 0x9c, 0xcc, 0x14, 0x14, 0x63, 0x98, 0x08, 0x19, 0x03, 0xd7, 0x02, 0x33, 0xc6, 0x86, + 0x8b, 0x2d, 0x31, 0x37, 0xbf, 0x34, 0xaf, 0x44, 0x82, 0x59, 0x81, 0x51, 0x83, 0xdb, 0x48, 0x52, + 0x0f, 0xaa, 0x11, 0xe4, 0x73, 0x58, 0xf8, 0xe9, 0x39, 0xe7, 0x67, 0xe6, 0x39, 0x71, 0x9e, 0xb8, + 0x27, 0xcf, 0xb0, 0xe2, 0xf9, 0x06, 0x2d, 0xc6, 0x20, 0xa8, 0x1e, 0x2b, 0xcb, 0x8e, 0x05, 0xf2, + 0x0c, 0x2f, 0x16, 0xc8, 0x33, 0x34, 0x3d, 0xdf, 0xa0, 0x85, 0xe9, 0xad, 0xae, 0xe7, 0x1b, 0xb4, + 0xc4, 0x20, 0xe6, 0xe9, 0x16, 0xa7, 0x64, 0xeb, 0xfb, 0x16, 0xa7, 0x43, 0x03, 0x22, 0xd5, 0xc9, + 0xf8, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, + 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x24, 0x2b, 0xb0, 0xa4, 0x82, + 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0x70, 0x88, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, + 0xdc, 0x56, 0x33, 0x1d, 0x30, 0x02, 0x00, 0x00, +} + +func (m *Delegation) 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 *Delegation) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Delegation) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintStakingmiddleware(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintStakingmiddleware(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintStakingmiddleware(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintStakingmiddleware(dAtA []byte, offset int, v uint64) int { + offset -= sovStakingmiddleware(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Delegation) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovStakingmiddleware(uint64(l)) + } + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovStakingmiddleware(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovStakingmiddleware(uint64(l)) + return n +} + +func sovStakingmiddleware(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozStakingmiddleware(x uint64) (n int) { + return sovStakingmiddleware(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Delegation) 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 ErrIntOverflowStakingmiddleware + } + 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: Delegation: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Delegation: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStakingmiddleware + } + 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 ErrInvalidLengthStakingmiddleware + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthStakingmiddleware + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStakingmiddleware + } + 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 ErrInvalidLengthStakingmiddleware + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthStakingmiddleware + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + 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 ErrIntOverflowStakingmiddleware + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthStakingmiddleware + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthStakingmiddleware + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipStakingmiddleware(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthStakingmiddleware + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipStakingmiddleware(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, ErrIntOverflowStakingmiddleware + } + 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, ErrIntOverflowStakingmiddleware + } + 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, ErrIntOverflowStakingmiddleware + } + 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, ErrInvalidLengthStakingmiddleware + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupStakingmiddleware + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthStakingmiddleware + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthStakingmiddleware = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowStakingmiddleware = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupStakingmiddleware = fmt.Errorf("proto: unexpected end of group") +) From 38c74448d2bf892bf939d8d48274c4643ffb0272 Mon Sep 17 00:00:00 2001 From: rustdev Date: Tue, 19 Dec 2023 16:33:57 +0000 Subject: [PATCH 02/13] call delegation keeper store method from custom staking. --- custom/staking/keeper/msg_server.go | 2 ++ x/stakingmiddleware/keeper/keeper.go | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/custom/staking/keeper/msg_server.go b/custom/staking/keeper/msg_server.go index 22a208cef..6066bba54 100644 --- a/custom/staking/keeper/msg_server.go +++ b/custom/staking/keeper/msg_server.go @@ -47,6 +47,8 @@ func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*typ k.mintkeeper.SetLastTotalPower(ctx, math.Int{}) k.stakingmiddleware.SetLastTotalPower(ctx, math.Int{}) + k.stakingmiddleware.SetDelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount) + return &types.MsgDelegateResponse{}, nil // return nil, fmt.Errorf("My custom error: Nikita") // return k.msgServer.Delegate(goCtx, msg) diff --git a/x/stakingmiddleware/keeper/keeper.go b/x/stakingmiddleware/keeper/keeper.go index a1f1bb960..95f2c9fa8 100644 --- a/x/stakingmiddleware/keeper/keeper.go +++ b/x/stakingmiddleware/keeper/keeper.go @@ -3,12 +3,14 @@ package keeper import ( "cosmossdk.io/math" "github.com/cometbft/cometbft/libs/log" - "github.com/notional-labs/composable/v6/x/mint/types" + "github.com/notional-labs/composable/v6/x/stakingmiddleware/types" "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + // "github.com/notional-labs/composable/v6/x/mint/types" + sdkmath "cosmossdk.io/math" ) // Keeper of the staking middleware store @@ -99,3 +101,20 @@ func (k Keeper) GetLastTotalPower(ctx sdk.Context) math.Int { return ip.Int } + +func (k Keeper) SetDelegation(ctx sdk.Context, DelegatorAddress string, ValidatorAddress string, Denom string, Amount sdkmath.Int) { + delegation := types.Delegation{DelegatorAddress: DelegatorAddress, ValidatorAddress: ValidatorAddress, Amount: sdk.NewCoin(Denom, Amount)} + delegatorAddress := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) + + store := ctx.KVStore(k.storeKey) + b := k.cdc.MustMarshal(&delegation) + store.Set(types.GetDelegationKey(delegatorAddress, GetValidatorAddr(delegation)), b) +} + +func GetValidatorAddr(d types.Delegation) sdk.ValAddress { + addr, err := sdk.ValAddressFromBech32(d.ValidatorAddress) + if err != nil { + panic(err) + } + return addr +} From e187b8e57aa94e8a899d5842e87f459f845e63fb Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Wed, 20 Dec 2023 00:13:13 +0700 Subject: [PATCH 03/13] linted, with the exception of unreachable code --- app/app.go | 2 +- custom/staking/keeper/msg_server.go | 1 - custom/staking/module.go | 17 ++++++++--------- x/stakingmiddleware/keeper/keeper.go | 12 +++++------- x/stakingmiddleware/keeper/msg_server.go | 1 - x/stakingmiddleware/module.go | 3 +-- 6 files changed, 15 insertions(+), 21 deletions(-) diff --git a/app/app.go b/app/app.go index a97da5804..fe5e82fe8 100644 --- a/app/app.go +++ b/app/app.go @@ -361,7 +361,7 @@ func NewComposableApp( mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)), - customstaking.NewAppModule(appCodec, *&app.CustomStakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)), + customstaking.NewAppModule(appCodec, app.CustomStakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)), stakingmiddleware.NewAppModule(appCodec, app.StakingMiddlewareKeeper), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), upgrade.NewAppModule(app.UpgradeKeeper), diff --git a/custom/staking/keeper/msg_server.go b/custom/staking/keeper/msg_server.go index 6066bba54..5004f8f86 100644 --- a/custom/staking/keeper/msg_server.go +++ b/custom/staking/keeper/msg_server.go @@ -29,7 +29,6 @@ func (k msgServer) EditValidator(goCtx context.Context, msg *types.MsgEditValida } func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*types.MsgDelegateResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) // bondDenom := k.BondDenom(ctx) diff --git a/custom/staking/module.go b/custom/staking/module.go index 6f982554b..8c2ec5b75 100644 --- a/custom/staking/module.go +++ b/custom/staking/module.go @@ -7,9 +7,8 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" stakingmodule "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/staking/exported" - "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" // custombankkeeper "github.com/notional-labs/composable/v6/custom/bank/keeper" customstakingkeeper "github.com/notional-labs/composable/v6/custom/staking/keeper" @@ -23,7 +22,7 @@ type AppModule struct { } // NewAppModule creates a new AppModule object -func NewAppModule(cdc codec.Codec, keeper customstakingkeeper.Keeper, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, ss exported.Subspace) AppModule { +func NewAppModule(cdc codec.Codec, keeper customstakingkeeper.Keeper, accountKeeper stakingtypes.AccountKeeper, bankKeeper stakingtypes.BankKeeper, ss exported.Subspace) AppModule { stakingModule := stakingmodule.NewAppModule(cdc, &keeper.Keeper, accountKeeper, bankKeeper, ss) return AppModule{ AppModule: stakingModule, @@ -37,20 +36,20 @@ func NewAppModule(cdc codec.Codec, keeper customstakingkeeper.Keeper, accountKee // when trying to force this custom keeper into a bankkeeper.BaseKeeper func (am AppModule) RegisterServices(cfg module.Configurator) { // types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(&am.keeper)) - types.RegisterMsgServer(cfg.MsgServer(), customstakingkeeper.NewMsgServerImpl(am.keeper.Keeper, am.keeper)) - querier := keeper.Querier{Keeper: &am.keeper.Keeper} - types.RegisterQueryServer(cfg.QueryServer(), querier) + stakingtypes.RegisterMsgServer(cfg.MsgServer(), customstakingkeeper.NewMsgServerImpl(am.keeper.Keeper, am.keeper)) + querier := stakingkeeper.Querier{Keeper: &am.keeper.Keeper} + stakingtypes.RegisterQueryServer(cfg.QueryServer(), querier) m := stakingkeeper.NewMigrator(&am.keeper.Keeper, am.subspace) - if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil { + if err := cfg.RegisterMigration(stakingtypes.ModuleName, 1, m.Migrate1to2); err != nil { panic(fmt.Sprintf("failed to migrate x/staking from version 1 to 2: %v", err)) } - if err := cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3); err != nil { + if err := cfg.RegisterMigration(stakingtypes.ModuleName, 2, m.Migrate2to3); err != nil { panic(fmt.Sprintf("failed to migrate x/staking from version 2 to 3: %v", err)) } - if err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4); err != nil { + if err := cfg.RegisterMigration(stakingtypes.ModuleName, 3, m.Migrate3to4); err != nil { panic(fmt.Sprintf("failed to migrate x/staking from version 3 to 4: %v", err)) } } diff --git a/x/stakingmiddleware/keeper/keeper.go b/x/stakingmiddleware/keeper/keeper.go index 95f2c9fa8..4d19d25bd 100644 --- a/x/stakingmiddleware/keeper/keeper.go +++ b/x/stakingmiddleware/keeper/keeper.go @@ -1,7 +1,6 @@ package keeper import ( - "cosmossdk.io/math" "github.com/cometbft/cometbft/libs/log" "github.com/notional-labs/composable/v6/x/stakingmiddleware/types" @@ -9,7 +8,6 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - // "github.com/notional-labs/composable/v6/x/mint/types" sdkmath "cosmossdk.io/math" ) @@ -82,18 +80,18 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { // } // SetLastTotalPower Set the last total validator power. -func (k Keeper) SetLastTotalPower(ctx sdk.Context, power math.Int) { +func (k Keeper) SetLastTotalPower(ctx sdk.Context, power sdkmath.Int) { store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshal(&sdk.IntProto{Int: power}) store.Set(types.DelegationKey, bz) } -func (k Keeper) GetLastTotalPower(ctx sdk.Context) math.Int { +func (k Keeper) GetLastTotalPower(ctx sdk.Context) sdkmath.Int { store := ctx.KVStore(k.storeKey) bz := store.Get(types.DelegationKey) if bz == nil { - return math.ZeroInt() + return sdkmath.ZeroInt() } ip := sdk.IntProto{} @@ -102,8 +100,8 @@ func (k Keeper) GetLastTotalPower(ctx sdk.Context) math.Int { return ip.Int } -func (k Keeper) SetDelegation(ctx sdk.Context, DelegatorAddress string, ValidatorAddress string, Denom string, Amount sdkmath.Int) { - delegation := types.Delegation{DelegatorAddress: DelegatorAddress, ValidatorAddress: ValidatorAddress, Amount: sdk.NewCoin(Denom, Amount)} +func (k Keeper) SetDelegation(ctx sdk.Context, sourceDelegatorAddress, validatorAddress, denom string, amount sdkmath.Int) { + delegation := types.Delegation{DelegatorAddress: sourceDelegatorAddress, ValidatorAddress: validatorAddress, Amount: sdk.NewCoin(denom, amount)} delegatorAddress := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) store := ctx.KVStore(k.storeKey) diff --git a/x/stakingmiddleware/keeper/msg_server.go b/x/stakingmiddleware/keeper/msg_server.go index 79056c132..30afdf83b 100644 --- a/x/stakingmiddleware/keeper/msg_server.go +++ b/x/stakingmiddleware/keeper/msg_server.go @@ -22,6 +22,5 @@ func NewMsgServerImpl(k Keeper) types.MsgServer { // UpdateParams updates the params. func (ms msgServer) SetPower(goCtx context.Context, req *types.MsgSetPower) (*types.MsgSetPowerResponse, error) { - return &types.MsgSetPowerResponse{}, nil } diff --git a/x/stakingmiddleware/module.go b/x/stakingmiddleware/module.go index 881d954d7..0cf65e3f4 100644 --- a/x/stakingmiddleware/module.go +++ b/x/stakingmiddleware/module.go @@ -20,7 +20,6 @@ import ( "github.com/notional-labs/composable/v6/x/stakingmiddleware/client/cli" "github.com/notional-labs/composable/v6/x/stakingmiddleware/keeper" "github.com/notional-labs/composable/v6/x/stakingmiddleware/types" - middlewarestaking "github.com/notional-labs/composable/v6/x/stakingmiddleware/types" ) var ( @@ -38,7 +37,7 @@ var _ module.AppModuleBasic = AppModuleBasic{} // Name returns the mint module's name. func (AppModuleBasic) Name() string { - return middlewarestaking.ModuleName + return types.ModuleName } // RegisterLegacyAminoCodec registers the mint module's types on the given LegacyAmino codec. From 0a40503f28344936c46af92a130994fa31c3befc Mon Sep 17 00:00:00 2001 From: rustdev Date: Tue, 19 Dec 2023 22:05:21 +0000 Subject: [PATCH 04/13] iterate delegation. --- x/stakingmiddleware/keeper/keeper.go | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/x/stakingmiddleware/keeper/keeper.go b/x/stakingmiddleware/keeper/keeper.go index 95f2c9fa8..ce73c66ae 100644 --- a/x/stakingmiddleware/keeper/keeper.go +++ b/x/stakingmiddleware/keeper/keeper.go @@ -111,6 +111,21 @@ func (k Keeper) SetDelegation(ctx sdk.Context, DelegatorAddress string, Validato store.Set(types.GetDelegationKey(delegatorAddress, GetValidatorAddr(delegation)), b) } +func (k Keeper) IterateDelegations(ctx sdk.Context, fn func(index int64, ubd types.Delegation) (stop bool)) { + store := ctx.KVStore(k.storeKey) + + iterator := sdk.KVStorePrefixIterator(store, types.DelegationKey) + defer iterator.Close() + + for i := int64(0); iterator.Valid(); iterator.Next() { + ubd := MustUnmarshalUBD(k.cdc, iterator.Value()) + if stop := fn(i, ubd); stop { + break + } + i++ + } +} + func GetValidatorAddr(d types.Delegation) sdk.ValAddress { addr, err := sdk.ValAddressFromBech32(d.ValidatorAddress) if err != nil { @@ -118,3 +133,17 @@ func GetValidatorAddr(d types.Delegation) sdk.ValAddress { } return addr } + +func UnmarshalBD(cdc codec.BinaryCodec, value []byte) (ubd types.Delegation, err error) { + err = cdc.Unmarshal(value, &ubd) + return ubd, err +} + +func MustUnmarshalUBD(cdc codec.BinaryCodec, value []byte) types.Delegation { + ubd, err := UnmarshalBD(cdc, value) + if err != nil { + panic(err) + } + + return ubd +} From 12128641156458763f3a7fb138163c9b5d11f7dd Mon Sep 17 00:00:00 2001 From: rustdev Date: Tue, 19 Dec 2023 23:52:28 +0000 Subject: [PATCH 05/13] iterate delegation storage --- custom/staking/keeper/msg_server.go | 7 +++++++ x/stakingmiddleware/keeper/keeper.go | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/custom/staking/keeper/msg_server.go b/custom/staking/keeper/msg_server.go index 5004f8f86..79cccfdc2 100644 --- a/custom/staking/keeper/msg_server.go +++ b/custom/staking/keeper/msg_server.go @@ -5,6 +5,7 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -47,6 +48,12 @@ func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*typ k.stakingmiddleware.SetLastTotalPower(ctx, math.Int{}) k.stakingmiddleware.SetDelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount) + delegations := k.stakingmiddleware.DequeueAllDelegation(ctx) + if len(delegations) >= 1 { + return nil, sdkerrors.Wrapf( + sdkerrors.ErrInvalidRequest, "should always be less then 2 : got %s, expected %s", len(delegations), + ) + } return &types.MsgDelegateResponse{}, nil // return nil, fmt.Errorf("My custom error: Nikita") diff --git a/x/stakingmiddleware/keeper/keeper.go b/x/stakingmiddleware/keeper/keeper.go index 650b45e45..ec91d2446 100644 --- a/x/stakingmiddleware/keeper/keeper.go +++ b/x/stakingmiddleware/keeper/keeper.go @@ -124,6 +124,28 @@ func (k Keeper) IterateDelegations(ctx sdk.Context, fn func(index int64, ubd typ } } +// DequeueAllMatureUBDQueue returns a concatenated list of all the timeslices inclusively previous to +// currTime, and deletes the timeslices from the queue. +func (k Keeper) DequeueAllDelegation(ctx sdk.Context) (delegations []types.Delegation) { + store := ctx.KVStore(k.storeKey) + + // gets an iterator for all timeslices from time 0 until the current Blockheader time + delegationIterator := sdk.KVStorePrefixIterator(store, types.DelegationKey) + defer delegationIterator.Close() + + for ; delegationIterator.Valid(); delegationIterator.Next() { + delegation := types.Delegation{} + value := delegationIterator.Value() + k.cdc.MustUnmarshal(value, &delegation) + + delegations = append(delegations, delegation) + + store.Delete(delegationIterator.Key()) + } + + return delegations +} + func GetValidatorAddr(d types.Delegation) sdk.ValAddress { addr, err := sdk.ValAddressFromBech32(d.ValidatorAddress) if err != nil { From a93ec9fc045db0afcb05533ba75429001fe95d89 Mon Sep 17 00:00:00 2001 From: rustdev Date: Wed, 20 Dec 2023 23:18:53 +0000 Subject: [PATCH 06/13] override end block custom staking module implementation --- custom/staking/keeper/keeper.go | 4 ++-- custom/staking/keeper/msg_server.go | 33 +++++++++++--------------- custom/staking/module.go | 36 +++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 21 deletions(-) diff --git a/custom/staking/keeper/keeper.go b/custom/staking/keeper/keeper.go index 7717e2249..0eb850289 100644 --- a/custom/staking/keeper/keeper.go +++ b/custom/staking/keeper/keeper.go @@ -14,7 +14,7 @@ type Keeper struct { cdc codec.BinaryCodec acck accountkeeper.AccountKeeper mintkeeper *mintkeeper.Keeper - stakingmiddleware *stakingmiddleware.Keeper + Stakingmiddleware *stakingmiddleware.Keeper authority string } @@ -46,7 +46,7 @@ func NewKeeper( acck: acck, authority: authority, mintkeeper: mintkeeper, - stakingmiddleware: stakingmiddleware, + Stakingmiddleware: stakingmiddleware, cdc: cdc, } return keeper diff --git a/custom/staking/keeper/msg_server.go b/custom/staking/keeper/msg_server.go index 79cccfdc2..6547c5046 100644 --- a/custom/staking/keeper/msg_server.go +++ b/custom/staking/keeper/msg_server.go @@ -3,7 +3,6 @@ package keeper import ( "context" - "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" @@ -32,28 +31,24 @@ func (k msgServer) EditValidator(goCtx context.Context, msg *types.MsgEditValida func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*types.MsgDelegateResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - // bondDenom := k.BondDenom(ctx) - // if msg.Amount.Denom != bondDenom { + bondDenom := k.BondDenom(ctx) + if msg.Amount.Denom != bondDenom { + return nil, sdkerrors.Wrapf( + sdkerrors.ErrInvalidRequest, "invalid coin denomination: got %s, expected %s", msg.Amount.Denom, bondDenom, + ) + } + + // k.mintkeeper.SetLastTotalPower(ctx, math.Int{}) + // k.stakingmiddleware.SetLastTotalPower(ctx, math.Int{}) + + // delegations := k.Stakingmiddleware.DequeueAllDelegation(ctx) + // if len(delegations) > 2 { // return nil, sdkerrors.Wrapf( - // sdkerrors.ErrInvalidRequest, "invalid coin denomination: got %s, expected %s", msg.Amount.Denom, bondDenom, + // sdkerrors.ErrInvalidRequest, "should always be less then X : got %s, expected %s", len(delegations), 1, // ) // } - // delegation := types.Delegation{ - // DelegatorAddress: msg.DelegatorAddress, - // ValidatorAddress: msg.ValidatorAddress, - // Shares: msg.Amount.Amount.ToLegacyDec(), - // } - k.mintkeeper.SetLastTotalPower(ctx, math.Int{}) - k.stakingmiddleware.SetLastTotalPower(ctx, math.Int{}) - - k.stakingmiddleware.SetDelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount) - delegations := k.stakingmiddleware.DequeueAllDelegation(ctx) - if len(delegations) >= 1 { - return nil, sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, "should always be less then 2 : got %s, expected %s", len(delegations), - ) - } + k.Stakingmiddleware.SetDelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount) return &types.MsgDelegateResponse{}, nil // return nil, fmt.Errorf("My custom error: Nikita") diff --git a/custom/staking/module.go b/custom/staking/module.go index 8c2ec5b75..3c31fe4fa 100644 --- a/custom/staking/module.go +++ b/custom/staking/module.go @@ -3,6 +3,7 @@ package bank import ( "fmt" + abcitype "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/module" stakingmodule "github.com/cosmos/cosmos-sdk/x/staking" @@ -11,6 +12,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" // custombankkeeper "github.com/notional-labs/composable/v6/custom/bank/keeper" + sdk "github.com/cosmos/cosmos-sdk/types" customstakingkeeper "github.com/notional-labs/composable/v6/custom/staking/keeper" ) @@ -53,3 +55,37 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { panic(fmt.Sprintf("failed to migrate x/staking from version 3 to 4: %v", err)) } } + +// func (am AppModule) BeginBlock(ctx sdk.Context, _abc abcitype.RequestBeginBlock) { +// //Define the logic around the batching. +// am.AppModule.BeginBlock(ctx, _abc) +// } + +func (am AppModule) EndBlock(ctx sdk.Context, _abc abcitype.RequestEndBlock) []abcitype.ValidatorUpdate { + //Define the logic around the batching. + //TODO!!! + + println("EndBlock Custom Staking Module") + + delegations := am.keeper.Stakingmiddleware.DequeueAllDelegation(ctx) + println("Delegations: ", delegations) + println("Delegations len: ", len(delegations)) + //for delegations print the delegator address and the validator address + for _, delegation := range delegations { + println("Delegator Address: ", delegation.DelegatorAddress) + println("Validator Address: ", delegation.ValidatorAddress) + fmt.Println("Amount", delegation.Amount.Amount) + } + + // am.keeper.Delegate() + ctx.EventManager().EmitEvent( + sdk.NewEvent( + "DequeueAllDelegation", + // sdk.NewAttribute(sdk.AttributeKeyAmount, balances.String()), + // sdk.NewAttribute(types.AttributeKeyValidator, dvPair.ValidatorAddress), + // sdk.NewAttribute(types.AttributeKeyDelegator, dvPair.DelegatorAddress), + ), + ) + + return am.AppModule.EndBlock(ctx, _abc) +} From fad57ec862411fde9ad9092060002e84e93a91a0 Mon Sep 17 00:00:00 2001 From: rustdev Date: Thu, 21 Dec 2023 15:20:41 +0000 Subject: [PATCH 07/13] add logic to app module to batch delegation. --- custom/staking/module.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/custom/staking/module.go b/custom/staking/module.go index 3c31fe4fa..e42a469e2 100644 --- a/custom/staking/module.go +++ b/custom/staking/module.go @@ -19,8 +19,9 @@ import ( // AppModule wraps around the bank module and the bank keeper to return the right total supply type AppModule struct { stakingmodule.AppModule - keeper customstakingkeeper.Keeper - subspace exported.Subspace + keeper customstakingkeeper.Keeper + subspace exported.Subspace + msgServer stakingtypes.MsgServer } // NewAppModule creates a new AppModule object @@ -30,6 +31,7 @@ func NewAppModule(cdc codec.Codec, keeper customstakingkeeper.Keeper, accountKee AppModule: stakingModule, keeper: keeper, subspace: ss, + msgServer: stakingkeeper.NewMsgServerImpl(&keeper.Keeper), } } @@ -75,9 +77,15 @@ func (am AppModule) EndBlock(ctx sdk.Context, _abc abcitype.RequestEndBlock) []a println("Delegator Address: ", delegation.DelegatorAddress) println("Validator Address: ", delegation.ValidatorAddress) fmt.Println("Amount", delegation.Amount.Amount) + + msgDelegate := stakingtypes.MsgDelegate{DelegatorAddress: delegation.DelegatorAddress, ValidatorAddress: delegation.ValidatorAddress, Amount: delegation.Amount} + _, err := am.msgServer.Delegate(ctx, &msgDelegate) + if err != nil { + println("Error for Delegator Address: ", delegation.DelegatorAddress) + } + } - // am.keeper.Delegate() ctx.EventManager().EmitEvent( sdk.NewEvent( "DequeueAllDelegation", From b6281a5bc0245014907246680ea8372324076cdf Mon Sep 17 00:00:00 2001 From: rustdev Date: Thu, 21 Dec 2023 15:49:05 +0000 Subject: [PATCH 08/13] introduce unbondong/redelegation/cancel unbonding filed to genesis --- .../stakingmiddleware/v1beta1/genesis.proto | 3 + .../v1beta1/stakingmiddleware.proto | 47 +- x/stakingmiddleware/types/genesis.pb.go | 233 ++++- .../types/stakingmiddleware.pb.go | 966 ++++++++++++++++-- 4 files changed, 1167 insertions(+), 82 deletions(-) diff --git a/proto/centauri/stakingmiddleware/v1beta1/genesis.proto b/proto/centauri/stakingmiddleware/v1beta1/genesis.proto index f19819e39..4ff0e83c8 100644 --- a/proto/centauri/stakingmiddleware/v1beta1/genesis.proto +++ b/proto/centauri/stakingmiddleware/v1beta1/genesis.proto @@ -19,4 +19,7 @@ message GenesisState { // delegations defines the delegations active at genesis. repeated Delegation delegations = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; + repeated BeginRedelegate begindelegations = 3 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; + repeated Undelegate undelegates = 4 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; + repeated CancelUnbondingDelegation cancelunbondingdelegations = 5 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; } diff --git a/proto/centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto b/proto/centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto index 124d47f71..0038645e4 100644 --- a/proto/centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto +++ b/proto/centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto @@ -23,4 +23,49 @@ message Delegation { string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; -} \ No newline at end of file +} + +// BeginRedelegate defines a SDK message for performing a begin redelegation of coins +// from a delegator to a validator. +message BeginRedelegate{ + option (cosmos.msg.v1.signer) = "delegator_address"; + option (amino.name) = "cosmos-sdk/MsgBeginRedelegate"; + + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string validator_src_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string validator_dst_address = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + cosmos.base.v1beta1.Coin amount = 4 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; +} + +// MsgDelegate defines a SDK message for performing a delegation of coins +// from a delegator to a validator. +message Undelegate { + option (cosmos.msg.v1.signer) = "delegator_address"; + option (amino.name) = "cosmos-sdk/MsgUndelegate"; + + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; +} + +// MsgDelegate defines a SDK message for performing a delegation of coins +// from a delegator to a validator. +message CancelUnbondingDelegation { + option (cosmos.msg.v1.signer) = "delegator_address"; + option (amino.name) = "cosmos-sdk/MsgCancelUnbondingDelegation"; + + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; + int64 creation_height = 4; +} + diff --git a/x/stakingmiddleware/types/genesis.pb.go b/x/stakingmiddleware/types/genesis.pb.go index bea8aead4..35177651a 100644 --- a/x/stakingmiddleware/types/genesis.pb.go +++ b/x/stakingmiddleware/types/genesis.pb.go @@ -31,7 +31,10 @@ type GenesisState struct { // the previous end block. LastTotalPower github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=last_total_power,json=lastTotalPower,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"last_total_power"` // delegations defines the delegations active at genesis. - Delegations []Delegation `protobuf:"bytes,2,rep,name=delegations,proto3" json:"delegations"` + Delegations []Delegation `protobuf:"bytes,2,rep,name=delegations,proto3" json:"delegations"` + Begindelegations []BeginRedelegate `protobuf:"bytes,3,rep,name=begindelegations,proto3" json:"begindelegations"` + Undelegates []Undelegate `protobuf:"bytes,4,rep,name=undelegates,proto3" json:"undelegates"` + Cancelunbondingdelegations []CancelUnbondingDelegation `protobuf:"bytes,5,rep,name=cancelunbondingdelegations,proto3" json:"cancelunbondingdelegations"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -74,6 +77,27 @@ func (m *GenesisState) GetDelegations() []Delegation { return nil } +func (m *GenesisState) GetBegindelegations() []BeginRedelegate { + if m != nil { + return m.Begindelegations + } + return nil +} + +func (m *GenesisState) GetUndelegates() []Undelegate { + if m != nil { + return m.Undelegates + } + return nil +} + +func (m *GenesisState) GetCancelunbondingdelegations() []CancelUnbondingDelegation { + if m != nil { + return m.Cancelunbondingdelegations + } + return nil +} + func init() { proto.RegisterType((*GenesisState)(nil), "centauri.stakingmiddleware.v1beta1.GenesisState") } @@ -83,26 +107,31 @@ func init() { } var fileDescriptor_1aa0bd912277c095 = []byte{ - // 293 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x48, 0x4e, 0xcd, 0x2b, - 0x49, 0x2c, 0x2d, 0xca, 0xd4, 0x2f, 0x2e, 0x49, 0xcc, 0xce, 0xcc, 0x4b, 0xcf, 0xcd, 0x4c, 0x49, - 0xc9, 0x49, 0x2d, 0x4f, 0x2c, 0x4a, 0xd5, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x4f, - 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x82, 0xe9, - 0xd0, 0xc3, 0xd0, 0xa1, 0x07, 0xd5, 0x21, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xae, 0x0f, - 0x62, 0x41, 0x74, 0x4a, 0x59, 0x11, 0x61, 0x17, 0xa6, 0x99, 0x10, 0xbd, 0x82, 0x89, 0xb9, 0x99, - 0x79, 0xf9, 0xfa, 0x60, 0x12, 0x22, 0xa4, 0x74, 0x94, 0x91, 0x8b, 0xc7, 0x1d, 0xe2, 0xb4, 0xe0, - 0x92, 0xc4, 0x92, 0x54, 0xa1, 0x08, 0x2e, 0x81, 0x9c, 0xc4, 0xe2, 0x92, 0xf8, 0x92, 0xfc, 0x92, - 0xc4, 0x9c, 0xf8, 0x82, 0xfc, 0xf2, 0xd4, 0x22, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x1e, 0x27, 0xbd, - 0x13, 0xf7, 0xe4, 0x19, 0x6e, 0xdd, 0x93, 0x57, 0x4b, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, - 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0x86, 0x52, 0xba, 0xc5, 0x29, 0xd9, 0xfa, - 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x7a, 0x9e, 0x79, 0x25, 0x41, 0x7c, 0x20, 0x73, 0x42, 0x40, 0xc6, - 0x04, 0x80, 0x4c, 0x11, 0x8a, 0xe6, 0xe2, 0x4e, 0x49, 0xcd, 0x49, 0x4d, 0x4f, 0x2c, 0xc9, 0xcc, - 0xcf, 0x2b, 0x96, 0x60, 0x52, 0x60, 0xd6, 0xe0, 0x36, 0xd2, 0xd3, 0x23, 0x1c, 0x12, 0x7a, 0x2e, - 0x70, 0x6d, 0x4e, 0x9c, 0x20, 0x47, 0xac, 0x78, 0xbe, 0x41, 0x8b, 0x31, 0x08, 0xd9, 0x34, 0x27, - 0xe3, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, - 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x92, 0xac, 0xc0, 0x12, 0x52, - 0x60, 0x57, 0x26, 0xb1, 0x81, 0xc3, 0xc0, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x7c, 0x15, - 0x09, 0xc0, 0x01, 0x00, 0x00, + // 382 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xc1, 0x4a, 0xeb, 0x40, + 0x14, 0x86, 0x93, 0xdb, 0xde, 0x0b, 0x37, 0x2d, 0x97, 0xde, 0xe0, 0xa2, 0x76, 0x91, 0x96, 0x2e, + 0xa4, 0x08, 0x4e, 0xac, 0xdd, 0x09, 0x6e, 0xa2, 0x20, 0xee, 0xa4, 0x5a, 0x10, 0x5d, 0x94, 0x49, + 0x72, 0x18, 0xc7, 0x26, 0x33, 0x25, 0x33, 0xb1, 0xfa, 0x06, 0x2e, 0xdd, 0xfa, 0x06, 0x2e, 0x7d, + 0x8c, 0x2e, 0xbb, 0x14, 0x17, 0x45, 0xda, 0x85, 0xaf, 0x21, 0x99, 0xb4, 0x12, 0x68, 0xd1, 0x6c, + 0x92, 0x30, 0xe4, 0xff, 0xbe, 0x73, 0xce, 0x1c, 0x63, 0xd7, 0x03, 0x26, 0x71, 0x1c, 0x51, 0x5b, + 0x48, 0x3c, 0xa0, 0x8c, 0x84, 0xd4, 0xf7, 0x03, 0x18, 0xe1, 0x08, 0xec, 0xdb, 0xb6, 0x0b, 0x12, + 0xb7, 0x6d, 0x02, 0x0c, 0x04, 0x15, 0x68, 0x18, 0x71, 0xc9, 0xcd, 0xe6, 0x32, 0x81, 0x56, 0x12, + 0x68, 0x91, 0xa8, 0x6d, 0x10, 0x4e, 0xb8, 0xfa, 0xdd, 0x4e, 0xbe, 0xd2, 0x64, 0x6d, 0x3f, 0x87, + 0x6b, 0x95, 0x99, 0x66, 0xff, 0xe3, 0x90, 0x32, 0x6e, 0xab, 0x67, 0x7a, 0xd4, 0x7c, 0x2a, 0x1a, + 0xe5, 0xe3, 0xb4, 0xb4, 0x33, 0x89, 0x25, 0x98, 0x17, 0x46, 0x25, 0xc0, 0x42, 0xf6, 0x25, 0x97, + 0x38, 0xe8, 0x0f, 0xf9, 0x08, 0xa2, 0xaa, 0xde, 0xd0, 0x5b, 0x65, 0x07, 0x8d, 0xa7, 0x75, 0xed, + 0x6d, 0x5a, 0xdf, 0x22, 0x54, 0x5e, 0xc7, 0x2e, 0xf2, 0x78, 0x68, 0x7b, 0x5c, 0x84, 0x5c, 0x2c, + 0x5e, 0x3b, 0xc2, 0x1f, 0xd8, 0xf2, 0x7e, 0x08, 0x02, 0x9d, 0x30, 0xd9, 0xfd, 0x97, 0x70, 0xce, + 0x13, 0xcc, 0x69, 0x42, 0x31, 0xaf, 0x8c, 0x92, 0x0f, 0x01, 0x10, 0x2c, 0x29, 0x67, 0xa2, 0xfa, + 0xab, 0x51, 0x68, 0x95, 0xf6, 0x10, 0xfa, 0x79, 0x12, 0xe8, 0xe8, 0x2b, 0xe6, 0xfc, 0x4d, 0x8a, + 0x78, 0xfe, 0x78, 0xd9, 0xd6, 0xbb, 0x59, 0x9a, 0x79, 0x63, 0x54, 0x5c, 0x20, 0x94, 0x65, 0x0d, + 0x05, 0x65, 0xe8, 0xe4, 0x31, 0x38, 0x49, 0xb6, 0x0b, 0x8b, 0x34, 0x64, 0x35, 0x2b, 0xdc, 0xa4, + 0x91, 0x78, 0x79, 0x00, 0xa2, 0x5a, 0xcc, 0xdf, 0x48, 0x8f, 0xad, 0x33, 0x64, 0x69, 0xe6, 0x83, + 0x6e, 0xd4, 0x3c, 0xcc, 0x3c, 0x08, 0x62, 0xe6, 0x72, 0xe6, 0x53, 0x46, 0xb2, 0x3d, 0xfd, 0x56, + 0xb2, 0x83, 0x3c, 0xb2, 0x43, 0x45, 0xe9, 0x2d, 0x29, 0xeb, 0x87, 0xf8, 0x8d, 0xcb, 0xe9, 0x8c, + 0x67, 0x96, 0x3e, 0x99, 0x59, 0xfa, 0xfb, 0xcc, 0xd2, 0x1f, 0xe7, 0x96, 0x36, 0x99, 0x5b, 0xda, + 0xeb, 0xdc, 0xd2, 0x2e, 0x37, 0xef, 0xd6, 0x6c, 0x9f, 0xba, 0x79, 0xf7, 0x8f, 0xda, 0xab, 0xce, + 0x67, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3c, 0xc1, 0x1d, 0x94, 0x14, 0x03, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -125,6 +154,48 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Cancelunbondingdelegations) > 0 { + for iNdEx := len(m.Cancelunbondingdelegations) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Cancelunbondingdelegations[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + } + if len(m.Undelegates) > 0 { + for iNdEx := len(m.Undelegates) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Undelegates[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if len(m.Begindelegations) > 0 { + for iNdEx := len(m.Begindelegations) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Begindelegations[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } if len(m.Delegations) > 0 { for iNdEx := len(m.Delegations) - 1; iNdEx >= 0; iNdEx-- { { @@ -177,6 +248,24 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } + if len(m.Begindelegations) > 0 { + for _, e := range m.Begindelegations { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.Undelegates) > 0 { + for _, e := range m.Undelegates { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.Cancelunbondingdelegations) > 0 { + for _, e := range m.Cancelunbondingdelegations { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } return n } @@ -282,6 +371,108 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Begindelegations", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Begindelegations = append(m.Begindelegations, BeginRedelegate{}) + if err := m.Begindelegations[len(m.Begindelegations)-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 Undelegates", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Undelegates = append(m.Undelegates, Undelegate{}) + if err := m.Undelegates[len(m.Undelegates)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Cancelunbondingdelegations", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Cancelunbondingdelegations = append(m.Cancelunbondingdelegations, CancelUnbondingDelegation{}) + if err := m.Cancelunbondingdelegations[len(m.Cancelunbondingdelegations)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/stakingmiddleware/types/stakingmiddleware.pb.go b/x/stakingmiddleware/types/stakingmiddleware.pb.go index 144e5dc44..d89b2e1fa 100644 --- a/x/stakingmiddleware/types/stakingmiddleware.pb.go +++ b/x/stakingmiddleware/types/stakingmiddleware.pb.go @@ -68,8 +68,136 @@ func (m *Delegation) XXX_DiscardUnknown() { var xxx_messageInfo_Delegation proto.InternalMessageInfo +// BeginRedelegate defines a SDK message for performing a begin redelegation of coins +// from a delegator to a validator. +type BeginRedelegate struct { + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` + ValidatorSrcAddress string `protobuf:"bytes,2,opt,name=validator_src_address,json=validatorSrcAddress,proto3" json:"validator_src_address,omitempty"` + ValidatorDstAddress string `protobuf:"bytes,3,opt,name=validator_dst_address,json=validatorDstAddress,proto3" json:"validator_dst_address,omitempty"` + Amount types.Coin `protobuf:"bytes,4,opt,name=amount,proto3" json:"amount"` +} + +func (m *BeginRedelegate) Reset() { *m = BeginRedelegate{} } +func (m *BeginRedelegate) String() string { return proto.CompactTextString(m) } +func (*BeginRedelegate) ProtoMessage() {} +func (*BeginRedelegate) Descriptor() ([]byte, []int) { + return fileDescriptor_b3eb4aece69e048d, []int{1} +} +func (m *BeginRedelegate) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BeginRedelegate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BeginRedelegate.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 *BeginRedelegate) XXX_Merge(src proto.Message) { + xxx_messageInfo_BeginRedelegate.Merge(m, src) +} +func (m *BeginRedelegate) XXX_Size() int { + return m.Size() +} +func (m *BeginRedelegate) XXX_DiscardUnknown() { + xxx_messageInfo_BeginRedelegate.DiscardUnknown(m) +} + +var xxx_messageInfo_BeginRedelegate proto.InternalMessageInfo + +// MsgDelegate defines a SDK message for performing a delegation of coins +// from a delegator to a validator. +type Undelegate struct { + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` + ValidatorAddress string `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + Amount types.Coin `protobuf:"bytes,3,opt,name=amount,proto3" json:"amount"` +} + +func (m *Undelegate) Reset() { *m = Undelegate{} } +func (m *Undelegate) String() string { return proto.CompactTextString(m) } +func (*Undelegate) ProtoMessage() {} +func (*Undelegate) Descriptor() ([]byte, []int) { + return fileDescriptor_b3eb4aece69e048d, []int{2} +} +func (m *Undelegate) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Undelegate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Undelegate.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 *Undelegate) XXX_Merge(src proto.Message) { + xxx_messageInfo_Undelegate.Merge(m, src) +} +func (m *Undelegate) XXX_Size() int { + return m.Size() +} +func (m *Undelegate) XXX_DiscardUnknown() { + xxx_messageInfo_Undelegate.DiscardUnknown(m) +} + +var xxx_messageInfo_Undelegate proto.InternalMessageInfo + +// MsgDelegate defines a SDK message for performing a delegation of coins +// from a delegator to a validator. +type CancelUnbondingDelegation struct { + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` + ValidatorAddress string `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + Amount types.Coin `protobuf:"bytes,3,opt,name=amount,proto3" json:"amount"` + CreationHeight int64 `protobuf:"varint,4,opt,name=creation_height,json=creationHeight,proto3" json:"creation_height,omitempty"` +} + +func (m *CancelUnbondingDelegation) Reset() { *m = CancelUnbondingDelegation{} } +func (m *CancelUnbondingDelegation) String() string { return proto.CompactTextString(m) } +func (*CancelUnbondingDelegation) ProtoMessage() {} +func (*CancelUnbondingDelegation) Descriptor() ([]byte, []int) { + return fileDescriptor_b3eb4aece69e048d, []int{3} +} +func (m *CancelUnbondingDelegation) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CancelUnbondingDelegation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CancelUnbondingDelegation.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 *CancelUnbondingDelegation) XXX_Merge(src proto.Message) { + xxx_messageInfo_CancelUnbondingDelegation.Merge(m, src) +} +func (m *CancelUnbondingDelegation) XXX_Size() int { + return m.Size() +} +func (m *CancelUnbondingDelegation) XXX_DiscardUnknown() { + xxx_messageInfo_CancelUnbondingDelegation.DiscardUnknown(m) +} + +var xxx_messageInfo_CancelUnbondingDelegation proto.InternalMessageInfo + func init() { proto.RegisterType((*Delegation)(nil), "centauri.stakingmiddleware.v1beta1.Delegation") + proto.RegisterType((*BeginRedelegate)(nil), "centauri.stakingmiddleware.v1beta1.BeginRedelegate") + proto.RegisterType((*Undelegate)(nil), "centauri.stakingmiddleware.v1beta1.Undelegate") + proto.RegisterType((*CancelUnbondingDelegation)(nil), "centauri.stakingmiddleware.v1beta1.CancelUnbondingDelegation") } func init() { @@ -77,7 +205,7 @@ func init() { } var fileDescriptor_b3eb4aece69e048d = []byte{ - // 344 bytes of a gzipped FileDescriptorProto + // 492 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xb2, 0x4a, 0x4e, 0xcd, 0x2b, 0x49, 0x2c, 0x2d, 0xca, 0xd4, 0x2f, 0x2e, 0x49, 0xcc, 0xce, 0xcc, 0x4b, 0xcf, 0xcd, 0x4c, 0x49, 0xc9, 0x49, 0x2d, 0x4f, 0x2c, 0x4a, 0xd5, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xc4, 0x94, @@ -95,11 +223,20 @@ var fileDescriptor_b3eb4aece69e048d = []byte{ 0x0f, 0xaa, 0x11, 0xe4, 0x73, 0x58, 0xf8, 0xe9, 0x39, 0xe7, 0x67, 0xe6, 0x39, 0x71, 0x9e, 0xb8, 0x27, 0xcf, 0xb0, 0xe2, 0xf9, 0x06, 0x2d, 0xc6, 0x20, 0xa8, 0x1e, 0x2b, 0xcb, 0x8e, 0x05, 0xf2, 0x0c, 0x2f, 0x16, 0xc8, 0x33, 0x34, 0x3d, 0xdf, 0xa0, 0x85, 0xe9, 0xad, 0xae, 0xe7, 0x1b, 0xb4, - 0xc4, 0x20, 0xe6, 0xe9, 0x16, 0xa7, 0x64, 0xeb, 0xfb, 0x16, 0xa7, 0x43, 0x03, 0x22, 0xd5, 0xc9, - 0xf8, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, - 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x24, 0x2b, 0xb0, 0xa4, 0x82, - 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0x70, 0x88, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, - 0xdc, 0x56, 0x33, 0x1d, 0x30, 0x02, 0x00, 0x00, + 0xc4, 0x20, 0xe6, 0xe9, 0x16, 0xa7, 0x64, 0xeb, 0xfb, 0x16, 0xa7, 0x43, 0x03, 0x22, 0x55, 0xe9, + 0x0b, 0x13, 0x17, 0xbf, 0x53, 0x6a, 0x7a, 0x66, 0x5e, 0x50, 0x2a, 0x54, 0x5f, 0x2a, 0xb5, 0x82, + 0xc6, 0x87, 0x4b, 0x14, 0x11, 0x34, 0xc5, 0x45, 0xc9, 0x44, 0x07, 0x8f, 0x30, 0x5c, 0x5b, 0x70, + 0x51, 0x32, 0x56, 0xd3, 0x52, 0x8a, 0x4b, 0xe0, 0xa6, 0x31, 0x13, 0x6d, 0x9a, 0x4b, 0x71, 0x09, + 0x66, 0x78, 0xb3, 0x90, 0x11, 0xde, 0x0e, 0x84, 0xc3, 0x5b, 0x16, 0x35, 0xbc, 0xd1, 0x82, 0x58, + 0x69, 0x2a, 0x13, 0x17, 0x57, 0x68, 0x1e, 0xb5, 0x43, 0x7c, 0x50, 0x24, 0x46, 0x6b, 0xc2, 0x81, + 0x23, 0x81, 0x1a, 0x38, 0x88, 0x80, 0x50, 0xba, 0xc3, 0xc4, 0x25, 0xe9, 0x9c, 0x98, 0x97, 0x9c, + 0x9a, 0x13, 0x9a, 0x97, 0x94, 0x9f, 0x97, 0x92, 0x99, 0x97, 0x3e, 0x3c, 0xf3, 0xac, 0x90, 0x3a, + 0x17, 0x7f, 0x72, 0x51, 0x2a, 0xd8, 0x5f, 0xf1, 0x19, 0xa9, 0x99, 0xe9, 0x19, 0x90, 0xa4, 0xc8, + 0x1c, 0xc4, 0x07, 0x13, 0xf6, 0x00, 0x8b, 0x5a, 0x79, 0x11, 0x0e, 0x4f, 0x75, 0xd4, 0xf0, 0xc4, + 0x19, 0x80, 0x4e, 0xc6, 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, 0x25, 0x59, + 0x81, 0xa5, 0xcc, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x97, 0x9f, 0xc6, 0x80, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xbb, 0x65, 0x42, 0xc6, 0x1e, 0x06, 0x00, 0x00, } func (m *Delegation) Marshal() (dAtA []byte, err error) { @@ -127,65 +264,755 @@ func (m *Delegation) MarshalToSizedBuffer(dAtA []byte) (int, error) { if err != nil { return 0, err } - i -= size - i = encodeVarintStakingmiddleware(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - if len(m.ValidatorAddress) > 0 { - i -= len(m.ValidatorAddress) - copy(dAtA[i:], m.ValidatorAddress) - i = encodeVarintStakingmiddleware(dAtA, i, uint64(len(m.ValidatorAddress))) - i-- - dAtA[i] = 0x12 - } - if len(m.DelegatorAddress) > 0 { - i -= len(m.DelegatorAddress) - copy(dAtA[i:], m.DelegatorAddress) - i = encodeVarintStakingmiddleware(dAtA, i, uint64(len(m.DelegatorAddress))) - i-- - dAtA[i] = 0xa + i -= size + i = encodeVarintStakingmiddleware(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintStakingmiddleware(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintStakingmiddleware(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *BeginRedelegate) 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 *BeginRedelegate) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BeginRedelegate) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintStakingmiddleware(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + if len(m.ValidatorDstAddress) > 0 { + i -= len(m.ValidatorDstAddress) + copy(dAtA[i:], m.ValidatorDstAddress) + i = encodeVarintStakingmiddleware(dAtA, i, uint64(len(m.ValidatorDstAddress))) + i-- + dAtA[i] = 0x1a + } + if len(m.ValidatorSrcAddress) > 0 { + i -= len(m.ValidatorSrcAddress) + copy(dAtA[i:], m.ValidatorSrcAddress) + i = encodeVarintStakingmiddleware(dAtA, i, uint64(len(m.ValidatorSrcAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintStakingmiddleware(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Undelegate) 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 *Undelegate) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Undelegate) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintStakingmiddleware(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintStakingmiddleware(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintStakingmiddleware(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *CancelUnbondingDelegation) 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 *CancelUnbondingDelegation) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CancelUnbondingDelegation) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.CreationHeight != 0 { + i = encodeVarintStakingmiddleware(dAtA, i, uint64(m.CreationHeight)) + i-- + dAtA[i] = 0x20 + } + { + size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintStakingmiddleware(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintStakingmiddleware(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintStakingmiddleware(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintStakingmiddleware(dAtA []byte, offset int, v uint64) int { + offset -= sovStakingmiddleware(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Delegation) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovStakingmiddleware(uint64(l)) + } + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovStakingmiddleware(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovStakingmiddleware(uint64(l)) + return n +} + +func (m *BeginRedelegate) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovStakingmiddleware(uint64(l)) + } + l = len(m.ValidatorSrcAddress) + if l > 0 { + n += 1 + l + sovStakingmiddleware(uint64(l)) + } + l = len(m.ValidatorDstAddress) + if l > 0 { + n += 1 + l + sovStakingmiddleware(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovStakingmiddleware(uint64(l)) + return n +} + +func (m *Undelegate) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovStakingmiddleware(uint64(l)) + } + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovStakingmiddleware(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovStakingmiddleware(uint64(l)) + return n +} + +func (m *CancelUnbondingDelegation) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovStakingmiddleware(uint64(l)) + } + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovStakingmiddleware(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovStakingmiddleware(uint64(l)) + if m.CreationHeight != 0 { + n += 1 + sovStakingmiddleware(uint64(m.CreationHeight)) + } + return n +} + +func sovStakingmiddleware(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozStakingmiddleware(x uint64) (n int) { + return sovStakingmiddleware(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Delegation) 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 ErrIntOverflowStakingmiddleware + } + 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: Delegation: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Delegation: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStakingmiddleware + } + 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 ErrInvalidLengthStakingmiddleware + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthStakingmiddleware + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStakingmiddleware + } + 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 ErrInvalidLengthStakingmiddleware + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthStakingmiddleware + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + 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 ErrIntOverflowStakingmiddleware + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthStakingmiddleware + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthStakingmiddleware + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipStakingmiddleware(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthStakingmiddleware + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *BeginRedelegate) 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 ErrIntOverflowStakingmiddleware + } + 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: BeginRedelegate: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BeginRedelegate: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStakingmiddleware + } + 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 ErrInvalidLengthStakingmiddleware + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthStakingmiddleware + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorSrcAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStakingmiddleware + } + 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 ErrInvalidLengthStakingmiddleware + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthStakingmiddleware + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorSrcAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorDstAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStakingmiddleware + } + 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 ErrInvalidLengthStakingmiddleware + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthStakingmiddleware + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorDstAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + 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 ErrIntOverflowStakingmiddleware + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthStakingmiddleware + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthStakingmiddleware + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipStakingmiddleware(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthStakingmiddleware + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } } - return len(dAtA) - i, nil -} -func encodeVarintStakingmiddleware(dAtA []byte, offset int, v uint64) int { - offset -= sovStakingmiddleware(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ + if iNdEx > l { + return io.ErrUnexpectedEOF } - dAtA[offset] = uint8(v) - return base + return nil } -func (m *Delegation) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.DelegatorAddress) - if l > 0 { - n += 1 + l + sovStakingmiddleware(uint64(l)) - } - l = len(m.ValidatorAddress) - if l > 0 { - n += 1 + l + sovStakingmiddleware(uint64(l)) +func (m *Undelegate) 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 ErrIntOverflowStakingmiddleware + } + 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: Undelegate: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Undelegate: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStakingmiddleware + } + 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 ErrInvalidLengthStakingmiddleware + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthStakingmiddleware + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStakingmiddleware + } + 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 ErrInvalidLengthStakingmiddleware + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthStakingmiddleware + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + 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 ErrIntOverflowStakingmiddleware + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthStakingmiddleware + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthStakingmiddleware + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipStakingmiddleware(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthStakingmiddleware + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } } - l = m.Amount.Size() - n += 1 + l + sovStakingmiddleware(uint64(l)) - return n -} -func sovStakingmiddleware(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozStakingmiddleware(x uint64) (n int) { - return sovStakingmiddleware(uint64((x << 1) ^ uint64((int64(x) >> 63)))) + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil } -func (m *Delegation) Unmarshal(dAtA []byte) error { +func (m *CancelUnbondingDelegation) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -208,10 +1035,10 @@ func (m *Delegation) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Delegation: wiretype end group for non-group") + return fmt.Errorf("proto: CancelUnbondingDelegation: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Delegation: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: CancelUnbondingDelegation: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -311,6 +1138,25 @@ func (m *Delegation) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CreationHeight", wireType) + } + m.CreationHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStakingmiddleware + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CreationHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipStakingmiddleware(dAtA[iNdEx:]) From 1a22e1895cf30f778d07de81b35384b534a5ff24 Mon Sep 17 00:00:00 2001 From: rustdev Date: Thu, 21 Dec 2023 19:29:31 +0000 Subject: [PATCH 09/13] add logic to EndBlock custom staking wrapper to dequeue all request. --- custom/staking/keeper/msg_server.go | 19 ++++- custom/staking/module.go | 68 +++++++++++++---- x/stakingmiddleware/keeper/keeper.go | 107 ++++++++++++++++++++++----- x/stakingmiddleware/types/keys.go | 39 ++++++++-- 4 files changed, 192 insertions(+), 41 deletions(-) diff --git a/custom/staking/keeper/msg_server.go b/custom/staking/keeper/msg_server.go index 6547c5046..5717e43a3 100644 --- a/custom/staking/keeper/msg_server.go +++ b/custom/staking/keeper/msg_server.go @@ -29,6 +29,7 @@ func (k msgServer) EditValidator(goCtx context.Context, msg *types.MsgEditValida } func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*types.MsgDelegateResponse, error) { + //todo add validation. check that this account really has some coins ctx := sdk.UnwrapSDKContext(goCtx) bondDenom := k.BondDenom(ctx) @@ -56,15 +57,27 @@ func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*typ } func (k msgServer) BeginRedelegate(goCtx context.Context, msg *types.MsgBeginRedelegate) (*types.MsgBeginRedelegateResponse, error) { - return k.msgServer.BeginRedelegate(goCtx, msg) + //todo add validation. check that this account really has some coins staked with this validator + ctx := sdk.UnwrapSDKContext(goCtx) + k.Stakingmiddleware.SetBeginRedelegation(ctx, msg.DelegatorAddress, msg.ValidatorSrcAddress, msg.ValidatorDstAddress, msg.Amount.Denom, msg.Amount.Amount) + return &types.MsgBeginRedelegateResponse{}, nil + // return k.msgServer.BeginRedelegate(goCtx, msg) } func (k msgServer) Undelegate(goCtx context.Context, msg *types.MsgUndelegate) (*types.MsgUndelegateResponse, error) { - return k.msgServer.Undelegate(goCtx, msg) + //todo add validation. check that this account really has some coins staked with this validator + ctx := sdk.UnwrapSDKContext(goCtx) + k.Stakingmiddleware.SetUndelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount) + return &types.MsgUndelegateResponse{}, nil + // return k.msgServer.Undelegate(goCtx, msg) } func (k msgServer) CancelUnbondingDelegation(goCtx context.Context, msg *types.MsgCancelUnbondingDelegation) (*types.MsgCancelUnbondingDelegationResponse, error) { - return k.msgServer.CancelUnbondingDelegation(goCtx, msg) + //todo add validation. check that this account really has some coins staked with this validator + ctx := sdk.UnwrapSDKContext(goCtx) + k.Stakingmiddleware.SetCancelUndelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount, msg.CreationHeight) + return &types.MsgCancelUnbondingDelegationResponse{}, nil + // return k.msgServer.CancelUnbondingDelegation(goCtx, msg) } func (ms msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { diff --git a/custom/staking/module.go b/custom/staking/module.go index e42a469e2..717d928a2 100644 --- a/custom/staking/module.go +++ b/custom/staking/module.go @@ -58,14 +58,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { } } -// func (am AppModule) BeginBlock(ctx sdk.Context, _abc abcitype.RequestBeginBlock) { -// //Define the logic around the batching. -// am.AppModule.BeginBlock(ctx, _abc) -// } - func (am AppModule) EndBlock(ctx sdk.Context, _abc abcitype.RequestEndBlock) []abcitype.ValidatorUpdate { - //Define the logic around the batching. - //TODO!!! println("EndBlock Custom Staking Module") @@ -83,17 +76,62 @@ func (am AppModule) EndBlock(ctx sdk.Context, _abc abcitype.RequestEndBlock) []a if err != nil { println("Error for Delegator Address: ", delegation.DelegatorAddress) } + } + + beginredelegations := am.keeper.Stakingmiddleware.DequeueAllRedelegation(ctx) + println("BeginRedelegations: ", beginredelegations) + println("BeginRedelegations len: ", len(beginredelegations)) + for _, beginredelegation := range beginredelegations { + println("Delegator Address: ", beginredelegation.DelegatorAddress) + println("Validator Address: ", beginredelegation.ValidatorSrcAddress) + // fmt.Println("Amount", delegation.Amount.Amount) + + // msgDelegate := stakingtypes.MsgDelegate{DelegatorAddress: delegation.DelegatorAddress, ValidatorAddress: delegation.ValidatorAddress, Amount: delegation.Amount} + // _, err := am.msgServer.Delegate(ctx, &msgDelegate) + // if err != nil { + // println("Error for Delegator Address: ", delegation.DelegatorAddress) + // } + } + + undelegations := am.keeper.Stakingmiddleware.DequeueAllUndelegation(ctx) + println("Undelegation: ", beginredelegations) + println("Undelegation len: ", len(beginredelegations)) + for _, undelegation := range undelegations { + println("Undelegation Delegator Address: ", undelegation.DelegatorAddress) + println("Undelegation Validator Address: ", undelegation.ValidatorAddress) + // fmt.Println("Amount", delegation.Amount.Amount) + + // msgDelegate := stakingtypes.MsgDelegate{DelegatorAddress: delegation.DelegatorAddress, ValidatorAddress: delegation.ValidatorAddress, Amount: delegation.Amount} + // _, err := am.msgServer.Delegate(ctx, &msgDelegate) + // if err != nil { + // println("Error for Delegator Address: ", delegation.DelegatorAddress) + // } + } + //DequeueAllCancelUnbondingDelegation + cancel_unbonding_delegations := am.keeper.Stakingmiddleware.DequeueAllCancelUnbondingDelegation(ctx) + println("Cancel Unbonding Delegations: ", cancel_unbonding_delegations) + println("Cancel Ubonding Delegations len: ", len(cancel_unbonding_delegations)) + for _, undelegation := range cancel_unbonding_delegations { + println("Cancel Unbonding Delegation Delegator Address: ", undelegation.DelegatorAddress) + println("Cancel Unbonding Delegations Validator Address: ", undelegation.ValidatorAddress) + // fmt.Println("Amount", delegation.Amount.Amount) + + // msgDelegate := stakingtypes.MsgDelegate{DelegatorAddress: delegation.DelegatorAddress, ValidatorAddress: delegation.ValidatorAddress, Amount: delegation.Amount} + // _, err := am.msgServer.Delegate(ctx, &msgDelegate) + // if err != nil { + // println("Error for Delegator Address: ", delegation.DelegatorAddress) + // } } - ctx.EventManager().EmitEvent( - sdk.NewEvent( - "DequeueAllDelegation", - // sdk.NewAttribute(sdk.AttributeKeyAmount, balances.String()), - // sdk.NewAttribute(types.AttributeKeyValidator, dvPair.ValidatorAddress), - // sdk.NewAttribute(types.AttributeKeyDelegator, dvPair.DelegatorAddress), - ), - ) + // ctx.EventManager().EmitEvent( + // sdk.NewEvent( + // "DequeueAllDelegation", + // // sdk.NewAttribute(sdk.AttributeKeyAmount, balances.String()), + // // sdk.NewAttribute(types.AttributeKeyValidator, dvPair.ValidatorAddress), + // // sdk.NewAttribute(types.AttributeKeyDelegator, dvPair.DelegatorAddress), + // ), + // ) return am.AppModule.EndBlock(ctx, _abc) } diff --git a/x/stakingmiddleware/keeper/keeper.go b/x/stakingmiddleware/keeper/keeper.go index ec91d2446..8bed69c57 100644 --- a/x/stakingmiddleware/keeper/keeper.go +++ b/x/stakingmiddleware/keeper/keeper.go @@ -83,12 +83,12 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { func (k Keeper) SetLastTotalPower(ctx sdk.Context, power sdkmath.Int) { store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshal(&sdk.IntProto{Int: power}) - store.Set(types.DelegationKey, bz) + store.Set(types.DelegateKey, bz) } func (k Keeper) GetLastTotalPower(ctx sdk.Context) sdkmath.Int { store := ctx.KVStore(k.storeKey) - bz := store.Get(types.DelegationKey) + bz := store.Get(types.DelegateKey) if bz == nil { return sdkmath.ZeroInt() @@ -106,31 +106,40 @@ func (k Keeper) SetDelegation(ctx sdk.Context, sourceDelegatorAddress, validator store := ctx.KVStore(k.storeKey) b := k.cdc.MustMarshal(&delegation) - store.Set(types.GetDelegationKey(delegatorAddress, GetValidatorAddr(delegation)), b) + store.Set(types.GetDelegateKey(delegatorAddress, GetValidatorAddr(delegation)), b) } -func (k Keeper) IterateDelegations(ctx sdk.Context, fn func(index int64, ubd types.Delegation) (stop bool)) { +func (k Keeper) SetBeginRedelegation(ctx sdk.Context, sourceDelegatorAddress, validatorSrcAddress, validatorDstAddress, denom string, amount sdkmath.Int) { + begindelegation := types.BeginRedelegate{DelegatorAddress: sourceDelegatorAddress, ValidatorSrcAddress: validatorSrcAddress, ValidatorDstAddress: validatorDstAddress, Amount: sdk.NewCoin(denom, amount)} + delegatorAddress := sdk.MustAccAddressFromBech32(begindelegation.DelegatorAddress) + store := ctx.KVStore(k.storeKey) + b := k.cdc.MustMarshal(&begindelegation) + store.Set(types.GetBeginRedelegateKey(delegatorAddress, GetValidatorAddrFromStr(validatorSrcAddress)), b) +} - iterator := sdk.KVStorePrefixIterator(store, types.DelegationKey) - defer iterator.Close() +func (k Keeper) SetUndelegation(ctx sdk.Context, sourceDelegatorAddress, validatorAddress, denom string, amount sdkmath.Int) { + undelegation := types.Undelegate{DelegatorAddress: sourceDelegatorAddress, ValidatorAddress: validatorAddress, Amount: sdk.NewCoin(denom, amount)} + delegatorAddress := sdk.MustAccAddressFromBech32(undelegation.DelegatorAddress) - for i := int64(0); iterator.Valid(); iterator.Next() { - ubd := MustUnmarshalUBD(k.cdc, iterator.Value()) - if stop := fn(i, ubd); stop { - break - } - i++ - } + store := ctx.KVStore(k.storeKey) + b := k.cdc.MustMarshal(&undelegation) + store.Set(types.GetUndelegateKey(delegatorAddress, GetValidatorAddrFromStr(validatorAddress)), b) +} + +func (k Keeper) SetCancelUndelegation(ctx sdk.Context, sourceDelegatorAddress, validatorAddress, denom string, amount sdkmath.Int, height int64) { + undelegation := types.CancelUnbondingDelegation{DelegatorAddress: sourceDelegatorAddress, ValidatorAddress: validatorAddress, Amount: sdk.NewCoin(denom, amount), CreationHeight: height} + delegatorAddress := sdk.MustAccAddressFromBech32(undelegation.DelegatorAddress) + + store := ctx.KVStore(k.storeKey) + b := k.cdc.MustMarshal(&undelegation) + store.Set(types.GetCancelUnbondingDelegateKey(delegatorAddress, GetValidatorAddrFromStr(validatorAddress)), b) } -// DequeueAllMatureUBDQueue returns a concatenated list of all the timeslices inclusively previous to -// currTime, and deletes the timeslices from the queue. func (k Keeper) DequeueAllDelegation(ctx sdk.Context) (delegations []types.Delegation) { store := ctx.KVStore(k.storeKey) - // gets an iterator for all timeslices from time 0 until the current Blockheader time - delegationIterator := sdk.KVStorePrefixIterator(store, types.DelegationKey) + delegationIterator := sdk.KVStorePrefixIterator(store, types.DelegateKey) defer delegationIterator.Close() for ; delegationIterator.Valid(); delegationIterator.Next() { @@ -146,6 +155,70 @@ func (k Keeper) DequeueAllDelegation(ctx sdk.Context) (delegations []types.Deleg return delegations } +func (k Keeper) DequeueAllRedelegation(ctx sdk.Context) (redelegations []types.BeginRedelegate) { + store := ctx.KVStore(k.storeKey) + + redelegationIterator := sdk.KVStorePrefixIterator(store, types.BeginRedelegateKey) + defer redelegationIterator.Close() + + for ; redelegationIterator.Valid(); redelegationIterator.Next() { + redelegation := types.BeginRedelegate{} + value := redelegationIterator.Value() + k.cdc.MustUnmarshal(value, &redelegation) + + redelegations = append(redelegations, redelegation) + + store.Delete(redelegationIterator.Key()) + } + + return redelegations +} + +func (k Keeper) DequeueAllUndelegation(ctx sdk.Context) (undelegations []types.Undelegate) { + store := ctx.KVStore(k.storeKey) + + undelegationIterator := sdk.KVStorePrefixIterator(store, types.UndelegateKey) + defer undelegationIterator.Close() + + for ; undelegationIterator.Valid(); undelegationIterator.Next() { + undelegation := types.Undelegate{} + value := undelegationIterator.Value() + k.cdc.MustUnmarshal(value, &undelegation) + + undelegations = append(undelegations, undelegation) + + store.Delete(undelegationIterator.Key()) + } + + return undelegations +} + +func (k Keeper) DequeueAllCancelUnbondingDelegation(ctx sdk.Context) (undelegations []types.CancelUnbondingDelegation) { + store := ctx.KVStore(k.storeKey) + + cancelunbondingundelegationIterator := sdk.KVStorePrefixIterator(store, types.CancelUnbondingDelegationKey) + defer cancelunbondingundelegationIterator.Close() + + for ; cancelunbondingundelegationIterator.Valid(); cancelunbondingundelegationIterator.Next() { + cancelunbondingdelegation := types.CancelUnbondingDelegation{} + value := cancelunbondingundelegationIterator.Value() + k.cdc.MustUnmarshal(value, &cancelunbondingdelegation) + + undelegations = append(undelegations, cancelunbondingdelegation) + + store.Delete(cancelunbondingundelegationIterator.Key()) + } + return undelegations +} + +func GetValidatorAddrFromStr(d string) sdk.ValAddress { + addr, err := sdk.ValAddressFromBech32(d) + if err != nil { + panic(err) + } + return addr +} + func GetValidatorAddr(d types.Delegation) sdk.ValAddress { addr, err := sdk.ValAddressFromBech32(d.ValidatorAddress) if err != nil { diff --git a/x/stakingmiddleware/types/keys.go b/x/stakingmiddleware/types/keys.go index fc04bd47c..f4f334983 100644 --- a/x/stakingmiddleware/types/keys.go +++ b/x/stakingmiddleware/types/keys.go @@ -7,7 +7,10 @@ import ( // MinterKey is the key to use for the keeper store. var ( - DelegationKey = []byte{0x01} // key for a delegation + DelegateKey = []byte{0x01} // key for a delegation + BeginRedelegateKey = []byte{0x02} // key for a delegation + UndelegateKey = []byte{0x03} // key for a delegation + CancelUnbondingDelegationKey = []byte{0x04} // key for a delegation ) const ( @@ -19,12 +22,36 @@ const ( StoreKey = "customstmiddleware" // not using the module name because of collisions with key "ibc" ) -// GetDelegationKey creates the key for delegator bond with validator +// GetDelegateKey creates the key for delegator bond with validator // VALUE: staking/Delegation -func GetDelegationKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte { - return append(GetDelegationsKey(delAddr), address.MustLengthPrefix(valAddr)...) +func GetDelegateKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte { + return append(DelegationKey(delAddr), address.MustLengthPrefix(valAddr)...) } -func GetDelegationsKey(delAddr sdk.AccAddress) []byte { - return append(DelegationKey, address.MustLengthPrefix(delAddr)...) +func DelegationKey(delAddr sdk.AccAddress) []byte { + return append(DelegateKey, address.MustLengthPrefix(delAddr)...) +} + +func GetBeginRedelegateKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte { + return append(BeginRedelegationsKey(delAddr), address.MustLengthPrefix(valAddr)...) +} + +func BeginRedelegationsKey(delAddr sdk.AccAddress) []byte { + return append(BeginRedelegateKey, address.MustLengthPrefix(delAddr)...) +} + +func GetUndelegateKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte { + return append(UndelegateionKey(delAddr), address.MustLengthPrefix(valAddr)...) +} + +func UndelegateionKey(delAddr sdk.AccAddress) []byte { + return append(UndelegateKey, address.MustLengthPrefix(delAddr)...) +} + +func GetCancelUnbondingDelegateKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte { + return append(CancelUnbondingDelegateKey(delAddr), address.MustLengthPrefix(valAddr)...) +} + +func CancelUnbondingDelegateKey(delAddr sdk.AccAddress) []byte { + return append(CancelUnbondingDelegationKey, address.MustLengthPrefix(delAddr)...) } From 6dafbcf2263b3a1145888b5bfe09b6c9071c7201 Mon Sep 17 00:00:00 2001 From: rustdev Date: Thu, 21 Dec 2023 20:21:26 +0000 Subject: [PATCH 10/13] add msg epoch params --- .../stakingmiddleware/v1beta1/genesis.proto | 10 +- .../v1beta1/stakingmiddleware.proto | 8 + .../stakingmiddleware/v1beta1/tx.proto | 27 ++ x/stakingmiddleware/keeper/genesis.go | 9 +- x/stakingmiddleware/keeper/keeper.go | 31 ++ x/stakingmiddleware/keeper/msg_server.go | 17 + x/stakingmiddleware/types/codec.go | 2 + x/stakingmiddleware/types/genesis.go | 4 +- x/stakingmiddleware/types/genesis.pb.go | 127 ++++-- x/stakingmiddleware/types/keys.go | 1 + x/stakingmiddleware/types/msgs.go | 28 ++ .../types/stakingmiddleware.pb.go | 223 +++++++-- x/stakingmiddleware/types/tx.pb.go | 422 +++++++++++++++++- 13 files changed, 823 insertions(+), 86 deletions(-) create mode 100644 x/stakingmiddleware/types/msgs.go diff --git a/proto/centauri/stakingmiddleware/v1beta1/genesis.proto b/proto/centauri/stakingmiddleware/v1beta1/genesis.proto index 4ff0e83c8..d57da1145 100644 --- a/proto/centauri/stakingmiddleware/v1beta1/genesis.proto +++ b/proto/centauri/stakingmiddleware/v1beta1/genesis.proto @@ -17,9 +17,11 @@ message GenesisState { (gogoproto.nullable) = false ]; + Params params = 2 [ (gogoproto.nullable) = false ]; + // delegations defines the delegations active at genesis. - repeated Delegation delegations = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; - repeated BeginRedelegate begindelegations = 3 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; - repeated Undelegate undelegates = 4 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; - repeated CancelUnbondingDelegation cancelunbondingdelegations = 5 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; + repeated Delegation delegations = 3 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; + repeated BeginRedelegate begindelegations = 4 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; + repeated Undelegate undelegates = 5 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; + repeated CancelUnbondingDelegation cancelunbondingdelegations = 6 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; } diff --git a/proto/centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto b/proto/centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto index 0038645e4..b427cbef0 100644 --- a/proto/centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto +++ b/proto/centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto @@ -69,3 +69,11 @@ message CancelUnbondingDelegation { int64 creation_height = 4; } + + +// Params holds parameters for the stakingmiddleware module. +message Params { + // expected blocks per year + uint64 blocks_per_epoch = 1; +} + diff --git a/proto/centauri/stakingmiddleware/v1beta1/tx.proto b/proto/centauri/stakingmiddleware/v1beta1/tx.proto index 5efe97b5d..4d71b6939 100644 --- a/proto/centauri/stakingmiddleware/v1beta1/tx.proto +++ b/proto/centauri/stakingmiddleware/v1beta1/tx.proto @@ -5,6 +5,7 @@ import "cosmos/msg/v1/msg.proto"; import "amino/amino.proto"; import "gogoproto/gogo.proto"; import "cosmos_proto/cosmos.proto"; +import "centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto"; option go_package = "x/stakingmiddleware/types"; @@ -12,6 +13,8 @@ option go_package = "x/stakingmiddleware/types"; service Msg { option (cosmos.msg.v1.service) = true; + rpc UpdateEpochParams(MsgUpdateEpochParams) returns (MsgUpdateParamsEpochResponse); + rpc SetPower(MsgSetPower) returns (MsgSetPowerResponse); } @@ -27,3 +30,27 @@ message MsgSetPower { // // Since: cosmos-sdk 0.47 message MsgSetPowerResponse {} + +// MsgUpdateParams is the Msg/UpdateParams request type. +// +// Since: cosmos-sdk 0.47 +message MsgUpdateEpochParams { + option (cosmos.msg.v1.signer) = "authority"; + option (amino.name) = "centauri/x/stakingmiddleware/MsgUpdateParams"; + + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // params defines the x/stakingmiddleware parameters to update. + // + // NOTE: All parameters must be supplied. + Params params = 2 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +// +// Since: cosmos-sdk 0.47 +message MsgUpdateParamsEpochResponse {} diff --git a/x/stakingmiddleware/keeper/genesis.go b/x/stakingmiddleware/keeper/genesis.go index 418884413..ff48282c9 100644 --- a/x/stakingmiddleware/keeper/genesis.go +++ b/x/stakingmiddleware/keeper/genesis.go @@ -8,10 +8,15 @@ import ( // InitGenesis new mint genesis func (keeper Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { keeper.SetLastTotalPower(ctx, data.LastTotalPower) + + if err := keeper.SetParams(ctx, data.Params); err != nil { + panic(err) + } } // ExportGenesis returns a GenesisState for a given context and keeper. func (keeper Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { - minter := keeper.GetLastTotalPower(ctx) - return types.NewGenesisState(minter) + power := keeper.GetLastTotalPower(ctx) + params := keeper.GetParams(ctx) + return types.NewGenesisState(power, params) } diff --git a/x/stakingmiddleware/keeper/keeper.go b/x/stakingmiddleware/keeper/keeper.go index 8bed69c57..5479a2bef 100644 --- a/x/stakingmiddleware/keeper/keeper.go +++ b/x/stakingmiddleware/keeper/keeper.go @@ -1,6 +1,8 @@ package keeper import ( + "fmt" + "github.com/cometbft/cometbft/libs/log" "github.com/notional-labs/composable/v6/x/stakingmiddleware/types" @@ -79,6 +81,35 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { // store.Set(kkk, b) // } +// SetParams sets the x/mint module parameters. +func (k Keeper) SetParams(ctx sdk.Context, p types.Params) error { + if p.BlocksPerEpoch < 5 { + //return error + return fmt.Errorf( + "BlocksPerEpoch must be greater than or equal to 5", + ) + + } + + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(&p) + store.Set(types.ParamsKey, bz) + + return nil +} + +// GetParams returns the current x/mint module parameters. +func (k Keeper) GetParams(ctx sdk.Context) (p types.Params) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParamsKey) + if bz == nil { + return p + } + + k.cdc.MustUnmarshal(bz, &p) + return p +} + // SetLastTotalPower Set the last total validator power. func (k Keeper) SetLastTotalPower(ctx sdk.Context, power sdkmath.Int) { store := ctx.KVStore(k.storeKey) diff --git a/x/stakingmiddleware/keeper/msg_server.go b/x/stakingmiddleware/keeper/msg_server.go index 30afdf83b..523b1610b 100644 --- a/x/stakingmiddleware/keeper/msg_server.go +++ b/x/stakingmiddleware/keeper/msg_server.go @@ -3,6 +3,9 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/notional-labs/composable/v6/x/stakingmiddleware/types" ) @@ -20,6 +23,20 @@ func NewMsgServerImpl(k Keeper) types.MsgServer { } } +// UpdateParams updates the params. +func (ms msgServer) UpdateEpochParams(goCtx context.Context, req *types.MsgUpdateEpochParams) (*types.MsgUpdateParamsEpochResponse, error) { + if ms.authority != req.Authority { + return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.authority, req.Authority) + } + + ctx := sdk.UnwrapSDKContext(goCtx) + if err := ms.SetParams(ctx, req.Params); err != nil { + return nil, err + } + + return &types.MsgUpdateParamsEpochResponse{}, nil +} + // UpdateParams updates the params. func (ms msgServer) SetPower(goCtx context.Context, req *types.MsgSetPower) (*types.MsgSetPowerResponse, error) { return &types.MsgSetPowerResponse{}, nil diff --git a/x/stakingmiddleware/types/codec.go b/x/stakingmiddleware/types/codec.go index 66b175743..ed9bf475d 100644 --- a/x/stakingmiddleware/types/codec.go +++ b/x/stakingmiddleware/types/codec.go @@ -17,12 +17,14 @@ import ( // provided LegacyAmino codec. These types are used for Amino JSON serialization func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { legacy.RegisterAminoMsg(cdc, &MsgSetPower{}, "composable/MsgSetPower") + legacy.RegisterAminoMsg(cdc, &MsgUpdateEpochParams{}, "composable/MsgUpdateEpochParams") } func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterImplementations( (*sdk.Msg)(nil), &MsgSetPower{}, + &MsgUpdateEpochParams{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } diff --git a/x/stakingmiddleware/types/genesis.go b/x/stakingmiddleware/types/genesis.go index 3830da245..7557dfb64 100644 --- a/x/stakingmiddleware/types/genesis.go +++ b/x/stakingmiddleware/types/genesis.go @@ -6,9 +6,10 @@ import ( ) // NewGenesisState creates a new GenesisState object -func NewGenesisState(m math.Int) *GenesisState { +func NewGenesisState(m math.Int, params Params) *GenesisState { return &GenesisState{ LastTotalPower: m, + Params: params, } } @@ -16,6 +17,7 @@ func NewGenesisState(m math.Int) *GenesisState { func DefaultGenesisState() *GenesisState { return &GenesisState{ LastTotalPower: sdk.ZeroInt(), + Params: Params{BlocksPerEpoch: 10}, } } diff --git a/x/stakingmiddleware/types/genesis.pb.go b/x/stakingmiddleware/types/genesis.pb.go index 35177651a..7cb2d3daa 100644 --- a/x/stakingmiddleware/types/genesis.pb.go +++ b/x/stakingmiddleware/types/genesis.pb.go @@ -30,11 +30,12 @@ type GenesisState struct { // last_total_power tracks the total amounts of bonded tokens recorded during // the previous end block. LastTotalPower github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=last_total_power,json=lastTotalPower,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"last_total_power"` + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` // delegations defines the delegations active at genesis. - Delegations []Delegation `protobuf:"bytes,2,rep,name=delegations,proto3" json:"delegations"` - Begindelegations []BeginRedelegate `protobuf:"bytes,3,rep,name=begindelegations,proto3" json:"begindelegations"` - Undelegates []Undelegate `protobuf:"bytes,4,rep,name=undelegates,proto3" json:"undelegates"` - Cancelunbondingdelegations []CancelUnbondingDelegation `protobuf:"bytes,5,rep,name=cancelunbondingdelegations,proto3" json:"cancelunbondingdelegations"` + Delegations []Delegation `protobuf:"bytes,3,rep,name=delegations,proto3" json:"delegations"` + Begindelegations []BeginRedelegate `protobuf:"bytes,4,rep,name=begindelegations,proto3" json:"begindelegations"` + Undelegates []Undelegate `protobuf:"bytes,5,rep,name=undelegates,proto3" json:"undelegates"` + Cancelunbondingdelegations []CancelUnbondingDelegation `protobuf:"bytes,6,rep,name=cancelunbondingdelegations,proto3" json:"cancelunbondingdelegations"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -70,6 +71,13 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + func (m *GenesisState) GetDelegations() []Delegation { if m != nil { return m.Delegations @@ -107,31 +115,33 @@ func init() { } var fileDescriptor_1aa0bd912277c095 = []byte{ - // 382 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xc1, 0x4a, 0xeb, 0x40, - 0x14, 0x86, 0x93, 0xdb, 0xde, 0x0b, 0x37, 0x2d, 0x97, 0xde, 0xe0, 0xa2, 0x76, 0x91, 0x96, 0x2e, - 0xa4, 0x08, 0x4e, 0xac, 0xdd, 0x09, 0x6e, 0xa2, 0x20, 0xee, 0xa4, 0x5a, 0x10, 0x5d, 0x94, 0x49, - 0x72, 0x18, 0xc7, 0x26, 0x33, 0x25, 0x33, 0xb1, 0xfa, 0x06, 0x2e, 0xdd, 0xfa, 0x06, 0x2e, 0x7d, - 0x8c, 0x2e, 0xbb, 0x14, 0x17, 0x45, 0xda, 0x85, 0xaf, 0x21, 0x99, 0xb4, 0x12, 0x68, 0xd1, 0x6c, - 0x92, 0x30, 0xe4, 0xff, 0xbe, 0x73, 0xce, 0x1c, 0x63, 0xd7, 0x03, 0x26, 0x71, 0x1c, 0x51, 0x5b, - 0x48, 0x3c, 0xa0, 0x8c, 0x84, 0xd4, 0xf7, 0x03, 0x18, 0xe1, 0x08, 0xec, 0xdb, 0xb6, 0x0b, 0x12, - 0xb7, 0x6d, 0x02, 0x0c, 0x04, 0x15, 0x68, 0x18, 0x71, 0xc9, 0xcd, 0xe6, 0x32, 0x81, 0x56, 0x12, - 0x68, 0x91, 0xa8, 0x6d, 0x10, 0x4e, 0xb8, 0xfa, 0xdd, 0x4e, 0xbe, 0xd2, 0x64, 0x6d, 0x3f, 0x87, - 0x6b, 0x95, 0x99, 0x66, 0xff, 0xe3, 0x90, 0x32, 0x6e, 0xab, 0x67, 0x7a, 0xd4, 0x7c, 0x2a, 0x1a, - 0xe5, 0xe3, 0xb4, 0xb4, 0x33, 0x89, 0x25, 0x98, 0x17, 0x46, 0x25, 0xc0, 0x42, 0xf6, 0x25, 0x97, - 0x38, 0xe8, 0x0f, 0xf9, 0x08, 0xa2, 0xaa, 0xde, 0xd0, 0x5b, 0x65, 0x07, 0x8d, 0xa7, 0x75, 0xed, - 0x6d, 0x5a, 0xdf, 0x22, 0x54, 0x5e, 0xc7, 0x2e, 0xf2, 0x78, 0x68, 0x7b, 0x5c, 0x84, 0x5c, 0x2c, - 0x5e, 0x3b, 0xc2, 0x1f, 0xd8, 0xf2, 0x7e, 0x08, 0x02, 0x9d, 0x30, 0xd9, 0xfd, 0x97, 0x70, 0xce, - 0x13, 0xcc, 0x69, 0x42, 0x31, 0xaf, 0x8c, 0x92, 0x0f, 0x01, 0x10, 0x2c, 0x29, 0x67, 0xa2, 0xfa, - 0xab, 0x51, 0x68, 0x95, 0xf6, 0x10, 0xfa, 0x79, 0x12, 0xe8, 0xe8, 0x2b, 0xe6, 0xfc, 0x4d, 0x8a, - 0x78, 0xfe, 0x78, 0xd9, 0xd6, 0xbb, 0x59, 0x9a, 0x79, 0x63, 0x54, 0x5c, 0x20, 0x94, 0x65, 0x0d, - 0x05, 0x65, 0xe8, 0xe4, 0x31, 0x38, 0x49, 0xb6, 0x0b, 0x8b, 0x34, 0x64, 0x35, 0x2b, 0xdc, 0xa4, - 0x91, 0x78, 0x79, 0x00, 0xa2, 0x5a, 0xcc, 0xdf, 0x48, 0x8f, 0xad, 0x33, 0x64, 0x69, 0xe6, 0x83, - 0x6e, 0xd4, 0x3c, 0xcc, 0x3c, 0x08, 0x62, 0xe6, 0x72, 0xe6, 0x53, 0x46, 0xb2, 0x3d, 0xfd, 0x56, - 0xb2, 0x83, 0x3c, 0xb2, 0x43, 0x45, 0xe9, 0x2d, 0x29, 0xeb, 0x87, 0xf8, 0x8d, 0xcb, 0xe9, 0x8c, - 0x67, 0x96, 0x3e, 0x99, 0x59, 0xfa, 0xfb, 0xcc, 0xd2, 0x1f, 0xe7, 0x96, 0x36, 0x99, 0x5b, 0xda, - 0xeb, 0xdc, 0xd2, 0x2e, 0x37, 0xef, 0xd6, 0x6c, 0x9f, 0xba, 0x79, 0xf7, 0x8f, 0xda, 0xab, 0xce, - 0x67, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3c, 0xc1, 0x1d, 0x94, 0x14, 0x03, 0x00, 0x00, + // 404 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xc1, 0x8a, 0xd3, 0x40, + 0x18, 0x80, 0x33, 0x6e, 0x2d, 0x98, 0x2e, 0xb2, 0x06, 0x0f, 0xb1, 0x87, 0x6c, 0xd9, 0x83, 0x94, + 0x05, 0x27, 0xb6, 0xbd, 0x09, 0x5e, 0xa2, 0xa0, 0xde, 0x4a, 0xb4, 0x20, 0x7a, 0x28, 0x93, 0xe4, + 0x67, 0x1c, 0x9b, 0xcc, 0x84, 0xcc, 0xc4, 0xea, 0x1b, 0x78, 0xf4, 0x31, 0x3c, 0xfa, 0x18, 0x3d, + 0xf6, 0x28, 0x1e, 0x8a, 0x34, 0x07, 0x5f, 0x43, 0x66, 0x92, 0x4a, 0xa0, 0xc5, 0xcd, 0xa5, 0x0d, + 0x43, 0xbe, 0xef, 0xcb, 0x3f, 0xfc, 0xf6, 0xe3, 0x18, 0xb8, 0x22, 0x65, 0xc1, 0x7c, 0xa9, 0xc8, + 0x8a, 0x71, 0x9a, 0xb1, 0x24, 0x49, 0x61, 0x4d, 0x0a, 0xf0, 0x3f, 0x4d, 0x22, 0x50, 0x64, 0xe2, + 0x53, 0xe0, 0x20, 0x99, 0xc4, 0x79, 0x21, 0x94, 0x70, 0xae, 0x0e, 0x04, 0x3e, 0x22, 0x70, 0x43, + 0x0c, 0xef, 0x53, 0x41, 0x85, 0x79, 0xdd, 0xd7, 0x4f, 0x35, 0x39, 0x7c, 0xd2, 0xa1, 0x75, 0xec, + 0xac, 0xd9, 0x7b, 0x24, 0x63, 0x5c, 0xf8, 0xe6, 0xb7, 0x3e, 0xba, 0xaa, 0x7a, 0xf6, 0xf9, 0x8b, + 0xfa, 0xd3, 0x5e, 0x2b, 0xa2, 0xc0, 0x79, 0x6b, 0x5f, 0xa4, 0x44, 0xaa, 0xa5, 0x12, 0x8a, 0xa4, + 0xcb, 0x5c, 0xac, 0xa1, 0x70, 0xd1, 0x08, 0x8d, 0xcf, 0x03, 0xbc, 0xd9, 0x5d, 0x5a, 0xbf, 0x76, + 0x97, 0x0f, 0x29, 0x53, 0x1f, 0xca, 0x08, 0xc7, 0x22, 0xf3, 0x63, 0x21, 0x33, 0x21, 0x9b, 0xbf, + 0x47, 0x32, 0x59, 0xf9, 0xea, 0x4b, 0x0e, 0x12, 0xbf, 0xe2, 0x2a, 0xbc, 0xab, 0x3d, 0x6f, 0xb4, + 0x66, 0xae, 0x2d, 0xce, 0x4b, 0xbb, 0x9f, 0x93, 0x82, 0x64, 0xd2, 0xbd, 0x35, 0x42, 0xe3, 0xc1, + 0xf4, 0x1a, 0xdf, 0x7c, 0x09, 0x78, 0x6e, 0x88, 0xa0, 0xa7, 0xdb, 0x61, 0xc3, 0x3b, 0xef, 0xed, + 0x41, 0x02, 0x29, 0x50, 0xa2, 0x98, 0xe0, 0xd2, 0x3d, 0x1b, 0x9d, 0x8d, 0x07, 0x53, 0xdc, 0x45, + 0xf7, 0xfc, 0x1f, 0x16, 0xdc, 0xd1, 0xca, 0xef, 0x7f, 0x7e, 0x5c, 0xa3, 0xb0, 0x6d, 0x73, 0x3e, + 0xda, 0x17, 0x11, 0x50, 0xc6, 0xdb, 0x85, 0x9e, 0x29, 0xcc, 0xba, 0x14, 0x02, 0xcd, 0x86, 0xd0, + 0xd0, 0xd0, 0xce, 0x1c, 0x79, 0xf5, 0x20, 0xe5, 0xe1, 0x00, 0xa4, 0x7b, 0xbb, 0xfb, 0x20, 0x0b, + 0x7e, 0xaa, 0xd0, 0xb6, 0x39, 0x5f, 0x91, 0x3d, 0x8c, 0x09, 0x8f, 0x21, 0x2d, 0x79, 0x24, 0x78, + 0xc2, 0x38, 0x6d, 0xcf, 0xd4, 0x37, 0xb1, 0xa7, 0x5d, 0x62, 0xcf, 0x8c, 0x65, 0x71, 0xb0, 0x9c, + 0xbe, 0xc4, 0xff, 0xb4, 0x82, 0xd9, 0x66, 0xef, 0xa1, 0xed, 0xde, 0x43, 0xbf, 0xf7, 0x1e, 0xfa, + 0x56, 0x79, 0xd6, 0xb6, 0xf2, 0xac, 0x9f, 0x95, 0x67, 0xbd, 0x7b, 0xf0, 0xf9, 0xc4, 0x1e, 0x9b, + 0x1d, 0x8a, 0xfa, 0x66, 0x43, 0x67, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x66, 0xe2, 0x9b, 0xf3, + 0x5e, 0x03, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -165,7 +175,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x2a + dAtA[i] = 0x32 } } if len(m.Undelegates) > 0 { @@ -179,7 +189,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x22 + dAtA[i] = 0x2a } } if len(m.Begindelegations) > 0 { @@ -193,7 +203,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 } } if len(m.Delegations) > 0 { @@ -207,9 +217,19 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a + } + } + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x12 { size := m.LastTotalPower.Size() i -= size @@ -242,6 +262,8 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.LastTotalPower.Size() n += 1 + l + sovGenesis(uint64(l)) + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) if len(m.Delegations) > 0 { for _, e := range m.Delegations { l = e.Size() @@ -338,6 +360,39 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Delegations", wireType) } @@ -371,7 +426,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 3: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Begindelegations", wireType) } @@ -405,7 +460,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 4: + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Undelegates", wireType) } @@ -439,7 +494,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 5: + case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Cancelunbondingdelegations", wireType) } diff --git a/x/stakingmiddleware/types/keys.go b/x/stakingmiddleware/types/keys.go index f4f334983..0e2edc734 100644 --- a/x/stakingmiddleware/types/keys.go +++ b/x/stakingmiddleware/types/keys.go @@ -11,6 +11,7 @@ var ( BeginRedelegateKey = []byte{0x02} // key for a delegation UndelegateKey = []byte{0x03} // key for a delegation CancelUnbondingDelegationKey = []byte{0x04} // key for a delegation + ParamsKey = []byte{0x05} // key for global staking middleware params in the keeper store ) const ( diff --git a/x/stakingmiddleware/types/msgs.go b/x/stakingmiddleware/types/msgs.go new file mode 100644 index 000000000..4418aa784 --- /dev/null +++ b/x/stakingmiddleware/types/msgs.go @@ -0,0 +1,28 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ sdk.Msg = &MsgUpdateEpochParams{} + +// GetSignBytes implements the LegacyMsg interface. +func (m MsgUpdateEpochParams) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) +} + +// GetSigners returns the expected signers for a MsgUpdateParams message. +func (m *MsgUpdateEpochParams) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(m.Authority) + return []sdk.AccAddress{addr} +} + +// ValidateBasic does a sanity check on the provided data. +func (m *MsgUpdateEpochParams) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil { + return errorsmod.Wrapf(err, "invalid authority address") + } + + return nil +} diff --git a/x/stakingmiddleware/types/stakingmiddleware.pb.go b/x/stakingmiddleware/types/stakingmiddleware.pb.go index d89b2e1fa..3b872272e 100644 --- a/x/stakingmiddleware/types/stakingmiddleware.pb.go +++ b/x/stakingmiddleware/types/stakingmiddleware.pb.go @@ -193,11 +193,58 @@ func (m *CancelUnbondingDelegation) XXX_DiscardUnknown() { var xxx_messageInfo_CancelUnbondingDelegation proto.InternalMessageInfo +// Params holds parameters for the stakingmiddleware module. +type Params struct { + // expected blocks per year + BlocksPerEpoch uint64 `protobuf:"varint,1,opt,name=blocks_per_epoch,json=blocksPerEpoch,proto3" json:"blocks_per_epoch,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_b3eb4aece69e048d, []int{4} +} +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) GetBlocksPerEpoch() uint64 { + if m != nil { + return m.BlocksPerEpoch + } + return 0 +} + func init() { proto.RegisterType((*Delegation)(nil), "centauri.stakingmiddleware.v1beta1.Delegation") proto.RegisterType((*BeginRedelegate)(nil), "centauri.stakingmiddleware.v1beta1.BeginRedelegate") proto.RegisterType((*Undelegate)(nil), "centauri.stakingmiddleware.v1beta1.Undelegate") proto.RegisterType((*CancelUnbondingDelegation)(nil), "centauri.stakingmiddleware.v1beta1.CancelUnbondingDelegation") + proto.RegisterType((*Params)(nil), "centauri.stakingmiddleware.v1beta1.Params") } func init() { @@ -205,38 +252,41 @@ func init() { } var fileDescriptor_b3eb4aece69e048d = []byte{ - // 492 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xb2, 0x4a, 0x4e, 0xcd, 0x2b, - 0x49, 0x2c, 0x2d, 0xca, 0xd4, 0x2f, 0x2e, 0x49, 0xcc, 0xce, 0xcc, 0x4b, 0xcf, 0xcd, 0x4c, 0x49, - 0xc9, 0x49, 0x2d, 0x4f, 0x2c, 0x4a, 0xd5, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xc4, 0x94, - 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x82, 0xe9, 0xd5, 0xc3, 0x54, 0x01, 0xd5, 0x2b, - 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xae, 0x0f, 0x62, 0x41, 0x74, 0x4a, 0x49, 0x26, 0xe7, - 0x17, 0xe7, 0xe6, 0x17, 0xc7, 0x43, 0x24, 0x20, 0x1c, 0xa8, 0x94, 0x1c, 0x84, 0xa7, 0x9f, 0x94, - 0x58, 0x8c, 0x70, 0x41, 0x72, 0x7e, 0x66, 0x1e, 0x54, 0x5e, 0x30, 0x31, 0x37, 0x33, 0x2f, 0x5f, - 0x1f, 0x4c, 0x42, 0x85, 0xc4, 0xa1, 0x5a, 0x72, 0x8b, 0xd3, 0xf5, 0xcb, 0x0c, 0x41, 0x14, 0x44, - 0x42, 0x69, 0x32, 0x13, 0x17, 0x97, 0x4b, 0x6a, 0x4e, 0x6a, 0x7a, 0x62, 0x49, 0x66, 0x7e, 0x9e, - 0x90, 0x2b, 0x97, 0x60, 0x0a, 0x84, 0x97, 0x5f, 0x14, 0x9f, 0x98, 0x92, 0x52, 0x94, 0x5a, 0x5c, - 0x2c, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0xe9, 0x24, 0x71, 0x69, 0x8b, 0xae, 0x08, 0xd4, 0x1d, 0x8e, - 0x10, 0x99, 0xe0, 0x92, 0xa2, 0xcc, 0xbc, 0xf4, 0x20, 0x01, 0xb8, 0x16, 0xa8, 0x38, 0xc8, 0x98, - 0xb2, 0xc4, 0x9c, 0xcc, 0x14, 0x14, 0x63, 0x98, 0x08, 0x19, 0x03, 0xd7, 0x02, 0x33, 0xc6, 0x86, - 0x8b, 0x2d, 0x31, 0x37, 0xbf, 0x34, 0xaf, 0x44, 0x82, 0x59, 0x81, 0x51, 0x83, 0xdb, 0x48, 0x52, - 0x0f, 0xaa, 0x11, 0xe4, 0x73, 0x58, 0xf8, 0xe9, 0x39, 0xe7, 0x67, 0xe6, 0x39, 0x71, 0x9e, 0xb8, - 0x27, 0xcf, 0xb0, 0xe2, 0xf9, 0x06, 0x2d, 0xc6, 0x20, 0xa8, 0x1e, 0x2b, 0xcb, 0x8e, 0x05, 0xf2, - 0x0c, 0x2f, 0x16, 0xc8, 0x33, 0x34, 0x3d, 0xdf, 0xa0, 0x85, 0xe9, 0xad, 0xae, 0xe7, 0x1b, 0xb4, - 0xc4, 0x20, 0xe6, 0xe9, 0x16, 0xa7, 0x64, 0xeb, 0xfb, 0x16, 0xa7, 0x43, 0x03, 0x22, 0x55, 0xe9, - 0x0b, 0x13, 0x17, 0xbf, 0x53, 0x6a, 0x7a, 0x66, 0x5e, 0x50, 0x2a, 0x54, 0x5f, 0x2a, 0xb5, 0x82, - 0xc6, 0x87, 0x4b, 0x14, 0x11, 0x34, 0xc5, 0x45, 0xc9, 0x44, 0x07, 0x8f, 0x30, 0x5c, 0x5b, 0x70, - 0x51, 0x32, 0x56, 0xd3, 0x52, 0x8a, 0x4b, 0xe0, 0xa6, 0x31, 0x13, 0x6d, 0x9a, 0x4b, 0x71, 0x09, - 0x66, 0x78, 0xb3, 0x90, 0x11, 0xde, 0x0e, 0x84, 0xc3, 0x5b, 0x16, 0x35, 0xbc, 0xd1, 0x82, 0x58, - 0x69, 0x2a, 0x13, 0x17, 0x57, 0x68, 0x1e, 0xb5, 0x43, 0x7c, 0x50, 0x24, 0x46, 0x6b, 0xc2, 0x81, - 0x23, 0x81, 0x1a, 0x38, 0x88, 0x80, 0x50, 0xba, 0xc3, 0xc4, 0x25, 0xe9, 0x9c, 0x98, 0x97, 0x9c, - 0x9a, 0x13, 0x9a, 0x97, 0x94, 0x9f, 0x97, 0x92, 0x99, 0x97, 0x3e, 0x3c, 0xf3, 0xac, 0x90, 0x3a, - 0x17, 0x7f, 0x72, 0x51, 0x2a, 0xd8, 0x5f, 0xf1, 0x19, 0xa9, 0x99, 0xe9, 0x19, 0x90, 0xa4, 0xc8, - 0x1c, 0xc4, 0x07, 0x13, 0xf6, 0x00, 0x8b, 0x5a, 0x79, 0x11, 0x0e, 0x4f, 0x75, 0xd4, 0xf0, 0xc4, - 0x19, 0x80, 0x4e, 0xc6, 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, 0x25, 0x59, - 0x81, 0xa5, 0xcc, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x97, 0x9f, 0xc6, 0x80, 0x00, - 0x00, 0x00, 0xff, 0xff, 0xbb, 0x65, 0x42, 0xc6, 0x1e, 0x06, 0x00, 0x00, + // 529 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x95, 0x4f, 0x6b, 0x13, 0x41, + 0x00, 0xc5, 0x77, 0x93, 0x12, 0xe8, 0x08, 0xfd, 0x13, 0xab, 0x26, 0x05, 0x37, 0x65, 0x2f, 0x0d, + 0x81, 0x66, 0x49, 0x7b, 0x32, 0x7a, 0xd0, 0xb4, 0x05, 0x11, 0x85, 0xb2, 0xa5, 0x17, 0x2f, 0xcb, + 0xec, 0xce, 0x30, 0x19, 0xb2, 0x3b, 0x13, 0x66, 0xa6, 0x51, 0xaf, 0x9e, 0xc4, 0x93, 0x20, 0xde, + 0x7b, 0xf4, 0x98, 0x83, 0x1f, 0xa2, 0xc7, 0xe2, 0xc9, 0x83, 0x88, 0x24, 0x87, 0xf8, 0x01, 0xfc, + 0x00, 0xb2, 0x3b, 0x93, 0x84, 0x98, 0x4a, 0x8a, 0xf4, 0x20, 0x5e, 0x76, 0x77, 0xde, 0x9b, 0xf7, + 0x98, 0xf9, 0x31, 0xbb, 0x0b, 0x9a, 0x11, 0x66, 0x0a, 0x9e, 0x0a, 0xea, 0x49, 0x05, 0x3b, 0x94, + 0x91, 0x84, 0x22, 0x14, 0xe3, 0x17, 0x50, 0x60, 0xaf, 0xd7, 0x08, 0xb1, 0x82, 0x8d, 0x79, 0xa7, + 0xde, 0x15, 0x5c, 0xf1, 0xa2, 0x3b, 0xce, 0xd6, 0xe7, 0x67, 0x98, 0xec, 0xe6, 0x06, 0xe1, 0x84, + 0x67, 0xd3, 0xbd, 0xf4, 0x49, 0x27, 0x37, 0xcb, 0x11, 0x97, 0x09, 0x97, 0x81, 0x36, 0xf4, 0xc0, + 0x58, 0x8e, 0x1e, 0x79, 0x21, 0x94, 0xd3, 0x15, 0x44, 0x9c, 0x32, 0xe3, 0xaf, 0xc3, 0x84, 0x32, + 0xee, 0x65, 0x57, 0x23, 0xdd, 0x31, 0x91, 0x44, 0x12, 0xaf, 0xd7, 0x48, 0x6f, 0xda, 0x70, 0xdf, + 0xe7, 0x00, 0x38, 0xc0, 0x31, 0x26, 0x50, 0x51, 0xce, 0x8a, 0x87, 0x60, 0x1d, 0xe9, 0x11, 0x17, + 0x01, 0x44, 0x48, 0x60, 0x29, 0x4b, 0xf6, 0x96, 0x5d, 0x5d, 0x6e, 0x95, 0x3e, 0x7f, 0xda, 0xd9, + 0x30, 0xeb, 0x78, 0xa4, 0x9d, 0x63, 0x25, 0x28, 0x23, 0xfe, 0xda, 0x24, 0x62, 0xf4, 0xb4, 0xa6, + 0x07, 0x63, 0x8a, 0x66, 0x6a, 0x72, 0x8b, 0x6a, 0x26, 0x91, 0x71, 0xcd, 0x03, 0x50, 0x80, 0x09, + 0x3f, 0x65, 0xaa, 0x94, 0xdf, 0xb2, 0xab, 0x37, 0x76, 0xcb, 0x75, 0x13, 0x4c, 0x77, 0x3e, 0xe6, + 0x57, 0xdf, 0xe7, 0x94, 0xb5, 0x96, 0xcf, 0xbf, 0x55, 0xac, 0x8f, 0xa3, 0x7e, 0xcd, 0xf6, 0x4d, + 0xa6, 0x79, 0xef, 0xcd, 0x59, 0xc5, 0xfa, 0x71, 0x56, 0xb1, 0x5e, 0x8f, 0xfa, 0xb5, 0xf9, 0x6d, + 0xbd, 0x1d, 0xf5, 0x6b, 0xb7, 0x75, 0xdf, 0x8e, 0x44, 0x1d, 0xef, 0x99, 0x24, 0x06, 0x04, 0x76, + 0x7f, 0xe6, 0xc0, 0x6a, 0x0b, 0x13, 0xca, 0x7c, 0x6c, 0x72, 0xf8, 0xba, 0xd0, 0x3c, 0x05, 0xb7, + 0xa6, 0x68, 0xa4, 0x88, 0xae, 0x8c, 0xe7, 0xe6, 0x24, 0x76, 0x2c, 0xa2, 0x4b, 0xdb, 0x90, 0x54, + 0x93, 0xb6, 0xfc, 0x95, 0xdb, 0x0e, 0xa4, 0x9a, 0xe7, 0xbd, 0xf4, 0x17, 0xbc, 0x1f, 0x2e, 0xe6, + 0x7d, 0x77, 0x96, 0xf7, 0x6f, 0x88, 0xdd, 0x0f, 0x39, 0x00, 0x4e, 0xd8, 0x75, 0x13, 0xff, 0x27, + 0x0e, 0xe3, 0xfd, 0xc5, 0x70, 0x4a, 0xb3, 0x70, 0xa6, 0x20, 0xdc, 0xaf, 0x39, 0x50, 0xde, 0x87, + 0x2c, 0xc2, 0xf1, 0x09, 0x0b, 0x39, 0x43, 0x94, 0x91, 0xff, 0xf3, 0x9d, 0x2d, 0x6e, 0x83, 0xd5, + 0x48, 0xe0, 0x6c, 0x5f, 0x41, 0x1b, 0x53, 0xd2, 0xd6, 0x47, 0x31, 0xef, 0xaf, 0x8c, 0xe5, 0xc7, + 0x99, 0xda, 0x7c, 0xb2, 0x98, 0xe7, 0xf6, 0x2c, 0xcf, 0x3f, 0x02, 0x74, 0x77, 0x41, 0xe1, 0x08, + 0x0a, 0x98, 0xc8, 0x62, 0x15, 0xac, 0x85, 0x31, 0x8f, 0x3a, 0x32, 0xe8, 0x62, 0x11, 0xe0, 0x2e, + 0x8f, 0xda, 0x19, 0xc9, 0x25, 0x7f, 0x45, 0xeb, 0x47, 0x58, 0x1c, 0xa6, 0x6a, 0x6b, 0xef, 0x7c, + 0xe0, 0xd8, 0x17, 0x03, 0xc7, 0xfe, 0x3e, 0x70, 0xec, 0x77, 0x43, 0xc7, 0xba, 0x18, 0x3a, 0xd6, + 0x97, 0xa1, 0x63, 0x3d, 0x2f, 0xbf, 0xbc, 0xe4, 0x3f, 0xa1, 0x5e, 0x75, 0xb1, 0x0c, 0x0b, 0xd9, + 0x37, 0x77, 0xef, 0x57, 0x00, 0x00, 0x00, 0xff, 0xff, 0x6c, 0xb3, 0x16, 0xfb, 0x52, 0x06, 0x00, + 0x00, } func (m *Delegation) Marshal() (dAtA []byte, err error) { @@ -439,6 +489,34 @@ func (m *CancelUnbondingDelegation) MarshalToSizedBuffer(dAtA []byte) (int, erro 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.BlocksPerEpoch != 0 { + i = encodeVarintStakingmiddleware(dAtA, i, uint64(m.BlocksPerEpoch)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func encodeVarintStakingmiddleware(dAtA []byte, offset int, v uint64) int { offset -= sovStakingmiddleware(v) base := offset @@ -533,6 +611,18 @@ func (m *CancelUnbondingDelegation) Size() (n int) { return n } +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BlocksPerEpoch != 0 { + n += 1 + sovStakingmiddleware(uint64(m.BlocksPerEpoch)) + } + return n +} + func sovStakingmiddleware(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1178,6 +1268,75 @@ func (m *CancelUnbondingDelegation) Unmarshal(dAtA []byte) error { } 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 ErrIntOverflowStakingmiddleware + } + 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 BlocksPerEpoch", wireType) + } + m.BlocksPerEpoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStakingmiddleware + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlocksPerEpoch |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipStakingmiddleware(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthStakingmiddleware + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipStakingmiddleware(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/stakingmiddleware/types/tx.pb.go b/x/stakingmiddleware/types/tx.pb.go index 56c79d309..189e21a45 100644 --- a/x/stakingmiddleware/types/tx.pb.go +++ b/x/stakingmiddleware/types/tx.pb.go @@ -118,9 +118,111 @@ func (m *MsgSetPowerResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSetPowerResponse proto.InternalMessageInfo +// MsgUpdateParams is the Msg/UpdateParams request type. +// +// Since: cosmos-sdk 0.47 +type MsgUpdateEpochParams struct { + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the x/stakingmiddleware parameters to update. + // + // NOTE: All parameters must be supplied. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateEpochParams) Reset() { *m = MsgUpdateEpochParams{} } +func (m *MsgUpdateEpochParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateEpochParams) ProtoMessage() {} +func (*MsgUpdateEpochParams) Descriptor() ([]byte, []int) { + return fileDescriptor_d15665ac9877b062, []int{2} +} +func (m *MsgUpdateEpochParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateEpochParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateEpochParams.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 *MsgUpdateEpochParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateEpochParams.Merge(m, src) +} +func (m *MsgUpdateEpochParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateEpochParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateEpochParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateEpochParams proto.InternalMessageInfo + +func (m *MsgUpdateEpochParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateEpochParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +// +// Since: cosmos-sdk 0.47 +type MsgUpdateParamsEpochResponse struct { +} + +func (m *MsgUpdateParamsEpochResponse) Reset() { *m = MsgUpdateParamsEpochResponse{} } +func (m *MsgUpdateParamsEpochResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsEpochResponse) ProtoMessage() {} +func (*MsgUpdateParamsEpochResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d15665ac9877b062, []int{3} +} +func (m *MsgUpdateParamsEpochResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsEpochResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsEpochResponse.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 *MsgUpdateParamsEpochResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsEpochResponse.Merge(m, src) +} +func (m *MsgUpdateParamsEpochResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsEpochResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsEpochResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsEpochResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgSetPower)(nil), "centauri.stakingmiddleware.v1beta1.MsgSetPower") proto.RegisterType((*MsgSetPowerResponse)(nil), "centauri.stakingmiddleware.v1beta1.MsgSetPowerResponse") + proto.RegisterType((*MsgUpdateEpochParams)(nil), "centauri.stakingmiddleware.v1beta1.MsgUpdateEpochParams") + proto.RegisterType((*MsgUpdateParamsEpochResponse)(nil), "centauri.stakingmiddleware.v1beta1.MsgUpdateParamsEpochResponse") } func init() { @@ -128,7 +230,7 @@ func init() { } var fileDescriptor_d15665ac9877b062 = []byte{ - // 267 bytes of a gzipped FileDescriptorProto + // 422 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4e, 0x4e, 0xcd, 0x2b, 0x49, 0x2c, 0x2d, 0xca, 0xd4, 0x2f, 0x2e, 0x49, 0xcc, 0xce, 0xcc, 0x4b, 0xcf, 0xcd, 0x4c, 0x49, 0xc9, 0x49, 0x2d, 0x4f, 0x2c, 0x4a, 0xd5, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x2f, @@ -136,16 +238,26 @@ var fileDescriptor_d15665ac9877b062 = []byte{ 0x55, 0x2c, 0x25, 0x9e, 0x9c, 0x5f, 0x9c, 0x9b, 0x5f, 0xac, 0x9f, 0x5b, 0x9c, 0xae, 0x5f, 0x66, 0x08, 0xa2, 0x20, 0x9a, 0xa5, 0x04, 0x13, 0x73, 0x33, 0xf3, 0xf2, 0xf5, 0xc1, 0x24, 0x54, 0x48, 0x24, 0x3d, 0x3f, 0x3d, 0x1f, 0xcc, 0xd4, 0x07, 0xb1, 0xa0, 0xa2, 0x92, 0x10, 0x13, 0xe2, 0x21, - 0x12, 0x10, 0x0e, 0x44, 0x4a, 0xc9, 0x80, 0x8b, 0xdb, 0xb7, 0x38, 0x3d, 0x38, 0xb5, 0x24, 0x20, - 0xbf, 0x3c, 0xb5, 0x48, 0x48, 0x91, 0x8b, 0x27, 0xad, 0x28, 0x3f, 0x37, 0x3e, 0x31, 0x25, 0xa5, - 0x28, 0xb5, 0xb8, 0x58, 0x82, 0x51, 0x81, 0x51, 0x83, 0x33, 0x88, 0x1b, 0x24, 0xe6, 0x08, 0x11, - 0x52, 0x12, 0xe5, 0x12, 0x46, 0xd2, 0x11, 0x94, 0x5a, 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x6a, 0xd4, - 0xc4, 0xc8, 0xc5, 0xec, 0x5b, 0x9c, 0x2e, 0x54, 0xc2, 0xc5, 0x01, 0x37, 0x4d, 0x5f, 0x8f, 0xb0, - 0xf7, 0xf4, 0x90, 0x0c, 0x93, 0x32, 0x27, 0x51, 0x03, 0xcc, 0x76, 0x29, 0xd6, 0x86, 0xe7, 0x1b, - 0xb4, 0x18, 0x9d, 0x8c, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, - 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0xb2, - 0x02, 0x4b, 0x74, 0x94, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x43, 0xc2, 0x18, 0x10, 0x00, - 0x00, 0xff, 0xff, 0x23, 0x35, 0xc7, 0x70, 0xb9, 0x01, 0x00, 0x00, + 0x12, 0x10, 0x0e, 0x54, 0xca, 0x8a, 0x08, 0xd7, 0x62, 0x3a, 0x0d, 0xac, 0x57, 0xc9, 0x80, 0x8b, + 0xdb, 0xb7, 0x38, 0x3d, 0x38, 0xb5, 0x24, 0x20, 0xbf, 0x3c, 0xb5, 0x48, 0x48, 0x91, 0x8b, 0x27, + 0xad, 0x28, 0x3f, 0x37, 0x3e, 0x31, 0x25, 0xa5, 0x28, 0xb5, 0xb8, 0x58, 0x82, 0x51, 0x81, 0x51, + 0x83, 0x33, 0x88, 0x1b, 0x24, 0xe6, 0x08, 0x11, 0x52, 0x12, 0xe5, 0x12, 0x46, 0xd2, 0x11, 0x94, + 0x5a, 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0xaa, 0x74, 0x8f, 0x91, 0x4b, 0xc4, 0xb7, 0x38, 0x3d, 0xb4, + 0x20, 0x25, 0xb1, 0x24, 0xd5, 0xb5, 0x20, 0x3f, 0x39, 0x23, 0x20, 0xb1, 0x28, 0x31, 0xb7, 0x58, + 0xc8, 0x8c, 0x8b, 0x33, 0xb1, 0xb4, 0x24, 0x23, 0xbf, 0x28, 0xb3, 0xa4, 0x12, 0x62, 0x9e, 0x93, + 0xc4, 0xa5, 0x2d, 0xba, 0x22, 0x50, 0x2f, 0x40, 0x8d, 0x0d, 0x2e, 0x29, 0xca, 0xcc, 0x4b, 0x0f, + 0x42, 0x28, 0x15, 0xf2, 0xe5, 0x62, 0x2b, 0x00, 0x9b, 0x20, 0xc1, 0xa4, 0xc0, 0xa8, 0xc1, 0x6d, + 0xa4, 0xa5, 0x47, 0x38, 0x9c, 0xf5, 0x20, 0x76, 0x3a, 0x71, 0x9e, 0xb8, 0x27, 0xcf, 0xb0, 0xe2, + 0xf9, 0x06, 0x2d, 0xc6, 0x20, 0xa8, 0x21, 0x56, 0xf6, 0x4d, 0xcf, 0x37, 0x68, 0x21, 0x8c, 0xef, + 0x7a, 0xbe, 0x41, 0x4b, 0x07, 0x1e, 0x6e, 0x15, 0x58, 0x42, 0x0e, 0xee, 0x19, 0x88, 0x99, 0x4a, + 0x72, 0x5c, 0x32, 0x68, 0x42, 0x60, 0x5f, 0xc2, 0x02, 0xc0, 0x68, 0x0a, 0x13, 0x17, 0xb3, 0x6f, + 0x71, 0xba, 0x50, 0x3f, 0x23, 0x97, 0x20, 0x66, 0x28, 0x58, 0x10, 0xe3, 0x7a, 0x6c, 0xe1, 0x27, + 0xe5, 0x40, 0x92, 0x4e, 0x2c, 0x2e, 0x13, 0x2a, 0xe1, 0xe2, 0x80, 0x47, 0xb0, 0x3e, 0x91, 0xa6, + 0xc1, 0x34, 0x48, 0x99, 0x93, 0xa8, 0x01, 0x66, 0xab, 0x14, 0x6b, 0x03, 0x28, 0xfc, 0x9d, 0x8c, + 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, + 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x12, 0x5b, 0xa8, 0x97, 0x54, + 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x13, 0xa7, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x78, 0x25, + 0x34, 0xad, 0x88, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -160,6 +272,7 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { + UpdateEpochParams(ctx context.Context, in *MsgUpdateEpochParams, opts ...grpc.CallOption) (*MsgUpdateParamsEpochResponse, error) SetPower(ctx context.Context, in *MsgSetPower, opts ...grpc.CallOption) (*MsgSetPowerResponse, error) } @@ -171,6 +284,15 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } +func (c *msgClient) UpdateEpochParams(ctx context.Context, in *MsgUpdateEpochParams, opts ...grpc.CallOption) (*MsgUpdateParamsEpochResponse, error) { + out := new(MsgUpdateParamsEpochResponse) + err := c.cc.Invoke(ctx, "/centauri.stakingmiddleware.v1beta1.Msg/UpdateEpochParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *msgClient) SetPower(ctx context.Context, in *MsgSetPower, opts ...grpc.CallOption) (*MsgSetPowerResponse, error) { out := new(MsgSetPowerResponse) err := c.cc.Invoke(ctx, "/centauri.stakingmiddleware.v1beta1.Msg/SetPower", in, out, opts...) @@ -182,6 +304,7 @@ func (c *msgClient) SetPower(ctx context.Context, in *MsgSetPower, opts ...grpc. // MsgServer is the server API for Msg service. type MsgServer interface { + UpdateEpochParams(context.Context, *MsgUpdateEpochParams) (*MsgUpdateParamsEpochResponse, error) SetPower(context.Context, *MsgSetPower) (*MsgSetPowerResponse, error) } @@ -189,6 +312,9 @@ type MsgServer interface { type UnimplementedMsgServer struct { } +func (*UnimplementedMsgServer) UpdateEpochParams(ctx context.Context, req *MsgUpdateEpochParams) (*MsgUpdateParamsEpochResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateEpochParams not implemented") +} func (*UnimplementedMsgServer) SetPower(ctx context.Context, req *MsgSetPower) (*MsgSetPowerResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SetPower not implemented") } @@ -197,6 +323,24 @@ func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } +func _Msg_UpdateEpochParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateEpochParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateEpochParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/centauri.stakingmiddleware.v1beta1.Msg/UpdateEpochParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateEpochParams(ctx, req.(*MsgUpdateEpochParams)) + } + return interceptor(ctx, in, info, handler) +} + func _Msg_SetPower_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MsgSetPower) if err := dec(in); err != nil { @@ -219,6 +363,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "centauri.stakingmiddleware.v1beta1.Msg", HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ + { + MethodName: "UpdateEpochParams", + Handler: _Msg_UpdateEpochParams_Handler, + }, { MethodName: "SetPower", Handler: _Msg_SetPower_Handler, @@ -281,6 +429,69 @@ func (m *MsgSetPowerResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgUpdateEpochParams) 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 *MsgUpdateEpochParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateEpochParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsEpochResponse) 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 *MsgUpdateParamsEpochResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsEpochResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -314,6 +525,30 @@ func (m *MsgSetPowerResponse) Size() (n int) { return n } +func (m *MsgUpdateEpochParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsEpochResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -452,6 +687,171 @@ func (m *MsgSetPowerResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateEpochParams) 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 ErrIntOverflowTx + } + 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: MsgUpdateEpochParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateEpochParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsEpochResponse) 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 ErrIntOverflowTx + } + 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: MsgUpdateParamsEpochResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsEpochResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From 1af77d8928e8b772062bba6899cdcd644137e96c Mon Sep 17 00:00:00 2001 From: rustdev Date: Thu, 21 Dec 2023 21:07:02 +0000 Subject: [PATCH 11/13] compete EndBlock for custom staking module. batch bond/unbond/redelegate --- custom/staking/module.go | 126 +++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 66 deletions(-) diff --git a/custom/staking/module.go b/custom/staking/module.go index 717d928a2..60ddc8028 100644 --- a/custom/staking/module.go +++ b/custom/staking/module.go @@ -61,77 +61,71 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { func (am AppModule) EndBlock(ctx sdk.Context, _abc abcitype.RequestEndBlock) []abcitype.ValidatorUpdate { println("EndBlock Custom Staking Module") - - delegations := am.keeper.Stakingmiddleware.DequeueAllDelegation(ctx) - println("Delegations: ", delegations) - println("Delegations len: ", len(delegations)) - //for delegations print the delegator address and the validator address - for _, delegation := range delegations { - println("Delegator Address: ", delegation.DelegatorAddress) - println("Validator Address: ", delegation.ValidatorAddress) - fmt.Println("Amount", delegation.Amount.Amount) - - msgDelegate := stakingtypes.MsgDelegate{DelegatorAddress: delegation.DelegatorAddress, ValidatorAddress: delegation.ValidatorAddress, Amount: delegation.Amount} - _, err := am.msgServer.Delegate(ctx, &msgDelegate) - if err != nil { - println("Error for Delegator Address: ", delegation.DelegatorAddress) + params := am.keeper.Stakingmiddleware.GetParams(ctx) + println("BlocksPerEpoch: ", params.BlocksPerEpoch) + println("Height: ", _abc.Height) + + should_execute_batch := (_abc.Height % int64(params.BlocksPerEpoch)) == 0 + if should_execute_batch { + println("Should batch delegation to be executed at block: ", _abc.Height) + + delegations := am.keeper.Stakingmiddleware.DequeueAllDelegation(ctx) + println("Delegations: ", delegations) + println("Delegations len: ", len(delegations)) + for _, delegation := range delegations { + println("Delegator Address: ", delegation.DelegatorAddress) + println("Validator Address: ", delegation.ValidatorAddress) + fmt.Println("Amount", delegation.Amount.Amount) + + msgDelegate := stakingtypes.MsgDelegate{DelegatorAddress: delegation.DelegatorAddress, ValidatorAddress: delegation.ValidatorAddress, Amount: delegation.Amount} + _, err := am.msgServer.Delegate(ctx, &msgDelegate) + if err != nil { + println("Error for Delegator Address: ", delegation.DelegatorAddress) + } } - } - beginredelegations := am.keeper.Stakingmiddleware.DequeueAllRedelegation(ctx) - println("BeginRedelegations: ", beginredelegations) - println("BeginRedelegations len: ", len(beginredelegations)) - for _, beginredelegation := range beginredelegations { - println("Delegator Address: ", beginredelegation.DelegatorAddress) - println("Validator Address: ", beginredelegation.ValidatorSrcAddress) - // fmt.Println("Amount", delegation.Amount.Amount) - - // msgDelegate := stakingtypes.MsgDelegate{DelegatorAddress: delegation.DelegatorAddress, ValidatorAddress: delegation.ValidatorAddress, Amount: delegation.Amount} - // _, err := am.msgServer.Delegate(ctx, &msgDelegate) - // if err != nil { - // println("Error for Delegator Address: ", delegation.DelegatorAddress) - // } - } + beginredelegations := am.keeper.Stakingmiddleware.DequeueAllRedelegation(ctx) + println("BeginRedelegations: ", beginredelegations) + println("BeginRedelegations len: ", len(beginredelegations)) + for _, redelegation := range beginredelegations { + println("Delegator Address: ", redelegation.DelegatorAddress) + println("Validator Address: ", redelegation.ValidatorSrcAddress) + + msg_redelegation := stakingtypes.MsgBeginRedelegate{DelegatorAddress: redelegation.DelegatorAddress, ValidatorSrcAddress: redelegation.ValidatorSrcAddress, ValidatorDstAddress: redelegation.ValidatorDstAddress, Amount: redelegation.Amount} + _, err := am.msgServer.BeginRedelegate(ctx, &msg_redelegation) + if err != nil { + println("Error for Delegator Address: ", msg_redelegation.DelegatorAddress) + } + } - undelegations := am.keeper.Stakingmiddleware.DequeueAllUndelegation(ctx) - println("Undelegation: ", beginredelegations) - println("Undelegation len: ", len(beginredelegations)) - for _, undelegation := range undelegations { - println("Undelegation Delegator Address: ", undelegation.DelegatorAddress) - println("Undelegation Validator Address: ", undelegation.ValidatorAddress) - // fmt.Println("Amount", delegation.Amount.Amount) - - // msgDelegate := stakingtypes.MsgDelegate{DelegatorAddress: delegation.DelegatorAddress, ValidatorAddress: delegation.ValidatorAddress, Amount: delegation.Amount} - // _, err := am.msgServer.Delegate(ctx, &msgDelegate) - // if err != nil { - // println("Error for Delegator Address: ", delegation.DelegatorAddress) - // } - } + undelegations := am.keeper.Stakingmiddleware.DequeueAllUndelegation(ctx) + println("Undelegation: ", beginredelegations) + println("Undelegation len: ", len(beginredelegations)) + for _, undelegation := range undelegations { + println("Undelegation Delegator Address: ", undelegation.DelegatorAddress) + println("Undelegation Validator Address: ", undelegation.ValidatorAddress) + + msg_undelegate := stakingtypes.MsgUndelegate{DelegatorAddress: undelegation.DelegatorAddress, ValidatorAddress: undelegation.ValidatorAddress, Amount: undelegation.Amount} + _, err := am.msgServer.Undelegate(ctx, &msg_undelegate) + if err != nil { + println("Error for Delegator Address: ", msg_undelegate.DelegatorAddress) + } + } - //DequeueAllCancelUnbondingDelegation - cancel_unbonding_delegations := am.keeper.Stakingmiddleware.DequeueAllCancelUnbondingDelegation(ctx) - println("Cancel Unbonding Delegations: ", cancel_unbonding_delegations) - println("Cancel Ubonding Delegations len: ", len(cancel_unbonding_delegations)) - for _, undelegation := range cancel_unbonding_delegations { - println("Cancel Unbonding Delegation Delegator Address: ", undelegation.DelegatorAddress) - println("Cancel Unbonding Delegations Validator Address: ", undelegation.ValidatorAddress) - // fmt.Println("Amount", delegation.Amount.Amount) - - // msgDelegate := stakingtypes.MsgDelegate{DelegatorAddress: delegation.DelegatorAddress, ValidatorAddress: delegation.ValidatorAddress, Amount: delegation.Amount} - // _, err := am.msgServer.Delegate(ctx, &msgDelegate) - // if err != nil { - // println("Error for Delegator Address: ", delegation.DelegatorAddress) - // } + cancel_unbonding_delegations := am.keeper.Stakingmiddleware.DequeueAllCancelUnbondingDelegation(ctx) + println("Cancel Unbonding Delegations: ", cancel_unbonding_delegations) + println("Cancel Ubonding Delegations len: ", len(cancel_unbonding_delegations)) + for _, cancel_unbonding_delegation := range cancel_unbonding_delegations { + println("Cancel Unbonding Delegation Delegator Address: ", cancel_unbonding_delegation.DelegatorAddress) + println("Cancel Unbonding Delegations Validator Address: ", cancel_unbonding_delegation.ValidatorAddress) + + msg_cancle_unbonding_delegation := stakingtypes.MsgCancelUnbondingDelegation{DelegatorAddress: cancel_unbonding_delegation.DelegatorAddress, ValidatorAddress: cancel_unbonding_delegation.ValidatorAddress, Amount: cancel_unbonding_delegation.Amount, CreationHeight: cancel_unbonding_delegation.CreationHeight} + _, err := am.msgServer.CancelUnbondingDelegation(ctx, &msg_cancle_unbonding_delegation) + if err != nil { + println("Error for Delegator Address: ", msg_cancle_unbonding_delegation.DelegatorAddress) + } + } } - // ctx.EventManager().EmitEvent( - // sdk.NewEvent( - // "DequeueAllDelegation", - // // sdk.NewAttribute(sdk.AttributeKeyAmount, balances.String()), - // // sdk.NewAttribute(types.AttributeKeyValidator, dvPair.ValidatorAddress), - // // sdk.NewAttribute(types.AttributeKeyDelegator, dvPair.DelegatorAddress), - // ), - // ) - return am.AppModule.EndBlock(ctx, _abc) } From b5658e53e96c5f75ad446c0e71ef3e127206c711 Mon Sep 17 00:00:00 2001 From: rustdev Date: Fri, 22 Dec 2023 20:25:28 +0000 Subject: [PATCH 12/13] introduce new end block logic to delay voting power update --- custom/staking/abci.go | 22 +++++++ custom/staking/keeper/keeper.go | 91 +++++++++++++++++++++++++++++ custom/staking/keeper/msg_server.go | 66 ++++++++++----------- custom/staking/module.go | 2 + 4 files changed, 147 insertions(+), 34 deletions(-) create mode 100644 custom/staking/abci.go diff --git a/custom/staking/abci.go b/custom/staking/abci.go new file mode 100644 index 000000000..915dafca0 --- /dev/null +++ b/custom/staking/abci.go @@ -0,0 +1,22 @@ +package bank + +import ( + "time" + + abci "github.com/cometbft/cometbft/abci/types" + + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" + + // "github.com/cosmos/cosmos-sdk/x/staking/keeper" + "github.com/cosmos/cosmos-sdk/x/staking/types" + + customstakingkeeper "github.com/notional-labs/composable/v6/custom/staking/keeper" +) + +// Called every block, update validator set +func EndBlocker(ctx sdk.Context, k *customstakingkeeper.Keeper) []abci.ValidatorUpdate { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) + + return k.BlockValidatorUpdates(ctx, ctx.BlockHeight()) +} diff --git a/custom/staking/keeper/keeper.go b/custom/staking/keeper/keeper.go index 0eb850289..3b51974e8 100644 --- a/custom/staking/keeper/keeper.go +++ b/custom/staking/keeper/keeper.go @@ -1,10 +1,13 @@ package keeper import ( + abcicometbft "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/codec" accountkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + "github.com/cosmos/cosmos-sdk/x/staking/types" + sdk "github.com/cosmos/cosmos-sdk/types" mintkeeper "github.com/notional-labs/composable/v6/x/mint/keeper" stakingmiddleware "github.com/notional-labs/composable/v6/x/stakingmiddleware/keeper" ) @@ -33,6 +36,94 @@ type Keeper struct { // return keeper // } +func (k Keeper) BlockValidatorUpdates(ctx sdk.Context, hight int64) []abcicometbft.ValidatorUpdate { + // Calculate validator set changes. + // + // NOTE: ApplyAndReturnValidatorSetUpdates has to come before + // UnbondAllMatureValidatorQueue. + // This fixes a bug when the unbonding period is instant (is the case in + // some of the tests). The test expected the validator to be completely + // unbonded after the Endblocker (go from Bonded -> Unbonding during + // ApplyAndReturnValidatorSetUpdates and then Unbonding -> Unbonded during + // UnbondAllMatureValidatorQueue). + println("BlockValidatorUpdates Custom Staking Module") + params := k.Stakingmiddleware.GetParams(ctx) + println("BlocksPerEpoch: ", params.BlocksPerEpoch) + should_execute_batch := (hight % int64(params.BlocksPerEpoch)) == 0 + var validatorUpdates []abcicometbft.ValidatorUpdate + if should_execute_batch { + println("Should Execute Batch: ", hight) + v, err := k.ApplyAndReturnValidatorSetUpdates(ctx) + if err != nil { + panic(err) + } + validatorUpdates = v + } + + // unbond all mature validators from the unbonding queue + k.UnbondAllMatureValidators(ctx) + + // Remove all mature unbonding delegations from the ubd queue. + matureUnbonds := k.DequeueAllMatureUBDQueue(ctx, ctx.BlockHeader().Time) + for _, dvPair := range matureUnbonds { + addr, err := sdk.ValAddressFromBech32(dvPair.ValidatorAddress) + if err != nil { + panic(err) + } + delegatorAddress := sdk.MustAccAddressFromBech32(dvPair.DelegatorAddress) + + balances, err := k.CompleteUnbonding(ctx, delegatorAddress, addr) + if err != nil { + continue + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeCompleteUnbonding, + sdk.NewAttribute(sdk.AttributeKeyAmount, balances.String()), + sdk.NewAttribute(types.AttributeKeyValidator, dvPair.ValidatorAddress), + sdk.NewAttribute(types.AttributeKeyDelegator, dvPair.DelegatorAddress), + ), + ) + } + + // Remove all mature redelegations from the red queue. + matureRedelegations := k.DequeueAllMatureRedelegationQueue(ctx, ctx.BlockHeader().Time) + for _, dvvTriplet := range matureRedelegations { + valSrcAddr, err := sdk.ValAddressFromBech32(dvvTriplet.ValidatorSrcAddress) + if err != nil { + panic(err) + } + valDstAddr, err := sdk.ValAddressFromBech32(dvvTriplet.ValidatorDstAddress) + if err != nil { + panic(err) + } + delegatorAddress := sdk.MustAccAddressFromBech32(dvvTriplet.DelegatorAddress) + + balances, err := k.CompleteRedelegation( + ctx, + delegatorAddress, + valSrcAddr, + valDstAddr, + ) + if err != nil { + continue + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeCompleteRedelegation, + sdk.NewAttribute(sdk.AttributeKeyAmount, balances.String()), + sdk.NewAttribute(types.AttributeKeyDelegator, dvvTriplet.DelegatorAddress), + sdk.NewAttribute(types.AttributeKeySrcValidator, dvvTriplet.ValidatorSrcAddress), + sdk.NewAttribute(types.AttributeKeyDstValidator, dvvTriplet.ValidatorDstAddress), + ), + ) + } + + return validatorUpdates +} + func NewKeeper( cdc codec.BinaryCodec, staking stakingkeeper.Keeper, diff --git a/custom/staking/keeper/msg_server.go b/custom/staking/keeper/msg_server.go index 5717e43a3..5b11da707 100644 --- a/custom/staking/keeper/msg_server.go +++ b/custom/staking/keeper/msg_server.go @@ -3,8 +3,6 @@ package keeper import ( "context" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -29,55 +27,55 @@ func (k msgServer) EditValidator(goCtx context.Context, msg *types.MsgEditValida } func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*types.MsgDelegateResponse, error) { - //todo add validation. check that this account really has some coins - ctx := sdk.UnwrapSDKContext(goCtx) + // //todo add validation. check that this account really has some coins + // ctx := sdk.UnwrapSDKContext(goCtx) - bondDenom := k.BondDenom(ctx) - if msg.Amount.Denom != bondDenom { - return nil, sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, "invalid coin denomination: got %s, expected %s", msg.Amount.Denom, bondDenom, - ) - } - - // k.mintkeeper.SetLastTotalPower(ctx, math.Int{}) - // k.stakingmiddleware.SetLastTotalPower(ctx, math.Int{}) - - // delegations := k.Stakingmiddleware.DequeueAllDelegation(ctx) - // if len(delegations) > 2 { + // bondDenom := k.BondDenom(ctx) + // if msg.Amount.Denom != bondDenom { // return nil, sdkerrors.Wrapf( - // sdkerrors.ErrInvalidRequest, "should always be less then X : got %s, expected %s", len(delegations), 1, + // sdkerrors.ErrInvalidRequest, "invalid coin denomination: got %s, expected %s", msg.Amount.Denom, bondDenom, // ) // } - k.Stakingmiddleware.SetDelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount) + // // k.mintkeeper.SetLastTotalPower(ctx, math.Int{}) + // // k.stakingmiddleware.SetLastTotalPower(ctx, math.Int{}) + + // // delegations := k.Stakingmiddleware.DequeueAllDelegation(ctx) + // // if len(delegations) > 2 { + // // return nil, sdkerrors.Wrapf( + // // sdkerrors.ErrInvalidRequest, "should always be less then X : got %s, expected %s", len(delegations), 1, + // // ) + // // } - return &types.MsgDelegateResponse{}, nil + // k.Stakingmiddleware.SetDelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount) + + // return &types.MsgDelegateResponse{}, nil // return nil, fmt.Errorf("My custom error: Nikita") - // return k.msgServer.Delegate(goCtx, msg) + return k.msgServer.Delegate(goCtx, msg) } func (k msgServer) BeginRedelegate(goCtx context.Context, msg *types.MsgBeginRedelegate) (*types.MsgBeginRedelegateResponse, error) { //todo add validation. check that this account really has some coins staked with this validator - ctx := sdk.UnwrapSDKContext(goCtx) - k.Stakingmiddleware.SetBeginRedelegation(ctx, msg.DelegatorAddress, msg.ValidatorSrcAddress, msg.ValidatorDstAddress, msg.Amount.Denom, msg.Amount.Amount) - return &types.MsgBeginRedelegateResponse{}, nil - // return k.msgServer.BeginRedelegate(goCtx, msg) + // ctx := sdk.UnwrapSDKContext(goCtx) + // k.Stakingmiddleware.SetBeginRedelegation(ctx, msg.DelegatorAddress, msg.ValidatorSrcAddress, msg.ValidatorDstAddress, msg.Amount.Denom, msg.Amount.Amount) + // return &types.MsgBeginRedelegateResponse{}, nil + return k.msgServer.BeginRedelegate(goCtx, msg) } func (k msgServer) Undelegate(goCtx context.Context, msg *types.MsgUndelegate) (*types.MsgUndelegateResponse, error) { - //todo add validation. check that this account really has some coins staked with this validator - ctx := sdk.UnwrapSDKContext(goCtx) - k.Stakingmiddleware.SetUndelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount) - return &types.MsgUndelegateResponse{}, nil - // return k.msgServer.Undelegate(goCtx, msg) + // //todo add validation. check that this account really has some coins staked with this validator + // ctx := sdk.UnwrapSDKContext(goCtx) + // k.Stakingmiddleware.SetUndelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount) + // return &types.MsgUndelegateResponse{}, nil + return k.msgServer.Undelegate(goCtx, msg) } func (k msgServer) CancelUnbondingDelegation(goCtx context.Context, msg *types.MsgCancelUnbondingDelegation) (*types.MsgCancelUnbondingDelegationResponse, error) { - //todo add validation. check that this account really has some coins staked with this validator - ctx := sdk.UnwrapSDKContext(goCtx) - k.Stakingmiddleware.SetCancelUndelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount, msg.CreationHeight) - return &types.MsgCancelUnbondingDelegationResponse{}, nil - // return k.msgServer.CancelUnbondingDelegation(goCtx, msg) + // //todo add validation. check that this account really has some coins staked with this validator + // ctx := sdk.UnwrapSDKContext(goCtx) + // k.Stakingmiddleware.SetCancelUndelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount, msg.CreationHeight) + // return &types.MsgCancelUnbondingDelegationResponse{}, nil + return k.msgServer.CancelUnbondingDelegation(goCtx, msg) } func (ms msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { diff --git a/custom/staking/module.go b/custom/staking/module.go index 60ddc8028..84baa4b46 100644 --- a/custom/staking/module.go +++ b/custom/staking/module.go @@ -60,6 +60,8 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { func (am AppModule) EndBlock(ctx sdk.Context, _abc abcitype.RequestEndBlock) []abcitype.ValidatorUpdate { + return EndBlocker(ctx, &am.keeper) + println("EndBlock Custom Staking Module") params := am.keeper.Stakingmiddleware.GetParams(ctx) println("BlocksPerEpoch: ", params.BlocksPerEpoch) From 447c600de4fbb0b278455bfc15f89e08f0a5be7f Mon Sep 17 00:00:00 2001 From: rustdev Date: Fri, 22 Dec 2023 21:00:12 +0000 Subject: [PATCH 13/13] refactor custom staking module, remove unnecessary keeper's functions --- app/keepers/keepers.go | 2 +- custom/staking/keeper/keeper.go | 31 -- custom/staking/keeper/msg_server.go | 36 -- custom/staking/module.go | 70 ---- custom/staking/types/keeper_interfaces.go | 10 - proto/centauri/mint/v1beta1/genesis.proto | 7 - .../stakingmiddleware/v1beta1/genesis.proto | 15 +- .../stakingmiddleware/v1beta1/query.proto | 11 +- .../stakingmiddleware/v1beta1/tx.proto | 15 - x/mint/types/genesis.pb.go | 92 +---- x/stakingmiddleware/client/cli/query.go | 24 +- x/stakingmiddleware/client/cli/tx.go | 25 +- x/stakingmiddleware/keeper/genesis.go | 5 +- x/stakingmiddleware/keeper/keeper.go | 200 ---------- x/stakingmiddleware/keeper/msg_server.go | 5 - x/stakingmiddleware/types/codec.go | 2 - x/stakingmiddleware/types/genesis.go | 13 +- x/stakingmiddleware/types/genesis.pb.go | 341 +--------------- x/stakingmiddleware/types/keys.go | 45 +-- x/stakingmiddleware/types/msg.go | 44 --- x/stakingmiddleware/types/query.pb.go | 195 +++++---- x/stakingmiddleware/types/query.pb.gw.go | 28 +- x/stakingmiddleware/types/tx.pb.go | 374 +----------------- 23 files changed, 217 insertions(+), 1373 deletions(-) delete mode 100644 custom/staking/types/keeper_interfaces.go delete mode 100644 x/stakingmiddleware/types/msg.go diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index f7a155c18..c46e8867c 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -196,7 +196,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers( appKeepers.StakingMiddlewareKeeper = stakingmiddleware.NewKeeper(appCodec, appKeepers.keys[stakingmiddlewaretypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String()) appKeepers.CustomStakingKeeper = customstaking.NewKeeper( - appCodec /*appKeepers.keys[stakingtypes.StoreKey],*/, *appKeepers.StakingKeeper, appKeepers.AccountKeeper, &appKeepers.MintKeeper, &appKeepers.StakingMiddlewareKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), + appCodec /*appKeepers.keys[stakingtypes.StoreKey],*/, *appKeepers.StakingKeeper, appKeepers.AccountKeeper, &appKeepers.StakingMiddlewareKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) appKeepers.DistrKeeper = distrkeeper.NewKeeper( diff --git a/custom/staking/keeper/keeper.go b/custom/staking/keeper/keeper.go index 3b51974e8..309f1b211 100644 --- a/custom/staking/keeper/keeper.go +++ b/custom/staking/keeper/keeper.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" sdk "github.com/cosmos/cosmos-sdk/types" - mintkeeper "github.com/notional-labs/composable/v6/x/mint/keeper" stakingmiddleware "github.com/notional-labs/composable/v6/x/stakingmiddleware/keeper" ) @@ -16,26 +15,10 @@ type Keeper struct { stakingkeeper.Keeper cdc codec.BinaryCodec acck accountkeeper.AccountKeeper - mintkeeper *mintkeeper.Keeper Stakingmiddleware *stakingmiddleware.Keeper authority string } -// func NewBaseKeeper( -// cdc codec.BinaryCodec, -// key storetypes.StoreKey, -// ak types.AccountKeeper, -// acck accountkeeper.AccountKeeper, -// bk bankkeeper.Keeper, -// authority string, -// ) Keeper { -// keeper := Keeper{ -// Keeper: *stakingkeeper.NewKeeper(cdc, key, ak, bk, authority), -// acck: acck, -// } -// return keeper -// } - func (k Keeper) BlockValidatorUpdates(ctx sdk.Context, hight int64) []abcicometbft.ValidatorUpdate { // Calculate validator set changes. // @@ -128,7 +111,6 @@ func NewKeeper( cdc codec.BinaryCodec, staking stakingkeeper.Keeper, acck accountkeeper.AccountKeeper, - mintkeeper *mintkeeper.Keeper, stakingmiddleware *stakingmiddleware.Keeper, authority string, ) Keeper { @@ -136,21 +118,8 @@ func NewKeeper( Keeper: staking, acck: acck, authority: authority, - mintkeeper: mintkeeper, Stakingmiddleware: stakingmiddleware, cdc: cdc, } return keeper } - -// func (k *Keeper) RegisterKeepers(akk banktypes.StakingKeeper) { -// k.acck = sk -// } - -// func (k Keeper) StoreDelegation(ctx sdk.Context, delegation types.Delegation) { -// delegatorAddress := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) - -// store := ctx.KVStore(k.storeKey) -// b := types.MustMarshalDelegation(k.cdc, delegation) -// store.Set(customstakingtypes.GetDelegationKey(delegatorAddress, delegation.GetValidatorAddr()), b) -// } diff --git a/custom/staking/keeper/msg_server.go b/custom/staking/keeper/msg_server.go index 5b11da707..234f3f2e4 100644 --- a/custom/staking/keeper/msg_server.go +++ b/custom/staking/keeper/msg_server.go @@ -27,54 +27,18 @@ func (k msgServer) EditValidator(goCtx context.Context, msg *types.MsgEditValida } func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*types.MsgDelegateResponse, error) { - // //todo add validation. check that this account really has some coins - // ctx := sdk.UnwrapSDKContext(goCtx) - - // bondDenom := k.BondDenom(ctx) - // if msg.Amount.Denom != bondDenom { - // return nil, sdkerrors.Wrapf( - // sdkerrors.ErrInvalidRequest, "invalid coin denomination: got %s, expected %s", msg.Amount.Denom, bondDenom, - // ) - // } - - // // k.mintkeeper.SetLastTotalPower(ctx, math.Int{}) - // // k.stakingmiddleware.SetLastTotalPower(ctx, math.Int{}) - - // // delegations := k.Stakingmiddleware.DequeueAllDelegation(ctx) - // // if len(delegations) > 2 { - // // return nil, sdkerrors.Wrapf( - // // sdkerrors.ErrInvalidRequest, "should always be less then X : got %s, expected %s", len(delegations), 1, - // // ) - // // } - - // k.Stakingmiddleware.SetDelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount) - - // return &types.MsgDelegateResponse{}, nil - // return nil, fmt.Errorf("My custom error: Nikita") return k.msgServer.Delegate(goCtx, msg) } func (k msgServer) BeginRedelegate(goCtx context.Context, msg *types.MsgBeginRedelegate) (*types.MsgBeginRedelegateResponse, error) { - //todo add validation. check that this account really has some coins staked with this validator - // ctx := sdk.UnwrapSDKContext(goCtx) - // k.Stakingmiddleware.SetBeginRedelegation(ctx, msg.DelegatorAddress, msg.ValidatorSrcAddress, msg.ValidatorDstAddress, msg.Amount.Denom, msg.Amount.Amount) - // return &types.MsgBeginRedelegateResponse{}, nil return k.msgServer.BeginRedelegate(goCtx, msg) } func (k msgServer) Undelegate(goCtx context.Context, msg *types.MsgUndelegate) (*types.MsgUndelegateResponse, error) { - // //todo add validation. check that this account really has some coins staked with this validator - // ctx := sdk.UnwrapSDKContext(goCtx) - // k.Stakingmiddleware.SetUndelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount) - // return &types.MsgUndelegateResponse{}, nil return k.msgServer.Undelegate(goCtx, msg) } func (k msgServer) CancelUnbondingDelegation(goCtx context.Context, msg *types.MsgCancelUnbondingDelegation) (*types.MsgCancelUnbondingDelegationResponse, error) { - // //todo add validation. check that this account really has some coins staked with this validator - // ctx := sdk.UnwrapSDKContext(goCtx) - // k.Stakingmiddleware.SetCancelUndelegation(ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Denom, msg.Amount.Amount, msg.CreationHeight) - // return &types.MsgCancelUnbondingDelegationResponse{}, nil return k.msgServer.CancelUnbondingDelegation(goCtx, msg) } diff --git a/custom/staking/module.go b/custom/staking/module.go index 84baa4b46..44a306f73 100644 --- a/custom/staking/module.go +++ b/custom/staking/module.go @@ -59,75 +59,5 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { } func (am AppModule) EndBlock(ctx sdk.Context, _abc abcitype.RequestEndBlock) []abcitype.ValidatorUpdate { - return EndBlocker(ctx, &am.keeper) - - println("EndBlock Custom Staking Module") - params := am.keeper.Stakingmiddleware.GetParams(ctx) - println("BlocksPerEpoch: ", params.BlocksPerEpoch) - println("Height: ", _abc.Height) - - should_execute_batch := (_abc.Height % int64(params.BlocksPerEpoch)) == 0 - if should_execute_batch { - println("Should batch delegation to be executed at block: ", _abc.Height) - - delegations := am.keeper.Stakingmiddleware.DequeueAllDelegation(ctx) - println("Delegations: ", delegations) - println("Delegations len: ", len(delegations)) - for _, delegation := range delegations { - println("Delegator Address: ", delegation.DelegatorAddress) - println("Validator Address: ", delegation.ValidatorAddress) - fmt.Println("Amount", delegation.Amount.Amount) - - msgDelegate := stakingtypes.MsgDelegate{DelegatorAddress: delegation.DelegatorAddress, ValidatorAddress: delegation.ValidatorAddress, Amount: delegation.Amount} - _, err := am.msgServer.Delegate(ctx, &msgDelegate) - if err != nil { - println("Error for Delegator Address: ", delegation.DelegatorAddress) - } - } - - beginredelegations := am.keeper.Stakingmiddleware.DequeueAllRedelegation(ctx) - println("BeginRedelegations: ", beginredelegations) - println("BeginRedelegations len: ", len(beginredelegations)) - for _, redelegation := range beginredelegations { - println("Delegator Address: ", redelegation.DelegatorAddress) - println("Validator Address: ", redelegation.ValidatorSrcAddress) - - msg_redelegation := stakingtypes.MsgBeginRedelegate{DelegatorAddress: redelegation.DelegatorAddress, ValidatorSrcAddress: redelegation.ValidatorSrcAddress, ValidatorDstAddress: redelegation.ValidatorDstAddress, Amount: redelegation.Amount} - _, err := am.msgServer.BeginRedelegate(ctx, &msg_redelegation) - if err != nil { - println("Error for Delegator Address: ", msg_redelegation.DelegatorAddress) - } - } - - undelegations := am.keeper.Stakingmiddleware.DequeueAllUndelegation(ctx) - println("Undelegation: ", beginredelegations) - println("Undelegation len: ", len(beginredelegations)) - for _, undelegation := range undelegations { - println("Undelegation Delegator Address: ", undelegation.DelegatorAddress) - println("Undelegation Validator Address: ", undelegation.ValidatorAddress) - - msg_undelegate := stakingtypes.MsgUndelegate{DelegatorAddress: undelegation.DelegatorAddress, ValidatorAddress: undelegation.ValidatorAddress, Amount: undelegation.Amount} - _, err := am.msgServer.Undelegate(ctx, &msg_undelegate) - if err != nil { - println("Error for Delegator Address: ", msg_undelegate.DelegatorAddress) - } - } - - cancel_unbonding_delegations := am.keeper.Stakingmiddleware.DequeueAllCancelUnbondingDelegation(ctx) - println("Cancel Unbonding Delegations: ", cancel_unbonding_delegations) - println("Cancel Ubonding Delegations len: ", len(cancel_unbonding_delegations)) - for _, cancel_unbonding_delegation := range cancel_unbonding_delegations { - println("Cancel Unbonding Delegation Delegator Address: ", cancel_unbonding_delegation.DelegatorAddress) - println("Cancel Unbonding Delegations Validator Address: ", cancel_unbonding_delegation.ValidatorAddress) - - msg_cancle_unbonding_delegation := stakingtypes.MsgCancelUnbondingDelegation{DelegatorAddress: cancel_unbonding_delegation.DelegatorAddress, ValidatorAddress: cancel_unbonding_delegation.ValidatorAddress, Amount: cancel_unbonding_delegation.Amount, CreationHeight: cancel_unbonding_delegation.CreationHeight} - _, err := am.msgServer.CancelUnbondingDelegation(ctx, &msg_cancle_unbonding_delegation) - if err != nil { - println("Error for Delegator Address: ", msg_cancle_unbonding_delegation.DelegatorAddress) - } - } - } - - return am.AppModule.EndBlock(ctx, _abc) } diff --git a/custom/staking/types/keeper_interfaces.go b/custom/staking/types/keeper_interfaces.go deleted file mode 100644 index 0907289a7..000000000 --- a/custom/staking/types/keeper_interfaces.go +++ /dev/null @@ -1,10 +0,0 @@ -package types - -import ( - "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -type MintKeeper interface { - SetLastTotalPower(ctx sdk.Context, power math.Int) -} diff --git a/proto/centauri/mint/v1beta1/genesis.proto b/proto/centauri/mint/v1beta1/genesis.proto index f984181b3..a30271a06 100644 --- a/proto/centauri/mint/v1beta1/genesis.proto +++ b/proto/centauri/mint/v1beta1/genesis.proto @@ -19,11 +19,4 @@ message GenesisState { (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coin", (gogoproto.nullable) = false ]; - - // last_total_power tracks the total amounts of bonded tokens recorded during - // the previous end block. - bytes last_total_power = 4 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", - (gogoproto.nullable) = false - ]; } diff --git a/proto/centauri/stakingmiddleware/v1beta1/genesis.proto b/proto/centauri/stakingmiddleware/v1beta1/genesis.proto index d57da1145..f2cdb42c2 100644 --- a/proto/centauri/stakingmiddleware/v1beta1/genesis.proto +++ b/proto/centauri/stakingmiddleware/v1beta1/genesis.proto @@ -10,18 +10,5 @@ option go_package = "x/stakingmiddleware/types"; // GenesisState defines the stakingmiddleware module's genesis state. message GenesisState { - // last_total_power tracks the total amounts of bonded tokens recorded during - // the previous end block. - bytes last_total_power = 1 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", - (gogoproto.nullable) = false - ]; - - Params params = 2 [ (gogoproto.nullable) = false ]; - - // delegations defines the delegations active at genesis. - repeated Delegation delegations = 3 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; - repeated BeginRedelegate begindelegations = 4 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; - repeated Undelegate undelegates = 5 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; - repeated CancelUnbondingDelegation cancelunbondingdelegations = 6 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; + Params params = 1 [ (gogoproto.nullable) = false ]; } diff --git a/proto/centauri/stakingmiddleware/v1beta1/query.proto b/proto/centauri/stakingmiddleware/v1beta1/query.proto index 4c592f4b4..026dd1972 100644 --- a/proto/centauri/stakingmiddleware/v1beta1/query.proto +++ b/proto/centauri/stakingmiddleware/v1beta1/query.proto @@ -3,20 +3,23 @@ package centauri.stakingmiddleware.v1beta1; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; +import "centauri/stakingmiddleware/v1beta1/stakingmiddleware.proto"; option go_package = "x/stakingmiddleware/types"; // Query provides defines the gRPC querier service. service Query { // Params returns the total set of minting parameters. - rpc Power(QueryPowerRequest) returns (QueryPowerResponse) { - option (google.api.http).get = "/cosmos/stakingmiddleware/v1beta1/params"; + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/cosmos/mint/v1beta1/params"; } } // QueryParamsRequest is the request type for the Query/Params RPC method. -message QueryPowerRequest {} +message QueryParamsRequest {} // QueryParamsResponse is the response type for the Query/Params RPC method. -message QueryPowerResponse { +message QueryParamsResponse { + // params defines the parameters of the module. + Params params = 1 [ (gogoproto.nullable) = false ]; } diff --git a/proto/centauri/stakingmiddleware/v1beta1/tx.proto b/proto/centauri/stakingmiddleware/v1beta1/tx.proto index 4d71b6939..491b4fcab 100644 --- a/proto/centauri/stakingmiddleware/v1beta1/tx.proto +++ b/proto/centauri/stakingmiddleware/v1beta1/tx.proto @@ -14,23 +14,8 @@ service Msg { option (cosmos.msg.v1.service) = true; rpc UpdateEpochParams(MsgUpdateEpochParams) returns (MsgUpdateParamsEpochResponse); - - rpc SetPower(MsgSetPower) returns (MsgSetPowerResponse); -} - -// MsgSetPower is the Msg/SetPower request type. -// -// Since: cosmos-sdk 0.47 -message MsgSetPower { - string from_address = 1; } -// MsgSetPowerResponse defines the response structure for executing a -// MsgSetPower message. -// -// Since: cosmos-sdk 0.47 -message MsgSetPowerResponse {} - // MsgUpdateParams is the Msg/UpdateParams request type. // // Since: cosmos-sdk 0.47 diff --git a/x/mint/types/genesis.pb.go b/x/mint/types/genesis.pb.go index 93b5c6d44..4c2486d24 100644 --- a/x/mint/types/genesis.pb.go +++ b/x/mint/types/genesis.pb.go @@ -5,7 +5,6 @@ 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/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" @@ -32,9 +31,6 @@ type GenesisState struct { // params defines all the paramaters of the module. Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` IncentivesSupply types.Coin `protobuf:"bytes,3,opt,name=incentives_supply,json=incentivesSupply,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coin" json:"incentives_supply"` - // last_total_power tracks the total amounts of bonded tokens recorded during - // the previous end block. - LastTotalPower github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=last_total_power,json=lastTotalPower,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"last_total_power"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -100,29 +96,26 @@ func init() { } var fileDescriptor_dc8b577617211e57 = []byte{ - // 340 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0x41, 0x4b, 0xf3, 0x30, - 0x18, 0x80, 0xdb, 0x7d, 0x63, 0x87, 0x7e, 0x43, 0x66, 0x51, 0xa8, 0x03, 0xb3, 0xa1, 0x30, 0x77, - 0x31, 0x61, 0x7a, 0xf4, 0x56, 0x0f, 0xe2, 0x41, 0x18, 0x9b, 0x07, 0xf1, 0x32, 0xd2, 0x1a, 0x6a, - 0x70, 0x4d, 0x4a, 0xf3, 0x6e, 0x73, 0xff, 0xc2, 0xdf, 0xe1, 0x2f, 0xd9, 0x71, 0x47, 0x51, 0x98, - 0xb2, 0xfd, 0x11, 0x49, 0xd2, 0xcd, 0xcb, 0x10, 0x4f, 0x2d, 0xe4, 0x79, 0x9e, 0xe4, 0xe5, 0xf5, - 0x8e, 0x63, 0x26, 0x80, 0x8e, 0x72, 0x4e, 0x52, 0x2e, 0x80, 0x8c, 0x3b, 0x11, 0x03, 0xda, 0x21, - 0x09, 0x13, 0x4c, 0x71, 0x85, 0xb3, 0x5c, 0x82, 0xf4, 0xf7, 0xd7, 0x10, 0xd6, 0x10, 0x2e, 0xa0, - 0xfa, 0x5e, 0x22, 0x13, 0x69, 0x08, 0xa2, 0xff, 0x2c, 0x5c, 0x6f, 0x6e, 0x2f, 0x1a, 0xd3, 0x12, - 0x28, 0x96, 0x2a, 0x95, 0x8a, 0x44, 0x54, 0xb1, 0xcd, 0x79, 0x2c, 0xb9, 0xb0, 0xe7, 0x47, 0x1f, - 0x25, 0xaf, 0x7a, 0x65, 0x1f, 0xd0, 0x07, 0x0a, 0xcc, 0xbf, 0xf0, 0x2a, 0x5a, 0x67, 0x79, 0xe0, - 0x36, 0xdd, 0xf6, 0xff, 0xb3, 0x43, 0xbc, 0xf5, 0x41, 0xf8, 0xc6, 0x40, 0x61, 0x79, 0xb6, 0x68, - 0x38, 0xbd, 0x42, 0xd1, 0x72, 0x46, 0x73, 0x9a, 0xaa, 0xa0, 0xf4, 0xab, 0xdc, 0x35, 0xd0, 0x5a, - 0xb6, 0x8a, 0x3f, 0xf1, 0x76, 0xb9, 0xd0, 0x3c, 0x1f, 0x33, 0x35, 0x50, 0xa3, 0x2c, 0x1b, 0x4e, - 0x83, 0x7f, 0xa6, 0x73, 0x80, 0xed, 0x18, 0x58, 0x8f, 0xb1, 0xa9, 0x5c, 0x4a, 0x2e, 0x42, 0xa2, - 0x1b, 0xaf, 0x9f, 0x8d, 0x93, 0x84, 0xc3, 0xe3, 0x28, 0xc2, 0xb1, 0x4c, 0x49, 0x31, 0xb3, 0xfd, - 0x9c, 0xaa, 0x87, 0x27, 0x02, 0xd3, 0x8c, 0x29, 0x23, 0xf4, 0x6a, 0x3f, 0x97, 0xf4, 0xcd, 0x1d, - 0xfe, 0x9d, 0x57, 0x1b, 0x52, 0x05, 0x03, 0x90, 0x40, 0x87, 0x83, 0x4c, 0x4e, 0x58, 0x1e, 0x94, - 0x9b, 0x6e, 0xbb, 0x1a, 0x62, 0x1d, 0x7f, 0x5f, 0x34, 0x5a, 0x7f, 0x88, 0x5f, 0x0b, 0xe8, 0xed, - 0xe8, 0xce, 0xad, 0xce, 0x74, 0x75, 0x25, 0x6c, 0xcd, 0x96, 0xc8, 0x9d, 0x2f, 0x91, 0xfb, 0xb5, - 0x44, 0xee, 0xcb, 0x0a, 0x39, 0xf3, 0x15, 0x72, 0xde, 0x56, 0xc8, 0xb9, 0xaf, 0x3e, 0xdb, 0x95, - 0x19, 0x37, 0xaa, 0x98, 0x65, 0x9c, 0x7f, 0x07, 0x00, 0x00, 0xff, 0xff, 0x51, 0x7e, 0xb8, 0x8b, - 0x22, 0x02, 0x00, 0x00, + // 296 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x90, 0x3f, 0x4e, 0xc3, 0x30, + 0x14, 0x87, 0xe3, 0x82, 0x3a, 0x84, 0x0e, 0x10, 0x81, 0x14, 0x2a, 0xe1, 0x56, 0x20, 0x01, 0x0b, + 0xb6, 0x0a, 0x23, 0x5b, 0x18, 0x98, 0x90, 0x50, 0xbb, 0xb1, 0x20, 0x27, 0x58, 0xc1, 0x82, 0xd8, + 0x56, 0x9e, 0x53, 0xe8, 0xc8, 0x0d, 0x38, 0x07, 0x27, 0xe9, 0xd8, 0x91, 0x09, 0x50, 0x72, 0x11, + 0x64, 0x3b, 0x2d, 0x4b, 0xc5, 0x64, 0x4b, 0xef, 0xfb, 0x7e, 0xef, 0x4f, 0x78, 0x94, 0x71, 0x69, + 0x58, 0x55, 0x0a, 0x5a, 0x08, 0x69, 0xe8, 0x74, 0x94, 0x72, 0xc3, 0x46, 0x34, 0xe7, 0x92, 0x83, + 0x00, 0xa2, 0x4b, 0x65, 0x54, 0xb4, 0xb7, 0x84, 0x88, 0x85, 0x48, 0x0b, 0xf5, 0x77, 0x73, 0x95, + 0x2b, 0x47, 0x50, 0xfb, 0xf3, 0x70, 0x7f, 0xb8, 0x3e, 0xd1, 0x99, 0x9e, 0xc0, 0x99, 0x82, 0x42, + 0x01, 0x4d, 0x19, 0xf0, 0x55, 0x3d, 0x53, 0x42, 0xfa, 0xfa, 0xe1, 0x5b, 0x27, 0xec, 0x5d, 0xfb, + 0x01, 0x26, 0x86, 0x19, 0x1e, 0x5d, 0x86, 0x5d, 0xab, 0xf3, 0x32, 0x46, 0x43, 0x74, 0xba, 0x75, + 0x7e, 0x40, 0xd6, 0x0e, 0x44, 0x6e, 0x1c, 0x94, 0x6c, 0xce, 0xbf, 0x06, 0xc1, 0xb8, 0x55, 0xac, + 0xac, 0x59, 0xc9, 0x0a, 0x88, 0x3b, 0xff, 0xca, 0xb7, 0x0e, 0x5a, 0xca, 0x5e, 0x89, 0x5e, 0xc2, + 0x1d, 0x21, 0x2d, 0x2f, 0xa6, 0x1c, 0xee, 0xa1, 0xd2, 0xfa, 0x79, 0x16, 0x6f, 0xb8, 0x9c, 0x7d, + 0xe2, 0xd7, 0x20, 0x76, 0x8d, 0x55, 0xca, 0x95, 0x12, 0x32, 0xa1, 0x36, 0xe3, 0xe3, 0x7b, 0x70, + 0x92, 0x0b, 0xf3, 0x58, 0xa5, 0x24, 0x53, 0x05, 0x6d, 0x77, 0xf6, 0xcf, 0x19, 0x3c, 0x3c, 0x51, + 0x33, 0xd3, 0x1c, 0x9c, 0x30, 0xde, 0xfe, 0x6b, 0x32, 0x71, 0x3d, 0x92, 0xe3, 0x79, 0x8d, 0xd1, + 0xa2, 0xc6, 0xe8, 0xa7, 0xc6, 0xe8, 0xbd, 0xc1, 0xc1, 0xa2, 0xc1, 0xc1, 0x67, 0x83, 0x83, 0xbb, + 0xde, 0xab, 0x3f, 0xac, 0xd3, 0xd3, 0xae, 0x3b, 0xd9, 0xc5, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x7c, 0x38, 0xd2, 0x82, 0xc8, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -145,16 +138,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - { - size := m.LastTotalPower.Size() - i -= size - if _, err := m.LastTotalPower.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 { size, err := m.IncentivesSupply.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -211,8 +194,6 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) l = m.IncentivesSupply.Size() n += 1 + l + sovGenesis(uint64(l)) - l = m.LastTotalPower.Size() - n += 1 + l + sovGenesis(uint64(l)) return n } @@ -350,39 +331,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LastTotalPower", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.LastTotalPower.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/stakingmiddleware/client/cli/query.go b/x/stakingmiddleware/client/cli/query.go index 939b8a5c0..31b1150dd 100644 --- a/x/stakingmiddleware/client/cli/query.go +++ b/x/stakingmiddleware/client/cli/query.go @@ -1,8 +1,6 @@ package cli import ( - "fmt" - "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" @@ -14,14 +12,14 @@ import ( func GetQueryCmd() *cobra.Command { mintingQueryCmd := &cobra.Command{ Use: types.ModuleName, - Short: "Querying commands for the minting module", + Short: "Querying commands for the staking middleware module", DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, } mintingQueryCmd.AddCommand( - GetCmdQueryPower(), + GetCmdQueryParams(), ) return mintingQueryCmd @@ -29,31 +27,25 @@ func GetQueryCmd() *cobra.Command { // GetCmdQueryParams implements a command to return the current minting // parameters. -func GetCmdQueryPower() *cobra.Command { +func GetCmdQueryParams() *cobra.Command { cmd := &cobra.Command{ - Use: "power", - Short: "Query the current power", + Use: "params", + Short: "Query the current minting parameters", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } - - return clientCtx.PrintString(fmt.Sprintf("%s\n", "hello world")) - queryClient := types.NewQueryClient(clientCtx) - params := &types.QueryPowerRequest{} - res, err := queryClient.Power(cmd.Context(), params) + params := &types.QueryParamsRequest{} + res, err := queryClient.Params(cmd.Context(), params) if err != nil { return err } - _ = res - // return nil - return clientCtx.PrintString(fmt.Sprintf("%s\n", "hello world")) - // return clientCtx.PrintProto(&res.Power) + return clientCtx.PrintProto(&res.Params) }, } diff --git a/x/stakingmiddleware/client/cli/tx.go b/x/stakingmiddleware/client/cli/tx.go index bd6465a2b..82597aec2 100644 --- a/x/stakingmiddleware/client/cli/tx.go +++ b/x/stakingmiddleware/client/cli/tx.go @@ -2,8 +2,6 @@ package cli import ( "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/tx" "github.com/spf13/cobra" "github.com/notional-labs/composable/v6/x/stakingmiddleware/types" @@ -19,28 +17,7 @@ func GetTxCmd() *cobra.Command { RunE: client.ValidateCmd, } - txCmd.AddCommand( - GetCmdSetPower(), - ) + txCmd.AddCommand() return txCmd } - -func GetCmdSetPower() *cobra.Command { - cmd := &cobra.Command{ - Use: "fund [amount]", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - msg := types.NewMsgSetPower(clientCtx.GetFromAddress()) - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - flags.AddTxFlagsToCmd(cmd) - - return cmd -} diff --git a/x/stakingmiddleware/keeper/genesis.go b/x/stakingmiddleware/keeper/genesis.go index ff48282c9..e5472e6ab 100644 --- a/x/stakingmiddleware/keeper/genesis.go +++ b/x/stakingmiddleware/keeper/genesis.go @@ -7,8 +7,6 @@ import ( // InitGenesis new mint genesis func (keeper Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { - keeper.SetLastTotalPower(ctx, data.LastTotalPower) - if err := keeper.SetParams(ctx, data.Params); err != nil { panic(err) } @@ -16,7 +14,6 @@ func (keeper Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { // ExportGenesis returns a GenesisState for a given context and keeper. func (keeper Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { - power := keeper.GetLastTotalPower(ctx) params := keeper.GetParams(ctx) - return types.NewGenesisState(power, params) + return types.NewGenesisState(params) } diff --git a/x/stakingmiddleware/keeper/keeper.go b/x/stakingmiddleware/keeper/keeper.go index 5479a2bef..837bbc7c6 100644 --- a/x/stakingmiddleware/keeper/keeper.go +++ b/x/stakingmiddleware/keeper/keeper.go @@ -9,8 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - - sdkmath "cosmossdk.io/math" ) // Keeper of the staking middleware store @@ -45,42 +43,6 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+types.ModuleName) } -// // SetParams sets the x/mint module parameters. -// func (k Keeper) SetParams(ctx sdk.Context, p types.Params) error { -// if err := p.Validate(); err != nil { -// return err -// } - -// store := ctx.KVStore(k.storeKey) -// bz := k.cdc.MustMarshal(&p) -// store.Set(types.ParamsKey, bz) - -// return nil -// } - -// // GetParams returns the current x/mint module parameters. -// func (k Keeper) GetParams(ctx sdk.Context) (p types.Params) { -// store := ctx.KVStore(k.storeKey) -// bz := store.Get(types.ParamsKey) -// if bz == nil { -// return p -// } - -// k.cdc.MustUnmarshal(bz, &p) -// return p -// } - -// func (k Keeper) StoreDelegation(ctx sdk.Context, delegation stakingtypes.Delegation) { -// delegatorAddress := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) -// log := k.Logger(ctx) -// log.Info("StoreDelegation", "delegatorAddress", delegatorAddress, "validatorAddress", delegation.GetValidatorAddr()) -// store := ctx.KVStore(k.storeKey) -// b := stakingtypes.MustMarshalDelegation(k.cdc, delegation) -// kkk := types.GetDelegationKey(delegatorAddress, delegation.GetValidatorAddr()) -// // log.Info() -// store.Set(kkk, b) -// } - // SetParams sets the x/mint module parameters. func (k Keeper) SetParams(ctx sdk.Context, p types.Params) error { if p.BlocksPerEpoch < 5 { @@ -109,165 +71,3 @@ func (k Keeper) GetParams(ctx sdk.Context) (p types.Params) { k.cdc.MustUnmarshal(bz, &p) return p } - -// SetLastTotalPower Set the last total validator power. -func (k Keeper) SetLastTotalPower(ctx sdk.Context, power sdkmath.Int) { - store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshal(&sdk.IntProto{Int: power}) - store.Set(types.DelegateKey, bz) -} - -func (k Keeper) GetLastTotalPower(ctx sdk.Context) sdkmath.Int { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.DelegateKey) - - if bz == nil { - return sdkmath.ZeroInt() - } - - ip := sdk.IntProto{} - k.cdc.MustUnmarshal(bz, &ip) - - return ip.Int -} - -func (k Keeper) SetDelegation(ctx sdk.Context, sourceDelegatorAddress, validatorAddress, denom string, amount sdkmath.Int) { - delegation := types.Delegation{DelegatorAddress: sourceDelegatorAddress, ValidatorAddress: validatorAddress, Amount: sdk.NewCoin(denom, amount)} - delegatorAddress := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) - - store := ctx.KVStore(k.storeKey) - b := k.cdc.MustMarshal(&delegation) - store.Set(types.GetDelegateKey(delegatorAddress, GetValidatorAddr(delegation)), b) -} - -func (k Keeper) SetBeginRedelegation(ctx sdk.Context, sourceDelegatorAddress, validatorSrcAddress, validatorDstAddress, denom string, amount sdkmath.Int) { - begindelegation := types.BeginRedelegate{DelegatorAddress: sourceDelegatorAddress, ValidatorSrcAddress: validatorSrcAddress, ValidatorDstAddress: validatorDstAddress, Amount: sdk.NewCoin(denom, amount)} - delegatorAddress := sdk.MustAccAddressFromBech32(begindelegation.DelegatorAddress) - - store := ctx.KVStore(k.storeKey) - b := k.cdc.MustMarshal(&begindelegation) - store.Set(types.GetBeginRedelegateKey(delegatorAddress, GetValidatorAddrFromStr(validatorSrcAddress)), b) -} - -func (k Keeper) SetUndelegation(ctx sdk.Context, sourceDelegatorAddress, validatorAddress, denom string, amount sdkmath.Int) { - undelegation := types.Undelegate{DelegatorAddress: sourceDelegatorAddress, ValidatorAddress: validatorAddress, Amount: sdk.NewCoin(denom, amount)} - delegatorAddress := sdk.MustAccAddressFromBech32(undelegation.DelegatorAddress) - - store := ctx.KVStore(k.storeKey) - b := k.cdc.MustMarshal(&undelegation) - store.Set(types.GetUndelegateKey(delegatorAddress, GetValidatorAddrFromStr(validatorAddress)), b) -} - -func (k Keeper) SetCancelUndelegation(ctx sdk.Context, sourceDelegatorAddress, validatorAddress, denom string, amount sdkmath.Int, height int64) { - undelegation := types.CancelUnbondingDelegation{DelegatorAddress: sourceDelegatorAddress, ValidatorAddress: validatorAddress, Amount: sdk.NewCoin(denom, amount), CreationHeight: height} - delegatorAddress := sdk.MustAccAddressFromBech32(undelegation.DelegatorAddress) - - store := ctx.KVStore(k.storeKey) - b := k.cdc.MustMarshal(&undelegation) - store.Set(types.GetCancelUnbondingDelegateKey(delegatorAddress, GetValidatorAddrFromStr(validatorAddress)), b) -} - -func (k Keeper) DequeueAllDelegation(ctx sdk.Context) (delegations []types.Delegation) { - store := ctx.KVStore(k.storeKey) - - delegationIterator := sdk.KVStorePrefixIterator(store, types.DelegateKey) - defer delegationIterator.Close() - - for ; delegationIterator.Valid(); delegationIterator.Next() { - delegation := types.Delegation{} - value := delegationIterator.Value() - k.cdc.MustUnmarshal(value, &delegation) - - delegations = append(delegations, delegation) - - store.Delete(delegationIterator.Key()) - } - - return delegations -} - -func (k Keeper) DequeueAllRedelegation(ctx sdk.Context) (redelegations []types.BeginRedelegate) { - store := ctx.KVStore(k.storeKey) - - redelegationIterator := sdk.KVStorePrefixIterator(store, types.BeginRedelegateKey) - defer redelegationIterator.Close() - - for ; redelegationIterator.Valid(); redelegationIterator.Next() { - redelegation := types.BeginRedelegate{} - value := redelegationIterator.Value() - k.cdc.MustUnmarshal(value, &redelegation) - - redelegations = append(redelegations, redelegation) - - store.Delete(redelegationIterator.Key()) - } - - return redelegations -} - -func (k Keeper) DequeueAllUndelegation(ctx sdk.Context) (undelegations []types.Undelegate) { - store := ctx.KVStore(k.storeKey) - - undelegationIterator := sdk.KVStorePrefixIterator(store, types.UndelegateKey) - defer undelegationIterator.Close() - - for ; undelegationIterator.Valid(); undelegationIterator.Next() { - undelegation := types.Undelegate{} - value := undelegationIterator.Value() - k.cdc.MustUnmarshal(value, &undelegation) - - undelegations = append(undelegations, undelegation) - - store.Delete(undelegationIterator.Key()) - } - - return undelegations -} - -func (k Keeper) DequeueAllCancelUnbondingDelegation(ctx sdk.Context) (undelegations []types.CancelUnbondingDelegation) { - store := ctx.KVStore(k.storeKey) - - cancelunbondingundelegationIterator := sdk.KVStorePrefixIterator(store, types.CancelUnbondingDelegationKey) - defer cancelunbondingundelegationIterator.Close() - - for ; cancelunbondingundelegationIterator.Valid(); cancelunbondingundelegationIterator.Next() { - cancelunbondingdelegation := types.CancelUnbondingDelegation{} - value := cancelunbondingundelegationIterator.Value() - k.cdc.MustUnmarshal(value, &cancelunbondingdelegation) - - undelegations = append(undelegations, cancelunbondingdelegation) - - store.Delete(cancelunbondingundelegationIterator.Key()) - } - return undelegations -} - -func GetValidatorAddrFromStr(d string) sdk.ValAddress { - addr, err := sdk.ValAddressFromBech32(d) - if err != nil { - panic(err) - } - return addr -} - -func GetValidatorAddr(d types.Delegation) sdk.ValAddress { - addr, err := sdk.ValAddressFromBech32(d.ValidatorAddress) - if err != nil { - panic(err) - } - return addr -} - -func UnmarshalBD(cdc codec.BinaryCodec, value []byte) (ubd types.Delegation, err error) { - err = cdc.Unmarshal(value, &ubd) - return ubd, err -} - -func MustUnmarshalUBD(cdc codec.BinaryCodec, value []byte) types.Delegation { - ubd, err := UnmarshalBD(cdc, value) - if err != nil { - panic(err) - } - - return ubd -} diff --git a/x/stakingmiddleware/keeper/msg_server.go b/x/stakingmiddleware/keeper/msg_server.go index 523b1610b..1d51b5da1 100644 --- a/x/stakingmiddleware/keeper/msg_server.go +++ b/x/stakingmiddleware/keeper/msg_server.go @@ -36,8 +36,3 @@ func (ms msgServer) UpdateEpochParams(goCtx context.Context, req *types.MsgUpdat return &types.MsgUpdateParamsEpochResponse{}, nil } - -// UpdateParams updates the params. -func (ms msgServer) SetPower(goCtx context.Context, req *types.MsgSetPower) (*types.MsgSetPowerResponse, error) { - return &types.MsgSetPowerResponse{}, nil -} diff --git a/x/stakingmiddleware/types/codec.go b/x/stakingmiddleware/types/codec.go index ed9bf475d..c8986807f 100644 --- a/x/stakingmiddleware/types/codec.go +++ b/x/stakingmiddleware/types/codec.go @@ -16,14 +16,12 @@ import ( // RegisterLegacyAminoCodec registers the account interfaces and concrete types on the // provided LegacyAmino codec. These types are used for Amino JSON serialization func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - legacy.RegisterAminoMsg(cdc, &MsgSetPower{}, "composable/MsgSetPower") legacy.RegisterAminoMsg(cdc, &MsgUpdateEpochParams{}, "composable/MsgUpdateEpochParams") } func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterImplementations( (*sdk.Msg)(nil), - &MsgSetPower{}, &MsgUpdateEpochParams{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/stakingmiddleware/types/genesis.go b/x/stakingmiddleware/types/genesis.go index 7557dfb64..fe53f6d29 100644 --- a/x/stakingmiddleware/types/genesis.go +++ b/x/stakingmiddleware/types/genesis.go @@ -1,23 +1,16 @@ package types -import ( - "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" -) - // NewGenesisState creates a new GenesisState object -func NewGenesisState(m math.Int, params Params) *GenesisState { +func NewGenesisState(params Params) *GenesisState { return &GenesisState{ - LastTotalPower: m, - Params: params, + Params: params, } } // DefaultGenesisState creates a default GenesisState object func DefaultGenesisState() *GenesisState { return &GenesisState{ - LastTotalPower: sdk.ZeroInt(), - Params: Params{BlocksPerEpoch: 10}, + Params: Params{BlocksPerEpoch: 10}, } } diff --git a/x/stakingmiddleware/types/genesis.pb.go b/x/stakingmiddleware/types/genesis.pb.go index 7cb2d3daa..56b0631be 100644 --- a/x/stakingmiddleware/types/genesis.pb.go +++ b/x/stakingmiddleware/types/genesis.pb.go @@ -5,7 +5,6 @@ package types import ( fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" @@ -27,15 +26,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the stakingmiddleware module's genesis state. type GenesisState struct { - // last_total_power tracks the total amounts of bonded tokens recorded during - // the previous end block. - LastTotalPower github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=last_total_power,json=lastTotalPower,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"last_total_power"` - Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` - // delegations defines the delegations active at genesis. - Delegations []Delegation `protobuf:"bytes,3,rep,name=delegations,proto3" json:"delegations"` - Begindelegations []BeginRedelegate `protobuf:"bytes,4,rep,name=begindelegations,proto3" json:"begindelegations"` - Undelegates []Undelegate `protobuf:"bytes,5,rep,name=undelegates,proto3" json:"undelegates"` - Cancelunbondingdelegations []CancelUnbondingDelegation `protobuf:"bytes,6,rep,name=cancelunbondingdelegations,proto3" json:"cancelunbondingdelegations"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -78,34 +69,6 @@ func (m *GenesisState) GetParams() Params { return Params{} } -func (m *GenesisState) GetDelegations() []Delegation { - if m != nil { - return m.Delegations - } - return nil -} - -func (m *GenesisState) GetBegindelegations() []BeginRedelegate { - if m != nil { - return m.Begindelegations - } - return nil -} - -func (m *GenesisState) GetUndelegates() []Undelegate { - if m != nil { - return m.Undelegates - } - return nil -} - -func (m *GenesisState) GetCancelunbondingdelegations() []CancelUnbondingDelegation { - if m != nil { - return m.Cancelunbondingdelegations - } - return nil -} - func init() { proto.RegisterType((*GenesisState)(nil), "centauri.stakingmiddleware.v1beta1.GenesisState") } @@ -115,33 +78,20 @@ func init() { } var fileDescriptor_1aa0bd912277c095 = []byte{ - // 404 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xc1, 0x8a, 0xd3, 0x40, - 0x18, 0x80, 0x33, 0x6e, 0x2d, 0x98, 0x2e, 0xb2, 0x06, 0x0f, 0xb1, 0x87, 0x6c, 0xd9, 0x83, 0x94, - 0x05, 0x27, 0xb6, 0xbd, 0x09, 0x5e, 0xa2, 0xa0, 0xde, 0x4a, 0xb4, 0x20, 0x7a, 0x28, 0x93, 0xe4, - 0x67, 0x1c, 0x9b, 0xcc, 0x84, 0xcc, 0xc4, 0xea, 0x1b, 0x78, 0xf4, 0x31, 0x3c, 0xfa, 0x18, 0x3d, - 0xf6, 0x28, 0x1e, 0x8a, 0x34, 0x07, 0x5f, 0x43, 0x66, 0x92, 0x4a, 0xa0, 0xc5, 0xcd, 0xa5, 0x0d, - 0x43, 0xbe, 0xef, 0xcb, 0x3f, 0xfc, 0xf6, 0xe3, 0x18, 0xb8, 0x22, 0x65, 0xc1, 0x7c, 0xa9, 0xc8, - 0x8a, 0x71, 0x9a, 0xb1, 0x24, 0x49, 0x61, 0x4d, 0x0a, 0xf0, 0x3f, 0x4d, 0x22, 0x50, 0x64, 0xe2, - 0x53, 0xe0, 0x20, 0x99, 0xc4, 0x79, 0x21, 0x94, 0x70, 0xae, 0x0e, 0x04, 0x3e, 0x22, 0x70, 0x43, - 0x0c, 0xef, 0x53, 0x41, 0x85, 0x79, 0xdd, 0xd7, 0x4f, 0x35, 0x39, 0x7c, 0xd2, 0xa1, 0x75, 0xec, - 0xac, 0xd9, 0x7b, 0x24, 0x63, 0x5c, 0xf8, 0xe6, 0xb7, 0x3e, 0xba, 0xaa, 0x7a, 0xf6, 0xf9, 0x8b, - 0xfa, 0xd3, 0x5e, 0x2b, 0xa2, 0xc0, 0x79, 0x6b, 0x5f, 0xa4, 0x44, 0xaa, 0xa5, 0x12, 0x8a, 0xa4, - 0xcb, 0x5c, 0xac, 0xa1, 0x70, 0xd1, 0x08, 0x8d, 0xcf, 0x03, 0xbc, 0xd9, 0x5d, 0x5a, 0xbf, 0x76, - 0x97, 0x0f, 0x29, 0x53, 0x1f, 0xca, 0x08, 0xc7, 0x22, 0xf3, 0x63, 0x21, 0x33, 0x21, 0x9b, 0xbf, - 0x47, 0x32, 0x59, 0xf9, 0xea, 0x4b, 0x0e, 0x12, 0xbf, 0xe2, 0x2a, 0xbc, 0xab, 0x3d, 0x6f, 0xb4, - 0x66, 0xae, 0x2d, 0xce, 0x4b, 0xbb, 0x9f, 0x93, 0x82, 0x64, 0xd2, 0xbd, 0x35, 0x42, 0xe3, 0xc1, - 0xf4, 0x1a, 0xdf, 0x7c, 0x09, 0x78, 0x6e, 0x88, 0xa0, 0xa7, 0xdb, 0x61, 0xc3, 0x3b, 0xef, 0xed, - 0x41, 0x02, 0x29, 0x50, 0xa2, 0x98, 0xe0, 0xd2, 0x3d, 0x1b, 0x9d, 0x8d, 0x07, 0x53, 0xdc, 0x45, - 0xf7, 0xfc, 0x1f, 0x16, 0xdc, 0xd1, 0xca, 0xef, 0x7f, 0x7e, 0x5c, 0xa3, 0xb0, 0x6d, 0x73, 0x3e, - 0xda, 0x17, 0x11, 0x50, 0xc6, 0xdb, 0x85, 0x9e, 0x29, 0xcc, 0xba, 0x14, 0x02, 0xcd, 0x86, 0xd0, - 0xd0, 0xd0, 0xce, 0x1c, 0x79, 0xf5, 0x20, 0xe5, 0xe1, 0x00, 0xa4, 0x7b, 0xbb, 0xfb, 0x20, 0x0b, - 0x7e, 0xaa, 0xd0, 0xb6, 0x39, 0x5f, 0x91, 0x3d, 0x8c, 0x09, 0x8f, 0x21, 0x2d, 0x79, 0x24, 0x78, - 0xc2, 0x38, 0x6d, 0xcf, 0xd4, 0x37, 0xb1, 0xa7, 0x5d, 0x62, 0xcf, 0x8c, 0x65, 0x71, 0xb0, 0x9c, - 0xbe, 0xc4, 0xff, 0xb4, 0x82, 0xd9, 0x66, 0xef, 0xa1, 0xed, 0xde, 0x43, 0xbf, 0xf7, 0x1e, 0xfa, - 0x56, 0x79, 0xd6, 0xb6, 0xf2, 0xac, 0x9f, 0x95, 0x67, 0xbd, 0x7b, 0xf0, 0xf9, 0xc4, 0x1e, 0x9b, - 0x1d, 0x8a, 0xfa, 0x66, 0x43, 0x67, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x66, 0xe2, 0x9b, 0xf3, - 0x5e, 0x03, 0x00, 0x00, + // 206 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x48, 0x4e, 0xcd, 0x2b, + 0x49, 0x2c, 0x2d, 0xca, 0xd4, 0x2f, 0x2e, 0x49, 0xcc, 0xce, 0xcc, 0x4b, 0xcf, 0xcd, 0x4c, 0x49, + 0xc9, 0x49, 0x2d, 0x4f, 0x2c, 0x4a, 0xd5, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x4f, + 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x82, 0xe9, + 0xd0, 0xc3, 0xd0, 0xa1, 0x07, 0xd5, 0x21, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xae, 0x0f, + 0x62, 0x41, 0x74, 0x4a, 0x59, 0x11, 0x61, 0x17, 0xa6, 0x99, 0x10, 0xbd, 0x82, 0x89, 0xb9, 0x99, + 0x79, 0xf9, 0xfa, 0x60, 0x12, 0x22, 0xa4, 0x14, 0xc1, 0xc5, 0xe3, 0x0e, 0x71, 0x59, 0x70, 0x49, + 0x62, 0x49, 0xaa, 0x90, 0x07, 0x17, 0x5b, 0x41, 0x62, 0x51, 0x62, 0x6e, 0xb1, 0x04, 0xa3, 0x02, + 0xa3, 0x06, 0xb7, 0x91, 0x96, 0x1e, 0x61, 0x97, 0xea, 0x05, 0x80, 0x75, 0x38, 0xb1, 0x9c, 0xb8, + 0x27, 0xcf, 0x10, 0x04, 0xd5, 0xef, 0x64, 0x7c, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, + 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, + 0x0c, 0x51, 0x92, 0x15, 0x58, 0xdc, 0x5e, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0x76, 0x95, + 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xdc, 0x25, 0x9a, 0xf8, 0x52, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -164,62 +114,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Cancelunbondingdelegations) > 0 { - for iNdEx := len(m.Cancelunbondingdelegations) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Cancelunbondingdelegations[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x32 - } - } - if len(m.Undelegates) > 0 { - for iNdEx := len(m.Undelegates) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Undelegates[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x2a - } - } - if len(m.Begindelegations) > 0 { - for iNdEx := len(m.Begindelegations) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Begindelegations[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - } - if len(m.Delegations) > 0 { - for iNdEx := len(m.Delegations) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Delegations[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } { size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -229,16 +123,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 - { - size := m.LastTotalPower.Size() - i -= size - if _, err := m.LastTotalPower.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -260,34 +144,8 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l - l = m.LastTotalPower.Size() - n += 1 + l + sovGenesis(uint64(l)) l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) - if len(m.Delegations) > 0 { - for _, e := range m.Delegations { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } - if len(m.Begindelegations) > 0 { - for _, e := range m.Begindelegations { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } - if len(m.Undelegates) > 0 { - for _, e := range m.Undelegates { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } - if len(m.Cancelunbondingdelegations) > 0 { - for _, e := range m.Cancelunbondingdelegations { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } return n } @@ -327,39 +185,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LastTotalPower", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.LastTotalPower.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) } @@ -392,142 +217,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Delegations", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Delegations = append(m.Delegations, Delegation{}) - if err := m.Delegations[len(m.Delegations)-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 Begindelegations", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Begindelegations = append(m.Begindelegations, BeginRedelegate{}) - if err := m.Begindelegations[len(m.Begindelegations)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Undelegates", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Undelegates = append(m.Undelegates, Undelegate{}) - if err := m.Undelegates[len(m.Undelegates)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Cancelunbondingdelegations", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Cancelunbondingdelegations = append(m.Cancelunbondingdelegations, CancelUnbondingDelegation{}) - if err := m.Cancelunbondingdelegations[len(m.Cancelunbondingdelegations)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/stakingmiddleware/types/keys.go b/x/stakingmiddleware/types/keys.go index 0e2edc734..dcaab0090 100644 --- a/x/stakingmiddleware/types/keys.go +++ b/x/stakingmiddleware/types/keys.go @@ -1,17 +1,8 @@ package types -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" -) - // MinterKey is the key to use for the keeper store. var ( - DelegateKey = []byte{0x01} // key for a delegation - BeginRedelegateKey = []byte{0x02} // key for a delegation - UndelegateKey = []byte{0x03} // key for a delegation - CancelUnbondingDelegationKey = []byte{0x04} // key for a delegation - ParamsKey = []byte{0x05} // key for global staking middleware params in the keeper store + ParamsKey = []byte{0x01} // key for global staking middleware params in the keeper store ) const ( @@ -22,37 +13,3 @@ const ( StoreKey = "customstmiddleware" // not using the module name because of collisions with key "ibc" ) - -// GetDelegateKey creates the key for delegator bond with validator -// VALUE: staking/Delegation -func GetDelegateKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte { - return append(DelegationKey(delAddr), address.MustLengthPrefix(valAddr)...) -} - -func DelegationKey(delAddr sdk.AccAddress) []byte { - return append(DelegateKey, address.MustLengthPrefix(delAddr)...) -} - -func GetBeginRedelegateKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte { - return append(BeginRedelegationsKey(delAddr), address.MustLengthPrefix(valAddr)...) -} - -func BeginRedelegationsKey(delAddr sdk.AccAddress) []byte { - return append(BeginRedelegateKey, address.MustLengthPrefix(delAddr)...) -} - -func GetUndelegateKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte { - return append(UndelegateionKey(delAddr), address.MustLengthPrefix(valAddr)...) -} - -func UndelegateionKey(delAddr sdk.AccAddress) []byte { - return append(UndelegateKey, address.MustLengthPrefix(delAddr)...) -} - -func GetCancelUnbondingDelegateKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte { - return append(CancelUnbondingDelegateKey(delAddr), address.MustLengthPrefix(valAddr)...) -} - -func CancelUnbondingDelegateKey(delAddr sdk.AccAddress) []byte { - return append(CancelUnbondingDelegationKey, address.MustLengthPrefix(delAddr)...) -} diff --git a/x/stakingmiddleware/types/msg.go b/x/stakingmiddleware/types/msg.go deleted file mode 100644 index 4f182b9a2..000000000 --- a/x/stakingmiddleware/types/msg.go +++ /dev/null @@ -1,44 +0,0 @@ -package types - -import ( - errorsmod "cosmossdk.io/errors" - "github.com/cosmos/cosmos-sdk/codec/legacy" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -var _ sdk.Msg = &MsgSetPower{} - -// Route Implements Msg. -func (m MsgSetPower) Route() string { return sdk.MsgTypeURL(&m) } - -// Type Implements Msg. -func (m MsgSetPower) Type() string { return sdk.MsgTypeURL(&m) } - -// GetSigners returns the expected signers for a MsgMintAndAllocateExp . -func (m MsgSetPower) GetSigners() []sdk.AccAddress { - daoAccount, err := sdk.AccAddressFromBech32(m.FromAddress) - if err != nil { - panic(err) - } - return []sdk.AccAddress{daoAccount} -} - -// GetSignBytes Implements Msg. -func (m MsgSetPower) GetSignBytes() []byte { - return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) -} - -// ValidateBasic does a sanity check on the provided data. -func (m MsgSetPower) ValidateBasic() error { - _, err := sdk.AccAddressFromBech32(m.FromAddress) - if err != nil { - return errorsmod.Wrap(err, "from address must be valid address") - } - return nil -} - -func NewMsgSetPower(fromAddr sdk.AccAddress) *MsgSetPower { - return &MsgSetPower{ - FromAddress: fromAddr.String(), - } -} diff --git a/x/stakingmiddleware/types/query.pb.go b/x/stakingmiddleware/types/query.pb.go index 4314b7bbe..772706fc6 100644 --- a/x/stakingmiddleware/types/query.pb.go +++ b/x/stakingmiddleware/types/query.pb.go @@ -30,21 +30,21 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // QueryParamsRequest is the request type for the Query/Params RPC method. -type QueryPowerRequest struct { +type QueryParamsRequest struct { } -func (m *QueryPowerRequest) Reset() { *m = QueryPowerRequest{} } -func (m *QueryPowerRequest) String() string { return proto.CompactTextString(m) } -func (*QueryPowerRequest) ProtoMessage() {} -func (*QueryPowerRequest) Descriptor() ([]byte, []int) { +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { return fileDescriptor_81a7c3c637f3f95a, []int{0} } -func (m *QueryPowerRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryPowerRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryPowerRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -54,34 +54,36 @@ func (m *QueryPowerRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, e return b[:n], nil } } -func (m *QueryPowerRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryPowerRequest.Merge(m, src) +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) } -func (m *QueryPowerRequest) XXX_Size() int { +func (m *QueryParamsRequest) XXX_Size() int { return m.Size() } -func (m *QueryPowerRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryPowerRequest.DiscardUnknown(m) +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryPowerRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo // QueryParamsResponse is the response type for the Query/Params RPC method. -type QueryPowerResponse struct { +type QueryParamsResponse struct { + // params defines the parameters of the module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` } -func (m *QueryPowerResponse) Reset() { *m = QueryPowerResponse{} } -func (m *QueryPowerResponse) String() string { return proto.CompactTextString(m) } -func (*QueryPowerResponse) ProtoMessage() {} -func (*QueryPowerResponse) Descriptor() ([]byte, []int) { +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { return fileDescriptor_81a7c3c637f3f95a, []int{1} } -func (m *QueryPowerResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryPowerResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryPowerResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -91,21 +93,28 @@ func (m *QueryPowerResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } -func (m *QueryPowerResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryPowerResponse.Merge(m, src) +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) } -func (m *QueryPowerResponse) XXX_Size() int { +func (m *QueryParamsResponse) XXX_Size() int { return m.Size() } -func (m *QueryPowerResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryPowerResponse.DiscardUnknown(m) +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryPowerResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} func init() { - proto.RegisterType((*QueryPowerRequest)(nil), "centauri.stakingmiddleware.v1beta1.QueryPowerRequest") - proto.RegisterType((*QueryPowerResponse)(nil), "centauri.stakingmiddleware.v1beta1.QueryPowerResponse") + proto.RegisterType((*QueryParamsRequest)(nil), "centauri.stakingmiddleware.v1beta1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "centauri.stakingmiddleware.v1beta1.QueryParamsResponse") } func init() { @@ -113,23 +122,26 @@ func init() { } var fileDescriptor_81a7c3c637f3f95a = []byte{ - // 250 bytes of a gzipped FileDescriptorProto + // 290 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4b, 0x4e, 0xcd, 0x2b, 0x49, 0x2c, 0x2d, 0xca, 0xd4, 0x2f, 0x2e, 0x49, 0xcc, 0xce, 0xcc, 0x4b, 0xcf, 0xcd, 0x4c, 0x49, 0xc9, 0x49, 0x2d, 0x4f, 0x2c, 0x4a, 0xd5, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x82, 0xa9, 0xd7, 0xc3, 0x50, 0xaf, 0x07, 0x55, 0x2f, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xae, 0x0f, 0x62, 0x41, 0x74, 0x4a, 0xc9, 0xa4, 0xe7, 0xe7, 0xa7, 0xe7, 0xa4, 0xea, 0x27, 0x16, 0x64, 0xea, 0x27, 0xe6, - 0xe5, 0xe5, 0x97, 0x24, 0x96, 0x64, 0xe6, 0xe7, 0x15, 0x43, 0x64, 0x95, 0x84, 0xb9, 0x04, 0x03, - 0x41, 0xd6, 0x04, 0xe4, 0x97, 0xa7, 0x16, 0x05, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x28, 0x89, - 0x70, 0x09, 0x21, 0x0b, 0x16, 0x17, 0xe4, 0xe7, 0x15, 0xa7, 0x1a, 0x6d, 0x62, 0xe4, 0x62, 0x05, - 0x0b, 0x0b, 0xad, 0x60, 0xe4, 0x62, 0x05, 0xcb, 0x09, 0x99, 0xea, 0x11, 0x76, 0x97, 0x1e, 0x86, - 0x05, 0x52, 0x66, 0xa4, 0x6a, 0x83, 0x38, 0x41, 0xc9, 0xa0, 0xe9, 0xf2, 0x93, 0xc9, 0x4c, 0x5a, - 0x42, 0x1a, 0xfa, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0x78, 0x02, 0xaf, 0x20, 0xb1, 0x28, 0x31, - 0xb7, 0xd8, 0xc9, 0xf8, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, - 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x24, 0x2b, - 0xb0, 0xe8, 0x2e, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x87, 0x8d, 0x31, 0x20, 0x00, 0x00, - 0xff, 0xff, 0x00, 0x00, 0x72, 0xbe, 0xa5, 0x01, 0x00, 0x00, + 0xe5, 0xe5, 0x97, 0x24, 0x96, 0x64, 0xe6, 0xe7, 0x15, 0x43, 0x65, 0xad, 0x88, 0x70, 0x07, 0xa6, + 0x8d, 0x60, 0xbd, 0x4a, 0x22, 0x5c, 0x42, 0x81, 0x20, 0x27, 0x06, 0x24, 0x16, 0x25, 0xe6, 0x16, + 0x07, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x28, 0xc5, 0x73, 0x09, 0xa3, 0x88, 0x16, 0x17, 0xe4, + 0xe7, 0x15, 0xa7, 0x0a, 0x79, 0x70, 0xb1, 0x15, 0x80, 0x45, 0x24, 0x18, 0x15, 0x18, 0x35, 0xb8, + 0x8d, 0xb4, 0xf4, 0x08, 0xfb, 0x48, 0x0f, 0x62, 0x86, 0x13, 0xcb, 0x89, 0x7b, 0xf2, 0x0c, 0x41, + 0x50, 0xfd, 0x46, 0x2b, 0x18, 0xb9, 0x58, 0xc1, 0x36, 0x08, 0xcd, 0x63, 0xe4, 0x62, 0x83, 0x28, + 0x11, 0x32, 0x23, 0xc6, 0x38, 0x4c, 0xd7, 0x4a, 0x99, 0x93, 0xac, 0x0f, 0xe2, 0x1f, 0x25, 0xe5, + 0xa6, 0xcb, 0x4f, 0x26, 0x33, 0xc9, 0x0a, 0x49, 0xeb, 0x27, 0xe7, 0x17, 0xe7, 0xe6, 0x17, 0xeb, + 0xe7, 0x66, 0xe6, 0x95, 0xc0, 0x83, 0x0c, 0xe2, 0x54, 0x27, 0xe3, 0x13, 0x8f, 0xe4, 0x18, 0x2f, + 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, + 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x92, 0xac, 0xc0, 0x12, 0xe0, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, + 0x6c, 0xe0, 0xd0, 0x35, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x9c, 0xf8, 0x2d, 0x7d, 0x23, 0x02, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -145,7 +157,7 @@ const _ = grpc.SupportPackageIsVersion4 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { // Params returns the total set of minting parameters. - Power(ctx context.Context, in *QueryPowerRequest, opts ...grpc.CallOption) (*QueryPowerResponse, error) + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) } type queryClient struct { @@ -156,9 +168,9 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { return &queryClient{cc} } -func (c *queryClient) Power(ctx context.Context, in *QueryPowerRequest, opts ...grpc.CallOption) (*QueryPowerResponse, error) { - out := new(QueryPowerResponse) - err := c.cc.Invoke(ctx, "/centauri.stakingmiddleware.v1beta1.Query/Power", in, out, opts...) +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/centauri.stakingmiddleware.v1beta1.Query/Params", in, out, opts...) if err != nil { return nil, err } @@ -168,35 +180,35 @@ func (c *queryClient) Power(ctx context.Context, in *QueryPowerRequest, opts ... // QueryServer is the server API for Query service. type QueryServer interface { // Params returns the total set of minting parameters. - Power(context.Context, *QueryPowerRequest) (*QueryPowerResponse, error) + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. type UnimplementedQueryServer struct { } -func (*UnimplementedQueryServer) Power(ctx context.Context, req *QueryPowerRequest) (*QueryPowerResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Power not implemented") +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) } -func _Query_Power_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryPowerRequest) +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).Power(ctx, in) + return srv.(QueryServer).Params(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/centauri.stakingmiddleware.v1beta1.Query/Power", + FullMethod: "/centauri.stakingmiddleware.v1beta1.Query/Params", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Power(ctx, req.(*QueryPowerRequest)) + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) } return interceptor(ctx, in, info, handler) } @@ -206,15 +218,15 @@ var _Query_serviceDesc = grpc.ServiceDesc{ HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "Power", - Handler: _Query_Power_Handler, + MethodName: "Params", + Handler: _Query_Params_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "centauri/stakingmiddleware/v1beta1/query.proto", } -func (m *QueryPowerRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -224,12 +236,12 @@ func (m *QueryPowerRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryPowerRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryPowerRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -237,7 +249,7 @@ func (m *QueryPowerRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryPowerResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -247,16 +259,26 @@ func (m *QueryPowerResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryPowerResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryPowerResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -271,7 +293,7 @@ func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *QueryPowerRequest) Size() (n int) { +func (m *QueryParamsRequest) Size() (n int) { if m == nil { return 0 } @@ -280,12 +302,14 @@ func (m *QueryPowerRequest) Size() (n int) { return n } -func (m *QueryPowerResponse) Size() (n int) { +func (m *QueryParamsResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) return n } @@ -295,7 +319,7 @@ func sovQuery(x uint64) (n int) { func sozQuery(x uint64) (n int) { return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *QueryPowerRequest) Unmarshal(dAtA []byte) error { +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -318,10 +342,10 @@ func (m *QueryPowerRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryPowerRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryPowerRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: @@ -345,7 +369,7 @@ func (m *QueryPowerRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryPowerResponse) Unmarshal(dAtA []byte) error { +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -368,12 +392,45 @@ func (m *QueryPowerResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryPowerResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryPowerResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/stakingmiddleware/types/query.pb.gw.go b/x/stakingmiddleware/types/query.pb.gw.go index fdb182ad2..e7c79699d 100644 --- a/x/stakingmiddleware/types/query.pb.gw.go +++ b/x/stakingmiddleware/types/query.pb.gw.go @@ -33,20 +33,20 @@ var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage var _ = metadata.Join -func request_Query_Power_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryPowerRequest +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest var metadata runtime.ServerMetadata - msg, err := client.Power(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_Power_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryPowerRequest +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest var metadata runtime.ServerMetadata - msg, err := server.Power(ctx, &protoReq) + msg, err := server.Params(ctx, &protoReq) return msg, metadata, err } @@ -57,7 +57,7 @@ func local_request_Query_Power_0(ctx context.Context, marshaler runtime.Marshale // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { - mux.Handle("GET", pattern_Query_Power_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -68,7 +68,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_Power_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -76,7 +76,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_Power_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -121,7 +121,7 @@ func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc // "QueryClient" to call the correct interceptors. func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { - mux.Handle("GET", pattern_Query_Power_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -130,14 +130,14 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_Power_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_Power_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -145,9 +145,9 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_Power_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "stakingmiddleware", "v1beta1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "mint", "v1beta1", "params"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( - forward_Query_Power_0 = runtime.ForwardResponseMessage + forward_Query_Params_0 = runtime.ForwardResponseMessage ) diff --git a/x/stakingmiddleware/types/tx.pb.go b/x/stakingmiddleware/types/tx.pb.go index 189e21a45..a3f3ad136 100644 --- a/x/stakingmiddleware/types/tx.pb.go +++ b/x/stakingmiddleware/types/tx.pb.go @@ -31,93 +31,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// MsgSetPower is the Msg/SetPower request type. -// -// Since: cosmos-sdk 0.47 -type MsgSetPower struct { - FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty"` -} - -func (m *MsgSetPower) Reset() { *m = MsgSetPower{} } -func (m *MsgSetPower) String() string { return proto.CompactTextString(m) } -func (*MsgSetPower) ProtoMessage() {} -func (*MsgSetPower) Descriptor() ([]byte, []int) { - return fileDescriptor_d15665ac9877b062, []int{0} -} -func (m *MsgSetPower) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgSetPower) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgSetPower.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 *MsgSetPower) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgSetPower.Merge(m, src) -} -func (m *MsgSetPower) XXX_Size() int { - return m.Size() -} -func (m *MsgSetPower) XXX_DiscardUnknown() { - xxx_messageInfo_MsgSetPower.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgSetPower proto.InternalMessageInfo - -func (m *MsgSetPower) GetFromAddress() string { - if m != nil { - return m.FromAddress - } - return "" -} - -// MsgSetPowerResponse defines the response structure for executing a -// MsgSetPower message. -// -// Since: cosmos-sdk 0.47 -type MsgSetPowerResponse struct { -} - -func (m *MsgSetPowerResponse) Reset() { *m = MsgSetPowerResponse{} } -func (m *MsgSetPowerResponse) String() string { return proto.CompactTextString(m) } -func (*MsgSetPowerResponse) ProtoMessage() {} -func (*MsgSetPowerResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d15665ac9877b062, []int{1} -} -func (m *MsgSetPowerResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgSetPowerResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgSetPowerResponse.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 *MsgSetPowerResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgSetPowerResponse.Merge(m, src) -} -func (m *MsgSetPowerResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgSetPowerResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgSetPowerResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgSetPowerResponse proto.InternalMessageInfo - // MsgUpdateParams is the Msg/UpdateParams request type. // // Since: cosmos-sdk 0.47 @@ -135,7 +48,7 @@ func (m *MsgUpdateEpochParams) Reset() { *m = MsgUpdateEpochParams{} } func (m *MsgUpdateEpochParams) String() string { return proto.CompactTextString(m) } func (*MsgUpdateEpochParams) ProtoMessage() {} func (*MsgUpdateEpochParams) Descriptor() ([]byte, []int) { - return fileDescriptor_d15665ac9877b062, []int{2} + return fileDescriptor_d15665ac9877b062, []int{0} } func (m *MsgUpdateEpochParams) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -189,7 +102,7 @@ func (m *MsgUpdateParamsEpochResponse) Reset() { *m = MsgUpdateParamsEpo func (m *MsgUpdateParamsEpochResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdateParamsEpochResponse) ProtoMessage() {} func (*MsgUpdateParamsEpochResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d15665ac9877b062, []int{3} + return fileDescriptor_d15665ac9877b062, []int{1} } func (m *MsgUpdateParamsEpochResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -219,8 +132,6 @@ func (m *MsgUpdateParamsEpochResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateParamsEpochResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*MsgSetPower)(nil), "centauri.stakingmiddleware.v1beta1.MsgSetPower") - proto.RegisterType((*MsgSetPowerResponse)(nil), "centauri.stakingmiddleware.v1beta1.MsgSetPowerResponse") proto.RegisterType((*MsgUpdateEpochParams)(nil), "centauri.stakingmiddleware.v1beta1.MsgUpdateEpochParams") proto.RegisterType((*MsgUpdateParamsEpochResponse)(nil), "centauri.stakingmiddleware.v1beta1.MsgUpdateParamsEpochResponse") } @@ -230,7 +141,7 @@ func init() { } var fileDescriptor_d15665ac9877b062 = []byte{ - // 422 bytes of a gzipped FileDescriptorProto + // 360 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4e, 0x4e, 0xcd, 0x2b, 0x49, 0x2c, 0x2d, 0xca, 0xd4, 0x2f, 0x2e, 0x49, 0xcc, 0xce, 0xcc, 0x4b, 0xcf, 0xcd, 0x4c, 0x49, 0xc9, 0x49, 0x2d, 0x4f, 0x2c, 0x4a, 0xd5, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x2f, @@ -238,26 +149,22 @@ var fileDescriptor_d15665ac9877b062 = []byte{ 0x55, 0x2c, 0x25, 0x9e, 0x9c, 0x5f, 0x9c, 0x9b, 0x5f, 0xac, 0x9f, 0x5b, 0x9c, 0xae, 0x5f, 0x66, 0x08, 0xa2, 0x20, 0x9a, 0xa5, 0x04, 0x13, 0x73, 0x33, 0xf3, 0xf2, 0xf5, 0xc1, 0x24, 0x54, 0x48, 0x24, 0x3d, 0x3f, 0x3d, 0x1f, 0xcc, 0xd4, 0x07, 0xb1, 0xa0, 0xa2, 0x92, 0x10, 0x13, 0xe2, 0x21, - 0x12, 0x10, 0x0e, 0x54, 0xca, 0x8a, 0x08, 0xd7, 0x62, 0x3a, 0x0d, 0xac, 0x57, 0xc9, 0x80, 0x8b, - 0xdb, 0xb7, 0x38, 0x3d, 0x38, 0xb5, 0x24, 0x20, 0xbf, 0x3c, 0xb5, 0x48, 0x48, 0x91, 0x8b, 0x27, - 0xad, 0x28, 0x3f, 0x37, 0x3e, 0x31, 0x25, 0xa5, 0x28, 0xb5, 0xb8, 0x58, 0x82, 0x51, 0x81, 0x51, - 0x83, 0x33, 0x88, 0x1b, 0x24, 0xe6, 0x08, 0x11, 0x52, 0x12, 0xe5, 0x12, 0x46, 0xd2, 0x11, 0x94, - 0x5a, 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0xaa, 0x74, 0x8f, 0x91, 0x4b, 0xc4, 0xb7, 0x38, 0x3d, 0xb4, - 0x20, 0x25, 0xb1, 0x24, 0xd5, 0xb5, 0x20, 0x3f, 0x39, 0x23, 0x20, 0xb1, 0x28, 0x31, 0xb7, 0x58, - 0xc8, 0x8c, 0x8b, 0x33, 0xb1, 0xb4, 0x24, 0x23, 0xbf, 0x28, 0xb3, 0xa4, 0x12, 0x62, 0x9e, 0x93, - 0xc4, 0xa5, 0x2d, 0xba, 0x22, 0x50, 0x2f, 0x40, 0x8d, 0x0d, 0x2e, 0x29, 0xca, 0xcc, 0x4b, 0x0f, - 0x42, 0x28, 0x15, 0xf2, 0xe5, 0x62, 0x2b, 0x00, 0x9b, 0x20, 0xc1, 0xa4, 0xc0, 0xa8, 0xc1, 0x6d, - 0xa4, 0xa5, 0x47, 0x38, 0x9c, 0xf5, 0x20, 0x76, 0x3a, 0x71, 0x9e, 0xb8, 0x27, 0xcf, 0xb0, 0xe2, - 0xf9, 0x06, 0x2d, 0xc6, 0x20, 0xa8, 0x21, 0x56, 0xf6, 0x4d, 0xcf, 0x37, 0x68, 0x21, 0x8c, 0xef, - 0x7a, 0xbe, 0x41, 0x4b, 0x07, 0x1e, 0x6e, 0x15, 0x58, 0x42, 0x0e, 0xee, 0x19, 0x88, 0x99, 0x4a, - 0x72, 0x5c, 0x32, 0x68, 0x42, 0x60, 0x5f, 0xc2, 0x02, 0xc0, 0x68, 0x0a, 0x13, 0x17, 0xb3, 0x6f, - 0x71, 0xba, 0x50, 0x3f, 0x23, 0x97, 0x20, 0x66, 0x28, 0x58, 0x10, 0xe3, 0x7a, 0x6c, 0xe1, 0x27, - 0xe5, 0x40, 0x92, 0x4e, 0x2c, 0x2e, 0x13, 0x2a, 0xe1, 0xe2, 0x80, 0x47, 0xb0, 0x3e, 0x91, 0xa6, - 0xc1, 0x34, 0x48, 0x99, 0x93, 0xa8, 0x01, 0x66, 0xab, 0x14, 0x6b, 0x03, 0x28, 0xfc, 0x9d, 0x8c, - 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, - 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x12, 0x5b, 0xa8, 0x97, 0x54, - 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x13, 0xa7, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x78, 0x25, - 0x34, 0xad, 0x88, 0x03, 0x00, 0x00, + 0x12, 0x10, 0x0e, 0x54, 0xca, 0x8a, 0x08, 0xd7, 0x62, 0x3a, 0x0d, 0xac, 0x57, 0xe9, 0x1e, 0x23, + 0x97, 0x88, 0x6f, 0x71, 0x7a, 0x68, 0x41, 0x4a, 0x62, 0x49, 0xaa, 0x6b, 0x41, 0x7e, 0x72, 0x46, + 0x40, 0x62, 0x51, 0x62, 0x6e, 0xb1, 0x90, 0x19, 0x17, 0x67, 0x62, 0x69, 0x49, 0x46, 0x7e, 0x51, + 0x66, 0x49, 0xa5, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xa7, 0x93, 0xc4, 0xa5, 0x2d, 0xba, 0x22, 0x50, + 0x9b, 0x1d, 0x53, 0x52, 0x8a, 0x52, 0x8b, 0x8b, 0x83, 0x4b, 0x8a, 0x32, 0xf3, 0xd2, 0x83, 0x10, + 0x4a, 0x85, 0x7c, 0xb9, 0xd8, 0x0a, 0xc0, 0x26, 0x48, 0x30, 0x29, 0x30, 0x6a, 0x70, 0x1b, 0x69, + 0xe9, 0x11, 0x0e, 0x1e, 0x3d, 0x88, 0x9d, 0x4e, 0x9c, 0x27, 0xee, 0xc9, 0x33, 0xac, 0x78, 0xbe, + 0x41, 0x8b, 0x31, 0x08, 0x6a, 0x88, 0x95, 0x7d, 0xd3, 0xf3, 0x0d, 0x5a, 0x08, 0xe3, 0xbb, 0x9e, + 0x6f, 0xd0, 0xd2, 0x81, 0x7b, 0xb7, 0x02, 0x8b, 0x87, 0xe1, 0x9e, 0x81, 0x98, 0xa9, 0x24, 0xc7, + 0x25, 0x83, 0x26, 0x04, 0xf6, 0x65, 0x50, 0x6a, 0x71, 0x41, 0x7e, 0x5e, 0x71, 0xaa, 0xd1, 0x3c, + 0x46, 0x2e, 0x66, 0xdf, 0xe2, 0x74, 0xa1, 0x7e, 0x46, 0x2e, 0x41, 0xcc, 0x50, 0xb0, 0x20, 0xc6, + 0xf5, 0xd8, 0xc2, 0x4f, 0xca, 0x81, 0x24, 0x9d, 0x58, 0x5c, 0x26, 0xc5, 0xda, 0x00, 0x0a, 0x09, + 0x27, 0xe3, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, + 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x92, 0xc4, 0xe6, 0xff, + 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0x70, 0xec, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, + 0x89, 0xbf, 0x82, 0x72, 0xc9, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -273,7 +180,6 @@ const _ = grpc.SupportPackageIsVersion4 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { UpdateEpochParams(ctx context.Context, in *MsgUpdateEpochParams, opts ...grpc.CallOption) (*MsgUpdateParamsEpochResponse, error) - SetPower(ctx context.Context, in *MsgSetPower, opts ...grpc.CallOption) (*MsgSetPowerResponse, error) } type msgClient struct { @@ -293,19 +199,9 @@ func (c *msgClient) UpdateEpochParams(ctx context.Context, in *MsgUpdateEpochPar return out, nil } -func (c *msgClient) SetPower(ctx context.Context, in *MsgSetPower, opts ...grpc.CallOption) (*MsgSetPowerResponse, error) { - out := new(MsgSetPowerResponse) - err := c.cc.Invoke(ctx, "/centauri.stakingmiddleware.v1beta1.Msg/SetPower", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - // MsgServer is the server API for Msg service. type MsgServer interface { UpdateEpochParams(context.Context, *MsgUpdateEpochParams) (*MsgUpdateParamsEpochResponse, error) - SetPower(context.Context, *MsgSetPower) (*MsgSetPowerResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -315,9 +211,6 @@ type UnimplementedMsgServer struct { func (*UnimplementedMsgServer) UpdateEpochParams(ctx context.Context, req *MsgUpdateEpochParams) (*MsgUpdateParamsEpochResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateEpochParams not implemented") } -func (*UnimplementedMsgServer) SetPower(ctx context.Context, req *MsgSetPower) (*MsgSetPowerResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method SetPower not implemented") -} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -341,24 +234,6 @@ func _Msg_UpdateEpochParams_Handler(srv interface{}, ctx context.Context, dec fu return interceptor(ctx, in, info, handler) } -func _Msg_SetPower_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgSetPower) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).SetPower(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/centauri.stakingmiddleware.v1beta1.Msg/SetPower", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).SetPower(ctx, req.(*MsgSetPower)) - } - return interceptor(ctx, in, info, handler) -} - var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "centauri.stakingmiddleware.v1beta1.Msg", HandlerType: (*MsgServer)(nil), @@ -367,68 +242,11 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "UpdateEpochParams", Handler: _Msg_UpdateEpochParams_Handler, }, - { - MethodName: "SetPower", - Handler: _Msg_SetPower_Handler, - }, }, Streams: []grpc.StreamDesc{}, Metadata: "centauri/stakingmiddleware/v1beta1/tx.proto", } -func (m *MsgSetPower) 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 *MsgSetPower) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgSetPower) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.FromAddress) > 0 { - i -= len(m.FromAddress) - copy(dAtA[i:], m.FromAddress) - i = encodeVarintTx(dAtA, i, uint64(len(m.FromAddress))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *MsgSetPowerResponse) 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 *MsgSetPowerResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgSetPowerResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - func (m *MsgUpdateEpochParams) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -503,28 +321,6 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *MsgSetPower) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.FromAddress) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - return n -} - -func (m *MsgSetPowerResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - func (m *MsgUpdateEpochParams) Size() (n int) { if m == nil { return 0 @@ -555,138 +351,6 @@ func sovTx(x uint64) (n int) { func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *MsgSetPower) 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 ErrIntOverflowTx - } - 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: MsgSetPower: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgSetPower: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FromAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - 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 ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.FromAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgSetPowerResponse) 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 ErrIntOverflowTx - } - 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: MsgSetPowerResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgSetPowerResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *MsgUpdateEpochParams) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0