diff --git a/.github/workflows/issues.yml b/.github/workflows/issues.yml index bab7b96a1153..b4f3775f27ba 100644 --- a/.github/workflows/issues.yml +++ b/.github/workflows/issues.yml @@ -11,7 +11,7 @@ jobs: name: Add issue to project runs-on: ubuntu-latest steps: - - uses: actions/add-to-project@v1.0.0 + - uses: actions/add-to-project@v1.0.1 with: project-url: https://github.com/orgs/cosmos/projects/26 # add all issues opened to the issue board for triage and assignment diff --git a/CHANGELOG.md b/CHANGELOG.md index 419f2ec401ee..7a146f35db77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,10 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i ### Improvements +* (telemetry) [#19903](https://github.com/cosmos/cosmos-sdk/pull/19903) Conditionally emit metrics based on enablement. + * **Introduction of `Now` Function**: Added a new function called `Now` to the telemetry package. It returns the current system time if telemetry is enabled, or a zero time if telemetry is not enabled. + * **Atomic Global Variable**: Implemented an atomic global variable to manage the state of telemetry's enablement. This ensures thread safety for the telemetry state. + * **Conditional Telemetry Emission**: All telemetry functions have been updated to emit metrics only when telemetry is enabled. They perform a check with `isTelemetryEnabled()` and return early if telemetry is disabled, minimizing unnecessary operations and overhead. * (types) [#19869](https://github.com/cosmos/cosmos-sdk/pull/19869) Removed `Any` type from `codec/types` and replaced it with an alias for `cosmos/gogoproto/types/any`. * (server) [#19854](https://github.com/cosmos/cosmos-sdk/pull/19854) Add customizability to start command. * Add `StartCmdOptions` in `server.AddCommands` instead of `servertypes.ModuleInitFlags`. To set custom flags set them in the `StartCmdOptions` struct on the `AddFlags` field. @@ -92,6 +96,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (types) [#18963](https://github.com/cosmos/cosmos-sdk/pull/18963) Swap out amino json encoding of `ABCIMessageLogs` for std lib json encoding * (x/auth) [#19651](https://github.com/cosmos/cosmos-sdk/pull/19651) Allow empty public keys in `GetSignBytesAdapter`. * (x/genutil) [#19735](https://github.com/cosmos/cosmos-sdk/pull/19735) Update genesis api to match new `appmodule.HasGenesis` interface. +* (server) [#19966](https://github.com/cosmos/cosmos-sdk/pull/19966) Return BlockHeader by shallow copy in server Context. ### Bug Fixes @@ -107,6 +112,9 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (crypto) [#19691](https://github.com/cosmos/cosmos-sdk/pull/19691) Fix tx sign doesn't throw an error when incorrect Ledger is used. * [#19833](https://github.com/cosmos/cosmos-sdk/pull/19833) Fix some places in which we call Remove inside a Walk. * [#19851](https://github.com/cosmos/cosmos-sdk/pull/19851) Fix some places in which we call Remove inside a Walk (x/staking and x/gov). +* (baseapp) [#19970](https://github.com/cosmos/cosmos-sdk/pull/19970) Fix default config values to use no-op mempool as default. +* (crypto) [#20027](https://github.com/cosmos/cosmos-sdk/pull/20027) secp256r1 keys now implement gogoproto's customtype interface. +* (x/bank) [#20028](https://github.com/cosmos/cosmos-sdk/pull/20028) Align query with multi denoms for send-enabled. ### API Breaking Changes @@ -169,6 +177,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * Every module has the codec already, passing it created an unneeded dependency. * Additionally, to reflect this change, the module manager does not take a codec either. * (runtime) [#19747](https://github.com/cosmos/cosmos-sdk/pull/19747) `runtime.ValidatorAddressCodec` and `runtime.ConsensusAddressCodec` have been moved to `core`. +* (baseapp) [#19993](https://github.com/cosmos/cosmos-sdk/pull/19993) Indicate pruning with error code "not found" rather than "invalid request". ### Client Breaking Changes diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3a019201f95c..22f82c615066 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -344,7 +344,7 @@ Members must: * Be active contributors to the Cosmos SDK, and furthermore should be continuously making substantial contributions to the project's codebase, review process, documentation and ADRs * Have stake in the Cosmos SDK project, represented by: - * Being a client / user of the Comsos SDK + * Being a client / user of the Cosmos SDK * "[giving back](https://www.debian.org/social_contract)" to the software * Delegate representation in case of vacation or absence diff --git a/api/cosmos/bank/module/v1/module.pulsar.go b/api/cosmos/bank/module/v1/module.pulsar.go index 188920e4441d..d34ac1d8e167 100644 --- a/api/cosmos/bank/module/v1/module.pulsar.go +++ b/api/cosmos/bank/module/v1/module.pulsar.go @@ -59,10 +59,57 @@ func (x *_Module_1_list) IsValid() bool { return x.list != nil } +var _ protoreflect.List = (*_Module_3_list)(nil) + +type _Module_3_list struct { + list *[]string +} + +func (x *_Module_3_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_Module_3_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfString((*x.list)[i]) +} + +func (x *_Module_3_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + (*x.list)[i] = concreteValue +} + +func (x *_Module_3_list) Append(value protoreflect.Value) { + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + *x.list = append(*x.list, concreteValue) +} + +func (x *_Module_3_list) AppendMutable() protoreflect.Value { + panic(fmt.Errorf("AppendMutable can not be called on message Module at list field RestrictionsOrder as it is not of Message kind")) +} + +func (x *_Module_3_list) Truncate(n int) { + *x.list = (*x.list)[:n] +} + +func (x *_Module_3_list) NewElement() protoreflect.Value { + v := "" + return protoreflect.ValueOfString(v) +} + +func (x *_Module_3_list) IsValid() bool { + return x.list != nil +} + var ( md_Module protoreflect.MessageDescriptor fd_Module_blocked_module_accounts_override protoreflect.FieldDescriptor fd_Module_authority protoreflect.FieldDescriptor + fd_Module_restrictions_order protoreflect.FieldDescriptor ) func init() { @@ -70,6 +117,7 @@ func init() { md_Module = File_cosmos_bank_module_v1_module_proto.Messages().ByName("Module") fd_Module_blocked_module_accounts_override = md_Module.Fields().ByName("blocked_module_accounts_override") fd_Module_authority = md_Module.Fields().ByName("authority") + fd_Module_restrictions_order = md_Module.Fields().ByName("restrictions_order") } var _ protoreflect.Message = (*fastReflection_Module)(nil) @@ -149,6 +197,12 @@ func (x *fastReflection_Module) Range(f func(protoreflect.FieldDescriptor, proto return } } + if len(x.RestrictionsOrder) != 0 { + value := protoreflect.ValueOfList(&_Module_3_list{list: &x.RestrictionsOrder}) + if !f(fd_Module_restrictions_order, value) { + return + } + } } // Has reports whether a field is populated. @@ -168,6 +222,8 @@ func (x *fastReflection_Module) Has(fd protoreflect.FieldDescriptor) bool { return len(x.BlockedModuleAccountsOverride) != 0 case "cosmos.bank.module.v1.Module.authority": return x.Authority != "" + case "cosmos.bank.module.v1.Module.restrictions_order": + return len(x.RestrictionsOrder) != 0 default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.bank.module.v1.Module")) @@ -188,6 +244,8 @@ func (x *fastReflection_Module) Clear(fd protoreflect.FieldDescriptor) { x.BlockedModuleAccountsOverride = nil case "cosmos.bank.module.v1.Module.authority": x.Authority = "" + case "cosmos.bank.module.v1.Module.restrictions_order": + x.RestrictionsOrder = nil default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.bank.module.v1.Module")) @@ -213,6 +271,12 @@ func (x *fastReflection_Module) Get(descriptor protoreflect.FieldDescriptor) pro case "cosmos.bank.module.v1.Module.authority": value := x.Authority return protoreflect.ValueOfString(value) + case "cosmos.bank.module.v1.Module.restrictions_order": + if len(x.RestrictionsOrder) == 0 { + return protoreflect.ValueOfList(&_Module_3_list{}) + } + listValue := &_Module_3_list{list: &x.RestrictionsOrder} + return protoreflect.ValueOfList(listValue) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.bank.module.v1.Module")) @@ -239,6 +303,10 @@ func (x *fastReflection_Module) Set(fd protoreflect.FieldDescriptor, value proto x.BlockedModuleAccountsOverride = *clv.list case "cosmos.bank.module.v1.Module.authority": x.Authority = value.Interface().(string) + case "cosmos.bank.module.v1.Module.restrictions_order": + lv := value.List() + clv := lv.(*_Module_3_list) + x.RestrictionsOrder = *clv.list default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.bank.module.v1.Module")) @@ -265,6 +333,12 @@ func (x *fastReflection_Module) Mutable(fd protoreflect.FieldDescriptor) protore } value := &_Module_1_list{list: &x.BlockedModuleAccountsOverride} return protoreflect.ValueOfList(value) + case "cosmos.bank.module.v1.Module.restrictions_order": + if x.RestrictionsOrder == nil { + x.RestrictionsOrder = []string{} + } + value := &_Module_3_list{list: &x.RestrictionsOrder} + return protoreflect.ValueOfList(value) case "cosmos.bank.module.v1.Module.authority": panic(fmt.Errorf("field authority of message cosmos.bank.module.v1.Module is not mutable")) default: @@ -285,6 +359,9 @@ func (x *fastReflection_Module) NewField(fd protoreflect.FieldDescriptor) protor return protoreflect.ValueOfList(&_Module_1_list{list: &list}) case "cosmos.bank.module.v1.Module.authority": return protoreflect.ValueOfString("") + case "cosmos.bank.module.v1.Module.restrictions_order": + list := []string{} + return protoreflect.ValueOfList(&_Module_3_list{list: &list}) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.bank.module.v1.Module")) @@ -364,6 +441,12 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { if l > 0 { n += 1 + l + runtime.Sov(uint64(l)) } + if len(x.RestrictionsOrder) > 0 { + for _, s := range x.RestrictionsOrder { + l = len(s) + n += 1 + l + runtime.Sov(uint64(l)) + } + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -393,6 +476,15 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if len(x.RestrictionsOrder) > 0 { + for iNdEx := len(x.RestrictionsOrder) - 1; iNdEx >= 0; iNdEx-- { + i -= len(x.RestrictionsOrder[iNdEx]) + copy(dAtA[i:], x.RestrictionsOrder[iNdEx]) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.RestrictionsOrder[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } if len(x.Authority) > 0 { i -= len(x.Authority) copy(dAtA[i:], x.Authority) @@ -522,6 +614,38 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { } x.Authority = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field RestrictionsOrder", wireType) + } + var stringLen uint64 + 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++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.RestrictionsOrder = append(x.RestrictionsOrder, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -582,6 +706,11 @@ type Module struct { BlockedModuleAccountsOverride []string `protobuf:"bytes,1,rep,name=blocked_module_accounts_override,json=blockedModuleAccountsOverride,proto3" json:"blocked_module_accounts_override,omitempty"` // authority defines the custom module authority. If not set, defaults to the governance module. Authority string `protobuf:"bytes,2,opt,name=authority,proto3" json:"authority,omitempty"` + // restrictions_order specifies the order of send restrictions and should be + // a list of module names which provide a send restriction instance. If no + // order is provided, then restrictions will be applied in alphabetical order + // of module names. + RestrictionsOrder []string `protobuf:"bytes,3,rep,name=restrictions_order,json=restrictionsOrder,proto3" json:"restrictions_order,omitempty"` } func (x *Module) Reset() { @@ -618,6 +747,13 @@ func (x *Module) GetAuthority() string { return "" } +func (x *Module) GetRestrictionsOrder() []string { + if x != nil { + return x.RestrictionsOrder + } + return nil +} + var File_cosmos_bank_module_v1_module_proto protoreflect.FileDescriptor var file_cosmos_bank_module_v1_module_proto_rawDesc = []byte{ @@ -626,30 +762,33 @@ var file_cosmos_bank_module_v1_module_proto_rawDesc = []byte{ 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x15, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x6e, 0x6b, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, - 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x8c, 0x01, + 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xbb, 0x01, 0x0a, 0x06, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x12, 0x47, 0x0a, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x5f, 0x6f, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64, 0x65, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x1d, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x4f, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x3a, - 0x1b, 0xba, 0xc0, 0x96, 0xda, 0x01, 0x15, 0x0a, 0x13, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, - 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x78, 0x2f, 0x62, 0x61, 0x6e, 0x6b, 0x42, 0xd0, 0x01, 0x0a, - 0x19, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x6e, 0x6b, - 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x4d, 0x6f, 0x64, 0x75, - 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x2f, 0x62, 0x61, 0x6e, 0x6b, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, - 0x31, 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x42, 0x4d, - 0xaa, 0x02, 0x15, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x42, 0x61, 0x6e, 0x6b, 0x2e, 0x4d, - 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x15, 0x43, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x5c, 0x42, 0x61, 0x6e, 0x6b, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, - 0xe2, 0x02, 0x21, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x42, 0x61, 0x6e, 0x6b, 0x5c, 0x4d, - 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, - 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x42, - 0x61, 0x6e, 0x6b, 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x12, + 0x2d, 0x0a, 0x12, 0x72, 0x65, 0x73, 0x74, 0x72, 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5f, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x11, 0x72, 0x65, 0x73, + 0x74, 0x72, 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x3a, 0x1b, + 0xba, 0xc0, 0x96, 0xda, 0x01, 0x15, 0x0a, 0x13, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, + 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x78, 0x2f, 0x62, 0x61, 0x6e, 0x6b, 0x42, 0xd0, 0x01, 0x0a, 0x19, + 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x6e, 0x6b, 0x2e, + 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x4d, 0x6f, 0x64, 0x75, 0x6c, + 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2f, 0x62, 0x61, 0x6e, 0x6b, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, + 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x42, 0x4d, 0xaa, + 0x02, 0x15, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x42, 0x61, 0x6e, 0x6b, 0x2e, 0x4d, 0x6f, + 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x15, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x5c, 0x42, 0x61, 0x6e, 0x6b, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, + 0x02, 0x21, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x42, 0x61, 0x6e, 0x6b, 0x5c, 0x4d, 0x6f, + 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, + 0x61, 0x74, 0x61, 0xea, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x42, 0x61, + 0x6e, 0x6b, 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/cosmos/feegrant/v1beta1/query_grpc.pb.go b/api/cosmos/feegrant/v1beta1/query_grpc.pb.go index 52eb181462f8..23cff18036c4 100644 --- a/api/cosmos/feegrant/v1beta1/query_grpc.pb.go +++ b/api/cosmos/feegrant/v1beta1/query_grpc.pb.go @@ -30,7 +30,7 @@ const ( // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type QueryClient interface { - // Allowance returns granted allwance to the grantee by the granter. + // Allowance returns granted allowance to the grantee by the granter. Allowance(ctx context.Context, in *QueryAllowanceRequest, opts ...grpc.CallOption) (*QueryAllowanceResponse, error) // Allowances returns all the grants for the given grantee address. Allowances(ctx context.Context, in *QueryAllowancesRequest, opts ...grpc.CallOption) (*QueryAllowancesResponse, error) @@ -79,7 +79,7 @@ func (c *queryClient) AllowancesByGranter(ctx context.Context, in *QueryAllowanc // All implementations must embed UnimplementedQueryServer // for forward compatibility type QueryServer interface { - // Allowance returns granted allwance to the grantee by the granter. + // Allowance returns granted allowance to the grantee by the granter. Allowance(context.Context, *QueryAllowanceRequest) (*QueryAllowanceResponse, error) // Allowances returns all the grants for the given grantee address. Allowances(context.Context, *QueryAllowancesRequest) (*QueryAllowancesResponse, error) diff --git a/baseapp/abci.go b/baseapp/abci.go index e54824f41e0f..148205e360e6 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -177,7 +177,7 @@ func (app *BaseApp) Query(_ context.Context, req *abci.RequestQuery) (resp *abci telemetry.IncrCounter(1, "query", "count") telemetry.IncrCounter(1, "query", req.Path) - defer telemetry.MeasureSince(time.Now(), req.Path) + defer telemetry.MeasureSince(telemetry.Now(), req.Path) if req.Path == QueryPathBroadcastTx { return sdkerrors.QueryResult(errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "can't route a broadcast tx message"), app.trace), nil @@ -1242,7 +1242,7 @@ func (app *BaseApp) CreateQueryContext(height int64, prove bool) (sdk.Context, e if err != nil { return sdk.Context{}, errorsmod.Wrapf( - sdkerrors.ErrInvalidRequest, + sdkerrors.ErrNotFound, "failed to load state at height %d; %s (latest height: %d)", height, err, lastBlockHeight, ) } diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 33c4d75284bb..4a3693094353 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -1404,7 +1404,7 @@ func TestPrecommiterCalledWithDeliverState(t *testing.T) { func TestABCI_Proposal_HappyPath(t *testing.T) { anteKey := []byte("ante-key") - pool := mempool.NewSenderNonceMempool() + pool := mempool.NewSenderNonceMempool(mempool.SenderNonceMaxTxOpt(5000)) anteOpt := func(bapp *baseapp.BaseApp) { bapp.SetAnteHandler(anteHandlerTxTest(t, capKey1, anteKey)) } @@ -1582,7 +1582,7 @@ func TestABCI_Proposals_WithVE(t *testing.T) { func TestABCI_PrepareProposal_ReachedMaxBytes(t *testing.T) { anteKey := []byte("ante-key") - pool := mempool.NewSenderNonceMempool() + pool := mempool.NewSenderNonceMempool(mempool.SenderNonceMaxTxOpt(5000)) anteOpt := func(bapp *baseapp.BaseApp) { bapp.SetAnteHandler(anteHandlerTxTest(t, capKey1, anteKey)) } @@ -1612,7 +1612,7 @@ func TestABCI_PrepareProposal_ReachedMaxBytes(t *testing.T) { func TestABCI_PrepareProposal_BadEncoding(t *testing.T) { anteKey := []byte("ante-key") - pool := mempool.NewSenderNonceMempool() + pool := mempool.NewSenderNonceMempool(mempool.SenderNonceMaxTxOpt(5000)) anteOpt := func(bapp *baseapp.BaseApp) { bapp.SetAnteHandler(anteHandlerTxTest(t, capKey1, anteKey)) } @@ -1639,7 +1639,7 @@ func TestABCI_PrepareProposal_BadEncoding(t *testing.T) { } func TestABCI_PrepareProposal_OverGasUnderBytes(t *testing.T) { - pool := mempool.NewSenderNonceMempool() + pool := mempool.NewSenderNonceMempool(mempool.SenderNonceMaxTxOpt(5000)) suite := NewBaseAppSuite(t, baseapp.SetMempool(pool)) baseapptestutil.RegisterCounterServer(suite.baseApp.MsgServiceRouter(), NoopCounterServerImpl{}) @@ -1680,7 +1680,7 @@ func TestABCI_PrepareProposal_OverGasUnderBytes(t *testing.T) { } func TestABCI_PrepareProposal_MaxGas(t *testing.T) { - pool := mempool.NewSenderNonceMempool() + pool := mempool.NewSenderNonceMempool(mempool.SenderNonceMaxTxOpt(5000)) suite := NewBaseAppSuite(t, baseapp.SetMempool(pool)) baseapptestutil.RegisterCounterServer(suite.baseApp.MsgServiceRouter(), NoopCounterServerImpl{}) @@ -1719,7 +1719,7 @@ func TestABCI_PrepareProposal_MaxGas(t *testing.T) { func TestABCI_PrepareProposal_Failures(t *testing.T) { anteKey := []byte("ante-key") - pool := mempool.NewSenderNonceMempool() + pool := mempool.NewSenderNonceMempool(mempool.SenderNonceMaxTxOpt(5000)) anteOpt := func(bapp *baseapp.BaseApp) { bapp.SetAnteHandler(anteHandlerTxTest(t, capKey1, anteKey)) } diff --git a/client/docs/swagger-ui/swagger.yaml b/client/docs/swagger-ui/swagger.yaml index 173676b0b5f9..587653a77ac6 100644 --- a/client/docs/swagger-ui/swagger.yaml +++ b/client/docs/swagger-ui/swagger.yaml @@ -29488,7 +29488,7 @@ paths: - Query /cosmos/feegrant/v1beta1/allowance/{granter}/{grantee}: get: - summary: Allowance returns granted allwance to the grantee by the granter. + summary: Allowance returns granted allowance to the grantee by the granter. operationId: Allowance responses: '200': diff --git a/client/flags/flags.go b/client/flags/flags.go index f2af30eb0714..801b7f5796a8 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -126,7 +126,7 @@ func AddTxFlagsToCmd(cmd *cobra.Command) { f.Uint64P(FlagSequence, "s", 0, "The sequence number of the signing account (offline mode only)") f.String(FlagNote, "", "Note to add a description to the transaction (previously --memo)") f.String(FlagFees, "", "Fees to pay along with transaction; eg: 10uatom") - f.String(FlagGasPrices, "", "Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom)") + f.String(FlagGasPrices, "", "Determine the transaction fee by multiplying max gas units by gas prices (e.g. 0.1uatom), rounding up to nearest denom unit") f.String(FlagNode, "tcp://localhost:26657", ": to CometBFT rpc interface for this chain") f.Bool(FlagUseLedger, false, "Use a connected Ledger device") f.Float64(FlagGasAdjustment, DefaultGasAdjustment, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ") diff --git a/client/rpc/rpc_test.go b/client/rpc/rpc_test.go index 7606602127f4..4fa96fa9c2e6 100644 --- a/client/rpc/rpc_test.go +++ b/client/rpc/rpc_test.go @@ -10,6 +10,8 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/metadata" + _ "cosmossdk.io/x/accounts" + "github.com/cosmos/cosmos-sdk/testutil/network" "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/cosmos/cosmos-sdk/types/address" diff --git a/client/v2/CHANGELOG.md b/client/v2/CHANGELOG.md index efabebf0491c..eabfebff70a5 100644 --- a/client/v2/CHANGELOG.md +++ b/client/v2/CHANGELOG.md @@ -48,11 +48,12 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#19618](https://github.com/cosmos/cosmos-sdk/pull/19618) Marshal enum as string in queries. * [#19060](https://github.com/cosmos/cosmos-sdk/pull/19060) Use client context from root (or enhanced) command in autocli commands. - * Note, the given command must have a `client.Context` in its context. + * Note, the given command must have a `client.Context` in its context. * [#19216](https://github.com/cosmos/cosmos-sdk/pull/19216) Do not overwrite TxConfig, use directly the one provided in context. TxConfig should always be set in the `client.Context` in `root.go` of an app. ### Bug Fixes +* [#19976](https://github.com/cosmos/cosmos-sdk/pull/19976) Add encoder for `cosmos.base.v1beta1.DecCoin`. * [#19377](https://github.com/cosmos/cosmos-sdk/pull/19377) Partly fix comment parsing in autocli. * [#19060](https://github.com/cosmos/cosmos-sdk/pull/19060) Simplify key flag parsing logic in flag handler. diff --git a/client/v2/autocli/query.go b/client/v2/autocli/query.go index d93edb4dfce7..c2a3717a44bb 100644 --- a/client/v2/autocli/query.go +++ b/client/v2/autocli/query.go @@ -4,9 +4,11 @@ import ( "context" "fmt" "io" + "strings" "time" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + "cosmossdk.io/math" "cosmossdk.io/x/tx/signing/aminojson" "github.com/cockroachdb/errors" "github.com/spf13/cobra" @@ -14,6 +16,8 @@ import ( "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/client/v2/internal/util" + + sdk "github.com/cosmos/cosmos-sdk/types" ) // BuildQueryCommand builds the query commands for all the provided modules. If a custom command is provided for a @@ -182,5 +186,41 @@ func encoder(encoder aminojson.Encoder) aminojson.Encoder { _, err := fmt.Fprintf(w, `"%s"`, (time.Duration(seconds)*time.Second + (time.Duration(nanos) * time.Nanosecond)).String()) return err + }).DefineTypeEncoding("cosmos.base.v1beta1.DecCoin", func(_ *aminojson.Encoder, msg protoreflect.Message, w io.Writer) error { + var ( + denomName protoreflect.Name = "denom" + amountName protoreflect.Name = "amount" + ) + + fields := msg.Descriptor().Fields() + denomField := fields.ByName(denomName) + if denomField == nil { + return fmt.Errorf("expected denom field") + } + + denom := msg.Get(denomField).String() + + amountField := fields.ByName(amountName) + if amountField == nil { + return fmt.Errorf("expected amount field") + } + + amount := msg.Get(amountField).String() + decimalPlace := len(amount) - math.LegacyPrecision + if decimalPlace > 0 { + amount = amount[:decimalPlace] + "." + amount[decimalPlace:] + } else if decimalPlace == 0 { + amount = "0." + amount + } else { + amount = "0." + strings.Repeat("0", -decimalPlace) + amount + } + + amountDec, err := math.LegacyNewDecFromStr(amount) + if err != nil { + return fmt.Errorf("invalid amount: %s: %w", amount, err) + } + + _, err = fmt.Fprintf(w, `"%s"`, sdk.NewDecCoinFromDec(denom, amountDec)) // TODO(@julienrbrt): Eventually remove this SDK dependency + return err }) } diff --git a/client/v2/autocli/testdata/help-echo-msg.golden b/client/v2/autocli/testdata/help-echo-msg.golden index a4ba521452ea..fc981ffd4611 100644 --- a/client/v2/autocli/testdata/help-echo-msg.golden +++ b/client/v2/autocli/testdata/help-echo-msg.golden @@ -15,7 +15,7 @@ Flags: --from string Name or address of private key with which to sign --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000) --gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1) - --gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom) + --gas-prices string Determine the transaction fee by multiplying max gas units by gas prices (e.g. 0.1uatom), rounding up to nearest denom unit --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) -h, --help help for send --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) (default "os") diff --git a/client/v2/go.mod b/client/v2/go.mod index 7be3e4429468..bbaefd535743 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -26,7 +26,7 @@ require ( cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/log v1.3.1 // indirect - cosmossdk.io/math v1.3.0 // indirect + cosmossdk.io/math v1.3.0 cosmossdk.io/store v1.0.2 // indirect cosmossdk.io/x/accounts v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 @@ -152,7 +152,7 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/client/v2/go.sum b/client/v2/go.sum index 5274840dc953..4b7075529528 100644 --- a/client/v2/go.sum +++ b/client/v2/go.sum @@ -820,8 +820,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/core/transaction/service.go b/core/transaction/service.go index bddc2ba4e634..627fb3f85dc3 100644 --- a/core/transaction/service.go +++ b/core/transaction/service.go @@ -9,7 +9,7 @@ type ExecMode uint8 // For backwards compatibility and easier casting, the exec mode values must be the same as in cosmos/cosmos-sdk/types package. const ( ExecModeCheck ExecMode = iota - _ + ExecModeReCheck ExecModeSimulate _ _ diff --git a/crypto/keys/secp256r1/privkey.go b/crypto/keys/secp256r1/privkey.go index 0e8ef46ca310..463a7c063c8d 100644 --- a/crypto/keys/secp256r1/privkey.go +++ b/crypto/keys/secp256r1/privkey.go @@ -1,10 +1,14 @@ package secp256r1 import ( + "encoding/base64" + "github.com/cosmos/cosmos-sdk/crypto/keys/internal/ecdsa" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" ) +var _ customProtobufType = (*ecdsaSK)(nil) + // GenPrivKey generates a new secp256r1 private key. It uses operating system randomness. func GenPrivKey() (*PrivKey, error) { key, err := ecdsa.GenPrivKey(secp256r1) @@ -52,6 +56,27 @@ type ecdsaSK struct { ecdsa.PrivKey } +// Marshal implements customProtobufType. +func (sk ecdsaSK) Marshal() ([]byte, error) { + return sk.PrivKey.Bytes(), nil +} + +// MarshalJSON implements customProtobufType. +func (sk ecdsaSK) MarshalJSON() ([]byte, error) { + b64 := base64.StdEncoding.EncodeToString(sk.PrivKey.Bytes()) + return []byte(b64), nil +} + +// UnmarshalJSON implements customProtobufType. +func (sk *ecdsaSK) UnmarshalJSON(data []byte) error { + bz, err := base64.StdEncoding.DecodeString(string(data)) + if err != nil { + return err + } + + return sk.PrivKey.Unmarshal(bz, secp256r1, fieldSize) +} + // Size implements proto.Marshaler interface func (sk *ecdsaSK) Size() int { if sk == nil { diff --git a/crypto/keys/secp256r1/privkey_internal_test.go b/crypto/keys/secp256r1/privkey_internal_test.go index 902ee6dafbf8..52ea3239dac6 100644 --- a/crypto/keys/secp256r1/privkey_internal_test.go +++ b/crypto/keys/secp256r1/privkey_internal_test.go @@ -113,3 +113,14 @@ func (suite *SKSuite) TestSize() { var nilPk *ecdsaSK require.Equal(0, nilPk.Size(), "nil value must have zero size") } + +func (suite *SKSuite) TestJson() { + require := suite.Require() + asd := suite.sk.(*PrivKey) + bz, err := asd.Secret.MarshalJSON() + require.NoError(err) + + sk := &ecdsaSK{} + require.NoError(sk.UnmarshalJSON(bz)) + require.Equal(suite.sk.(*PrivKey).Secret, sk) +} diff --git a/crypto/keys/secp256r1/pubkey.go b/crypto/keys/secp256r1/pubkey.go index cacec514c3d7..c0d4cfc956b8 100644 --- a/crypto/keys/secp256r1/pubkey.go +++ b/crypto/keys/secp256r1/pubkey.go @@ -1,6 +1,8 @@ package secp256r1 import ( + "encoding/base64" + cmtcrypto "github.com/cometbft/cometbft/crypto" "github.com/cosmos/gogoproto/proto" @@ -8,6 +10,20 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" ) +// customProtobufType is here to make sure that ecdsaPK and ecdsaSK implement the +// gogoproto customtype interface. +type customProtobufType interface { + Marshal() ([]byte, error) + MarshalTo(data []byte) (n int, err error) + Unmarshal(data []byte) error + Size() int + + MarshalJSON() ([]byte, error) + UnmarshalJSON(data []byte) error +} + +var _ customProtobufType = (*ecdsaPK)(nil) + // String implements proto.Message interface. func (m *PubKey) String() string { return m.Key.String(name) @@ -49,6 +65,27 @@ type ecdsaPK struct { ecdsa.PubKey } +// Marshal implements customProtobufType. +func (pk ecdsaPK) Marshal() ([]byte, error) { + return pk.PubKey.Bytes(), nil +} + +// MarshalJSON implements customProtobufType. +func (pk ecdsaPK) MarshalJSON() ([]byte, error) { + b64 := base64.StdEncoding.EncodeToString(pk.PubKey.Bytes()) + return []byte(b64), nil +} + +// UnmarshalJSON implements customProtobufType. +func (pk *ecdsaPK) UnmarshalJSON(data []byte) error { + bz, err := base64.StdEncoding.DecodeString(string(data)) + if err != nil { + return err + } + + return pk.PubKey.Unmarshal(bz, secp256r1, pubKeySize) +} + // Size implements proto.Marshaler interface func (pk *ecdsaPK) Size() int { if pk == nil { diff --git a/crypto/keys/secp256r1/pubkey_internal_test.go b/crypto/keys/secp256r1/pubkey_internal_test.go index d3d2ed3823eb..77f4a66e5114 100644 --- a/crypto/keys/secp256r1/pubkey_internal_test.go +++ b/crypto/keys/secp256r1/pubkey_internal_test.go @@ -126,3 +126,14 @@ func (suite *PKSuite) TestSize() { var nilPk *ecdsaPK require.Equal(0, nilPk.Size(), "nil value must have zero size") } + +func (suite *PKSuite) TestJson() { + require := suite.Require() + + bz, err := suite.pk.Key.MarshalJSON() + require.NoError(err) + + pk := &ecdsaPK{} + require.NoError(pk.UnmarshalJSON(bz)) + require.Equal(suite.pk.Key, pk) +} diff --git a/docs/build/building-modules/05-protobuf-annotations.md b/docs/build/building-modules/05-protobuf-annotations.md index 5eaee51b8139..fe212f726b0e 100644 --- a/docs/build/building-modules/05-protobuf-annotations.md +++ b/docs/build/building-modules/05-protobuf-annotations.md @@ -126,8 +126,21 @@ Encoding instructs the amino json marshaler how to encode certain fields that ma https://github.com/cosmos/cosmos-sdk/blob/e8f28bf5db18b8d6b7e0d94b542ce4cf48fed9d6/proto/cosmos/bank/v1beta1/genesis.proto#L23 ``` -Another example is how `bytes` is encoded when using the amino json encoding format. The `bytes_as_string` option tells the json marshaler [how to encode bytes as string](https://github.com/pinosu/cosmos-sdk/blob/9879ece09c58068402782fa2096199dc89a23d13/x/tx/signing/aminojson/json_marshal.go#L75). +Another example is a protobuf `bytes` that contains a valid JSON document. +The `inline_json` option tells the json marshaler to embed the JSON bytes into the wrapping document without escaping. ```proto -(amino.encoding) = "bytes_as_string", -``` \ No newline at end of file +(amino.encoding) = "inline_json", +``` + +E.g. the bytes containing `{"foo":123}` in the `envelope` field would lead to the following JSON: + +```json +{ + "envelope": { + "foo": 123 + } +} +``` + +If the bytes are not valid JSON, this leads to JSON broken documents. Thus a JSON validity check needs to be in place at some point of the process. diff --git a/go.mod b/go.mod index d47c3195a8ea..668ee0e48882 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( cosmossdk.io/log v1.3.1 cosmossdk.io/math v1.3.0 cosmossdk.io/store v1.0.2 + cosmossdk.io/x/accounts v0.0.0-00010101000000-000000000000 cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 cosmossdk.io/x/bank v0.0.0-00010101000000-000000000000 cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 @@ -56,7 +57,7 @@ require ( gitlab.com/yawning/secp256k1-voi v0.0.0-20230925100816-f2616030848b golang.org/x/crypto v0.22.0 golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 - golang.org/x/sync v0.6.0 + golang.org/x/sync v0.7.0 google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de google.golang.org/grpc v1.63.2 google.golang.org/protobuf v1.33.0 @@ -68,7 +69,6 @@ require ( require ( buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.32.0-20230509103710-5e5b9fdd0180.1 // indirect buf.build/gen/go/tendermint/tendermint/protocolbuffers/go v1.32.0-20231117195010-33ed361a9051.1 // indirect - cosmossdk.io/x/accounts v0.0.0-00010101000000-000000000000 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/DataDog/datadog-go v4.8.3+incompatible // indirect diff --git a/go.sum b/go.sum index 034e5941143f..a8df3ad45873 100644 --- a/go.sum +++ b/go.sum @@ -837,8 +837,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/server/api/server_test.go b/server/api/server_test.go index 1dbc7e6677cb..d867678883aa 100644 --- a/server/api/server_test.go +++ b/server/api/server_test.go @@ -18,6 +18,7 @@ import ( "github.com/stretchr/testify/suite" "google.golang.org/grpc/codes" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" _ "cosmossdk.io/x/auth/tx/config" _ "cosmossdk.io/x/bank" diff --git a/server/config/config.go b/server/config/config.go index f3e5b04913bf..9099fdb3e5bc 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -263,7 +263,7 @@ func DefaultConfig() *Config { }, }, Mempool: MempoolConfig{ - MaxTxs: 5_000, + MaxTxs: -1, }, } } diff --git a/server/config/toml.go b/server/config/toml.go index f06ece5071f8..016cd36643e4 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -240,7 +240,7 @@ stop-node-on-err = {{ .Streaming.ABCI.StopNodeOnErr }} [mempool] # Setting max-txs to 0 will allow for a unbounded amount of transactions in the mempool. -# Setting max_txs to negative 1 (-1) will disable transactions from being inserted into the mempool. +# Setting max_txs to negative 1 (-1) will disable transactions from being inserted into the mempool (no-op mempool). # Setting max_txs to a positive number (> 0) will limit the number of transactions in the mempool, by the specified amount. # # Note, this configuration only applies to SDK built-in app-side mempool diff --git a/server/start.go b/server/start.go index cfed5a393a12..4c2d39022053 100644 --- a/server/start.go +++ b/server/start.go @@ -533,10 +533,6 @@ func startAPIServer( } func startTelemetry(cfg serverconfig.Config) (*telemetry.Metrics, error) { - if !cfg.Telemetry.Enabled { - return nil, nil - } - return telemetry.New(cfg.Telemetry) } diff --git a/simapp/ante.go b/simapp/ante.go index 8fde65c79aee..713c342b8bcf 100644 --- a/simapp/ante.go +++ b/simapp/ante.go @@ -37,9 +37,9 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first circuitante.NewCircuitBreakerDecorator(options.CircuitKeeper), ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker), - ante.NewValidateBasicDecorator(), + ante.NewValidateBasicDecorator(options.AccountKeeper.Environment()), ante.NewTxTimeoutHeightDecorator(), - ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, options.TxManager), + ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, options.TxManager, options.AccountKeeper.Environment()), ante.NewValidateMemoDecorator(options.AccountKeeper), ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker), diff --git a/simapp/app.go b/simapp/app.go index bee3d1931335..1c077ed7fb21 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -309,7 +309,7 @@ func NewSimApp( } app.AccountsKeeper = accountsKeeper - app.AuthKeeper = authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), logger), appCodec, authtypes.ProtoBaseAccount, maccPerms, signingCtx.AddressCodec(), sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + app.AuthKeeper = authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), logger), appCodec, authtypes.ProtoBaseAccount, maccPerms, signingCtx.AddressCodec(), sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AccountsKeeper) app.BankKeeper = bankkeeper.NewBaseKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[banktypes.StoreKey]), logger), diff --git a/simapp/app_config.go b/simapp/app_config.go index 46eadb103a7e..95d978c7a6cc 100644 --- a/simapp/app_config.go +++ b/simapp/app_config.go @@ -6,6 +6,7 @@ import ( "google.golang.org/protobuf/types/known/durationpb" + accountsmodulev1 "cosmossdk.io/api/cosmos/accounts/module/v1" runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" @@ -29,6 +30,7 @@ import ( upgrademodulev1 "cosmossdk.io/api/cosmos/upgrade/module/v1" vestingmodulev1 "cosmossdk.io/api/cosmos/vesting/module/v1" "cosmossdk.io/depinject/appconfig" + "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth/tx/config" // import for side-effects authtypes "cosmossdk.io/x/auth/types" _ "cosmossdk.io/x/auth/vesting" // import for side-effects @@ -138,6 +140,7 @@ var ( // properly initialized with tokens from genesis accounts. // NOTE: The genutils module must also occur after auth so that it can access the params from auth. InitGenesis: []string{ + accounts.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, @@ -198,8 +201,10 @@ var ( Config: appconfig.WrapAny(&slashingmodulev1.Module{}), }, { - Name: "tx", - Config: appconfig.WrapAny(&txconfigv1.Config{}), + Name: "tx", + Config: appconfig.WrapAny(&txconfigv1.Config{ + SkipAnteHandler: true, // SimApp is using non default AnteHandler such as circuit and unorderedtx decorators + }), }, { Name: genutiltypes.ModuleName, @@ -256,6 +261,10 @@ var ( Name: pooltypes.ModuleName, Config: appconfig.WrapAny(&poolmodulev1.Module{}), }, + { + Name: accounts.ModuleName, + Config: appconfig.WrapAny(&accountsmodulev1.Module{}), + }, { Name: epochstypes.ModuleName, Config: appconfig.WrapAny(&epochsmodulev1.Module{}), diff --git a/simapp/app_di.go b/simapp/app_di.go index efaca0e3e21f..b223e8e4f797 100644 --- a/simapp/app_di.go +++ b/simapp/app_di.go @@ -15,7 +15,9 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" + "cosmossdk.io/x/accounts" "cosmossdk.io/x/auth" + "cosmossdk.io/x/auth/ante" "cosmossdk.io/x/auth/ante/unorderedtx" authkeeper "cosmossdk.io/x/auth/keeper" authsims "cosmossdk.io/x/auth/simulation" @@ -73,6 +75,7 @@ type SimApp struct { UnorderedTxManager *unorderedtx.Manager // keepers + AccountsKeeper accounts.Keeper AuthKeeper authkeeper.AccountKeeper BankKeeper bankkeeper.Keeper StakingKeeper *stakingkeeper.Keeper @@ -183,6 +186,7 @@ func NewSimApp( &app.txConfig, &app.interfaceRegistry, &app.AuthKeeper, + &app.AccountsKeeper, &app.BankKeeper, &app.StakingKeeper, &app.SlashingKeeper, @@ -292,6 +296,9 @@ func NewSimApp( } } + // set custom ante handlers + app.setCustomAnteHandler() + if err := app.Load(loadLatest); err != nil { panic(err) } @@ -299,6 +306,30 @@ func NewSimApp( return app } +// overwritte default ante handlers with custom ante handlers +// set SkipAnteHandler to true in app config and set custom ante handler on baseapp +func (app *SimApp) setCustomAnteHandler() { + anteHandler, err := NewAnteHandler( + HandlerOptions{ + ante.HandlerOptions{ + AccountKeeper: app.AuthKeeper, + BankKeeper: app.BankKeeper, + SignModeHandler: app.txConfig.SignModeHandler(), + FeegrantKeeper: app.FeeGrantKeeper, + SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + }, + &app.CircuitBreakerKeeper, + app.UnorderedTxManager, + }, + ) + if err != nil { + panic(err) + } + + // Set the AnteHandler for the app + app.SetAnteHandler(anteHandler) +} + // Close implements the Application interface and closes all necessary application // resources. func (app *SimApp) Close() error { diff --git a/simapp/go.mod b/simapp/go.mod index d2d99c08931c..36fa6263788b 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -205,7 +205,7 @@ require ( golang.org/x/mod v0.16.0 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/oauth2 v0.18.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/simapp/go.sum b/simapp/go.sum index 57eb3e80623d..256e6f6fc6d0 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -1230,8 +1230,8 @@ golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index e5421a84e37f..58e93e130d52 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -27,6 +27,7 @@ import ( func Test_TestnetCmd(t *testing.T) { config := configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.GenutilModule(), @@ -44,7 +45,7 @@ func Test_TestnetCmd(t *testing.T) { ) require.NoError(t, err) require.NotNil(t, moduleManager) - require.Len(t, moduleManager.Modules, 7) + require.Len(t, moduleManager.Modules, 8) home := t.TempDir() cdcOpts := codectestutil.CodecOptions{} diff --git a/simapp/upgrades.go b/simapp/upgrades.go index ebe4cf20b4f3..4351e99f1063 100644 --- a/simapp/upgrades.go +++ b/simapp/upgrades.go @@ -5,9 +5,9 @@ import ( storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/accounts" + epochstypes "cosmossdk.io/x/epochs/types" protocolpooltypes "cosmossdk.io/x/protocolpool/types" upgradetypes "cosmossdk.io/x/upgrade/types" - "github.com/cosmos/cosmos-sdk/types/module" crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" ) @@ -38,6 +38,7 @@ func (app SimApp) RegisterUpgradeHandlers() { Added: []string{ accounts.StoreKey, protocolpooltypes.StoreKey, + epochstypes.StoreKey, }, Deleted: []string{ crisistypes.StoreKey, // The SDK discontinued the crisis module in v0.51.0 diff --git a/store/go.mod b/store/go.mod index f635677029fb..0446be569f85 100644 --- a/store/go.mod +++ b/store/go.mod @@ -19,7 +19,7 @@ require ( github.com/spf13/cast v1.6.0 github.com/stretchr/testify v1.9.0 github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d - golang.org/x/sync v0.6.0 + golang.org/x/sync v0.7.0 ) require ( diff --git a/store/go.sum b/store/go.sum index 21e7cf2105b2..b626978b5d70 100644 --- a/store/go.sum +++ b/store/go.sum @@ -261,8 +261,8 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/store/snapshots/manager.go b/store/snapshots/manager.go index 634f2d5b5b86..4c54ac4c6bae 100644 --- a/store/snapshots/manager.go +++ b/store/snapshots/manager.go @@ -73,7 +73,7 @@ const ( snapshotMaxItemSize = int(64e6) // SDK has no key/value size limit, so we set an arbitrary limit ) -var ErrOptsZeroSnapshotInterval = errors.New("snaphot-interval must not be 0") +var ErrOptsZeroSnapshotInterval = errors.New("snapshot-interval must not be 0") // NewManager creates a new manager. func NewManager(store *Store, opts SnapshotOptions, commitSnapshotter CommitSnapshotter, storageSnapshotter StorageSnapshotter, extensions map[string]ExtensionSnapshotter, logger log.Logger) *Manager { diff --git a/telemetry/metrics.go b/telemetry/metrics.go index 502fdb611209..07d1020eb892 100644 --- a/telemetry/metrics.go +++ b/telemetry/metrics.go @@ -14,6 +14,15 @@ import ( "github.com/prometheus/common/expfmt" ) +// globalTelemetryEnabled is a private variable that stores the telemetry enabled state. +// It is set on initialization and does not change for the lifetime of the program. +var globalTelemetryEnabled bool + +// IsTelemetryEnabled provides controlled access to check if telemetry is enabled. +func IsTelemetryEnabled() bool { + return globalTelemetryEnabled +} + // globalLabels defines the set of global labels that will be applied to all // metrics emitted using the telemetry package function wrappers. var globalLabels = []metrics.Label{} @@ -95,6 +104,7 @@ type GatherResponse struct { // New creates a new instance of Metrics func New(cfg Config) (_ *Metrics, rerr error) { + globalTelemetryEnabled = cfg.Enabled if !cfg.Enabled { return nil, nil } diff --git a/telemetry/wrapper.go b/telemetry/wrapper.go index 4cd96b78f715..da11f1fa0450 100644 --- a/telemetry/wrapper.go +++ b/telemetry/wrapper.go @@ -24,6 +24,10 @@ func NewLabel(name, value string) metrics.Label { // metric for a module with a given set of keys. If any global labels are defined, // they will be added to the module label. func ModuleMeasureSince(module string, start time.Time, keys ...string) { + if !IsTelemetryEnabled() { + return + } + metrics.MeasureSinceWithLabels( keys, start.UTC(), @@ -35,6 +39,10 @@ func ModuleMeasureSince(module string, start time.Time, keys ...string) { // module with a given set of keys. If any global labels are defined, they will // be added to the module label. func ModuleSetGauge(module string, val float32, keys ...string) { + if !IsTelemetryEnabled() { + return + } + metrics.SetGaugeWithLabels( keys, val, @@ -45,29 +53,58 @@ func ModuleSetGauge(module string, val float32, keys ...string) { // IncrCounter provides a wrapper functionality for emitting a counter metric with // global labels (if any). func IncrCounter(val float32, keys ...string) { + if !IsTelemetryEnabled() { + return + } + metrics.IncrCounterWithLabels(keys, val, globalLabels) } // IncrCounterWithLabels provides a wrapper functionality for emitting a counter // metric with global labels (if any) along with the provided labels. func IncrCounterWithLabels(keys []string, val float32, labels []metrics.Label) { + if !IsTelemetryEnabled() { + return + } + metrics.IncrCounterWithLabels(keys, val, append(labels, globalLabels...)) } // SetGauge provides a wrapper functionality for emitting a gauge metric with // global labels (if any). func SetGauge(val float32, keys ...string) { + if !IsTelemetryEnabled() { + return + } + metrics.SetGaugeWithLabels(keys, val, globalLabels) } // SetGaugeWithLabels provides a wrapper functionality for emitting a gauge // metric with global labels (if any) along with the provided labels. func SetGaugeWithLabels(keys []string, val float32, labels []metrics.Label) { + if !IsTelemetryEnabled() { + return + } + metrics.SetGaugeWithLabels(keys, val, append(labels, globalLabels...)) } // MeasureSince provides a wrapper functionality for emitting a a time measure // metric with global labels (if any). func MeasureSince(start time.Time, keys ...string) { + if !IsTelemetryEnabled() { + return + } + metrics.MeasureSinceWithLabels(keys, start.UTC(), globalLabels) } + +// Now return the current time if telemetry is enabled or a zero time if it's not +func Now() time.Time { + if !IsTelemetryEnabled() { + return time.Time{} + } + + return time.Now() +} diff --git a/telemetry/wrapper_test.go b/telemetry/wrapper_test.go new file mode 100644 index 000000000000..5388839874bc --- /dev/null +++ b/telemetry/wrapper_test.go @@ -0,0 +1,51 @@ +package telemetry + +import ( + "sync" + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +var mu sync.Mutex + +func initTelemetry(v bool) { + globalTelemetryEnabled = v +} + +// Reset the global state to a known disabled state before each test. +func setupTest(t *testing.T) { + t.Helper() + mu.Lock() // Ensure no other test can modify global state at the same time. + defer mu.Unlock() + initTelemetry(false) +} + +// TestNow tests the Now function when telemetry is enabled and disabled. +func TestNow(t *testing.T) { + setupTest(t) // Locks the mutex to avoid race condition. + + initTelemetry(true) + telemetryTime := Now() + assert.NotEqual(t, time.Time{}, telemetryTime, "Now() should not return zero time when telemetry is enabled") + + setupTest(t) // Reset the global state and lock the mutex again. + + initTelemetry(false) + telemetryTime = Now() + assert.Equal(t, time.Time{}, telemetryTime, "Now() should return zero time when telemetry is disabled") +} + +// TestIsTelemetryEnabled tests the IsTelemetryEnabled function. +func TestIsTelemetryEnabled(t *testing.T) { + setupTest(t) // Locks the mutex to avoid race condition. + + initTelemetry(true) + assert.True(t, IsTelemetryEnabled(), "IsTelemetryEnabled() should return true when globalTelemetryEnabled is set to true") + + setupTest(t) // Reset the global state and lock the mutex again. + + initTelemetry(false) + assert.False(t, IsTelemetryEnabled(), "IsTelemetryEnabled() should return false when globalTelemetryEnabled is set to false") +} diff --git a/tests/e2e/baseapp/block_gas_test.go b/tests/e2e/baseapp/block_gas_test.go index 134771884df1..0098c2d48650 100644 --- a/tests/e2e/baseapp/block_gas_test.go +++ b/tests/e2e/baseapp/block_gas_test.go @@ -17,6 +17,7 @@ import ( "cosmossdk.io/log" sdkmath "cosmossdk.io/math" store "cosmossdk.io/store/types" + _ "cosmossdk.io/x/accounts" xauthsigning "cosmossdk.io/x/auth/signing" "github.com/cosmos/cosmos-sdk/baseapp" @@ -85,6 +86,7 @@ func TestBaseApp_BlockGas(t *testing.T) { err = depinject.Inject( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.TxModule(), configurator.ConsensusModule(), diff --git a/tests/go.mod b/tests/go.mod index 87022401ab94..305a28684890 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -207,7 +207,7 @@ require ( golang.org/x/mod v0.16.0 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/oauth2 v0.18.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/tests/go.sum b/tests/go.sum index 91af4cd3a083..a43f5ce5eb0f 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -1199,8 +1199,8 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/tests/integration/bank/app_test.go b/tests/integration/bank/app_test.go index d1b2e91dbe36..7043b1eb0be6 100644 --- a/tests/integration/bank/app_test.go +++ b/tests/integration/bank/app_test.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" sdkmath "cosmossdk.io/math" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" _ "cosmossdk.io/x/auth/tx/config" authtypes "cosmossdk.io/x/auth/types" @@ -92,6 +93,7 @@ func createTestSuite(t *testing.T, genesisAccounts []authtypes.GenesisAccount) s app, err := simtestutil.SetupWithConfiguration( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.TxModule(), diff --git a/tests/integration/bank/keeper/deterministic_test.go b/tests/integration/bank/keeper/deterministic_test.go index 78d736143c35..ec399463c11d 100644 --- a/tests/integration/bank/keeper/deterministic_test.go +++ b/tests/integration/bank/keeper/deterministic_test.go @@ -86,6 +86,7 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authority.String(), + nil, ) blockedAddresses := map[string]bool{ diff --git a/tests/integration/distribution/appconfig.go b/tests/integration/distribution/appconfig.go index 7cf9a5a7436b..c22f15e63fd8 100644 --- a/tests/integration/distribution/appconfig.go +++ b/tests/integration/distribution/appconfig.go @@ -1,6 +1,7 @@ package distribution_test import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -15,6 +16,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/integration/distribution/keeper/msg_server_test.go b/tests/integration/distribution/keeper/msg_server_test.go index 962d6c8779e9..386e5edab56a 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" "gotest.tools/v3/assert" @@ -16,6 +17,7 @@ import ( "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" authsims "cosmossdk.io/x/auth/simulation" + authtestutil "cosmossdk.io/x/auth/testutil" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/bank" bankkeeper "cosmossdk.io/x/bank/keeper" @@ -85,6 +87,10 @@ func initFixture(t *testing.T) *fixture { stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, } + // gomock initializations + ctrl := gomock.NewController(t) + acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) + accountKeeper := authkeeper.NewAccountKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()), cdc, @@ -93,6 +99,7 @@ func initFixture(t *testing.T) *fixture { addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authority.String(), + acctsModKeeper, ) blockedAddresses := map[string]bool{ diff --git a/tests/integration/evidence/app_config.go b/tests/integration/evidence/app_config.go index 1132ea10e9f1..6a9bba7e164f 100644 --- a/tests/integration/evidence/app_config.go +++ b/tests/integration/evidence/app_config.go @@ -1,6 +1,7 @@ package evidence_test import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -14,6 +15,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/integration/evidence/keeper/infraction_test.go b/tests/integration/evidence/keeper/infraction_test.go index 87d5a52c9fa4..d0b890abe627 100644 --- a/tests/integration/evidence/keeper/infraction_test.go +++ b/tests/integration/evidence/keeper/infraction_test.go @@ -9,6 +9,7 @@ import ( "time" abci "github.com/cometbft/cometbft/abci/types" + "github.com/golang/mock/gomock" "gotest.tools/v3/assert" "cosmossdk.io/collections" @@ -20,6 +21,7 @@ import ( "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" authsims "cosmossdk.io/x/auth/simulation" + authtestutil "cosmossdk.io/x/auth/testutil" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/bank" bankkeeper "cosmossdk.io/x/bank/keeper" @@ -98,6 +100,10 @@ func initFixture(tb testing.TB) *fixture { authority := authtypes.NewModuleAddress("gov") + // gomock initializations + ctrl := gomock.NewController(tb) + acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) + maccPerms := map[string][]string{ pooltypes.ModuleName: {}, minttypes.ModuleName: {authtypes.Minter}, @@ -113,6 +119,7 @@ func initFixture(tb testing.TB) *fixture { addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authority.String(), + acctsModKeeper, ) blockedAddresses := map[string]bool{ diff --git a/tests/integration/example/example_test.go b/tests/integration/example/example_test.go index e921c175021b..b995e00b18c4 100644 --- a/tests/integration/example/example_test.go +++ b/tests/integration/example/example_test.go @@ -50,6 +50,7 @@ func Example() { addresscodec.NewBech32Codec("cosmos"), "cosmos", authority, + nil, ) // subspace is nil because we don't test params (which is legacy anyway) @@ -141,6 +142,7 @@ func Example_oneModule() { addresscodec.NewBech32Codec("cosmos"), "cosmos", authority, + nil, ) // subspace is nil because we don't test params (which is legacy anyway) diff --git a/tests/integration/gov/common_test.go b/tests/integration/gov/common_test.go index d5243c15e66f..65a66cf52cf4 100644 --- a/tests/integration/gov/common_test.go +++ b/tests/integration/gov/common_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/depinject" sdklog "cosmossdk.io/log" "cosmossdk.io/math" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" authtypes "cosmossdk.io/x/auth/types" _ "cosmossdk.io/x/bank" @@ -105,6 +106,7 @@ func createTestSuite(t *testing.T) suite { app, err := simtestutil.SetupWithConfiguration( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.BankModule(), diff --git a/tests/integration/gov/genesis_test.go b/tests/integration/gov/genesis_test.go index 6cbe8e7be48c..8959cd3335bb 100644 --- a/tests/integration/gov/genesis_test.go +++ b/tests/integration/gov/genesis_test.go @@ -13,6 +13,7 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" sdkmath "cosmossdk.io/math" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" authtypes "cosmossdk.io/x/auth/types" @@ -46,6 +47,7 @@ type suite struct { } var appConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.BankModule(), diff --git a/tests/integration/gov/keeper/keeper_test.go b/tests/integration/gov/keeper/keeper_test.go index 1a7b2608163c..426e80037dde 100644 --- a/tests/integration/gov/keeper/keeper_test.go +++ b/tests/integration/gov/keeper/keeper_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "testing" + "github.com/golang/mock/gomock" "gotest.tools/v3/assert" "cosmossdk.io/core/appmodule" @@ -11,6 +12,7 @@ import ( "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" authsims "cosmossdk.io/x/auth/simulation" + authtestutil "cosmossdk.io/x/auth/testutil" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/bank" bankkeeper "cosmossdk.io/x/bank/keeper" @@ -72,6 +74,10 @@ func initFixture(tb testing.TB) *fixture { types.ModuleName: {authtypes.Burner}, } + // gomock initializations + ctrl := gomock.NewController(tb) + acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) + accountKeeper := authkeeper.NewAccountKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()), cdc, @@ -80,6 +86,7 @@ func initFixture(tb testing.TB) *fixture { addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authority.String(), + acctsModKeeper, ) blockedAddresses := map[string]bool{ diff --git a/tests/integration/gov/module_test.go b/tests/integration/gov/module_test.go index c482716aae96..c1d41a0b6cb5 100644 --- a/tests/integration/gov/module_test.go +++ b/tests/integration/gov/module_test.go @@ -7,6 +7,7 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" + _ "cosmossdk.io/x/accounts" authkeeper "cosmossdk.io/x/auth/keeper" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/gov/types" @@ -22,6 +23,7 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { app, err := simtestutil.SetupAtGenesis( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.BankModule(), diff --git a/tests/integration/mint/app_config.go b/tests/integration/mint/app_config.go index 1d080c94acbc..5a00b66295cd 100644 --- a/tests/integration/mint/app_config.go +++ b/tests/integration/mint/app_config.go @@ -1,6 +1,7 @@ package mint import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -13,6 +14,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/integration/runtime/query_test.go b/tests/integration/runtime/query_test.go index 4ad7a7553aed..de3e3e7457d4 100644 --- a/tests/integration/runtime/query_test.go +++ b/tests/integration/runtime/query_test.go @@ -14,6 +14,7 @@ import ( reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" "cosmossdk.io/depinject" "cosmossdk.io/log" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" _ "cosmossdk.io/x/auth/tx/config" _ "cosmossdk.io/x/bank" @@ -42,6 +43,7 @@ func initFixture(t assert.TestingT) *fixture { app, err := simtestutil.Setup( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.TxModule(), configurator.ConsensusModule(), diff --git a/tests/integration/slashing/app_config.go b/tests/integration/slashing/app_config.go index ee2e36f41cbe..7ee06d925aff 100644 --- a/tests/integration/slashing/app_config.go +++ b/tests/integration/slashing/app_config.go @@ -1,6 +1,7 @@ package slashing import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -16,6 +17,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index dc14c0284836..09fec08e575e 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" "gotest.tools/v3/assert" @@ -14,6 +15,7 @@ import ( storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" + authtestutil "cosmossdk.io/x/auth/testutil" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/bank" bankkeeper "cosmossdk.io/x/bank/keeper" @@ -73,6 +75,10 @@ func initFixture(tb testing.TB) *fixture { stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, } + // gomock initializations + ctrl := gomock.NewController(&testing.T{}) + acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) + accountKeeper := authkeeper.NewAccountKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()), cdc, @@ -81,6 +87,7 @@ func initFixture(tb testing.TB) *fixture { addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authority.String(), + acctsModKeeper, ) blockedAddresses := map[string]bool{ diff --git a/tests/integration/slashing/slashing_test.go b/tests/integration/slashing/slashing_test.go index 0ac41336231a..bec39e2449f8 100644 --- a/tests/integration/slashing/slashing_test.go +++ b/tests/integration/slashing/slashing_test.go @@ -62,6 +62,7 @@ func TestSlashingMsgs(t *testing.T) { app, err := sims.SetupWithConfiguration( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.SlashingModule(), diff --git a/tests/integration/staking/app_config.go b/tests/integration/staking/app_config.go index 89b85e88b2b0..86972f92e649 100644 --- a/tests/integration/staking/app_config.go +++ b/tests/integration/staking/app_config.go @@ -1,6 +1,7 @@ package staking import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -16,6 +17,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/integration/staking/keeper/common_test.go b/tests/integration/staking/keeper/common_test.go index f864019603c0..c67341031eb1 100644 --- a/tests/integration/staking/keeper/common_test.go +++ b/tests/integration/staking/keeper/common_test.go @@ -4,6 +4,7 @@ import ( "math/big" "testing" + "github.com/golang/mock/gomock" "gotest.tools/v3/assert" "cosmossdk.io/core/appmodule" @@ -13,6 +14,7 @@ import ( "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" authsims "cosmossdk.io/x/auth/simulation" + authtestutil "cosmossdk.io/x/auth/testutil" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/bank" bankkeeper "cosmossdk.io/x/bank/keeper" @@ -122,6 +124,10 @@ func initFixture(tb testing.TB) *fixture { types.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, } + // gomock initializations + ctrl := gomock.NewController(&testing.T{}) + acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) + accountKeeper := authkeeper.NewAccountKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()), cdc, @@ -130,6 +136,7 @@ func initFixture(tb testing.TB) *fixture { addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authority.String(), + acctsModKeeper, ) blockedAddresses := map[string]bool{ diff --git a/tests/integration/staking/keeper/deterministic_test.go b/tests/integration/staking/keeper/deterministic_test.go index cc8c2fbae654..3c90367d4025 100644 --- a/tests/integration/staking/keeper/deterministic_test.go +++ b/tests/integration/staking/keeper/deterministic_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/golang/mock/gomock" "gotest.tools/v3/assert" "pgregory.net/rapid" @@ -14,6 +15,7 @@ import ( "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" authsims "cosmossdk.io/x/auth/simulation" + authtestutil "cosmossdk.io/x/auth/testutil" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/bank" bankkeeper "cosmossdk.io/x/bank/keeper" @@ -86,6 +88,10 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, } + // gomock initializations + ctrl := gomock.NewController(t) + acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) + accountKeeper := authkeeper.NewAccountKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()), cdc, @@ -94,6 +100,7 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authority.String(), + acctsModKeeper, ) blockedAddresses := map[string]bool{ diff --git a/tests/integration/tx/context_test.go b/tests/integration/tx/context_test.go index 7246a2c798d1..ffe21c2053cb 100644 --- a/tests/integration/tx/context_test.go +++ b/tests/integration/tx/context_test.go @@ -8,6 +8,7 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" + _ "cosmossdk.io/x/accounts" "cosmossdk.io/x/tx/signing" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -33,6 +34,7 @@ func TestDefineCustomGetSigners(t *testing.T) { _, err := simtestutil.SetupAtGenesis( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.BankModule(), diff --git a/tests/sims/authz/operations_test.go b/tests/sims/authz/operations_test.go index 60e4ca724112..0a2ef3354859 100644 --- a/tests/sims/authz/operations_test.go +++ b/tests/sims/authz/operations_test.go @@ -11,7 +11,8 @@ import ( "cosmossdk.io/core/header" "cosmossdk.io/depinject" "cosmossdk.io/log" - _ "cosmossdk.io/x/auth" // import as blank for app wiring + _ "cosmossdk.io/x/accounts" // import as blank for app wiring + _ "cosmossdk.io/x/auth" // import as blank for app wiring authkeeper "cosmossdk.io/x/auth/keeper" _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring "cosmossdk.io/x/authz" @@ -39,6 +40,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/sims/bank/operations_test.go b/tests/sims/bank/operations_test.go index 5d4564af1f11..9ba074f4efee 100644 --- a/tests/sims/bank/operations_test.go +++ b/tests/sims/bank/operations_test.go @@ -9,6 +9,7 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" _ "cosmossdk.io/x/auth/tx/config" _ "cosmossdk.io/x/bank" @@ -47,6 +48,7 @@ func (suite *SimTestSuite) SetupTest() { suite.app, err = simtestutil.Setup( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/sims/distribution/app_config.go b/tests/sims/distribution/app_config.go index 02130ff2387b..efd27dcf1a9d 100644 --- a/tests/sims/distribution/app_config.go +++ b/tests/sims/distribution/app_config.go @@ -1,6 +1,7 @@ package distribution import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -15,6 +16,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/sims/feegrant/operations_test.go b/tests/sims/feegrant/operations_test.go index cf00c52389f8..21ef34e3aa57 100644 --- a/tests/sims/feegrant/operations_test.go +++ b/tests/sims/feegrant/operations_test.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/core/header" "cosmossdk.io/depinject" "cosmossdk.io/log" + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" _ "cosmossdk.io/x/auth/tx/config" @@ -56,6 +57,7 @@ func (suite *SimTestSuite) SetupTest() { suite.app, err = simtestutil.Setup( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/sims/gov/operations_test.go b/tests/sims/gov/operations_test.go index 239049e76bc9..2b81623fac61 100644 --- a/tests/sims/gov/operations_test.go +++ b/tests/sims/gov/operations_test.go @@ -13,6 +13,7 @@ import ( "cosmossdk.io/core/header" "cosmossdk.io/depinject" "cosmossdk.io/log" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" _ "cosmossdk.io/x/auth/tx/config" @@ -384,6 +385,7 @@ func createTestSuite(t *testing.T, isCheckTx bool) (suite, sdk.Context) { app, err := simtestutil.Setup( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.TxModule(), configurator.BankModule(), diff --git a/tests/sims/nft/app_config.go b/tests/sims/nft/app_config.go index 8ce4a69e09e4..156056fe4bdf 100644 --- a/tests/sims/nft/app_config.go +++ b/tests/sims/nft/app_config.go @@ -1,6 +1,7 @@ package nft import ( + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -14,6 +15,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/sims/protocolpool/app_config.go b/tests/sims/protocolpool/app_config.go index 7163523f09ea..b0c680cf9572 100644 --- a/tests/sims/protocolpool/app_config.go +++ b/tests/sims/protocolpool/app_config.go @@ -1,6 +1,7 @@ package protocolpool import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -15,6 +16,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/sims/slashing/app_config.go b/tests/sims/slashing/app_config.go index ee2e36f41cbe..7ee06d925aff 100644 --- a/tests/sims/slashing/app_config.go +++ b/tests/sims/slashing/app_config.go @@ -1,6 +1,7 @@ package slashing import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -16,6 +17,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/starship/tests/go.mod b/tests/starship/tests/go.mod index 2960e1cd17a0..11ecf6b1a7a7 100644 --- a/tests/starship/tests/go.mod +++ b/tests/starship/tests/go.mod @@ -238,7 +238,7 @@ require ( golang.org/x/mod v0.16.0 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/oauth2 v0.18.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/tests/starship/tests/go.sum b/tests/starship/tests/go.sum index e8db95ab02c5..37b721a6da81 100644 --- a/tests/starship/tests/go.sum +++ b/tests/starship/tests/go.sum @@ -1199,8 +1199,8 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/testutil/configurator/configurator.go b/testutil/configurator/configurator.go index 44f0ba461369..f1476221d2c3 100644 --- a/testutil/configurator/configurator.go +++ b/testutil/configurator/configurator.go @@ -1,6 +1,7 @@ package configurator import ( + accountsmodulev1 "cosmossdk.io/api/cosmos/accounts/module/v1" runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" @@ -89,6 +90,7 @@ func defaultConfig() *Config { testutil.ProtocolPoolModuleName, }, InitGenesisOrder: []string{ + testutil.AccountsModuleName, testutil.AuthModuleName, testutil.BankModuleName, testutil.DistributionModuleName, @@ -330,6 +332,15 @@ func ProtocolPoolModule() ModuleOption { } } +func AccountsModule() ModuleOption { + return func(config *Config) { + config.ModuleConfigs[testutil.AccountsModuleName] = &appv1alpha1.ModuleConfig{ + Name: testutil.AccountsModuleName, + Config: appconfig.WrapAny(&accountsmodulev1.Module{}), + } + } +} + func CounterModule() ModuleOption { return func(config *Config) { config.ModuleConfigs["counter"] = &appv1alpha1.ModuleConfig{ diff --git a/testutil/network/network.go b/testutil/network/network.go index 8dca40ae5473..42e288b614a5 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -25,6 +25,7 @@ import ( sdkmath "cosmossdk.io/math" "cosmossdk.io/math/unsafe" pruningtypes "cosmossdk.io/store/pruning/types" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" // import auth as a blank _ "cosmossdk.io/x/auth/tx/config" // import auth tx config as a blank authtypes "cosmossdk.io/x/auth/types" @@ -168,6 +169,7 @@ func DefaultConfig(factory TestFixtureFactory) Config { // MinimumAppConfig defines the minimum of modules required for a call to New to succeed func MinimumAppConfig() depinject.Config { return configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.GenutilModule(), diff --git a/tools/confix/data/v0.50-app.toml b/tools/confix/data/v0.50-app.toml index 9c801a2d74ae..058f43ec4be1 100644 --- a/tools/confix/data/v0.50-app.toml +++ b/tools/confix/data/v0.50-app.toml @@ -227,9 +227,9 @@ stop-node-on-err = true [mempool] # Setting max-txs to 0 will allow for a unbounded amount of transactions in the mempool. -# Setting max_txs to negative 1 (-1) will disable transactions from being inserted into the mempool. +# Setting max_txs to negative 1 (-1) will disable transactions from being inserted into the mempool (no-op mempool). # Setting max_txs to a positive number (> 0) will limit the number of transactions in the mempool, by the specified amount. # # Note, this configuration only applies to SDK built-in app-side mempool # implementations. -max-txs = 5000 +max-txs = -1 diff --git a/tools/confix/data/v0.51-app.toml b/tools/confix/data/v0.51-app.toml index f725f5bbc5bb..1809e606dba6 100644 --- a/tools/confix/data/v0.51-app.toml +++ b/tools/confix/data/v0.51-app.toml @@ -233,7 +233,7 @@ stop-node-on-err = true # # Note, this configuration only applies to SDK built-in app-side mempool # implementations. -max-txs = 5000 +max-txs = -1 [custom] diff --git a/tools/confix/go.mod b/tools/confix/go.mod index 29fce0069c82..bd80418bd33e 100644 --- a/tools/confix/go.mod +++ b/tools/confix/go.mod @@ -140,7 +140,7 @@ require ( go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.22.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/tools/confix/go.sum b/tools/confix/go.sum index 891993508b51..b1dd2c57e532 100644 --- a/tools/confix/go.sum +++ b/tools/confix/go.sum @@ -825,8 +825,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/tools/cosmovisor/go.mod b/tools/cosmovisor/go.mod index 97de9d4b1a84..9eed1285d429 100644 --- a/tools/cosmovisor/go.mod +++ b/tools/cosmovisor/go.mod @@ -163,7 +163,7 @@ require ( golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/oauth2 v0.18.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/tools/cosmovisor/go.sum b/tools/cosmovisor/go.sum index b0c8f053076c..52e782e83794 100644 --- a/tools/cosmovisor/go.sum +++ b/tools/cosmovisor/go.sum @@ -1194,8 +1194,8 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/tools/hubl/go.mod b/tools/hubl/go.mod index 51fab15bfa33..2468db63ca24 100644 --- a/tools/hubl/go.mod +++ b/tools/hubl/go.mod @@ -141,7 +141,7 @@ require ( golang.org/x/crypto v0.22.0 // indirect golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/tools/hubl/go.sum b/tools/hubl/go.sum index eb7677a9ecef..0887b02add5a 100644 --- a/tools/hubl/go.sum +++ b/tools/hubl/go.sum @@ -822,8 +822,8 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/types/context.go b/types/context.go index 2c63445f8709..0ebee5f132c5 100644 --- a/types/context.go +++ b/types/context.go @@ -6,7 +6,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - "github.com/cosmos/gogoproto/proto" "cosmossdk.io/core/comet" "cosmossdk.io/core/header" @@ -78,10 +77,10 @@ func (c Context) Logger() log.Logger { return c.logge func (c Context) VoteInfos() []abci.VoteInfo { return c.voteInfo } func (c Context) GasMeter() storetypes.GasMeter { return c.gasMeter } func (c Context) BlockGasMeter() storetypes.GasMeter { return c.blockGasMeter } -func (c Context) IsCheckTx() bool { return c.checkTx } // Deprecated: use execMode instead -func (c Context) IsReCheckTx() bool { return c.recheckTx } // Deprecated: use execMode instead +func (c Context) IsCheckTx() bool { return c.checkTx } // Deprecated: use core/transaction service instead +func (c Context) IsReCheckTx() bool { return c.recheckTx } // Deprecated: use core/transaction service instead func (c Context) IsSigverifyTx() bool { return c.sigverifyTx } -func (c Context) ExecMode() ExecMode { return c.execMode } +func (c Context) ExecMode() ExecMode { return c.execMode } // Deprecated: use core/transaction service instead func (c Context) MinGasPrices() DecCoins { return c.minGasPrice } func (c Context) EventManager() EventManagerI { return c.eventManager } func (c Context) Priority() int64 { return c.priority } @@ -91,10 +90,9 @@ func (c Context) StreamingManager() storetypes.StreamingManager { return c.strea func (c Context) CometInfo() comet.Info { return c.cometInfo } func (c Context) HeaderInfo() header.Info { return c.headerInfo } -// clone the header before returning +// BlockHeader returns the header by value. func (c Context) BlockHeader() cmtproto.Header { - msg := proto.Clone(&c.header).(*cmtproto.Header) - return *msg + return c.header } // HeaderHash returns a copy of the header hash obtained during abci.RequestBeginBlock diff --git a/types/kv/helpers_test.go b/types/kv/helpers_test.go new file mode 100644 index 000000000000..37e9f368532b --- /dev/null +++ b/types/kv/helpers_test.go @@ -0,0 +1,89 @@ +package kv_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/cosmos/cosmos-sdk/types/kv" +) + +func TestAssertKeyAtLeastLength(t *testing.T) { + cases := []struct { + name string + key []byte + length int + expectPanic bool + }{ + { + name: "Store key length is less than the given length", + key: []byte("hello"), + length: 10, + expectPanic: true, + }, + { + name: "Store key length is equal to the given length", + key: []byte("store-key"), + length: 9, + expectPanic: false, + }, + { + name: "Store key length is greater than the given length", + key: []byte("unique"), + length: 3, + expectPanic: false, + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + if tc.expectPanic { + assert.Panics(t, func() { + kv.AssertKeyAtLeastLength(tc.key, tc.length) + }) + return + } + kv.AssertKeyAtLeastLength(tc.key, tc.length) + }) + } +} + +func TestAssertKeyLength(t *testing.T) { + cases := []struct { + name string + key []byte + length int + expectPanic bool + }{ + { + name: "Store key length is less than the given length", + key: []byte("hello"), + length: 10, + expectPanic: true, + }, + { + name: "Store key length is equal to the given length", + key: []byte("store-key"), + length: 9, + expectPanic: false, + }, + { + name: "Store key length is greater than the given length", + key: []byte("unique"), + length: 3, + expectPanic: true, + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + if tc.expectPanic { + assert.Panics(t, func() { + kv.AssertKeyLength(tc.key, tc.length) + }) + return + } + kv.AssertKeyLength(tc.key, tc.length) + }) + } +} diff --git a/types/mempool/mempool_test.go b/types/mempool/mempool_test.go index 3dbd5f1349b0..cdc0756141a6 100644 --- a/types/mempool/mempool_test.go +++ b/types/mempool/mempool_test.go @@ -211,7 +211,7 @@ type MempoolTestSuite struct { func (s *MempoolTestSuite) resetMempool() { s.iterations = 0 - s.mempool = mempool.NewSenderNonceMempool() + s.mempool = mempool.NewSenderNonceMempool(mempool.SenderNonceMaxTxOpt(5000)) } func (s *MempoolTestSuite) SetupTest() { diff --git a/types/mempool/sender_nonce.go b/types/mempool/sender_nonce.go index 524d20a73c74..9e2b25e4e47d 100644 --- a/types/mempool/sender_nonce.go +++ b/types/mempool/sender_nonce.go @@ -20,7 +20,7 @@ var ( _ Iterator = (*senderNonceMempoolIterator)(nil) ) -var DefaultMaxTx = 0 +var DefaultMaxTx = -1 // SenderNonceMempool is a mempool that prioritizes transactions within a sender // by nonce, the lowest first, but selects a random sender on each iteration. diff --git a/types/mempool/sender_nonce_test.go b/types/mempool/sender_nonce_test.go index e458c0bc4233..d4e4fe565ee3 100644 --- a/types/mempool/sender_nonce_test.go +++ b/types/mempool/sender_nonce_test.go @@ -114,7 +114,7 @@ func (s *MempoolTestSuite) TestTxOrder() { } for i, tt := range tests { t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) { - pool := mempool.NewSenderNonceMempool(mempool.SenderNonceSeedOpt(tt.seed)) + pool := mempool.NewSenderNonceMempool(mempool.SenderNonceMaxTxOpt(5000), mempool.SenderNonceSeedOpt(tt.seed)) // create test txs and insert into mempool for i, ts := range tt.txs { tx := testTx{id: i, priority: int64(ts.p), nonce: uint64(ts.n), address: ts.a} @@ -172,7 +172,7 @@ func (s *MempoolTestSuite) TestTxNotFoundOnSender() { t := s.T() ctx := sdk.NewContext(nil, false, log.NewNopLogger()) accounts := simtypes.RandomAccounts(rand.New(rand.NewSource(0)), 1) - mp := mempool.NewSenderNonceMempool() + mp := mempool.NewSenderNonceMempool(mempool.SenderNonceMaxTxOpt(5000)) txSender := testTx{ nonce: 0, diff --git a/types/query/pagination_test.go b/types/query/pagination_test.go index 7893ef78d354..a35257ccabfa 100644 --- a/types/query/pagination_test.go +++ b/types/query/pagination_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/log" "cosmossdk.io/math" "cosmossdk.io/store/prefix" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" _ "cosmossdk.io/x/bank" @@ -68,6 +69,7 @@ func (s *paginationTestSuite) SetupTest() { app, err := testutilsims.Setup( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.ConsensusModule(), diff --git a/x/accounts/defaults/lockup/go.mod b/x/accounts/defaults/lockup/go.mod index 51e24059d646..ca699d48ebdf 100644 --- a/x/accounts/defaults/lockup/go.mod +++ b/x/accounts/defaults/lockup/go.mod @@ -141,7 +141,7 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/accounts/defaults/lockup/go.sum b/x/accounts/defaults/lockup/go.sum index a290da41372a..13ac00c9387e 100644 --- a/x/accounts/defaults/lockup/go.sum +++ b/x/accounts/defaults/lockup/go.sum @@ -761,8 +761,8 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/accounts/depinject.go b/x/accounts/depinject.go index bef3dd4208cf..8714d98ba1d9 100644 --- a/x/accounts/depinject.go +++ b/x/accounts/depinject.go @@ -1,8 +1,73 @@ package accounts -import "cosmossdk.io/depinject" +import ( + "context" + + modulev1 "cosmossdk.io/api/cosmos/accounts/module/v1" + signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/core/address" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/depinject" + "cosmossdk.io/depinject/appconfig" + baseaccount "cosmossdk.io/x/accounts/defaults/base" + "cosmossdk.io/x/tx/signing" + + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" +) var _ depinject.OnePerModuleType = AppModule{} // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} + +func init() { + appconfig.RegisterModule( + &modulev1.Module{}, + appconfig.Provide(ProvideModule), + ) +} + +type ModuleInputs struct { + depinject.In + + Cdc codec.Codec + Environment appmodule.Environment + AddressCodec address.Codec + ExecRouter MsgRouter + QueryRouter QueryRouter + Registry cdctypes.InterfaceRegistry +} + +type ModuleOutputs struct { + depinject.Out + + AccountsKeeper Keeper + Module appmodule.AppModule +} + +var _ signing.SignModeHandler = directHandler{} + +type directHandler struct{} + +func (s directHandler) Mode() signingv1beta1.SignMode { + return signingv1beta1.SignMode_SIGN_MODE_DIRECT +} + +func (s directHandler) GetSignBytes(_ context.Context, _ signing.SignerData, _ signing.TxData) ([]byte, error) { + panic("not implemented") +} + +func ProvideModule(in ModuleInputs) ModuleOutputs { + handler := directHandler{} + account := baseaccount.NewAccount("base", signing.NewHandlerMap(handler)) + accountskeeper, err := NewKeeper( + in.Cdc, in.Environment, in.AddressCodec, in.Cdc, + in.ExecRouter, in.QueryRouter, in.Registry, account, + ) + if err != nil { + panic(err) + } + m := NewAppModule(in.Cdc, accountskeeper) + return ModuleOutputs{AccountsKeeper: accountskeeper, Module: m} +} diff --git a/x/accounts/go.mod b/x/accounts/go.mod index df1de0b48509..68d121255350 100644 --- a/x/accounts/go.mod +++ b/x/accounts/go.mod @@ -147,7 +147,7 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/accounts/go.sum b/x/accounts/go.sum index 3f5011df944b..939199ac2c28 100644 --- a/x/accounts/go.sum +++ b/x/accounts/go.sum @@ -809,8 +809,8 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/accounts/keeper.go b/x/accounts/keeper.go index 6a4779499819..667f6c19a742 100644 --- a/x/accounts/keeper.go +++ b/x/accounts/keeper.go @@ -126,6 +126,15 @@ type Keeper struct { AccountsState collections.Map[collections.Pair[uint64, []byte], []byte] } +// IsAccountsModuleAccount check if an address belong to a smart account. +func (k Keeper) IsAccountsModuleAccount( + ctx context.Context, + accountAddr []byte, +) bool { + hasAcc, _ := k.AccountByNumber.Has(ctx, accountAddr) + return hasAcc +} + // Init creates a new account of the given type. func (k Keeper) Init( ctx context.Context, diff --git a/x/auth/CHANGELOG.md b/x/auth/CHANGELOG.md index 585075a9d39e..1e8fa2a5bdf4 100644 --- a/x/auth/CHANGELOG.md +++ b/x/auth/CHANGELOG.md @@ -33,6 +33,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* [#19967](https://github.com/cosmos/cosmos-sdk/pull/19967) Refactor ante handlers to use `transaction.Service` for getting exec mode. * [#18780](https://github.com/cosmos/cosmos-sdk/pull/18780) Move sig verification out of the for loop, into the authenticate method. * [#19188](https://github.com/cosmos/cosmos-sdk/pull/19188) Remove creation of `BaseAccount` when sending a message to an account that does not exist. * When signing a transaction with an account that has not been created accountnumber 0 must be used diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index 657489a0c545..c3e68b92af59 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -42,7 +42,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { anteDecorators := []sdk.AnteDecorator{ NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first NewExtensionOptionsDecorator(options.ExtensionOptionChecker), - NewValidateBasicDecorator(), + NewValidateBasicDecorator(options.AccountKeeper.Environment()), NewTxTimeoutHeightDecorator(), NewValidateMemoDecorator(options.AccountKeeper), NewConsumeGasForTxSizeDecorator(options.AccountKeeper), diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 59e9eca61ee1..37994cad1ec7 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -1,6 +1,8 @@ package ante import ( + "cosmossdk.io/core/appmodule/v2" + "cosmossdk.io/core/transaction" errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/auth/migrations/legacytx" @@ -18,15 +20,20 @@ import ( // If ValidateBasic passes, decorator calls next AnteHandler in chain. Note, // ValidateBasicDecorator decorator will not get executed on ReCheckTx since it // is not dependent on application state. -type ValidateBasicDecorator struct{} +type ValidateBasicDecorator struct { + env appmodule.Environment +} -func NewValidateBasicDecorator() ValidateBasicDecorator { - return ValidateBasicDecorator{} +func NewValidateBasicDecorator(env appmodule.Environment) ValidateBasicDecorator { + return ValidateBasicDecorator{ + env: env, + } } func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, next sdk.AnteHandler) (sdk.Context, error) { // no need to validate basic on recheck tx, call next antehandler - if ctx.ExecMode() == sdk.ExecModeReCheck { + txService := vbd.env.TransactionService + if txService.ExecMode(ctx) == transaction.ExecModeReCheck { return next(ctx, tx, false) } @@ -36,7 +43,7 @@ func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, } } - return next(ctx, tx, ctx.ExecMode() == sdk.ExecModeSimulate) + return next(ctx, tx, false) } // ValidateMemoDecorator will validate memo given the parameters passed in @@ -69,7 +76,7 @@ func (vmd ValidateMemoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, } } - return next(ctx, tx, ctx.ExecMode() == sdk.ExecModeSimulate) + return next(ctx, tx, false) } // ConsumeTxSizeGasDecorator will take in parameters and consume gas proportional @@ -101,7 +108,8 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ b ctx.GasMeter().ConsumeGas(params.TxSizeCostPerByte*storetypes.Gas(len(ctx.TxBytes())), "txSize") // simulate gas cost for signatures in simulate mode - if ctx.ExecMode() == sdk.ExecModeSimulate { + txService := cgts.ak.Environment().TransactionService + if txService.ExecMode(ctx) == transaction.ExecModeSimulate { // in simulate mode, each element should be a nil signature sigs, err := sigTx.GetSignaturesV2() if err != nil { @@ -143,7 +151,7 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ b } } - return next(ctx, tx, ctx.ExecMode() == sdk.ExecModeSimulate) + return next(ctx, tx, false) } // isIncompleteSignature tests whether SignatureData is fully filled in for simulation purposes @@ -206,5 +214,5 @@ func (txh TxTimeoutHeightDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ boo ) } - return next(ctx, tx, ctx.ExecMode() == sdk.ExecModeSimulate) + return next(ctx, tx, false) } diff --git a/x/auth/ante/basic_test.go b/x/auth/ante/basic_test.go index 21d69d866b44..7546d59e7d62 100644 --- a/x/auth/ante/basic_test.go +++ b/x/auth/ante/basic_test.go @@ -36,7 +36,7 @@ func TestValidateBasic(t *testing.T) { invalidTx, err := suite.CreateTestTx(suite.ctx, privs, accNums, accSeqs, suite.ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) - vbd := ante.NewValidateBasicDecorator() + vbd := ante.NewValidateBasicDecorator(suite.accountKeeper.Environment()) antehandler := sdk.ChainAnteDecorators(vbd) _, err = antehandler(suite.ctx, invalidTx, false) diff --git a/x/auth/ante/expected_keepers.go b/x/auth/ante/expected_keepers.go index c33dcaa685d3..52bf0acc31f3 100644 --- a/x/auth/ante/expected_keepers.go +++ b/x/auth/ante/expected_keepers.go @@ -4,11 +4,16 @@ import ( "context" "cosmossdk.io/core/address" + "cosmossdk.io/core/appmodule" "cosmossdk.io/x/auth/types" sdk "github.com/cosmos/cosmos-sdk/types" ) +type HasEnvironment interface { + Environment() appmodule.Environment +} + // AccountKeeper defines the contract needed for AccountKeeper related APIs. // Interface provides support to use non-sdk AccountKeeper for AnteHandler's decorators. type AccountKeeper interface { @@ -16,8 +21,9 @@ type AccountKeeper interface { GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI SetAccount(ctx context.Context, acc sdk.AccountI) GetModuleAddress(moduleName string) sdk.AccAddress - AddressCodec() address.Codec NewAccountWithAddress(ctx context.Context, addr sdk.AccAddress) sdk.AccountI + AddressCodec() address.Codec + Environment() appmodule.Environment } // FeegrantKeeper defines the expected feegrant keeper. diff --git a/x/auth/ante/export_test.go b/x/auth/ante/export_test.go new file mode 100644 index 000000000000..ad990a30d210 --- /dev/null +++ b/x/auth/ante/export_test.go @@ -0,0 +1,12 @@ +package ante + +import ( + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var SimSecp256k1PubkeyInternal = simSecp256k1Pubkey + +func SetSVDPubKey(svd SigVerificationDecorator, ctx sdk.Context, acc sdk.AccountI, txPubKey cryptotypes.PubKey) error { + return svd.setPubKey(ctx, acc, txPubKey) +} diff --git a/x/auth/ante/ext.go b/x/auth/ante/ext.go index 92fefff3afff..b87a2b8b4f74 100644 --- a/x/auth/ante/ext.go +++ b/x/auth/ante/ext.go @@ -49,7 +49,7 @@ func (r RejectExtensionOptionsDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, return ctx, err } - return next(ctx, tx, ctx.ExecMode() == sdk.ExecModeSimulate) + return next(ctx, tx, false) } func checkExtOpts(tx sdk.Tx, checker ExtensionOptionChecker) error { diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index 018b447c97e3..cf3e54a5b272 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" + "cosmossdk.io/core/transaction" errorsmod "cosmossdk.io/errors" "cosmossdk.io/x/auth/types" @@ -45,7 +46,9 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, nex return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") } - if ctx.ExecMode() != sdk.ExecModeSimulate && ctx.BlockHeight() > 0 && feeTx.GetGas() == 0 { + txService := dfd.accountKeeper.Environment().TransactionService + execMode := txService.ExecMode(ctx) + if execMode != transaction.ExecModeSimulate && ctx.BlockHeight() > 0 && feeTx.GetGas() == 0 { return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidGasLimit, "must provide positive gas") } @@ -55,7 +58,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, nex ) fee := feeTx.GetFee() - if ctx.ExecMode() != sdk.ExecModeSimulate { + if execMode != transaction.ExecModeSimulate { fee, priority, err = dfd.txFeeChecker(ctx, tx) if err != nil { return ctx, err @@ -67,7 +70,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, nex newCtx := ctx.WithPriority(priority) - return next(newCtx, tx, ctx.ExecMode() == sdk.ExecModeSimulate) + return next(newCtx, tx, false) } func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee sdk.Coins) error { diff --git a/x/auth/ante/setup.go b/x/auth/ante/setup.go index 6ab8fcd4c1d2..66e69fb7b8bf 100644 --- a/x/auth/ante/setup.go +++ b/x/auth/ante/setup.go @@ -67,14 +67,14 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, } }() - return next(newCtx, tx, ctx.ExecMode() == sdk.ExecModeSimulate) + return next(newCtx, tx, false) } // SetGasMeter returns a new context with a gas meter set from a given context. func SetGasMeter(ctx sdk.Context, gasLimit uint64) sdk.Context { // In various cases such as simulation and during the genesis block, we do not // meter any gas utilization. - if ctx.ExecMode() == sdk.ExecModeSimulate || ctx.BlockHeight() == 0 { + if ctx.ExecMode() == sdk.ExecModeSimulate || ctx.BlockHeight() == 0 { // NOTE: using environment here breaks the API of SetGasMeter, an alternative must be found for server/v2. ref: https://github.com/cosmos/cosmos-sdk/issues/19640 return ctx.WithGasMeter(storetypes.NewInfiniteGasMeter()) } diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index facc160fcee3..9db1433c0d02 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -10,6 +10,7 @@ import ( secp256k1dcrd "github.com/decred/dcrd/dcrec/secp256k1/v4" "google.golang.org/protobuf/types/known/anypb" + "cosmossdk.io/core/transaction" errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" aa_interface_v1 "cosmossdk.io/x/accounts/interfaces/account_abstraction/v1" @@ -215,7 +216,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ boo ctx.EventManager().EmitEvents(events) - return next(ctx, tx, ctx.ExecMode() == sdk.ExecModeSimulate) + return next(ctx, tx, false) } // authenticate the authentication of the TX for a specific tx signer. @@ -280,7 +281,7 @@ func (svd SigVerificationDecorator) consumeSignatureGas( pubKey cryptotypes.PubKey, signature signing.SignatureV2, ) error { - if ctx.ExecMode() == sdk.ExecModeSimulate && pubKey == nil { + if svd.ak.Environment().TransactionService.ExecMode(ctx) == transaction.ExecModeSimulate && pubKey == nil { pubKey = simSecp256k1Pubkey } @@ -310,7 +311,7 @@ func (svd SigVerificationDecorator) verifySig(ctx sdk.Context, tx sdk.Tx, acc sd // we're in simulation mode, or in ReCheckTx, or context is not // on sig verify tx, then we do not need to verify the signatures // in the tx. - if ctx.ExecMode() == sdk.ExecModeSimulate || ctx.IsReCheckTx() || !ctx.IsSigverifyTx() { + if svd.ak.Environment().TransactionService.ExecMode(ctx) == transaction.ExecModeSimulate || ctx.IsReCheckTx() || !ctx.IsSigverifyTx() { return nil } @@ -384,7 +385,7 @@ func (svd SigVerificationDecorator) setPubKey(ctx sdk.Context, acc sdk.AccountI, if txPubKey == nil { // if we're not in simulation mode, and we do not have a valid pubkey // for this signer, then we simply error. - if ctx.ExecMode() != sdk.ExecModeSimulate { + if svd.ak.Environment().TransactionService.ExecMode(ctx) != transaction.ExecModeSimulate { return fmt.Errorf("the account %s is without a pubkey and did not provide a pubkey in the tx to set it", acc.GetAddress().String()) } // if we're in simulation mode, then we can populate the pubkey with the @@ -479,7 +480,7 @@ func (vscd ValidateSigCountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ b } } - return next(ctx, tx, ctx.ExecMode() == sdk.ExecModeSimulate) + return next(ctx, tx, false) } // DefaultSigVerificationGasConsumer is the default implementation of SignatureVerificationGasConsumer. It consumes gas diff --git a/x/auth/ante/sigverify_internal_test.go b/x/auth/ante/sigverify_internal_test.go index 3408b82f2634..47be009d798a 100644 --- a/x/auth/ante/sigverify_internal_test.go +++ b/x/auth/ante/sigverify_internal_test.go @@ -1,10 +1,14 @@ -package ante +package ante_test import ( + "context" "testing" "github.com/stretchr/testify/require" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/transaction" + "cosmossdk.io/x/auth/ante" authcodec "cosmossdk.io/x/auth/codec" authtypes "cosmossdk.io/x/auth/types" @@ -12,8 +16,26 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) +type mockAccount struct { + ante.AccountKeeper +} + +func (*mockAccount) Environment() appmodule.Environment { + return appmodule.Environment{ + TransactionService: &mockTransactionService{}, + } +} + +type mockTransactionService struct { + transaction.Service +} + +func (*mockTransactionService) ExecMode(ctx context.Context) transaction.ExecMode { + return transaction.ExecMode(sdk.UnwrapSDKContext(ctx).ExecMode()) +} + func TestSigVerify_setPubKey(t *testing.T) { - svd := SigVerificationDecorator{} + svd := ante.NewSigVerificationDecorator(&mockAccount{}, nil, nil, nil) alicePk := secp256k1.GenPrivKey().PubKey() bobPk := secp256k1.GenPrivKey().PubKey() @@ -28,22 +50,22 @@ func TestSigVerify_setPubKey(t *testing.T) { t.Run("on not sig verify tx - skip", func(t *testing.T) { acc := &authtypes.BaseAccount{} ctx = ctx.WithExecMode(sdk.ExecModeSimulate).WithIsSigverifyTx(false) - err := svd.setPubKey(ctx, acc, nil) + err := ante.SetSVDPubKey(svd, ctx, acc, nil) require.NoError(t, err) }) t.Run("on sim, populate with sim key, if pubkey is nil", func(t *testing.T) { acc := &authtypes.BaseAccount{Address: aliceAddr} ctx = ctx.WithExecMode(sdk.ExecModeSimulate).WithIsSigverifyTx(true) - err := svd.setPubKey(ctx, acc, nil) + err := ante.SetSVDPubKey(svd, ctx, acc, nil) require.NoError(t, err) - require.Equal(t, acc.PubKey.GetCachedValue(), simSecp256k1Pubkey) + require.Equal(t, acc.PubKey.GetCachedValue(), ante.SimSecp256k1PubkeyInternal) }) t.Run("on sim, populate with real pub key, if pubkey is not nil", func(t *testing.T) { acc := &authtypes.BaseAccount{Address: aliceAddr} ctx = ctx.WithExecMode(sdk.ExecModeSimulate).WithIsSigverifyTx(true) - err := svd.setPubKey(ctx, acc, alicePk) + err := ante.SetSVDPubKey(svd, ctx, acc, alicePk) require.NoError(t, err) require.Equal(t, acc.PubKey.GetCachedValue(), alicePk) }) @@ -51,7 +73,7 @@ func TestSigVerify_setPubKey(t *testing.T) { t.Run("not on sim, populate the address", func(t *testing.T) { acc := &authtypes.BaseAccount{Address: aliceAddr} ctx = ctx.WithExecMode(sdk.ExecModeFinalize).WithIsSigverifyTx(true) - err := svd.setPubKey(ctx, acc, alicePk) + err := ante.SetSVDPubKey(svd, ctx, acc, alicePk) require.NoError(t, err) require.Equal(t, acc.PubKey.GetCachedValue(), alicePk) }) @@ -59,7 +81,7 @@ func TestSigVerify_setPubKey(t *testing.T) { t.Run("not on sim, fail on invalid pubkey.address", func(t *testing.T) { acc := &authtypes.BaseAccount{Address: aliceAddr} ctx = ctx.WithExecMode(sdk.ExecModeFinalize).WithIsSigverifyTx(true) - err := svd.setPubKey(ctx, acc, bobPk) + err := ante.SetSVDPubKey(svd, ctx, acc, bobPk) require.ErrorContains(t, err, "cannot be claimed") }) } diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index 1814e94f2b29..85ff7257dbcb 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -81,7 +81,7 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite { suite.accountKeeper = keeper.NewAccountKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()), suite.encCfg.Codec, types.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec("cosmos"), - sdk.Bech32MainPrefix, types.NewModuleAddress("gov").String(), + sdk.Bech32MainPrefix, types.NewModuleAddress("gov").String(), nil, ) suite.accountKeeper.GetModuleAccount(suite.ctx, types.FeeCollectorName) err := suite.accountKeeper.Params.Set(suite.ctx, types.DefaultParams()) diff --git a/x/auth/ante/unordered.go b/x/auth/ante/unordered.go index 0394701ddf59..193f5545125a 100644 --- a/x/auth/ante/unordered.go +++ b/x/auth/ante/unordered.go @@ -3,6 +3,8 @@ package ante import ( "crypto/sha256" + "cosmossdk.io/core/appmodule/v2" + "cosmossdk.io/core/transaction" errorsmod "cosmossdk.io/errors" "cosmossdk.io/x/auth/ante/unorderedtx" @@ -28,12 +30,14 @@ type UnorderedTxDecorator struct { // maxUnOrderedTTL defines the maximum TTL a transaction can define. maxUnOrderedTTL uint64 txManager *unorderedtx.Manager + env appmodule.Environment } -func NewUnorderedTxDecorator(maxTTL uint64, m *unorderedtx.Manager) *UnorderedTxDecorator { +func NewUnorderedTxDecorator(maxTTL uint64, m *unorderedtx.Manager, env appmodule.Environment) *UnorderedTxDecorator { return &UnorderedTxDecorator{ maxUnOrderedTTL: maxTTL, txManager: m, + env: env, } } @@ -42,7 +46,7 @@ func (d *UnorderedTxDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, ne if !ok || !unorderedTx.GetUnordered() { // If the transaction does not implement unordered capabilities or has the // unordered value as false, we bypass. - return next(ctx, tx, ctx.ExecMode() == sdk.ExecModeSimulate) + return next(ctx, tx, false) } // TTL is defined as a specific block height at which this tx is no longer valid @@ -65,10 +69,10 @@ func (d *UnorderedTxDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, ne return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "tx %X is duplicated") } - if ctx.ExecMode() == sdk.ExecModeFinalize { + if d.env.TransactionService.ExecMode(ctx) == transaction.ExecModeFinalize { // a new tx included in the block, add the hash to the unordered tx manager d.txManager.Add(txHash, ttl) } - return next(ctx, tx, ctx.ExecMode() == sdk.ExecModeSimulate) + return next(ctx, tx, false) } diff --git a/x/auth/ante/unordered_test.go b/x/auth/ante/unordered_test.go index 61653ee75a46..5e4ec4a5ead3 100644 --- a/x/auth/ante/unordered_test.go +++ b/x/auth/ante/unordered_test.go @@ -23,7 +23,9 @@ func TestUnorderedTxDecorator_OrderedTx(t *testing.T) { txm.Start() - chain := sdk.ChainAnteDecorators(ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, txm)) + suite := SetupTestSuite(t, false) + + chain := sdk.ChainAnteDecorators(ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, txm, suite.accountKeeper.Environment())) tx, txBz := genUnorderedTx(t, false, 0) ctx := sdk.Context{}.WithTxBytes(txBz).WithBlockHeight(100) @@ -40,7 +42,9 @@ func TestUnorderedTxDecorator_UnorderedTx_NoTTL(t *testing.T) { txm.Start() - chain := sdk.ChainAnteDecorators(ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, txm)) + suite := SetupTestSuite(t, false) + + chain := sdk.ChainAnteDecorators(ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, txm, suite.accountKeeper.Environment())) tx, txBz := genUnorderedTx(t, true, 0) ctx := sdk.Context{}.WithTxBytes(txBz).WithBlockHeight(100) @@ -57,7 +61,9 @@ func TestUnorderedTxDecorator_UnorderedTx_InvalidTTL(t *testing.T) { txm.Start() - chain := sdk.ChainAnteDecorators(ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, txm)) + suite := SetupTestSuite(t, false) + + chain := sdk.ChainAnteDecorators(ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, txm, suite.accountKeeper.Environment())) tx, txBz := genUnorderedTx(t, true, 100+unorderedtx.DefaultMaxUnOrderedTTL+1) ctx := sdk.Context{}.WithTxBytes(txBz).WithBlockHeight(100) @@ -74,7 +80,9 @@ func TestUnorderedTxDecorator_UnorderedTx_AlreadyExists(t *testing.T) { txm.Start() - chain := sdk.ChainAnteDecorators(ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, txm)) + suite := SetupTestSuite(t, false) + + chain := sdk.ChainAnteDecorators(ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, txm, suite.accountKeeper.Environment())) tx, txBz := genUnorderedTx(t, true, 150) ctx := sdk.Context{}.WithTxBytes(txBz).WithBlockHeight(100) @@ -94,7 +102,9 @@ func TestUnorderedTxDecorator_UnorderedTx_ValidCheckTx(t *testing.T) { txm.Start() - chain := sdk.ChainAnteDecorators(ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, txm)) + suite := SetupTestSuite(t, false) + + chain := sdk.ChainAnteDecorators(ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, txm, suite.accountKeeper.Environment())) tx, txBz := genUnorderedTx(t, true, 150) ctx := sdk.Context{}.WithTxBytes(txBz).WithBlockHeight(100).WithExecMode(sdk.ExecModeCheck) @@ -111,7 +121,9 @@ func TestUnorderedTxDecorator_UnorderedTx_ValidDeliverTx(t *testing.T) { txm.Start() - chain := sdk.ChainAnteDecorators(ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, txm)) + suite := SetupTestSuite(t, false) + + chain := sdk.ChainAnteDecorators(ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, txm, suite.accountKeeper.Environment())) tx, txBz := genUnorderedTx(t, true, 150) ctx := sdk.Context{}.WithTxBytes(txBz).WithBlockHeight(100).WithExecMode(sdk.ExecModeFinalize) diff --git a/x/auth/ante/validator_tx_fee.go b/x/auth/ante/validator_tx_fee.go index eb04320c1abe..af4f02fed05f 100644 --- a/x/auth/ante/validator_tx_fee.go +++ b/x/auth/ante/validator_tx_fee.go @@ -24,7 +24,7 @@ func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, // Ensure that the provided fees meet a minimum threshold for the validator, // if this is a CheckTx. This is only for local mempool purposes, and thus // is only ran on check tx. - if ctx.ExecMode() == sdk.ExecModeCheck { + if ctx.ExecMode() == sdk.ExecModeCheck { // NOTE: using environment here breaks the API of fee logic, an alternative must be found for server/v2. ref: https://github.com/cosmos/cosmos-sdk/issues/19640 minGasPrices := ctx.MinGasPrices() if !minGasPrices.IsZero() { requiredFees := make(sdk.Coins, len(minGasPrices)) diff --git a/x/auth/depinject.go b/x/auth/depinject.go index 67d75e7c902a..d8f4ca497f84 100644 --- a/x/auth/depinject.go +++ b/x/auth/depinject.go @@ -27,6 +27,7 @@ func init() { type ModuleInputs struct { depinject.In + AccountsModKeeper types.AccountsModKeeper Config *modulev1.Module Environment appmodule.Environment @@ -69,7 +70,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { panic(err) } - k := keeper.NewAccountKeeper(in.Environment, in.Cdc, in.AccountI, maccPerms, in.AddressCodec, in.Config.Bech32Prefix, auth) + k := keeper.NewAccountKeeper(in.Environment, in.Cdc, in.AccountI, maccPerms, in.AddressCodec, in.Config.Bech32Prefix, auth, in.AccountsModKeeper) m := NewAppModule(in.Cdc, k, in.RandomGenesisAccountsFn) return ModuleOutputs{AccountKeeper: k, Module: m} diff --git a/x/auth/go.mod b/x/auth/go.mod index 13e4cf4dec85..c379c7ed239d 100644 --- a/x/auth/go.mod +++ b/x/auth/go.mod @@ -152,7 +152,7 @@ require ( golang.org/x/crypto v0.22.0 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/auth/go.sum b/x/auth/go.sum index 0470dbf6a442..94a3a961df88 100644 --- a/x/auth/go.sum +++ b/x/auth/go.sum @@ -812,8 +812,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/auth/keeper/account.go b/x/auth/keeper/account.go index bdd36d12450f..3e21fd9a8594 100644 --- a/x/auth/keeper/account.go +++ b/x/auth/keeper/account.go @@ -32,7 +32,7 @@ func (ak AccountKeeper) NewAccount(ctx context.Context, acc sdk.AccountI) sdk.Ac // HasAccount implements AccountKeeperI. func (ak AccountKeeper) HasAccount(ctx context.Context, addr sdk.AccAddress) bool { has, _ := ak.Accounts.Has(ctx, addr) - return has + return has || ak.AccountsModKeeper.IsAccountsModuleAccount(ctx, addr) } // GetAccount implements AccountKeeperI. diff --git a/x/auth/keeper/deterministic_test.go b/x/auth/keeper/deterministic_test.go index 61baa01c2835..f6f7657f50b7 100644 --- a/x/auth/keeper/deterministic_test.go +++ b/x/auth/keeper/deterministic_test.go @@ -79,6 +79,7 @@ func (suite *DeterministicTestSuite) SetupTest() { authcodec.NewBech32Codec("cosmos"), "cosmos", types.NewModuleAddress("gov").String(), + nil, ) queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.encCfg.InterfaceRegistry) @@ -299,6 +300,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryModuleAccounts() { authcodec.NewBech32Codec("cosmos"), "cosmos", types.NewModuleAddress("gov").String(), + nil, ) suite.setModuleAccounts(suite.ctx, ak, maccs) @@ -346,6 +348,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryModuleAccountByName() { authcodec.NewBech32Codec("cosmos"), "cosmos", types.NewModuleAddress("gov").String(), + nil, ) suite.setModuleAccounts(suite.ctx, ak, []string{mName}) diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 9f03b175fcb4..1991bae32bf4 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -53,6 +53,9 @@ type AccountKeeperI interface { // AddressCodec returns the account address codec. AddressCodec() address.Codec + + // Environment returns the module's environment. + Environment() appmodule.Environment } func NewAccountIndexes(sb *collections.SchemaBuilder) AccountsIndexes { @@ -80,7 +83,8 @@ func (a AccountsIndexes) IndexesList() []collections.Index[sdk.AccAddress, sdk.A // AccountKeeper encodes/decodes accounts using the go-amino (binary) // encoding/decoding library. type AccountKeeper struct { - addressCodec address.Codec + addressCodec address.Codec + AccountsModKeeper types.AccountsModKeeper environment appmodule.Environment cdc codec.BinaryCodec @@ -112,7 +116,7 @@ var _ AccountKeeperI = &AccountKeeper{} // may use auth.Keeper to access the accounts permissions map. func NewAccountKeeper( env appmodule.Environment, cdc codec.BinaryCodec, proto func() sdk.AccountI, - maccPerms map[string][]string, ac address.Codec, bech32Prefix, authority string, + maccPerms map[string][]string, ac address.Codec, bech32Prefix, authority string, accountsModKeeper types.AccountsModKeeper, ) AccountKeeper { permAddrs := make(map[string]types.PermissionsForAddress) for name, perms := range maccPerms { @@ -122,16 +126,17 @@ func NewAccountKeeper( sb := collections.NewSchemaBuilder(env.KVStoreService) ak := AccountKeeper{ - addressCodec: ac, - bech32Prefix: bech32Prefix, - environment: env, - proto: proto, - cdc: cdc, - permAddrs: permAddrs, - authority: authority, - Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), - AccountNumber: collections.NewSequence(sb, types.GlobalAccountNumberKey, "account_number"), - Accounts: collections.NewIndexedMap(sb, types.AddressStoreKeyPrefix, "accounts", sdk.AccAddressKey, codec.CollInterfaceValue[sdk.AccountI](cdc), NewAccountIndexes(sb)), + addressCodec: ac, + bech32Prefix: bech32Prefix, + environment: env, + proto: proto, + cdc: cdc, + permAddrs: permAddrs, + authority: authority, + Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), + AccountNumber: collections.NewSequence(sb, types.GlobalAccountNumberKey, "account_number"), + Accounts: collections.NewIndexedMap(sb, types.AddressStoreKeyPrefix, "accounts", sdk.AccAddressKey, codec.CollInterfaceValue[sdk.AccountI](cdc), NewAccountIndexes(sb)), + AccountsModKeeper: accountsModKeeper, } schema, err := sb.Build() if err != nil { @@ -275,3 +280,8 @@ func (ak AccountKeeper) GetParams(ctx context.Context) (params types.Params) { } return params } + +// Environment returns the module's environment. +func (ak AccountKeeper) Environment() appmodule.Environment { + return ak.environment +} diff --git a/x/auth/keeper/keeper_test.go b/x/auth/keeper/keeper_test.go index 02a25bb6ec83..78267c01d3ca 100644 --- a/x/auth/keeper/keeper_test.go +++ b/x/auth/keeper/keeper_test.go @@ -72,6 +72,7 @@ func (suite *KeeperTestSuite) SetupTest() { authcodec.NewBech32Codec("cosmos"), "cosmos", types.NewModuleAddress("gov").String(), + nil, ) suite.msgServer = keeper.NewMsgServerImpl(suite.accountKeeper) queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.encCfg.InterfaceRegistry) diff --git a/x/auth/testutil/app_config.go b/x/auth/testutil/app_config.go index eeb5a324cb45..f72850c4bf1a 100644 --- a/x/auth/testutil/app_config.go +++ b/x/auth/testutil/app_config.go @@ -1,6 +1,7 @@ package testutil import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/auth/vesting" // import as blank for app wiring @@ -13,6 +14,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.VestingModule(), diff --git a/x/auth/testutil/expected_keepers_mocks.go b/x/auth/testutil/expected_keepers_mocks.go index 2d0e602a8cbc..2604271001d9 100644 --- a/x/auth/testutil/expected_keepers_mocks.go +++ b/x/auth/testutil/expected_keepers_mocks.go @@ -81,3 +81,43 @@ func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAd mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromAccountToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromAccountToModule), ctx, senderAddr, recipientModule, amt) } + + +// MockAccountsModKeeper is a mock of AccountsModKeeper interface. +type MockAccountsModKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountsModKeeperMockRecorder +} + +// MockAccountsModKeeperMockRecorder is the mock recorder for MockAccountsModKeeper. +type MockAccountsModKeeperMockRecorder struct { + mock *MockAccountsModKeeper +} + +// NewMockAccountsModKeeper creates a new mock instance. +func NewMockAccountsModKeeper(ctrl *gomock.Controller) *MockAccountsModKeeper { + mock := &MockAccountsModKeeper{ctrl: ctrl} + mock.recorder = &MockAccountsModKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountsModKeeper) EXPECT() *MockAccountsModKeeperMockRecorder { + return m.recorder +} + +// IsAccountsModuleAccount mocks base method. +func (m *MockAccountsModKeeper) IsAccountsModuleAccount(ctx context.Context, addr []byte) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsAccountsModuleAccount", ctx, addr) + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsAccountsModuleAccount indicates an expected call of IsAccountsModuleAccount. +func (mr *MockAccountsModKeeperMockRecorder) IsAccountsModuleAccount(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAccountsModuleAccount", reflect.TypeOf((*MockAccountsModKeeper)(nil).IsAccountsModuleAccount), ctx, addr) +} + + diff --git a/x/auth/types/expected_keepers.go b/x/auth/types/expected_keepers.go index ffcfe49aa10d..f7821d91251b 100644 --- a/x/auth/types/expected_keepers.go +++ b/x/auth/types/expected_keepers.go @@ -12,3 +12,8 @@ type BankKeeper interface { SendCoins(ctx context.Context, from, to sdk.AccAddress, amt sdk.Coins) error SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error } + +// AccountsModKeeper defines the contract for x/accounts APIs +type AccountsModKeeper interface { + IsAccountsModuleAccount(ctx context.Context, accountAddr []byte) bool +} diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index 83273f32bbad..350bba50bec2 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -62,7 +62,7 @@ func (s *VestingAccountTestSuite) SetupTest() { maccPerms, authcodec.NewBech32Codec("cosmos"), "cosmos", - authtypes.NewModuleAddress("gov").String(), + authtypes.NewModuleAddress("gov").String(), nil, ) } diff --git a/x/authz/go.mod b/x/authz/go.mod index 4c7a7b099575..f3cda496f8d0 100644 --- a/x/authz/go.mod +++ b/x/authz/go.mod @@ -150,7 +150,7 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/authz/go.sum b/x/authz/go.sum index 0470dbf6a442..94a3a961df88 100644 --- a/x/authz/go.sum +++ b/x/authz/go.sum @@ -812,8 +812,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/bank/CHANGELOG.md b/x/bank/CHANGELOG.md index 234561bd9912..d6d3a6962123 100644 --- a/x/bank/CHANGELOG.md +++ b/x/bank/CHANGELOG.md @@ -28,6 +28,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features * [#17569](https://github.com/cosmos/cosmos-sdk/pull/17569) Introduce a new message type, `MsgBurn`, to burn coins. +* [#20014](https://github.com/cosmos/cosmos-sdk/pull/20014) Support app wiring for `SendRestrictionFn`. ### Improvements diff --git a/x/bank/autocli.go b/x/bank/autocli.go index 065dda07068d..4b4c3529f2bd 100644 --- a/x/bank/autocli.go +++ b/x/bank/autocli.go @@ -85,7 +85,7 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { To look up one or more specific denoms, supply them as arguments to this command. To look up all denoms, do not provide any arguments.`, ), - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "denoms"}}, + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "denoms", Varargs: true}}, }, }, }, diff --git a/x/bank/depinject.go b/x/bank/depinject.go index 8a9d3efdd825..1d6f7dd3e533 100644 --- a/x/bank/depinject.go +++ b/x/bank/depinject.go @@ -1,6 +1,11 @@ package bank import ( + "fmt" + "sort" + + "golang.org/x/exp/maps" + modulev1 "cosmossdk.io/api/cosmos/bank/module/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" @@ -18,8 +23,10 @@ var _ depinject.OnePerModuleType = AppModule{} func (am AppModule) IsOnePerModuleType() {} func init() { - appconfig.RegisterModule(&modulev1.Module{}, + appconfig.RegisterModule( + &modulev1.Module{}, appconfig.Provide(ProvideModule), + appconfig.Invoke(InvokeSetSendRestrictions), ) } @@ -86,3 +93,39 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { return ModuleOutputs{BankKeeper: bankKeeper, Module: m} } + +func InvokeSetSendRestrictions( + config *modulev1.Module, + keeper keeper.BaseKeeper, + restrictions map[string]types.SendRestrictionFn, +) error { + if config == nil { + return nil + } + + modules := maps.Keys(restrictions) + order := config.RestrictionsOrder + if len(order) == 0 { + order = modules + sort.Strings(order) + } + + if len(order) != len(modules) { + return fmt.Errorf("len(restrictions order: %v) != len(restriction modules: %v)", order, modules) + } + + if len(modules) == 0 { + return nil + } + + for _, module := range order { + restriction, ok := restrictions[module] + if !ok { + return fmt.Errorf("can't find send restriction for module %s", module) + } + + keeper.AppendSendRestriction(restriction) + } + + return nil +} diff --git a/x/bank/go.mod b/x/bank/go.mod index 2f6df0f6d9ab..c84db1fc7274 100644 --- a/x/bank/go.mod +++ b/x/bank/go.mod @@ -149,7 +149,7 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/bank/go.sum b/x/bank/go.sum index 0470dbf6a442..94a3a961df88 100644 --- a/x/bank/go.sum +++ b/x/bank/go.sum @@ -812,8 +812,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index c643eb01489b..749c81ace578 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -439,6 +439,10 @@ func (k BaseKeeper) setSupply(ctx context.Context, coin sdk.Coin) { func (k BaseKeeper) trackDelegation(ctx context.Context, addr sdk.AccAddress, balance, amt sdk.Coins) error { acc := k.ak.GetAccount(ctx, addr) if acc == nil { + // check if it's an x/accounts smart account + if k.ak.HasAccount(ctx, addr) { + return nil + } return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr) } @@ -456,6 +460,10 @@ func (k BaseKeeper) trackDelegation(ctx context.Context, addr sdk.AccAddress, ba func (k BaseKeeper) trackUndelegation(ctx context.Context, addr sdk.AccAddress, amt sdk.Coins) error { acc := k.ak.GetAccount(ctx, addr) if acc == nil { + // check if it's an x/accounts smart account + if k.ak.HasAccount(ctx, addr) { + return nil + } return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr) } diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 86043fc81074..2c8f114ee8e3 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -1778,6 +1778,7 @@ func (suite *KeeperTestSuite) TestUndelegateCoins_Invalid() { suite.mockFundAccount(accAddrs[0]) require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], origCoins)) + suite.authKeeper.EXPECT().HasAccount(ctx, accAddrs[0]).Return(false) suite.mockDelegateCoins(ctx, acc0, holderAcc) require.NoError(suite.bankKeeper.DelegateCoins(ctx, accAddrs[0], holderAcc.GetAddress(), delCoins)) diff --git a/x/bank/proto/cosmos/bank/module/v1/module.proto b/x/bank/proto/cosmos/bank/module/v1/module.proto index dd79d1707d01..effc0b577da6 100644 --- a/x/bank/proto/cosmos/bank/module/v1/module.proto +++ b/x/bank/proto/cosmos/bank/module/v1/module.proto @@ -17,4 +17,10 @@ message Module { // authority defines the custom module authority. If not set, defaults to the governance module. string authority = 2; + + // restrictions_order specifies the order of send restrictions and should be + // a list of module names which provide a send restriction instance. If no + // order is provided, then restrictions will be applied in alphabetical order + // of module names. + repeated string restrictions_order = 3; } diff --git a/x/bank/testutil/expected_keepers_mocks.go b/x/bank/testutil/expected_keepers_mocks.go index 058c4e2d7e36..0b3ded8ec673 100644 --- a/x/bank/testutil/expected_keepers_mocks.go +++ b/x/bank/testutil/expected_keepers_mocks.go @@ -216,3 +216,17 @@ func (mr *MockAccountKeeperMockRecorder) ValidatePermissions(macc interface{}) * mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidatePermissions", reflect.TypeOf((*MockAccountKeeper)(nil).ValidatePermissions), macc) } + +// IsAccountsModuleAccount mocks base method. +func (m *MockAccountKeeper) IsAccountsModuleAccount(ctx context.Context, addr []byte) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsAccountsModuleAccount", ctx, addr) + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsAccountsModuleAccount indicates an expected call of IsAccountsModuleAccount. +func (mr *MockAccountKeeperMockRecorder) IsAccountsModuleAccount(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAccountsModuleAccount", reflect.TypeOf((*MockAccountKeeper)(nil).IsAccountsModuleAccount), ctx, addr) +} diff --git a/x/bank/types/restrictions.go b/x/bank/types/restrictions.go index 6d7d6fe6bc86..2ec4489a0978 100644 --- a/x/bank/types/restrictions.go +++ b/x/bank/types/restrictions.go @@ -54,6 +54,9 @@ func ComposeMintingRestrictions(restrictions ...MintingRestrictionFn) MintingRes // A SendRestrictionFn can restrict sends and/or provide a new receiver address. type SendRestrictionFn func(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) (newToAddr sdk.AccAddress, err error) +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (SendRestrictionFn) IsOnePerModuleType() {} + var _ SendRestrictionFn = NoOpSendRestrictionFn // NoOpSendRestrictionFn is a no-op SendRestrictionFn. diff --git a/x/circuit/go.mod b/x/circuit/go.mod index f0b0c9832355..f21819e97b9f 100644 --- a/x/circuit/go.mod +++ b/x/circuit/go.mod @@ -149,7 +149,7 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/circuit/go.sum b/x/circuit/go.sum index 0470dbf6a442..94a3a961df88 100644 --- a/x/circuit/go.sum +++ b/x/circuit/go.sum @@ -812,8 +812,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/circuit/module.go b/x/circuit/module.go index 5f14b29e4c8c..32dd06677651 100644 --- a/x/circuit/module.go +++ b/x/circuit/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "time" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc" @@ -16,7 +15,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/telemetry" "github.com/cosmos/cosmos-sdk/types/module" ) @@ -93,12 +91,10 @@ func (am AppModule) ValidateGenesis(bz json.RawMessage) error { // InitGenesis performs genesis initialization for the circuit module. func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) error { - start := time.Now() var genesisState types.GenesisState if err := am.cdc.UnmarshalJSON(data, &genesisState); err != nil { return err } - telemetry.MeasureSince(start, "InitGenesis", "crisis", "unmarshal") return am.keeper.InitGenesis(ctx, &genesisState) } diff --git a/x/crisis/abci.go b/x/crisis/abci.go index 8ce275ecd799..2eacc641c4ad 100644 --- a/x/crisis/abci.go +++ b/x/crisis/abci.go @@ -2,7 +2,6 @@ package crisis import ( "context" - "time" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" @@ -12,7 +11,7 @@ import ( // check all registered invariants func EndBlocker(ctx context.Context, k keeper.Keeper) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyEndBlocker) sdkCtx := sdk.UnwrapSDKContext(ctx) if k.InvCheckPeriod() == 0 || sdkCtx.BlockHeight()%int64(k.InvCheckPeriod()) != 0 { diff --git a/x/crisis/module.go b/x/crisis/module.go index 807a276aca93..0a17ce54908b 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "time" "github.com/spf13/cobra" "google.golang.org/grpc" @@ -13,7 +12,6 @@ import ( "cosmossdk.io/core/registry" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/telemetry" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/crisis/keeper" "github.com/cosmos/cosmos-sdk/x/crisis/types" @@ -118,12 +116,10 @@ func (am AppModule) ValidateGenesis(bz json.RawMessage) error { // InitGenesis performs genesis initialization for the crisis module. func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) error { - start := time.Now() var genesisState types.GenesisState if err := am.cdc.UnmarshalJSON(data, &genesisState); err != nil { return err } - telemetry.MeasureSince(start, "InitGenesis", "crisis", "unmarshal") am.keeper.InitGenesis(ctx, &genesisState) if !am.skipGenesisInvariants { diff --git a/x/distribution/go.mod b/x/distribution/go.mod index 3a0185ca4ae9..7fe828d73477 100644 --- a/x/distribution/go.mod +++ b/x/distribution/go.mod @@ -151,7 +151,7 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/distribution/go.sum b/x/distribution/go.sum index 0fed16823a57..ab6432216994 100644 --- a/x/distribution/go.sum +++ b/x/distribution/go.sum @@ -814,8 +814,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/distribution/keeper/abci.go b/x/distribution/keeper/abci.go index 544b62e1e69e..60d1aea984a9 100644 --- a/x/distribution/keeper/abci.go +++ b/x/distribution/keeper/abci.go @@ -1,8 +1,6 @@ package keeper import ( - "time" - "cosmossdk.io/x/distribution/types" "github.com/cosmos/cosmos-sdk/telemetry" @@ -13,7 +11,7 @@ import ( // and distribute rewards for the previous block. // TODO: use context.Context after including the comet service func (k Keeper) BeginBlocker(ctx sdk.Context) error { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) // determine the total power signing the block var previousTotalPower int64 diff --git a/x/distribution/migrations/v4/migrate_funds_test.go b/x/distribution/migrations/v4/migrate_funds_test.go index 7158037befe5..43516921b4cd 100644 --- a/x/distribution/migrations/v4/migrate_funds_test.go +++ b/x/distribution/migrations/v4/migrate_funds_test.go @@ -55,6 +55,7 @@ func TestFundsMigration(t *testing.T) { addressCodec, sdk.Bech32MainPrefix, authority, + nil, ) // create bank keeper diff --git a/x/epochs/go.mod b/x/epochs/go.mod index 356efa81bebd..d5e4338a5538 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -142,7 +142,7 @@ require ( golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/epochs/go.sum b/x/epochs/go.sum index bedbe848b007..6ef06c257210 100644 --- a/x/epochs/go.sum +++ b/x/epochs/go.sum @@ -807,8 +807,8 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/epochs/keeper/abci.go b/x/epochs/keeper/abci.go index 826a0da5e6d8..e05399e9b02e 100644 --- a/x/epochs/keeper/abci.go +++ b/x/epochs/keeper/abci.go @@ -3,7 +3,6 @@ package keeper import ( "context" "fmt" - "time" "cosmossdk.io/x/epochs/types" @@ -12,7 +11,7 @@ import ( // BeginBlocker of epochs module. func (k Keeper) BeginBlocker(ctx context.Context) error { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) logger := k.Logger() headerInfo := k.environment.HeaderService.GetHeaderInfo(ctx) diff --git a/x/epochs/simulation/genesis.go b/x/epochs/simulation/genesis.go index 98993af2672e..c236faacbb8a 100644 --- a/x/epochs/simulation/genesis.go +++ b/x/epochs/simulation/genesis.go @@ -14,7 +14,7 @@ import ( // GenCommunityTax randomized CommunityTax func GenDuration(r *rand.Rand) time.Duration { - return time.Hour * time.Duration(r.Intn(168)) // limit 1 week + return time.Hour * time.Duration(r.Intn(168)+1) // between 1 hour to 1 week } func RandomizedEpochs(r *rand.Rand) []types.EpochInfo { diff --git a/x/evidence/CHANGELOG.md b/x/evidence/CHANGELOG.md index 7683aa73566e..f92f3d5b2e44 100644 --- a/x/evidence/CHANGELOG.md +++ b/x/evidence/CHANGELOG.md @@ -27,6 +27,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Api Breaking Changes +* [#20016](https://github.com/cosmos/cosmos-sdk/pull/20016) `NewMsgSubmitEvidence` now takes a string as argument instead of an `AccAddress`. * [#19482](https://github.com/cosmos/cosmos-sdk/pull/19482) `appmodule.Environment` is passed to `NewKeeper` instead of individual services * [#19627](https://github.com/cosmos/cosmos-sdk/pull/19627) `NewAppModule` now takes in a `codec.Codec` as its first argument diff --git a/x/evidence/go.mod b/x/evidence/go.mod index 5323b0e69afb..8c1bc9eefd84 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -150,7 +150,7 @@ require ( golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/evidence/go.sum b/x/evidence/go.sum index 0eb976341a4f..7c65e84bde44 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -812,8 +812,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/evidence/keeper/abci.go b/x/evidence/keeper/abci.go index 0ad33d81a73d..5e5321e40f3e 100644 --- a/x/evidence/keeper/abci.go +++ b/x/evidence/keeper/abci.go @@ -3,7 +3,6 @@ package keeper import ( "context" "fmt" - "time" "cosmossdk.io/core/comet" "cosmossdk.io/x/evidence/types" @@ -15,7 +14,7 @@ import ( // BeginBlocker iterates through and handles any newly discovered evidence of // misbehavior submitted by CometBFT. Currently, only equivocation is handled. func (k Keeper) BeginBlocker(ctx context.Context) error { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) bi := sdk.UnwrapSDKContext(ctx).CometInfo() diff --git a/x/evidence/keeper/keeper_test.go b/x/evidence/keeper/keeper_test.go index 61f9eb0ef4a2..1784b003b945 100644 --- a/x/evidence/keeper/keeper_test.go +++ b/x/evidence/keeper/keeper_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/suite" "cosmossdk.io/collections" + coreaddress "cosmossdk.io/core/address" "cosmossdk.io/core/header" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -74,6 +75,9 @@ type KeeperTestSuite struct { ctx sdk.Context + addressCodec coreaddress.Codec + consAddressCodec coreaddress.ConsensusAddressCodec + evidenceKeeper keeper.Keeper bankKeeper *evidencetestutil.MockBankKeeper accountKeeper *evidencetestutil.MockAccountKeeper @@ -91,6 +95,8 @@ func (suite *KeeperTestSuite) SetupTest() { tkey := storetypes.NewTransientStoreKey("evidence_transient_store") testCtx := testutil.DefaultContextWithDB(suite.T(), key, tkey) suite.ctx = testCtx.Ctx + suite.addressCodec = address.NewBech32Codec("cosmos") + suite.consAddressCodec = address.NewBech32Codec("cosmosvalcons") ctrl := gomock.NewController(suite.T()) @@ -137,11 +143,14 @@ func (suite *KeeperTestSuite) populateEvidence(ctx sdk.Context, numEvidence int) for i := 0; i < numEvidence; i++ { pk := ed25519.GenPrivKey() + consAddr, err := suite.consAddressCodec.BytesToString(pk.PubKey().Address()) + suite.Require().NoError(err) + evidence[i] = &types.Equivocation{ Height: 11, Power: 100, Time: time.Now().UTC(), - ConsensusAddress: sdk.ConsAddress(pk.PubKey().Address().Bytes()).String(), + ConsensusAddress: consAddr, } suite.Nil(suite.evidenceKeeper.SubmitEvidence(ctx, evidence[i])) @@ -153,12 +162,14 @@ func (suite *KeeperTestSuite) populateEvidence(ctx sdk.Context, numEvidence int) func (suite *KeeperTestSuite) TestSubmitValidEvidence() { ctx := suite.ctx.WithIsCheckTx(false) pk := ed25519.GenPrivKey() + consAddr, err := suite.consAddressCodec.BytesToString(pk.PubKey().Address()) + suite.Require().NoError(err) e := &types.Equivocation{ Height: 1, Power: 100, Time: time.Now().UTC(), - ConsensusAddress: sdk.ConsAddress(pk.PubKey().Address().Bytes()).String(), + ConsensusAddress: consAddr, } suite.Nil(suite.evidenceKeeper.SubmitEvidence(ctx, e)) @@ -171,12 +182,14 @@ func (suite *KeeperTestSuite) TestSubmitValidEvidence() { func (suite *KeeperTestSuite) TestSubmitValidEvidence_Duplicate() { ctx := suite.ctx.WithIsCheckTx(false) pk := ed25519.GenPrivKey() + consAddr, err := suite.consAddressCodec.BytesToString(pk.PubKey().Address()) + suite.Require().NoError(err) e := &types.Equivocation{ Height: 1, Power: 100, Time: time.Now().UTC(), - ConsensusAddress: sdk.ConsAddress(pk.PubKey().Address().Bytes()).String(), + ConsensusAddress: consAddr, } suite.Nil(suite.evidenceKeeper.SubmitEvidence(ctx, e)) @@ -190,14 +203,16 @@ func (suite *KeeperTestSuite) TestSubmitValidEvidence_Duplicate() { func (suite *KeeperTestSuite) TestSubmitInvalidEvidence() { ctx := suite.ctx.WithIsCheckTx(false) pk := ed25519.GenPrivKey() + consAddr, err := suite.consAddressCodec.BytesToString(pk.PubKey().Address()) + suite.Require().NoError(err) e := &types.Equivocation{ Height: 0, Power: 100, Time: time.Now().UTC(), - ConsensusAddress: sdk.ConsAddress(pk.PubKey().Address().Bytes()).String(), + ConsensusAddress: consAddr, } - err := suite.evidenceKeeper.SubmitEvidence(ctx, e) + err = suite.evidenceKeeper.SubmitEvidence(ctx, e) suite.ErrorIs(err, types.ErrInvalidEvidence) res, err := suite.evidenceKeeper.Evidences.Get(ctx, e.Hash()) diff --git a/x/evidence/keeper/msg_server_test.go b/x/evidence/keeper/msg_server_test.go index f5dd4b6b5fd2..86ac3447dcaa 100644 --- a/x/evidence/keeper/msg_server_test.go +++ b/x/evidence/keeper/msg_server_test.go @@ -6,30 +6,34 @@ import ( "cosmossdk.io/x/evidence/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - sdk "github.com/cosmos/cosmos-sdk/types" ) func (s *KeeperTestSuite) TestSubmitEvidence() { pk := ed25519.GenPrivKey() + consAddr, err := s.consAddressCodec.BytesToString(pk.PubKey().Address()) + s.Require().NoError(err) e := &types.Equivocation{ Height: 1, Power: 100, Time: time.Now().UTC(), - ConsensusAddress: sdk.ConsAddress(pk.PubKey().Address().Bytes()).String(), + ConsensusAddress: consAddr, } - validEvidence, err := types.NewMsgSubmitEvidence(sdk.AccAddress(valAddress), e) + accAddr, err := s.addressCodec.BytesToString(valAddress) + s.Require().NoError(err) + + validEvidence, err := types.NewMsgSubmitEvidence(accAddr, e) s.Require().NoError(err) e2 := &types.Equivocation{ Height: 0, Power: 100, Time: time.Now().UTC(), - ConsensusAddress: sdk.ConsAddress(pk.PubKey().Address().Bytes()).String(), + ConsensusAddress: consAddr, } - invalidEvidence, err := types.NewMsgSubmitEvidence(sdk.AccAddress(valAddress), e2) + invalidEvidence, err := types.NewMsgSubmitEvidence(accAddr, e2) s.Require().NoError(err) testCases := []struct { @@ -47,7 +51,7 @@ func (s *KeeperTestSuite) TestSubmitEvidence() { { name: "missing evidence", req: &types.MsgSubmitEvidence{ - Submitter: sdk.AccAddress(valAddress).String(), + Submitter: accAddr, }, expErr: true, expErrMsg: "missing evidence: invalid evidence", diff --git a/x/evidence/types/evidence_test.go b/x/evidence/types/evidence_test.go index 6e527bf371b8..bfa20f82a98d 100644 --- a/x/evidence/types/evidence_test.go +++ b/x/evidence/types/evidence_test.go @@ -16,20 +16,24 @@ import ( ) func TestEquivocation_Valid(t *testing.T) { + consCodec := address.NewBech32Codec("cosmosvalcons") n, _ := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z") - addr := sdk.ConsAddress("foo_________________") + addr, err := consCodec.BytesToString(sdk.ConsAddress("foo_________________")) + require.NoError(t, err) e := types.Equivocation{ Height: 100, Time: n, Power: 1000000, - ConsensusAddress: addr.String(), + ConsensusAddress: addr, } + consAddr, err := consCodec.BytesToString(e.GetConsensusAddress(consCodec)) + require.NoError(t, err) require.Equal(t, e.GetTotalPower(), int64(0)) require.Equal(t, e.GetValidatorPower(), e.Power) require.Equal(t, e.GetTime(), e.Time) - require.Equal(t, e.GetConsensusAddress(address.NewBech32Codec("cosmosvalcons")).String(), e.ConsensusAddress) + require.Equal(t, consAddr, e.ConsensusAddress) require.Equal(t, e.GetHeight(), e.Height) require.Equal(t, e.Route(), types.RouteEquivocation) require.Equal(t, strings.ToUpper(hex.EncodeToString(e.Hash())), "1E10F9267BEA3A9A4AB5302C2C510CC1AFD7C54E232DA5B2E3360DFAFACF7A76") @@ -39,7 +43,7 @@ func TestEquivocation_Valid(t *testing.T) { require.Equal(t, int64(0), e.GetTotalPower()) require.Equal(t, e.Power, e.GetValidatorPower()) require.Equal(t, e.Time, e.GetTime()) - require.Equal(t, e.ConsensusAddress, e.GetConsensusAddress(address.NewBech32Codec("cosmosvalcons")).String()) + require.Equal(t, e.ConsensusAddress, consAddr) require.Equal(t, e.Height, e.GetHeight()) require.Equal(t, types.RouteEquivocation, e.Route()) require.Equal(t, "1E10F9267BEA3A9A4AB5302C2C510CC1AFD7C54E232DA5B2E3360DFAFACF7A76", strings.ToUpper(hex.EncodeToString(e.Hash()))) @@ -49,7 +53,8 @@ func TestEquivocation_Valid(t *testing.T) { func TestEquivocationValidateBasic(t *testing.T) { var zeroTime time.Time - addr := sdk.ConsAddress("foo_________________") + addr, err := address.NewBech32Codec("cosmosvalcons").BytesToString(sdk.ConsAddress("foo_________________")) + require.NoError(t, err) n, _ := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z") testCases := []struct { @@ -57,10 +62,10 @@ func TestEquivocationValidateBasic(t *testing.T) { e types.Equivocation expectErr bool }{ - {"valid", types.Equivocation{100, n, 1000000, addr.String()}, false}, - {"invalid time", types.Equivocation{100, zeroTime, 1000000, addr.String()}, true}, - {"invalid height", types.Equivocation{0, n, 1000000, addr.String()}, true}, - {"invalid power", types.Equivocation{100, n, 0, addr.String()}, true}, + {"valid", types.Equivocation{100, n, 1000000, addr}, false}, + {"invalid time", types.Equivocation{100, zeroTime, 1000000, addr}, true}, + {"invalid height", types.Equivocation{0, n, 1000000, addr}, true}, + {"invalid power", types.Equivocation{100, n, 0, addr}, true}, {"invalid address", types.Equivocation{100, n, 1000000, ""}, true}, } diff --git a/x/evidence/types/msgs.go b/x/evidence/types/msgs.go index 8d65aca64dbc..92df414692a5 100644 --- a/x/evidence/types/msgs.go +++ b/x/evidence/types/msgs.go @@ -18,7 +18,7 @@ var ( ) // NewMsgSubmitEvidence returns a new MsgSubmitEvidence with a signer/submitter. -func NewMsgSubmitEvidence(s sdk.AccAddress, evi exported.Evidence) (*MsgSubmitEvidence, error) { +func NewMsgSubmitEvidence(s string, evi exported.Evidence) (*MsgSubmitEvidence, error) { msg, ok := evi.(proto.Message) if !ok { return nil, fmt.Errorf("cannot proto marshal %T", evi) @@ -27,7 +27,7 @@ func NewMsgSubmitEvidence(s sdk.AccAddress, evi exported.Evidence) (*MsgSubmitEv if err != nil { return nil, err } - return &MsgSubmitEvidence{Submitter: s.String(), Evidence: any}, nil + return &MsgSubmitEvidence{Submitter: s, Evidence: any}, nil } func (m MsgSubmitEvidence) GetEvidence() exported.Evidence { diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index 4115b34f5a88..7b05aac9bb12 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -155,7 +155,7 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index 6173b46c789b..6817d2a7fdae 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -822,8 +822,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/feegrant/proto/cosmos/feegrant/v1beta1/query.proto b/x/feegrant/proto/cosmos/feegrant/v1beta1/query.proto index 591537acd9ef..b06c774139f7 100644 --- a/x/feegrant/proto/cosmos/feegrant/v1beta1/query.proto +++ b/x/feegrant/proto/cosmos/feegrant/v1beta1/query.proto @@ -12,7 +12,7 @@ option go_package = "cosmossdk.io/x/feegrant"; // Query defines the gRPC querier service. service Query { - // Allowance returns granted allwance to the grantee by the granter. + // Allowance returns granted allowance to the grantee by the granter. rpc Allowance(QueryAllowanceRequest) returns (QueryAllowanceResponse) { option (google.api.http).get = "/cosmos/feegrant/v1beta1/allowance/{granter}/{grantee}"; } diff --git a/x/feegrant/query.pb.go b/x/feegrant/query.pb.go index a4673fc23302..675bcf038f46 100644 --- a/x/feegrant/query.pb.go +++ b/x/feegrant/query.pb.go @@ -415,7 +415,7 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { - // Allowance returns granted allwance to the grantee by the granter. + // Allowance returns granted allowance to the grantee by the granter. Allowance(ctx context.Context, in *QueryAllowanceRequest, opts ...grpc.CallOption) (*QueryAllowanceResponse, error) // Allowances returns all the grants for the given grantee address. Allowances(ctx context.Context, in *QueryAllowancesRequest, opts ...grpc.CallOption) (*QueryAllowancesResponse, error) @@ -462,7 +462,7 @@ func (c *queryClient) AllowancesByGranter(ctx context.Context, in *QueryAllowanc // QueryServer is the server API for Query service. type QueryServer interface { - // Allowance returns granted allwance to the grantee by the granter. + // Allowance returns granted allowance to the grantee by the granter. Allowance(context.Context, *QueryAllowanceRequest) (*QueryAllowanceResponse, error) // Allowances returns all the grants for the given grantee address. Allowances(context.Context, *QueryAllowancesRequest) (*QueryAllowancesResponse, error) diff --git a/x/gov/go.mod b/x/gov/go.mod index a77116559378..cf6c5ae424ee 100644 --- a/x/gov/go.mod +++ b/x/gov/go.mod @@ -154,7 +154,7 @@ require ( golang.org/x/crypto v0.22.0 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 + golang.org/x/sync v0.7.0 golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/gov/go.sum b/x/gov/go.sum index 6173b46c789b..6817d2a7fdae 100644 --- a/x/gov/go.sum +++ b/x/gov/go.sum @@ -822,8 +822,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/gov/keeper/abci.go b/x/gov/keeper/abci.go index 4e4052102b31..4969d4abfbda 100644 --- a/x/gov/keeper/abci.go +++ b/x/gov/keeper/abci.go @@ -21,7 +21,7 @@ import ( // EndBlocker is called every block. func (k Keeper) EndBlocker(ctx context.Context) error { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyEndBlocker) logger := k.Logger() // delete dead proposals from store and returns theirs deposits. diff --git a/x/group/go.mod b/x/group/go.mod index 736dc304c395..6d765f73fc48 100644 --- a/x/group/go.mod +++ b/x/group/go.mod @@ -10,6 +10,7 @@ require ( cosmossdk.io/log v1.3.1 cosmossdk.io/math v1.3.0 cosmossdk.io/store v1.0.2 + cosmossdk.io/x/accounts v0.0.0-00010101000000-000000000000 cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 cosmossdk.io/x/authz v0.0.0-00010101000000-000000000000 cosmossdk.io/x/bank v0.0.0-00010101000000-000000000000 @@ -39,7 +40,6 @@ require ( buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.32.0-20230509103710-5e5b9fdd0180.1 // indirect buf.build/gen/go/tendermint/tendermint/protocolbuffers/go v1.32.0-20231117195010-33ed361a9051.1 // indirect cosmossdk.io/collections v0.4.0 // indirect - cosmossdk.io/x/accounts v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v0.13.1 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect @@ -157,7 +157,7 @@ require ( golang.org/x/crypto v0.22.0 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/group/go.sum b/x/group/go.sum index 5a94fb2717ac..25667d2579d0 100644 --- a/x/group/go.sum +++ b/x/group/go.sum @@ -822,8 +822,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/group/migrations/v2/migrate_test.go b/x/group/migrations/v2/migrate_test.go index 80e42c0d2862..942a47ca097a 100644 --- a/x/group/migrations/v2/migrate_test.go +++ b/x/group/migrations/v2/migrate_test.go @@ -3,6 +3,7 @@ package v2_test import ( "testing" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" "cosmossdk.io/core/address" @@ -11,6 +12,7 @@ import ( storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" + authtestutil "cosmossdk.io/x/auth/testutil" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/group" "cosmossdk.io/x/group/internal/orm" @@ -101,7 +103,10 @@ func createOldPolicyAccount(ctx sdk.Context, storeKey storetypes.StoreKey, cdc c if err != nil { return nil, nil, err } - accountKeeper := authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(storeKey.(*storetypes.KVStoreKey)), log.NewNopLogger()), cdc, authtypes.ProtoBaseAccount, nil, addressCodec, sdk.Bech32MainPrefix, authorityStrAddr) + ctrl := gomock.NewController(&testing.T{}) + acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) + + accountKeeper := authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(storeKey.(*storetypes.KVStoreKey)), log.NewNopLogger()), cdc, authtypes.ProtoBaseAccount, nil, addressCodec, sdk.Bech32MainPrefix, authorityStrAddr, acctsModKeeper) oldPolicyAccounts := make([]*authtypes.ModuleAccount, len(policies)) for i, policyAddr := range policies { diff --git a/x/group/testutil/app_config.go b/x/group/testutil/app_config.go index f760be271998..d23caa88ebf2 100644 --- a/x/group/testutil/app_config.go +++ b/x/group/testutil/app_config.go @@ -1,6 +1,7 @@ package testutil import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/authz" // import as blank for app wiring @@ -15,6 +16,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/x/mint/go.mod b/x/mint/go.mod index fecfa9067ca0..5c22eef4f3e9 100644 --- a/x/mint/go.mod +++ b/x/mint/go.mod @@ -150,7 +150,7 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/mint/go.sum b/x/mint/go.sum index 0470dbf6a442..94a3a961df88 100644 --- a/x/mint/go.sum +++ b/x/mint/go.sum @@ -812,8 +812,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/mint/keeper/abci.go b/x/mint/keeper/abci.go index 8c3c1b3a4b01..04677ad2f317 100644 --- a/x/mint/keeper/abci.go +++ b/x/mint/keeper/abci.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "time" "cosmossdk.io/core/event" "cosmossdk.io/x/mint/types" @@ -13,7 +12,7 @@ import ( // BeginBlocker mints new tokens for the previous block. func (k Keeper) BeginBlocker(ctx context.Context, ic types.InflationCalculationFn) error { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) // fetch stored minter & params minter, err := k.Minter.Get(ctx) diff --git a/x/nft/go.mod b/x/nft/go.mod index 672c76ac25b2..72bed743e9b3 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -149,7 +149,7 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/nft/go.sum b/x/nft/go.sum index 0470dbf6a442..94a3a961df88 100644 --- a/x/nft/go.sum +++ b/x/nft/go.sum @@ -812,8 +812,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/params/go.mod b/x/params/go.mod index 49e8b610c7c8..d0c43d733ca2 100644 --- a/x/params/go.mod +++ b/x/params/go.mod @@ -150,7 +150,7 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/params/go.sum b/x/params/go.sum index 0470dbf6a442..94a3a961df88 100644 --- a/x/params/go.sum +++ b/x/params/go.sum @@ -812,8 +812,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/protocolpool/go.mod b/x/protocolpool/go.mod index ca0fc609ab05..5bd04358dd4b 100644 --- a/x/protocolpool/go.mod +++ b/x/protocolpool/go.mod @@ -151,7 +151,7 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/protocolpool/go.sum b/x/protocolpool/go.sum index 0470dbf6a442..94a3a961df88 100644 --- a/x/protocolpool/go.sum +++ b/x/protocolpool/go.sum @@ -812,8 +812,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/slashing/CHANGELOG.md b/x/slashing/CHANGELOG.md index 81a7018057d4..121c64c1b0a5 100644 --- a/x/slashing/CHANGELOG.md +++ b/x/slashing/CHANGELOG.md @@ -35,6 +35,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* [#20026](https://github.com/cosmos/cosmos-sdk/pull/20026) Removal of the Address.String() method and related changes: + * `Migrate` now takes a `ValidatorAddressCodec` as argument. + * `Migrator` has a new field of `ValidatorAddressCodec` type. * [#16441](https://github.com/cosmos/cosmos-sdk/pull/16441) Params state is migrated to collections. `GetParams` has been removed. * [#17023](https://github.com/cosmos/cosmos-sdk/pull/17023) Use collections for `ValidatorSigningInfo`: * remove `Keeper`: `SetValidatorSigningInfo`, `GetValidatorSigningInfo`, `IterateValidatorSigningInfos` diff --git a/x/slashing/abci.go b/x/slashing/abci.go index 20613b40cfd6..72645213d82b 100644 --- a/x/slashing/abci.go +++ b/x/slashing/abci.go @@ -2,7 +2,6 @@ package slashing import ( "context" - "time" "cosmossdk.io/x/slashing/keeper" "cosmossdk.io/x/slashing/types" @@ -14,7 +13,7 @@ import ( // BeginBlocker check for infraction evidence or downtime of validators // on every begin block func BeginBlocker(ctx context.Context, k keeper.Keeper) error { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) // Iterate over all the validators which *should* have signed this block // store whether or not they have actually signed it and slash/unbond any diff --git a/x/slashing/go.mod b/x/slashing/go.mod index 02b9335dc0d6..65a14ecaaf9c 100644 --- a/x/slashing/go.mod +++ b/x/slashing/go.mod @@ -152,7 +152,7 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/slashing/go.sum b/x/slashing/go.sum index 29b8bd7967de..a1632dddc43b 100644 --- a/x/slashing/go.sum +++ b/x/slashing/go.sum @@ -814,8 +814,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/slashing/keeper/migrations.go b/x/slashing/keeper/migrations.go index 8dde29ff7707..9f00003d315b 100644 --- a/x/slashing/keeper/migrations.go +++ b/x/slashing/keeper/migrations.go @@ -3,6 +3,7 @@ package keeper import ( "context" + "cosmossdk.io/core/address" v4 "cosmossdk.io/x/slashing/migrations/v4" "github.com/cosmos/cosmos-sdk/runtime" @@ -10,12 +11,16 @@ import ( // Migrator is a struct for handling in-place store migrations. type Migrator struct { - keeper Keeper + keeper Keeper + valCodec address.ValidatorAddressCodec } // NewMigrator returns a new Migrator. -func NewMigrator(keeper Keeper) Migrator { - return Migrator{keeper: keeper} +func NewMigrator(keeper Keeper, valCodec address.ValidatorAddressCodec) Migrator { + return Migrator{ + keeper: keeper, + valCodec: valCodec, + } } // Migrate1to2 migrates from version 1 to 2. @@ -40,5 +45,5 @@ func (m Migrator) Migrate3to4(ctx context.Context) error { if err != nil { return err } - return v4.Migrate(ctx, m.keeper.cdc, store, params) + return v4.Migrate(ctx, m.keeper.cdc, store, params, m.valCodec) } diff --git a/x/slashing/migrations/v4/migrate.go b/x/slashing/migrations/v4/migrate.go index f81566996e68..331068c32824 100644 --- a/x/slashing/migrations/v4/migrate.go +++ b/x/slashing/migrations/v4/migrate.go @@ -6,6 +6,7 @@ import ( "github.com/bits-and-blooms/bitset" gogotypes "github.com/cosmos/gogoproto/types" + "cosmossdk.io/core/address" "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/slashing/types" @@ -17,12 +18,15 @@ import ( // Migrate migrates state to consensus version 4. Specifically, the migration // deletes all existing validator bitmap entries and replaces them with a real // "chunked" bitmap. -func Migrate(ctx context.Context, cdc codec.BinaryCodec, store storetypes.KVStore, params types.Params) error { +func Migrate(ctx context.Context, cdc codec.BinaryCodec, store storetypes.KVStore, params types.Params, addressCodec address.ValidatorAddressCodec) error { // Get all the missed blocks for each validator, based on the existing signing // info. var missedBlocks []types.ValidatorMissedBlocks iterateValidatorSigningInfos(ctx, cdc, store, func(addr sdk.ConsAddress, info types.ValidatorSigningInfo) (stop bool) { - bechAddr := addr.String() + bechAddr, err := addressCodec.BytesToString(addr) + if err != nil { + return true + } localMissedBlocks := GetValidatorMissedBlocks(ctx, cdc, store, addr, params) missedBlocks = append(missedBlocks, types.ValidatorMissedBlocks{ diff --git a/x/slashing/migrations/v4/migrate_test.go b/x/slashing/migrations/v4/migrate_test.go index 41d8995af6e4..84fe79544624 100644 --- a/x/slashing/migrations/v4/migrate_test.go +++ b/x/slashing/migrations/v4/migrate_test.go @@ -12,6 +12,7 @@ import ( v4 "cosmossdk.io/x/slashing/migrations/v4" slashingtypes "cosmossdk.io/x/slashing/types" + "github.com/cosmos/cosmos-sdk/codec/address" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -27,9 +28,12 @@ func TestMigrate(t *testing.T) { ctx := testutil.DefaultContext(storeKey, tKey) store := ctx.KVStore(storeKey) params := slashingtypes.Params{SignedBlocksWindow: 100} + valCodec := address.NewBech32Codec("cosmosvalcons") + consStrAddr, err := valCodec.BytesToString(consAddr) + require.NoError(t, err) // store old signing info and bitmap entries - bz := cdc.MustMarshal(&slashingtypes.ValidatorSigningInfo{Address: consAddr.String()}) + bz := cdc.MustMarshal(&slashingtypes.ValidatorSigningInfo{Address: consStrAddr}) store.Set(v4.ValidatorSigningInfoKey(consAddr), bz) for i := int64(0); i < params.SignedBlocksWindow; i++ { @@ -39,7 +43,7 @@ func TestMigrate(t *testing.T) { store.Set(v4.ValidatorMissedBlockBitArrayKey(consAddr, i), bz) } - err := v4.Migrate(ctx, cdc, store, params) + err = v4.Migrate(ctx, cdc, store, params, valCodec) require.NoError(t, err) for i := int64(0); i < params.SignedBlocksWindow; i++ { diff --git a/x/slashing/module.go b/x/slashing/module.go index dab442d3860d..c5ae4fef1919 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -103,7 +103,7 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { // RegisterMigrations registers module migrations. func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error { - m := keeper.NewMigrator(am.keeper) + m := keeper.NewMigrator(am.keeper, am.stakingKeeper.ValidatorAddressCodec()) if err := mr.Register(types.ModuleName, 1, m.Migrate1to2); err != nil { return fmt.Errorf("failed to migrate x/%s from version 1 to 2: %w", types.ModuleName, err) diff --git a/x/slashing/simulation/proposals.go b/x/slashing/simulation/proposals.go index 5d37412ad821..1ea39d97f19a 100644 --- a/x/slashing/simulation/proposals.go +++ b/x/slashing/simulation/proposals.go @@ -33,10 +33,15 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg { } // SimulateMsgUpdateParams returns a random MsgUpdateParams -func SimulateMsgUpdateParams(r *rand.Rand, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) { +func SimulateMsgUpdateParams(r *rand.Rand, _ []simtypes.Account, ac coreaddress.Codec) (sdk.Msg, error) { // use the default gov module account address as authority var authority sdk.AccAddress = address.Module("gov") + authorityAddr, err := ac.BytesToString(authority) + if err != nil { + return nil, err + } + params := types.DefaultParams() params.DowntimeJailDuration = time.Duration(simtypes.RandTimestamp(r).UnixNano()) params.SignedBlocksWindow = int64(simtypes.RandIntBetween(r, 1, 1000)) @@ -45,7 +50,7 @@ func SimulateMsgUpdateParams(r *rand.Rand, _ []simtypes.Account, _ coreaddress.C params.SlashFractionDowntime = sdkmath.LegacyNewDecWithPrec(int64(simtypes.RandIntBetween(r, 1, 100)), 2) return &types.MsgUpdateParams{ - Authority: authority.String(), + Authority: authorityAddr, Params: params, }, nil } diff --git a/x/slashing/simulation/proposals_test.go b/x/slashing/simulation/proposals_test.go index 6a67de33fd29..d2b553964a00 100644 --- a/x/slashing/simulation/proposals_test.go +++ b/x/slashing/simulation/proposals_test.go @@ -12,7 +12,6 @@ import ( "cosmossdk.io/x/slashing/types" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) @@ -21,6 +20,7 @@ func TestProposalMsgs(t *testing.T) { // initialize parameters s := rand.NewSource(1) r := rand.New(s) + ac := codectestutil.CodecOptions{}.GetAddressCodec() accounts := simtypes.RandomAccounts(r, 3) @@ -34,12 +34,15 @@ func TestProposalMsgs(t *testing.T) { assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) - msg, err := w0.MsgSimulatorFn()(r, accounts, codectestutil.CodecOptions{}.GetAddressCodec()) + msg, err := w0.MsgSimulatorFn()(r, accounts, ac) assert.NilError(t, err) msgUpdateParams, ok := msg.(*types.MsgUpdateParams) assert.Assert(t, ok) - assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) + moduleAddr, err := ac.BytesToString(address.Module("gov")) + assert.NilError(t, err) + + assert.Equal(t, moduleAddr, msgUpdateParams.Authority) assert.Equal(t, int64(905), msgUpdateParams.Params.SignedBlocksWindow) assert.DeepEqual(t, sdkmath.LegacyNewDecWithPrec(7, 2), msgUpdateParams.Params.MinSignedPerWindow) assert.DeepEqual(t, sdkmath.LegacyNewDecWithPrec(60, 2), msgUpdateParams.Params.SlashFractionDoubleSign) diff --git a/x/staking/go.mod b/x/staking/go.mod index 4167fd09c0e9..13470f82b9fd 100644 --- a/x/staking/go.mod +++ b/x/staking/go.mod @@ -150,7 +150,7 @@ require ( golang.org/x/crypto v0.22.0 // indirect golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/staking/go.sum b/x/staking/go.sum index 0470dbf6a442..94a3a961df88 100644 --- a/x/staking/go.sum +++ b/x/staking/go.sum @@ -812,8 +812,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/staking/keeper/abci.go b/x/staking/keeper/abci.go index 1e70b2c6bb1c..59db9be890cb 100644 --- a/x/staking/keeper/abci.go +++ b/x/staking/keeper/abci.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "time" "cosmossdk.io/core/appmodule" "cosmossdk.io/x/staking/types" @@ -13,12 +12,13 @@ import ( // BeginBlocker will persist the current header and validator set as a historical entry // and prune the oldest entry based on the HistoricalEntries parameter func (k *Keeper) BeginBlocker(ctx context.Context) error { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) return k.TrackHistoricalInfo(ctx) } // EndBlocker called at every block, update validator set func (k *Keeper) EndBlocker(ctx context.Context) ([]appmodule.ValidatorUpdate, error) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) + start := telemetry.Now() + defer telemetry.ModuleMeasureSince(types.ModuleName, start, telemetry.MetricKeyEndBlocker) return k.BlockValidatorUpdates(ctx) } diff --git a/x/tx/CHANGELOG.md b/x/tx/CHANGELOG.md index 040681ddb96c..a290d125dd73 100644 --- a/x/tx/CHANGELOG.md +++ b/x/tx/CHANGELOG.md @@ -25,15 +25,19 @@ Types of changes (Stanzas): "Bug Fixes" for any bug fixes. "API Breaking" for breaking exported APIs used by developers building on SDK. Ref: https://keepachangelog.com/en/1.0.0/ + +Since v0.13.0, x/tx follows Cosmos SDK semver: https://github.com/cosmos/cosmos-sdk/blob/main/RELEASES.md --> # Changelog ## [Unreleased] +## [v0.13.2](https://github.com/cosmos/cosmos-sdk/releases/tag/x/tx/v0.13.2) - 2024-04-12 + ### Features -* [#19786](https://github.com/cosmos/cosmos-sdk/pull/19786) Add bytes as string option to encoder. +* [#19786](https://github.com/cosmos/cosmos-sdk/pull/19786)/[#19919](https://github.com/cosmos/cosmos-sdk/pull/19919) Add "inline_json" option to Amino JSON encoder. ### Improvements @@ -43,7 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#19955](https://github.com/cosmos/cosmos-sdk/pull/19955) Don't shadow Amino marshalling error messages -## v0.13.1 +## [v0.13.1](https://github.com/cosmos/cosmos-sdk/releases/tag/x/tx/v0.13.1) - 2024-03-05 ### Features @@ -57,7 +61,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#19265](https://github.com/cosmos/cosmos-sdk/pull/19265) Reject denoms that contain a comma. -## v0.13.0 +## [v0.13.0](https://github.com/cosmos/cosmos-sdk/releases/tag/x/tx/v0.13.0) - 2023-12-19 ### Improvements diff --git a/x/tx/signing/aminojson/encoder.go b/x/tx/signing/aminojson/encoder.go index 5b8a91f449d7..d799eb52e627 100644 --- a/x/tx/signing/aminojson/encoder.go +++ b/x/tx/signing/aminojson/encoder.go @@ -81,16 +81,21 @@ func nullSliceAsEmptyEncoder(enc *Encoder, v protoreflect.Value, w io.Writer) er } } -// cosmosBytesAsString replicates the behavior at: +// cosmosInlineJSON takes bytes and inlines them into a JSON document. +// +// This requires the bytes contain valid JSON since otherwise the resulting document would be invalid. +// Invalid JSON will result in an error. +// +// This replicates the behavior of JSON messages embedded in protobuf bytes +// required for CosmWasm, e.g.: // https://github.com/CosmWasm/wasmd/blob/08567ff20e372e4f4204a91ca64a371538742bed/x/wasm/types/tx.go#L20-L22 -func cosmosBytesAsString(_ *Encoder, v protoreflect.Value, w io.Writer) error { +func cosmosInlineJSON(_ *Encoder, v protoreflect.Value, w io.Writer) error { switch bz := v.Interface().(type) { case []byte: - blob, err := json.RawMessage(bz).MarshalJSON() - if err != nil { - return err + if !json.Valid(bz) { + return errors.New("invalid JSON bytes") } - _, err = w.Write(blob) + _, err := w.Write(bz) return err default: return fmt.Errorf("unsupported type %T", bz) diff --git a/x/tx/signing/aminojson/encoder_test.go b/x/tx/signing/aminojson/encoder_test.go index a843238614bb..1ebf9990ac38 100644 --- a/x/tx/signing/aminojson/encoder_test.go +++ b/x/tx/signing/aminojson/encoder_test.go @@ -9,21 +9,64 @@ import ( "gotest.tools/v3/assert" ) -func TestCosmosBytesAsString(t *testing.T) { +func TestCosmosInlineJSON(t *testing.T) { cases := map[string]struct { value protoreflect.Value wantErr bool wantOutput string }{ - "valid bytes - json": { + "supported type - valid JSON object": { value: protoreflect.ValueOfBytes([]byte(`{"test":"value"}`)), wantErr: false, wantOutput: `{"test":"value"}`, }, - "valid bytes - string": { - value: protoreflect.ValueOfBytes([]byte(`foo`)), + "supported type - valid JSON array": { + // spaces are normalized away + value: protoreflect.ValueOfBytes([]byte(`[1,2,3]`)), wantErr: false, - wantOutput: `foo`, + wantOutput: `[1,2,3]`, + }, + "supported type - valid JSON is not normalized": { + value: protoreflect.ValueOfBytes([]byte(`[1, 2, 3]`)), + wantErr: false, + wantOutput: `[1, 2, 3]`, + }, + "supported type - valid JSON array (empty)": { + value: protoreflect.ValueOfBytes([]byte(`[]`)), + wantErr: false, + wantOutput: `[]`, + }, + "supported type - valid JSON number": { + value: protoreflect.ValueOfBytes([]byte(`43.72`)), + wantErr: false, + wantOutput: `43.72`, + }, + "supported type - valid JSON boolean": { + value: protoreflect.ValueOfBytes([]byte(`true`)), + wantErr: false, + wantOutput: `true`, + }, + "supported type - valid JSON null": { + value: protoreflect.ValueOfBytes([]byte(`null`)), + wantErr: false, + wantOutput: `null`, + }, + "supported type - valid JSON string": { + value: protoreflect.ValueOfBytes([]byte(`"hey yo"`)), + wantErr: false, + wantOutput: `"hey yo"`, + }, + "supported type - invalid JSON": { + value: protoreflect.ValueOfBytes([]byte(`foo`)), + wantErr: true, + }, + "supported type - invalid JSON (empty)": { + value: protoreflect.ValueOfBytes([]byte(``)), + wantErr: true, + }, + "supported type - invalid JSON (nil bytes)": { + value: protoreflect.ValueOfBytes(nil), + wantErr: true, }, "unsupported type - bool": { value: protoreflect.ValueOfBool(true), @@ -38,7 +81,7 @@ func TestCosmosBytesAsString(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { var buf bytes.Buffer - err := cosmosBytesAsString(nil, tc.value, &buf) + err := cosmosInlineJSON(nil, tc.value, &buf) if tc.wantErr { require.Error(t, err) diff --git a/x/tx/signing/aminojson/internal/testpb/test.proto b/x/tx/signing/aminojson/internal/testpb/test.proto index 8be5a3dc1362..0bbb999426e6 100644 --- a/x/tx/signing/aminojson/internal/testpb/test.proto +++ b/x/tx/signing/aminojson/internal/testpb/test.proto @@ -20,6 +20,10 @@ message WithAList { repeated string list = 2; } +message WithAJson { + bytes field1 = 1 [(amino.encoding) = "inline_json"]; +} + message ABitOfEverything { option (amino.name) = "ABitOfEverything"; diff --git a/x/tx/signing/aminojson/internal/testpb/test.pulsar.go b/x/tx/signing/aminojson/internal/testpb/test.pulsar.go index 7cc06a47766e..0adf0b573d60 100644 --- a/x/tx/signing/aminojson/internal/testpb/test.pulsar.go +++ b/x/tx/signing/aminojson/internal/testpb/test.pulsar.go @@ -1286,6 +1286,428 @@ func (x *fastReflection_WithAList) ProtoMethods() *protoiface.Methods { } } +var ( + md_WithAJson protoreflect.MessageDescriptor + fd_WithAJson_field1 protoreflect.FieldDescriptor +) + +func init() { + file_testpb_test_proto_init() + md_WithAJson = File_testpb_test_proto.Messages().ByName("WithAJson") + fd_WithAJson_field1 = md_WithAJson.Fields().ByName("field1") +} + +var _ protoreflect.Message = (*fastReflection_WithAJson)(nil) + +type fastReflection_WithAJson WithAJson + +func (x *WithAJson) ProtoReflect() protoreflect.Message { + return (*fastReflection_WithAJson)(x) +} + +func (x *WithAJson) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_test_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_WithAJson_messageType fastReflection_WithAJson_messageType +var _ protoreflect.MessageType = fastReflection_WithAJson_messageType{} + +type fastReflection_WithAJson_messageType struct{} + +func (x fastReflection_WithAJson_messageType) Zero() protoreflect.Message { + return (*fastReflection_WithAJson)(nil) +} +func (x fastReflection_WithAJson_messageType) New() protoreflect.Message { + return new(fastReflection_WithAJson) +} +func (x fastReflection_WithAJson_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_WithAJson +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_WithAJson) Descriptor() protoreflect.MessageDescriptor { + return md_WithAJson +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_WithAJson) Type() protoreflect.MessageType { + return _fastReflection_WithAJson_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_WithAJson) New() protoreflect.Message { + return new(fastReflection_WithAJson) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_WithAJson) Interface() protoreflect.ProtoMessage { + return (*WithAJson)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_WithAJson) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if len(x.Field1) != 0 { + value := protoreflect.ValueOfBytes(x.Field1) + if !f(fd_WithAJson_field1, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_WithAJson) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.WithAJson.field1": + return len(x.Field1) != 0 + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAJson")) + } + panic(fmt.Errorf("message testpb.WithAJson does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_WithAJson) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.WithAJson.field1": + x.Field1 = nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAJson")) + } + panic(fmt.Errorf("message testpb.WithAJson does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_WithAJson) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.WithAJson.field1": + value := x.Field1 + return protoreflect.ValueOfBytes(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAJson")) + } + panic(fmt.Errorf("message testpb.WithAJson does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_WithAJson) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.WithAJson.field1": + x.Field1 = value.Bytes() + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAJson")) + } + panic(fmt.Errorf("message testpb.WithAJson does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_WithAJson) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.WithAJson.field1": + panic(fmt.Errorf("field field1 of message testpb.WithAJson is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAJson")) + } + panic(fmt.Errorf("message testpb.WithAJson does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_WithAJson) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.WithAJson.field1": + return protoreflect.ValueOfBytes(nil) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAJson")) + } + panic(fmt.Errorf("message testpb.WithAJson does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_WithAJson) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.WithAJson", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_WithAJson) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_WithAJson) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_WithAJson) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_WithAJson) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*WithAJson) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + l = len(x.Field1) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*WithAJson) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if len(x.Field1) > 0 { + i -= len(x.Field1) + copy(dAtA[i:], x.Field1) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Field1))) + i-- + dAtA[i] = 0xa + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*WithAJson) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + 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++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: WithAJson: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: WithAJson: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Field1", wireType) + } + var byteLen int + 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++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Field1 = append(x.Field1[:0], dAtA[iNdEx:postIndex]...) + if x.Field1 == nil { + x.Field1 = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + var _ protoreflect.List = (*_ABitOfEverything_6_list)(nil) type _ABitOfEverything_6_list struct { @@ -1382,7 +1804,7 @@ func (x *ABitOfEverything) ProtoReflect() protoreflect.Message { } func (x *ABitOfEverything) slowProtoReflect() protoreflect.Message { - mi := &file_testpb_test_proto_msgTypes[2] + mi := &file_testpb_test_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2616,7 +3038,7 @@ func (x *Duration) ProtoReflect() protoreflect.Message { } func (x *Duration) slowProtoReflect() protoreflect.Message { - mi := &file_testpb_test_proto_msgTypes[3] + mi := &file_testpb_test_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3130,7 +3552,7 @@ func (x *NestedMessage) ProtoReflect() protoreflect.Message { } func (x *NestedMessage) slowProtoReflect() protoreflect.Message { - mi := &file_testpb_test_proto_msgTypes[4] + mi := &file_testpb_test_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3716,6 +4138,41 @@ func (x *WithAList) GetList() []string { return nil } +type WithAJson struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Field1 []byte `protobuf:"bytes,1,opt,name=field1,proto3" json:"field1,omitempty"` +} + +func (x *WithAJson) Reset() { + *x = WithAJson{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_test_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *WithAJson) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*WithAJson) ProtoMessage() {} + +// Deprecated: Use WithAJson.ProtoReflect.Descriptor instead. +func (*WithAJson) Descriptor() ([]byte, []int) { + return file_testpb_test_proto_rawDescGZIP(), []int{2} +} + +func (x *WithAJson) GetField1() []byte { + if x != nil { + return x.Field1 + } + return nil +} + type ABitOfEverything struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -3742,7 +4199,7 @@ type ABitOfEverything struct { func (x *ABitOfEverything) Reset() { *x = ABitOfEverything{} if protoimpl.UnsafeEnabled { - mi := &file_testpb_test_proto_msgTypes[2] + mi := &file_testpb_test_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3756,7 +4213,7 @@ func (*ABitOfEverything) ProtoMessage() {} // Deprecated: Use ABitOfEverything.ProtoReflect.Descriptor instead. func (*ABitOfEverything) Descriptor() ([]byte, []int) { - return file_testpb_test_proto_rawDescGZIP(), []int{2} + return file_testpb_test_proto_rawDescGZIP(), []int{3} } func (x *ABitOfEverything) GetMessage() *NestedMessage { @@ -3883,7 +4340,7 @@ type Duration struct { func (x *Duration) Reset() { *x = Duration{} if protoimpl.UnsafeEnabled { - mi := &file_testpb_test_proto_msgTypes[3] + mi := &file_testpb_test_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3897,7 +4354,7 @@ func (*Duration) ProtoMessage() {} // Deprecated: Use Duration.ProtoReflect.Descriptor instead. func (*Duration) Descriptor() ([]byte, []int) { - return file_testpb_test_proto_rawDescGZIP(), []int{3} + return file_testpb_test_proto_rawDescGZIP(), []int{4} } func (x *Duration) GetDuration() *durationpb.Duration { @@ -3926,7 +4383,7 @@ type NestedMessage struct { func (x *NestedMessage) Reset() { *x = NestedMessage{} if protoimpl.UnsafeEnabled { - mi := &file_testpb_test_proto_msgTypes[4] + mi := &file_testpb_test_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3940,7 +4397,7 @@ func (*NestedMessage) ProtoMessage() {} // Deprecated: Use NestedMessage.ProtoReflect.Descriptor instead. func (*NestedMessage) Descriptor() ([]byte, []int) { - return file_testpb_test_proto_rawDescGZIP(), []int{4} + return file_testpb_test_proto_rawDescGZIP(), []int{5} } func (x *NestedMessage) GetFoo() string { @@ -3989,57 +4446,60 @@ var file_testpb_test_proto_rawDesc = []byte{ 0x6d, 0x70, 0x74, 0x79, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x42, 0x05, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, 0x52, 0x11, 0x64, 0x6f, 0x6e, 0x74, 0x4f, 0x6d, 0x69, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x69, 0x73, - 0x74, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x22, 0x92, 0x03, - 0x0a, 0x10, 0x41, 0x42, 0x69, 0x74, 0x4f, 0x66, 0x45, 0x76, 0x65, 0x72, 0x79, 0x74, 0x68, 0x69, - 0x6e, 0x67, 0x12, 0x2f, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4e, 0x65, 0x73, - 0x74, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, - 0x61, 0x67, 0x65, 0x12, 0x22, 0x0a, 0x04, 0x65, 0x6e, 0x75, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0e, 0x32, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x6e, 0x45, 0x6e, 0x75, - 0x6d, 0x52, 0x04, 0x65, 0x6e, 0x75, 0x6d, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x70, 0x65, 0x61, - 0x74, 0x65, 0x64, 0x18, 0x06, 0x20, 0x03, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x70, 0x65, 0x61, - 0x74, 0x65, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x74, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x03, 0x73, 0x74, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x6f, 0x6c, 0x18, 0x08, 0x20, - 0x01, 0x28, 0x08, 0x52, 0x04, 0x62, 0x6f, 0x6f, 0x6c, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x79, 0x74, - 0x65, 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x12, - 0x10, 0x0a, 0x03, 0x69, 0x33, 0x32, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x69, 0x33, - 0x32, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x33, 0x32, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x07, 0x52, 0x03, - 0x66, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x33, 0x32, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0d, - 0x52, 0x03, 0x75, 0x33, 0x32, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x33, 0x32, 0x18, 0x0d, 0x20, - 0x01, 0x28, 0x11, 0x52, 0x04, 0x73, 0x69, 0x33, 0x32, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x66, 0x33, - 0x32, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x0f, 0x52, 0x04, 0x73, 0x66, 0x33, 0x32, 0x12, 0x10, 0x0a, - 0x03, 0x69, 0x36, 0x34, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x69, 0x36, 0x34, 0x12, - 0x10, 0x0a, 0x03, 0x66, 0x36, 0x34, 0x18, 0x10, 0x20, 0x01, 0x28, 0x06, 0x52, 0x03, 0x66, 0x36, - 0x34, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x36, 0x34, 0x18, 0x11, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, - 0x75, 0x36, 0x34, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x36, 0x34, 0x18, 0x12, 0x20, 0x01, 0x28, - 0x12, 0x52, 0x04, 0x73, 0x69, 0x36, 0x34, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x66, 0x36, 0x34, 0x18, - 0x13, 0x20, 0x01, 0x28, 0x10, 0x52, 0x04, 0x73, 0x66, 0x36, 0x34, 0x3a, 0x15, 0x8a, 0xe7, 0xb0, - 0x2a, 0x10, 0x41, 0x42, 0x69, 0x74, 0x4f, 0x66, 0x45, 0x76, 0x65, 0x72, 0x79, 0x74, 0x68, 0x69, - 0x6e, 0x67, 0x22, 0x7b, 0x0a, 0x08, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x35, - 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, - 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x08, 0x64, 0x75, 0x72, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x38, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, - 0x6d, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, - 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, - 0x47, 0x0a, 0x0d, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x12, 0x10, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x66, - 0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, - 0x03, 0x62, 0x61, 0x72, 0x3a, 0x12, 0x8a, 0xe7, 0xb0, 0x2a, 0x0d, 0x4e, 0x65, 0x73, 0x74, 0x65, - 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2a, 0x29, 0x0a, 0x06, 0x41, 0x6e, 0x45, 0x6e, - 0x75, 0x6d, 0x12, 0x0d, 0x0a, 0x09, 0x55, 0x4e, 0x44, 0x45, 0x46, 0x49, 0x4e, 0x45, 0x44, 0x10, - 0x00, 0x12, 0x07, 0x0a, 0x03, 0x4f, 0x4e, 0x45, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x54, 0x57, - 0x4f, 0x10, 0x02, 0x42, 0x83, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, - 0x70, 0x62, 0x42, 0x09, 0x54, 0x65, 0x73, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, - 0x32, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x78, 0x2f, - 0x74, 0x78, 0x2f, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x6a, 0x73, 0x6f, 0x6e, 0x2f, 0x69, 0x6e, 0x74, - 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x74, 0x65, 0x73, - 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, - 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, - 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, - 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x74, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x22, 0x35, 0x0a, + 0x09, 0x57, 0x69, 0x74, 0x68, 0x41, 0x4a, 0x73, 0x6f, 0x6e, 0x12, 0x28, 0x0a, 0x06, 0x66, 0x69, + 0x65, 0x6c, 0x64, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x10, 0x9a, 0xe7, 0xb0, 0x2a, + 0x0b, 0x69, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x5f, 0x6a, 0x73, 0x6f, 0x6e, 0x52, 0x06, 0x66, 0x69, + 0x65, 0x6c, 0x64, 0x31, 0x22, 0x92, 0x03, 0x0a, 0x10, 0x41, 0x42, 0x69, 0x74, 0x4f, 0x66, 0x45, + 0x76, 0x65, 0x72, 0x79, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x12, 0x2f, 0x0a, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x74, 0x65, 0x73, + 0x74, 0x70, 0x62, 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x22, 0x0a, 0x04, 0x65, 0x6e, + 0x75, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, + 0x62, 0x2e, 0x41, 0x6e, 0x45, 0x6e, 0x75, 0x6d, 0x52, 0x04, 0x65, 0x6e, 0x75, 0x6d, 0x12, 0x1a, + 0x0a, 0x08, 0x72, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x06, 0x20, 0x03, 0x28, 0x05, + 0x52, 0x08, 0x72, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x74, + 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x74, 0x72, 0x12, 0x12, 0x0a, 0x04, + 0x62, 0x6f, 0x6f, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x62, 0x6f, 0x6f, 0x6c, + 0x12, 0x14, 0x0a, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x33, 0x32, 0x18, 0x0a, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x03, 0x69, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x33, 0x32, 0x18, + 0x0b, 0x20, 0x01, 0x28, 0x07, 0x52, 0x03, 0x66, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x33, + 0x32, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x75, 0x33, 0x32, 0x12, 0x12, 0x0a, 0x04, + 0x73, 0x69, 0x33, 0x32, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x11, 0x52, 0x04, 0x73, 0x69, 0x33, 0x32, + 0x12, 0x12, 0x0a, 0x04, 0x73, 0x66, 0x33, 0x32, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x0f, 0x52, 0x04, + 0x73, 0x66, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x36, 0x34, 0x18, 0x0f, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x03, 0x69, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x36, 0x34, 0x18, 0x10, 0x20, + 0x01, 0x28, 0x06, 0x52, 0x03, 0x66, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x36, 0x34, 0x18, + 0x11, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x75, 0x36, 0x34, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, + 0x36, 0x34, 0x18, 0x12, 0x20, 0x01, 0x28, 0x12, 0x52, 0x04, 0x73, 0x69, 0x36, 0x34, 0x12, 0x12, + 0x0a, 0x04, 0x73, 0x66, 0x36, 0x34, 0x18, 0x13, 0x20, 0x01, 0x28, 0x10, 0x52, 0x04, 0x73, 0x66, + 0x36, 0x34, 0x3a, 0x15, 0x8a, 0xe7, 0xb0, 0x2a, 0x10, 0x41, 0x42, 0x69, 0x74, 0x4f, 0x66, 0x45, + 0x76, 0x65, 0x72, 0x79, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x22, 0x7b, 0x0a, 0x08, 0x44, 0x75, 0x72, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x35, 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x38, 0x0a, 0x09, + 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d, + 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x47, 0x0a, 0x0d, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x62, 0x61, 0x72, 0x3a, 0x12, 0x8a, 0xe7, 0xb0, + 0x2a, 0x0d, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2a, + 0x29, 0x0a, 0x06, 0x41, 0x6e, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x0d, 0x0a, 0x09, 0x55, 0x4e, 0x44, + 0x45, 0x46, 0x49, 0x4e, 0x45, 0x44, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x4f, 0x4e, 0x45, 0x10, + 0x01, 0x12, 0x07, 0x0a, 0x03, 0x54, 0x57, 0x4f, 0x10, 0x02, 0x42, 0x83, 0x01, 0x0a, 0x0a, 0x63, + 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x09, 0x54, 0x65, 0x73, 0x74, 0x50, + 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x32, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, + 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x78, 0x2f, 0x74, 0x78, 0x2f, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x6a, + 0x73, 0x6f, 0x6e, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, + 0x74, 0x70, 0x62, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, + 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, + 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, + 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -4055,24 +4515,25 @@ func file_testpb_test_proto_rawDescGZIP() []byte { } var file_testpb_test_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_testpb_test_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_testpb_test_proto_msgTypes = make([]protoimpl.MessageInfo, 7) var file_testpb_test_proto_goTypes = []interface{}{ (AnEnum)(0), // 0: testpb.AnEnum (*WithAMap)(nil), // 1: testpb.WithAMap (*WithAList)(nil), // 2: testpb.WithAList - (*ABitOfEverything)(nil), // 3: testpb.ABitOfEverything - (*Duration)(nil), // 4: testpb.Duration - (*NestedMessage)(nil), // 5: testpb.NestedMessage - nil, // 6: testpb.WithAMap.StrMapEntry - (*durationpb.Duration)(nil), // 7: google.protobuf.Duration - (*timestamppb.Timestamp)(nil), // 8: google.protobuf.Timestamp + (*WithAJson)(nil), // 3: testpb.WithAJson + (*ABitOfEverything)(nil), // 4: testpb.ABitOfEverything + (*Duration)(nil), // 5: testpb.Duration + (*NestedMessage)(nil), // 6: testpb.NestedMessage + nil, // 7: testpb.WithAMap.StrMapEntry + (*durationpb.Duration)(nil), // 8: google.protobuf.Duration + (*timestamppb.Timestamp)(nil), // 9: google.protobuf.Timestamp } var file_testpb_test_proto_depIdxs = []int32{ - 6, // 0: testpb.WithAMap.str_map:type_name -> testpb.WithAMap.StrMapEntry - 5, // 1: testpb.ABitOfEverything.message:type_name -> testpb.NestedMessage + 7, // 0: testpb.WithAMap.str_map:type_name -> testpb.WithAMap.StrMapEntry + 6, // 1: testpb.ABitOfEverything.message:type_name -> testpb.NestedMessage 0, // 2: testpb.ABitOfEverything.enum:type_name -> testpb.AnEnum - 7, // 3: testpb.Duration.duration:type_name -> google.protobuf.Duration - 8, // 4: testpb.Duration.timestamp:type_name -> google.protobuf.Timestamp + 8, // 3: testpb.Duration.duration:type_name -> google.protobuf.Duration + 9, // 4: testpb.Duration.timestamp:type_name -> google.protobuf.Timestamp 5, // [5:5] is the sub-list for method output_type 5, // [5:5] is the sub-list for method input_type 5, // [5:5] is the sub-list for extension type_name @@ -4111,7 +4572,7 @@ func file_testpb_test_proto_init() { } } file_testpb_test_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ABitOfEverything); i { + switch v := v.(*WithAJson); i { case 0: return &v.state case 1: @@ -4123,7 +4584,7 @@ func file_testpb_test_proto_init() { } } file_testpb_test_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Duration); i { + switch v := v.(*ABitOfEverything); i { case 0: return &v.state case 1: @@ -4135,6 +4596,18 @@ func file_testpb_test_proto_init() { } } file_testpb_test_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Duration); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_testpb_test_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*NestedMessage); i { case 0: return &v.state @@ -4153,7 +4626,7 @@ func file_testpb_test_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_testpb_test_proto_rawDesc, NumEnums: 1, - NumMessages: 6, + NumMessages: 7, NumExtensions: 0, NumServices: 0, }, diff --git a/x/tx/signing/aminojson/json_marshal.go b/x/tx/signing/aminojson/json_marshal.go index cdbb9aa2ac21..f276cb39d23e 100644 --- a/x/tx/signing/aminojson/json_marshal.go +++ b/x/tx/signing/aminojson/json_marshal.go @@ -72,8 +72,8 @@ func NewEncoder(options EncoderOptions) Encoder { "threshold_string": thresholdStringEncoder, }, aminoFieldEncoders: map[string]FieldEncoder{ - "legacy_coins": nullSliceAsEmptyEncoder, - "bytes_as_string": cosmosBytesAsString, + "legacy_coins": nullSliceAsEmptyEncoder, + "inline_json": cosmosInlineJSON, }, protoTypeEncoders: map[string]MessageEncoder{ "google.protobuf.Timestamp": marshalTimestamp, diff --git a/x/tx/signing/aminojson/json_marshal_test.go b/x/tx/signing/aminojson/json_marshal_test.go index be8caf8c7364..a51b83bb49da 100644 --- a/x/tx/signing/aminojson/json_marshal_test.go +++ b/x/tx/signing/aminojson/json_marshal_test.go @@ -210,6 +210,34 @@ func TestMarshalDuration(t *testing.T) { require.Equal(t, `{"duration":"1s"}`, string(bz)) } +func TestWithAJson(t *testing.T) { + encoder := aminojson.NewEncoder(aminojson.EncoderOptions{}) + + // list + msg := &testpb.WithAJson{ + Field1: []byte(`[{"name":"child1"}]`), + } + bz, err := encoder.Marshal(msg) + require.NoError(t, err) + require.Equal(t, `{"field1":[{"name":"child1"}]}`, string(bz)) + + // string + msg = &testpb.WithAJson{ + Field1: []byte(`"hello again"`), + } + bz, err = encoder.Marshal(msg) + require.NoError(t, err) + require.Equal(t, `{"field1":"hello again"}`, string(bz)) + + // object + msg = &testpb.WithAJson{ + Field1: []byte(`{"deeper":{"nesting":1}}`), + } + bz, err = encoder.Marshal(msg) + require.NoError(t, err) + require.Equal(t, `{"field1":{"deeper":{"nesting":1}}}`, string(bz)) +} + func TestIndent(t *testing.T) { encoder := aminojson.NewEncoder(aminojson.EncoderOptions{Indent: " "}) diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index d5dc93579345..85ba84072ce4 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -181,7 +181,7 @@ require ( golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/oauth2 v0.18.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/x/upgrade/go.sum b/x/upgrade/go.sum index a11d41e9b69b..7c53bbeb3ea9 100644 --- a/x/upgrade/go.sum +++ b/x/upgrade/go.sum @@ -1220,8 +1220,8 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/x/upgrade/keeper/abci.go b/x/upgrade/keeper/abci.go index 6ef39c8062b0..bd2844dcbf23 100644 --- a/x/upgrade/keeper/abci.go +++ b/x/upgrade/keeper/abci.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "time" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/upgrade/types" @@ -22,7 +21,7 @@ import ( // a migration to be executed if needed upon this switch (migration defined in the new binary) // skipUpgradeHeightArray is a set of block heights for which the upgrade must be skipped func (k Keeper) PreBlocker(ctx context.Context) error { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) blockHeight := k.environment.HeaderService.GetHeaderInfo(ctx).Height plan, err := k.GetUpgradePlan(ctx)