diff --git a/api/poktroll/shared/service.pulsar.go b/api/poktroll/shared/service.pulsar.go index 131bf6936..a923eda0b 100644 --- a/api/poktroll/shared/service.pulsar.go +++ b/api/poktroll/shared/service.pulsar.go @@ -2,7 +2,6 @@ package shared import ( - binary "encoding/binary" fmt "fmt" _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" @@ -11,7 +10,6 @@ import ( protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - math "math" reflect "reflect" sync "sync" ) @@ -2418,8 +2416,8 @@ func (x *fastReflection_ServiceRevenueShare) Range(f func(protoreflect.FieldDesc return } } - if x.RevSharePercentage != float64(0) || math.Signbit(x.RevSharePercentage) { - value := protoreflect.ValueOfFloat64(x.RevSharePercentage) + if x.RevSharePercentage != uint64(0) { + value := protoreflect.ValueOfUint64(x.RevSharePercentage) if !f(fd_ServiceRevenueShare_rev_share_percentage, value) { return } @@ -2442,7 +2440,7 @@ func (x *fastReflection_ServiceRevenueShare) Has(fd protoreflect.FieldDescriptor case "poktroll.shared.ServiceRevenueShare.address": return x.Address != "" case "poktroll.shared.ServiceRevenueShare.rev_share_percentage": - return x.RevSharePercentage != float64(0) || math.Signbit(x.RevSharePercentage) + return x.RevSharePercentage != uint64(0) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.shared.ServiceRevenueShare")) @@ -2462,7 +2460,7 @@ func (x *fastReflection_ServiceRevenueShare) Clear(fd protoreflect.FieldDescript case "poktroll.shared.ServiceRevenueShare.address": x.Address = "" case "poktroll.shared.ServiceRevenueShare.rev_share_percentage": - x.RevSharePercentage = float64(0) + x.RevSharePercentage = uint64(0) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.shared.ServiceRevenueShare")) @@ -2484,7 +2482,7 @@ func (x *fastReflection_ServiceRevenueShare) Get(descriptor protoreflect.FieldDe return protoreflect.ValueOfString(value) case "poktroll.shared.ServiceRevenueShare.rev_share_percentage": value := x.RevSharePercentage - return protoreflect.ValueOfFloat64(value) + return protoreflect.ValueOfUint64(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.shared.ServiceRevenueShare")) @@ -2508,7 +2506,7 @@ func (x *fastReflection_ServiceRevenueShare) Set(fd protoreflect.FieldDescriptor case "poktroll.shared.ServiceRevenueShare.address": x.Address = value.Interface().(string) case "poktroll.shared.ServiceRevenueShare.rev_share_percentage": - x.RevSharePercentage = value.Float() + x.RevSharePercentage = value.Uint() default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.shared.ServiceRevenueShare")) @@ -2549,7 +2547,7 @@ func (x *fastReflection_ServiceRevenueShare) NewField(fd protoreflect.FieldDescr case "poktroll.shared.ServiceRevenueShare.address": return protoreflect.ValueOfString("") case "poktroll.shared.ServiceRevenueShare.rev_share_percentage": - return protoreflect.ValueOfFloat64(float64(0)) + return protoreflect.ValueOfUint64(uint64(0)) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.shared.ServiceRevenueShare")) @@ -2623,8 +2621,8 @@ func (x *fastReflection_ServiceRevenueShare) ProtoMethods() *protoiface.Methods if l > 0 { n += 1 + l + runtime.Sov(uint64(l)) } - if x.RevSharePercentage != 0 || math.Signbit(x.RevSharePercentage) { - n += 9 + if x.RevSharePercentage != 0 { + n += 1 + runtime.Sov(uint64(x.RevSharePercentage)) } if x.unknownFields != nil { n += len(x.unknownFields) @@ -2655,11 +2653,10 @@ func (x *fastReflection_ServiceRevenueShare) ProtoMethods() *protoiface.Methods i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } - if x.RevSharePercentage != 0 || math.Signbit(x.RevSharePercentage) { - i -= 8 - binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(x.RevSharePercentage)))) + if x.RevSharePercentage != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.RevSharePercentage)) i-- - dAtA[i] = 0x19 + dAtA[i] = 0x18 } if len(x.Address) > 0 { i -= len(x.Address) @@ -2750,16 +2747,24 @@ func (x *fastReflection_ServiceRevenueShare) ProtoMethods() *protoiface.Methods x.Address = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: - if wireType != 1 { + if wireType != 0 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field RevSharePercentage", wireType) } - var v uint64 - if (iNdEx + 8) > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + x.RevSharePercentage = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.RevSharePercentage |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } } - v = uint64(binary.LittleEndian.Uint64(dAtA[iNdEx:])) - iNdEx += 8 - x.RevSharePercentage = float64(math.Float64frombits(v)) default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -3598,8 +3603,8 @@ type ServiceRevenueShare struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` // The Bech32 address of the revenue share recipient - RevSharePercentage float64 `protobuf:"fixed64,3,opt,name=rev_share_percentage,json=revSharePercentage,proto3" json:"rev_share_percentage,omitempty"` // The percentage of revenue share the recipient will receive + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` // The Bech32 address of the revenue share recipient + RevSharePercentage uint64 `protobuf:"varint,3,opt,name=rev_share_percentage,json=revSharePercentage,proto3" json:"rev_share_percentage,omitempty"` // The percentage of revenue share the recipient will receive } func (x *ServiceRevenueShare) Reset() { @@ -3629,7 +3634,7 @@ func (x *ServiceRevenueShare) GetAddress() string { return "" } -func (x *ServiceRevenueShare) GetRevSharePercentage() float64 { +func (x *ServiceRevenueShare) GetRevSharePercentage() uint64 { if x != nil { return x.RevSharePercentage } @@ -3730,7 +3735,7 @@ var file_poktroll_shared_service_proto_rawDesc = []byte{ 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x30, 0x0a, 0x14, 0x72, 0x65, 0x76, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x65, - 0x72, 0x63, 0x65, 0x6e, 0x74, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x01, 0x52, 0x12, + 0x72, 0x63, 0x65, 0x6e, 0x74, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x12, 0x72, 0x65, 0x76, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x65, 0x72, 0x63, 0x65, 0x6e, 0x74, 0x61, 0x67, 0x65, 0x4a, 0x04, 0x08, 0x02, 0x10, 0x03, 0x22, 0x56, 0x0a, 0x0c, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x30, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, diff --git a/config.yml b/config.yml index 5be451816..cbd3fbe25 100644 --- a/config.yml +++ b/config.yml @@ -229,7 +229,7 @@ genesis: url: http://relayminer1:8545 rev_share: - address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj - rev_share_percentage: "100" + rev_share_percentage: 100 - service_id: rest endpoints: - configs: [] @@ -237,7 +237,7 @@ genesis: url: http://relayminer1:8545 rev_share: - address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj - rev_share_percentage: "100" + rev_share_percentage: 100 - service_id: ollama endpoints: - configs: [] @@ -245,7 +245,7 @@ genesis: url: http://relayminer1:8545 rev_share: - address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj - rev_share_percentage: "100" + rev_share_percentage: 100 stake: # NB: This value should be exactly 1upokt smaller than the value in # `supplier1_stake_config.yaml` so that the stake command causes a state change. diff --git a/localnet/poktrolld/config/supplier1_stake_config.yaml b/localnet/poktrolld/config/supplier1_stake_config.yaml index e3d475939..046fddb4c 100644 --- a/localnet/poktrolld/config/supplier1_stake_config.yaml +++ b/localnet/poktrolld/config/supplier1_stake_config.yaml @@ -2,8 +2,8 @@ owner_address: pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4 operator_address: pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4 stake_amount: 1000069upokt default_rev_share_percent: - pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4: 80.5 - pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw: 19.5 + pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4: 80 + pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw: 20 services: - service_id: anvil endpoints: diff --git a/localnet/poktrolld/config/supplier_stake_config_example.yaml b/localnet/poktrolld/config/supplier_stake_config_example.yaml index ce14f4a08..2fef94f0b 100644 --- a/localnet/poktrolld/config/supplier_stake_config_example.yaml +++ b/localnet/poktrolld/config/supplier_stake_config_example.yaml @@ -30,8 +30,8 @@ stake_amount: 1000069upokt # or include at least one item. default_rev_share_percent: # The sum of all shares MUST equal 100%. Staking will fail otherwise. - pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4: 80.5 - pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw: 19.5 + pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4: 80 + pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw: 20 services: # The endpoint URL for the Anvil service is provided via the RelayMiner. # The RelayMiner acts as a proxy, forwarding requests to the actual Anvil data node behind it. diff --git a/proto/poktroll/shared/service.proto b/proto/poktroll/shared/service.proto index 8d400dd33..9a5cdd470 100644 --- a/proto/poktroll/shared/service.proto +++ b/proto/poktroll/shared/service.proto @@ -57,11 +57,12 @@ message SupplierEndpoint { // ServiceRevenueShare message to hold revenue share configuration details message ServiceRevenueShare { - // 2 was reserved in #1028 during the change of rev_share_percentage from float to double + // 2 was reserved in #1028 during the change of rev_share_percentage from float to uint64 + // TODO_TECHDEBT: Investigate why we can't use a double or float: https://github.com/pokt-network/poktroll/actions/runs/12832899448/job/35787150432?pr=1028 reserved 2; string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the revenue share recipient - double rev_share_percentage = 3; // The percentage of revenue share the recipient will receive + uint64 rev_share_percentage = 3; // The percentage of revenue share the recipient will receive } // Enum to define RPC types diff --git a/testutil/integration/app.go b/testutil/integration/app.go index 25d0a0c6e..04305089a 100644 --- a/testutil/integration/app.go +++ b/testutil/integration/app.go @@ -908,7 +908,7 @@ func (app *App) setupDefaultActorsState( RevShare: []*sharedtypes.ServiceRevenueShare{ { Address: sample.AccAddress(), - RevSharePercentage: 100, + RevSharePercentage: uint64(100), }, }, ServiceId: defaultService.Id, diff --git a/testutil/keeper/tokenomics.go b/testutil/keeper/tokenomics.go index 626aa5b11..31f5dc53a 100644 --- a/testutil/keeper/tokenomics.go +++ b/testutil/keeper/tokenomics.go @@ -146,7 +146,7 @@ func TokenomicsKeeperWithActorAddrs(t testing.TB) ( RevShare: []*sharedtypes.ServiceRevenueShare{ { Address: supplierOwnerAddr, - RevSharePercentage: 100, + RevSharePercentage: uint64(100), }, }, }, diff --git a/x/shared/types/service.pb.go b/x/shared/types/service.pb.go index b483b2743..6da21cd5f 100644 --- a/x/shared/types/service.pb.go +++ b/x/shared/types/service.pb.go @@ -7,7 +7,6 @@ package types import ( - encoding_binary "encoding/binary" fmt "fmt" _ "github.com/cosmos/cosmos-proto" _ "github.com/cosmos/gogoproto/gogoproto" @@ -321,8 +320,8 @@ func (m *SupplierEndpoint) GetConfigs() []*ConfigOption { // ServiceRevenueShare message to hold revenue share configuration details type ServiceRevenueShare struct { - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - RevSharePercentage float64 `protobuf:"fixed64,3,opt,name=rev_share_percentage,json=revSharePercentage,proto3" json:"rev_share_percentage,omitempty"` + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + RevSharePercentage uint64 `protobuf:"varint,3,opt,name=rev_share_percentage,json=revSharePercentage,proto3" json:"rev_share_percentage,omitempty"` } func (m *ServiceRevenueShare) Reset() { *m = ServiceRevenueShare{} } @@ -361,7 +360,7 @@ func (m *ServiceRevenueShare) GetAddress() string { return "" } -func (m *ServiceRevenueShare) GetRevSharePercentage() float64 { +func (m *ServiceRevenueShare) GetRevSharePercentage() uint64 { if m != nil { return m.RevSharePercentage } @@ -431,7 +430,7 @@ func init() { func init() { proto.RegisterFile("poktroll/shared/service.proto", fileDescriptor_302c2f793a11ae1e) } var fileDescriptor_302c2f793a11ae1e = []byte{ - // 630 bytes of a gzipped FileDescriptorProto + // 628 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcf, 0x6e, 0xd3, 0x4e, 0x10, 0xce, 0xc6, 0xf9, 0xfd, 0x92, 0x4c, 0xdb, 0xd4, 0x1a, 0x82, 0x30, 0x95, 0x6a, 0x95, 0x88, 0x43, 0x55, 0xa9, 0x49, 0x95, 0x0a, 0x21, 0x0e, 0x08, 0xb5, 0x51, 0xa8, 0xda, 0xaa, 0x49, 0xb4, @@ -458,20 +457,20 @@ var fileDescriptor_302c2f793a11ae1e = []byte{ 0x85, 0x41, 0x74, 0xd0, 0x19, 0x4e, 0x03, 0x46, 0xcb, 0x22, 0xb0, 0x65, 0x80, 0x4f, 0xa1, 0x6c, 0x27, 0x46, 0x84, 0x99, 0xb8, 0xf5, 0x85, 0x9a, 0xd4, 0xa8, 0x7e, 0x20, 0x4d, 0xa7, 0x39, 0xbb, 0xf1, 0x8e, 0xc0, 0xbd, 0xdf, 0xc8, 0xc6, 0x36, 0x94, 0xf3, 0xdb, 0x25, 0x7f, 0xb9, 0xdd, 0x9c, - 0x88, 0x3b, 0x50, 0x9f, 0x7b, 0x24, 0x57, 0xc9, 0x66, 0x7e, 0x64, 0x8d, 0x58, 0xb2, 0x4b, 0x84, - 0x62, 0x6e, 0xc4, 0x60, 0x8e, 0x1c, 0x95, 0x2a, 0x45, 0x55, 0x69, 0xbc, 0x82, 0xe5, 0x9f, 0xc5, - 0xe1, 0x0e, 0x28, 0x97, 0x6c, 0x9a, 0xcc, 0xad, 0xb5, 0xf5, 0x3f, 0x1e, 0x24, 0xa4, 0x92, 0x8a, - 0x75, 0xf8, 0x6f, 0x62, 0x79, 0x71, 0xbe, 0xdd, 0xe9, 0xc7, 0xd6, 0x31, 0x94, 0x33, 0xa3, 0x70, - 0x15, 0x96, 0x4e, 0x7b, 0xc7, 0xbd, 0xfe, 0x59, 0xcf, 0xa4, 0x83, 0x8e, 0x5a, 0xc0, 0x0a, 0x94, - 0x0e, 0x64, 0x44, 0x70, 0x05, 0xaa, 0x67, 0xdd, 0x7d, 0xa3, 0xdf, 0x39, 0xee, 0x0e, 0xd5, 0x22, - 0x2e, 0x43, 0xe5, 0xc8, 0xe8, 0xa7, 0x34, 0x45, 0xd2, 0x68, 0xd7, 0x18, 0xaa, 0xa5, 0xad, 0x1d, - 0x58, 0xf9, 0x65, 0x30, 0x22, 0xd4, 0xf2, 0x96, 0x9d, 0x7e, 0xef, 0xe5, 0xe1, 0x81, 0x5a, 0xc0, - 0x25, 0x28, 0x0f, 0x0f, 0x4f, 0xba, 0xfd, 0xd3, 0xa1, 0x4a, 0xf6, 0x4f, 0xbe, 0xcc, 0x74, 0x72, - 0x3d, 0xd3, 0xc9, 0xcd, 0x4c, 0x27, 0xdf, 0x66, 0x3a, 0x79, 0x7f, 0xab, 0x17, 0xae, 0x6f, 0xf5, - 0xc2, 0xcd, 0xad, 0x5e, 0x78, 0xdd, 0x1a, 0xb9, 0xd1, 0x45, 0x7c, 0xde, 0xb4, 0xf9, 0xb8, 0x25, - 0x4f, 0xb8, 0xed, 0xb3, 0xe8, 0x8a, 0x8b, 0xcb, 0xd6, 0xfc, 0x91, 0x78, 0x9b, 0x3f, 0x13, 0x72, - 0x15, 0xc2, 0xf3, 0xff, 0x93, 0x7f, 0x7c, 0xf7, 0x7b, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1e, 0x46, - 0x55, 0xcc, 0x46, 0x04, 0x00, 0x00, + 0x88, 0x3b, 0x50, 0x9f, 0x7b, 0x24, 0x57, 0xc9, 0x66, 0x7e, 0x64, 0x8d, 0x58, 0xb6, 0x4b, 0x98, + 0x1b, 0x31, 0x98, 0x23, 0x47, 0xa5, 0x4a, 0x51, 0x55, 0x1a, 0xaf, 0x60, 0xf9, 0x67, 0x71, 0xb8, + 0x03, 0xca, 0x25, 0x9b, 0x26, 0x73, 0x6b, 0x6d, 0xfd, 0x8f, 0x07, 0x09, 0xa9, 0xa4, 0x62, 0x1d, + 0xfe, 0x9b, 0x58, 0x5e, 0x9c, 0x6f, 0x77, 0xfa, 0xb1, 0x75, 0x0c, 0xe5, 0xcc, 0x28, 0x5c, 0x85, + 0xa5, 0xd3, 0xde, 0x71, 0xaf, 0x7f, 0xd6, 0x33, 0xe9, 0xa0, 0xa3, 0x16, 0xb0, 0x02, 0xa5, 0x03, + 0x19, 0x11, 0x5c, 0x81, 0xea, 0x59, 0x77, 0xdf, 0xe8, 0x77, 0x8e, 0xbb, 0x43, 0xb5, 0x88, 0xcb, + 0x50, 0x39, 0x32, 0xfa, 0x29, 0x4d, 0x91, 0x34, 0xda, 0x35, 0x86, 0x6a, 0x69, 0x6b, 0x07, 0x56, + 0x7e, 0x19, 0x8c, 0x08, 0xb5, 0xbc, 0x65, 0xa7, 0xdf, 0x7b, 0x79, 0x78, 0xa0, 0x16, 0x70, 0x09, + 0xca, 0xc3, 0xc3, 0x93, 0x6e, 0xff, 0x74, 0xa8, 0x92, 0xfd, 0x93, 0x2f, 0x33, 0x9d, 0x5c, 0xcf, + 0x74, 0x72, 0x33, 0xd3, 0xc9, 0xb7, 0x99, 0x4e, 0xde, 0xdf, 0xea, 0x85, 0xeb, 0x5b, 0xbd, 0x70, + 0x73, 0xab, 0x17, 0x5e, 0xb7, 0x46, 0x6e, 0x74, 0x11, 0x9f, 0x37, 0x6d, 0x3e, 0x6e, 0xc9, 0x13, + 0x6e, 0xfb, 0x2c, 0xba, 0xe2, 0xe2, 0xb2, 0x35, 0x7f, 0x24, 0xde, 0xe6, 0xcf, 0x84, 0x5c, 0x85, + 0xf0, 0xfc, 0xff, 0xe4, 0x1f, 0xdf, 0xfd, 0x1e, 0x00, 0x00, 0xff, 0xff, 0x46, 0xaf, 0x53, 0xa2, + 0x46, 0x04, 0x00, 0x00, } func (m *Service) Marshal() (dAtA []byte, err error) { @@ -681,10 +680,9 @@ func (m *ServiceRevenueShare) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if m.RevSharePercentage != 0 { - i -= 8 - encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(m.RevSharePercentage)))) + i = encodeVarintService(dAtA, i, uint64(m.RevSharePercentage)) i-- - dAtA[i] = 0x19 + dAtA[i] = 0x18 } if len(m.Address) > 0 { i -= len(m.Address) @@ -837,7 +835,7 @@ func (m *ServiceRevenueShare) Size() (n int) { n += 1 + l + sovService(uint64(l)) } if m.RevSharePercentage != 0 { - n += 9 + n += 1 + sovService(uint64(m.RevSharePercentage)) } return n } @@ -1458,16 +1456,24 @@ func (m *ServiceRevenueShare) Unmarshal(dAtA []byte) error { m.Address = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: - if wireType != 1 { + if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field RevSharePercentage", wireType) } - var v uint64 - if (iNdEx + 8) > l { - return io.ErrUnexpectedEOF + m.RevSharePercentage = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RevSharePercentage |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } } - v = uint64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) - iNdEx += 8 - m.RevSharePercentage = float64(math.Float64frombits(v)) default: iNdEx = preIndex skippy, err := skipService(dAtA[iNdEx:]) diff --git a/x/shared/types/service_configs.go b/x/shared/types/service_configs.go index 019f8f442..bcfb3935e 100644 --- a/x/shared/types/service_configs.go +++ b/x/shared/types/service_configs.go @@ -7,7 +7,7 @@ import ( ) const ( - requiredRevSharePercentageSum = 100 + requiredRevSharePercentageSum = uint64(100) ) // ValidateAppServiceConfigs returns an error if any of the application service configs are invalid @@ -95,7 +95,7 @@ func ValidateSupplierServiceConfigs(services []*SupplierServiceConfig) error { // ensuring that the sum of the revenue share percentages is 100. // NB: This function is unit tested via the supplier staking config tests. func ValidateServiceRevShare(revShareList []*ServiceRevenueShare) error { - revSharePercentageSum := float64(0) + revSharePercentageSum := uint64(0) if len(revShareList) == 0 { return ErrSharedInvalidRevShare.Wrap("no rev share configurations") @@ -106,7 +106,7 @@ func ValidateServiceRevShare(revShareList []*ServiceRevenueShare) error { return ErrSharedInvalidRevShare.Wrap("rev share cannot be nil") } - // Validate the revshare address + // Validate the revenue share address if revShare.Address == "" { return ErrSharedInvalidRevShare.Wrapf("rev share address cannot be empty: %v", revShare) } diff --git a/x/supplier/config/supplier_configs_reader.go b/x/supplier/config/supplier_configs_reader.go index e07cc68c7..6c604677e 100644 --- a/x/supplier/config/supplier_configs_reader.go +++ b/x/supplier/config/supplier_configs_reader.go @@ -19,14 +19,14 @@ type YAMLStakeConfig struct { OperatorAddress string `yaml:"operator_address"` StakeAmount string `yaml:"stake_amount"` Services []*YAMLStakeService `yaml:"services"` - DefaultRevSharePercent map[string]float64 `yaml:"default_rev_share_percent"` + DefaultRevSharePercent map[string]uint64 `yaml:"default_rev_share_percent"` } // YAMLStakeService is the structure describing a single service entry in the // stake config file. type YAMLStakeService struct { ServiceId string `yaml:"service_id"` - RevSharePercent map[string]float64 `yaml:"rev_share_percent"` + RevSharePercent map[string]uint64 `yaml:"rev_share_percent"` Endpoints []YAMLServiceEndpoint `yaml:"endpoints"` } @@ -102,7 +102,7 @@ func ParseSupplierConfigs(ctx context.Context, configContent []byte) (*SupplierS ) } - defaultRevSharePercent := map[string]float64{} + defaultRevSharePercent := map[string]uint64{} if len(stakeConfig.DefaultRevSharePercent) == 0 { // Ensure that if no default rev share is provided, the owner address is set // to 100% rev share. diff --git a/x/supplier/config/supplier_configs_reader_test.go b/x/supplier/config/supplier_configs_reader_test.go index f5d557345..5b0f149bc 100644 --- a/x/supplier/config/supplier_configs_reader_test.go +++ b/x/supplier/config/supplier_configs_reader_test.go @@ -287,8 +287,8 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { owner_address: %s operator_address: %s default_rev_share_percent: - %s: 50.5 - %s: 49.5 + %s: 51 + %s: 49 stake_amount: 1000upokt services: # Service with default rev share @@ -322,11 +322,11 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { RevShare: []*types.ServiceRevenueShare{ { Address: firstShareHolderAddress, - RevSharePercentage: 50.5, + RevSharePercentage: 51, }, { Address: secondShareHolderAddress, - RevSharePercentage: 49.5, + RevSharePercentage: 49, }, }, }, @@ -728,24 +728,6 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) { `, ownerAddress, operatorAddress, firstShareHolderAddress, ""), expectedError: config.ErrSupplierConfigUnmarshalYAML, }, - { - desc: "negative revenue share allocation is disallowed", - inputConfig: fmt.Sprintf(` - owner_address: %s - operator_address: %s - stake_amount: 1000upokt - services: - - service_id: svc - endpoints: - - publicly_exposed_url: http://pokt.network:8081 - rpc_type: json_rpc - rev_share_percent: - %s: 90 - %s: 11 - %s: -1 - `, ownerAddress, operatorAddress, ownerAddress, firstShareHolderAddress, secondShareHolderAddress), - expectedError: sharedtypes.ErrSharedInvalidRevShare, - }, { desc: "errors when the rev share config is empty", inputConfig: fmt.Sprintf(` diff --git a/x/tokenomics/keeper/token_logic_modules_test.go b/x/tokenomics/keeper/token_logic_modules_test.go index 9f955e735..eae0d4628 100644 --- a/x/tokenomics/keeper/token_logic_modules_test.go +++ b/x/tokenomics/keeper/token_logic_modules_test.go @@ -45,7 +45,7 @@ func TestProcessTokenLogicModules_TLMBurnEqualsMint_Valid(t *testing.T) { // Test Parameters appInitialStake := apptypes.DefaultMinStake.Amount.Mul(cosmosmath.NewInt(2)) supplierInitialStake := cosmosmath.NewInt(1000000) - supplierRevShareRatios := []float64{12.5, 37.5, 50} + supplierRevShareRatios := []uint64{12, 38, 50} globalComputeUnitsToTokensMultiplier := uint64(1) serviceComputeUnitsPerRelay := uint64(1) service := prepareTestService(serviceComputeUnitsPerRelay) @@ -185,7 +185,7 @@ func TestProcessTokenLogicModules_TLMBurnEqualsMint_Valid_SupplierExceedsMaxClai service := prepareTestService(serviceComputeUnitsPerRelay) numRelays := uint64(1000) // By a single supplier for application in this session supplierInitialStake := cosmosmath.NewInt(1000000) - supplierRevShareRatios := []float64{12.5, 37.5, 50} + supplierRevShareRatios := []uint64{12, 38, 50} // Prepare the keepers keepers, ctx := testkeeper.NewTokenomicsModuleKeepers(t, @@ -338,7 +338,7 @@ func TestProcessTokenLogicModules_TLMGlobalMint_Valid_MintDistributionCorrect(t // Test Parameters appInitialStake := apptypes.DefaultMinStake.Amount.Mul(cosmosmath.NewInt(2)) supplierInitialStake := cosmosmath.NewInt(1000000) - supplierRevShareRatios := []float64{12.5, 37.5, 50} + supplierRevShareRatios := []uint64{12, 38, 50} globalComputeUnitsToTokensMultiplier := uint64(1) serviceComputeUnitsPerRelay := uint64(1) service := prepareTestService(serviceComputeUnitsPerRelay) @@ -458,8 +458,8 @@ func TestProcessTokenLogicModules_TLMGlobalMint_Valid_MintDistributionCorrect(t addr := revShare.Address balanceBefore := supplierShareholderBalancesBefore[addr] balanceAfter := supplierShareholderBalancesAfter[addr].Amount.Int64() - mintShare := int64(supplierMint * revShare.RevSharePercentage / 100) - rewardShare := int64(float64(numTokensClaimed) * revShare.RevSharePercentage / 100) + mintShare := int64(supplierMint * float64(revShare.RevSharePercentage) / 100.0) + rewardShare := int64(float64(numTokensClaimed) * float64(revShare.RevSharePercentage) / 100.0) balanceIncrease := cosmosmath.NewInt(mintShare + rewardShare) expectedBalanceAfter := balanceBefore.Amount.Add(balanceIncrease).Int64() // TODO_MAINNET(@red-0ne): Remove the InDelta check and use the exact amount once the floating point arithmetic is fixed diff --git a/x/tokenomics/token_logic_module/distribution.go b/x/tokenomics/token_logic_module/distribution.go index bdd2b5c38..f7071562d 100644 --- a/x/tokenomics/token_logic_module/distribution.go +++ b/x/tokenomics/token_logic_module/distribution.go @@ -94,7 +94,7 @@ func GetShareAmountMap( shareAmountMap = make(map[string]uint64, len(serviceRevShare)) for _, revShare := range serviceRevShare { // TODO_MAINNET(@red-0ne): Use big.Rat for deterministic results. - sharePercentageFloat := big.NewFloat(float64(revShare.RevSharePercentage) / 100) + sharePercentageFloat := big.NewFloat(float64(revShare.RevSharePercentage) / float64(100.0)) amountToDistributeFloat := big.NewFloat(float64(amountToDistribute)) shareAmount, _ := big.NewFloat(0).Mul(amountToDistributeFloat, sharePercentageFloat).Uint64() shareAmountMap[revShare.Address] = shareAmount