diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 83c53e3f2cd..1090638c445 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -75,6 +75,8 @@ import ( "github.com/osmosis-labs/osmosis/v12/x/txfees" txfeeskeeper "github.com/osmosis-labs/osmosis/v12/x/txfees/keeper" txfeestypes "github.com/osmosis-labs/osmosis/v12/x/txfees/types" + valsetpref "github.com/osmosis-labs/osmosis/v12/x/valset-pref" + valsetpreftypes "github.com/osmosis-labs/osmosis/v12/x/valset-pref/types" ) type AppKeepers struct { @@ -92,29 +94,30 @@ type AppKeepers struct { ScopedWasmKeeper capabilitykeeper.ScopedKeeper // "Normal" keepers - AccountKeeper *authkeeper.AccountKeeper - BankKeeper *bankkeeper.BaseKeeper - AuthzKeeper *authzkeeper.Keeper - StakingKeeper *stakingkeeper.Keeper - DistrKeeper *distrkeeper.Keeper - SlashingKeeper *slashingkeeper.Keeper - IBCKeeper *ibckeeper.Keeper - ICAHostKeeper *icahostkeeper.Keeper - TransferKeeper *ibctransferkeeper.Keeper - EvidenceKeeper *evidencekeeper.Keeper - GAMMKeeper *gammkeeper.Keeper - TwapKeeper *twap.Keeper - LockupKeeper *lockupkeeper.Keeper - EpochsKeeper *epochskeeper.Keeper - IncentivesKeeper *incentiveskeeper.Keeper - MintKeeper *mintkeeper.Keeper - PoolIncentivesKeeper *poolincentiveskeeper.Keeper - TxFeesKeeper *txfeeskeeper.Keeper - SuperfluidKeeper *superfluidkeeper.Keeper - GovKeeper *govkeeper.Keeper - WasmKeeper *wasm.Keeper - ContractKeeper *wasmkeeper.PermissionedKeeper - TokenFactoryKeeper *tokenfactorykeeper.Keeper + AccountKeeper *authkeeper.AccountKeeper + BankKeeper *bankkeeper.BaseKeeper + AuthzKeeper *authzkeeper.Keeper + StakingKeeper *stakingkeeper.Keeper + DistrKeeper *distrkeeper.Keeper + SlashingKeeper *slashingkeeper.Keeper + IBCKeeper *ibckeeper.Keeper + ICAHostKeeper *icahostkeeper.Keeper + TransferKeeper *ibctransferkeeper.Keeper + EvidenceKeeper *evidencekeeper.Keeper + GAMMKeeper *gammkeeper.Keeper + TwapKeeper *twap.Keeper + LockupKeeper *lockupkeeper.Keeper + EpochsKeeper *epochskeeper.Keeper + IncentivesKeeper *incentiveskeeper.Keeper + MintKeeper *mintkeeper.Keeper + PoolIncentivesKeeper *poolincentiveskeeper.Keeper + TxFeesKeeper *txfeeskeeper.Keeper + SuperfluidKeeper *superfluidkeeper.Keeper + GovKeeper *govkeeper.Keeper + WasmKeeper *wasm.Keeper + ContractKeeper *wasmkeeper.PermissionedKeeper + TokenFactoryKeeper *tokenfactorykeeper.Keeper + ValidatorSetPreferenceKeeper *valsetpref.Keeper // IBC modules // transfer module @@ -338,6 +341,14 @@ func (appKeepers *AppKeepers) InitNormalKeepers( ) appKeepers.TokenFactoryKeeper = &tokenFactoryKeeper + validatorSetPreferenceKeeper := valsetpref.NewKeeper( + appKeepers.keys[valsetpreftypes.StoreKey], + appKeepers.GetSubspace(valsetpreftypes.ModuleName), + appKeepers.StakingKeeper, + ) + + appKeepers.ValidatorSetPreferenceKeeper = &validatorSetPreferenceKeeper + // The last arguments can contain custom message handlers, and custom query handlers, // if we want to allow any custom callbacks supportedFeatures := "iterator,staking,stargate,osmosis" @@ -556,5 +567,6 @@ func KVStoreKeys() []string { superfluidtypes.StoreKey, wasm.StoreKey, tokenfactorytypes.StoreKey, + valsetpreftypes.StoreKey, } } diff --git a/app/keepers/modules.go b/app/keepers/modules.go index 88f214644c7..a24fccd4e97 100644 --- a/app/keepers/modules.go +++ b/app/keepers/modules.go @@ -40,6 +40,7 @@ import ( "github.com/osmosis-labs/osmosis/v12/x/tokenfactory" "github.com/osmosis-labs/osmosis/v12/x/twap/twapmodule" "github.com/osmosis-labs/osmosis/v12/x/txfees" + valsetprefmodule "github.com/osmosis-labs/osmosis/v12/x/valset-pref/valpref-module" ) // AppModuleBasics returns ModuleBasics for the module BasicManager. @@ -84,6 +85,7 @@ var AppModuleBasics = []module.AppModuleBasic{ epochs.AppModuleBasic{}, superfluid.AppModuleBasic{}, tokenfactory.AppModuleBasic{}, + valsetprefmodule.AppModuleBasic{}, wasm.AppModuleBasic{}, ica.AppModuleBasic{}, } diff --git a/app/modules.go b/app/modules.go index 3421fec2ba9..8c9ed5eb1cf 100644 --- a/app/modules.go +++ b/app/modules.go @@ -67,6 +67,8 @@ import ( twaptypes "github.com/osmosis-labs/osmosis/v12/x/twap/types" "github.com/osmosis-labs/osmosis/v12/x/txfees" txfeestypes "github.com/osmosis-labs/osmosis/v12/x/txfees/types" + valsetpreftypes "github.com/osmosis-labs/osmosis/v12/x/valset-pref/types" + valsetprefmodule "github.com/osmosis-labs/osmosis/v12/x/valset-pref/valpref-module" ) // moduleAccountPermissions defines module account permissions @@ -90,6 +92,7 @@ var moduleAccountPermissions = map[string][]string{ txfeestypes.NonNativeFeeCollectorName: nil, wasm.ModuleName: {authtypes.Burner}, tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + valsetpreftypes.ModuleName: {authtypes.Staking}, } // appModules return modules to initialize module manager. @@ -142,6 +145,7 @@ func appModules( app.EpochsKeeper, ), tokenfactory.NewAppModule(*app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper), + valsetprefmodule.NewAppModule(appCodec, *app.ValidatorSetPreferenceKeeper), } } @@ -211,6 +215,7 @@ func OrderInitGenesis(allModuleNames []string) []string { poolincentivestypes.ModuleName, superfluidtypes.ModuleName, tokenfactorytypes.ModuleName, + valsetpreftypes.ModuleName, incentivestypes.ModuleName, epochstypes.ModuleName, lockuptypes.ModuleName, diff --git a/app/upgrades/v13/constants.go b/app/upgrades/v13/constants.go index 7779df096f6..cd42ff4813a 100644 --- a/app/upgrades/v13/constants.go +++ b/app/upgrades/v13/constants.go @@ -1,16 +1,19 @@ package v13 import ( - "github.com/osmosis-labs/osmosis/v12/app/upgrades" - store "github.com/cosmos/cosmos-sdk/store/types" + "github.com/osmosis-labs/osmosis/v12/app/upgrades" + valsetpreftypes "github.com/osmosis-labs/osmosis/v12/x/valset-pref/types" ) -// UpgradeName defines the on-chain upgrade name for the Osmosis v9 upgrade. +// UpgradeName defines the on-chain upgrade name for the Osmosis v13 upgrade. const UpgradeName = "v13" var Upgrade = upgrades.Upgrade{ UpgradeName: UpgradeName, CreateUpgradeHandler: CreateUpgradeHandler, - StoreUpgrades: store.StoreUpgrades{}, + StoreUpgrades: store.StoreUpgrades{ + Added: []string{valsetpreftypes.StoreKey}, + Deleted: []string{}, // double check bech32ibc + }, } diff --git a/osmoutils/slice_helper.go b/osmoutils/slice_helper.go index f4c14a7b975..a7ee4db4eb0 100644 --- a/osmoutils/slice_helper.go +++ b/osmoutils/slice_helper.go @@ -35,3 +35,17 @@ func ReverseSlice[T any](s []T) []T { } return s } + +// ContainsDuplicate checks if there are any duplicate +// elements in the slice. +func ContainsDuplicate[T any](arr []T) bool { + visited := make(map[any]bool, 0) + for i := 0; i < len(arr); i++ { + if visited[arr[i]] { + return true + } else { + visited[arr[i]] = true + } + } + return false +} diff --git a/proto/osmosis/validator-preference/v1beta1/query.proto b/proto/osmosis/valset-pref/v1beta1/query.proto similarity index 68% rename from proto/osmosis/validator-preference/v1beta1/query.proto rename to proto/osmosis/valset-pref/v1beta1/query.proto index 9a6d666c8e4..e2ed5a54ac8 100644 --- a/proto/osmosis/validator-preference/v1beta1/query.proto +++ b/proto/osmosis/valset-pref/v1beta1/query.proto @@ -1,11 +1,11 @@ syntax = "proto3"; -package osmosis.validatorpreference.v1beta1; +package osmosis.valsetpref.v1beta1; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; -import "osmosis/validator-preference/v1beta1/state.proto"; +import "osmosis/valset-pref/v1beta1/state.proto"; -option go_package = "github.com/osmosis-labs/osmosis/v12/x/validator-preference/client/queryproto"; +option go_package = "github.com/osmosis-labs/osmosis/v12/x/valset-pref/client/queryproto"; option (gogoproto.goproto_getters_all) = false; // Query defines the gRPC querier service. @@ -13,15 +13,14 @@ service Query { // Returns the list of ValidatorPreferences for the user. rpc UserValidatorPreferences(QueryUserValidatorPreferences) returns (QueryUserValidatorPreferenceResponse) { - option (google.api.http).get = - "/osmosis/validator-preference/v1beta1/{user}"; + option (google.api.http).get = "/osmosis/valset-pref/v1beta1/{address}"; } } // Request type for UserValidatorPreferences. message QueryUserValidatorPreferences { // user account address - string user = 1; + string address = 1; } // Response type the QueryUserValidatorPreferences query request diff --git a/proto/osmosis/validator-preference/v1beta1/state.proto b/proto/osmosis/valset-pref/v1beta1/state.proto similarity index 90% rename from proto/osmosis/validator-preference/v1beta1/state.proto rename to proto/osmosis/valset-pref/v1beta1/state.proto index cbfcf56a34d..3b1ee283714 100644 --- a/proto/osmosis/validator-preference/v1beta1/state.proto +++ b/proto/osmosis/valset-pref/v1beta1/state.proto @@ -1,10 +1,10 @@ syntax = "proto3"; -package osmosis.validatorpreference.v1beta1; +package osmosis.valsetpref.v1beta1; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; -option go_package = "github.com/osmosis-labs/osmosis/v12/x/validator-preference/types"; +option go_package = "github.com/osmosis-labs/osmosis/v12/x/valset-pref/types"; option (gogoproto.goproto_getters_all) = false; // ValidatorPreference defines the message structure for diff --git a/proto/osmosis/validator-preference/v1beta1/tx.proto b/proto/osmosis/valset-pref/v1beta1/tx.proto similarity index 92% rename from proto/osmosis/validator-preference/v1beta1/tx.proto rename to proto/osmosis/valset-pref/v1beta1/tx.proto index 00967e38c9a..e0ef71fdcfd 100644 --- a/proto/osmosis/validator-preference/v1beta1/tx.proto +++ b/proto/osmosis/valset-pref/v1beta1/tx.proto @@ -1,13 +1,13 @@ syntax = "proto3"; -package osmosis.validatorpreference.v1beta1; +package osmosis.valsetpref.v1beta1; import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; -import "osmosis/validator-preference/v1beta1/state.proto"; +import "osmosis/valset-pref/v1beta1/state.proto"; -option go_package = "github.com/osmosis-labs/osmosis/v12/x/validator-preference/types"; +option go_package = "github.com/osmosis-labs/osmosis/v12/x/valset-pref/types"; -// Msg defines the validator-preference modules's gRPC message service. +// Msg defines the valset-pref modules's gRPC message service. service Msg { // SetValidatorSetPreference creates a set of validator preference. // This message will process both create + update request. diff --git a/tests/e2e/scripts/rate_limiter.wasm b/tests/e2e/scripts/rate_limiter.wasm index f3f763f30a4..e19651209c4 100755 Binary files a/tests/e2e/scripts/rate_limiter.wasm and b/tests/e2e/scripts/rate_limiter.wasm differ diff --git a/x/validator-preference/README.md b/x/valset-pref/README.md similarity index 100% rename from x/validator-preference/README.md rename to x/valset-pref/README.md diff --git a/x/valset-pref/client/query_proto_wrap.go b/x/valset-pref/client/query_proto_wrap.go new file mode 100644 index 00000000000..8d597222851 --- /dev/null +++ b/x/valset-pref/client/query_proto_wrap.go @@ -0,0 +1,22 @@ +package client + +import ( + "context" + + validatorprefkeeper "github.com/osmosis-labs/osmosis/v12/x/valset-pref" + "github.com/osmosis-labs/osmosis/v12/x/valset-pref/client/queryproto" +) + +type Querier struct { + validatorprefkeeper.Keeper +} + +var _ queryproto.QueryServer = Querier{} + +func NewQuerier(k validatorprefkeeper.Keeper) Querier { + return Querier{k} +} + +func (q Querier) UserValidatorPreferences(ctx context.Context, req *queryproto.QueryUserValidatorPreferences) (*queryproto.QueryUserValidatorPreferenceResponse, error) { + return &queryproto.QueryUserValidatorPreferenceResponse{}, nil +} diff --git a/x/validator-preference/client/queryproto/query.pb.go b/x/valset-pref/client/queryproto/query.pb.go similarity index 81% rename from x/validator-preference/client/queryproto/query.pb.go rename to x/valset-pref/client/queryproto/query.pb.go index 3af9d73e681..4c160f8c932 100644 --- a/x/validator-preference/client/queryproto/query.pb.go +++ b/x/valset-pref/client/queryproto/query.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: osmosis/validator-preference/v1beta1/query.proto +// source: osmosis/valset-pref/v1beta1/query.proto package queryproto @@ -9,7 +9,7 @@ import ( _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" - types "github.com/osmosis-labs/osmosis/v12/x/validator-preference/types" + types "github.com/osmosis-labs/osmosis/v12/x/valset-pref/types" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" @@ -33,14 +33,14 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Request type for UserValidatorPreferences. type QueryUserValidatorPreferences struct { // user account address - User string `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` } func (m *QueryUserValidatorPreferences) Reset() { *m = QueryUserValidatorPreferences{} } func (m *QueryUserValidatorPreferences) String() string { return proto.CompactTextString(m) } func (*QueryUserValidatorPreferences) ProtoMessage() {} func (*QueryUserValidatorPreferences) Descriptor() ([]byte, []int) { - return fileDescriptor_888a45acbabdd269, []int{0} + return fileDescriptor_9ffbeb4123fe56ae, []int{0} } func (m *QueryUserValidatorPreferences) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -78,7 +78,7 @@ func (m *QueryUserValidatorPreferenceResponse) Reset() { *m = QueryUserV func (m *QueryUserValidatorPreferenceResponse) String() string { return proto.CompactTextString(m) } func (*QueryUserValidatorPreferenceResponse) ProtoMessage() {} func (*QueryUserValidatorPreferenceResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_888a45acbabdd269, []int{1} + return fileDescriptor_9ffbeb4123fe56ae, []int{1} } func (m *QueryUserValidatorPreferenceResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -108,37 +108,37 @@ func (m *QueryUserValidatorPreferenceResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryUserValidatorPreferenceResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*QueryUserValidatorPreferences)(nil), "osmosis.validatorpreference.v1beta1.QueryUserValidatorPreferences") - proto.RegisterType((*QueryUserValidatorPreferenceResponse)(nil), "osmosis.validatorpreference.v1beta1.QueryUserValidatorPreferenceResponse") + proto.RegisterType((*QueryUserValidatorPreferences)(nil), "osmosis.valsetpref.v1beta1.QueryUserValidatorPreferences") + proto.RegisterType((*QueryUserValidatorPreferenceResponse)(nil), "osmosis.valsetpref.v1beta1.QueryUserValidatorPreferenceResponse") } func init() { - proto.RegisterFile("osmosis/validator-preference/v1beta1/query.proto", fileDescriptor_888a45acbabdd269) + proto.RegisterFile("osmosis/valset-pref/v1beta1/query.proto", fileDescriptor_9ffbeb4123fe56ae) } -var fileDescriptor_888a45acbabdd269 = []byte{ +var fileDescriptor_9ffbeb4123fe56ae = []byte{ // 338 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0xc8, 0x2f, 0xce, 0xcd, - 0x2f, 0xce, 0x2c, 0xd6, 0x2f, 0x4b, 0xcc, 0xc9, 0x4c, 0x49, 0x2c, 0xc9, 0x2f, 0xd2, 0x2d, 0x28, - 0x4a, 0x4d, 0x4b, 0x2d, 0x4a, 0xcd, 0x4b, 0x4e, 0xd5, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, - 0xd4, 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x86, 0xea, - 0xd0, 0x83, 0xeb, 0x40, 0x68, 0xd0, 0x83, 0x6a, 0x90, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xab, - 0xd7, 0x07, 0xb1, 0x20, 0x5a,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x13, 0x1e, 0xcb, 0x31, - 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x4f, 0x7a, 0x66, 0x49, 0x46, 0x69, - 0x92, 0x5e, 0x72, 0x7e, 0x2e, 0xcc, 0x54, 0xdd, 0x9c, 0xc4, 0xa4, 0x62, 0x84, 0x15, 0x86, 0x46, - 0xfa, 0x15, 0xd8, 0x2d, 0x4a, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0x81, 0xa4, 0x51, 0x70, 0xba, 0x48, - 0x62, 0x03, 0x53, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x44, 0xbd, 0xf5, 0xa9, 0xdd, 0x02, + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0xcd, 0x4a, 0x03, 0x31, + 0x14, 0x85, 0x27, 0xfe, 0x62, 0xba, 0x1b, 0x5c, 0x0c, 0x83, 0xc6, 0x52, 0x44, 0xbb, 0x69, 0x42, + 0xeb, 0xaa, 0x3b, 0xa9, 0x2f, 0xa0, 0x05, 0x15, 0xdc, 0x65, 0xda, 0xdb, 0x71, 0x60, 0x3a, 0x19, + 0x73, 0xd3, 0xa2, 0x88, 0x08, 0x3e, 0x81, 0xe0, 0x43, 0xd9, 0x65, 0xc5, 0x8d, 0x2b, 0xd1, 0xd6, + 0x07, 0x91, 0xce, 0x0f, 0x55, 0xb0, 0xb3, 0x70, 0x95, 0x84, 0x7c, 0xf7, 0x9c, 0x7b, 0x72, 0x43, + 0xf7, 0x15, 0xf6, 0x15, 0x06, 0x28, 0x86, 0x32, 0x44, 0x30, 0xb5, 0x58, 0x43, 0x4f, 0x0c, 0xeb, + 0x1e, 0x18, 0x59, 0x17, 0x57, 0x03, 0xd0, 0x37, 0x3c, 0xd6, 0xca, 0x28, 0xdb, 0xcd, 0x40, 0x9e, + 0x82, 0x33, 0x8e, 0x67, 0x9c, 0xbb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 0x2d, 0x94, 0x1e, + 0xce, 0xc5, 0xeb, 0x0d, 0x71, 0xfd, 0xcb, 0xa2, 0x13, 0x06, 0x10, 0x99, 0xf4, 0xb3, 0x25, 0x23, + 0xf7, 0xd6, 0x92, 0xe5, 0xe0, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xbd, 0xc4, 0xe6, 0x56, 0x9d, 0x02, 0x00, 0x00, } @@ -168,7 +168,7 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { func (c *queryClient) UserValidatorPreferences(ctx context.Context, in *QueryUserValidatorPreferences, opts ...grpc.CallOption) (*QueryUserValidatorPreferenceResponse, error) { out := new(QueryUserValidatorPreferenceResponse) - err := c.cc.Invoke(ctx, "/osmosis.validatorpreference.v1beta1.Query/UserValidatorPreferences", in, out, opts...) + err := c.cc.Invoke(ctx, "/osmosis.valsetpref.v1beta1.Query/UserValidatorPreferences", in, out, opts...) if err != nil { return nil, err } @@ -203,7 +203,7 @@ func _Query_UserValidatorPreferences_Handler(srv interface{}, ctx context.Contex } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/osmosis.validatorpreference.v1beta1.Query/UserValidatorPreferences", + FullMethod: "/osmosis.valsetpref.v1beta1.Query/UserValidatorPreferences", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(QueryServer).UserValidatorPreferences(ctx, req.(*QueryUserValidatorPreferences)) @@ -212,7 +212,7 @@ func _Query_UserValidatorPreferences_Handler(srv interface{}, ctx context.Contex } var _Query_serviceDesc = grpc.ServiceDesc{ - ServiceName: "osmosis.validatorpreference.v1beta1.Query", + ServiceName: "osmosis.valsetpref.v1beta1.Query", HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ { @@ -221,7 +221,7 @@ var _Query_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "osmosis/validator-preference/v1beta1/query.proto", + Metadata: "osmosis/valset-pref/v1beta1/query.proto", } func (m *QueryUserValidatorPreferences) Marshal() (dAtA []byte, err error) { @@ -244,10 +244,10 @@ func (m *QueryUserValidatorPreferences) MarshalToSizedBuffer(dAtA []byte) (int, _ = i var l int _ = l - if len(m.User) > 0 { - i -= len(m.User) - copy(dAtA[i:], m.User) - i = encodeVarintQuery(dAtA, i, uint64(len(m.User))) + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) i-- dAtA[i] = 0xa } @@ -308,7 +308,7 @@ func (m *QueryUserValidatorPreferences) Size() (n int) { } var l int _ = l - l = len(m.User) + l = len(m.Address) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } @@ -367,7 +367,7 @@ func (m *QueryUserValidatorPreferences) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field User", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -395,7 +395,7 @@ func (m *QueryUserValidatorPreferences) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.User = string(dAtA[iNdEx:postIndex]) + m.Address = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex diff --git a/x/validator-preference/client/queryproto/query.pb.gw.go b/x/valset-pref/client/queryproto/query.pb.gw.go similarity index 92% rename from x/validator-preference/client/queryproto/query.pb.gw.go rename to x/valset-pref/client/queryproto/query.pb.gw.go index 00172683446..c79a1f8f501 100644 --- a/x/validator-preference/client/queryproto/query.pb.gw.go +++ b/x/valset-pref/client/queryproto/query.pb.gw.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: osmosis/validator-preference/v1beta1/query.proto +// source: osmosis/valset-pref/v1beta1/query.proto /* Package queryproto is a reverse proxy. @@ -44,15 +44,15 @@ func request_Query_UserValidatorPreferences_0(ctx context.Context, marshaler run _ = err ) - val, ok = pathParams["user"] + val, ok = pathParams["address"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") } - protoReq.User, err = runtime.String(val) + protoReq.Address, err = runtime.String(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) } msg, err := client.UserValidatorPreferences(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) @@ -71,15 +71,15 @@ func local_request_Query_UserValidatorPreferences_0(ctx context.Context, marshal _ = err ) - val, ok = pathParams["user"] + val, ok = pathParams["address"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") } - protoReq.User, err = runtime.String(val) + protoReq.Address, err = runtime.String(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) } msg, err := server.UserValidatorPreferences(ctx, &protoReq) @@ -181,7 +181,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_UserValidatorPreferences_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"osmosis", "validator-preference", "v1beta1", "user"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_UserValidatorPreferences_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"osmosis", "valset-pref", "v1beta1", "address"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( diff --git a/x/valset-pref/keeper.go b/x/valset-pref/keeper.go new file mode 100644 index 00000000000..ffa5184e1e8 --- /dev/null +++ b/x/valset-pref/keeper.go @@ -0,0 +1,53 @@ +package keeper + +import ( + "fmt" + + "github.com/tendermint/tendermint/libs/log" + + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/gogo/protobuf/proto" + "github.com/osmosis-labs/osmosis/v12/osmoutils" + "github.com/osmosis-labs/osmosis/v12/x/valset-pref/types" +) + +type Keeper struct { + storeKey sdk.StoreKey + paramSpace paramtypes.Subspace + stakingKeeper types.StakingInterface +} + +func NewKeeper(storeKey sdk.StoreKey, + paramSpace paramtypes.Subspace, + stakingKeeper types.StakingInterface, +) Keeper { + return Keeper{ + storeKey: storeKey, + paramSpace: paramSpace, + stakingKeeper: stakingKeeper, + } +} + +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +func (k Keeper) SetValidatorSetPreferences(ctx sdk.Context, delegator string, validators types.ValidatorSetPreferences) { + store := ctx.KVStore(k.storeKey) + osmoutils.MustSet(store, []byte(delegator), &validators) +} + +func (k Keeper) GetValidatorSetPreference(ctx sdk.Context, delegator string) (types.ValidatorSetPreferences, bool) { + store := ctx.KVStore(k.storeKey) + bz := store.Get([]byte(delegator)) + if bz == nil { + return types.ValidatorSetPreferences{}, false + } + var valsetPref types.ValidatorSetPreferences + if err := proto.Unmarshal(bz, &valsetPref); err != nil { + return types.ValidatorSetPreferences{}, false + } + + return valsetPref, true +} diff --git a/x/valset-pref/keeper_test.go b/x/valset-pref/keeper_test.go new file mode 100644 index 00000000000..3498c2eccda --- /dev/null +++ b/x/valset-pref/keeper_test.go @@ -0,0 +1,52 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/osmosis-labs/osmosis/v12/app/apptesting" + "github.com/osmosis-labs/osmosis/v12/x/valset-pref/types" + "github.com/stretchr/testify/suite" +) + +type KeeperTestSuite struct { + apptesting.KeeperTestHelper +} + +func (suite *KeeperTestSuite) SetupTest() { + suite.Setup() +} + +// SetupMultipleValidators setups "numValidator" validators and returns their address in string +func (suite *KeeperTestSuite) SetupMultipleValidators(numValidator int) []string { + valAddrs := []string{} + for i := 0; i < numValidator; i++ { + valAddr := suite.SetupValidator(stakingtypes.Bonded) + valAddrs = append(valAddrs, valAddr.String()) + } + return valAddrs +} + +func (suite *KeeperTestSuite) PrepareDelegateToValidatorSet() []types.ValidatorPreference { + valAddrs := suite.SetupMultipleValidators(3) + valPreferences := []types.ValidatorPreference{ + { + ValOperAddress: valAddrs[0], + Weight: sdk.NewDecWithPrec(5, 1), + }, + { + ValOperAddress: valAddrs[1], + Weight: sdk.NewDecWithPrec(3, 1), + }, + { + ValOperAddress: valAddrs[2], + Weight: sdk.NewDecWithPrec(2, 1), + }, + } + return valPreferences +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(KeeperTestSuite)) +} diff --git a/x/valset-pref/msg_server.go b/x/valset-pref/msg_server.go new file mode 100644 index 00000000000..22be1b7ff88 --- /dev/null +++ b/x/valset-pref/msg_server.go @@ -0,0 +1,50 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/osmosis-labs/osmosis/v12/x/valset-pref/types" +) + +type msgServer struct { + keeper *Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper *Keeper) types.MsgServer { + return &msgServer{ + keeper: keeper, + } +} + +var _ types.MsgServer = msgServer{} + +func (server msgServer) SetValidatorSetPreference(goCtx context.Context, msg *types.MsgSetValidatorSetPreference) (*types.MsgSetValidatorSetPreferenceResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + err := server.keeper.SetupValidatorSetPreference(ctx, msg.Delegator, msg.Preferences) + if err != nil { + return nil, err + } + + setMsg := types.ValidatorSetPreferences{ + Preferences: msg.Preferences, + } + + server.keeper.SetValidatorSetPreferences(ctx, msg.Delegator, setMsg) + return &types.MsgSetValidatorSetPreferenceResponse{}, nil +} + +func (server msgServer) DelegateToValidatorSet(goCtx context.Context, msg *types.MsgDelegateToValidatorSet) (*types.MsgDelegateToValidatorSetResponse, error) { + return &types.MsgDelegateToValidatorSetResponse{}, nil +} + +func (server msgServer) UndelegateFromValidatorSet(goCtx context.Context, msg *types.MsgUndelegateFromValidatorSet) (*types.MsgUndelegateFromValidatorSetResponse, error) { + return &types.MsgUndelegateFromValidatorSetResponse{}, nil +} + +func (server msgServer) WithdrawDelegationRewards(goCtx context.Context, msg *types.MsgWithdrawDelegationRewards) (*types.MsgWithdrawDelegationRewardsResponse, error) { + return &types.MsgWithdrawDelegationRewardsResponse{}, nil +} diff --git a/x/valset-pref/msg_server_test.go b/x/valset-pref/msg_server_test.go new file mode 100644 index 00000000000..2a97e899068 --- /dev/null +++ b/x/valset-pref/msg_server_test.go @@ -0,0 +1,126 @@ +package keeper_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + valPref "github.com/osmosis-labs/osmosis/v12/x/valset-pref" + "github.com/osmosis-labs/osmosis/v12/x/valset-pref/types" +) + +func (suite *KeeperTestSuite) TestSetValidatorSetPreference() { + suite.SetupTest() + + // setup 3 validators + valAddrs := suite.SetupMultipleValidators(3) + + tests := []struct { + name string + delegator sdk.AccAddress + preferences []types.ValidatorPreference + expectPass bool + }{ + { + name: "creation of new validator set", + delegator: sdk.AccAddress([]byte("addr1---------------")), + preferences: []types.ValidatorPreference{ + { + ValOperAddress: valAddrs[0], + Weight: sdk.NewDecWithPrec(5, 1), + }, + { + ValOperAddress: valAddrs[1], + Weight: sdk.NewDecWithPrec(3, 1), + }, + { + ValOperAddress: valAddrs[2], + Weight: sdk.NewDecWithPrec(2, 1), + }, + }, + expectPass: true, + }, + { + name: "update 2 validator weights but leave the 3rd one as is", + delegator: sdk.AccAddress([]byte("addr1---------------")), + preferences: []types.ValidatorPreference{ + { + ValOperAddress: valAddrs[0], + Weight: sdk.NewDecWithPrec(5, 1), + }, + { + ValOperAddress: valAddrs[1], + Weight: sdk.NewDecWithPrec(4, 1), + }, + { + ValOperAddress: valAddrs[2], + Weight: sdk.NewDecWithPrec(1, 1), + }, + }, + expectPass: true, + }, + { + name: "update existing validator with same valAddr and weights", + delegator: sdk.AccAddress([]byte("addr1---------------")), + preferences: []types.ValidatorPreference{ + { + ValOperAddress: valAddrs[0], + Weight: sdk.NewDecWithPrec(5, 1), + }, + { + ValOperAddress: valAddrs[1], + Weight: sdk.NewDecWithPrec(4, 1), + }, + { + ValOperAddress: valAddrs[2], + Weight: sdk.NewDecWithPrec(1, 1), + }, + }, + expectPass: false, + }, + { + name: "update existing validator with same valAddr but different weights", + delegator: sdk.AccAddress([]byte("addr1---------------")), + preferences: []types.ValidatorPreference{ + { + ValOperAddress: valAddrs[0], + Weight: sdk.NewDecWithPrec(1, 1), + }, + { + ValOperAddress: valAddrs[1], + Weight: sdk.NewDecWithPrec(2, 1), + }, + { + ValOperAddress: valAddrs[2], + Weight: sdk.NewDecWithPrec(7, 1), + }, + }, + expectPass: true, + }, + { + name: "create validator set with unknown validator address", + delegator: sdk.AccAddress([]byte("addr1---------------")), + preferences: []types.ValidatorPreference{ + { + ValOperAddress: "addr1---------------", + Weight: sdk.NewDec(1), + }, + }, + expectPass: false, + }, + } + + for _, test := range tests { + suite.Run(test.name, func() { + // setup message server + msgServer := valPref.NewMsgServerImpl(suite.App.ValidatorSetPreferenceKeeper) + c := sdk.WrapSDKContext(suite.Ctx) + + // call the create validator set preference + _, err := msgServer.SetValidatorSetPreference(c, types.NewMsgSetValidatorSetPreference(test.delegator, test.preferences)) + if test.expectPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + } + + }) + } +} diff --git a/x/valset-pref/types/codec.go b/x/valset-pref/types/codec.go new file mode 100644 index 00000000000..995b19f8034 --- /dev/null +++ b/x/valset-pref/types/codec.go @@ -0,0 +1,31 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgSetValidatorSetPreference{}, "osmosis/valset-pref/MsgSetValidatorSetPreference", nil) + cdc.RegisterConcrete(&MsgDelegateToValidatorSet{}, "osmosis/valset-pref/MsgDelegateToValidatorSet", nil) + cdc.RegisterConcrete(&MsgUndelegateFromValidatorSet{}, "osmosis/valset-pref/MsgUndelegateFromValidatorSet", nil) + cdc.RegisterConcrete(&MsgWithdrawDelegationRewards{}, "osmosis/valset-pref/MsgWithdrawDelegationRewards", nil) +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgSetValidatorSetPreference{}, + &MsgDelegateToValidatorSet{}, + &MsgUndelegateFromValidatorSet{}, + &MsgWithdrawDelegationRewards{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) +) diff --git a/x/valset-pref/types/expected_interfaces.go b/x/valset-pref/types/expected_interfaces.go new file mode 100644 index 00000000000..7a54060e1d2 --- /dev/null +++ b/x/valset-pref/types/expected_interfaces.go @@ -0,0 +1,17 @@ +package types + +import ( + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +// StakingInterface expected staking keeper. +type StakingInterface interface { + GetAllValidators(ctx sdk.Context) (validators []stakingtypes.Validator) + GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, found bool) + Delegate(ctx sdk.Context, delAddr sdk.AccAddress, bondAmt sdk.Int, tokenSrc stakingtypes.BondStatus, validator stakingtypes.Validator, subtractAccount bool) (newShares sdk.Dec, err error) + GetDelegation(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (delegation stakingtypes.Delegation, found bool) + Undelegate(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount sdk.Dec) (time.Time, error) +} diff --git a/x/valset-pref/types/keys.go b/x/valset-pref/types/keys.go new file mode 100644 index 00000000000..24347ccf83e --- /dev/null +++ b/x/valset-pref/types/keys.go @@ -0,0 +1,15 @@ +package types + +var ( + // ModuleName defines the module name + ModuleName = "validatorsetpreference" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // KeyPrefixValidatorSet defines prefix key for validator set. + KeyPrefixValidatorSet = []byte{0x01} + + // QuerierRoute defines the module's query routing key + QuerierRoute = ModuleName +) diff --git a/x/valset-pref/types/msgs.go b/x/valset-pref/types/msgs.go new file mode 100644 index 00000000000..d0288b35a8a --- /dev/null +++ b/x/valset-pref/types/msgs.go @@ -0,0 +1,176 @@ +package types + +import ( + fmt "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/osmosis-labs/osmosis/v12/osmoutils" +) + +// constants +const ( + TypeMsgSetValidatorSetPreference = "set_validator_set_preference" +) + +var _ sdk.Msg = &MsgSetValidatorSetPreference{} + +// NewMsgCreateValidatorSetPreference creates a msg to create a validator-set preference. +func NewMsgSetValidatorSetPreference(delegator sdk.AccAddress, preferences []ValidatorPreference) *MsgSetValidatorSetPreference { + return &MsgSetValidatorSetPreference{ + Delegator: delegator.String(), + Preferences: preferences, + } +} + +func (m MsgSetValidatorSetPreference) Type() string { return TypeMsgSetValidatorSetPreference } +func (m MsgSetValidatorSetPreference) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(m.Delegator) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid delegator address (%s)", err) + } + + totalWeight := sdk.ZeroDec() + validatorAddrs := []string{} + for _, validator := range m.Preferences { + _, err := sdk.ValAddressFromBech32(validator.ValOperAddress) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid validator address (%s)", err) + } + + totalWeight = totalWeight.Add(validator.Weight) + validatorAddrs = append(validatorAddrs, validator.ValOperAddress) + } + + // check that all the validator address are unique + containsDuplicate := osmoutils.ContainsDuplicate(validatorAddrs) + if containsDuplicate { + return fmt.Errorf("The validator operator address are duplicated") + } + + // check if the total validator distribution weights equal 1 + if !totalWeight.Equal(sdk.OneDec()) { + return fmt.Errorf("The weights allocated to the validators do not add up to 1, Got: %d", totalWeight) + } + + return nil +} + +func (m MsgSetValidatorSetPreference) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) +} + +// GetSigners takes a create validator-set message and returns the delegator in a byte array. +func (m MsgSetValidatorSetPreference) GetSigners() []sdk.AccAddress { + delegator, _ := sdk.AccAddressFromBech32(m.Delegator) + return []sdk.AccAddress{delegator} +} + +// constants +const ( + TypeMsgDelegateToValidatorSet = "delegate_to_validator_set" +) + +var _ sdk.Msg = &MsgDelegateToValidatorSet{} + +// NewMsgMsgStakeToValidatorSet creates a msg to stake to a validator set. +func NewMsgMsgStakeToValidatorSet(delegator sdk.AccAddress, coin sdk.Coin) *MsgDelegateToValidatorSet { + return &MsgDelegateToValidatorSet{ + Delegator: delegator.String(), + Coin: coin, + } +} + +func (m MsgDelegateToValidatorSet) Type() string { return TypeMsgDelegateToValidatorSet } +func (m MsgDelegateToValidatorSet) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(m.Delegator) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err) + } + + if !m.Coin.IsValid() { + return fmt.Errorf("The stake coin is not valid") + } + + return nil +} + +func (m MsgDelegateToValidatorSet) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) +} + +func (m MsgDelegateToValidatorSet) GetSigners() []sdk.AccAddress { + delegator, _ := sdk.AccAddressFromBech32(m.Delegator) + return []sdk.AccAddress{delegator} +} + +// constants +const ( + TypeMsgUndelegateFromValidatorSet = "undelegate_from_validator_set" +) + +var _ sdk.Msg = &MsgUndelegateFromValidatorSet{} + +// NewMsgMsgStakeToValidatorSet creates a msg to stake to a validator. +func NewMsgUndelegateFromValidatorSet(delegator sdk.AccAddress, coin sdk.Coin) *MsgUndelegateFromValidatorSet { + return &MsgUndelegateFromValidatorSet{ + Delegator: delegator.String(), + Coin: coin, + } +} + +func (m MsgUndelegateFromValidatorSet) Type() string { return TypeMsgUndelegateFromValidatorSet } +func (m MsgUndelegateFromValidatorSet) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(m.Delegator) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err) + } + + if !m.Coin.IsValid() { + return fmt.Errorf("The stake coin is not valid") + } + + return nil +} + +func (m MsgUndelegateFromValidatorSet) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) +} + +func (m MsgUndelegateFromValidatorSet) GetSigners() []sdk.AccAddress { + delegator, _ := sdk.AccAddressFromBech32(m.Delegator) + return []sdk.AccAddress{delegator} +} + +// constants +const ( + TypeMsgWithdrawDelegationRewards = "withdraw_delegation_rewards" +) + +var _ sdk.Msg = &MsgWithdrawDelegationRewards{} + +// NewMsgMsgStakeToValidatorSet creates a msg to stake to a validator. +func NewMsgWithdrawDelegationRewards(delegator sdk.AccAddress) *MsgWithdrawDelegationRewards { + return &MsgWithdrawDelegationRewards{ + Delegator: delegator.String(), + } +} + +func (m MsgWithdrawDelegationRewards) Type() string { return TypeMsgWithdrawDelegationRewards } +func (m MsgWithdrawDelegationRewards) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(m.Delegator) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err) + } + + return nil +} + +func (m MsgWithdrawDelegationRewards) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) +} + +func (m MsgWithdrawDelegationRewards) GetSigners() []sdk.AccAddress { + delegator, _ := sdk.AccAddressFromBech32(m.Delegator) + return []sdk.AccAddress{delegator} +} diff --git a/x/valset-pref/types/msgs_test.go b/x/valset-pref/types/msgs_test.go new file mode 100644 index 00000000000..85456aca4b5 --- /dev/null +++ b/x/valset-pref/types/msgs_test.go @@ -0,0 +1,157 @@ +package types_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + "github.com/osmosis-labs/osmosis/v12/app/apptesting" + appParams "github.com/osmosis-labs/osmosis/v12/app/params" + "github.com/osmosis-labs/osmosis/v12/x/valset-pref/types" +) + +func TestMsgSetValidatorSetPreference(t *testing.T) { + appParams.SetAddressPrefixes() + addr1, invalidAddr := apptesting.GenerateTestAddrs() + + tests := []struct { + name string + msg types.MsgSetValidatorSetPreference + expectPass bool + }{ + { + name: "proper msg", + msg: types.MsgSetValidatorSetPreference{ + Delegator: addr1, + Preferences: []types.ValidatorPreference{ + { + ValOperAddress: "osmovaloper1x2cfenmflhj3dwm2ph6nkgqr3nppkg86fxaymg", + Weight: sdk.NewDecWithPrec(5, 1), + }, + { + ValOperAddress: "osmovaloper1jcr68jghzm24zwe78zuhz7xahua8429erxk7vm", + Weight: sdk.NewDecWithPrec(3, 1), + }, + { + ValOperAddress: "osmovaloper1gqsr38e4zteekwr6kq5se5jpadafqmcfyz8jds", + Weight: sdk.NewDecWithPrec(2, 1), + }, + }, + }, + expectPass: true, + }, + { + name: "duplicate validator msg", + msg: types.MsgSetValidatorSetPreference{ + Delegator: addr1, + Preferences: []types.ValidatorPreference{ + { + ValOperAddress: "osmovaloper1x2cfenmflhj3dwm2ph6nkgqr3nppkg86fxaymg", + Weight: sdk.NewDecWithPrec(6, 1), + }, + { + ValOperAddress: "osmovaloper1x2cfenmflhj3dwm2ph6nkgqr3nppkg86fxaymg", + Weight: sdk.NewDecWithPrec(4, 1), + }, + { + ValOperAddress: "osmovaloper1jcr68jghzm24zwe78zuhz7xahua8429erxk7vm", + Weight: sdk.NewDecWithPrec(2, 1), + }, + }, + }, + expectPass: false, + }, + { + name: "invalid delegator", + msg: types.MsgSetValidatorSetPreference{ + Delegator: invalidAddr, + Preferences: []types.ValidatorPreference{ + { + ValOperAddress: "osmovaloper1x2cfenmflhj3dwm2ph6nkgqr3nppkg86fxaymg", + Weight: sdk.NewDec(1), + }, + }, + }, + expectPass: false, + }, + { + name: "invalid validator address", + msg: types.MsgSetValidatorSetPreference{ + Delegator: addr1, + Preferences: []types.ValidatorPreference{ + { + ValOperAddress: "osmovaloper1x2cfenmflhj3dwm2ph6nkgqr3nppkg86fxay", // invalid address + Weight: sdk.NewDecWithPrec(2, 1), + }, + { + ValOperAddress: "osmovaloper1jcr68jghzm24zwe78zuhz7xahua8429erxk7vm", + Weight: sdk.NewDecWithPrec(2, 1), + }, + { + ValOperAddress: "osmovaloper1x2cfenmflhj3dwm2ph6nkgqr3nppkg86fxaymg", + Weight: sdk.NewDecWithPrec(6, 1), + }, + }, + }, + expectPass: false, + }, + { + name: "weights > 1", + msg: types.MsgSetValidatorSetPreference{ + Delegator: addr1, + Preferences: []types.ValidatorPreference{ + { + ValOperAddress: "osmovaloper1x2cfenmflhj3dwm2ph6nkgqr3nppkg86fxaymg", + Weight: sdk.NewDecWithPrec(5, 1), + }, + { + ValOperAddress: "osmovaloper1jcr68jghzm24zwe78zuhz7xahua8429erxk7vm", + Weight: sdk.NewDecWithPrec(3, 1), + }, + { + ValOperAddress: "osmovaloper1gqsr38e4zteekwr6kq5se5jpadafqmcfyz8jds", + Weight: sdk.NewDecWithPrec(3, 1), + }, + }, + }, + expectPass: false, + }, + { + name: "weights < 1", + msg: types.MsgSetValidatorSetPreference{ + Delegator: addr1, + Preferences: []types.ValidatorPreference{ + { + ValOperAddress: "osmovaloper1x2cfenmflhj3dwm2ph6nkgqr3nppkg86fxaymg", + Weight: sdk.NewDecWithPrec(2, 1), + }, + { + ValOperAddress: "osmovaloper1jcr68jghzm24zwe78zuhz7xahua8429erxk7vm", + Weight: sdk.NewDecWithPrec(2, 1), + }, + { + ValOperAddress: "osmovaloper1gqsr38e4zteekwr6kq5se5jpadafqmcfyz8jds", + Weight: sdk.NewDecWithPrec(2, 1), + }, + }, + }, + expectPass: false, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + if test.expectPass { + require.NoError(t, test.msg.ValidateBasic(), "test: %v", test.name) + require.Equal(t, test.msg.Type(), "set_validator_set_preference") + signers := test.msg.GetSigners() + require.Equal(t, len(signers), 1) + require.Equal(t, signers[0].String(), addr1) + } else { + require.Error(t, test.msg.ValidateBasic(), "test: %v", test.name) + } + }) + } + +} diff --git a/x/validator-preference/types/state.pb.go b/x/valset-pref/types/state.pb.go similarity index 82% rename from x/validator-preference/types/state.pb.go rename to x/valset-pref/types/state.pb.go index 467994f7447..0874415d570 100644 --- a/x/validator-preference/types/state.pb.go +++ b/x/valset-pref/types/state.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: osmosis/validator-preference/v1beta1/state.proto +// source: osmosis/valset-pref/v1beta1/state.proto package types @@ -42,7 +42,7 @@ func (m *ValidatorPreference) Reset() { *m = ValidatorPreference{} } func (m *ValidatorPreference) String() string { return proto.CompactTextString(m) } func (*ValidatorPreference) ProtoMessage() {} func (*ValidatorPreference) Descriptor() ([]byte, []int) { - return fileDescriptor_2f4199f1be974865, []int{0} + return fileDescriptor_d3010474a5b89fce, []int{0} } func (m *ValidatorPreference) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -84,7 +84,7 @@ func (m *ValidatorSetPreferences) Reset() { *m = ValidatorSetPreferences func (m *ValidatorSetPreferences) String() string { return proto.CompactTextString(m) } func (*ValidatorSetPreferences) ProtoMessage() {} func (*ValidatorSetPreferences) Descriptor() ([]byte, []int) { - return fileDescriptor_2f4199f1be974865, []int{1} + return fileDescriptor_d3010474a5b89fce, []int{1} } func (m *ValidatorSetPreferences) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -114,39 +114,39 @@ func (m *ValidatorSetPreferences) XXX_DiscardUnknown() { var xxx_messageInfo_ValidatorSetPreferences proto.InternalMessageInfo func init() { - proto.RegisterType((*ValidatorPreference)(nil), "osmosis.validatorpreference.v1beta1.ValidatorPreference") - proto.RegisterType((*ValidatorSetPreferences)(nil), "osmosis.validatorpreference.v1beta1.ValidatorSetPreferences") + proto.RegisterType((*ValidatorPreference)(nil), "osmosis.valsetpref.v1beta1.ValidatorPreference") + proto.RegisterType((*ValidatorSetPreferences)(nil), "osmosis.valsetpref.v1beta1.ValidatorSetPreferences") } func init() { - proto.RegisterFile("osmosis/validator-preference/v1beta1/state.proto", fileDescriptor_2f4199f1be974865) + proto.RegisterFile("osmosis/valset-pref/v1beta1/state.proto", fileDescriptor_d3010474a5b89fce) } -var fileDescriptor_2f4199f1be974865 = []byte{ - // 358 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x41, 0x4b, 0xfb, 0x30, - 0x18, 0xc6, 0x9b, 0xfd, 0x61, 0xf0, 0xef, 0x40, 0xa4, 0x0a, 0x1b, 0x53, 0xd2, 0x51, 0x41, 0x76, - 0x59, 0xe2, 0xe6, 0x45, 0x3c, 0xe9, 0x50, 0xaf, 0xca, 0x04, 0x0f, 0x1e, 0x1c, 0x69, 0xfb, 0xda, - 0x15, 0xbb, 0xa6, 0x24, 0xb1, 0xba, 0x6f,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xd2, 0x92, 0xee, - 0x03, 0x55, 0xa3, 0x08, 0x24, 0x39, 0x03, 0xa7, 0x97, 0xd3, 0xd6, 0x2b, 0xd2, 0xab, 0x85, 0xcd, - 0x6b, 0x50, 0x4b, 0xa7, 0xd2, 0x88, 0xf5, 0xca, 0xb2, 0x19, 0xb2, 0x56, 0x6a, 0xfc, 0x6b, 0x56, - 0x3a, 0x47, 0xe4, 0x0f, 0x1d, 0x23, 0x6b, 0x92, 0x77, 0xeb, 0x0b, 0x8b, 0xf3, 0xc4, 0x34, 0xb2, - 0x8c, 0x2b, 0xd2, 0x56, 0x6f, 0xf5, 0xa1, 0xee, 0xdd, 0xf8, 0x0b, 0x6b, 0xe3, 0x29, 0x46, 0x93, - 0x29, 0x46, 0x9f, 0x53, 0x8c, 0x5e, 0x66, 0x58, 0x9b, 0xcc, 0xb0, 0xf6, 0x3e, 0xc3, 0xda, 0xed, - 0xc9, 0x4a, 0xc2, 0xdc, 0x4a, 0x2b, 0x60, 0xb6, 0xa4, 0xc5, 0xec, 0xdb, 0x1d, 0xfa, 0xbc, 0xfe, - 0x07, 0xa4, 0xf9, 0xed, 0x72, 0x3a, 0xa1, 0xc3, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x10, 0xdc, - 0x3d, 0x1c, 0x2e, 0x02, 0x00, 0x00, +var fileDescriptor_d3010474a5b89fce = []byte{ + // 355 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xcf, 0x4a, 0xeb, 0x40, + 0x18, 0xc5, 0x93, 0x5e, 0x28, 0xdc, 0x14, 0x44, 0xa2, 0xd0, 0x12, 0x25, 0x29, 0x59, 0x68, 0x37, + 0x9d, 0xa1, 0x75, 0x21, 0xb8, 0xb3, 0xa8, 0x5b, 0xa5, 0xa2, 0x0b, 0x37, 0x65, 0x92, 0x7c, 0x4d, + 0x83, 0x93, 0xcc, 0x30, 0x33, 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, 0x32, 0xb8, 0xc7, 0x6a, + 0xcc, 0x41, 0xa2, 0x33, 0xf0, 0xfb, 0xa5, 0xda, 0x7d, 0xd6, 0x8d, 0xfa, 0xca, 0xe6, 0x35, 0xa8, + 0xb5, 0x53, 0x69, 0xc6, 0x46, 0x8d, 0xaf, 0x8f, 0x8d, 0x4a, 0xf3, 0x5f, 0xab, 0xd6, 0xc5, 0xe8, + 0xef, 0x8f, 0x42, 0xbf, 0x04, 0xee, 0x59, 0x4b, 0x67, 0x8b, 0xcc, 0x31, 0x8b, 0x68, 0x1b, 0x13, + 0xdd, 0xfe, 0xe6, 0xfc, 0xde, 0xcd, 0xe4, 0xd3, 0xd6, 0x26, 0x33, 0x5b, 0x9f, 0xce, 0x6c, 0xfd, + 0x63, 0x66, 0xeb, 0x2f, 0x73, 0x5b, 0x9b, 0xce, 0x6d, 0xed, 0x6d, 0x6e, 0x6b, 0x77, 0xc7, 0x1b, + 0xc1, 0x4a, 0x07, 0x6d, 0x4a, 0x3c, 0x89, 0x57, 0x05, 0x77, 0xba, 0xf8, 0xe9, 0x5b, 0xcd, 0x79, + 0x5a, 0xaf, 0x9a, 0xf7, 0x71, 0xf4, 0x15, 0x00, 0x00, 0xff, 0xff, 0x6d, 0x8b, 0x26, 0x51, 0x0a, + 0x02, 0x00, 0x00, } func (m *ValidatorPreference) Marshal() (dAtA []byte, err error) { diff --git a/x/validator-preference/types/tx.pb.go b/x/valset-pref/types/tx.pb.go similarity index 89% rename from x/validator-preference/types/tx.pb.go rename to x/valset-pref/types/tx.pb.go index f1450087091..96bffff9b22 100644 --- a/x/validator-preference/types/tx.pb.go +++ b/x/valset-pref/types/tx.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: osmosis/validator-preference/v1beta1/tx.proto +// source: osmosis/valset-pref/v1beta1/tx.proto package types @@ -41,7 +41,7 @@ func (m *MsgSetValidatorSetPreference) Reset() { *m = MsgSetValidatorSet func (m *MsgSetValidatorSetPreference) String() string { return proto.CompactTextString(m) } func (*MsgSetValidatorSetPreference) ProtoMessage() {} func (*MsgSetValidatorSetPreference) Descriptor() ([]byte, []int) { - return fileDescriptor_fa9fa79f914b826d, []int{0} + return fileDescriptor_daa95be02b2fc560, []int{0} } func (m *MsgSetValidatorSetPreference) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -91,7 +91,7 @@ func (m *MsgSetValidatorSetPreferenceResponse) Reset() { *m = MsgSetVali func (m *MsgSetValidatorSetPreferenceResponse) String() string { return proto.CompactTextString(m) } func (*MsgSetValidatorSetPreferenceResponse) ProtoMessage() {} func (*MsgSetValidatorSetPreferenceResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fa9fa79f914b826d, []int{1} + return fileDescriptor_daa95be02b2fc560, []int{1} } func (m *MsgSetValidatorSetPreferenceResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -136,7 +136,7 @@ func (m *MsgDelegateToValidatorSet) Reset() { *m = MsgDelegateToValidato func (m *MsgDelegateToValidatorSet) String() string { return proto.CompactTextString(m) } func (*MsgDelegateToValidatorSet) ProtoMessage() {} func (*MsgDelegateToValidatorSet) Descriptor() ([]byte, []int) { - return fileDescriptor_fa9fa79f914b826d, []int{2} + return fileDescriptor_daa95be02b2fc560, []int{2} } func (m *MsgDelegateToValidatorSet) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -186,7 +186,7 @@ func (m *MsgDelegateToValidatorSetResponse) Reset() { *m = MsgDelegateTo func (m *MsgDelegateToValidatorSetResponse) String() string { return proto.CompactTextString(m) } func (*MsgDelegateToValidatorSetResponse) ProtoMessage() {} func (*MsgDelegateToValidatorSetResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fa9fa79f914b826d, []int{3} + return fileDescriptor_daa95be02b2fc560, []int{3} } func (m *MsgDelegateToValidatorSetResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -230,7 +230,7 @@ func (m *MsgUndelegateFromValidatorSet) Reset() { *m = MsgUndelegateFrom func (m *MsgUndelegateFromValidatorSet) String() string { return proto.CompactTextString(m) } func (*MsgUndelegateFromValidatorSet) ProtoMessage() {} func (*MsgUndelegateFromValidatorSet) Descriptor() ([]byte, []int) { - return fileDescriptor_fa9fa79f914b826d, []int{4} + return fileDescriptor_daa95be02b2fc560, []int{4} } func (m *MsgUndelegateFromValidatorSet) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -280,7 +280,7 @@ func (m *MsgUndelegateFromValidatorSetResponse) Reset() { *m = MsgUndele func (m *MsgUndelegateFromValidatorSetResponse) String() string { return proto.CompactTextString(m) } func (*MsgUndelegateFromValidatorSetResponse) ProtoMessage() {} func (*MsgUndelegateFromValidatorSetResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fa9fa79f914b826d, []int{5} + return fileDescriptor_daa95be02b2fc560, []int{5} } func (m *MsgUndelegateFromValidatorSetResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -320,7 +320,7 @@ func (m *MsgWithdrawDelegationRewards) Reset() { *m = MsgWithdrawDelegat func (m *MsgWithdrawDelegationRewards) String() string { return proto.CompactTextString(m) } func (*MsgWithdrawDelegationRewards) ProtoMessage() {} func (*MsgWithdrawDelegationRewards) Descriptor() ([]byte, []int) { - return fileDescriptor_fa9fa79f914b826d, []int{6} + return fileDescriptor_daa95be02b2fc560, []int{6} } func (m *MsgWithdrawDelegationRewards) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -363,7 +363,7 @@ func (m *MsgWithdrawDelegationRewardsResponse) Reset() { *m = MsgWithdra func (m *MsgWithdrawDelegationRewardsResponse) String() string { return proto.CompactTextString(m) } func (*MsgWithdrawDelegationRewardsResponse) ProtoMessage() {} func (*MsgWithdrawDelegationRewardsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fa9fa79f914b826d, []int{7} + return fileDescriptor_daa95be02b2fc560, []int{7} } func (m *MsgWithdrawDelegationRewardsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -393,55 +393,55 @@ func (m *MsgWithdrawDelegationRewardsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgWithdrawDelegationRewardsResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*MsgSetValidatorSetPreference)(nil), "osmosis.validatorpreference.v1beta1.MsgSetValidatorSetPreference") - proto.RegisterType((*MsgSetValidatorSetPreferenceResponse)(nil), "osmosis.validatorpreference.v1beta1.MsgSetValidatorSetPreferenceResponse") - proto.RegisterType((*MsgDelegateToValidatorSet)(nil), "osmosis.validatorpreference.v1beta1.MsgDelegateToValidatorSet") - proto.RegisterType((*MsgDelegateToValidatorSetResponse)(nil), "osmosis.validatorpreference.v1beta1.MsgDelegateToValidatorSetResponse") - proto.RegisterType((*MsgUndelegateFromValidatorSet)(nil), "osmosis.validatorpreference.v1beta1.MsgUndelegateFromValidatorSet") - proto.RegisterType((*MsgUndelegateFromValidatorSetResponse)(nil), "osmosis.validatorpreference.v1beta1.MsgUndelegateFromValidatorSetResponse") - proto.RegisterType((*MsgWithdrawDelegationRewards)(nil), "osmosis.validatorpreference.v1beta1.MsgWithdrawDelegationRewards") - proto.RegisterType((*MsgWithdrawDelegationRewardsResponse)(nil), "osmosis.validatorpreference.v1beta1.MsgWithdrawDelegationRewardsResponse") + proto.RegisterType((*MsgSetValidatorSetPreference)(nil), "osmosis.valsetpref.v1beta1.MsgSetValidatorSetPreference") + proto.RegisterType((*MsgSetValidatorSetPreferenceResponse)(nil), "osmosis.valsetpref.v1beta1.MsgSetValidatorSetPreferenceResponse") + proto.RegisterType((*MsgDelegateToValidatorSet)(nil), "osmosis.valsetpref.v1beta1.MsgDelegateToValidatorSet") + proto.RegisterType((*MsgDelegateToValidatorSetResponse)(nil), "osmosis.valsetpref.v1beta1.MsgDelegateToValidatorSetResponse") + proto.RegisterType((*MsgUndelegateFromValidatorSet)(nil), "osmosis.valsetpref.v1beta1.MsgUndelegateFromValidatorSet") + proto.RegisterType((*MsgUndelegateFromValidatorSetResponse)(nil), "osmosis.valsetpref.v1beta1.MsgUndelegateFromValidatorSetResponse") + proto.RegisterType((*MsgWithdrawDelegationRewards)(nil), "osmosis.valsetpref.v1beta1.MsgWithdrawDelegationRewards") + proto.RegisterType((*MsgWithdrawDelegationRewardsResponse)(nil), "osmosis.valsetpref.v1beta1.MsgWithdrawDelegationRewardsResponse") } func init() { - proto.RegisterFile("osmosis/validator-preference/v1beta1/tx.proto", fileDescriptor_fa9fa79f914b826d) + proto.RegisterFile("osmosis/valset-pref/v1beta1/tx.proto", fileDescriptor_daa95be02b2fc560) } -var fileDescriptor_fa9fa79f914b826d = []byte{ +var fileDescriptor_daa95be02b2fc560 = []byte{ // 530 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0x4f, 0x8b, 0xd3, 0x40, - 0x1c, 0xed, 0x6c, 0x55, 0xd8, 0xe9, 0x45, 0xc2, 0x22, 0x6d, 0xd0, 0xb4, 0x66, 0xd5, 0xed, 0xa5, - 0x19, 0x1b, 0x2f, 0xe2, 0x41, 0x34, 0xca, 0x82, 0x42, 0x41, 0xb2, 0xfe, 0x81, 0x3d, 0x08, 0x93, - 0x66, 0xcc, 0x06, 0xdb, 0x4c, 0xc9, 0x6f, 0xec, 0xee, 0x7e, 0x0b, 0x3f, 0x82, 0x57, 0x45, 0xd8, - 0x83, 0x5f, 0x62, 0xf1, 0xb4, 0x47, 0x4f, 0x55, 0xda, 0x6f, 0xb0, 0x9f, 0x40, 0x92, 0x4c, 0x27, - 0x3d, 0x6c, 0x6a, 0x68, 0xdd, 0x53, 0x0b, 0xf3, 0x7b, 0xef, 0xf7, 0x5e, 0xde, 0x1b, 0x06, 0x77, - 0x38, 0x0c, 0x39, 0x84, 0x40, 0xc6, 0x74, 0x10, 0xfa, 0x54, 0xf0, 0xb8, 0x33, 0x8a, 0xd9, 0x07, - 0x16, 0xb3, 0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0x1a, 0xe8, 0xf3, 0xcc, - 0xa8, 0x9c, 0xcd, 0x8c, 0xca, 0xaf, 0x99, 0x51, 0xd9, 0x7f, 0xb2, 0x70, 0x3f, 0xe5, 0xba, 0xce, - 0x80, 0x7a, 0x40, 0xd4, 0xe3, 0xd1, 0xb5, 0xc9, 0xd1, 0xc5, 0x4f, 0x48, 0x7a, 0x7b, 0xbd, 0x6b, - 0xe9, 0xdb, 0xf1, 0xe0, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xcf, 0x83, 0x26, 0x47, 0xf9, 0x06, + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x4d, 0x8b, 0xd3, 0x40, + 0x18, 0xee, 0x6c, 0x17, 0x61, 0xa7, 0x17, 0x09, 0x8b, 0xb4, 0x41, 0xd3, 0x1a, 0x57, 0xdb, 0x4b, + 0x33, 0x34, 0x22, 0x7e, 0x80, 0xa0, 0x55, 0xbc, 0x15, 0x34, 0xeb, 0x07, 0x78, 0x10, 0x26, 0xcd, + 0xbb, 0xd9, 0x60, 0x92, 0x09, 0x99, 0x71, 0x3f, 0xfe, 0x84, 0x78, 0x13, 0xfc, 0x09, 0x5e, 0x3c, + 0xf8, 0x0b, 0xbc, 0xed, 0x71, 0x8f, 0x9e, 0xaa, 0xb4, 0x07, 0xef, 0xfb, 0x0b, 0x24, 0x1f, 0x3b, + 0x8d, 0x60, 0x12, 0x08, 0x7a, 0x6a, 0x61, 0x9e, 0xe7, 0x79, 0x9f, 0x27, 0xef, 0x33, 0x83, 0x77, + 0x18, 0x0f, 0x18, 0xf7, 0x38, 0x39, 0xa0, 0x3e, 0x07, 0x31, 0x8e, 0x62, 0xd8, 0x23, 0x07, 0x13, + 0x1b, 0x04, 0x9d, 0x10, 0x71, 0x64, 0x44, 0x31, 0x13, 0x4c, 0x51, 0x73, 0x94, 0x91, 0xa1, 0x12, + 0x90, 0x91, 0x83, 0xd4, 0x6d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0x94, 0xb1, + 0x4f, 0x6d, 0x4e, 0xe4, 0x13, 0x3f, 0x31, 0xc9, 0xd1, 0x1f, 0x0f, 0x7d, 0x7a, 0xd9, 0xec, 0x0b, + 0xe9, 0x0b, 0x7f, 0xf3, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0a, 0x1f, 0xbc, 0x17, 0x84, 0x06, 0x00, 0x00, } @@ -482,7 +482,7 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { func (c *msgClient) SetValidatorSetPreference(ctx context.Context, in *MsgSetValidatorSetPreference, opts ...grpc.CallOption) (*MsgSetValidatorSetPreferenceResponse, error) { out := new(MsgSetValidatorSetPreferenceResponse) - err := c.cc.Invoke(ctx, "/osmosis.validatorpreference.v1beta1.Msg/SetValidatorSetPreference", in, out, opts...) + err := c.cc.Invoke(ctx, "/osmosis.valsetpref.v1beta1.Msg/SetValidatorSetPreference", in, out, opts...) if err != nil { return nil, err } @@ -491,7 +491,7 @@ func (c *msgClient) SetValidatorSetPreference(ctx context.Context, in *MsgSetVal func (c *msgClient) DelegateToValidatorSet(ctx context.Context, in *MsgDelegateToValidatorSet, opts ...grpc.CallOption) (*MsgDelegateToValidatorSetResponse, error) { out := new(MsgDelegateToValidatorSetResponse) - err := c.cc.Invoke(ctx, "/osmosis.validatorpreference.v1beta1.Msg/DelegateToValidatorSet", in, out, opts...) + err := c.cc.Invoke(ctx, "/osmosis.valsetpref.v1beta1.Msg/DelegateToValidatorSet", in, out, opts...) if err != nil { return nil, err } @@ -500,7 +500,7 @@ func (c *msgClient) DelegateToValidatorSet(ctx context.Context, in *MsgDelegateT func (c *msgClient) UndelegateFromValidatorSet(ctx context.Context, in *MsgUndelegateFromValidatorSet, opts ...grpc.CallOption) (*MsgUndelegateFromValidatorSetResponse, error) { out := new(MsgUndelegateFromValidatorSetResponse) - err := c.cc.Invoke(ctx, "/osmosis.validatorpreference.v1beta1.Msg/UndelegateFromValidatorSet", in, out, opts...) + err := c.cc.Invoke(ctx, "/osmosis.valsetpref.v1beta1.Msg/UndelegateFromValidatorSet", in, out, opts...) if err != nil { return nil, err } @@ -509,7 +509,7 @@ func (c *msgClient) UndelegateFromValidatorSet(ctx context.Context, in *MsgUndel func (c *msgClient) WithdrawDelegationRewards(ctx context.Context, in *MsgWithdrawDelegationRewards, opts ...grpc.CallOption) (*MsgWithdrawDelegationRewardsResponse, error) { out := new(MsgWithdrawDelegationRewardsResponse) - err := c.cc.Invoke(ctx, "/osmosis.validatorpreference.v1beta1.Msg/WithdrawDelegationRewards", in, out, opts...) + err := c.cc.Invoke(ctx, "/osmosis.valsetpref.v1beta1.Msg/WithdrawDelegationRewards", in, out, opts...) if err != nil { return nil, err } @@ -564,7 +564,7 @@ func _Msg_SetValidatorSetPreference_Handler(srv interface{}, ctx context.Context } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/osmosis.validatorpreference.v1beta1.Msg/SetValidatorSetPreference", + FullMethod: "/osmosis.valsetpref.v1beta1.Msg/SetValidatorSetPreference", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MsgServer).SetValidatorSetPreference(ctx, req.(*MsgSetValidatorSetPreference)) @@ -582,7 +582,7 @@ func _Msg_DelegateToValidatorSet_Handler(srv interface{}, ctx context.Context, d } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/osmosis.validatorpreference.v1beta1.Msg/DelegateToValidatorSet", + FullMethod: "/osmosis.valsetpref.v1beta1.Msg/DelegateToValidatorSet", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MsgServer).DelegateToValidatorSet(ctx, req.(*MsgDelegateToValidatorSet)) @@ -600,7 +600,7 @@ func _Msg_UndelegateFromValidatorSet_Handler(srv interface{}, ctx context.Contex } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/osmosis.validatorpreference.v1beta1.Msg/UndelegateFromValidatorSet", + FullMethod: "/osmosis.valsetpref.v1beta1.Msg/UndelegateFromValidatorSet", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MsgServer).UndelegateFromValidatorSet(ctx, req.(*MsgUndelegateFromValidatorSet)) @@ -618,7 +618,7 @@ func _Msg_WithdrawDelegationRewards_Handler(srv interface{}, ctx context.Context } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/osmosis.validatorpreference.v1beta1.Msg/WithdrawDelegationRewards", + FullMethod: "/osmosis.valsetpref.v1beta1.Msg/WithdrawDelegationRewards", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MsgServer).WithdrawDelegationRewards(ctx, req.(*MsgWithdrawDelegationRewards)) @@ -627,7 +627,7 @@ func _Msg_WithdrawDelegationRewards_Handler(srv interface{}, ctx context.Context } var _Msg_serviceDesc = grpc.ServiceDesc{ - ServiceName: "osmosis.validatorpreference.v1beta1.Msg", + ServiceName: "osmosis.valsetpref.v1beta1.Msg", HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ { @@ -648,7 +648,7 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "osmosis/validator-preference/v1beta1/tx.proto", + Metadata: "osmosis/valset-pref/v1beta1/tx.proto", } func (m *MsgSetValidatorSetPreference) Marshal() (dAtA []byte, err error) { diff --git a/x/valset-pref/validator_set.go b/x/valset-pref/validator_set.go new file mode 100644 index 00000000000..0973a30fd05 --- /dev/null +++ b/x/valset-pref/validator_set.go @@ -0,0 +1,89 @@ +package keeper + +import ( + "fmt" + "sort" + + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/osmosis-labs/osmosis/v12/x/valset-pref/types" +) + +func (k Keeper) SetupValidatorSetPreference(ctx sdk.Context, delegator string, preferences []types.ValidatorPreference) error { + // check if a user already has a validator-set created + existingValidators, found := k.GetValidatorSetPreference(ctx, delegator) + if found { + // check if the new preferences is the same as the existing preferences + isEqual := k.IsValidatorSetEqual(preferences, existingValidators.Preferences) + if isEqual { + return fmt.Errorf("The preferences (validator and weights) are the same") + } + } + + // checks that all the validators exist on chain + isValid := k.IsPreferenceValid(ctx, preferences) + if !isValid { + return fmt.Errorf("The validator preference list is not valid") + } + + return nil +} + +// GetValAddrAndVal checks if the validator address is valid and the validator provided exists on chain. +func (k Keeper) getValAddrAndVal(ctx sdk.Context, valOperAddress string) (sdk.ValAddress, stakingtypes.Validator, error) { + valAddr, err := sdk.ValAddressFromBech32(valOperAddress) + if err != nil { + return nil, stakingtypes.Validator{}, fmt.Errorf("validator address not formatted") + } + + validator, found := k.stakingKeeper.GetValidator(ctx, valAddr) + if !found { + return nil, stakingtypes.Validator{}, fmt.Errorf("validator not found %s", validator) + } + + return valAddr, validator, nil +} + +// IsPreferenceValid loops through the validator preferences and checks its existence and validity. +func (k Keeper) IsPreferenceValid(ctx sdk.Context, preferences []types.ValidatorPreference) bool { + for _, val := range preferences { + _, _, err := k.getValAddrAndVal(ctx, val.ValOperAddress) + if err != nil { + return false + } + } + return true +} + +// IsValidatorSetEqual returns true if the two preferences are equal. +func (k Keeper) IsValidatorSetEqual(newPreferences, existingPreferences []types.ValidatorPreference) bool { + var isEqual bool + // check if the two validator-set length are equal + if len(newPreferences) != len(existingPreferences) { + return false + } + + // sort the new validator-set + sort.Slice(newPreferences, func(i, j int) bool { + return newPreferences[i].ValOperAddress < newPreferences[j].ValOperAddress + }) + + // sort the existing validator-set + sort.Slice(existingPreferences, func(i, j int) bool { + return existingPreferences[i].ValOperAddress < existingPreferences[j].ValOperAddress + }) + + // make sure that both valAddress and weights cannot be the same in the new val-set + // if we just find one difference between two sets we can guarantee that they are different + for i := range newPreferences { + if newPreferences[i].ValOperAddress != existingPreferences[i].ValOperAddress || + !newPreferences[i].Weight.Equal(existingPreferences[i].Weight) { + isEqual = false + break + } else { + isEqual = true + } + } + + return isEqual +} diff --git a/x/valset-pref/valpref-module/module.go b/x/valset-pref/valpref-module/module.go new file mode 100644 index 00000000000..0c5904fbf1a --- /dev/null +++ b/x/valset-pref/valpref-module/module.go @@ -0,0 +1,189 @@ +package validator_preference + +import ( + "context" + "encoding/json" + "fmt" + "math/rand" + + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + + keeper "github.com/osmosis-labs/osmosis/v12/x/valset-pref" + "github.com/osmosis-labs/osmosis/v12/x/valset-pref/types" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + validatorprefclient "github.com/osmosis-labs/osmosis/v12/x/valset-pref/client" + "github.com/osmosis-labs/osmosis/v12/x/valset-pref/client/queryproto" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface for the capability module. +type AppModuleBasic struct { + cdc codec.Codec +} + +func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the capability module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types. +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns the capability module's default genesis state. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return nil +} + +// ValidateGenesis performs genesis state validation for the capability module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + return nil +} + +// RegisterRESTRoutes registers the capability module's REST service handlers. +func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + queryproto.RegisterQueryHandlerClient(context.Background(), mux, queryproto.NewQueryClient(clientCtx)) //nolint:errcheck +} + +// GetTxCmd returns the capability module's root tx command. +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return nil +} + +// GetQueryCmd returns the capability module's root query command. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return nil +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface for the capability module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// Name returns the capability module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} + +// Route returns the capability module's message routing key. +func (am AppModule) Route() sdk.Route { + return sdk.Route{} +} + +// QuerierRoute returns the capability module's query routing key. +func (AppModule) QuerierRoute() string { return types.QuerierRoute } + +// LegacyQuerierHandler returns the x/valset-pref module's Querier. +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { + return func(sdk.Context, []string, abci.RequestQuery) ([]byte, error) { + return nil, fmt.Errorf("legacy querier not supported for the x/%s module", types.ModuleName) + } +} + +// RegisterServices registers module services. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(&am.keeper)) + queryproto.RegisterQueryServer(cfg.QueryServer(), validatorprefclient.NewQuerier(am.keeper)) +} + +// RegisterInvariants registers the capability module's invariants. +func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { +} + +// InitGenesis performs the capability module's genesis initialization It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + return nil +} + +// BeginBlock executes all ABCI BeginBlock logic respective to the capability module. +func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock executes all ABCI EndBlock logic respective to the capability module. It +// returns no validator updates. +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} + +// ___________________________________________________________________________ + +// AppModuleSimulation functions + +// GenerateGenesisState creates a randomized GenState of the pool-incentives module. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { +} + +// ProposalContents doesn't return any content functions for governance proposals. +func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { + return []simtypes.WeightedProposalContent{} +} + +// RandomizedParams creates randomized pool-incentives param changes for the simulator. +func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { + return nil +} + +// RegisterStoreDecoder registers a decoder for supply module's types. +func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { +} + +// WeightedOperations returns the all the module operations with their respective weights. +func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + return []simtypes.WeightedOperation{} +} + +func (am AppModule) ConsensusVersion() uint64 { + return 1 +}