From da70c0e29a34353d0fd1a106cc834003585e49ad Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 22 May 2024 13:50:07 +0200 Subject: [PATCH] [Session] add `num_blocks_per_session` param (#530) Co-authored-by: Daniel Olshansky --- Makefile | 7 ++ api/poktroll/session/params.pulsar.go | 94 +++++++++++++++---- api/poktroll/session/tx.pulsar.go | 53 ++++++----- config.yml | 7 ++ e2e/tests/params_types_test.go | 5 - e2e/tests/parse_params_test.go | 74 ++++++++++++++- e2e/tests/update_params.feature | 15 ++- e2e/tests/update_params_test.go | 75 ++++++++++++--- proto/poktroll/session/params.proto | 2 + proto/poktroll/session/tx.proto | 2 +- .../proof_min_relay_difficulty_bits.json | 2 +- tools/scripts/params/session_all.json | 13 +++ ...cs_compute_units_to_tokens_multiplier.json | 2 +- x/application/types/params.go | 2 + x/proof/keeper/msg_server_update_param.go | 2 +- .../keeper/msg_server_update_param_test.go | 2 +- x/proof/types/message_update_param.go | 2 +- x/proof/types/message_update_param_test.go | 4 +- x/proof/types/params.go | 6 +- x/service/types/params.go | 5 +- x/session/keeper/msg_update_params_test.go | 2 +- x/session/module/genesis_test.go | 5 +- x/session/types/errors.go | 2 + x/session/types/genesis.go | 2 +- x/session/types/message_update_params.go | 2 +- x/session/types/params.go | 47 ++++++++-- x/session/types/params_test.go | 42 +++++++++ .../keeper/msg_server_update_param.go | 2 +- .../keeper/msg_server_update_param_test.go | 2 +- x/tokenomics/types/message_update_param.go | 2 +- .../types/message_update_param_test.go | 4 +- x/tokenomics/types/params.go | 2 +- 32 files changed, 395 insertions(+), 93 deletions(-) create mode 100644 tools/scripts/params/session_all.json create mode 100644 x/session/types/params_test.go diff --git a/Makefile b/Makefile index f6101552f..2f4fa580d 100644 --- a/Makefile +++ b/Makefile @@ -807,6 +807,7 @@ claim_list_session: ## List all the claims ending at a specific session (specifi # TODO_CONSIDERATION: additional factoring (e.g. POKTROLLD_FLAGS). PARAM_FLAGS = --home=$(POKTROLLD_HOME) --keyring-backend test --from $(PNF_ADDRESS) --node $(POCKET_NODE) +### Tokenomics Module Params ### .PHONY: update_tokenomics_params_all params_update_tokenomics_all: ## Update the tokenomics module params poktrolld tx authz exec ./tools/scripts/params/tokenomics_all.json $(PARAM_FLAGS) @@ -815,6 +816,7 @@ params_update_tokenomics_all: ## Update the tokenomics module params params_update_tokenomics_compute_units_to_tokens_multiplier: ## Update the tokenomics module params poktrolld tx authz exec ./tools/scripts/params/tokenomics_compute_units_to_tokens_multiplier.json $(PARAM_FLAGS) +### Proof Module Params ### .PHONY: params_update_proof_all params_update_proof_all: ## Update the proof module params poktrolld tx authz exec ./tools/scripts/params/proof_all.json $(PARAM_FLAGS) @@ -823,6 +825,11 @@ params_update_proof_all: ## Update the proof module params params_update_proof_min_relay_difficulty_bits: ## Update the proof module params poktrolld tx authz exec ./tools/scripts/params/proof_min_relay_difficulty_bits.json $(PARAM_FLAGS) +### Session Module Params ### +.PHONY: params_update_session_all +params_update_session_all: ## Update the session module params + poktrolld tx authz exec ./tools/scripts/params/session_all.json $(PARAM_FLAGS) + .PHONY: params_query_all params_query_all: check_jq ## Query the params from all available modules @for module in $(MODULES); do \ diff --git a/api/poktroll/session/params.pulsar.go b/api/poktroll/session/params.pulsar.go index c9ea81482..39d1e8a86 100644 --- a/api/poktroll/session/params.pulsar.go +++ b/api/poktroll/session/params.pulsar.go @@ -15,12 +15,14 @@ import ( ) var ( - md_Params protoreflect.MessageDescriptor + md_Params protoreflect.MessageDescriptor + fd_Params_num_blocks_per_session protoreflect.FieldDescriptor ) func init() { file_poktroll_session_params_proto_init() md_Params = File_poktroll_session_params_proto.Messages().ByName("Params") + fd_Params_num_blocks_per_session = md_Params.Fields().ByName("num_blocks_per_session") } var _ protoreflect.Message = (*fastReflection_Params)(nil) @@ -88,6 +90,12 @@ func (x *fastReflection_Params) Interface() protoreflect.ProtoMessage { // While iterating, mutating operations may only be performed // on the current field descriptor. func (x *fastReflection_Params) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.NumBlocksPerSession != uint64(0) { + value := protoreflect.ValueOfUint64(x.NumBlocksPerSession) + if !f(fd_Params_num_blocks_per_session, value) { + return + } + } } // Has reports whether a field is populated. @@ -103,6 +111,8 @@ func (x *fastReflection_Params) Range(f func(protoreflect.FieldDescriptor, proto // a repeated field is populated if it is non-empty. func (x *fastReflection_Params) Has(fd protoreflect.FieldDescriptor) bool { switch fd.FullName() { + case "poktroll.session.Params.num_blocks_per_session": + return x.NumBlocksPerSession != uint64(0) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.session.Params")) @@ -119,6 +129,8 @@ func (x *fastReflection_Params) Has(fd protoreflect.FieldDescriptor) bool { // Clear is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Params) Clear(fd protoreflect.FieldDescriptor) { switch fd.FullName() { + case "poktroll.session.Params.num_blocks_per_session": + x.NumBlocksPerSession = uint64(0) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.session.Params")) @@ -135,6 +147,9 @@ func (x *fastReflection_Params) Clear(fd protoreflect.FieldDescriptor) { // of the value; to obtain a mutable reference, use Mutable. func (x *fastReflection_Params) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { switch descriptor.FullName() { + case "poktroll.session.Params.num_blocks_per_session": + value := x.NumBlocksPerSession + return protoreflect.ValueOfUint64(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.session.Params")) @@ -155,6 +170,8 @@ func (x *fastReflection_Params) Get(descriptor protoreflect.FieldDescriptor) pro // Set is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Params) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { switch fd.FullName() { + case "poktroll.session.Params.num_blocks_per_session": + x.NumBlocksPerSession = value.Uint() default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.session.Params")) @@ -175,6 +192,8 @@ func (x *fastReflection_Params) Set(fd protoreflect.FieldDescriptor, value proto // Mutable is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Params) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { switch fd.FullName() { + case "poktroll.session.Params.num_blocks_per_session": + panic(fmt.Errorf("field num_blocks_per_session of message poktroll.session.Params is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.session.Params")) @@ -188,6 +207,8 @@ func (x *fastReflection_Params) Mutable(fd protoreflect.FieldDescriptor) protore // For lists, maps, and messages, this returns a new, empty, mutable value. func (x *fastReflection_Params) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { switch fd.FullName() { + case "poktroll.session.Params.num_blocks_per_session": + return protoreflect.ValueOfUint64(uint64(0)) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.session.Params")) @@ -257,6 +278,9 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { var n int var l int _ = l + if x.NumBlocksPerSession != 0 { + n += 1 + runtime.Sov(uint64(x.NumBlocksPerSession)) + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -286,6 +310,11 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if x.NumBlocksPerSession != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.NumBlocksPerSession)) + i-- + dAtA[i] = 0x8 + } if input.Buf != nil { input.Buf = append(input.Buf, dAtA...) } else { @@ -335,6 +364,25 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field NumBlocksPerSession", wireType) + } + x.NumBlocksPerSession = 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.NumBlocksPerSession |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -388,6 +436,8 @@ type Params struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + + NumBlocksPerSession uint64 `protobuf:"varint,1,opt,name=num_blocks_per_session,json=numBlocksPerSession,proto3" json:"num_blocks_per_session,omitempty"` } func (x *Params) Reset() { @@ -410,6 +460,13 @@ func (*Params) Descriptor() ([]byte, []int) { return file_poktroll_session_params_proto_rawDescGZIP(), []int{0} } +func (x *Params) GetNumBlocksPerSession() uint64 { + if x != nil { + return x.NumBlocksPerSession + } + return 0 +} + var File_poktroll_session_params_proto protoreflect.FileDescriptor var file_poktroll_session_params_proto_rawDesc = []byte{ @@ -418,21 +475,26 @@ var file_poktroll_session_params_proto_rawDesc = []byte{ 0x10, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x1a, 0x11, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x14, 0x67, 0x6f, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, - 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x2c, 0x0a, 0x06, 0x50, 0x61, - 0x72, 0x61, 0x6d, 0x73, 0x3a, 0x22, 0xe8, 0xa0, 0x1f, 0x01, 0x8a, 0xe7, 0xb0, 0x2a, 0x19, 0x70, - 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x78, 0x2f, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x2f, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x42, 0xa7, 0x01, 0x0a, 0x14, 0x63, 0x6f, 0x6d, - 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x42, 0x0b, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, - 0x5a, 0x21, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, - 0x70, 0x69, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x73, 0x65, 0x73, 0x73, - 0x69, 0x6f, 0x6e, 0xa2, 0x02, 0x03, 0x50, 0x53, 0x58, 0xaa, 0x02, 0x10, 0x50, 0x6f, 0x6b, 0x74, - 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0xca, 0x02, 0x10, 0x50, - 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0xe2, - 0x02, 0x1c, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x53, 0x65, 0x73, 0x73, 0x69, - 0x6f, 0x6e, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, - 0x11, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x53, 0x65, 0x73, 0x73, 0x69, - 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x7d, 0x0a, 0x06, 0x50, 0x61, + 0x72, 0x61, 0x6d, 0x73, 0x12, 0x4f, 0x0a, 0x16, 0x6e, 0x75, 0x6d, 0x5f, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x73, 0x5f, 0x70, 0x65, 0x72, 0x5f, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x04, 0x42, 0x1a, 0xea, 0xde, 0x1f, 0x16, 0x6e, 0x75, 0x6d, 0x5f, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x73, 0x5f, 0x70, 0x65, 0x72, 0x5f, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, + 0x52, 0x13, 0x6e, 0x75, 0x6d, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x50, 0x65, 0x72, 0x53, 0x65, + 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x22, 0xe8, 0xa0, 0x1f, 0x01, 0x8a, 0xe7, 0xb0, 0x2a, 0x19, + 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x78, 0x2f, 0x73, 0x65, 0x73, 0x73, 0x69, + 0x6f, 0x6e, 0x2f, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x42, 0xa7, 0x01, 0x0a, 0x14, 0x63, 0x6f, + 0x6d, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x73, 0x65, 0x73, 0x73, 0x69, + 0x6f, 0x6e, 0x42, 0x0b, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, + 0x01, 0x5a, 0x21, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x73, 0x65, 0x73, + 0x73, 0x69, 0x6f, 0x6e, 0xa2, 0x02, 0x03, 0x50, 0x53, 0x58, 0xaa, 0x02, 0x10, 0x50, 0x6f, 0x6b, + 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0xca, 0x02, 0x10, + 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, + 0xe2, 0x02, 0x1c, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x53, 0x65, 0x73, 0x73, + 0x69, 0x6f, 0x6e, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, + 0x02, 0x11, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x53, 0x65, 0x73, 0x73, + 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/poktroll/session/tx.pulsar.go b/api/poktroll/session/tx.pulsar.go index deb862e76..c391cfd4b 100644 --- a/api/poktroll/session/tx.pulsar.go +++ b/api/poktroll/session/tx.pulsar.go @@ -972,38 +972,39 @@ var file_poktroll_session_tx_proto_rawDesc = []byte{ 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x14, 0x67, 0x6f, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1d, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x2f, 0x70, 0x61, 0x72, - 0x61, 0x6d, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xbd, 0x01, 0x0a, 0x0f, 0x4d, 0x73, + 0x61, 0x6d, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xc7, 0x01, 0x0a, 0x0f, 0x4d, 0x73, 0x67, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x36, 0x0a, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x09, 0x61, 0x75, 0x74, 0x68, - 0x6f, 0x72, 0x69, 0x74, 0x79, 0x12, 0x3b, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, + 0x6f, 0x72, 0x69, 0x74, 0x79, 0x12, 0x45, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x2e, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x42, - 0x09, 0xc8, 0xde, 0x1f, 0x00, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, - 0x6d, 0x73, 0x3a, 0x35, 0x82, 0xe7, 0xb0, 0x2a, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, - 0x74, 0x79, 0x8a, 0xe7, 0xb0, 0x2a, 0x22, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, - 0x78, 0x2f, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x2f, 0x4d, 0x73, 0x67, 0x55, 0x70, 0x64, - 0x61, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0x19, 0x0a, 0x17, 0x4d, 0x73, 0x67, - 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x6a, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x5c, 0x0a, 0x0c, 0x55, - 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x21, 0x2e, 0x70, 0x6f, - 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x2e, 0x4d, - 0x73, 0x67, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x1a, 0x29, - 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x2e, 0x4d, 0x73, 0x67, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, - 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x1a, 0x05, 0x80, 0xe7, 0xb0, 0x2a, 0x01, - 0x42, 0xa3, 0x01, 0x0a, 0x14, 0x63, 0x6f, 0x6d, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, - 0x6c, 0x2e, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x42, 0x07, 0x54, 0x78, 0x50, 0x72, 0x6f, - 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x21, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, - 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, - 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0xa2, 0x02, 0x03, 0x50, 0x53, 0x58, 0xaa, 0x02, 0x10, - 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, - 0xca, 0x02, 0x10, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x53, 0x65, 0x73, 0x73, - 0x69, 0x6f, 0x6e, 0xe2, 0x02, 0x1c, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x53, - 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, - 0x74, 0x61, 0xea, 0x02, 0x11, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x53, - 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x13, 0xc8, 0xde, 0x1f, 0x00, 0xea, 0xde, 0x1f, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0xa8, + 0xe7, 0xb0, 0x2a, 0x01, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x3a, 0x35, 0x82, 0xe7, + 0xb0, 0x2a, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x8a, 0xe7, 0xb0, 0x2a, + 0x22, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x78, 0x2f, 0x73, 0x65, 0x73, 0x73, + 0x69, 0x6f, 0x6e, 0x2f, 0x4d, 0x73, 0x67, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x72, + 0x61, 0x6d, 0x73, 0x22, 0x19, 0x0a, 0x17, 0x4d, 0x73, 0x67, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x6a, + 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x5c, 0x0a, 0x0c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, + 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x21, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, + 0x2e, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x2e, 0x4d, 0x73, 0x67, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x1a, 0x29, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, + 0x6f, 0x6c, 0x6c, 0x2e, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x2e, 0x4d, 0x73, 0x67, 0x55, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x1a, 0x05, 0x80, 0xe7, 0xb0, 0x2a, 0x01, 0x42, 0xa3, 0x01, 0x0a, 0x14, 0x63, + 0x6f, 0x6d, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x73, 0x65, 0x73, 0x73, + 0x69, 0x6f, 0x6e, 0x42, 0x07, 0x54, 0x78, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x21, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, + 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, + 0x6e, 0xa2, 0x02, 0x03, 0x50, 0x53, 0x58, 0xaa, 0x02, 0x10, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, + 0x6c, 0x6c, 0x2e, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0xca, 0x02, 0x10, 0x50, 0x6f, 0x6b, + 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0xe2, 0x02, 0x1c, + 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, + 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x11, 0x50, + 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/config.yml b/config.yml index 217397882..d54a9cc30 100644 --- a/config.yml +++ b/config.yml @@ -51,6 +51,10 @@ accounts: mnemonic: "elder spatial erosion soap athlete tide subject recipe also awkward head pattern cart version beach usual oxygen confirm erupt diamond maze smooth census garment" coins: - 300000000upokt + - name: unauthorized + mnemonic: "abuse tumble whip pioneer immense pipe method note upon glory switch rail metal camp gasp top require rain party total struggle glance between fossil" + coins: + - 100000upokt faucet: name: faucet coins: @@ -179,3 +183,6 @@ genesis: service: params: add_service_fee: "1000000000" + session: + params: + num_blocks_per_session: 4 diff --git a/e2e/tests/params_types_test.go b/e2e/tests/params_types_test.go index 30b736b31..facd7abca 100644 --- a/e2e/tests/params_types_test.go +++ b/e2e/tests/params_types_test.go @@ -2,11 +2,6 @@ package e2e -const ( - computeUnitsToTokensMultipler = "compute_units_to_tokens_multiplier" - minRelayDifficultyBits = "min_relay_difficulty_bits" -) - type ( // moduleNameKey is the key for a module name in the module params map. moduleNameKey = string diff --git a/e2e/tests/parse_params_test.go b/e2e/tests/parse_params_test.go index ef4f59146..97d8e9b0f 100644 --- a/e2e/tests/parse_params_test.go +++ b/e2e/tests/parse_params_test.go @@ -10,7 +10,10 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/regen-network/gocuke" + apptypes "github.com/pokt-network/poktroll/x/application/types" prooftypes "github.com/pokt-network/poktroll/x/proof/types" + servicetypes "github.com/pokt-network/poktroll/x/service/types" + sessiontypes "github.com/pokt-network/poktroll/x/session/types" tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" ) @@ -71,6 +74,13 @@ func (s *suite) paramsMapToMsgUpdateParams(moduleName string, paramsMap paramsMa msgUpdateParams = s.newTokenomicsMsgUpdateParams(paramsMap) case prooftypes.ModuleName: msgUpdateParams = s.newProofMsgUpdateParams(paramsMap) + case sessiontypes.ModuleName: + msgUpdateParams = s.newSessionMsgUpdateParams(paramsMap) + case apptypes.ModuleName: + msgUpdateParams = s.newAppMsgUpdateParams(paramsMap) + case servicetypes.ModuleName: + msgUpdateParams = s.newServiceMsgUpdateParams(paramsMap) + // NB: gateway & supplier modules currently have no parameters default: err := fmt.Errorf("unexpected module name %q", moduleName) s.Fatal(err) @@ -90,7 +100,7 @@ func (s *suite) newTokenomicsMsgUpdateParams(params paramsMap) cosmostypes.Msg { for paramName, paramValue := range params { switch paramName { - case tokenomicstypes.NameComputeUnitsToTokensMultiplier: + case tokenomicstypes.ParamComputeUnitsToTokensMultiplier: msgUpdateParams.Params.ComputeUnitsToTokensMultiplier = uint64(paramValue.value.(int64)) default: s.Fatalf("unexpected %q type param name %q", paramValue.typeStr, paramName) @@ -110,7 +120,7 @@ func (s *suite) newProofMsgUpdateParams(params paramsMap) cosmostypes.Msg { for paramName, paramValue := range params { s.Logf("paramName: %s, value: %v", paramName, paramValue.value) switch paramName { - case prooftypes.NameMinRelayDifficultyBits: + case prooftypes.ParamMinRelayDifficultyBits: msgUpdateParams.Params.MinRelayDifficultyBits = uint64(paramValue.value.(int64)) default: s.Fatalf("unexpected %q type param name %q", paramValue.typeStr, paramName) @@ -119,6 +129,66 @@ func (s *suite) newProofMsgUpdateParams(params paramsMap) cosmostypes.Msg { return proto.Message(msgUpdateParams) } +func (s *suite) newSessionMsgUpdateParams(params paramsMap) cosmostypes.Msg { + authority := authtypes.NewModuleAddress(s.granterName).String() + + msgUpdateParams := &sessiontypes.MsgUpdateParams{ + Authority: authority, + Params: sessiontypes.Params{}, + } + + for paramName, paramValue := range params { + s.Logf("paramName: %s, value: %v", paramName, paramValue.value) + switch paramName { + case sessiontypes.ParamNumBlocksPerSession: + msgUpdateParams.Params.NumBlocksPerSession = uint64(paramValue.value.(int64)) + default: + s.Fatalf("unexpected %q type param name %q", paramValue.typeStr, paramName) + } + } + return proto.Message(msgUpdateParams) +} + +func (s *suite) newAppMsgUpdateParams(params paramsMap) cosmostypes.Msg { + authority := authtypes.NewModuleAddress(s.granterName).String() + + msgUpdateParams := &apptypes.MsgUpdateParams{ + Authority: authority, + Params: apptypes.Params{}, + } + + for paramName, paramValue := range params { + s.Logf("paramName: %s, value: %v", paramName, paramValue.value) + switch paramName { + case apptypes.ParamMaxDelegatedGateways: + msgUpdateParams.Params.MaxDelegatedGateways = uint64(paramValue.value.(int64)) + default: + s.Fatalf("unexpected %q type param name %q", paramValue.typeStr, paramName) + } + } + return proto.Message(msgUpdateParams) +} + +func (s *suite) newServiceMsgUpdateParams(params paramsMap) cosmostypes.Msg { + authority := authtypes.NewModuleAddress(s.granterName).String() + + msgUpdateParams := &servicetypes.MsgUpdateParams{ + Authority: authority, + Params: servicetypes.Params{}, + } + + for paramName, paramValue := range params { + s.Logf("paramName: %s, value: %v", paramName, paramValue.value) + switch paramName { + case servicetypes.ParamAddServiceFee: + msgUpdateParams.Params.AddServiceFee = uint64(paramValue.value.(int64)) + default: + s.Fatalf("unexpected %q type param name %q", paramValue.typeStr, paramName) + } + } + return proto.Message(msgUpdateParams) +} + // newMsgUpdateParam returns a MsgUpdateParam for the given module name, param name, // and param type/value. func (s *suite) newMsgUpdateParam( diff --git a/e2e/tests/update_params.feature b/e2e/tests/update_params.feature index e88f17819..e1acb3a06 100644 --- a/e2e/tests/update_params.feature +++ b/e2e/tests/update_params.feature @@ -5,7 +5,6 @@ Feature: Params Namespace Given the user has the pocketd binary installed And all "tokenomics" module params are set to their default values And an authz grant from the "gov" "module" account to the "pnf" "user" account for the "/poktroll.tokenomics.MsgUpdateParams" message exists - And a key and account exist for the "unauthorized" user When the "unauthorized" account sends an authz exec message to update all "tokenomics" module params | name | value | type | | compute_units_to_tokens_multiplier | 666 | int64 | @@ -33,6 +32,17 @@ Feature: Params Namespace | min_relay_difficulty_bits | 8 | int64 | Then all "proof" module params should be updated + # NB: If you are reading this and the proof module has parameters + # that are not being updated in this test, please update the test. + Scenario: An authorized user updates all "session" module params + Given the user has the pocketd binary installed + And all "session" module params are set to their default values + And an authz grant from the "gov" "module" account to the "pnf" "user" account for the "/poktroll.session.MsgUpdateParams" message exists + When the "pnf" account sends an authz exec message to update all "session" module params + | name | value | type | + | num_blocks_per_session | 10 | int64 | + Then all "session" module params should be updated + # NB: If you are reading this and any module has parameters that # are not being updated in this test, please update the test. Scenario Outline: An authorized user updates individual module params @@ -49,11 +59,10 @@ Feature: Params Namespace | tokenomics | /poktroll.tokenomics.MsgUpdateParam | compute_units_to_tokens_multiplier | 68 | int64 | | proof | /poktroll.proof.MsgUpdateParam | min_relay_difficulty_bits | 12 | int64 | - Scenario: An unauthorized cannot update individual module params + Scenario: An unauthorized user cannot update individual module params Given the user has the pocketd binary installed And all "proof" module params are set to their default values And an authz grant from the "gov" "module" account to the "pnf" "user" account for the "/poktroll.proof.MsgUpdateParams" message exists - And a key and account exist for the "unauthorized" user When the "unauthorized" account sends an authz exec message to update "proof" the module param | name | value | type | | "min_relay_difficulty_bits | 666 | int64 | diff --git a/e2e/tests/update_params_test.go b/e2e/tests/update_params_test.go index ca66e4dbd..f0f1fff12 100644 --- a/e2e/tests/update_params_test.go +++ b/e2e/tests/update_params_test.go @@ -15,7 +15,12 @@ import ( "github.com/regen-network/gocuke" "github.com/stretchr/testify/require" + apptypes "github.com/pokt-network/poktroll/x/application/types" + gatewaytypes "github.com/pokt-network/poktroll/x/gateway/types" prooftypes "github.com/pokt-network/poktroll/x/proof/types" + servicetypes "github.com/pokt-network/poktroll/x/service/types" + sessiontypes "github.com/pokt-network/poktroll/x/session/types" + suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" ) @@ -49,6 +54,31 @@ func (s *suite) AllModuleParamsAreSetToTheirDefaultValues(moduleName string) { s.cdc.MustUnmarshalJSON([]byte(res.Stdout), &proofParamsRes) require.Equal(s, prooftypes.DefaultParams(), proofParamsRes.GetParams()) + case sessiontypes.ModuleName: + var sessionParamsRes sessiontypes.QueryParamsResponse + s.cdc.MustUnmarshalJSON([]byte(res.Stdout), &sessionParamsRes) + require.Equal(s, sessiontypes.DefaultParams(), sessionParamsRes.GetParams()) + + case apptypes.ModuleName: + var appParamsRes apptypes.QueryParamsResponse + s.cdc.MustUnmarshalJSON([]byte(res.Stdout), &appParamsRes) + require.Equal(s, apptypes.DefaultParams(), appParamsRes.GetParams()) + + case gatewaytypes.ModuleName: + var gatewayParamsRes gatewaytypes.QueryParamsResponse + s.cdc.MustUnmarshalJSON([]byte(res.Stdout), &gatewayParamsRes) + require.Equal(s, gatewaytypes.DefaultParams(), gatewayParamsRes.GetParams()) + + case suppliertypes.ModuleName: + var supplierParamsRes suppliertypes.QueryParamsResponse + s.cdc.MustUnmarshalJSON([]byte(res.Stdout), &supplierParamsRes) + require.Equal(s, suppliertypes.DefaultParams(), supplierParamsRes.GetParams()) + + case servicetypes.ModuleName: + var serviceParamsRes servicetypes.QueryParamsResponse + s.cdc.MustUnmarshalJSON([]byte(res.Stdout), &serviceParamsRes) + require.Equal(s, servicetypes.DefaultParams(), serviceParamsRes.GetParams()) + default: s.Fatalf("unexpected module name: (%v)", moduleName) } @@ -119,17 +149,6 @@ func (s *suite) AnAuthzGrantFromTheAccountToTheAccountForTheMessageExists( s.granteeName = granteeName } -// AKeyAndAccountExistForTheUser checks if a key with the given name exists in the keyring, -// and if not, adds a new key with the given name to the keyring. It then checks if an account -// corresponding the the new key exists. -func (s *suite) AKeyAndAccountExistForTheUser(keyName string) { - if !s.keyExistsInKeyring(keyName) { - s.addKeyToKeyring(keyName) - } - - s.ensureAccountForKeyName(keyName) -} - // AllModuleParamsShouldBeSetToTheirDefaultValues asserts that all module params are set to their default values. func (s *suite) AllModuleParamsShouldBeSetToTheirDefaultValues(moduleName string) { s.AllModuleParamsAreSetToTheirDefaultValues(moduleName) @@ -276,7 +295,7 @@ func (s *suite) assertExpectedModuleParamsUpdated(moduleName string) { switch moduleName { case tokenomicstypes.ModuleName: - computeUnitsToTokensMultiplier := uint64(s.expectedModuleParams[moduleName][computeUnitsToTokensMultipler].value.(int64)) + computeUnitsToTokensMultiplier := uint64(s.expectedModuleParams[moduleName][tokenomicstypes.ParamComputeUnitsToTokensMultiplier].value.(int64)) assertUpdatedParams(s, []byte(res.Stdout), &tokenomicstypes.QueryParamsResponse{ @@ -286,7 +305,7 @@ func (s *suite) assertExpectedModuleParamsUpdated(moduleName string) { }, ) case prooftypes.ModuleName: - minRelayDifficultyBits := uint64(s.expectedModuleParams[moduleName][minRelayDifficultyBits].value.(int64)) + minRelayDifficultyBits := uint64(s.expectedModuleParams[moduleName][prooftypes.ParamMinRelayDifficultyBits].value.(int64)) assertUpdatedParams(s, []byte(res.Stdout), &prooftypes.QueryParamsResponse{ @@ -295,6 +314,36 @@ func (s *suite) assertExpectedModuleParamsUpdated(moduleName string) { }, }, ) + case sessiontypes.ModuleName: + numBlocksPerSession := uint64(s.expectedModuleParams[moduleName][sessiontypes.ParamNumBlocksPerSession].value.(int64)) + assertUpdatedParams(s, + []byte(res.Stdout), + &sessiontypes.QueryParamsResponse{ + Params: sessiontypes.Params{ + NumBlocksPerSession: numBlocksPerSession, + }, + }, + ) + case apptypes.ModuleName: + maxDelegatedGateways := uint64(s.expectedModuleParams[moduleName][apptypes.ParamMaxDelegatedGateways].value.(int64)) + assertUpdatedParams(s, + []byte(res.Stdout), + &apptypes.QueryParamsResponse{ + Params: apptypes.Params{ + MaxDelegatedGateways: maxDelegatedGateways, + }, + }, + ) + case servicetypes.ModuleName: + addServiceFee := uint64(s.expectedModuleParams[moduleName][servicetypes.ParamAddServiceFee].value.(int64)) + assertUpdatedParams(s, + []byte(res.Stdout), + &servicetypes.QueryParamsResponse{ + Params: servicetypes.Params{ + AddServiceFee: addServiceFee, + }, + }, + ) default: s.Fatalf("unexpected module name %q", moduleName) } diff --git a/proto/poktroll/session/params.proto b/proto/poktroll/session/params.proto index cbe3559dc..33f7c0077 100644 --- a/proto/poktroll/session/params.proto +++ b/proto/poktroll/session/params.proto @@ -10,4 +10,6 @@ import "gogoproto/gogo.proto"; message Params { option (amino.name) = "poktroll/x/session/Params"; option (gogoproto.equal) = true; + + uint64 num_blocks_per_session = 1 [(gogoproto.jsontag) = "num_blocks_per_session"]; } \ No newline at end of file diff --git a/proto/poktroll/session/tx.proto b/proto/poktroll/session/tx.proto index 747ed8888..c0434408e 100644 --- a/proto/poktroll/session/tx.proto +++ b/proto/poktroll/session/tx.proto @@ -33,7 +33,7 @@ message MsgUpdateParams { // params defines the x/session parameters to update. // NOTE: All parameters must be supplied. - Params params = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; + Params params = 2 [(gogoproto.jsontag) = "params",(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; } // MsgUpdateParamsResponse defines the response structure for executing a diff --git a/tools/scripts/params/proof_min_relay_difficulty_bits.json b/tools/scripts/params/proof_min_relay_difficulty_bits.json index 6f6ade8c7..72c14a1d5 100644 --- a/tools/scripts/params/proof_min_relay_difficulty_bits.json +++ b/tools/scripts/params/proof_min_relay_difficulty_bits.json @@ -5,7 +5,7 @@ "@type": "/poktroll.proof.MsgUpdateParam", "authority": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t", "name": "min_relay_difficulty_bits", - "as_int64": "10" + "as_int64": "0" } ] } diff --git a/tools/scripts/params/session_all.json b/tools/scripts/params/session_all.json new file mode 100644 index 000000000..55b2f6200 --- /dev/null +++ b/tools/scripts/params/session_all.json @@ -0,0 +1,13 @@ +{ + "body": { + "messages": [ + { + "@type": "/poktroll.session.MsgUpdateParams", + "authority": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t", + "params": { + "num_blocks_per_session": "4" + } + } + ] + } +} diff --git a/tools/scripts/params/tokenomics_compute_units_to_tokens_multiplier.json b/tools/scripts/params/tokenomics_compute_units_to_tokens_multiplier.json index 10c34f501..363bb1350 100644 --- a/tools/scripts/params/tokenomics_compute_units_to_tokens_multiplier.json +++ b/tools/scripts/params/tokenomics_compute_units_to_tokens_multiplier.json @@ -5,7 +5,7 @@ "@type": "/poktroll.tokenomics.MsgUpdateParam", "authority": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t", "name": "compute_units_to_tokens_multiplier", - "as_int64": "69" + "as_int64": "42" } ] } diff --git a/x/application/types/params.go b/x/application/types/params.go index 7542f35ac..732aca8fb 100644 --- a/x/application/types/params.go +++ b/x/application/types/params.go @@ -6,6 +6,8 @@ import ( paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) +const ParamMaxDelegatedGateways = "max_delegated_gateways" + var ( _ paramtypes.ParamSet = (*Params)(nil) diff --git a/x/proof/keeper/msg_server_update_param.go b/x/proof/keeper/msg_server_update_param.go index 1280e6b93..9b8770489 100644 --- a/x/proof/keeper/msg_server_update_param.go +++ b/x/proof/keeper/msg_server_update_param.go @@ -24,7 +24,7 @@ func (k msgServer) UpdateParam( params := k.GetParams(ctx) switch msg.Name { - case types.NameMinRelayDifficultyBits: + case types.ParamMinRelayDifficultyBits: value, ok := msg.AsType.(*types.MsgUpdateParam_AsInt64) if !ok { return nil, fmt.Errorf("unsupported value type for %s param: %T", msg.Name, msg.AsType) diff --git a/x/proof/keeper/msg_server_update_param_test.go b/x/proof/keeper/msg_server_update_param_test.go index fc98161fe..9b11ccb4f 100644 --- a/x/proof/keeper/msg_server_update_param_test.go +++ b/x/proof/keeper/msg_server_update_param_test.go @@ -24,7 +24,7 @@ func TestMsgUpdateParam_UpdateMinRelayDifficultyBitsOnly(t *testing.T) { // Update the min relay difficulty bits updateParamMsg := &prooftypes.MsgUpdateParam{ Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), - Name: prooftypes.NameMinRelayDifficultyBits, + Name: prooftypes.ParamMinRelayDifficultyBits, AsType: &prooftypes.MsgUpdateParam_AsInt64{AsInt64: expectedMinRelayDifficultyBits}, } res, err := msgSrv.UpdateParam(ctx, updateParamMsg) diff --git a/x/proof/types/message_update_param.go b/x/proof/types/message_update_param.go index a90efc87b..4b46e5e07 100644 --- a/x/proof/types/message_update_param.go +++ b/x/proof/types/message_update_param.go @@ -47,7 +47,7 @@ func (msg *MsgUpdateParam) ValidateBasic() error { // Parameter name must be supported by this module. switch msg.Name { - case NameMinRelayDifficultyBits: + case ParamMinRelayDifficultyBits: return msg.paramTypeIsInt64() default: return ErrProofParamNameInvalid.Wrapf("unsupported name param %q", msg.Name) diff --git a/x/proof/types/message_update_param_test.go b/x/proof/types/message_update_param_test.go index 37101a476..7b5328668 100644 --- a/x/proof/types/message_update_param_test.go +++ b/x/proof/types/message_update_param_test.go @@ -37,7 +37,7 @@ func TestMsgUpdateParam_ValidateBasic(t *testing.T) { name: "invalid: incorrect param type", msg: MsgUpdateParam{ Authority: sample.AccAddress(), - Name: NameMinRelayDifficultyBits, + Name: ParamMinRelayDifficultyBits, AsType: &MsgUpdateParam_AsString{AsString: "invalid"}, }, expectedErr: ErrProofParamInvalid, @@ -45,7 +45,7 @@ func TestMsgUpdateParam_ValidateBasic(t *testing.T) { name: "valid: correct authority and param name", msg: MsgUpdateParam{ Authority: sample.AccAddress(), - Name: NameMinRelayDifficultyBits, + Name: ParamMinRelayDifficultyBits, AsType: &MsgUpdateParam_AsInt64{AsInt64: 1}, }, diff --git a/x/proof/types/params.go b/x/proof/types/params.go index f8d80f3ba..aba00b70c 100644 --- a/x/proof/types/params.go +++ b/x/proof/types/params.go @@ -6,7 +6,7 @@ var ( _ paramtypes.ParamSet = (*Params)(nil) KeyMinRelayDifficultyBits = []byte("MinRelayDifficultyBits") - NameMinRelayDifficultyBits = "min_relay_difficulty_bits" + ParamMinRelayDifficultyBits = "min_relay_difficulty_bits" DefaultMinRelayDifficultyBits uint64 = 0 // TODO_BLOCKER(#142, #401): Determine the default value. ) @@ -53,11 +53,11 @@ func (params *Params) ValidateBasic() error { func ValidateMinRelayDifficultyBits(v interface{}) error { difficulty, ok := v.(uint64) if !ok { - return ErrProofParamNameInvalid.Wrapf("invalid parameter type: %T", v) + return ErrProofParamInvalid.Wrapf("invalid parameter type: %T", v) } if difficulty < 0 { - return ErrProofParamNameInvalid.Wrapf("invalid ValidateMinRelayDifficultyBits: (%v)", difficulty) + return ErrProofParamInvalid.Wrapf("invalid MinRelayDifficultyBits: (%v)", difficulty) } return nil diff --git a/x/service/types/params.go b/x/service/types/params.go index 48af04d00..ee3a4b792 100644 --- a/x/service/types/params.go +++ b/x/service/types/params.go @@ -9,7 +9,10 @@ import ( // DefaultAddServiceFee is the default value for the add service fee // parameter in the genesis state of the service module. // TODO_BLOCKER: Revisit default param values for service fee -const DefaultAddServiceFee = 1000000000 // 1000 POKT +const ( + ParamAddServiceFee = "add_service_fee" + DefaultAddServiceFee = 1000000000 // 1000 POKT +) var ( _ paramtypes.ParamSet = (*Params)(nil) diff --git a/x/session/keeper/msg_update_params_test.go b/x/session/keeper/msg_update_params_test.go index bf9df225b..f28228bd6 100644 --- a/x/session/keeper/msg_update_params_test.go +++ b/x/session/keeper/msg_update_params_test.go @@ -35,7 +35,7 @@ func TestMsgUpdateParams(t *testing.T) { Authority: k.GetAuthority(), Params: types.Params{}, }, - shouldError: false, + shouldError: true, }, { desc: "valid: send default params", diff --git a/x/session/module/genesis_test.go b/x/session/module/genesis_test.go index 91b8cc149..5fab07849 100644 --- a/x/session/module/genesis_test.go +++ b/x/session/module/genesis_test.go @@ -20,8 +20,11 @@ func TestGenesisState_Validate(t *testing.T) { isValid: true, }, { - desc: "valid genesis state", + desc: "valid genesis state", genState: &types.GenesisState{ + Params: types.Params{ + NumBlocksPerSession: 1, + }, // this line is used by starport scaffolding # types/genesis/validField }, diff --git a/x/session/types/errors.go b/x/session/types/errors.go index 6ffff939c..c6339194d 100644 --- a/x/session/types/errors.go +++ b/x/session/types/errors.go @@ -15,4 +15,6 @@ var ( ErrSessionInvalidService = sdkerrors.Register(ModuleName, 1106, "invalid service in session") ErrSessionInvalidBlockHeight = sdkerrors.Register(ModuleName, 1107, "invalid block height for session") ErrSessionInvalidSessionId = sdkerrors.Register(ModuleName, 1108, "invalid sessionId") + ErrSessionParamNameInvalid = sdkerrors.Register(ModuleName, 1109, "the provided param name is invalid") + ErrSessionParamInvalid = sdkerrors.Register(ModuleName, 1110, "the provided param is invalid") ) diff --git a/x/session/types/genesis.go b/x/session/types/genesis.go index a88ab1682..60d614ce4 100644 --- a/x/session/types/genesis.go +++ b/x/session/types/genesis.go @@ -15,5 +15,5 @@ func DefaultGenesis() *GenesisState { func (gs GenesisState) Validate() error { // this line is used by starport scaffolding # genesis/types/validate - return gs.Params.Validate() + return gs.Params.ValidateBasic() } diff --git a/x/session/types/message_update_params.go b/x/session/types/message_update_params.go index aeed4a633..e5f5ab0bc 100644 --- a/x/session/types/message_update_params.go +++ b/x/session/types/message_update_params.go @@ -13,7 +13,7 @@ func (m *MsgUpdateParams) ValidateBasic() error { return errorsmod.Wrap(err, "invalid authority address") } - if err := m.Params.Validate(); err != nil { + if err := m.Params.ValidateBasic(); err != nil { return err } diff --git a/x/session/types/params.go b/x/session/types/params.go index 95b0cf8a2..3fd7f5010 100644 --- a/x/session/types/params.go +++ b/x/session/types/params.go @@ -2,7 +2,15 @@ package types import paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -var _ paramtypes.ParamSet = (*Params)(nil) +const ( + DefaultNumBlocksPerSession = 4 + ParamNumBlocksPerSession = "num_blocks_per_session" +) + +var ( + _ paramtypes.ParamSet = (*Params)(nil) + KeyNumBlocksPerSession = []byte("NumBlocksPerSession") +) // ParamKeyTable the param key table for launch module func ParamKeyTable() paramtypes.KeyTable { @@ -11,7 +19,9 @@ func ParamKeyTable() paramtypes.KeyTable { // NewParams creates a new Params instance func NewParams() Params { - return Params{} + return Params{ + NumBlocksPerSession: DefaultNumBlocksPerSession, + } } // DefaultParams returns a default set of parameters @@ -20,11 +30,36 @@ func DefaultParams() Params { } // ParamSetPairs get the params.ParamSet -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{} +func (params *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair( + KeyNumBlocksPerSession, + ¶ms.NumBlocksPerSession, + ValidateNumBlocksPerSession, + ), + } } -// Validate validates the set of params -func (p Params) Validate() error { +// ValidateBasic does a sanity check on the provided params. +func (params *Params) ValidateBasic() error { + if err := ValidateNumBlocksPerSession(params.NumBlocksPerSession); err != nil { + return err + } + + return nil +} + +// ValidateNumBlocksPerSession validates the NumBlocksPerSession param +// NB: The argument is an interface type to satisfy the ParamSetPair function signature. +func ValidateNumBlocksPerSession(v interface{}) error { + numBlocksPerSession, ok := v.(uint64) + if !ok { + return ErrSessionParamInvalid.Wrapf("invalid parameter type: %T", v) + } + + if numBlocksPerSession < 1 { + return ErrSessionParamInvalid.Wrapf("invalid NumBlocksPerSession: (%v)", numBlocksPerSession) + } + return nil } diff --git a/x/session/types/params_test.go b/x/session/types/params_test.go new file mode 100644 index 000000000..5c9f2e829 --- /dev/null +++ b/x/session/types/params_test.go @@ -0,0 +1,42 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestParams_ValidateNumBlocksPerSession(t *testing.T) { + tests := []struct { + desc string + numBlocksPerSession any + err error + }{ + { + desc: "invalid type", + numBlocksPerSession: "invalid", + err: ErrSessionParamInvalid.Wrapf("invalid parameter type: %T", "invalid"), + }, + { + desc: "zero NumBlocksPerSession", + numBlocksPerSession: uint64(0), + err: ErrSessionParamInvalid.Wrapf("invalid NumBlocksPerSession: (%v)", uint64(0)), + }, + { + desc: "valid NumBlocksPerSession", + numBlocksPerSession: uint64(4), + }, + } + + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + err := ValidateNumBlocksPerSession(tt.numBlocksPerSession) + if tt.err != nil { + require.Error(t, err) + require.Contains(t, err.Error(), tt.err.Error()) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/x/tokenomics/keeper/msg_server_update_param.go b/x/tokenomics/keeper/msg_server_update_param.go index 1ca990d6d..0f1415e0f 100644 --- a/x/tokenomics/keeper/msg_server_update_param.go +++ b/x/tokenomics/keeper/msg_server_update_param.go @@ -24,7 +24,7 @@ func (k msgServer) UpdateParam( params := k.GetParams(ctx) switch msg.Name { - case types.NameComputeUnitsToTokensMultiplier: + case types.ParamComputeUnitsToTokensMultiplier: value, ok := msg.AsType.(*types.MsgUpdateParam_AsInt64) if !ok { return nil, fmt.Errorf("unsupported value type for %s param: %T", msg.Name, msg.AsType) diff --git a/x/tokenomics/keeper/msg_server_update_param_test.go b/x/tokenomics/keeper/msg_server_update_param_test.go index 2144d84b1..344734671 100644 --- a/x/tokenomics/keeper/msg_server_update_param_test.go +++ b/x/tokenomics/keeper/msg_server_update_param_test.go @@ -24,7 +24,7 @@ func TestMsgUpdateParam_UpdateMinRelayDifficultyBitsOnly(t *testing.T) { // Update the min relay difficulty bits updateParamMsg := &tokenomicstypes.MsgUpdateParam{ Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), - Name: tokenomicstypes.NameComputeUnitsToTokensMultiplier, + Name: tokenomicstypes.ParamComputeUnitsToTokensMultiplier, AsType: &tokenomicstypes.MsgUpdateParam_AsInt64{AsInt64: expectedComputeUnitsToTokensMultiplier}, } res, err := msgSrv.UpdateParam(ctx, updateParamMsg) diff --git a/x/tokenomics/types/message_update_param.go b/x/tokenomics/types/message_update_param.go index 4c96e20ee..32d0fa358 100644 --- a/x/tokenomics/types/message_update_param.go +++ b/x/tokenomics/types/message_update_param.go @@ -45,7 +45,7 @@ func (msg *MsgUpdateParam) ValidateBasic() error { // Parameter name must be supported by this module. switch msg.Name { - case NameComputeUnitsToTokensMultiplier: + case ParamComputeUnitsToTokensMultiplier: return msg.paramTypeIsInt64() default: return ErrTokenomicsParamNameInvalid.Wrapf("unsupported name param %q", msg.Name) diff --git a/x/tokenomics/types/message_update_param_test.go b/x/tokenomics/types/message_update_param_test.go index 6abb3aff4..c0898f089 100644 --- a/x/tokenomics/types/message_update_param_test.go +++ b/x/tokenomics/types/message_update_param_test.go @@ -36,7 +36,7 @@ func TestMsgUpdateParam_ValidateBasic(t *testing.T) { name: "invalid: incorrect param type", msg: MsgUpdateParam{ Authority: sample.AccAddress(), - Name: NameComputeUnitsToTokensMultiplier, + Name: ParamComputeUnitsToTokensMultiplier, AsType: &MsgUpdateParam_AsString{AsString: "invalid"}, }, expectedErr: ErrTokenomicsParamInvalid, @@ -44,7 +44,7 @@ func TestMsgUpdateParam_ValidateBasic(t *testing.T) { name: "valid: correct authority and param name", msg: MsgUpdateParam{ Authority: sample.AccAddress(), - Name: NameComputeUnitsToTokensMultiplier, + Name: ParamComputeUnitsToTokensMultiplier, AsType: &MsgUpdateParam_AsInt64{AsInt64: 1}, }, expectedErr: nil, diff --git a/x/tokenomics/types/params.go b/x/tokenomics/types/params.go index b7e9756f6..42f62d9b0 100644 --- a/x/tokenomics/types/params.go +++ b/x/tokenomics/types/params.go @@ -8,7 +8,7 @@ var ( _ paramtypes.ParamSet = (*Params)(nil) KeyComputeUnitsToTokensMultiplier = []byte("ComputeUnitsToTokensMultiplier") - NameComputeUnitsToTokensMultiplier = "compute_units_to_tokens_multiplier" + ParamComputeUnitsToTokensMultiplier = "compute_units_to_tokens_multiplier" DefaultComputeUnitsToTokensMultiplier uint64 = 42 // TODO_BLOCKER: Determine the default value. )