From f272fc82ddfde21a0eb49f18979d0f3b7d704ed6 Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Tue, 31 May 2022 14:04:25 -0600 Subject: [PATCH 01/22] feat: migrate x/staking to app wiring --- proto/cosmos/staking/module/v1/module.proto | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 proto/cosmos/staking/module/v1/module.proto diff --git a/proto/cosmos/staking/module/v1/module.proto b/proto/cosmos/staking/module/v1/module.proto new file mode 100644 index 00000000000..ead0e04319d --- /dev/null +++ b/proto/cosmos/staking/module/v1/module.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package cosmos.staking.module.v1; + +import "cosmos/app/v1alpha1/module.proto"; + +// Module is the config object of the capability module. +message Module { + option (cosmos.app.v1alpha1.module) = { + go_import: "github.com/cosmos/cosmos-sdk/x/staking" + }; +} \ No newline at end of file From 0530a1ca0d105ffa38490475a0ed2aa9905f2b19 Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Tue, 31 May 2022 15:11:23 -0600 Subject: [PATCH 02/22] add staking to app yaml --- simapp/app.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/simapp/app.yaml b/simapp/app.yaml index 504f9db776a..0b5baaa3694 100644 --- a/simapp/app.yaml +++ b/simapp/app.yaml @@ -46,3 +46,7 @@ modules: - name: params config: "@type": cosmos.params.module.v1.Module + + - name: staking + config: + "@type": cosmos.staking.module.v1.Module From 15446da8d27555d8158ed0d533aa545a51312ac0 Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Tue, 31 May 2022 16:07:18 -0600 Subject: [PATCH 03/22] modified staking module --- x/staking/module.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/x/staking/module.go b/x/staking/module.go index 93b41daef60..081129afbed 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -4,9 +4,14 @@ import ( "context" "encoding/json" "fmt" + "github.com/cosmos/cosmos-sdk/runtime" + store "github.com/cosmos/cosmos-sdk/store/types" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "math/rand" - "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -71,7 +76,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod } // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the staking module. -func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) { if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { panic(err) } @@ -172,6 +177,27 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val return EndBlocker(ctx, am.keeper) } +func init() { + //appmodule.Register(&modulev1.Module{}, appmodule.Provide(provideModuleBasic, provideModule)) +} + +func provideModuleBasic() runtime.AppModuleBasicWrapper { + return runtime.WrapAppModuleBasic(AppModuleBasic{}) +} + +func provideModule( + kvStoreKey *store.KVStoreKey, + ak authkeeper.AccountKeeper, + bk bankkeeper.Keeper, + cdc codec.Codec, + paramsKeeper paramskeeper.Keeper, +) (keeper.Keeper, runtime.AppModuleWrapper) { + + k := keeper.NewKeeper(cdc, kvStoreKey, ak, bk, paramsKeeper.Subspace(types.ModuleName)) + m := NewAppModule(cdc, k, ak, bk) + return k, runtime.WrapAppModule(m) +} + // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the staking module. From 12d1ec424871d5ff31bd18fb89ef835971fddc5e Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Tue, 31 May 2022 16:35:49 -0600 Subject: [PATCH 04/22] partial simapp changes --- simapp/app.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 46a641b30f8..10ed96ffb04 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -210,6 +210,7 @@ func NewSimApp( ) *SimApp { var appBuilder *runtime.AppBuilder var paramsKeeper paramskeeper.Keeper + var stakingKeeper stakingkeeper.Keeper var accountKeeper authkeeper.AccountKeeper var appCodec codec.Codec var legacyAmino *codec.LegacyAmino @@ -217,6 +218,7 @@ func NewSimApp( err := depinject.Inject(appConfig, &appBuilder, ¶msKeeper, + &stakingKeeper, &appCodec, &legacyAmino, &interfaceRegistry, @@ -229,7 +231,7 @@ func NewSimApp( runtimeApp := appBuilder.Build(logger, db, traceStore, baseAppOptions...) keys := sdk.NewKVStoreKeys( - banktypes.StoreKey, stakingtypes.StoreKey, + banktypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, capabilitytypes.StoreKey, @@ -269,9 +271,9 @@ func NewSimApp( app.BankKeeper = bankkeeper.NewBaseKeeper( appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(), ) - stakingKeeper := stakingkeeper.NewKeeper( - appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), - ) + //stakingKeeper := stakingkeeper.NewKeeper( + // appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), + //) app.MintKeeper = mintkeeper.NewKeeper( appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper, app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, @@ -359,7 +361,6 @@ func NewSimApp( mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), upgrade.NewAppModule(app.UpgradeKeeper), evidence.NewAppModule(app.EvidenceKeeper), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), @@ -408,7 +409,6 @@ func NewSimApp( feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil), - staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), params.NewAppModule(app.ParamsKeeper), @@ -607,7 +607,6 @@ func GetMaccPerms() map[string][]string { // initParamsKeeper init params keeper and its subspaces func initParamsKeeper(paramsKeeper paramskeeper.Keeper) { paramsKeeper.Subspace(banktypes.ModuleName) - paramsKeeper.Subspace(stakingtypes.ModuleName) paramsKeeper.Subspace(minttypes.ModuleName) paramsKeeper.Subspace(distrtypes.ModuleName) paramsKeeper.Subspace(slashingtypes.ModuleName) From ebeb7c5dbedd6cfb5007476d2fa29dc21f8db2b8 Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Tue, 31 May 2022 17:34:21 -0600 Subject: [PATCH 05/22] generated pulsar --- api/cosmos/staking/module/v1/module.pulsar.go | 503 ++++++++++++++++++ 1 file changed, 503 insertions(+) create mode 100644 api/cosmos/staking/module/v1/module.pulsar.go diff --git a/api/cosmos/staking/module/v1/module.pulsar.go b/api/cosmos/staking/module/v1/module.pulsar.go new file mode 100644 index 00000000000..8446098f49c --- /dev/null +++ b/api/cosmos/staking/module/v1/module.pulsar.go @@ -0,0 +1,503 @@ +// Code generated by protoc-gen-go-pulsar. DO NOT EDIT. +package modulev1 + +import ( + _ "cosmossdk.io/api/cosmos/app/v1alpha1" + fmt "fmt" + runtime "github.com/cosmos/cosmos-proto/runtime" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoiface "google.golang.org/protobuf/runtime/protoiface" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + reflect "reflect" + sync "sync" +) + +var ( + md_Module protoreflect.MessageDescriptor +) + +func init() { + file_cosmos_staking_module_v1_module_proto_init() + md_Module = File_cosmos_staking_module_v1_module_proto.Messages().ByName("Module") +} + +var _ protoreflect.Message = (*fastReflection_Module)(nil) + +type fastReflection_Module Module + +func (x *Module) ProtoReflect() protoreflect.Message { + return (*fastReflection_Module)(x) +} + +func (x *Module) slowProtoReflect() protoreflect.Message { + mi := &file_cosmos_staking_module_v1_module_proto_msgTypes[0] + 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_Module_messageType fastReflection_Module_messageType +var _ protoreflect.MessageType = fastReflection_Module_messageType{} + +type fastReflection_Module_messageType struct{} + +func (x fastReflection_Module_messageType) Zero() protoreflect.Message { + return (*fastReflection_Module)(nil) +} +func (x fastReflection_Module_messageType) New() protoreflect.Message { + return new(fastReflection_Module) +} +func (x fastReflection_Module_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_Module +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_Module) Descriptor() protoreflect.MessageDescriptor { + return md_Module +} + +// 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_Module) Type() protoreflect.MessageType { + return _fastReflection_Module_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_Module) New() protoreflect.Message { + return new(fastReflection_Module) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_Module) Interface() protoreflect.ProtoMessage { + return (*Module)(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_Module) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { +} + +// 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_Module) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.staking.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.staking.module.v1.Module 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_Module) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.staking.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.staking.module.v1.Module 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_Module) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.staking.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.staking.module.v1.Module 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_Module) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.staking.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.staking.module.v1.Module 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_Module) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.staking.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.staking.module.v1.Module 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_Module) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.staking.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.staking.module.v1.Module 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_Module) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in cosmos.staking.module.v1.Module", 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_Module) 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_Module) 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_Module) 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_Module) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*Module) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = 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().(*Module) + 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 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().(*Module) + 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: Module: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: Module: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + 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, + } +} + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.0 +// protoc (unknown) +// source: cosmos/staking/module/v1/module.proto + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// Module is the config object of the capability module. +type Module struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *Module) Reset() { + *x = Module{} + if protoimpl.UnsafeEnabled { + mi := &file_cosmos_staking_module_v1_module_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Module) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Module) ProtoMessage() {} + +// Deprecated: Use Module.ProtoReflect.Descriptor instead. +func (*Module) Descriptor() ([]byte, []int) { + return file_cosmos_staking_module_v1_module_proto_rawDescGZIP(), []int{0} +} + +var File_cosmos_staking_module_v1_module_proto protoreflect.FileDescriptor + +var file_cosmos_staking_module_v1_module_proto_rawDesc = []byte{ + 0x0a, 0x25, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x73, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x18, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, + 0x73, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67, 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, 0x38, 0x0a, 0x06, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x2e, 0xba, + 0xc0, 0x96, 0xda, 0x01, 0x28, 0x0a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, + 0x73, 0x64, 0x6b, 0x2f, 0x78, 0x2f, 0x73, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x42, 0xe2, 0x01, + 0x0a, 0x1c, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x73, 0x74, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 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, 0x32, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x73, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x6d, + 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x76, + 0x31, 0xa2, 0x02, 0x03, 0x43, 0x53, 0x4d, 0xaa, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x2e, 0x53, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, + 0x56, 0x31, 0xca, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x53, 0x74, 0x61, 0x6b, + 0x69, 0x6e, 0x67, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x24, + 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x53, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x5c, 0x4d, + 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, + 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x1b, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x53, + 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x3a, + 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_cosmos_staking_module_v1_module_proto_rawDescOnce sync.Once + file_cosmos_staking_module_v1_module_proto_rawDescData = file_cosmos_staking_module_v1_module_proto_rawDesc +) + +func file_cosmos_staking_module_v1_module_proto_rawDescGZIP() []byte { + file_cosmos_staking_module_v1_module_proto_rawDescOnce.Do(func() { + file_cosmos_staking_module_v1_module_proto_rawDescData = protoimpl.X.CompressGZIP(file_cosmos_staking_module_v1_module_proto_rawDescData) + }) + return file_cosmos_staking_module_v1_module_proto_rawDescData +} + +var file_cosmos_staking_module_v1_module_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_cosmos_staking_module_v1_module_proto_goTypes = []interface{}{ + (*Module)(nil), // 0: cosmos.staking.module.v1.Module +} +var file_cosmos_staking_module_v1_module_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_cosmos_staking_module_v1_module_proto_init() } +func file_cosmos_staking_module_v1_module_proto_init() { + if File_cosmos_staking_module_v1_module_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_cosmos_staking_module_v1_module_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Module); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_cosmos_staking_module_v1_module_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_cosmos_staking_module_v1_module_proto_goTypes, + DependencyIndexes: file_cosmos_staking_module_v1_module_proto_depIdxs, + MessageInfos: file_cosmos_staking_module_v1_module_proto_msgTypes, + }.Build() + File_cosmos_staking_module_v1_module_proto = out.File + file_cosmos_staking_module_v1_module_proto_rawDesc = nil + file_cosmos_staking_module_v1_module_proto_goTypes = nil + file_cosmos_staking_module_v1_module_proto_depIdxs = nil +} From fbbbd46326caa4b4e88f915ce9c00e834eba1fba Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Thu, 2 Jun 2022 01:19:54 -0600 Subject: [PATCH 06/22] pre merge --- simapp/app.go | 6 +++--- x/staking/module.go | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 10ed96ffb04..93d0e17ed1a 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -271,9 +271,7 @@ func NewSimApp( app.BankKeeper = bankkeeper.NewBaseKeeper( appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(), ) - //stakingKeeper := stakingkeeper.NewKeeper( - // appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), - //) + app.MintKeeper = mintkeeper.NewKeeper( appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper, app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, @@ -296,6 +294,7 @@ func NewSimApp( app.StakingKeeper = *stakingKeeper.SetHooks( stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), ) + initStak app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper) @@ -612,4 +611,5 @@ func initParamsKeeper(paramsKeeper paramskeeper.Keeper) { paramsKeeper.Subspace(slashingtypes.ModuleName) paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) paramsKeeper.Subspace(crisistypes.ModuleName) + paramsKeeper.Subspace(stakingtypes.ModuleName) } diff --git a/x/staking/module.go b/x/staking/module.go index 081129afbed..3bb7fbd65b9 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -2,13 +2,15 @@ package staking import ( "context" + modulev1 "cosmossdk.io/api/cosmos/staking/module/v1" + "cosmossdk.io/core/appmodule" "encoding/json" "fmt" "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "math/rand" @@ -178,7 +180,7 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val } func init() { - //appmodule.Register(&modulev1.Module{}, appmodule.Provide(provideModuleBasic, provideModule)) + appmodule.Register(&modulev1.Module{}, appmodule.Provide(provideModuleBasic, provideModule)) } func provideModuleBasic() runtime.AppModuleBasicWrapper { @@ -190,10 +192,9 @@ func provideModule( ak authkeeper.AccountKeeper, bk bankkeeper.Keeper, cdc codec.Codec, - paramsKeeper paramskeeper.Keeper, + subSpace paramstypes.Subspace, ) (keeper.Keeper, runtime.AppModuleWrapper) { - - k := keeper.NewKeeper(cdc, kvStoreKey, ak, bk, paramsKeeper.Subspace(types.ModuleName)) + k := keeper.NewKeeper(cdc, kvStoreKey, ak, bk, subSpace) m := NewAppModule(cdc, k, ak, bk) return k, runtime.WrapAppModule(m) } From 6046ac516f7257a7586903fa6977a5c3d0f1a592 Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Thu, 2 Jun 2022 01:39:57 -0600 Subject: [PATCH 07/22] simapp app --- simapp/app.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index b0281164aa1..00c750ef581 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -212,6 +212,7 @@ func NewSimApp( var paramsKeeper paramskeeper.Keeper var accountKeeper authkeeper.AccountKeeper var bankKeeper bankkeeper.Keeper + var stakingKeeper stakingkeeper.Keeper var appCodec codec.Codec var legacyAmino *codec.LegacyAmino var interfaceRegistry codectypes.InterfaceRegistry @@ -223,6 +224,7 @@ func NewSimApp( &interfaceRegistry, &accountKeeper, &bankKeeper, + &stakingKeeper, ) if err != nil { panic(err) @@ -231,7 +233,6 @@ func NewSimApp( runtimeApp := appBuilder.Build(logger, db, traceStore, baseAppOptions...) keys := sdk.NewKVStoreKeys( - stakingtypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, capabilitytypes.StoreKey, @@ -270,9 +271,6 @@ func NewSimApp( // add keepers app.BankKeeper = bankKeeper - stakingKeeper := stakingkeeper.NewKeeper( - appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), - ) app.MintKeeper = mintkeeper.NewKeeper( appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper, app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, @@ -323,7 +321,7 @@ func NewSimApp( app.GovKeeper = *govKeeper.SetHooks( govtypes.NewMultiGovHooks( - // register the governance hooks + // register the governance hooks ), ) // set the governance module account as the authority for conducting upgrades @@ -359,7 +357,6 @@ func NewSimApp( mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), upgrade.NewAppModule(app.UpgradeKeeper), evidence.NewAppModule(app.EvidenceKeeper), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), @@ -596,7 +593,6 @@ func GetMaccPerms() map[string][]string { // initParamsKeeper init params keeper and its subspaces func initParamsKeeper(paramsKeeper paramskeeper.Keeper) { - paramsKeeper.Subspace(stakingtypes.ModuleName) paramsKeeper.Subspace(minttypes.ModuleName) paramsKeeper.Subspace(distrtypes.ModuleName) paramsKeeper.Subspace(slashingtypes.ModuleName) From 39eb9a90ff186f2ff600ae9748b4cea6d4287ff2 Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Thu, 2 Jun 2022 02:32:34 -0600 Subject: [PATCH 08/22] add depinject struct for parmeters --- x/staking/module.go | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/x/staking/module.go b/x/staking/module.go index 3bb7fbd65b9..de0f48e3a68 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -6,10 +6,9 @@ import ( "cosmossdk.io/core/appmodule" "encoding/json" "fmt" + "github.com/cosmos/cosmos-sdk/depinject" "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "math/rand" @@ -180,22 +179,33 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val } func init() { - appmodule.Register(&modulev1.Module{}, appmodule.Provide(provideModuleBasic, provideModule)) + appmodule.Register( + &modulev1.Module{}, + appmodule.Provide( + provideModuleBasic, + provideModule, + ), + ) } func provideModuleBasic() runtime.AppModuleBasicWrapper { return runtime.WrapAppModuleBasic(AppModuleBasic{}) } -func provideModule( - kvStoreKey *store.KVStoreKey, - ak authkeeper.AccountKeeper, - bk bankkeeper.Keeper, - cdc codec.Codec, - subSpace paramstypes.Subspace, -) (keeper.Keeper, runtime.AppModuleWrapper) { - k := keeper.NewKeeper(cdc, kvStoreKey, ak, bk, subSpace) - m := NewAppModule(cdc, k, ak, bk) +type stakingInputs struct { + depinject.In + + Config *modulev1.Module + AccountKeeper types.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper"` + BankKeeper types.BankKeeper `key:"cosmos.auth.v1.BankKeeper"` + CDC codec.Codec + Subspace paramstypes.Subspace + Key *store.KVStoreKey +} + +func provideModule(in stakingInputs) (keeper.Keeper, runtime.AppModuleWrapper) { + k := keeper.NewKeeper(in.CDC, in.Key, in.AccountKeeper, in.BankKeeper, in.Subspace) + m := NewAppModule(in.CDC, k, in.AccountKeeper, in.BankKeeper) return k, runtime.WrapAppModule(m) } From c0eaec6981734f34d1f5ff0fb1d453d7ae81029b Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 2 Jun 2022 11:07:28 +0200 Subject: [PATCH 09/22] Add depinject key to bankKeeper --- x/bank/module.go | 14 +++++++++++--- x/staking/module.go | 9 +++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/x/bank/module.go b/x/bank/module.go index b376c289482..ee9bb5c1c43 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -2,9 +2,10 @@ package bank import ( "context" - modulev1 "cosmossdk.io/api/cosmos/bank/module/v1" "encoding/json" "fmt" + + modulev1 "cosmossdk.io/api/cosmos/bank/module/v1" "github.com/cosmos/cosmos-sdk/depinject" store "github.com/cosmos/cosmos-sdk/store/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -227,7 +228,14 @@ type bankInputs struct { Key *store.KVStoreKey } -func provideModule(in bankInputs) (keeper.Keeper, runtime.AppModuleWrapper) { +type bankOutputs struct { + depinject.Out + + BankKeeper keeper.Keeper `key:"cosmos.bank.v1.BankKeeper"` + Module runtime.AppModuleWrapper +} + +func provideModule(in bankInputs) bankOutputs { // configure blocked module accounts. // // default behavior for blockedAddresses is to regard any module mentioned in AccountKeeper's module account @@ -246,5 +254,5 @@ func provideModule(in bankInputs) (keeper.Keeper, runtime.AppModuleWrapper) { bankKeeper := keeper.NewBaseKeeper(in.Cdc, in.Key, in.AccountKeeper, in.Subspace, blockedAddresses) m := NewAppModule(in.Cdc, bankKeeper, in.AccountKeeper) - return bankKeeper, runtime.WrapAppModule(m) + return bankOutputs{BankKeeper: bankKeeper, Module: runtime.WrapAppModule(m)} } diff --git a/x/staking/module.go b/x/staking/module.go index de0f48e3a68..74ba1caa46d 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -2,16 +2,17 @@ package staking import ( "context" - modulev1 "cosmossdk.io/api/cosmos/staking/module/v1" - "cosmossdk.io/core/appmodule" "encoding/json" "fmt" + "math/rand" + + modulev1 "cosmossdk.io/api/cosmos/staking/module/v1" + "cosmossdk.io/core/appmodule" "github.com/cosmos/cosmos-sdk/depinject" "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" - "math/rand" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -197,7 +198,7 @@ type stakingInputs struct { Config *modulev1.Module AccountKeeper types.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper"` - BankKeeper types.BankKeeper `key:"cosmos.auth.v1.BankKeeper"` + BankKeeper types.BankKeeper `key:"cosmos.bank.v1.BankKeeper"` CDC codec.Codec Subspace paramstypes.Subspace Key *store.KVStoreKey From 834fd1acf367fcc9156fa3e2c68d4eefbad66856 Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Thu, 2 Jun 2022 09:51:35 -0600 Subject: [PATCH 10/22] PR changes --- x/bank/module.go | 2 +- x/staking/module.go | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/x/bank/module.go b/x/bank/module.go index ee9bb5c1c43..e8b5266f6ac 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -231,7 +231,7 @@ type bankInputs struct { type bankOutputs struct { depinject.Out - BankKeeper keeper.Keeper `key:"cosmos.bank.v1.BankKeeper"` + BankKeeper keeper.Keeper `key:"cosmos.bank.v1.Keeper"` Module runtime.AppModuleWrapper } diff --git a/x/staking/module.go b/x/staking/module.go index 74ba1caa46d..3d71402bf6c 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -198,16 +198,23 @@ type stakingInputs struct { Config *modulev1.Module AccountKeeper types.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper"` - BankKeeper types.BankKeeper `key:"cosmos.bank.v1.BankKeeper"` + BankKeeper types.BankKeeper `key:"cosmos.bank.v1.Keeper"` CDC codec.Codec Subspace paramstypes.Subspace Key *store.KVStoreKey } -func provideModule(in stakingInputs) (keeper.Keeper, runtime.AppModuleWrapper) { +type stakingOutputs struct { + depinject.Out + + StakingKeeper keeper.Keeper `key:"cosmos.staking.v1.Keeper"` + Module runtime.AppModuleWrapper +} + +func provideModule(in stakingInputs) stakingOutputs { k := keeper.NewKeeper(in.CDC, in.Key, in.AccountKeeper, in.BankKeeper, in.Subspace) m := NewAppModule(in.CDC, k, in.AccountKeeper, in.BankKeeper) - return k, runtime.WrapAppModule(m) + return stakingOutputs{StakingKeeper: k, Module: runtime.WrapAppModule(m)} } // AppModuleSimulation functions From ed83c413a51f1f1cada889a2f0bd85881d24588c Mon Sep 17 00:00:00 2001 From: Jeancarlo Barrios Date: Thu, 2 Jun 2022 10:22:23 -0600 Subject: [PATCH 11/22] Update proto/cosmos/staking/module/v1/module.proto Co-authored-by: Marie Gauthier --- proto/cosmos/staking/module/v1/module.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/cosmos/staking/module/v1/module.proto b/proto/cosmos/staking/module/v1/module.proto index ead0e04319d..bf7e1cc48eb 100644 --- a/proto/cosmos/staking/module/v1/module.proto +++ b/proto/cosmos/staking/module/v1/module.proto @@ -4,7 +4,7 @@ package cosmos.staking.module.v1; import "cosmos/app/v1alpha1/module.proto"; -// Module is the config object of the capability module. +// Module is the config object of the staking module. message Module { option (cosmos.app.v1alpha1.module) = { go_import: "github.com/cosmos/cosmos-sdk/x/staking" From 7bb92f1e8257e5752a5a2d570a471e9d292f3c27 Mon Sep 17 00:00:00 2001 From: Jeancarlo Barrios Date: Thu, 2 Jun 2022 10:29:13 -0600 Subject: [PATCH 12/22] Update x/staking/module.go Co-authored-by: Marie Gauthier --- x/staking/module.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/staking/module.go b/x/staking/module.go index 3d71402bf6c..c49f415551d 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -199,7 +199,7 @@ type stakingInputs struct { Config *modulev1.Module AccountKeeper types.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper"` BankKeeper types.BankKeeper `key:"cosmos.bank.v1.Keeper"` - CDC codec.Codec + Cdc codec.Codec Subspace paramstypes.Subspace Key *store.KVStoreKey } From 722a05e6cf9f9d435dcb0a9a486e5b57e9d09f75 Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Thu, 2 Jun 2022 10:36:21 -0600 Subject: [PATCH 13/22] PR changes --- x/staking/module.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/staking/module.go b/x/staking/module.go index c49f415551d..39265f4b5a2 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -212,8 +212,8 @@ type stakingOutputs struct { } func provideModule(in stakingInputs) stakingOutputs { - k := keeper.NewKeeper(in.CDC, in.Key, in.AccountKeeper, in.BankKeeper, in.Subspace) - m := NewAppModule(in.CDC, k, in.AccountKeeper, in.BankKeeper) + k := keeper.NewKeeper(in.Cdc, in.Key, in.AccountKeeper, in.BankKeeper, in.Subspace) + m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper) return stakingOutputs{StakingKeeper: k, Module: runtime.WrapAppModule(m)} } From 16a6a404f70fb28e520daf38bfe1b7a5b376dd1b Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Thu, 2 Jun 2022 10:59:09 -0600 Subject: [PATCH 14/22] update pulsar --- api/cosmos/staking/module/v1/module.pulsar.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/cosmos/staking/module/v1/module.pulsar.go b/api/cosmos/staking/module/v1/module.pulsar.go index 8446098f49c..f1e7eedfa0d 100644 --- a/api/cosmos/staking/module/v1/module.pulsar.go +++ b/api/cosmos/staking/module/v1/module.pulsar.go @@ -382,7 +382,7 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// Module is the config object of the capability module. +// Module is the config object of the staking module. type Module struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache From 6e8a954162d6cc3f5f6a96b2fe9bba63b6f7d310 Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Thu, 2 Jun 2022 11:31:23 -0600 Subject: [PATCH 15/22] PR changes --- x/staking/module.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/staking/module.go b/x/staking/module.go index 39265f4b5a2..a24fd1d3964 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -204,6 +204,7 @@ type stakingInputs struct { Key *store.KVStoreKey } +// Dependency Injection Outputs type stakingOutputs struct { depinject.Out From 2005d7517425ef793508a8edeb4bb38abe0378aa Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Thu, 2 Jun 2022 14:56:47 -0600 Subject: [PATCH 16/22] merge changes --- simapp/app.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index dfc5c27784a..284fb4f4a88 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -250,19 +250,16 @@ func NewSimApp( initParamsKeeper(app.ParamsKeeper) - // add keepers - app.BankKeeper = bankKeeper - app.MintKeeper = mintkeeper.NewKeeper( - app.appCodec, app.keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper, + app.appCodec, app.keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &app.StakingKeeper, app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, ) app.DistrKeeper = distrkeeper.NewKeeper( app.appCodec, app.keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper, - &stakingKeeper, authtypes.FeeCollectorName, + &app.StakingKeeper, authtypes.FeeCollectorName, ) app.SlashingKeeper = slashingkeeper.NewKeeper( - app.appCodec, app.keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName), + app.appCodec, app.keys[slashingtypes.StoreKey], &app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName), ) app.CrisisKeeper = crisiskeeper.NewKeeper( app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName, @@ -270,7 +267,7 @@ func NewSimApp( // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks - app.StakingKeeper = *stakingKeeper.SetHooks( + app.StakingKeeper = *app.StakingKeeper.SetHooks( stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), ) @@ -296,12 +293,12 @@ func NewSimApp( */ govKeeper := govkeeper.NewKeeper( app.appCodec, app.keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, - &stakingKeeper, govRouter, app.MsgServiceRouter(), govConfig, + &app.StakingKeeper, govRouter, app.MsgServiceRouter(), govConfig, ) app.GovKeeper = *govKeeper.SetHooks( govtypes.NewMultiGovHooks( - // register the governance hooks + // register the governance hooks ), ) // set the governance module account as the authority for conducting upgrades From 1dc27595a692f47a06557427cf1e2b2af1fe0c1d Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 2 Jun 2022 15:51:06 -0500 Subject: [PATCH 17/22] Pass StakingKeeper by reference everywhere - hack: Fixes post construction SetHooks mutation --- simapp/app.go | 24 ++++++++++---------- simapp/export.go | 4 ++-- x/staking/abci.go | 4 ++-- x/staking/keeper/grpc_query.go | 2 +- x/staking/keeper/invariants.go | 12 +++++----- x/staking/keeper/keeper.go | 8 +++---- x/staking/keeper/migrations.go | 4 ++-- x/staking/keeper/msg_server.go | 4 ++-- x/staking/keeper/querier.go | 40 +++++++++++++++------------------- x/staking/module.go | 8 +++---- 10 files changed, 51 insertions(+), 59 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 284fb4f4a88..774a400586d 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -170,7 +170,7 @@ type SimApp struct { AccountKeeper authkeeper.AccountKeeper BankKeeper bankkeeper.Keeper CapabilityKeeper *capabilitykeeper.Keeper - StakingKeeper stakingkeeper.Keeper + StakingKeeper *stakingkeeper.Keeper SlashingKeeper slashingkeeper.Keeper MintKeeper mintkeeper.Keeper DistrKeeper distrkeeper.Keeper @@ -251,23 +251,21 @@ func NewSimApp( initParamsKeeper(app.ParamsKeeper) app.MintKeeper = mintkeeper.NewKeeper( - app.appCodec, app.keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &app.StakingKeeper, + app.appCodec, app.keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), app.StakingKeeper, app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, ) app.DistrKeeper = distrkeeper.NewKeeper( app.appCodec, app.keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper, - &app.StakingKeeper, authtypes.FeeCollectorName, + app.StakingKeeper, authtypes.FeeCollectorName, ) app.SlashingKeeper = slashingkeeper.NewKeeper( - app.appCodec, app.keys[slashingtypes.StoreKey], &app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName), + app.appCodec, app.keys[slashingtypes.StoreKey], app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName), ) app.CrisisKeeper = crisiskeeper.NewKeeper( app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName, ) - // register the staking hooks - // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks - app.StakingKeeper = *app.StakingKeeper.SetHooks( + app.StakingKeeper.SetHooks( stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), ) @@ -293,7 +291,7 @@ func NewSimApp( */ govKeeper := govkeeper.NewKeeper( app.appCodec, app.keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, - &app.StakingKeeper, govRouter, app.MsgServiceRouter(), govConfig, + app.StakingKeeper, govRouter, app.MsgServiceRouter(), govConfig, ) app.GovKeeper = *govKeeper.SetHooks( @@ -308,7 +306,7 @@ func NewSimApp( // create evidence keeper with router evidenceKeeper := evidencekeeper.NewKeeper( - app.appCodec, app.keys[evidencetypes.StoreKey], &app.StakingKeeper, app.SlashingKeeper, + app.appCodec, app.keys[evidencetypes.StoreKey], app.StakingKeeper, app.SlashingKeeper, ) // If evidence needs to be handled for the app, set routes in router here and seal app.EvidenceKeeper = *evidenceKeeper @@ -330,8 +328,8 @@ func NewSimApp( crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), gov.NewAppModule(app.appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), mint.NewAppModule(app.appCodec, app.MintKeeper, app.AccountKeeper, nil), - slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), + distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), upgrade.NewAppModule(app.UpgradeKeeper), evidence.NewAppModule(app.EvidenceKeeper), authzmodule.NewAppModule(app.appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), @@ -380,8 +378,8 @@ func NewSimApp( gov.NewAppModule(app.appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), mint.NewAppModule(app.appCodec, app.MintKeeper, app.AccountKeeper, nil), staking.NewAppModule(app.appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), - distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), + slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), params.NewAppModule(app.ParamsKeeper), evidence.NewAppModule(app.EvidenceKeeper), authzmodule.NewAppModule(app.appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), diff --git a/simapp/export.go b/simapp/export.go index fd6a39c5711..1fbd40fa50d 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -36,7 +36,7 @@ func (app *SimApp) ExportAppStateAndValidators( return servertypes.ExportedApp{}, err } - validators, err := staking.WriteValidators(ctx, app.StakingKeeper) + validators, err := staking.WriteValidators(ctx, *app.StakingKeeper) return servertypes.ExportedApp{ AppState: appState, Validators: validators, @@ -163,7 +163,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] // Iterate through validators by power descending, reset bond heights, and // update bond intra-tx counters. - store := ctx.KVStore(app.keys[stakingtypes.StoreKey]) + store := ctx.KVStore(app.GetKey(stakingtypes.StoreKey)) iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) counter := int16(0) diff --git a/x/staking/abci.go b/x/staking/abci.go index 28253b5bd3f..4f6a77c427c 100644 --- a/x/staking/abci.go +++ b/x/staking/abci.go @@ -13,14 +13,14 @@ 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 BeginBlocker(ctx sdk.Context, k keeper.Keeper) { +func BeginBlocker(ctx sdk.Context, k *keeper.Keeper) { defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) k.TrackHistoricalInfo(ctx) } // Called every block, update validator set -func EndBlocker(ctx sdk.Context, k keeper.Keeper) []abci.ValidatorUpdate { +func EndBlocker(ctx sdk.Context, k *keeper.Keeper) []abci.ValidatorUpdate { defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) return k.BlockValidatorUpdates(ctx) diff --git a/x/staking/keeper/grpc_query.go b/x/staking/keeper/grpc_query.go index 79f9542adf2..885d0281573 100644 --- a/x/staking/keeper/grpc_query.go +++ b/x/staking/keeper/grpc_query.go @@ -15,7 +15,7 @@ import ( // Querier is used as Keeper will have duplicate methods if used directly, and gRPC names take precedence over keeper type Querier struct { - Keeper + *Keeper } var _ types.QueryServer = Querier{} diff --git a/x/staking/keeper/invariants.go b/x/staking/keeper/invariants.go index ed88ec62518..c2c41cd9505 100644 --- a/x/staking/keeper/invariants.go +++ b/x/staking/keeper/invariants.go @@ -9,7 +9,7 @@ import ( ) // RegisterInvariants registers all staking invariants -func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper) { +func RegisterInvariants(ir sdk.InvariantRegistry, k *Keeper) { ir.RegisterRoute(types.ModuleName, "module-accounts", ModuleAccountInvariants(k)) ir.RegisterRoute(types.ModuleName, "nonnegative-power", @@ -21,7 +21,7 @@ func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper) { } // AllInvariants runs all invariants of the staking module. -func AllInvariants(k Keeper) sdk.Invariant { +func AllInvariants(k *Keeper) sdk.Invariant { return func(ctx sdk.Context) (string, bool) { res, stop := ModuleAccountInvariants(k)(ctx) if stop { @@ -44,7 +44,7 @@ func AllInvariants(k Keeper) sdk.Invariant { // ModuleAccountInvariants checks that the bonded and notBonded ModuleAccounts pools // reflects the tokens actively bonded and not bonded -func ModuleAccountInvariants(k Keeper) sdk.Invariant { +func ModuleAccountInvariants(k *Keeper) sdk.Invariant { return func(ctx sdk.Context) (string, bool) { bonded := sdk.ZeroInt() notBonded := sdk.ZeroInt() @@ -91,7 +91,7 @@ func ModuleAccountInvariants(k Keeper) sdk.Invariant { } // NonNegativePowerInvariant checks that all stored validators have >= 0 power. -func NonNegativePowerInvariant(k Keeper) sdk.Invariant { +func NonNegativePowerInvariant(k *Keeper) sdk.Invariant { return func(ctx sdk.Context) (string, bool) { var ( msg string @@ -126,7 +126,7 @@ func NonNegativePowerInvariant(k Keeper) sdk.Invariant { } // PositiveDelegationInvariant checks that all stored delegations have > 0 shares. -func PositiveDelegationInvariant(k Keeper) sdk.Invariant { +func PositiveDelegationInvariant(k *Keeper) sdk.Invariant { return func(ctx sdk.Context) (string, bool) { var ( msg string @@ -156,7 +156,7 @@ func PositiveDelegationInvariant(k Keeper) sdk.Invariant { // DelegatorSharesInvariant checks whether all the delegator shares which persist // in the delegator object add up to the correct total delegator shares // amount stored in each validator. -func DelegatorSharesInvariant(k Keeper) sdk.Invariant { +func DelegatorSharesInvariant(k *Keeper) sdk.Invariant { return func(ctx sdk.Context) (string, bool) { var ( msg string diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 5dde8f1bb92..247c356bf49 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -32,7 +32,7 @@ type Keeper struct { func NewKeeper( cdc codec.BinaryCodec, key storetypes.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, ps paramtypes.Subspace, -) Keeper { +) *Keeper { // set KeyTable if it has not already been set if !ps.HasKeyTable() { ps = ps.WithKeyTable(types.ParamKeyTable()) @@ -47,7 +47,7 @@ func NewKeeper( panic(fmt.Sprintf("%s module account has not been set", types.NotBondedPoolName)) } - return Keeper{ + return &Keeper{ storeKey: key, cdc: cdc, authKeeper: ak, @@ -63,14 +63,12 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { } // Set the validator hooks -func (k *Keeper) SetHooks(sh types.StakingHooks) *Keeper { +func (k *Keeper) SetHooks(sh types.StakingHooks) { if k.hooks != nil { panic("cannot set validator hooks twice") } k.hooks = sh - - return k } // Load the last total validator power. diff --git a/x/staking/keeper/migrations.go b/x/staking/keeper/migrations.go index 1d1f019f120..9b6b5f51249 100644 --- a/x/staking/keeper/migrations.go +++ b/x/staking/keeper/migrations.go @@ -8,11 +8,11 @@ import ( // Migrator is a struct for handling in-place store migrations. type Migrator struct { - keeper Keeper + keeper *Keeper } // NewMigrator returns a new Migrator. -func NewMigrator(keeper Keeper) Migrator { +func NewMigrator(keeper *Keeper) Migrator { return Migrator{ keeper: keeper, } diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 3e4ad4417d1..e1564b2c379 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -19,12 +19,12 @@ import ( ) type msgServer struct { - Keeper + *Keeper } // NewMsgServerImpl returns an implementation of the bank MsgServer interface // for the provided Keeper. -func NewMsgServerImpl(keeper Keeper) types.MsgServer { +func NewMsgServerImpl(keeper *Keeper) types.MsgServer { return &msgServer{Keeper: keeper} } diff --git a/x/staking/keeper/querier.go b/x/staking/keeper/querier.go index 95c26d49a45..dbe862c4e3e 100644 --- a/x/staking/keeper/querier.go +++ b/x/staking/keeper/querier.go @@ -14,7 +14,7 @@ import ( ) // creates a querier for staking REST endpoints -func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { +func NewQuerier(k *Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { case types.QueryValidators: @@ -65,7 +65,7 @@ func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { } } -func queryValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { +func queryValidators(ctx sdk.Context, req abci.RequestQuery, k *Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { var params types.QueryValidatorsParams err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) @@ -97,7 +97,7 @@ func queryValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQue return res, nil } -func queryValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { +func queryValidator(ctx sdk.Context, req abci.RequestQuery, k *Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { var params types.QueryValidatorParams err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) @@ -118,7 +118,7 @@ func queryValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuer return res, nil } -func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { +func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k *Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { var params types.QueryValidatorParams err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) @@ -152,7 +152,7 @@ func queryValidatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, return res, nil } -func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { +func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k *Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { var params types.QueryValidatorParams err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) @@ -180,7 +180,7 @@ func queryValidatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, return res, nil } -func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { +func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k *Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { var params types.QueryDelegatorParams err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) @@ -206,7 +206,7 @@ func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, return res, nil } -func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { +func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, k *Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { var params types.QueryDelegatorParams err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) @@ -227,7 +227,7 @@ func queryDelegatorUnbondingDelegations(ctx sdk.Context, req abci.RequestQuery, return res, nil } -func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { +func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k *Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { var params types.QueryDelegatorParams stakingParams := k.GetParams(ctx) @@ -250,7 +250,7 @@ func queryDelegatorValidators(ctx sdk.Context, req abci.RequestQuery, k Keeper, return res, nil } -func queryDelegatorValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { +func queryDelegatorValidator(ctx sdk.Context, req abci.RequestQuery, k *Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { var params types.QueryDelegatorValidatorRequest err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) @@ -281,7 +281,7 @@ func queryDelegatorValidator(ctx sdk.Context, req abci.RequestQuery, k Keeper, l return res, nil } -func queryDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { +func queryDelegation(ctx sdk.Context, req abci.RequestQuery, k *Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { var params types.QueryDelegatorValidatorRequest err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) @@ -317,7 +317,7 @@ func queryDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQue return res, nil } -func queryUnbondingDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { +func queryUnbondingDelegation(ctx sdk.Context, req abci.RequestQuery, k *Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { var params types.QueryDelegatorValidatorRequest err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) @@ -348,7 +348,7 @@ func queryUnbondingDelegation(ctx sdk.Context, req abci.RequestQuery, k Keeper, return res, nil } -func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { +func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k *Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { var params types.QueryRedelegationParams err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) @@ -389,7 +389,7 @@ func queryRedelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacy return res, nil } -func queryHistoricalInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { +func queryHistoricalInfo(ctx sdk.Context, req abci.RequestQuery, k *Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { var params types.QueryHistoricalInfoRequest err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms) @@ -410,7 +410,7 @@ func queryHistoricalInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper, legac return res, nil } -func queryPool(ctx sdk.Context, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { +func queryPool(ctx sdk.Context, k *Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { bondDenom := k.BondDenom(ctx) bondedPool := k.GetBondedPool(ctx) notBondedPool := k.GetNotBondedPool(ctx) @@ -432,7 +432,7 @@ func queryPool(ctx sdk.Context, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ( return res, nil } -func queryParameters(ctx sdk.Context, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { +func queryParameters(ctx sdk.Context, k *Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { params := k.GetParams(ctx) res, err := codec.MarshalJSONIndent(legacyQuerierCdc, params) @@ -445,7 +445,7 @@ func queryParameters(ctx sdk.Context, k Keeper, legacyQuerierCdc *codec.LegacyAm // util -func DelegationToDelegationResponse(ctx sdk.Context, k Keeper, del types.Delegation) (types.DelegationResponse, error) { +func DelegationToDelegationResponse(ctx sdk.Context, k *Keeper, del types.Delegation) (types.DelegationResponse, error) { val, found := k.GetValidator(ctx, del.GetValidatorAddr()) if !found { return types.DelegationResponse{}, types.ErrNoValidatorFound @@ -464,9 +464,7 @@ func DelegationToDelegationResponse(ctx sdk.Context, k Keeper, del types.Delegat ), nil } -func DelegationsToDelegationResponses( - ctx sdk.Context, k Keeper, delegations types.Delegations, -) (types.DelegationResponses, error) { +func DelegationsToDelegationResponses(ctx sdk.Context, k *Keeper, delegations types.Delegations) (types.DelegationResponses, error) { resp := make(types.DelegationResponses, len(delegations)) for i, del := range delegations { @@ -481,9 +479,7 @@ func DelegationsToDelegationResponses( return resp, nil } -func RedelegationsToRedelegationResponses( - ctx sdk.Context, k Keeper, redels types.Redelegations, -) (types.RedelegationResponses, error) { +func RedelegationsToRedelegationResponses(ctx sdk.Context, k *Keeper, redels types.Redelegations) (types.RedelegationResponses, error) { resp := make(types.RedelegationResponses, len(redels)) for i, redel := range redels { diff --git a/x/staking/module.go b/x/staking/module.go index a24fd1d3964..0a4dd893327 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -98,13 +98,13 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { type AppModule struct { AppModuleBasic - keeper keeper.Keeper + keeper *keeper.Keeper accountKeeper types.AccountKeeper bankKeeper types.BankKeeper } // NewAppModule creates a new AppModule object -func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper) AppModule { +func NewAppModule(cdc codec.Codec, keeper *keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{cdc: cdc}, keeper: keeper, @@ -208,7 +208,7 @@ type stakingInputs struct { type stakingOutputs struct { depinject.Out - StakingKeeper keeper.Keeper `key:"cosmos.staking.v1.Keeper"` + StakingKeeper *keeper.Keeper `key:"cosmos.staking.v1.Keeper"` Module runtime.AppModuleWrapper } @@ -243,6 +243,6 @@ func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { // WeightedOperations returns the all the staking module operations with their respective weights. func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { return simulation.WeightedOperations( - simState.AppParams, simState.Cdc, am.accountKeeper, am.bankKeeper, am.keeper, + simState.AppParams, simState.Cdc, am.accountKeeper, am.bankKeeper, *am.keeper, ) } From 215b63f03e021f1a62f5a217cb396007880e08e3 Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Thu, 2 Jun 2022 16:38:28 -0600 Subject: [PATCH 18/22] change some keeper value to reference for the hooks fix --- x/staking/teststaking/helper.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/staking/teststaking/helper.go b/x/staking/teststaking/helper.go index 012f21f00ed..7691b94e8a6 100644 --- a/x/staking/teststaking/helper.go +++ b/x/staking/teststaking/helper.go @@ -29,7 +29,7 @@ type Helper struct { // NewHelper creates a new instance of Helper. func NewHelper(t *testing.T, ctx sdk.Context, k keeper.Keeper) *Helper { - return &Helper{t, keeper.NewMsgServerImpl(k), k, ctx, ZeroCommission(), sdk.DefaultBondDenom} + return &Helper{t, keeper.NewMsgServerImpl(&k), k, ctx, ZeroCommission(), sdk.DefaultBondDenom} } // CreateValidator calls staking module `MsgServer/CreateValidator` to create a new validator @@ -126,7 +126,7 @@ func (sh *Helper) CheckDelegator(delegator sdk.AccAddress, val sdk.ValAddress, f // TurnBlock calls EndBlocker and updates the block time func (sh *Helper) TurnBlock(newTime time.Time) sdk.Context { sh.Ctx = sh.Ctx.WithBlockTime(newTime) - staking.EndBlocker(sh.Ctx, sh.k) + staking.EndBlocker(sh.Ctx, &sh.k) return sh.Ctx } @@ -134,7 +134,7 @@ func (sh *Helper) TurnBlock(newTime time.Time) sdk.Context { // duration to the current block time func (sh *Helper) TurnBlockTimeDiff(diff time.Duration) sdk.Context { sh.Ctx = sh.Ctx.WithBlockTime(sh.Ctx.BlockHeader().Time.Add(diff)) - staking.EndBlocker(sh.Ctx, sh.k) + staking.EndBlocker(sh.Ctx, &sh.k) return sh.Ctx } From cd880e4d531d6d31413de3007a4f86319445222c Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Thu, 2 Jun 2022 17:04:41 -0600 Subject: [PATCH 19/22] change test tools to recieve pointer insted of instance --- x/staking/keeper/test_common.go | 6 +++--- x/staking/keeper/validator_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x/staking/keeper/test_common.go b/x/staking/keeper/test_common.go index 42e94740d3e..edc97449763 100644 --- a/x/staking/keeper/test_common.go +++ b/x/staking/keeper/test_common.go @@ -9,13 +9,13 @@ import ( ) // does a certain by-power index record exist -func ValidatorByPowerIndexExists(ctx sdk.Context, keeper Keeper, power []byte) bool { +func ValidatorByPowerIndexExists(ctx sdk.Context, keeper *Keeper, power []byte) bool { store := ctx.KVStore(keeper.storeKey) return store.Has(power) } // update validator for testing -func TestingUpdateValidator(keeper Keeper, ctx sdk.Context, validator types.Validator, apply bool) types.Validator { +func TestingUpdateValidator(keeper *Keeper, ctx sdk.Context, validator types.Validator, apply bool) types.Validator { keeper.SetValidator(ctx, validator) // Remove any existing power key for validator. @@ -57,7 +57,7 @@ func TestingUpdateValidator(keeper Keeper, ctx sdk.Context, validator types.Vali } // RandomValidator returns a random validator given access to the keeper and ctx -func RandomValidator(r *rand.Rand, keeper Keeper, ctx sdk.Context) (val types.Validator, ok bool) { +func RandomValidator(r *rand.Rand, keeper *Keeper, ctx sdk.Context) (val types.Validator, ok bool) { vals := keeper.GetAllValidators(ctx) if len(vals) == 0 { return types.Validator{}, false diff --git a/x/staking/keeper/validator_test.go b/x/staking/keeper/validator_test.go index ffa6d595854..906a49c6b68 100644 --- a/x/staking/keeper/validator_test.go +++ b/x/staking/keeper/validator_test.go @@ -1113,7 +1113,7 @@ func TestUpdateValidatorCommission(t *testing.T) { } } -func applyValidatorSetUpdates(t *testing.T, ctx sdk.Context, k keeper.Keeper, expectedUpdatesLen int) []abci.ValidatorUpdate { +func applyValidatorSetUpdates(t *testing.T, ctx sdk.Context, k *keeper.Keeper, expectedUpdatesLen int) []abci.ValidatorUpdate { updates, err := k.ApplyAndReturnValidatorSetUpdates(ctx) require.NoError(t, err) if expectedUpdatesLen >= 0 { From 9ec5a3cd5eeae319f08ea27ee741edc371e74678 Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Thu, 2 Jun 2022 17:12:27 -0600 Subject: [PATCH 20/22] change test tools to recieve pointer insted of instance --- x/distribution/simulation/operations.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index 44aa71a8e15..4e7a6d5ab5b 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -26,7 +26,7 @@ const ( // WeightedOperations returns all the operations from the module with their respective weights func WeightedOperations( appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, - bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper, + bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper, ) simulation.WeightedOperations { var weightMsgSetWithdrawAddress int appParams.GetOrGenerate(cdc, OpWeightMsgSetWithdrawAddress, &weightMsgSetWithdrawAddress, nil, @@ -113,7 +113,7 @@ func SimulateMsgSetWithdrawAddress(ak types.AccountKeeper, bk types.BankKeeper, } // SimulateMsgWithdrawDelegatorReward generates a MsgWithdrawDelegatorReward with random values. -func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper) simtypes.Operation { +func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -155,7 +155,7 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee } // SimulateMsgWithdrawValidatorCommission generates a MsgWithdrawValidatorCommission with random values. -func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper) simtypes.Operation { +func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -200,7 +200,7 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban // SimulateMsgFundCommunityPool simulates MsgFundCommunityPool execution where // a random account sends a random amount of its funds to the community pool. -func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper) simtypes.Operation { +func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { From b241d5114c167b98f7a0c006584f63b86fbbde39 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 2 Jun 2022 18:23:22 -0500 Subject: [PATCH 21/22] Fix tests, more pass by reference --- simapp/app.go | 8 ++++---- simapp/export.go | 2 +- x/distribution/module.go | 4 ++-- x/distribution/simulation/operations.go | 11 ++++------- x/slashing/module.go | 4 ++-- x/slashing/simulation/operations.go | 4 ++-- x/staking/genesis.go | 2 +- x/staking/keeper/test_common.go | 6 +++--- x/staking/keeper/validator_test.go | 2 +- x/staking/module.go | 2 +- x/staking/simulation/operations.go | 14 +++++++------- x/staking/teststaking/helper.go | 10 +++++----- 12 files changed, 33 insertions(+), 36 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 774a400586d..51cfbaf7ff0 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -328,8 +328,8 @@ func NewSimApp( crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), gov.NewAppModule(app.appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), mint.NewAppModule(app.appCodec, app.MintKeeper, app.AccountKeeper, nil), - slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), - distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), + slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), upgrade.NewAppModule(app.UpgradeKeeper), evidence.NewAppModule(app.EvidenceKeeper), authzmodule.NewAppModule(app.appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), @@ -378,8 +378,8 @@ func NewSimApp( gov.NewAppModule(app.appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), mint.NewAppModule(app.appCodec, app.MintKeeper, app.AccountKeeper, nil), staking.NewAppModule(app.appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), - distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), - slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), + distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), params.NewAppModule(app.ParamsKeeper), evidence.NewAppModule(app.EvidenceKeeper), authzmodule.NewAppModule(app.appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), diff --git a/simapp/export.go b/simapp/export.go index 1fbd40fa50d..7ecb25f6436 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -36,7 +36,7 @@ func (app *SimApp) ExportAppStateAndValidators( return servertypes.ExportedApp{}, err } - validators, err := staking.WriteValidators(ctx, *app.StakingKeeper) + validators, err := staking.WriteValidators(ctx, app.StakingKeeper) return servertypes.ExportedApp{ AppState: appState, Validators: validators, diff --git a/x/distribution/module.go b/x/distribution/module.go index e2f240b1eda..be0e92d1e9c 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -89,13 +89,13 @@ type AppModule struct { keeper keeper.Keeper accountKeeper types.AccountKeeper bankKeeper types.BankKeeper - stakingKeeper stakingkeeper.Keeper + stakingKeeper *stakingkeeper.Keeper } // NewAppModule creates a new AppModule object func NewAppModule( cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.AccountKeeper, - bankKeeper types.BankKeeper, stakingKeeper stakingkeeper.Keeper, + bankKeeper types.BankKeeper, stakingKeeper *stakingkeeper.Keeper, ) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{cdc: cdc}, diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index 44aa71a8e15..ba21eb7828a 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -24,10 +24,7 @@ const ( ) // WeightedOperations returns all the operations from the module with their respective weights -func WeightedOperations( - appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, - bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper, -) simulation.WeightedOperations { +func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simulation.WeightedOperations { var weightMsgSetWithdrawAddress int appParams.GetOrGenerate(cdc, OpWeightMsgSetWithdrawAddress, &weightMsgSetWithdrawAddress, nil, func(_ *rand.Rand) { @@ -113,7 +110,7 @@ func SimulateMsgSetWithdrawAddress(ak types.AccountKeeper, bk types.BankKeeper, } // SimulateMsgWithdrawDelegatorReward generates a MsgWithdrawDelegatorReward with random values. -func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper) simtypes.Operation { +func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -155,7 +152,7 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee } // SimulateMsgWithdrawValidatorCommission generates a MsgWithdrawValidatorCommission with random values. -func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper) simtypes.Operation { +func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -200,7 +197,7 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban // SimulateMsgFundCommunityPool simulates MsgFundCommunityPool execution where // a random account sends a random amount of its funds to the community pool. -func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper) simtypes.Operation { +func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { diff --git a/x/slashing/module.go b/x/slashing/module.go index 73991883aa0..47ab5e56d3b 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -91,11 +91,11 @@ type AppModule struct { keeper keeper.Keeper accountKeeper types.AccountKeeper bankKeeper types.BankKeeper - stakingKeeper stakingkeeper.Keeper + stakingKeeper *stakingkeeper.Keeper } // NewAppModule creates a new AppModule object -func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper, sk stakingkeeper.Keeper) AppModule { +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper, sk *stakingkeeper.Keeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{cdc: cdc}, keeper: keeper, diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 56eef65d8a5..1aaf4387f70 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -24,7 +24,7 @@ const ( // WeightedOperations returns all the operations from the module with their respective weights func WeightedOperations( appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, - bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper, + bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper, ) simulation.WeightedOperations { var weightMsgUnjail int appParams.GetOrGenerate(cdc, OpWeightMsgUnjail, &weightMsgUnjail, nil, @@ -42,7 +42,7 @@ func WeightedOperations( } // SimulateMsgUnjail generates a MsgUnjail with random values -func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper) simtypes.Operation { +func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, diff --git a/x/staking/genesis.go b/x/staking/genesis.go index 5b94b8adf48..bd05fc5ba01 100644 --- a/x/staking/genesis.go +++ b/x/staking/genesis.go @@ -12,7 +12,7 @@ import ( ) // WriteValidators returns a slice of bonded genesis validators. -func WriteValidators(ctx sdk.Context, keeper keeper.Keeper) (vals []tmtypes.GenesisValidator, err error) { +func WriteValidators(ctx sdk.Context, keeper *keeper.Keeper) (vals []tmtypes.GenesisValidator, err error) { keeper.IterateLastValidators(ctx, func(_ int64, validator types.ValidatorI) (stop bool) { pk, err := validator.ConsPubKey() if err != nil { diff --git a/x/staking/keeper/test_common.go b/x/staking/keeper/test_common.go index 42e94740d3e..edc97449763 100644 --- a/x/staking/keeper/test_common.go +++ b/x/staking/keeper/test_common.go @@ -9,13 +9,13 @@ import ( ) // does a certain by-power index record exist -func ValidatorByPowerIndexExists(ctx sdk.Context, keeper Keeper, power []byte) bool { +func ValidatorByPowerIndexExists(ctx sdk.Context, keeper *Keeper, power []byte) bool { store := ctx.KVStore(keeper.storeKey) return store.Has(power) } // update validator for testing -func TestingUpdateValidator(keeper Keeper, ctx sdk.Context, validator types.Validator, apply bool) types.Validator { +func TestingUpdateValidator(keeper *Keeper, ctx sdk.Context, validator types.Validator, apply bool) types.Validator { keeper.SetValidator(ctx, validator) // Remove any existing power key for validator. @@ -57,7 +57,7 @@ func TestingUpdateValidator(keeper Keeper, ctx sdk.Context, validator types.Vali } // RandomValidator returns a random validator given access to the keeper and ctx -func RandomValidator(r *rand.Rand, keeper Keeper, ctx sdk.Context) (val types.Validator, ok bool) { +func RandomValidator(r *rand.Rand, keeper *Keeper, ctx sdk.Context) (val types.Validator, ok bool) { vals := keeper.GetAllValidators(ctx) if len(vals) == 0 { return types.Validator{}, false diff --git a/x/staking/keeper/validator_test.go b/x/staking/keeper/validator_test.go index ffa6d595854..906a49c6b68 100644 --- a/x/staking/keeper/validator_test.go +++ b/x/staking/keeper/validator_test.go @@ -1113,7 +1113,7 @@ func TestUpdateValidatorCommission(t *testing.T) { } } -func applyValidatorSetUpdates(t *testing.T, ctx sdk.Context, k keeper.Keeper, expectedUpdatesLen int) []abci.ValidatorUpdate { +func applyValidatorSetUpdates(t *testing.T, ctx sdk.Context, k *keeper.Keeper, expectedUpdatesLen int) []abci.ValidatorUpdate { updates, err := k.ApplyAndReturnValidatorSetUpdates(ctx) require.NoError(t, err) if expectedUpdatesLen >= 0 { diff --git a/x/staking/module.go b/x/staking/module.go index 0a4dd893327..8e35603cc48 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -243,6 +243,6 @@ func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { // WeightedOperations returns the all the staking module operations with their respective weights. func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { return simulation.WeightedOperations( - simState.AppParams, simState.Cdc, am.accountKeeper, am.bankKeeper, *am.keeper, + simState.AppParams, simState.Cdc, am.accountKeeper, am.bankKeeper, am.keeper, ) } diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index 7cff6459db1..c94347dd588 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -27,7 +27,7 @@ const ( // WeightedOperations returns all the operations from the module with their respective weights func WeightedOperations( appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, - bk types.BankKeeper, k keeper.Keeper, + bk types.BankKeeper, k *keeper.Keeper, ) simulation.WeightedOperations { var ( weightMsgCreateValidator int @@ -103,7 +103,7 @@ func WeightedOperations( } // SimulateMsgCreateValidator generates a MsgCreateValidator with random values -func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -180,7 +180,7 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k } // SimulateMsgEditValidator generates a MsgEditValidator with random values -func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -240,7 +240,7 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k kee } // SimulateMsgDelegate generates a MsgDelegate with random values -func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -304,7 +304,7 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K } // SimulateMsgUndelegate generates a MsgUndelegate with random values -func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -383,7 +383,7 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper } // SimulateMsgCancelUnbondingDelegate generates a MsgCancelUnbondingDelegate with random values -func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -451,7 +451,7 @@ func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKee } // SimulateMsgBeginRedelegate generates a MsgBeginRedelegate with random values -func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { diff --git a/x/staking/teststaking/helper.go b/x/staking/teststaking/helper.go index 7691b94e8a6..e6bf1d1dcc8 100644 --- a/x/staking/teststaking/helper.go +++ b/x/staking/teststaking/helper.go @@ -19,7 +19,7 @@ import ( type Helper struct { t *testing.T msgSrvr stakingtypes.MsgServer - k keeper.Keeper + k *keeper.Keeper Ctx sdk.Context Commission stakingtypes.CommissionRates @@ -28,8 +28,8 @@ type Helper struct { } // NewHelper creates a new instance of Helper. -func NewHelper(t *testing.T, ctx sdk.Context, k keeper.Keeper) *Helper { - return &Helper{t, keeper.NewMsgServerImpl(&k), k, ctx, ZeroCommission(), sdk.DefaultBondDenom} +func NewHelper(t *testing.T, ctx sdk.Context, k *keeper.Keeper) *Helper { + return &Helper{t, keeper.NewMsgServerImpl(k), k, ctx, ZeroCommission(), sdk.DefaultBondDenom} } // CreateValidator calls staking module `MsgServer/CreateValidator` to create a new validator @@ -126,7 +126,7 @@ func (sh *Helper) CheckDelegator(delegator sdk.AccAddress, val sdk.ValAddress, f // TurnBlock calls EndBlocker and updates the block time func (sh *Helper) TurnBlock(newTime time.Time) sdk.Context { sh.Ctx = sh.Ctx.WithBlockTime(newTime) - staking.EndBlocker(sh.Ctx, &sh.k) + staking.EndBlocker(sh.Ctx, sh.k) return sh.Ctx } @@ -134,7 +134,7 @@ func (sh *Helper) TurnBlock(newTime time.Time) sdk.Context { // duration to the current block time func (sh *Helper) TurnBlockTimeDiff(diff time.Duration) sdk.Context { sh.Ctx = sh.Ctx.WithBlockTime(sh.Ctx.BlockHeader().Time.Add(diff)) - staking.EndBlocker(sh.Ctx, &sh.k) + staking.EndBlocker(sh.Ctx, sh.k) return sh.Ctx } From 35440b7fe47f2910675cd10cd21dbdfeb574e7f0 Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Thu, 2 Jun 2022 17:23:32 -0600 Subject: [PATCH 22/22] change test tools to recieve pointer insted of instance --- simapp/app.go | 8 ++++---- x/distribution/module.go | 4 ++-- x/slashing/module.go | 4 ++-- x/slashing/simulation/operations.go | 4 ++-- x/staking/module.go | 2 +- x/staking/simulation/operations.go | 14 +++++++------- x/staking/teststaking/helper.go | 10 +++++----- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 774a400586d..51cfbaf7ff0 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -328,8 +328,8 @@ func NewSimApp( crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), gov.NewAppModule(app.appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), mint.NewAppModule(app.appCodec, app.MintKeeper, app.AccountKeeper, nil), - slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), - distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), + slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), upgrade.NewAppModule(app.UpgradeKeeper), evidence.NewAppModule(app.EvidenceKeeper), authzmodule.NewAppModule(app.appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), @@ -378,8 +378,8 @@ func NewSimApp( gov.NewAppModule(app.appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), mint.NewAppModule(app.appCodec, app.MintKeeper, app.AccountKeeper, nil), staking.NewAppModule(app.appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), - distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), - slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper), + distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), params.NewAppModule(app.ParamsKeeper), evidence.NewAppModule(app.EvidenceKeeper), authzmodule.NewAppModule(app.appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), diff --git a/x/distribution/module.go b/x/distribution/module.go index e2f240b1eda..be0e92d1e9c 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -89,13 +89,13 @@ type AppModule struct { keeper keeper.Keeper accountKeeper types.AccountKeeper bankKeeper types.BankKeeper - stakingKeeper stakingkeeper.Keeper + stakingKeeper *stakingkeeper.Keeper } // NewAppModule creates a new AppModule object func NewAppModule( cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.AccountKeeper, - bankKeeper types.BankKeeper, stakingKeeper stakingkeeper.Keeper, + bankKeeper types.BankKeeper, stakingKeeper *stakingkeeper.Keeper, ) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{cdc: cdc}, diff --git a/x/slashing/module.go b/x/slashing/module.go index 73991883aa0..47ab5e56d3b 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -91,11 +91,11 @@ type AppModule struct { keeper keeper.Keeper accountKeeper types.AccountKeeper bankKeeper types.BankKeeper - stakingKeeper stakingkeeper.Keeper + stakingKeeper *stakingkeeper.Keeper } // NewAppModule creates a new AppModule object -func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper, sk stakingkeeper.Keeper) AppModule { +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper, sk *stakingkeeper.Keeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{cdc: cdc}, keeper: keeper, diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 56eef65d8a5..1aaf4387f70 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -24,7 +24,7 @@ const ( // WeightedOperations returns all the operations from the module with their respective weights func WeightedOperations( appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, - bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper, + bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper, ) simulation.WeightedOperations { var weightMsgUnjail int appParams.GetOrGenerate(cdc, OpWeightMsgUnjail, &weightMsgUnjail, nil, @@ -42,7 +42,7 @@ func WeightedOperations( } // SimulateMsgUnjail generates a MsgUnjail with random values -func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper) simtypes.Operation { +func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, diff --git a/x/staking/module.go b/x/staking/module.go index 0a4dd893327..8e35603cc48 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -243,6 +243,6 @@ func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { // WeightedOperations returns the all the staking module operations with their respective weights. func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { return simulation.WeightedOperations( - simState.AppParams, simState.Cdc, am.accountKeeper, am.bankKeeper, *am.keeper, + simState.AppParams, simState.Cdc, am.accountKeeper, am.bankKeeper, am.keeper, ) } diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index 7cff6459db1..c94347dd588 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -27,7 +27,7 @@ const ( // WeightedOperations returns all the operations from the module with their respective weights func WeightedOperations( appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, - bk types.BankKeeper, k keeper.Keeper, + bk types.BankKeeper, k *keeper.Keeper, ) simulation.WeightedOperations { var ( weightMsgCreateValidator int @@ -103,7 +103,7 @@ func WeightedOperations( } // SimulateMsgCreateValidator generates a MsgCreateValidator with random values -func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -180,7 +180,7 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k } // SimulateMsgEditValidator generates a MsgEditValidator with random values -func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -240,7 +240,7 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k kee } // SimulateMsgDelegate generates a MsgDelegate with random values -func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -304,7 +304,7 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K } // SimulateMsgUndelegate generates a MsgUndelegate with random values -func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -383,7 +383,7 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper } // SimulateMsgCancelUnbondingDelegate generates a MsgCancelUnbondingDelegate with random values -func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -451,7 +451,7 @@ func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKee } // SimulateMsgBeginRedelegate generates a MsgBeginRedelegate with random values -func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { diff --git a/x/staking/teststaking/helper.go b/x/staking/teststaking/helper.go index 7691b94e8a6..e6bf1d1dcc8 100644 --- a/x/staking/teststaking/helper.go +++ b/x/staking/teststaking/helper.go @@ -19,7 +19,7 @@ import ( type Helper struct { t *testing.T msgSrvr stakingtypes.MsgServer - k keeper.Keeper + k *keeper.Keeper Ctx sdk.Context Commission stakingtypes.CommissionRates @@ -28,8 +28,8 @@ type Helper struct { } // NewHelper creates a new instance of Helper. -func NewHelper(t *testing.T, ctx sdk.Context, k keeper.Keeper) *Helper { - return &Helper{t, keeper.NewMsgServerImpl(&k), k, ctx, ZeroCommission(), sdk.DefaultBondDenom} +func NewHelper(t *testing.T, ctx sdk.Context, k *keeper.Keeper) *Helper { + return &Helper{t, keeper.NewMsgServerImpl(k), k, ctx, ZeroCommission(), sdk.DefaultBondDenom} } // CreateValidator calls staking module `MsgServer/CreateValidator` to create a new validator @@ -126,7 +126,7 @@ func (sh *Helper) CheckDelegator(delegator sdk.AccAddress, val sdk.ValAddress, f // TurnBlock calls EndBlocker and updates the block time func (sh *Helper) TurnBlock(newTime time.Time) sdk.Context { sh.Ctx = sh.Ctx.WithBlockTime(newTime) - staking.EndBlocker(sh.Ctx, &sh.k) + staking.EndBlocker(sh.Ctx, sh.k) return sh.Ctx } @@ -134,7 +134,7 @@ func (sh *Helper) TurnBlock(newTime time.Time) sdk.Context { // duration to the current block time func (sh *Helper) TurnBlockTimeDiff(diff time.Duration) sdk.Context { sh.Ctx = sh.Ctx.WithBlockTime(sh.Ctx.BlockHeader().Time.Add(diff)) - staking.EndBlocker(sh.Ctx, &sh.k) + staking.EndBlocker(sh.Ctx, sh.k) return sh.Ctx }