From db3accbbd949ad3d90938e3b253cb228f5351b57 Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Thu, 3 Aug 2023 14:02:31 -0400 Subject: [PATCH] refactor(proto): use slices instead of maps hashmap might be a cause of inconsistent AppHash Signed-off-by: Artur Troian --- go/node/deployment/v1beta3/params.go | 39 +- go/node/deployment/v1beta3/params.pb.go | 162 ++------ go/node/take/v1beta3/denom_take_rate.go | 21 + go/node/take/v1beta3/params.go | 32 +- go/node/take/v1beta3/params.pb.go | 374 ++++++++++++------ .../akash/deployment/v1beta3/params.proto | 14 +- proto/node/akash/take/v1beta3/params.proto | 25 +- 7 files changed, 382 insertions(+), 285 deletions(-) create mode 100644 go/node/take/v1beta3/denom_take_rate.go diff --git a/go/node/deployment/v1beta3/params.go b/go/node/deployment/v1beta3/params.go index 08ef50e3..01b36b9a 100644 --- a/go/node/deployment/v1beta3/params.go +++ b/go/node/deployment/v1beta3/params.go @@ -1,7 +1,8 @@ package v1beta3 import ( - math "math" + "fmt" + "math" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -26,8 +27,8 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { func DefaultParams() Params { return Params{ - MinDeposits: map[string]uint32{ - "uakt": 5000000, + MinDeposits: sdk.Coins{ + sdk.NewCoin("uakt", sdk.NewInt(5000000)), }, } } @@ -54,27 +55,37 @@ func (p Params) ValidateDeposit(amt sdk.Coin) error { } func (p Params) MinDepositFor(denom string) (sdk.Coin, error) { - val, ok := p.MinDeposits[denom] - if !ok { - return sdk.NewInt64Coin(denom, math.MaxInt64), errors.Wrapf(ErrInvalidDeposit, "Invalid deposit denomination %v", denom) + for _, minDeposit := range p.MinDeposits { + if minDeposit.Denom == denom { + return sdk.NewCoin(minDeposit.Denom, minDeposit.Amount), nil + } } - return sdk.NewCoin(denom, sdk.NewInt(int64(val))), nil + + return sdk.NewInt64Coin(denom, math.MaxInt64), errors.Wrapf(ErrInvalidDeposit, "Invalid deposit denomination %v", denom) } func validateMinDeposits(i interface{}) error { - vals, ok := i.(map[string]uint32) + vals, ok := i.(sdk.Coins) if !ok { return errors.Wrapf(ErrInvalidParam, "Min Deposits - invalid type: %T", i) } - if _, ok := vals["uakt"]; !ok { - return errors.Wrapf(ErrInvalidParam, "Min Deposits - uakt not given: %#v", vals) - } + check := make(map[string]bool) - for denom, val := range vals { - if val >= math.MaxInt32 { - return errors.Wrapf(ErrInvalidParam, "Min Deposit (%v) - too large: %v", denom, val) + for _, minDeposit := range vals { + if _, exists := check[minDeposit.Denom]; exists { + return fmt.Errorf("duplicate Min Deposit for denom (%#v)", minDeposit) } + + check[minDeposit.Denom] = true + + if minDeposit.Amount.Uint64() >= math.MaxInt32 { + return errors.Wrapf(ErrInvalidParam, "Min Deposit (%v) - too large: %v", minDeposit.Denom, minDeposit.Amount.Uint64()) + } + } + + if _, exists := check["uakt"]; !exists { + return errors.Wrapf(ErrInvalidParam, "Min Deposits - uakt not given: %#v", vals) } return nil diff --git a/go/node/deployment/v1beta3/params.pb.go b/go/node/deployment/v1beta3/params.pb.go index ca51a0e9..087b5ab5 100644 --- a/go/node/deployment/v1beta3/params.pb.go +++ b/go/node/deployment/v1beta3/params.pb.go @@ -5,6 +5,8 @@ package v1beta3 import ( fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -25,8 +27,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the x/deployment package type Params struct { - // denom -> min deposit - MinDeposits map[string]uint32 `protobuf:"bytes,1,rep,name=min_deposits,json=minDeposits,proto3" json:"min_deposits" yaml:"min_deposits" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + MinDeposits github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=min_deposits,json=minDeposits,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"min_deposits" yaml:"min_deposits"` } func (m *Params) Reset() { *m = Params{} } @@ -62,7 +63,7 @@ func (m *Params) XXX_DiscardUnknown() { var xxx_messageInfo_Params proto.InternalMessageInfo -func (m *Params) GetMinDeposits() map[string]uint32 { +func (m *Params) GetMinDeposits() github_com_cosmos_cosmos_sdk_types.Coins { if m != nil { return m.MinDeposits } @@ -71,7 +72,6 @@ func (m *Params) GetMinDeposits() map[string]uint32 { func init() { proto.RegisterType((*Params)(nil), "akash.deployment.v1beta3.Params") - proto.RegisterMapType((map[string]uint32)(nil), "akash.deployment.v1beta3.Params.MinDepositsEntry") } func init() { @@ -79,26 +79,26 @@ func init() { } var fileDescriptor_9a677e8b392d6c91 = []byte{ - // 289 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4d, 0xcc, 0x4e, 0x2c, - 0xce, 0xd0, 0x4f, 0x49, 0x2d, 0xc8, 0xc9, 0xaf, 0xcc, 0x4d, 0xcd, 0x2b, 0xd1, 0x2f, 0x33, 0x4c, - 0x4a, 0x2d, 0x49, 0x34, 0xd6, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, - 0xc9, 0x17, 0x92, 0x00, 0x2b, 0xd3, 0x43, 0x28, 0xd3, 0x83, 0x2a, 0x93, 0x12, 0x49, 0xcf, 0x4f, - 0xcf, 0x07, 0x2b, 0xd2, 0x07, 0xb1, 0x20, 0xea, 0x95, 0x6e, 0x33, 0x72, 0xb1, 0x05, 0x80, 0x0d, - 0x10, 0x9a, 0xc0, 0xc8, 0xc5, 0x93, 0x9b, 0x99, 0x17, 0x9f, 0x92, 0x5a, 0x90, 0x5f, 0x9c, 0x59, - 0x52, 0x2c, 0xc1, 0xa8, 0xc0, 0xac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0x96, 0x01, 0x00, - 0x00, + // 292 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0xbf, 0x4a, 0x03, 0x31, + 0x1c, 0xc7, 0x2f, 0x08, 0x1d, 0x5a, 0xa7, 0xea, 0x50, 0x3b, 0xe4, 0xe4, 0x40, 0xe8, 0xd2, 0x84, + 0xb3, 0x9b, 0xe0, 0x52, 0x5d, 0x05, 0x71, 0x11, 0x5c, 0x24, 0x77, 0x17, 0xaf, 0xe1, 0x9a, 0xfc, + 0xc2, 0x25, 0x2a, 0xf7, 0x16, 0x3e, 0x84, 0x93, 0x8b, 0xaf, 0xd1, 0xb1, 0xa3, 0xd3, 0x29, 0x77, + 0x9b, 0xa3, 0x4f, 0x20, 0xcd, 0x05, 0x5a, 0xc1, 0x29, 0xff, 0x3e, 0xf9, 0x7c, 0x7f, 0x7c, 0xfb, + 0x27, 0xac, 0x60, 0x66, 0x41, 0x33, 0xae, 0x97, 0x50, 0x49, 0xae, 0x2c, 0x7d, 0x8a, 0x13, 0x6e, + 0xd9, 0x8c, 0x6a, 0x56, 0x32, 0x69, 0x88, 0x2e, 0xc1, 0xc2, 0x70, 0xe4, 0x30, 0xb2, 0xc5, 0x88, + 0xc7, 0xc6, 0x87, 0x39, 0xe4, 0xe0, 0x20, 0xba, 0xd9, 0x75, 0xfc, 0x18, 0xa7, 0x60, 0x24, 0x18, + 0x9a, 0x30, 0xc3, 0xbd, 0x31, 0xa6, 0x29, 0x08, 0xd5, 0xbd, 0x47, 0xef, 0xa8, 0xdf, 0xbb, 0x76, + 0x01, 0xc3, 0x57, 0xd4, 0xdf, 0x97, 0x42, 0xdd, 0x67, 0x5c, 0x83, 0x11, 0xd6, 0x8c, 0xd0, 0xf1, + 0xde, 0x64, 0x70, 0x7a, 0x44, 0x3a, 0x05, 0xd9, 0x28, 0x7c, 0x5a, 0x4c, 0x2e, 0x40, 0xa8, 0xf9, + 0xc3, 0xaa, 0x0e, 0x83, 0xa6, 0x0e, 0x07, 0x57, 0x42, 0x5d, 0xfa, 0x5f, 0xdf, 0x75, 0xf8, 0xc7, + 0xf2, 0x53, 0x87, 0x07, 0x15, 0x93, 0xcb, 0xb3, 0x68, 0xf7, 0x36, 0x7a, 0xfb, 0x0c, 0x27, 0xb9, + 0xb0, 0x8b, 0xc7, 0x84, 0xa4, 0x20, 0xa9, 0x9f, 0xb2, 0x5b, 0xa6, 0x26, 0x2b, 0xa8, 0xad, 0x34, + 0x37, 0x2e, 0xc6, 0xdc, 0x0c, 0xe4, 0xd6, 0x3f, 0xbf, 0x5d, 0x35, 0x18, 0xad, 0x1b, 0x8c, 0xbe, + 0x1a, 0x8c, 0x5e, 0x5a, 0x1c, 0xac, 0x5b, 0x1c, 0x7c, 0xb4, 0x38, 0xb8, 0x3b, 0xdf, 0x11, 0xba, + 0x9a, 0xa6, 0x8a, 0xdb, 0x67, 0x28, 0x0b, 0x7f, 0x62, 0x5a, 0xd0, 0x1c, 0xa8, 0x82, 0x8c, 0xff, + 0xd3, 0x73, 0xd2, 0x73, 0x8d, 0xcc, 0x7e, 0x03, 0x00, 0x00, 0xff, 0xff, 0xc7, 0xd3, 0xdf, 0x39, + 0x8a, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -122,18 +122,15 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if len(m.MinDeposits) > 0 { - for k := range m.MinDeposits { - v := m.MinDeposits[k] - baseI := i - i = encodeVarintParams(dAtA, i, uint64(v)) - i-- - dAtA[i] = 0x10 - i -= len(k) - copy(dAtA[i:], k) - i = encodeVarintParams(dAtA, i, uint64(len(k))) - i-- - dAtA[i] = 0xa - i = encodeVarintParams(dAtA, i, uint64(baseI-i)) + for iNdEx := len(m.MinDeposits) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.MinDeposits[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0xa } @@ -159,11 +156,9 @@ func (m *Params) Size() (n int) { var l int _ = l if len(m.MinDeposits) > 0 { - for k, v := range m.MinDeposits { - _ = k - _ = v - mapEntrySize := 1 + len(k) + sovParams(uint64(len(k))) + 1 + sovParams(uint64(v)) - n += mapEntrySize + 1 + sovParams(uint64(mapEntrySize)) + for _, e := range m.MinDeposits { + l = e.Size() + n += 1 + l + sovParams(uint64(l)) } } return n @@ -233,89 +228,10 @@ func (m *Params) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.MinDeposits == nil { - m.MinDeposits = make(map[string]uint32) - } - var mapkey string - var mapvalue uint32 - for iNdEx < postIndex { - entryPreIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParams - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - if fieldNum == 1 { - var stringLenmapkey uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParams - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLenmapkey |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLenmapkey := int(stringLenmapkey) - if intStringLenmapkey < 0 { - return ErrInvalidLengthParams - } - postStringIndexmapkey := iNdEx + intStringLenmapkey - if postStringIndexmapkey < 0 { - return ErrInvalidLengthParams - } - if postStringIndexmapkey > l { - return io.ErrUnexpectedEOF - } - mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) - iNdEx = postStringIndexmapkey - } else if fieldNum == 2 { - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParams - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - mapvalue |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - } else { - iNdEx = entryPreIndex - skippy, err := skipParams(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthParams - } - if (iNdEx + skippy) > postIndex { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } + m.MinDeposits = append(m.MinDeposits, types.Coin{}) + if err := m.MinDeposits[len(m.MinDeposits)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } - m.MinDeposits[mapkey] = mapvalue iNdEx = postIndex default: iNdEx = preIndex diff --git a/go/node/take/v1beta3/denom_take_rate.go b/go/node/take/v1beta3/denom_take_rate.go new file mode 100644 index 00000000..1b18485f --- /dev/null +++ b/go/node/take/v1beta3/denom_take_rate.go @@ -0,0 +1,21 @@ +package v1beta3 + +import ( + "sort" +) + +type DenomTakeRates []DenomTakeRate + +var _ sort.Interface = (*DenomTakeRates)(nil) + +func (u DenomTakeRates) Len() int { + return len(u) +} + +func (u DenomTakeRates) Swap(i, j int) { + u[i], u[j] = u[j], u[i] +} + +func (u DenomTakeRates) Less(i, j int) bool { + return u[i].Denom < u[j].Denom +} diff --git a/go/node/take/v1beta3/params.go b/go/node/take/v1beta3/params.go index 73fe469a..900052c6 100644 --- a/go/node/take/v1beta3/params.go +++ b/go/node/take/v1beta3/params.go @@ -1,9 +1,10 @@ package v1beta3 import ( - "github.com/pkg/errors" "fmt" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/pkg/errors" ) var _ paramtypes.ParamSet = (*Params)(nil) @@ -27,8 +28,11 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { func DefaultParams() Params { return Params{ DefaultTakeRate: 20, - DenomTakeRates: map[string]uint32{ - "uakt": 0, + DenomTakeRates: DenomTakeRates{ + { + Denom: "uakt", + Rate: 0, + }, }, } } @@ -50,26 +54,34 @@ func validateTakeRate(i interface{}) error { return errors.Wrapf(ErrInvalidParam, "%T", i) } if val > 100 { - return fmt.Errorf("Invalid Take Rate (%#v)", val) + return fmt.Errorf("invalid Take Rate (%#v)", val) } return nil } func validateDenomTakeRates(i interface{}) error { - val, ok := i.(map[string]uint32) + takeRates, ok := i.(DenomTakeRates) if !ok { return errors.Wrapf(ErrInvalidParam, "%T", i) } - for k, v := range(val) { - if v > 100 { - return fmt.Errorf("Invalid Denom Take Rate (%v=%#v)", k,v) + check := make(map[string]uint32) + + for k, v := range takeRates { + if _, exists := check[v.Denom]; exists { + return fmt.Errorf("duplicate Denom Take Rate (%#v)", v) + } + + check[v.Denom] = v.Rate + + if v.Rate > 100 { + return fmt.Errorf("invalid Denom Take Rate (%v=%#v)", k, v) } } // must have uakt=0 - if v, ok := val["uakt"]; !ok || v != 0 { - return fmt.Errorf("Invalid Denom Take Rate - uakt must be 0 (%#v)", v) + if rate, exists := check["uakt"]; !exists || rate != 0 { + return fmt.Errorf("invalid Denom Take Rate - uakt must be 0") } return nil diff --git a/go/node/take/v1beta3/params.pb.go b/go/node/take/v1beta3/params.pb.go index 52db3bc0..49283e36 100644 --- a/go/node/take/v1beta3/params.pb.go +++ b/go/node/take/v1beta3/params.pb.go @@ -23,18 +23,70 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type DenomTakeRate struct { + Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom" yaml:"denom"` + Rate uint32 `protobuf:"varint,2,opt,name=rate,proto3" json:"rate" yaml:"rate"` +} + +func (m *DenomTakeRate) Reset() { *m = DenomTakeRate{} } +func (m *DenomTakeRate) String() string { return proto.CompactTextString(m) } +func (*DenomTakeRate) ProtoMessage() {} +func (*DenomTakeRate) Descriptor() ([]byte, []int) { + return fileDescriptor_4c72a477131e48ec, []int{0} +} +func (m *DenomTakeRate) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DenomTakeRate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DenomTakeRate.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 *DenomTakeRate) XXX_Merge(src proto.Message) { + xxx_messageInfo_DenomTakeRate.Merge(m, src) +} +func (m *DenomTakeRate) XXX_Size() int { + return m.Size() +} +func (m *DenomTakeRate) XXX_DiscardUnknown() { + xxx_messageInfo_DenomTakeRate.DiscardUnknown(m) +} + +var xxx_messageInfo_DenomTakeRate proto.InternalMessageInfo + +func (m *DenomTakeRate) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +func (m *DenomTakeRate) GetRate() uint32 { + if m != nil { + return m.Rate + } + return 0 +} + // Params defines the parameters for the x/take package type Params struct { // denom -> % take rate - DenomTakeRates map[string]uint32 `protobuf:"bytes,1,rep,name=denom_take_rates,json=denomTakeRates,proto3" json:"denom_take_rates" yaml:"denom_take_rates" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` - DefaultTakeRate uint32 `protobuf:"varint,2,opt,name=default_take_rate,json=defaultTakeRate,proto3" json:"default_take_rate" yaml:"default_take_rate"` + DenomTakeRates DenomTakeRates `protobuf:"bytes,1,rep,name=denom_take_rates,json=denomTakeRates,proto3,castrepeated=DenomTakeRates" json:"denom_take_rates" yaml:"denom_take_rates"` + DefaultTakeRate uint32 `protobuf:"varint,2,opt,name=default_take_rate,json=defaultTakeRate,proto3" json:"default_take_rate" yaml:"default_take_rate"` } 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_4c72a477131e48ec, []int{0} + return fileDescriptor_4c72a477131e48ec, []int{1} } func (m *Params) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -63,7 +115,7 @@ func (m *Params) XXX_DiscardUnknown() { var xxx_messageInfo_Params proto.InternalMessageInfo -func (m *Params) GetDenomTakeRates() map[string]uint32 { +func (m *Params) GetDenomTakeRates() DenomTakeRates { if m != nil { return m.DenomTakeRates } @@ -78,35 +130,72 @@ func (m *Params) GetDefaultTakeRate() uint32 { } func init() { + proto.RegisterType((*DenomTakeRate)(nil), "akash.take.v1beta3.DenomTakeRate") proto.RegisterType((*Params)(nil), "akash.take.v1beta3.Params") - proto.RegisterMapType((map[string]uint32)(nil), "akash.take.v1beta3.Params.DenomTakeRatesEntry") } func init() { proto.RegisterFile("akash/take/v1beta3/params.proto", fileDescriptor_4c72a477131e48ec) } var fileDescriptor_4c72a477131e48ec = []byte{ - // 330 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0x31, 0x4f, 0xc2, 0x40, - 0x14, 0xc7, 0x7b, 0x10, 0x49, 0x3c, 0x23, 0x60, 0x25, 0xb1, 0x61, 0xe8, 0x91, 0x4e, 0x2c, 0xde, - 0x45, 0x19, 0x34, 0x6c, 0x12, 0xd8, 0xb5, 0x71, 0x72, 0x21, 0x0f, 0x7b, 0x16, 0x52, 0xda, 0x6b, - 0xca, 0x81, 0xe1, 0x5b, 0xf8, 0x0d, 0xfc, 0x3a, 0x8c, 0x8c, 0x4e, 0xa7, 0x29, 0x1b, 0x23, 0x9f, - 0xc0, 0xb4, 0x85, 0x98, 0x52, 0xb7, 0xf7, 0xf2, 0xff, 0xfd, 0xde, 0x6b, 0xef, 0x61, 0x02, 0x1e, - 0xcc, 0xc6, 0x4c, 0x82, 0xc7, 0xd9, 0xe2, 0x66, 0xc4, 0x25, 0x74, 0x58, 0x08, 0x11, 0xf8, 0x33, - 0x1a, 0x46, 0x42, 0x0a, 0x5d, 0x4f, 0x01, 0x9a, 0x00, 0x74, 0x0f, 0x34, 0x1b, 0xae, 0x70, 0x45, - 0x1a, 0xb3, 0xa4, 0xca, 0x48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 0x7c, 0x17, 0x91, 0xb7, 0xef, 0x20, 0x9c, - 0x30, 0x57, 0xb0, 0x40, 0x38, 0x3c, 0x77, 0xeb, 0x51, 0x25, 0xbd, 0x5d, 0xe7, 0x37, 0x00, 0x00, - 0xff, 0xff, 0x3f, 0x67, 0x31, 0xaf, 0x08, 0x02, 0x00, 0x00, + // 362 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x52, 0x3f, 0x4f, 0xfa, 0x40, + 0x18, 0xee, 0xf1, 0x03, 0x92, 0x5f, 0x11, 0xd0, 0xc6, 0xc4, 0xc6, 0xa1, 0x2f, 0xde, 0xc4, 0x62, + 0x1b, 0x65, 0xd0, 0x38, 0x36, 0x7c, 0x00, 0x6d, 0x4c, 0x4c, 0x5c, 0xc8, 0x61, 0xcf, 0x42, 0x4a, + 0xb9, 0xa6, 0x3d, 0x34, 0x2e, 0x7e, 0x06, 0xbf, 0x82, 0x89, 0x93, 0x9f, 0x84, 0x91, 0xd1, 0xe9, + 0x34, 0x65, 0xeb, 0xd8, 0x4f, 0x60, 0x7a, 0x85, 0x48, 0x61, 0xbb, 0xe7, 0xcf, 0xfb, 0xe4, 0x79, + 0xef, 0x4e, 0x05, 0xe2, 0x93, 0x78, 0x64, 0x71, 0xe2, 0x53, 0xeb, 0xe9, 0x6c, 0x48, 0x39, 0xe9, + 0x59, 0x21, 0x89, 0x48, 0x10, 0x9b, 0x61, 0xc4, 0x38, 0xd3, 0x34, 0x69, 0x30, 0x73, 0x83, 0xb9, + 0x32, 0x1c, 0x1f, 0x7a, 0xcc, 0x63, 0x52, 0xb6, 0xf2, 0x53, 0xe1, 0xc4, 0xaf, 0x6a, 0xb3, 0x4f, + 0xa7, 0x2c, 0xb8, 0x25, 0x3e, 0x75, 0x08, 0xa7, 0xda, 0xa5, 0x5a, 0x73, 0x73, 0x42, 0x47, 0x1d, + 0xd4, 0xfd, 0x6f, 0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 0x22, 0x7f, 0x85, 0x48, 0x38, 0xb6, + 0x3c, 0x66, 0x4d, 0x99, 0x4b, 0x4b, 0xbf, 0x65, 0x58, 0x97, 0xaf, 0xdf, 0xfb, 0x0d, 0x00, 0x00, + 0xff, 0xff, 0x64, 0x93, 0x15, 0xab, 0x4a, 0x02, 0x00, 0x00, +} + +func (m *DenomTakeRate) 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 *DenomTakeRate) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DenomTakeRate) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Rate != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.Rate)) + i-- + dAtA[i] = 0x10 + } + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintParams(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -135,18 +224,15 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x10 } if len(m.DenomTakeRates) > 0 { - for k := range m.DenomTakeRates { - v := m.DenomTakeRates[k] - baseI := i - i = encodeVarintParams(dAtA, i, uint64(v)) - i-- - dAtA[i] = 0x10 - i -= len(k) - copy(dAtA[i:], k) - i = encodeVarintParams(dAtA, i, uint64(len(k))) - i-- - dAtA[i] = 0xa - i = encodeVarintParams(dAtA, i, uint64(baseI-i)) + for iNdEx := len(m.DenomTakeRates) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.DenomTakeRates[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0xa } @@ -165,6 +251,22 @@ func encodeVarintParams(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *DenomTakeRate) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovParams(uint64(l)) + } + if m.Rate != 0 { + n += 1 + sovParams(uint64(m.Rate)) + } + return n +} + func (m *Params) Size() (n int) { if m == nil { return 0 @@ -172,11 +274,9 @@ func (m *Params) Size() (n int) { var l int _ = l if len(m.DenomTakeRates) > 0 { - for k, v := range m.DenomTakeRates { - _ = k - _ = v - mapEntrySize := 1 + len(k) + sovParams(uint64(len(k))) + 1 + sovParams(uint64(v)) - n += mapEntrySize + 1 + sovParams(uint64(mapEntrySize)) + for _, e := range m.DenomTakeRates { + l = e.Size() + n += 1 + l + sovParams(uint64(l)) } } if m.DefaultTakeRate != 0 { @@ -191,6 +291,107 @@ func sovParams(x uint64) (n int) { func sozParams(x uint64) (n int) { return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *DenomTakeRate) 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 ErrIntOverflowParams + } + 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: DenomTakeRate: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DenomTakeRate: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + 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 ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Rate", wireType) + } + m.Rate = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Rate |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *Params) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -249,89 +450,10 @@ func (m *Params) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.DenomTakeRates == nil { - m.DenomTakeRates = make(map[string]uint32) - } - var mapkey string - var mapvalue uint32 - for iNdEx < postIndex { - entryPreIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParams - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - if fieldNum == 1 { - var stringLenmapkey uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParams - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLenmapkey |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLenmapkey := int(stringLenmapkey) - if intStringLenmapkey < 0 { - return ErrInvalidLengthParams - } - postStringIndexmapkey := iNdEx + intStringLenmapkey - if postStringIndexmapkey < 0 { - return ErrInvalidLengthParams - } - if postStringIndexmapkey > l { - return io.ErrUnexpectedEOF - } - mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) - iNdEx = postStringIndexmapkey - } else if fieldNum == 2 { - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParams - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - mapvalue |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - } else { - iNdEx = entryPreIndex - skippy, err := skipParams(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthParams - } - if (iNdEx + skippy) > postIndex { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } + m.DenomTakeRates = append(m.DenomTakeRates, DenomTakeRate{}) + if err := m.DenomTakeRates[len(m.DenomTakeRates)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } - m.DenomTakeRates[mapkey] = mapvalue iNdEx = postIndex case 2: if wireType != 0 { diff --git a/proto/node/akash/deployment/v1beta3/params.proto b/proto/node/akash/deployment/v1beta3/params.proto index 2b8120b5..91ed80ca 100644 --- a/proto/node/akash/deployment/v1beta3/params.proto +++ b/proto/node/akash/deployment/v1beta3/params.proto @@ -3,17 +3,17 @@ syntax = "proto3"; package akash.deployment.v1beta3; import "gogoproto/gogo.proto"; +import "cosmos/base/v1beta1/coin.proto"; option go_package = "github.com/akash-network/akash-api/go/node/deployment/v1beta3"; // Params defines the parameters for the x/deployment package message Params { - - // denom -> min deposit - map min_deposits = 1 [ - (gogoproto.customname) = "MinDeposits", - (gogoproto.nullable) = false, - (gogoproto.jsontag) = "min_deposits", - (gogoproto.moretags) = "yaml:\"min_deposits\"" + repeated cosmos.base.v1beta1.Coin min_deposits = 1[ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", + (gogoproto.customname) = "MinDeposits", + (gogoproto.nullable) = false, + (gogoproto.jsontag) = "min_deposits", + (gogoproto.moretags) = "yaml:\"min_deposits\"" ]; } diff --git a/proto/node/akash/take/v1beta3/params.proto b/proto/node/akash/take/v1beta3/params.proto index 08fd7073..ab18adf3 100644 --- a/proto/node/akash/take/v1beta3/params.proto +++ b/proto/node/akash/take/v1beta3/params.proto @@ -6,14 +6,29 @@ import "gogoproto/gogo.proto"; option go_package = "github.com/akash-network/akash-api/go/node/take/v1beta3"; +// DenomTakeRate describes take rate for specified denom +message DenomTakeRate { + string denom = 1 [ + (gogoproto.customname) = "Denom", + (gogoproto.jsontag) = "denom", + (gogoproto.moretags) = "yaml:\"denom\"" + ]; + uint32 rate = 2 [ + (gogoproto.customname) = "Rate", + (gogoproto.jsontag) = "rate", + (gogoproto.moretags) = "yaml:\"rate\"" + ]; +} + // Params defines the parameters for the x/take package message Params { // denom -> % take rate - map denom_take_rates = 1 [ - (gogoproto.customname) = "DenomTakeRates", - (gogoproto.nullable) = false, - (gogoproto.jsontag) = "denom_take_rates", - (gogoproto.moretags) = "yaml:\"denom_take_rates\"" + repeated DenomTakeRate denom_take_rates = 1 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "DenomTakeRates", + (gogoproto.customname) = "DenomTakeRates", + (gogoproto.jsontag) = "denom_take_rates", + (gogoproto.moretags) = "yaml:\"denom_take_rates\"" ]; uint32 default_take_rate = 2 [