diff --git a/app/app.go b/app/app.go index 2fb0430e..6275e8c5 100644 --- a/app/app.go +++ b/app/app.go @@ -413,6 +413,10 @@ func New( v1_5.CreateUpgradeHandler( app.ModuleManager, app.Configurator(), + app.appCodec, + app.GetStoreKeys(), + app.BundlesKeeper, + app.PoolKeeper, ), ) diff --git a/app/upgrades/v1_5/upgrade.go b/app/upgrades/v1_5/upgrade.go index f084f583..7c9c2a44 100644 --- a/app/upgrades/v1_5/upgrade.go +++ b/app/upgrades/v1_5/upgrade.go @@ -4,8 +4,16 @@ import ( "context" "fmt" + "cosmossdk.io/math" + + storetypes "cosmossdk.io/store/types" upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/KYVENetwork/chain/app/upgrades/v1_5/v1_4_types" + "github.com/KYVENetwork/chain/x/bundles/keeper" + bundlestypes "github.com/KYVENetwork/chain/x/bundles/types" + poolkeeper "github.com/KYVENetwork/chain/x/pool/keeper" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" ) @@ -14,11 +22,48 @@ const ( UpgradeName = "v1.5.0" ) -func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator) upgradetypes.UpgradeHandler { +func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator, cdc codec.Codec, storeKeys []storetypes.StoreKey, bundlesKeeper keeper.Keeper, poolKeeper *poolkeeper.Keeper) upgradetypes.UpgradeHandler { return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - logger := sdk.UnwrapSDKContext(ctx).Logger().With("upgrade", UpgradeName) + sdkCtx := sdk.UnwrapSDKContext(ctx) + logger := sdkCtx.Logger().With("upgrade", UpgradeName) logger.Info(fmt.Sprintf("performing upgrade %v", UpgradeName)) + + if err := migrateStorageCosts(sdkCtx, bundlesKeeper, poolKeeper, storeKeys, cdc); err != nil { + return nil, err + } + // TODO: migrate gov params + return mm.RunMigrations(ctx, configurator, fromVM) } } + +func migrateStorageCosts(sdkCtx sdk.Context, bundlesKeeper keeper.Keeper, poolKeeper *poolkeeper.Keeper, storeKeys []storetypes.StoreKey, cdc codec.Codec) error { + var bundlesStoreKey storetypes.StoreKey + for _, k := range storeKeys { + if k.Name() == "bundles" { + bundlesStoreKey = k + break + } + } + if bundlesStoreKey == nil { + return fmt.Errorf("store key not found: bundles") + } + + // Copy storage cost from old params to new params + // The storage cost of all storage providers will be the same after this migration + oldParams := v1_4_types.GetParams(sdkCtx, bundlesStoreKey, cdc) + newParams := bundlestypes.Params{ + UploadTimeout: oldParams.UploadTimeout, + StorageCosts: []bundlestypes.StorageCost{ + // TODO: define value for storage provider id 1 and 2 + {StorageProviderId: 1, Cost: math.LegacyMustNewDecFromStr("0.00")}, + {StorageProviderId: 2, Cost: math.LegacyMustNewDecFromStr("0.00")}, + }, + NetworkFee: oldParams.NetworkFee, + MaxPoints: oldParams.MaxPoints, + } + + bundlesKeeper.SetParams(sdkCtx, newParams) + return nil +} diff --git a/app/upgrades/v1_5/v1_4_types/getters_params.go b/app/upgrades/v1_5/v1_4_types/getters_params.go new file mode 100644 index 00000000..d3f98bef --- /dev/null +++ b/app/upgrades/v1_5/v1_4_types/getters_params.go @@ -0,0 +1,21 @@ +package v1_4_types + +import ( + storeTypes "cosmossdk.io/store/types" + "github.com/KYVENetwork/chain/x/bundles/types" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// GetParams returns the current x/bundles module parameters. +func GetParams(ctx sdk.Context, storeKey storeTypes.StoreKey, cdc codec.Codec) (params Params) { + store := ctx.KVStore(storeKey) + + bz := store.Get(types.ParamsPrefix) + if bz == nil { + return params + } + + cdc.MustUnmarshal(bz, ¶ms) + return params +} diff --git a/app/upgrades/v1_5/v1_4_types/params.pb.go b/app/upgrades/v1_5/v1_4_types/params.pb.go new file mode 100644 index 00000000..d57b8070 --- /dev/null +++ b/app/upgrades/v1_5/v1_4_types/params.pb.go @@ -0,0 +1,443 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: kyve/bundles/v1beta1/params.proto + +package v1_4_types + +import ( + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "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 + +// Params defines the bundles module parameters. +type Params struct { + // upload_timeout ... + UploadTimeout uint64 `protobuf:"varint,1,opt,name=upload_timeout,json=uploadTimeout,proto3" json:"upload_timeout,omitempty"` + // storage_cost ... + StorageCost cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=storage_cost,json=storageCost,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"storage_cost"` + // network_fee ... + NetworkFee cosmossdk_io_math.LegacyDec `protobuf:"bytes,3,opt,name=network_fee,json=networkFee,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"network_fee"` + // max_points ... + MaxPoints uint64 `protobuf:"varint,4,opt,name=max_points,json=maxPoints,proto3" json:"max_points,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_cfd3a74b72a01aaa, []int{0} +} +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) GetUploadTimeout() uint64 { + if m != nil { + return m.UploadTimeout + } + return 0 +} + +func (m *Params) GetMaxPoints() uint64 { + if m != nil { + return m.MaxPoints + } + return 0 +} + +func init() { + proto.RegisterType((*Params)(nil), "kyve.bundles.v1beta1.Params") +} + +func init() { proto.RegisterFile("kyve/bundles/v1beta1/params.proto", fileDescriptor_cfd3a74b72a01aaa) } + +var fileDescriptor_cfd3a74b72a01aaa = []byte{ + // 300 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x90, 0xc1, 0x4a, 0xf3, 0x40, + 0x14, 0x85, 0x33, 0xff, 0x5f, 0x0a, 0x9d, 0xaa, 0x8b, 0xd0, 0x45, 0x50, 0x4c, 0xab, 0x22, 0x74, + 0x21, 0x19, 0x8a, 0x6f, 0x50, 0x6b, 0x37, 0x8a, 0x94, 0x22, 0x82, 0x6e, 0xc2, 0x64, 0x7a, 0x4d, + 0x43, 0x3b, 0xb9, 0x21, 0x73, 0x53, 0xdb, 0xb7, 0xf0, 0xb1, 0xba, 0xec, 0x52, 0x44, 0x8a, 0x34, + 0x2f, 0x22, 0x4d, 0x82, 0x6b, 0x77, 0x97, 0xc3, 0xf7, 0x1d, 0x2e, 0x87, 0x9f, 0xcd, 0x56, 0x0b, + 0x10, 0x41, 0x16, 0x4f, 0xe6, 0x60, 0xc4, 0xa2, 0x17, 0x00, 0xc9, 0x9e, 0x48, 0x64, 0x2a, 0xb5, + 0xf1, 0x92, 0x14, 0x09, 0xed, 0xd6, 0x1e, 0xf1, 0x2a, 0xc4, 0xab, 0x90, 0xe3, 0x56, 0x88, 0x21, + 0x16, 0x80, 0xd8, 0x5f, 0x25, 0x7b, 0xfe, 0xc5, 0x78, 0x7d, 0x54, 0xc8, 0xf6, 0x25, 0x3f, 0xca, + 0x92, 0x39, 0xca, 0x89, 0x4f, 0x91, 0x06, 0xcc, 0xc8, 0x61, 0x1d, 0xd6, 0xad, 0x8d, 0x0f, 0xcb, + 0xf4, 0xb1, 0x0c, 0xed, 0x21, 0x3f, 0x30, 0x84, 0xa9, 0x0c, 0xc1, 0x57, 0x68, 0xc8, 0xf9, 0xd7, + 0x61, 0xdd, 0x46, 0xff, 0x62, 0xbd, 0x6d, 0x5b, 0x9f, 0xdb, 0xf6, 0x89, 0x42, 0xa3, 0xd1, 0x98, + 0xc9, 0xcc, 0x8b, 0x50, 0x68, 0x49, 0x53, 0xef, 0x1e, 0x42, 0xa9, 0x56, 0x03, 0x50, 0xe3, 0x66, + 0x25, 0xde, 0xa0, 0x21, 0x7b, 0xc0, 0x9b, 0x31, 0xd0, 0x1b, 0xa6, 0x33, 0xff, 0x15, 0xc0, 0xf9, + 0xff, 0xf7, 0x1a, 0x5e, 0x79, 0x43, 0x00, 0xfb, 0x94, 0x73, 0x2d, 0x97, 0x7e, 0x82, 0x51, 0x4c, + 0xc6, 0xa9, 0x15, 0x0f, 0x37, 0xb4, 0x5c, 0x8e, 0x8a, 0xa0, 0x3f, 0x5c, 0xef, 0x5c, 0xb6, 0xd9, + 0xb9, 0xec, 0x7b, 0xe7, 0xb2, 0xf7, 0xdc, 0xb5, 0x36, 0xb9, 0x6b, 0x7d, 0xe4, 0xae, 0xf5, 0x72, + 0x15, 0x46, 0x34, 0xcd, 0x02, 0x4f, 0xa1, 0x16, 0x77, 0xcf, 0x4f, 0xb7, 0x0f, 0x65, 0xa7, 0x50, + 0x53, 0x19, 0xc5, 0x62, 0xf9, 0xbb, 0x30, 0xad, 0x12, 0x30, 0x41, 0xbd, 0x58, 0xeb, 0xfa, 0x27, + 0x00, 0x00, 0xff, 0xff, 0xed, 0xea, 0x8e, 0xaf, 0x7e, 0x01, 0x00, 0x00, +} + +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.MaxPoints != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.MaxPoints)) + i-- + dAtA[i] = 0x20 + } + { + size := m.NetworkFee.Size() + i -= size + if _, err := m.NetworkFee.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size := m.StorageCost.Size() + i -= size + if _, err := m.StorageCost.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if m.UploadTimeout != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.UploadTimeout)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.UploadTimeout != 0 { + n += 1 + sovParams(uint64(m.UploadTimeout)) + } + l = m.StorageCost.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.NetworkFee.Size() + n += 1 + l + sovParams(uint64(l)) + if m.MaxPoints != 0 { + n += 1 + sovParams(uint64(m.MaxPoints)) + } + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +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 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: 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 UploadTimeout", wireType) + } + m.UploadTimeout = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UploadTimeout |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StorageCost", 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 + } + if err := m.StorageCost.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NetworkFee", 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 + } + if err := m.NetworkFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxPoints", wireType) + } + m.MaxPoints = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxPoints |= uint64(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 skipParams(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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index 8b1374fa..4f393572 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -22,9 +22,20 @@ paths: type: string format: uint64 description: upload_timeout ... - storage_cost: - type: string - description: storage_cost ... + storage_costs: + type: array + items: + type: object + properties: + storage_provider_id: + type: integer + format: int64 + description: storage_provider_id ... + cost: + type: string + description: cost ... + title: StorageCost defines the cost for storage providers + description: storage_costs ... network_fee: type: string description: network_fee ... @@ -4269,9 +4280,20 @@ paths: type: string format: uint64 description: upload_timeout ... - storage_cost: - type: string - description: storage_cost ... + storage_costs: + type: array + items: + type: object + properties: + storage_provider_id: + type: integer + format: int64 + description: storage_provider_id ... + cost: + type: string + description: cost ... + title: StorageCost defines the cost for storage providers + description: storage_costs ... network_fee: type: string description: network_fee ... diff --git a/go.mod b/go.mod index efcd919f..d00d1890 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ toolchain go1.22.0 require ( cosmossdk.io/api v0.7.3 cosmossdk.io/client/v2 v2.0.0-beta.1 + cosmossdk.io/collections v0.4.0 cosmossdk.io/core v0.11.0 cosmossdk.io/depinject v1.0.0-alpha.4 cosmossdk.io/errors v1.0.1 @@ -54,7 +55,6 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v1.1.6 // indirect cloud.google.com/go/storage v1.36.0 // indirect - cosmossdk.io/collections v0.4.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.2 // indirect diff --git a/proto/kyve/bundles/v1beta1/params.proto b/proto/kyve/bundles/v1beta1/params.proto index a5255c55..97e4bae3 100644 --- a/proto/kyve/bundles/v1beta1/params.proto +++ b/proto/kyve/bundles/v1beta1/params.proto @@ -6,15 +6,23 @@ import "gogoproto/gogo.proto"; option go_package = "github.com/KYVENetwork/chain/x/bundles/types"; +// StorageCost defines the cost for storage providers +message StorageCost { + // storage_provider_id ... + uint32 storage_provider_id = 1; + // cost ... + string cost = 2 [ + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", + (gogoproto.nullable) = false + ]; +} + // Params defines the bundles module parameters. message Params { // upload_timeout ... uint64 upload_timeout = 1; - // storage_cost ... - string storage_cost = 2 [ - (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", - (gogoproto.nullable) = false - ]; + // storage_costs ... + repeated StorageCost storage_costs = 2 [(gogoproto.nullable) = false]; // network_fee ... string network_fee = 3 [ (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", diff --git a/x/bundles/keeper/getters_params.go b/x/bundles/keeper/getters_params.go index c4771d8f..44a5190c 100644 --- a/x/bundles/keeper/getters_params.go +++ b/x/bundles/keeper/getters_params.go @@ -3,20 +3,15 @@ package keeper import ( "cosmossdk.io/math" "github.com/KYVENetwork/chain/x/bundles/types" - "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" ) // GetParams returns the current x/bundles module parameters. func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { - store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) - - bz := store.Get(types.ParamsKey) - if bz == nil { - return params + params, err := k.BundlesParams.Get(ctx) + if err != nil { + return types.DefaultParams() } - - k.cdc.MustUnmarshal(bz, ¶ms) return params } @@ -26,8 +21,14 @@ func (k Keeper) GetUploadTimeout(ctx sdk.Context) (res uint64) { } // GetStorageCost returns the StorageCost param -func (k Keeper) GetStorageCost(ctx sdk.Context) (res math.LegacyDec) { - return k.GetParams(ctx).StorageCost +func (k Keeper) GetStorageCost(ctx sdk.Context, storageProviderId uint32) (res math.LegacyDec) { + storageCosts := k.GetParams(ctx).StorageCosts + for _, storageCost := range storageCosts { + if storageCost.StorageProviderId == storageProviderId { + return storageCost.Cost + } + } + return math.LegacyZeroDec() } // GetNetworkFee returns the NetworkFee param @@ -42,7 +43,5 @@ func (k Keeper) GetMaxPoints(ctx sdk.Context) (res uint64) { // SetParams sets the x/bundles module parameters. func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { - store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) - bz := k.cdc.MustMarshal(¶ms) - store.Set(types.ParamsKey, bz) + _ = k.BundlesParams.Set(ctx, params) } diff --git a/x/bundles/keeper/keeper.go b/x/bundles/keeper/keeper.go index 1c2183b3..7691e59b 100644 --- a/x/bundles/keeper/keeper.go +++ b/x/bundles/keeper/keeper.go @@ -3,12 +3,12 @@ package keeper import ( "fmt" + "cosmossdk.io/collections" "cosmossdk.io/core/store" "cosmossdk.io/log" - "github.com/KYVENetwork/chain/util" - storetypes "cosmossdk.io/store/types" + "github.com/KYVENetwork/chain/util" "github.com/KYVENetwork/chain/x/bundles/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -30,6 +30,9 @@ type ( stakerKeeper types.StakerKeeper delegationKeeper types.DelegationKeeper fundersKeeper types.FundersKeeper + + Schema collections.Schema + BundlesParams collections.Item[types.Params] } ) @@ -49,6 +52,7 @@ func NewKeeper( delegationKeeper types.DelegationKeeper, fundersKeeper types.FundersKeeper, ) Keeper { + sb := collections.NewSchemaBuilder(storeService) return Keeper{ cdc: cdc, storeService: storeService, @@ -64,6 +68,8 @@ func NewKeeper( stakerKeeper: stakerKeeper, delegationKeeper: delegationKeeper, fundersKeeper: fundersKeeper, + + BundlesParams: collections.NewItem(sb, types.ParamsPrefix, "params", codec.CollValue[types.Params](cdc)), } } diff --git a/x/bundles/keeper/keeper_suite_inflation_splitting_test.go b/x/bundles/keeper/keeper_suite_inflation_splitting_test.go index e0586d69..bde9ad47 100644 --- a/x/bundles/keeper/keeper_suite_inflation_splitting_test.go +++ b/x/bundles/keeper/keeper_suite_inflation_splitting_test.go @@ -266,7 +266,7 @@ var _ = Describe("inflation splitting", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.GetCurrentStorageProviderId()).MulInt64(100).TruncateInt64()) totalUploaderReward := totalPayout - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -359,7 +359,7 @@ var _ = Describe("inflation splitting", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.GetCurrentStorageProviderId()).MulInt64(100).TruncateInt64()) totalUploaderReward := totalPayout - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -465,7 +465,7 @@ var _ = Describe("inflation splitting", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.GetCurrentStorageProviderId()).MulInt64(100).TruncateInt64()) totalUploaderReward := totalPayout - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -572,7 +572,7 @@ var _ = Describe("inflation splitting", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.GetCurrentStorageProviderId()).MulInt64(100).TruncateInt64()) totalUploaderReward := totalPayout - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -679,7 +679,7 @@ var _ = Describe("inflation splitting", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.GetCurrentStorageProviderId()).MulInt64(100).TruncateInt64()) totalUploaderReward := totalPayout - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -784,7 +784,7 @@ var _ = Describe("inflation splitting", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.GetCurrentStorageProviderId()).MulInt64(100).TruncateInt64()) totalUploaderReward := totalPayout - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -891,7 +891,7 @@ var _ = Describe("inflation splitting", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.GetCurrentStorageProviderId()).MulInt64(100).TruncateInt64()) totalUploaderReward := totalPayout - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -998,7 +998,7 @@ var _ = Describe("inflation splitting", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.GetCurrentStorageProviderId()).MulInt64(100).TruncateInt64()) totalUploaderReward := totalPayout - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -1103,7 +1103,7 @@ var _ = Describe("inflation splitting", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.GetCurrentStorageProviderId()).MulInt64(100).TruncateInt64()) totalUploaderReward := totalPayout - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -1210,7 +1210,7 @@ var _ = Describe("inflation splitting", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.GetCurrentStorageProviderId()).MulInt64(100).TruncateInt64()) totalUploaderReward := totalPayout - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -1317,7 +1317,7 @@ var _ = Describe("inflation splitting", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.GetCurrentStorageProviderId()).MulInt64(100).TruncateInt64()) totalUploaderReward := totalPayout - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) diff --git a/x/bundles/keeper/keeper_suite_stakers_leave_test.go b/x/bundles/keeper/keeper_suite_stakers_leave_test.go index 007dad85..b93f69e7 100644 --- a/x/bundles/keeper/keeper_suite_stakers_leave_test.go +++ b/x/bundles/keeper/keeper_suite_stakers_leave_test.go @@ -244,7 +244,7 @@ var _ = Describe("stakers leave", Ordered, func() { // calculate uploader rewards networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100).TruncateInt64()) totalUploaderReward := pool.InflationShareWeight - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) diff --git a/x/bundles/keeper/keeper_suite_valid_bundles_test.go b/x/bundles/keeper/keeper_suite_valid_bundles_test.go index 8726437b..121fdd7c 100644 --- a/x/bundles/keeper/keeper_suite_valid_bundles_test.go +++ b/x/bundles/keeper/keeper_suite_valid_bundles_test.go @@ -22,6 +22,7 @@ TEST CASES - valid bundles * Produce a valid bundle with multiple validators and foreign delegation although some did not vote at all * Produce a valid bundle with multiple validators and foreign delegation although some voted abstain * Produce a valid bundle with multiple validators and foreign delegation although some voted invalid +* Produce a valid bundle with multiple validators and no foreign delegations and another storage provider */ @@ -234,7 +235,7 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100).TruncateInt64()) totalUploaderReward := pool.InflationShareWeight - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -379,7 +380,7 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100).TruncateInt64()) totalUploaderReward := pool.InflationShareWeight - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -557,7 +558,7 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100).TruncateInt64()) totalUploaderReward := pool.InflationShareWeight - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -736,7 +737,7 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100).TruncateInt64()) totalUploaderReward := pool.InflationShareWeight - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -925,7 +926,7 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100).TruncateInt64()) totalUploaderReward := pool.InflationShareWeight - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -953,4 +954,150 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(s.App().FundersKeeper.GetTotalActiveFunding(s.Ctx(), fundingState.PoolId)).To(Equal(100*i.KYVE - 1*amountPerBundle)) Expect(fundingState.ActiveFunderAddresses).To(HaveLen(1)) }) + + It("Produce a valid bundle with multiple validators and no foreign delegations and another storage provider", func() { + // ARRANGE + storageProviderId := uint32(1) + + params := s.App().BundlesKeeper.GetParams(s.Ctx()) + params.StorageCosts = append(params.StorageCosts, bundletypes.StorageCost{StorageProviderId: 1, Cost: math.LegacyMustNewDecFromStr("0.9")}) + s.App().BundlesKeeper.SetParams(s.Ctx(), params) + + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + pool.CurrentStorageProviderId = storageProviderId + s.App().PoolKeeper.SetPool(s.Ctx(), pool) + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0_A, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 0, + BundleSize: 100, + FromKey: "0", + ToKey: "99", + BundleSummary: "test_value", + }) + + s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + Vote: bundletypes.VOTE_TYPE_VALID, + }) + + initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) + initialBalanceValaddress1 = s.GetBalanceFromAddress(i.VALADDRESS_1_A) + + s.CommitAfterSeconds(60) + + // ACT + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_1_A, + Staker: i.STAKER_1, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + DataSize: 100, + DataHash: "test_hash2", + FromIndex: 100, + BundleSize: 100, + FromKey: "100", + ToKey: "199", + BundleSummary: "test_value2", + }) + + // ASSERT + // check if bundle got finalized on pool + pool, poolFound := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + Expect(poolFound).To(BeTrue()) + + Expect(pool.CurrentKey).To(Equal("99")) + Expect(pool.CurrentSummary).To(Equal("test_value")) + Expect(pool.CurrentIndex).To(Equal(uint64(100))) + Expect(pool.TotalBundles).To(Equal(uint64(1))) + + // check if finalized bundle got saved + finalizedBundle, finalizedBundleFound := s.App().BundlesKeeper.GetFinalizedBundle(s.Ctx(), 0, 0) + Expect(finalizedBundleFound).To(BeTrue()) + + Expect(finalizedBundle.PoolId).To(Equal(uint64(0))) + Expect(finalizedBundle.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) + Expect(finalizedBundle.Uploader).To(Equal(i.STAKER_0)) + Expect(finalizedBundle.FromIndex).To(Equal(uint64(0))) + Expect(finalizedBundle.ToIndex).To(Equal(uint64(100))) + Expect(finalizedBundle.FromKey).To(Equal("0")) + Expect(finalizedBundle.ToKey).To(Equal("99")) + Expect(finalizedBundle.BundleSummary).To(Equal("test_value")) + Expect(finalizedBundle.DataHash).To(Equal("test_hash")) + Expect(finalizedBundle.FinalizedAt).NotTo(BeZero()) + Expect(finalizedBundle.StakeSecurity.ValidVotePower).To(Equal(200 * i.KYVE)) + Expect(finalizedBundle.StakeSecurity.TotalVotePower).To(Equal(200 * i.KYVE)) + + // check if next bundle proposal got registered + bundleProposal, bundleProposalFound := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) + Expect(bundleProposalFound).To(BeTrue()) + + Expect(bundleProposal.PoolId).To(Equal(uint64(0))) + Expect(bundleProposal.StorageId).To(Equal("P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg")) + Expect(bundleProposal.Uploader).To(Equal(i.STAKER_1)) + Expect(bundleProposal.NextUploader).NotTo(BeEmpty()) + Expect(bundleProposal.DataSize).To(Equal(uint64(100))) + Expect(bundleProposal.DataHash).To(Equal("test_hash2")) + Expect(bundleProposal.BundleSize).To(Equal(uint64(100))) + Expect(bundleProposal.FromKey).To(Equal("100")) + Expect(bundleProposal.ToKey).To(Equal("199")) + Expect(bundleProposal.BundleSummary).To(Equal("test_value2")) + Expect(bundleProposal.UpdatedAt).NotTo(BeZero()) + Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_1)) + Expect(bundleProposal.VotersInvalid).To(BeEmpty()) + Expect(bundleProposal.VotersAbstain).To(BeEmpty()) + + // check uploader status + valaccountUploader, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_0) + Expect(valaccountUploader.Points).To(BeZero()) + + balanceUploaderValaddress := s.GetBalanceFromAddress(valaccountUploader.Valaddress) + Expect(balanceUploaderValaddress).To(Equal(initialBalanceValaddress0)) + + balanceUploader := s.GetBalanceFromAddress(valaccountUploader.Staker) + uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), valaccountUploader.Staker) + + // check voter status + valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) + Expect(valaccountVoter.Points).To(BeZero()) + + balanceVoterValaddress := s.GetBalanceFromAddress(valaccountVoter.Valaddress) + Expect(balanceVoterValaddress).To(Equal(initialBalanceValaddress1)) + + balanceVoter := s.GetBalanceFromAddress(valaccountVoter.Staker) + Expect(balanceVoter).To(Equal(initialBalanceStaker1)) + + // calculate uploader rewards + // calculate uploader rewards + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), storageProviderId).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.InflationShareWeight - treasuryReward - storageReward + + uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) + uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward + + // assert storage reward -> 0.9 * 100 + Expect(storageReward).To(Equal(uint64(90))) + // assert payout transfer + Expect(balanceUploader).To(Equal(initialBalanceStaker0)) + // assert commission rewards + Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) + // assert uploader self delegation rewards + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(uploaderDelegationReward)) + + fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) + + // assert total pool funds + Expect(s.App().FundersKeeper.GetTotalActiveFunding(s.Ctx(), fundingState.PoolId)).To(Equal(100*i.KYVE - 1*amountPerBundle)) + Expect(fundingState.ActiveFunderAddresses).To(HaveLen(1)) + }) }) diff --git a/x/bundles/keeper/keeper_suite_zero_delegation_test.go b/x/bundles/keeper/keeper_suite_zero_delegation_test.go index 27433b78..5f4fc408 100644 --- a/x/bundles/keeper/keeper_suite_zero_delegation_test.go +++ b/x/bundles/keeper/keeper_suite_zero_delegation_test.go @@ -464,7 +464,7 @@ var _ = Describe("zero delegation", Ordered, func() { // calculate uploader rewards networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100).TruncateInt64()) totalUploaderReward := pool.InflationShareWeight - treasuryReward - storageReward uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) diff --git a/x/bundles/keeper/logic_bundles.go b/x/bundles/keeper/logic_bundles.go index abae927c..3ff6d2ea 100644 --- a/x/bundles/keeper/logic_bundles.go +++ b/x/bundles/keeper/logic_bundles.go @@ -243,7 +243,7 @@ func (k Keeper) calculatePayouts(ctx sdk.Context, poolId uint64, totalPayout uin bundleReward.Treasury = uint64(math.LegacyNewDec(int64(totalPayout)).Mul(k.GetNetworkFee(ctx)).TruncateInt64()) // calculate wanted storage reward the uploader should receive - storageReward := uint64(k.GetStorageCost(ctx).MulInt64(int64(bundleProposal.DataSize)).TruncateInt64()) + storageReward := uint64(k.GetStorageCost(ctx, bundleProposal.StorageProviderId).MulInt64(int64(bundleProposal.DataSize)).TruncateInt64()) // if not even the full storage reward can not be paid out we pay out the remains. // in this case the uploader will not earn the commission rewards and delegators not diff --git a/x/bundles/keeper/msg_server_update_params.go b/x/bundles/keeper/msg_server_update_params.go index 00407887..9e67e99b 100644 --- a/x/bundles/keeper/msg_server_update_params.go +++ b/x/bundles/keeper/msg_server_update_params.go @@ -5,6 +5,7 @@ import ( "encoding/json" "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" // Bundles diff --git a/x/bundles/keeper/msg_server_update_params_test.go b/x/bundles/keeper/msg_server_update_params_test.go index 2bcb7517..74a75cb5 100644 --- a/x/bundles/keeper/msg_server_update_params_test.go +++ b/x/bundles/keeper/msg_server_update_params_test.go @@ -67,7 +67,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { params := s.App().BundlesKeeper.GetParams(s.Ctx()) Expect(params.UploadTimeout).To(Equal(types.DefaultUploadTimeout)) - Expect(params.StorageCost).To(Equal(types.DefaultStorageCost)) + Expect(params.StorageCosts).To(Equal(types.DefaultStorageCosts)) Expect(params.NetworkFee).To(Equal(types.DefaultNetworkFee)) Expect(params.MaxPoints).To(Equal(types.DefaultMaxPoints)) }) @@ -108,7 +108,9 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { // ARRANGE payload := `{ "upload_timeout": 20, - "storage_cost": "0.050000000000000000", + "storage_costs": [ + {"storage_provider_id": 0, "cost": "0.05"} + ], "network_fee": "0.05", "max_points": 15 }` @@ -140,7 +142,10 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(voteErr).NotTo(HaveOccurred()) Expect(updatedParams.UploadTimeout).To(Equal(uint64(20))) - Expect(updatedParams.StorageCost).To(Equal(math.LegacyMustNewDecFromStr("0.05"))) + Expect(updatedParams.StorageCosts).To(Equal([]types.StorageCost{{ + StorageProviderId: 0, + Cost: math.LegacyMustNewDecFromStr("0.05"), + }})) Expect(updatedParams.NetworkFee).To(Equal(math.LegacyMustNewDecFromStr("0.05"))) Expect(updatedParams.MaxPoints).To(Equal(uint64(15))) }) @@ -176,7 +181,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(voteErr).NotTo(HaveOccurred()) Expect(updatedParams.UploadTimeout).To(Equal(types.DefaultUploadTimeout)) - Expect(updatedParams.StorageCost).To(Equal(types.DefaultStorageCost)) + Expect(updatedParams.StorageCosts).To(Equal(types.DefaultStorageCosts)) Expect(updatedParams.NetworkFee).To(Equal(types.DefaultNetworkFee)) Expect(updatedParams.MaxPoints).To(Equal(types.DefaultMaxPoints)) }) @@ -208,7 +213,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(submitErr).To(HaveOccurred()) Expect(updatedParams.UploadTimeout).To(Equal(types.DefaultUploadTimeout)) - Expect(updatedParams.StorageCost).To(Equal(types.DefaultStorageCost)) + Expect(updatedParams.StorageCosts).To(Equal(types.DefaultStorageCosts)) Expect(updatedParams.NetworkFee).To(Equal(types.DefaultNetworkFee)) Expect(updatedParams.MaxPoints).To(Equal(types.DefaultMaxPoints)) }) @@ -246,7 +251,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(voteErr).NotTo(HaveOccurred()) Expect(updatedParams.UploadTimeout).To(Equal(uint64(20))) - Expect(updatedParams.StorageCost).To(Equal(types.DefaultStorageCost)) + Expect(updatedParams.StorageCosts).To(Equal(types.DefaultStorageCosts)) Expect(updatedParams.NetworkFee).To(Equal(types.DefaultNetworkFee)) Expect(updatedParams.MaxPoints).To(Equal(types.DefaultMaxPoints)) }) @@ -278,15 +283,18 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(submitErr).To(HaveOccurred()) Expect(updatedParams.UploadTimeout).To(Equal(types.DefaultUploadTimeout)) - Expect(updatedParams.StorageCost).To(Equal(types.DefaultStorageCost)) + Expect(updatedParams.StorageCosts).To(Equal(types.DefaultStorageCosts)) Expect(updatedParams.NetworkFee).To(Equal(types.DefaultNetworkFee)) Expect(updatedParams.MaxPoints).To(Equal(types.DefaultMaxPoints)) }) - It("Update storage cost", func() { + It("Update storage costs", func() { // ARRANGE payload := `{ - "storage_cost": "0.050000000000000000" + "storage_costs": [ + {"storage_provider_id": 0, "cost": "0.05"}, + {"storage_provider_id": 1, "cost": "0.08"} + ] }` msg := &types.MsgUpdateParams{ @@ -316,7 +324,10 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(voteErr).NotTo(HaveOccurred()) Expect(updatedParams.UploadTimeout).To(Equal(types.DefaultUploadTimeout)) - Expect(updatedParams.StorageCost).To(Equal(math.LegacyMustNewDecFromStr("0.05"))) + Expect(updatedParams.StorageCosts).To(Equal([]types.StorageCost{ + {StorageProviderId: 0, Cost: math.LegacyMustNewDecFromStr("0.05")}, + {StorageProviderId: 1, Cost: math.LegacyMustNewDecFromStr("0.08")}, + })) Expect(updatedParams.NetworkFee).To(Equal(types.DefaultNetworkFee)) Expect(updatedParams.MaxPoints).To(Equal(types.DefaultMaxPoints)) }) @@ -324,7 +335,9 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { It("Update storage cost with invalid value", func() { // ARRANGE payload := `{ - "storage_cost": -100 + "storage_costs": [ + "-100" + ] }` msg := &types.MsgUpdateParams{ @@ -348,7 +361,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(submitErr).To(HaveOccurred()) Expect(updatedParams.UploadTimeout).To(Equal(types.DefaultUploadTimeout)) - Expect(updatedParams.StorageCost).To(Equal(types.DefaultStorageCost)) + Expect(updatedParams.StorageCosts).To(Equal(types.DefaultStorageCosts)) Expect(updatedParams.NetworkFee).To(Equal(types.DefaultNetworkFee)) Expect(updatedParams.MaxPoints).To(Equal(types.DefaultMaxPoints)) }) @@ -386,7 +399,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(voteErr).NotTo(HaveOccurred()) Expect(updatedParams.UploadTimeout).To(Equal(types.DefaultUploadTimeout)) - Expect(updatedParams.StorageCost).To(Equal(types.DefaultStorageCost)) + Expect(updatedParams.StorageCosts).To(Equal(types.DefaultStorageCosts)) Expect(updatedParams.NetworkFee).To(Equal(math.LegacyMustNewDecFromStr("0.05"))) Expect(updatedParams.MaxPoints).To(Equal(types.DefaultMaxPoints)) }) @@ -418,7 +431,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(submitErr).To(HaveOccurred()) Expect(updatedParams.UploadTimeout).To(Equal(types.DefaultUploadTimeout)) - Expect(updatedParams.StorageCost).To(Equal(types.DefaultStorageCost)) + Expect(updatedParams.StorageCosts).To(Equal(types.DefaultStorageCosts)) Expect(updatedParams.NetworkFee).To(Equal(types.DefaultNetworkFee)) Expect(updatedParams.MaxPoints).To(Equal(types.DefaultMaxPoints)) }) @@ -456,7 +469,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(voteErr).NotTo(HaveOccurred()) Expect(updatedParams.UploadTimeout).To(Equal(types.DefaultUploadTimeout)) - Expect(updatedParams.StorageCost).To(Equal(types.DefaultStorageCost)) + Expect(updatedParams.StorageCosts).To(Equal(types.DefaultStorageCosts)) Expect(updatedParams.NetworkFee).To(Equal(types.DefaultNetworkFee)) Expect(updatedParams.MaxPoints).To(Equal(uint64(15))) }) @@ -488,7 +501,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(submitErr).To(HaveOccurred()) Expect(updatedParams.UploadTimeout).To(Equal(types.DefaultUploadTimeout)) - Expect(updatedParams.StorageCost).To(Equal(types.DefaultStorageCost)) + Expect(updatedParams.StorageCosts).To(Equal(types.DefaultStorageCosts)) Expect(updatedParams.NetworkFee).To(Equal(types.DefaultNetworkFee)) Expect(updatedParams.MaxPoints).To(Equal(types.DefaultMaxPoints)) }) diff --git a/x/bundles/spec/08_params.md b/x/bundles/spec/08_params.md index c14aa4ce..520f6c68 100644 --- a/x/bundles/spec/08_params.md +++ b/x/bundles/spec/08_params.md @@ -6,9 +6,9 @@ order: 8 The bundles module contains the following parameters: -| Key | Type | Example | -|---------------|-------------------------|---------| -| UploadTimeout | uint64 (time s) | 600 | -| StorageCost | uint64 (tkyve per byte) | 25 | -| NetworkFee | sdk.Dec (%) | "0.01" | -| MaxPoints | uint64 | 5 | +| Key | Type | Example | +|---------------|-----------------------------------------------------------|----------------------------------------| +| UploadTimeout | uint64 (time s) | 600 | +| StorageCosts | []StorageCost (storageProviderId, cost in tkyve per byte) | ["storage_provider_id": 1, "cost": 25] | +| NetworkFee | sdk.Dec (%) | "0.01" | +| MaxPoints | uint64 | 5 | diff --git a/x/bundles/types/keys.go b/x/bundles/types/keys.go index 073aa04f..2e72be6a 100644 --- a/x/bundles/types/keys.go +++ b/x/bundles/types/keys.go @@ -1,6 +1,7 @@ package types import ( + "cosmossdk.io/collections" "github.com/KYVENetwork/chain/util" ) @@ -13,12 +14,9 @@ const ( // RouterKey defines the module's message routing key RouterKey = ModuleName - - // MemStoreKey defines the in-memory store key - MemStoreKey = "mem_bundles" ) -var ParamsKey = []byte{0x00} +var ParamsPrefix = collections.NewPrefix(0) var ( // BundleKeyPrefix ... diff --git a/x/bundles/types/params.go b/x/bundles/types/params.go index 4d3f7f42..af02b01c 100644 --- a/x/bundles/types/params.go +++ b/x/bundles/types/params.go @@ -2,14 +2,15 @@ package types import ( "cosmossdk.io/math" + "github.com/KYVENetwork/chain/util" ) // DefaultUploadTimeout ... var DefaultUploadTimeout = uint64(600) -// DefaultStorageCost ... -var DefaultStorageCost = math.LegacyMustNewDecFromStr("0.025") +// DefaultStorageCosts ... +var DefaultStorageCosts []StorageCost // DefaultNetworkFee ... var DefaultNetworkFee = math.LegacyMustNewDecFromStr("0.01") @@ -20,13 +21,13 @@ var DefaultMaxPoints = uint64(24) // NewParams creates a new Params instance func NewParams( uploadTimeout uint64, - storageCost math.LegacyDec, + storageCosts []StorageCost, networkFee math.LegacyDec, maxPoints uint64, ) Params { return Params{ UploadTimeout: uploadTimeout, - StorageCost: storageCost, + StorageCosts: storageCosts, NetworkFee: networkFee, MaxPoints: maxPoints, } @@ -36,7 +37,7 @@ func NewParams( func DefaultParams() Params { return NewParams( DefaultUploadTimeout, - DefaultStorageCost, + DefaultStorageCosts, DefaultNetworkFee, DefaultMaxPoints, ) @@ -48,8 +49,10 @@ func (p Params) Validate() error { return err } - if err := util.ValidateDecimal(p.StorageCost); err != nil { - return err + for _, v := range p.StorageCosts { + if err := util.ValidateDecimal(v.Cost); err != nil { + return err + } } if err := util.ValidatePercentage(p.NetworkFee); err != nil { diff --git a/x/bundles/types/params.pb.go b/x/bundles/types/params.pb.go index 4413334d..0bc8581c 100644 --- a/x/bundles/types/params.pb.go +++ b/x/bundles/types/params.pb.go @@ -24,12 +24,60 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// StorageCost defines the cost for storage providers +type StorageCost struct { + // storage_provider_id ... + StorageProviderId uint32 `protobuf:"varint,1,opt,name=storage_provider_id,json=storageProviderId,proto3" json:"storage_provider_id,omitempty"` + // cost ... + Cost cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=cost,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"cost"` +} + +func (m *StorageCost) Reset() { *m = StorageCost{} } +func (m *StorageCost) String() string { return proto.CompactTextString(m) } +func (*StorageCost) ProtoMessage() {} +func (*StorageCost) Descriptor() ([]byte, []int) { + return fileDescriptor_cfd3a74b72a01aaa, []int{0} +} +func (m *StorageCost) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StorageCost) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StorageCost.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 *StorageCost) XXX_Merge(src proto.Message) { + xxx_messageInfo_StorageCost.Merge(m, src) +} +func (m *StorageCost) XXX_Size() int { + return m.Size() +} +func (m *StorageCost) XXX_DiscardUnknown() { + xxx_messageInfo_StorageCost.DiscardUnknown(m) +} + +var xxx_messageInfo_StorageCost proto.InternalMessageInfo + +func (m *StorageCost) GetStorageProviderId() uint32 { + if m != nil { + return m.StorageProviderId + } + return 0 +} + // Params defines the bundles module parameters. type Params struct { // upload_timeout ... UploadTimeout uint64 `protobuf:"varint,1,opt,name=upload_timeout,json=uploadTimeout,proto3" json:"upload_timeout,omitempty"` - // storage_cost ... - StorageCost cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=storage_cost,json=storageCost,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"storage_cost"` + // storage_costs ... + StorageCosts []StorageCost `protobuf:"bytes,2,rep,name=storage_costs,json=storageCosts,proto3" json:"storage_costs"` // network_fee ... NetworkFee cosmossdk_io_math.LegacyDec `protobuf:"bytes,3,opt,name=network_fee,json=networkFee,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"network_fee"` // max_points ... @@ -40,7 +88,7 @@ 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_cfd3a74b72a01aaa, []int{0} + return fileDescriptor_cfd3a74b72a01aaa, []int{1} } func (m *Params) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -76,6 +124,13 @@ func (m *Params) GetUploadTimeout() uint64 { return 0 } +func (m *Params) GetStorageCosts() []StorageCost { + if m != nil { + return m.StorageCosts + } + return nil +} + func (m *Params) GetMaxPoints() uint64 { if m != nil { return m.MaxPoints @@ -84,32 +139,75 @@ func (m *Params) GetMaxPoints() uint64 { } func init() { + proto.RegisterType((*StorageCost)(nil), "kyve.bundles.v1beta1.StorageCost") proto.RegisterType((*Params)(nil), "kyve.bundles.v1beta1.Params") } func init() { proto.RegisterFile("kyve/bundles/v1beta1/params.proto", fileDescriptor_cfd3a74b72a01aaa) } var fileDescriptor_cfd3a74b72a01aaa = []byte{ - // 300 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x90, 0xc1, 0x4a, 0xf3, 0x40, - 0x14, 0x85, 0x33, 0xff, 0x5f, 0x0a, 0x9d, 0xaa, 0x8b, 0xd0, 0x45, 0x50, 0x4c, 0xab, 0x22, 0x74, - 0x21, 0x19, 0x8a, 0x6f, 0x50, 0x6b, 0x37, 0x8a, 0x94, 0x22, 0x82, 0x6e, 0xc2, 0x64, 0x7a, 0x4d, - 0x43, 0x3b, 0xb9, 0x21, 0x73, 0x53, 0xdb, 0xb7, 0xf0, 0xb1, 0xba, 0xec, 0x52, 0x44, 0x8a, 0x34, - 0x2f, 0x22, 0x4d, 0x82, 0x6b, 0x77, 0x97, 0xc3, 0xf7, 0x1d, 0x2e, 0x87, 0x9f, 0xcd, 0x56, 0x0b, - 0x10, 0x41, 0x16, 0x4f, 0xe6, 0x60, 0xc4, 0xa2, 0x17, 0x00, 0xc9, 0x9e, 0x48, 0x64, 0x2a, 0xb5, - 0xf1, 0x92, 0x14, 0x09, 0xed, 0xd6, 0x1e, 0xf1, 0x2a, 0xc4, 0xab, 0x90, 0xe3, 0x56, 0x88, 0x21, - 0x16, 0x80, 0xd8, 0x5f, 0x25, 0x7b, 0xfe, 0xc5, 0x78, 0x7d, 0x54, 0xc8, 0xf6, 0x25, 0x3f, 0xca, - 0x92, 0x39, 0xca, 0x89, 0x4f, 0x91, 0x06, 0xcc, 0xc8, 0x61, 0x1d, 0xd6, 0xad, 0x8d, 0x0f, 0xcb, - 0xf4, 0xb1, 0x0c, 0xed, 0x21, 0x3f, 0x30, 0x84, 0xa9, 0x0c, 0xc1, 0x57, 0x68, 0xc8, 0xf9, 0xd7, - 0x61, 0xdd, 0x46, 0xff, 0x62, 0xbd, 0x6d, 0x5b, 0x9f, 0xdb, 0xf6, 0x89, 0x42, 0xa3, 0xd1, 0x98, - 0xc9, 0xcc, 0x8b, 0x50, 0x68, 0x49, 0x53, 0xef, 0x1e, 0x42, 0xa9, 0x56, 0x03, 0x50, 0xe3, 0x66, - 0x25, 0xde, 0xa0, 0x21, 0x7b, 0xc0, 0x9b, 0x31, 0xd0, 0x1b, 0xa6, 0x33, 0xff, 0x15, 0xc0, 0xf9, - 0xff, 0xf7, 0x1a, 0x5e, 0x79, 0x43, 0x00, 0xfb, 0x94, 0x73, 0x2d, 0x97, 0x7e, 0x82, 0x51, 0x4c, - 0xc6, 0xa9, 0x15, 0x0f, 0x37, 0xb4, 0x5c, 0x8e, 0x8a, 0xa0, 0x3f, 0x5c, 0xef, 0x5c, 0xb6, 0xd9, - 0xb9, 0xec, 0x7b, 0xe7, 0xb2, 0xf7, 0xdc, 0xb5, 0x36, 0xb9, 0x6b, 0x7d, 0xe4, 0xae, 0xf5, 0x72, - 0x15, 0x46, 0x34, 0xcd, 0x02, 0x4f, 0xa1, 0x16, 0x77, 0xcf, 0x4f, 0xb7, 0x0f, 0x65, 0xa7, 0x50, - 0x53, 0x19, 0xc5, 0x62, 0xf9, 0xbb, 0x30, 0xad, 0x12, 0x30, 0x41, 0xbd, 0x58, 0xeb, 0xfa, 0x27, - 0x00, 0x00, 0xff, 0xff, 0xed, 0xea, 0x8e, 0xaf, 0x7e, 0x01, 0x00, 0x00, + // 364 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xcd, 0x4a, 0xeb, 0x40, + 0x14, 0xc7, 0x93, 0x36, 0x14, 0x3a, 0xbd, 0xbd, 0x70, 0x73, 0xbb, 0x08, 0x8a, 0xe9, 0x87, 0x08, + 0x5d, 0xc8, 0x0c, 0xd5, 0x85, 0xfb, 0x5a, 0x0b, 0x62, 0x91, 0x12, 0x45, 0xd0, 0x4d, 0x98, 0x24, + 0x63, 0x1a, 0xda, 0xe4, 0x84, 0xcc, 0x24, 0xb6, 0x6f, 0xe1, 0x63, 0x75, 0xd9, 0xa5, 0xb8, 0x28, + 0x92, 0xbe, 0x88, 0xe4, 0xc3, 0x8f, 0x85, 0x0b, 0x77, 0xc9, 0xff, 0xfc, 0xce, 0x99, 0xdf, 0xe1, + 0xa0, 0xee, 0x7c, 0x95, 0x30, 0x62, 0xc5, 0x81, 0xb3, 0x60, 0x9c, 0x24, 0x03, 0x8b, 0x09, 0x3a, + 0x20, 0x21, 0x8d, 0xa8, 0xcf, 0x71, 0x18, 0x81, 0x00, 0xb5, 0x95, 0x21, 0xb8, 0x44, 0x70, 0x89, + 0xec, 0xb5, 0x5c, 0x70, 0x21, 0x07, 0x48, 0xf6, 0x55, 0xb0, 0xbd, 0x04, 0x35, 0x6e, 0x04, 0x44, + 0xd4, 0x65, 0xe7, 0xc0, 0x85, 0x8a, 0xd1, 0x7f, 0x5e, 0xfc, 0x9a, 0x61, 0x04, 0x89, 0xe7, 0xb0, + 0xc8, 0xf4, 0x1c, 0x4d, 0xee, 0xc8, 0xfd, 0xa6, 0xf1, 0xaf, 0x2c, 0x4d, 0xcb, 0xca, 0xa5, 0xa3, + 0x9e, 0x21, 0xc5, 0x06, 0x2e, 0xb4, 0x4a, 0x47, 0xee, 0xd7, 0x87, 0x87, 0xeb, 0x6d, 0x5b, 0x7a, + 0xdd, 0xb6, 0xf7, 0x6d, 0xe0, 0x3e, 0x70, 0xee, 0xcc, 0xb1, 0x07, 0xc4, 0xa7, 0x62, 0x86, 0x27, + 0xcc, 0xa5, 0xf6, 0x6a, 0xc4, 0x6c, 0x23, 0x6f, 0xe8, 0xa5, 0x32, 0xaa, 0x4d, 0x73, 0x69, 0xf5, + 0x08, 0xfd, 0x8d, 0xc3, 0x05, 0x50, 0xc7, 0x14, 0x9e, 0xcf, 0x20, 0x16, 0xf9, 0x73, 0x8a, 0xd1, + 0x2c, 0xd2, 0xdb, 0x22, 0x54, 0x27, 0xa8, 0xf9, 0xa1, 0x96, 0x4d, 0xe0, 0x5a, 0xa5, 0x53, 0xed, + 0x37, 0x4e, 0xba, 0xf8, 0xa7, 0x6d, 0xf1, 0xb7, 0xa5, 0x86, 0x4a, 0xa6, 0x65, 0xfc, 0xe1, 0x5f, + 0x11, 0x57, 0x47, 0xa8, 0x11, 0x30, 0xf1, 0x04, 0xd1, 0xdc, 0x7c, 0x64, 0x4c, 0xab, 0xfe, 0xde, + 0x1f, 0x95, 0x7d, 0x63, 0xc6, 0xd4, 0x03, 0x84, 0x7c, 0xba, 0x34, 0x43, 0xf0, 0x02, 0xc1, 0x35, + 0x25, 0xd7, 0xae, 0xfb, 0x74, 0x39, 0xcd, 0x83, 0xe1, 0x78, 0x9d, 0xea, 0xf2, 0x26, 0xd5, 0xe5, + 0xb7, 0x54, 0x97, 0x9f, 0x77, 0xba, 0xb4, 0xd9, 0xe9, 0xd2, 0xcb, 0x4e, 0x97, 0x1e, 0x8e, 0x5d, + 0x4f, 0xcc, 0x62, 0x0b, 0xdb, 0xe0, 0x93, 0xab, 0xfb, 0xbb, 0x8b, 0xeb, 0x62, 0x26, 0xb1, 0x67, + 0xd4, 0x0b, 0xc8, 0xf2, 0xf3, 0xbe, 0x62, 0x15, 0x32, 0x6e, 0xd5, 0xf2, 0x5b, 0x9d, 0xbe, 0x07, + 0x00, 0x00, 0xff, 0xff, 0xc3, 0xde, 0x6b, 0xd2, 0xfc, 0x01, 0x00, 0x00, +} + +func (m *StorageCost) 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 *StorageCost) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StorageCost) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Cost.Size() + i -= size + if _, err := m.Cost.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if m.StorageProviderId != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.StorageProviderId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -147,16 +245,20 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { } i-- dAtA[i] = 0x1a - { - size := m.StorageCost.Size() - i -= size - if _, err := m.StorageCost.MarshalTo(dAtA[i:]); err != nil { - return 0, err + if len(m.StorageCosts) > 0 { + for iNdEx := len(m.StorageCosts) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.StorageCosts[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 } - i = encodeVarintParams(dAtA, i, uint64(size)) } - i-- - dAtA[i] = 0x12 if m.UploadTimeout != 0 { i = encodeVarintParams(dAtA, i, uint64(m.UploadTimeout)) i-- @@ -176,6 +278,20 @@ func encodeVarintParams(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *StorageCost) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.StorageProviderId != 0 { + n += 1 + sovParams(uint64(m.StorageProviderId)) + } + l = m.Cost.Size() + n += 1 + l + sovParams(uint64(l)) + return n +} + func (m *Params) Size() (n int) { if m == nil { return 0 @@ -185,8 +301,12 @@ func (m *Params) Size() (n int) { if m.UploadTimeout != 0 { n += 1 + sovParams(uint64(m.UploadTimeout)) } - l = m.StorageCost.Size() - n += 1 + l + sovParams(uint64(l)) + if len(m.StorageCosts) > 0 { + for _, e := range m.StorageCosts { + l = e.Size() + n += 1 + l + sovParams(uint64(l)) + } + } l = m.NetworkFee.Size() n += 1 + l + sovParams(uint64(l)) if m.MaxPoints != 0 { @@ -201,6 +321,109 @@ func sovParams(x uint64) (n int) { func sozParams(x uint64) (n int) { return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *StorageCost) 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: StorageCost: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: StorageCost: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StorageProviderId", wireType) + } + m.StorageProviderId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StorageProviderId |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Cost", 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 + } + if err := m.Cost.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + 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 @@ -251,9 +474,9 @@ func (m *Params) Unmarshal(dAtA []byte) error { } case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StorageCost", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field StorageCosts", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowParams @@ -263,23 +486,23 @@ func (m *Params) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthParams } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthParams } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.StorageCost.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.StorageCosts = append(m.StorageCosts, StorageCost{}) + if err := m.StorageCosts[len(m.StorageCosts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/stakers/keeper/msg_server_claim_commission_rewards_test.go b/x/stakers/keeper/msg_server_claim_commission_rewards_test.go index c6da4844..f07d1669 100644 --- a/x/stakers/keeper/msg_server_claim_commission_rewards_test.go +++ b/x/stakers/keeper/msg_server_claim_commission_rewards_test.go @@ -164,7 +164,7 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100).TruncateInt64()) totalUploaderReward := pool.InflationShareWeight - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -201,7 +201,7 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100).TruncateInt64()) totalUploaderReward := pool.InflationShareWeight - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -229,7 +229,7 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100).TruncateInt64()) totalUploaderReward := pool.InflationShareWeight - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -253,7 +253,7 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100).TruncateInt64()) totalUploaderReward := pool.InflationShareWeight - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -279,7 +279,7 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100).TruncateInt64()) totalUploaderReward := pool.InflationShareWeight - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -305,7 +305,7 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64()) - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100).TruncateInt64()) totalUploaderReward := pool.InflationShareWeight - treasuryReward - storageReward uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) @@ -377,7 +377,7 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { networkFee = s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward = uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64()) - storageReward = uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + storageReward = uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100).TruncateInt64()) totalUploaderReward = pool.InflationShareWeight - treasuryReward - storageReward uploaderPayoutReward = uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64())