diff --git a/Makefile b/Makefile index 0dd79ed99..5736ff63b 100644 --- a/Makefile +++ b/Makefile @@ -846,6 +846,10 @@ params_update_shared_all: ## Update the session module params params_update_shared_num_blocks_per_session: ## Update the shared module params poktrolld tx authz exec ./tools/scripts/params/shared_num_blocks_per_session.json $(PARAM_FLAGS) +.PHONY: params_update_shared_claim_window_open_offset_blocks +params_update_shared_claim_window_open_offset_blocks: ## Update the shared module params + poktrolld tx authz exec ./tools/scripts/params/shared_claim_window_open_offset_blocks.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/shared/params.pulsar.go b/api/poktroll/shared/params.pulsar.go index bf24f26b3..d7db9139c 100644 --- a/api/poktroll/shared/params.pulsar.go +++ b/api/poktroll/shared/params.pulsar.go @@ -15,14 +15,16 @@ import ( ) var ( - md_Params protoreflect.MessageDescriptor - fd_Params_num_blocks_per_session protoreflect.FieldDescriptor + md_Params protoreflect.MessageDescriptor + fd_Params_num_blocks_per_session protoreflect.FieldDescriptor + fd_Params_claim_window_open_offset_blocks protoreflect.FieldDescriptor ) func init() { file_poktroll_shared_params_proto_init() md_Params = File_poktroll_shared_params_proto.Messages().ByName("Params") fd_Params_num_blocks_per_session = md_Params.Fields().ByName("num_blocks_per_session") + fd_Params_claim_window_open_offset_blocks = md_Params.Fields().ByName("claim_window_open_offset_blocks") } var _ protoreflect.Message = (*fastReflection_Params)(nil) @@ -96,6 +98,12 @@ func (x *fastReflection_Params) Range(f func(protoreflect.FieldDescriptor, proto return } } + if x.ClaimWindowOpenOffsetBlocks != uint64(0) { + value := protoreflect.ValueOfUint64(x.ClaimWindowOpenOffsetBlocks) + if !f(fd_Params_claim_window_open_offset_blocks, value) { + return + } + } } // Has reports whether a field is populated. @@ -113,6 +121,8 @@ func (x *fastReflection_Params) Has(fd protoreflect.FieldDescriptor) bool { switch fd.FullName() { case "poktroll.shared.Params.num_blocks_per_session": return x.NumBlocksPerSession != uint64(0) + case "poktroll.shared.Params.claim_window_open_offset_blocks": + return x.ClaimWindowOpenOffsetBlocks != uint64(0) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.shared.Params")) @@ -131,6 +141,8 @@ func (x *fastReflection_Params) Clear(fd protoreflect.FieldDescriptor) { switch fd.FullName() { case "poktroll.shared.Params.num_blocks_per_session": x.NumBlocksPerSession = uint64(0) + case "poktroll.shared.Params.claim_window_open_offset_blocks": + x.ClaimWindowOpenOffsetBlocks = uint64(0) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.shared.Params")) @@ -150,6 +162,9 @@ func (x *fastReflection_Params) Get(descriptor protoreflect.FieldDescriptor) pro case "poktroll.shared.Params.num_blocks_per_session": value := x.NumBlocksPerSession return protoreflect.ValueOfUint64(value) + case "poktroll.shared.Params.claim_window_open_offset_blocks": + value := x.ClaimWindowOpenOffsetBlocks + return protoreflect.ValueOfUint64(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.shared.Params")) @@ -172,6 +187,8 @@ func (x *fastReflection_Params) Set(fd protoreflect.FieldDescriptor, value proto switch fd.FullName() { case "poktroll.shared.Params.num_blocks_per_session": x.NumBlocksPerSession = value.Uint() + case "poktroll.shared.Params.claim_window_open_offset_blocks": + x.ClaimWindowOpenOffsetBlocks = value.Uint() default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.shared.Params")) @@ -194,6 +211,8 @@ func (x *fastReflection_Params) Mutable(fd protoreflect.FieldDescriptor) protore switch fd.FullName() { case "poktroll.shared.Params.num_blocks_per_session": panic(fmt.Errorf("field num_blocks_per_session of message poktroll.shared.Params is not mutable")) + case "poktroll.shared.Params.claim_window_open_offset_blocks": + panic(fmt.Errorf("field claim_window_open_offset_blocks of message poktroll.shared.Params is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.shared.Params")) @@ -209,6 +228,8 @@ func (x *fastReflection_Params) NewField(fd protoreflect.FieldDescriptor) protor switch fd.FullName() { case "poktroll.shared.Params.num_blocks_per_session": return protoreflect.ValueOfUint64(uint64(0)) + case "poktroll.shared.Params.claim_window_open_offset_blocks": + return protoreflect.ValueOfUint64(uint64(0)) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.shared.Params")) @@ -281,6 +302,9 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { if x.NumBlocksPerSession != 0 { n += 1 + runtime.Sov(uint64(x.NumBlocksPerSession)) } + if x.ClaimWindowOpenOffsetBlocks != 0 { + n += 1 + runtime.Sov(uint64(x.ClaimWindowOpenOffsetBlocks)) + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -310,6 +334,11 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if x.ClaimWindowOpenOffsetBlocks != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.ClaimWindowOpenOffsetBlocks)) + i-- + dAtA[i] = 0x10 + } if x.NumBlocksPerSession != 0 { i = runtime.EncodeVarint(dAtA, i, uint64(x.NumBlocksPerSession)) i-- @@ -383,6 +412,25 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { break } } + case 2: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ClaimWindowOpenOffsetBlocks", wireType) + } + x.ClaimWindowOpenOffsetBlocks = 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.ClaimWindowOpenOffsetBlocks |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -437,7 +485,8 @@ type Params struct { 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"` + NumBlocksPerSession uint64 `protobuf:"varint,1,opt,name=num_blocks_per_session,json=numBlocksPerSession,proto3" json:"num_blocks_per_session,omitempty"` + ClaimWindowOpenOffsetBlocks uint64 `protobuf:"varint,2,opt,name=claim_window_open_offset_blocks,json=claimWindowOpenOffsetBlocks,proto3" json:"claim_window_open_offset_blocks,omitempty"` } func (x *Params) Reset() { @@ -467,6 +516,13 @@ func (x *Params) GetNumBlocksPerSession() uint64 { return 0 } +func (x *Params) GetClaimWindowOpenOffsetBlocks() uint64 { + if x != nil { + return x.ClaimWindowOpenOffsetBlocks + } + return 0 +} + var File_poktroll_shared_params_proto protoreflect.FileDescriptor var file_poktroll_shared_params_proto_rawDesc = []byte{ @@ -475,26 +531,32 @@ var file_poktroll_shared_params_proto_rawDesc = []byte{ 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 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, 0x7c, 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, 0x21, 0xe8, 0xa0, 0x1f, 0x01, 0x8a, 0xe7, 0xb0, 0x2a, 0x18, 0x70, 0x6f, - 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x78, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2f, - 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x42, 0xa1, 0x01, 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x70, - 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x42, 0x0b, - 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x20, 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, 0x68, 0x61, 0x72, 0x65, 0x64, 0xa2, - 0x02, 0x03, 0x50, 0x53, 0x58, 0xaa, 0x02, 0x0f, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, - 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x64, 0xca, 0x02, 0x0f, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, - 0x6c, 0x6c, 0x5c, 0x53, 0x68, 0x61, 0x72, 0x65, 0x64, 0xe2, 0x02, 0x1b, 0x50, 0x6f, 0x6b, 0x74, - 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x53, 0x68, 0x61, 0x72, 0x65, 0x64, 0x5c, 0x47, 0x50, 0x42, 0x4d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x10, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, - 0x6c, 0x6c, 0x3a, 0x3a, 0x53, 0x68, 0x61, 0x72, 0x65, 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe7, 0x01, 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, 0x12, 0x69, 0x0a, 0x1f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x5f, 0x77, 0x69, + 0x6e, 0x64, 0x6f, 0x77, 0x5f, 0x6f, 0x70, 0x65, 0x6e, 0x5f, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, + 0x5f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x42, 0x23, 0xea, + 0xde, 0x1f, 0x1f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x5f, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x5f, + 0x6f, 0x70, 0x65, 0x6e, 0x5f, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x5f, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x73, 0x52, 0x1b, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x57, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x4f, + 0x70, 0x65, 0x6e, 0x4f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x3a, + 0x21, 0xe8, 0xa0, 0x1f, 0x01, 0x8a, 0xe7, 0xb0, 0x2a, 0x18, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, + 0x6c, 0x6c, 0x2f, 0x78, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2f, 0x50, 0x61, 0x72, 0x61, + 0x6d, 0x73, 0x42, 0xa1, 0x01, 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, + 0x6f, 0x6c, 0x6c, 0x2e, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x42, 0x0b, 0x50, 0x61, 0x72, 0x61, + 0x6d, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x20, 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, 0x68, 0x61, 0x72, 0x65, 0x64, 0xa2, 0x02, 0x03, 0x50, 0x53, + 0x58, 0xaa, 0x02, 0x0f, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x64, 0xca, 0x02, 0x0f, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x53, + 0x68, 0x61, 0x72, 0x65, 0x64, 0xe2, 0x02, 0x1b, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, + 0x5c, 0x53, 0x68, 0x61, 0x72, 0x65, 0x64, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, + 0x61, 0x74, 0x61, 0xea, 0x02, 0x10, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, + 0x53, 0x68, 0x61, 0x72, 0x65, 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/config.yml b/config.yml index a967662a4..367897b9b 100644 --- a/config.yml +++ b/config.yml @@ -186,3 +186,4 @@ genesis: shared: params: num_blocks_per_session: 4 + claim_window_open_offset_blocks: 0 diff --git a/e2e/tests/parse_params_test.go b/e2e/tests/parse_params_test.go index e4c497931..ea74b4d26 100644 --- a/e2e/tests/parse_params_test.go +++ b/e2e/tests/parse_params_test.go @@ -142,6 +142,8 @@ func (s *suite) newSharedMsgUpdateParams(params paramsMap) cosmostypes.Msg { switch paramName { case sharedtypes.ParamNumBlocksPerSession: msgUpdateParams.Params.NumBlocksPerSession = uint64(paramValue.value.(int64)) + case sharedtypes.ParamClaimWindowOpenOffsetBlocks: + msgUpdateParams.Params.ClaimWindowOpenOffsetBlocks = uint64(paramValue.value.(int64)) default: s.Fatalf("unexpected %q type param name %q", paramValue.typeStr, paramName) } diff --git a/e2e/tests/update_params.feature b/e2e/tests/update_params.feature index 2d66d03eb..4230e7e1d 100644 --- a/e2e/tests/update_params.feature +++ b/e2e/tests/update_params.feature @@ -41,8 +41,9 @@ Feature: Params Namespace And all "shared" 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.shared.MsgUpdateParams" message exists When the "pnf" account sends an authz exec message to update all "shared" module params - | name | value | type | - | num_blocks_per_session | 10 | int64 | + | name | value | type | + | num_blocks_per_session | 8 | int64 | + | claim_window_open_offset_blocks | 8 | int64 | Then all "shared" module params should be updated # NB: If you are reading this and any module has parameters that @@ -61,6 +62,7 @@ Feature: Params Namespace | tokenomics | /poktroll.tokenomics.MsgUpdateParam | compute_units_to_tokens_multiplier | 68 | int64 | | proof | /poktroll.proof.MsgUpdateParam | min_relay_difficulty_bits | 12 | int64 | | shared | /poktroll.shared.MsgUpdateParam | num_blocks_per_session | 8 | int64 | + | shared | /poktroll.shared.MsgUpdateParam | claim_window_open_offset_blocks | 8 | int64 | Scenario: An unauthorized user cannot update individual module params Given the user has the pocketd binary installed diff --git a/e2e/tests/update_params_test.go b/e2e/tests/update_params_test.go index 8bde266a6..be4fb657f 100644 --- a/e2e/tests/update_params_test.go +++ b/e2e/tests/update_params_test.go @@ -321,13 +321,23 @@ func (s *suite) assertExpectedModuleParamsUpdated(moduleName string) { }, ) case sharedtypes.ModuleName: - numBlocksPerSession := uint64(s.expectedModuleParams[moduleName][sharedtypes.ParamNumBlocksPerSession].value.(int64)) + params := sharedtypes.DefaultParams() + paramsMap := s.expectedModuleParams[moduleName] + + numBlocksPerSessionParam, ok := paramsMap[sharedtypes.ParamNumBlocksPerSession] + if ok { + params.NumBlocksPerSession = uint64(numBlocksPerSessionParam.value.(int64)) + } + + claimWindowOpenOffsetBlocksParam, ok := paramsMap[sharedtypes.ParamClaimWindowOpenOffsetBlocks] + if ok { + params.ClaimWindowOpenOffsetBlocks = uint64(claimWindowOpenOffsetBlocksParam.value.(int64)) + } + assertUpdatedParams(s, []byte(res.Stdout), &sharedtypes.QueryParamsResponse{ - Params: sharedtypes.Params{ - NumBlocksPerSession: numBlocksPerSession, - }, + Params: params, }, ) case apptypes.ModuleName: diff --git a/proto/poktroll/shared/params.proto b/proto/poktroll/shared/params.proto index adeb68749..f47b1d33c 100644 --- a/proto/poktroll/shared/params.proto +++ b/proto/poktroll/shared/params.proto @@ -11,5 +11,9 @@ message Params { option (amino.name) = "poktroll/x/shared/Params"; option (gogoproto.equal) = true; + // num_blocks_per_session is the number of blocks between the session start & end heights. uint64 num_blocks_per_session = 1 [(gogoproto.jsontag) = "num_blocks_per_session"]; + // claim_window_open_offset_blocks is the number of blocks after the session grace + // period height, at which the claim window opens. + uint64 claim_window_open_offset_blocks = 2 [(gogoproto.jsontag) = "claim_window_open_offset_blocks"]; } \ No newline at end of file diff --git a/tools/scripts/params/shared_all.json b/tools/scripts/params/shared_all.json index 72502f45d..d2bb0f41f 100644 --- a/tools/scripts/params/shared_all.json +++ b/tools/scripts/params/shared_all.json @@ -5,7 +5,8 @@ "@type": "/poktroll.shared.MsgUpdateParams", "authority": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t", "params": { - "num_blocks_per_session": "4" + "num_blocks_per_session": "4", + "claim_window_open_offset_blocks": "0", } } ] diff --git a/tools/scripts/params/shared_claim_window_open_offset_blocks.json b/tools/scripts/params/shared_claim_window_open_offset_blocks.json new file mode 100644 index 000000000..7852a222d --- /dev/null +++ b/tools/scripts/params/shared_claim_window_open_offset_blocks.json @@ -0,0 +1,12 @@ +{ + "body": { + "messages": [ + { + "@type": "/poktroll.shared.MsgUpdateParam", + "authority": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t", + "name": "claim_window_open_offset_blocks", + "as_int64": "0" + } + ] + } +} diff --git a/x/shared/keeper/msg_server_update_param.go b/x/shared/keeper/msg_server_update_param.go index 4768527cc..34a971c76 100644 --- a/x/shared/keeper/msg_server_update_param.go +++ b/x/shared/keeper/msg_server_update_param.go @@ -30,6 +30,18 @@ func (k msgServer) UpdateParam(ctx context.Context, msg *types.MsgUpdateParam) ( } params.NumBlocksPerSession = numBlocksPerSession + case types.ParamClaimWindowOpenOffsetBlocks: + value, ok := msg.AsType.(*types.MsgUpdateParam_AsInt64) + if !ok { + return nil, types.ErrSharedParamInvalid.Wrapf("unsupported value type for %s param: %T", msg.Name, msg.AsType) + } + claimWindowOpenOffsetBlocks := uint64(value.AsInt64) + + if err := types.ValidateClaimWindowOpenOffsetBlocks(claimWindowOpenOffsetBlocks); err != nil { + return nil, err + } + + params.ClaimWindowOpenOffsetBlocks = claimWindowOpenOffsetBlocks default: return nil, types.ErrSharedParamInvalid.Wrapf("unsupported param %q", msg.Name) } diff --git a/x/shared/keeper/msg_server_update_param_test.go b/x/shared/keeper/msg_server_update_param_test.go index 65702fd45..8b32866f7 100644 --- a/x/shared/keeper/msg_server_update_param_test.go +++ b/x/shared/keeper/msg_server_update_param_test.go @@ -26,7 +26,7 @@ func TestMsgUpdateParam_UpdateNumBlocksPerSession(t *testing.T) { // Ensure the default values are different from the new values we want to set require.NotEqual(t, uint64(expectedNumBlocksPerSession), defaultParams.NumBlocksPerSession) - // Update the min relay difficulty bits + // Update the number of blocks per session updateParamMsg := &sharedtypes.MsgUpdateParam{ Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), Name: sharedtypes.ParamNumBlocksPerSession, @@ -37,6 +37,34 @@ func TestMsgUpdateParam_UpdateNumBlocksPerSession(t *testing.T) { require.Equal(t, uint64(expectedNumBlocksPerSession), res.Params.NumBlocksPerSession) - // TODO_BLOCKER: once we have more than one param per module, add assertions - // here which ensure that other params were not changed! + // Ensure the other parameters are unchanged + require.Equal(t, defaultParams.ClaimWindowOpenOffsetBlocks, res.Params.ClaimWindowOpenOffsetBlocks) +} + +func TestMsgUpdateParam_UpdateClaimWindowOpenOffsetBlocks(t *testing.T) { + var expectedClaimWindowOpenOffestBlocks int64 = 4 + + k, ctx := keepertest.SharedKeeper(t) + msgSrv := keeper.NewMsgServerImpl(k) + + // Set the parameters to their default values + defaultParams := sharedtypes.DefaultParams() + require.NoError(t, k.SetParams(ctx, defaultParams)) + + // Ensure the default values are different from the new values we want to set + require.NotEqual(t, uint64(expectedClaimWindowOpenOffestBlocks), defaultParams.ClaimWindowOpenOffsetBlocks) + + // Update the claim window open offset blocks + updateParamMsg := &sharedtypes.MsgUpdateParam{ + Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), + Name: sharedtypes.ParamClaimWindowOpenOffsetBlocks, + AsType: &sharedtypes.MsgUpdateParam_AsInt64{AsInt64: expectedClaimWindowOpenOffestBlocks}, + } + res, err := msgSrv.UpdateParam(ctx, updateParamMsg) + require.NoError(t, err) + + require.Equal(t, uint64(expectedClaimWindowOpenOffestBlocks), res.Params.ClaimWindowOpenOffsetBlocks) + + // Ensure the other parameters are unchanged + require.Equal(t, defaultParams.NumBlocksPerSession, res.Params.NumBlocksPerSession) } diff --git a/x/shared/types/message_update_param.go b/x/shared/types/message_update_param.go index 3cb9b8f2e..4a94ac9b9 100644 --- a/x/shared/types/message_update_param.go +++ b/x/shared/types/message_update_param.go @@ -47,10 +47,11 @@ func (msg *MsgUpdateParam) ValidateBasic() error { // Parameter name must be supported by this module. switch msg.Name { - case ParamNumBlocksPerSession: + case ParamNumBlocksPerSession, + ParamClaimWindowOpenOffsetBlocks: return msg.paramTypeIsInt64() default: - return ErrSharedParamNameInvalid.Wrapf("unsupported name param %q", msg.Name) + return ErrSharedParamNameInvalid.Wrapf("unsupported param %q", msg.Name) } } diff --git a/x/shared/types/params.go b/x/shared/types/params.go index 9cfcf5bd5..ce668d9e6 100644 --- a/x/shared/types/params.go +++ b/x/shared/types/params.go @@ -5,13 +5,16 @@ import ( ) const ( - DefaultNumBlocksPerSession = 4 - ParamNumBlocksPerSession = "num_blocks_per_session" + DefaultNumBlocksPerSession = 4 + ParamNumBlocksPerSession = "num_blocks_per_session" + DefaultClaimWindowOpenOffsetBlocks = 0 + ParamClaimWindowOpenOffsetBlocks = "claim_window_open_offset_blocks" ) var ( - _ paramtypes.ParamSet = (*Params)(nil) - KeyNumBlocksPerSession = []byte("NumBlocksPerSession") + _ paramtypes.ParamSet = (*Params)(nil) + KeyNumBlocksPerSession = []byte("NumBlocksPerSession") + KeyClaimWindowOpenOffsetBlocks = []byte("ClaimWindowOpenOffsetBlocks") ) // ParamKeyTable the param key table for launch module @@ -22,7 +25,8 @@ func ParamKeyTable() paramtypes.KeyTable { // NewParams creates a new Params instance func NewParams() Params { return Params{ - NumBlocksPerSession: DefaultNumBlocksPerSession, + NumBlocksPerSession: DefaultNumBlocksPerSession, + ClaimWindowOpenOffsetBlocks: DefaultClaimWindowOpenOffsetBlocks, } } @@ -39,6 +43,11 @@ func (params *Params) ParamSetPairs() paramtypes.ParamSetPairs { ¶ms.NumBlocksPerSession, ValidateNumBlocksPerSession, ), + paramtypes.NewParamSetPair( + KeyClaimWindowOpenOffsetBlocks, + ¶ms.ClaimWindowOpenOffsetBlocks, + ValidateClaimWindowOpenOffsetBlocks, + ), } } @@ -48,6 +57,10 @@ func (params *Params) ValidateBasic() error { return err } + if err := ValidateClaimWindowOpenOffsetBlocks(params.ClaimWindowOpenOffsetBlocks); err != nil { + return err + } + return nil } @@ -65,3 +78,14 @@ func ValidateNumBlocksPerSession(v interface{}) error { return nil } + +// ValidateClaimWindowOpenOffsetBlocks validates the ClaimWindowOpenOffsetBlocks param +// NB: The argument is an interface type to satisfy the ParamSetPair function signature. +func ValidateClaimWindowOpenOffsetBlocks(v interface{}) error { + _, ok := v.(uint64) + if !ok { + return ErrSharedParamInvalid.Wrapf("invalid parameter type: %T", v) + } + + return nil +} diff --git a/x/shared/types/params.pb.go b/x/shared/types/params.pb.go index 0929cac08..60d117f1c 100644 --- a/x/shared/types/params.pb.go +++ b/x/shared/types/params.pb.go @@ -26,7 +26,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the module. type Params struct { - NumBlocksPerSession uint64 `protobuf:"varint,1,opt,name=num_blocks_per_session,json=numBlocksPerSession,proto3" json:"num_blocks_per_session"` + NumBlocksPerSession uint64 `protobuf:"varint,1,opt,name=num_blocks_per_session,json=numBlocksPerSession,proto3" json:"num_blocks_per_session"` + ClaimWindowOpenOffsetBlocks uint64 `protobuf:"varint,2,opt,name=claim_window_open_offset_blocks,json=claimWindowOpenOffsetBlocks,proto3" json:"claim_window_open_offset_blocks"` } func (m *Params) Reset() { *m = Params{} } @@ -69,6 +70,13 @@ func (m *Params) GetNumBlocksPerSession() uint64 { return 0 } +func (m *Params) GetClaimWindowOpenOffsetBlocks() uint64 { + if m != nil { + return m.ClaimWindowOpenOffsetBlocks + } + return 0 +} + func init() { proto.RegisterType((*Params)(nil), "poktroll.shared.Params") } @@ -76,22 +84,25 @@ func init() { func init() { proto.RegisterFile("poktroll/shared/params.proto", fileDescriptor_ee6189c7aa51bbf5) } var fileDescriptor_ee6189c7aa51bbf5 = []byte{ - // 228 bytes of a gzipped FileDescriptorProto + // 287 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x29, 0xc8, 0xcf, 0x2e, 0x29, 0xca, 0xcf, 0xc9, 0xd1, 0x2f, 0xce, 0x48, 0x2c, 0x4a, 0x4d, 0xd1, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x87, 0xc9, 0xea, 0x41, 0x64, 0xa5, 0x04, 0x13, 0x73, 0x33, 0xf3, 0xf2, 0xf5, 0xc1, 0x24, 0x44, 0x8d, 0x94, 0x48, 0x7a, 0x7e, 0x7a, - 0x3e, 0x98, 0xa9, 0x0f, 0x62, 0x41, 0x44, 0x95, 0x6a, 0xb8, 0xd8, 0x02, 0xc0, 0x26, 0x09, 0xf9, - 0x73, 0x89, 0xe5, 0x95, 0xe6, 0xc6, 0x27, 0xe5, 0xe4, 0x27, 0x67, 0x17, 0xc7, 0x17, 0xa4, 0x16, - 0xc5, 0x17, 0xa7, 0x16, 0x17, 0x67, 0xe6, 0xe7, 0x49, 0x30, 0x2a, 0x30, 0x6a, 0xb0, 0x38, 0x49, - 0xbd, 0xba, 0x27, 0x8f, 0x43, 0x45, 0x90, 0x70, 0x5e, 0x69, 0xae, 0x13, 0x58, 0x38, 0x20, 0xb5, - 0x28, 0x18, 0x22, 0x68, 0xa5, 0xf8, 0x62, 0x81, 0x3c, 0x63, 0xd7, 0xf3, 0x0d, 0x5a, 0x12, 0x70, - 0xb7, 0x57, 0xc0, 0x5c, 0x0f, 0xb1, 0xd3, 0xc9, 0xf3, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, - 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, - 0xe5, 0x18, 0xa2, 0xf4, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x41, - 0xda, 0x75, 0xf3, 0x52, 0x4b, 0xca, 0xf3, 0x8b, 0xb2, 0xf5, 0x31, 0xcd, 0x2a, 0xa9, 0x2c, 0x48, - 0x2d, 0x4e, 0x62, 0x03, 0xfb, 0xc7, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x43, 0x33, 0xe9, 0x1c, - 0x29, 0x01, 0x00, 0x00, + 0x3e, 0x98, 0xa9, 0x0f, 0x62, 0x41, 0x44, 0x95, 0x9e, 0x33, 0x72, 0xb1, 0x05, 0x80, 0x8d, 0x12, + 0xf2, 0xe7, 0x12, 0xcb, 0x2b, 0xcd, 0x8d, 0x4f, 0xca, 0xc9, 0x4f, 0xce, 0x2e, 0x8e, 0x2f, 0x48, + 0x2d, 0x8a, 0x2f, 0x4e, 0x2d, 0x2e, 0xce, 0xcc, 0xcf, 0x93, 0x60, 0x54, 0x60, 0xd4, 0x60, 0x71, + 0x92, 0x7a, 0x75, 0x4f, 0x1e, 0x87, 0x8a, 0x20, 0xe1, 0xbc, 0xd2, 0x5c, 0x27, 0xb0, 0x70, 0x40, + 0x6a, 0x51, 0x30, 0x44, 0x50, 0x28, 0x93, 0x4b, 0x3e, 0x39, 0x27, 0x31, 0x33, 0x37, 0xbe, 0x3c, + 0x33, 0x2f, 0x25, 0xbf, 0x3c, 0x3e, 0xbf, 0x20, 0x35, 0x2f, 0x3e, 0x3f, 0x2d, 0xad, 0x38, 0xb5, + 0x04, 0x6a, 0x86, 0x04, 0x13, 0xd8, 0x64, 0xe5, 0x57, 0xf7, 0xe4, 0x09, 0x29, 0x0d, 0x92, 0x06, + 0x2b, 0x08, 0x07, 0xcb, 0xfb, 0x17, 0xa4, 0xe6, 0xf9, 0x83, 0x65, 0x21, 0x96, 0x5a, 0x29, 0xbe, + 0x58, 0x20, 0xcf, 0xd8, 0xf5, 0x7c, 0x83, 0x96, 0x04, 0x3c, 0x9c, 0x2a, 0x60, 0x21, 0x05, 0xf1, + 0x9e, 0x93, 0xe7, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, + 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xe9, 0xa7, 0x67, + 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x83, 0xb4, 0xeb, 0xe6, 0xa5, 0x96, 0x94, + 0xe7, 0x17, 0x65, 0xeb, 0x63, 0x9a, 0x55, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0x0e, 0x3b, + 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x32, 0x51, 0x62, 0xe7, 0x95, 0x01, 0x00, 0x00, } func (this *Params) Equal(that interface{}) bool { @@ -116,6 +127,9 @@ func (this *Params) Equal(that interface{}) bool { if this.NumBlocksPerSession != that1.NumBlocksPerSession { return false } + if this.ClaimWindowOpenOffsetBlocks != that1.ClaimWindowOpenOffsetBlocks { + return false + } return true } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -138,6 +152,11 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.ClaimWindowOpenOffsetBlocks != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.ClaimWindowOpenOffsetBlocks)) + i-- + dAtA[i] = 0x10 + } if m.NumBlocksPerSession != 0 { i = encodeVarintParams(dAtA, i, uint64(m.NumBlocksPerSession)) i-- @@ -166,6 +185,9 @@ func (m *Params) Size() (n int) { if m.NumBlocksPerSession != 0 { n += 1 + sovParams(uint64(m.NumBlocksPerSession)) } + if m.ClaimWindowOpenOffsetBlocks != 0 { + n += 1 + sovParams(uint64(m.ClaimWindowOpenOffsetBlocks)) + } return n } @@ -223,6 +245,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { break } } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ClaimWindowOpenOffsetBlocks", wireType) + } + m.ClaimWindowOpenOffsetBlocks = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ClaimWindowOpenOffsetBlocks |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/shared/types/params_test.go b/x/shared/types/params_test.go index a2611b04a..f64cc33af 100644 --- a/x/shared/types/params_test.go +++ b/x/shared/types/params_test.go @@ -40,3 +40,33 @@ func TestParams_ValidateNumBlocksPerSession(t *testing.T) { }) } } + +func TestParams_ValidateClaimWindowOpenOffsetBlocks(t *testing.T) { + tests := []struct { + desc string + claimWindowOpenOffsetBlocks any + err error + }{ + { + desc: "invalid type", + claimWindowOpenOffsetBlocks: "invalid", + err: ErrSharedParamInvalid.Wrapf("invalid parameter type: %T", "invalid"), + }, + { + desc: "valid ClaimWindowOpenOffsetBlocks", + claimWindowOpenOffsetBlocks: uint64(4), + }, + } + + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + err := ValidateClaimWindowOpenOffsetBlocks(tt.claimWindowOpenOffsetBlocks) + if tt.err != nil { + require.Error(t, err) + require.Contains(t, err.Error(), tt.err.Error()) + } else { + require.NoError(t, err) + } + }) + } +}