diff --git a/demo/app/app.go b/demo/app/app.go index 05fcb885..424a82ff 100644 --- a/demo/app/app.go +++ b/demo/app/app.go @@ -359,6 +359,8 @@ func NewMeshApp( scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName) + scopedMeshKeeper := app.CapabilityKeeper.ScopeToModule(meshsectypes.ModuleName) + app.CapabilityKeeper.Seal() // add keepers @@ -404,28 +406,6 @@ func NewMeshApp( authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - // setup mesh-security keeper with vanilla Cosmos-SDK - // see also NewKeeperX constructor for integration with Osmosis SDK fork - // should be initialized before wasm keeper for custom query/msg handlers - app.MeshSecKeeper = meshseckeeper.NewKeeper( - app.appCodec, - keys[meshsectypes.StoreKey], - memKeys[meshsectypes.MemStoreKey], - app.BankKeeper, - app.StakingKeeper, - &app.WasmKeeper, // ensure this is a pointer as we instantiate the keeper a bit later - authtypes.NewModuleAddress(govtypes.ModuleName).String(), - ) - - app.SlashingKeeper = slashingkeeper.NewKeeper( - appCodec, - legacyAmino, - keys[slashingtypes.StoreKey], - // decorate the sdk keeper to capture all jail/ unjail events for MS - meshseckeeper.NewStakingDecorator(app.StakingKeeper, app.MeshSecKeeper), - authtypes.NewModuleAddress(govtypes.ModuleName).String(), - ) - invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)) app.CrisisKeeper = crisiskeeper.NewKeeper( appCodec, @@ -438,17 +418,6 @@ func NewMeshApp( app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper) - // register the staking hooks - // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks - app.StakingKeeper.SetHooks( - stakingtypes.NewMultiStakingHooks( - app.DistrKeeper.Hooks(), - app.SlashingKeeper.Hooks(), - // register hook to capture valset updates - app.MeshSecKeeper.Hooks(), - ), - ) - app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper) groupConfig := group.DefaultConfig() @@ -483,6 +452,40 @@ func NewMeshApp( scopedIBCKeeper, ) + // setup mesh-security keeper with vanilla Cosmos-SDK + // see also NewKeeperX constructor for integration with Osmosis SDK fork + // should be initialized before wasm keeper for custom query/msg handlers + app.MeshSecKeeper = meshseckeeper.NewKeeper( + app.appCodec, + keys[meshsectypes.StoreKey], + memKeys[meshsectypes.MemStoreKey], + app.BankKeeper, + app.StakingKeeper, + &app.WasmKeeper, // ensure this is a pointer as we instantiate the keeper a bit later + scopedMeshKeeper, + app.IBCKeeper.ChannelKeeper, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + + app.SlashingKeeper = slashingkeeper.NewKeeper( + appCodec, + legacyAmino, + keys[slashingtypes.StoreKey], + // decorate the sdk keeper to capture all jail/ unjail events for MS + meshseckeeper.NewStakingDecorator(app.StakingKeeper, app.MeshSecKeeper), + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + + // register the staking hooks + // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks + app.StakingKeeper.SetHooks( + stakingtypes.NewMultiStakingHooks( + app.DistrKeeper.Hooks(), + app.SlashingKeeper.Hooks(), + // register hook to capture valset updates + app.MeshSecKeeper.Hooks(), + ), + ) // Register the proposal types // Deprecated: Avoid adding new handlers, instead use the new proposal flow // by granting the governance module the right to execute the message. diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index b5fc4f31..e35f550b 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -22,6 +22,7 @@ - [Query](#osmosis.meshsecurity.v1beta1.Query) - [osmosis/meshsecurity/v1beta1/scheduler.proto](#osmosis/meshsecurity/v1beta1/scheduler.proto) + - [ScheduledWork](#osmosis.meshsecurity.v1beta1.ScheduledWork) - [ValidatorAddress](#osmosis.meshsecurity.v1beta1.ValidatorAddress) - [osmosis/meshsecurity/v1beta1/tx.proto](#osmosis/meshsecurity/v1beta1/tx.proto) @@ -52,6 +53,7 @@ Params defines the parameters for the x/meshsecurity module. | `total_contracts_max_cap` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | TotalContractsMaxCap is the maximum that the sum of all contract max caps must not exceed | | `epoch_length` | [uint32](#uint32) | | Epoch length is the number of blocks that defines an epoch | | `max_gas_end_blocker` | [uint32](#uint32) | | MaxGasEndBlocker defines the maximum gas that can be spent in a contract sudo callback | +| `infraction_time` | [uint64](#uint64) | | | @@ -238,6 +240,21 @@ Query provides defines the gRPC querier service + + +### ScheduledWork + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `repeat` | [bool](#bool) | | | + + + + + + ### ValidatorAddress diff --git a/proto/osmosis/meshsecurity/v1beta1/meshsecurity.proto b/proto/osmosis/meshsecurity/v1beta1/meshsecurity.proto index 02cfc51e..b2fab291 100644 --- a/proto/osmosis/meshsecurity/v1beta1/meshsecurity.proto +++ b/proto/osmosis/meshsecurity/v1beta1/meshsecurity.proto @@ -36,4 +36,6 @@ message Params { // MaxGasEndBlocker defines the maximum gas that can be spent in a contract // sudo callback uint32 max_gas_end_blocker = 3; + + uint64 infraction_time = 4; } \ No newline at end of file diff --git a/proto/osmosis/meshsecurityprovider/v1beta1/delegate.proto b/proto/osmosis/meshsecurityprovider/v1beta1/delegate.proto new file mode 100644 index 00000000..78f36146 --- /dev/null +++ b/proto/osmosis/meshsecurityprovider/v1beta1/delegate.proto @@ -0,0 +1,45 @@ +syntax = "proto3"; +package osmosis.meshsecurityprovider.v1beta1; + +import "cosmos/base/v1beta1/coin.proto"; +import "gogoproto/gogo.proto"; +import "amino/amino.proto"; + +option go_package = "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types"; +option (gogoproto.goproto_getters_all) = false; +option (gogoproto.equal_all) = false; + +// Params defines the parameters for the x/meshsecurity module. +message Depositors { + string address = 1; + repeated cosmos.base.v1beta1.Coin tokens = 2 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} + +// vault-staker +message Intermediary { + string consumer_validator = 1; + string chain_id = 2; + string contract_address = 3; + bool jailed = 4; + bool tombstoned = 5; + BondStatus status = 6; + cosmos.base.v1beta1.Coin token = 7; +} + +// BondStatus is the status of a validator. +enum BondStatus { + option (gogoproto.goproto_enum_prefix) = false; + + // UNSPECIFIED defines an invalid validator status. + BOND_STATUS_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "Unspecified"]; + // UNBONDED defines a validator that is not bonded. + BOND_STATUS_UNBONDED = 1 [(gogoproto.enumvalue_customname) = "Unbonded"]; + // UNBONDING defines a validator that is unbonding. + BOND_STATUS_UNBONDING = 2 [(gogoproto.enumvalue_customname) = "Unbonding"]; + // BONDED defines a validator that is bonded. + BOND_STATUS_BONDED = 3 [(gogoproto.enumvalue_customname) = "Bonded"]; + } \ No newline at end of file diff --git a/proto/osmosis/meshsecurityprovider/v1beta1/genesis.proto b/proto/osmosis/meshsecurityprovider/v1beta1/genesis.proto new file mode 100644 index 00000000..aff7fb21 --- /dev/null +++ b/proto/osmosis/meshsecurityprovider/v1beta1/genesis.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; +package osmosis.meshsecurityprovider.v1beta1; + +import "osmosis/meshsecurityprovider/v1beta1/params.proto"; +import "gogoproto/gogo.proto"; +import "amino/amino.proto"; + +option go_package = "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types"; +option (gogoproto.goproto_getters_all) = false; +option (gogoproto.equal_all) = false; + +// GenesisState defines meshsecurity module's genesis state. +message GenesisState { + option (gogoproto.equal) = true; + + Params params = 1 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; +} diff --git a/proto/osmosis/meshsecurityprovider/v1beta1/params.proto b/proto/osmosis/meshsecurityprovider/v1beta1/params.proto new file mode 100644 index 00000000..646d23cd --- /dev/null +++ b/proto/osmosis/meshsecurityprovider/v1beta1/params.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; +package osmosis.meshsecurityprovider.v1beta1; + +import "cosmos/base/v1beta1/coin.proto"; +import "gogoproto/gogo.proto"; +import "amino/amino.proto"; + +option go_package = "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types"; +option (gogoproto.goproto_getters_all) = false; +option (gogoproto.equal_all) = false; + +// Params defines the parameters for the x/meshsecurity module. +message Params { + option (amino.name) = "meshsecurityprovider/Params"; + option (gogoproto.equal) = true; + + // TimeoutPeriod has the unit time.Millisecond + uint64 timeout_period = 1; + + string vault_contract_address = 2; +} + diff --git a/proto/osmosis/meshsecurityprovider/v1beta1/query.proto b/proto/osmosis/meshsecurityprovider/v1beta1/query.proto new file mode 100644 index 00000000..3b58da35 --- /dev/null +++ b/proto/osmosis/meshsecurityprovider/v1beta1/query.proto @@ -0,0 +1,30 @@ +syntax = "proto3"; +package osmosis.meshsecurityprovider.v1beta1; + +import "cosmos/base/v1beta1/coin.proto"; +import "osmosis/meshsecurityprovider/v1beta1/params.proto"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "amino/amino.proto"; + +option go_package = "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types"; +option (gogoproto.goproto_getters_all) = false; +option (gogoproto.equal_all) = false; + +// Query provides defines the gRPC querier service +service Query { + // Params queries the parameters of x/meshsecurity module. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/osmosis/meshsecurityprovider/v1beta1/params"; + } +} +// QueryParamsRequest is the request type for the +// Query/Params RPC method +message QueryParamsRequest {} + +// QueryParamsResponse is the response type for the +// Query/Params RPC method +message QueryParamsResponse { + Params params = 1 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; +} diff --git a/proto/osmosis/meshsecurityprovider/v1beta1/tx.proto b/proto/osmosis/meshsecurityprovider/v1beta1/tx.proto new file mode 100644 index 00000000..a2d1265b --- /dev/null +++ b/proto/osmosis/meshsecurityprovider/v1beta1/tx.proto @@ -0,0 +1,61 @@ +syntax = "proto3"; +package osmosis.meshsecurityprovider.v1beta1; + +import "cosmos_proto/cosmos.proto"; +import "cosmos/msg/v1/msg.proto"; +import "gogoproto/gogo.proto"; +import "amino/amino.proto"; +import "cosmos/base/v1beta1/coin.proto"; + +option go_package = "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types"; +option (gogoproto.goproto_getters_all) = false; + +service Msg { + rpc Delegate(MsgDelegate) returns (MsgDelegateResponse); + + rpc Undelegate(MsgUndelegate) returns (MsgUndelegateResponse); + + + + rpc SetConsumerCommissionRate(MsgSetConsumerCommissionRate) returns (MsgSetConsumerCommissionRateResponse); +} +message MsgDelegate { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; +} +message MsgDelegateResponse {} + +message MsgUndelegate { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; +} + +// MsgUndelegateResponse defines the Msg/Undelegate response type. +message MsgUndelegateResponse { +} + +message MsgSetConsumerCommissionRate { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string provider_addr = 1 [ (gogoproto.moretags) = "yaml:\"address\"" ]; + + string chain_id = 2; + + string rate = 3 [ + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; +} + + +message MsgSetConsumerCommissionRateResponse {} diff --git a/proto/osmosis/types/v1beta1/wire.proto b/proto/osmosis/types/v1beta1/wire.proto new file mode 100644 index 00000000..cb1e5187 --- /dev/null +++ b/proto/osmosis/types/v1beta1/wire.proto @@ -0,0 +1,66 @@ +syntax = "proto3"; +package osmosis.types.v1beta1; + +import "cosmos/base/v1beta1/coin.proto"; +import "gogoproto/gogo.proto"; +import "amino/amino.proto"; +import "cosmos/staking/v1beta1/staking.proto"; +import "tendermint/abci/types.proto"; + + +option go_package = "github.com/osmosis-labs/mesh-security-sdk/x/types"; +option (gogoproto.goproto_getters_all) = false; +option (gogoproto.equal_all) = false; + +// enum PipedValsetOperation +enum PipedValsetOperation { + UNSPECIFIED = 0; + VALIDATOR_BONDED = 1; + VALIDATOR_UNBONDED = 2; + VALIDATOR_JAILED = 3; + VALIDATOR_TOMBSTONED = 4; + VALIDATOR_UNJAILED = 5; + VALIDATOR_MODIFIED = 6; + VALIDATOR_SLASHED = 7; +} + +// SlashInfo defines info event from slashing +message SlashInfo { + string validator = 1; + int64 infraction_height = 2; + int64 power = 3; + string total_slash_amount = 4; + string slash_fraction = 5; + int64 time_infraction = 6; +} + +// InfoSchedule +message ScheduleInfo { + string validator = 1; + string actor = 2; + string denom = 3; +} + +// ConsumerPacketData contains a consumer packet data and a type tag +message ConsumerPacketData { + PipedValsetOperation type = 1; + + oneof data { + SlashInfo slashPacketData = 2; + ScheduleInfo schedulePacketData = 3; + } +} + +// InfractionType indicates the infraction type a validator committed. +// Note ccv.InfractionType to maintain compatibility between ICS versions +// using different versions of the cosmos-sdk and ibc-go modules. +enum InfractionType { + option (gogoproto.goproto_enum_prefix) = false; + + // UNSPECIFIED defines an empty infraction type. + INFRACTION_TYPE_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "InfractionEmpty"]; + // DOUBLE_SIGN defines a validator that double-signs a block. + INFRACTION_TYPE_DOUBLE_SIGN = 1 [(gogoproto.enumvalue_customname) = "DoubleSign"]; + // DOWNTIME defines a validator that missed signing too many blocks. + INFRACTION_TYPE_DOWNTIME = 2 [(gogoproto.enumvalue_customname) = "Downtime"]; +} diff --git a/tests/e2e/valset_test.go b/tests/e2e/valset_test.go index 9d5201d3..303197bc 100644 --- a/tests/e2e/valset_test.go +++ b/tests/e2e/valset_test.go @@ -174,7 +174,9 @@ func jailValidator(t *testing.T, consAddr sdk.ConsAddress, coordinator *wasmibct ctx = chain.GetContext() signInfo.MissedBlocksCounter = app.SlashingKeeper.MinSignedPerWindow(ctx) app.SlashingKeeper.SetValidatorSigningInfo(ctx, consAddr, signInfo) - power := app.StakingKeeper.GetLastValidatorPower(ctx, sdk.ValAddress(consAddr)) + + v, _ := app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr) + power := app.StakingKeeper.GetLastValidatorPower(ctx, v.GetOperator()) app.SlashingKeeper.HandleValidatorSignature(ctx, cryptotypes.Address(consAddr), power, false) // when updates trigger chain.NextBlock() diff --git a/x/meshsecurity/ibc_module.go b/x/meshsecurity/ibc_module.go new file mode 100644 index 00000000..79d069b6 --- /dev/null +++ b/x/meshsecurity/ibc_module.go @@ -0,0 +1,167 @@ +package meshsecurity + +import ( + // "fmt" + "strings" + // "strconv" + + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + // porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" + // host "github.com/cosmos/ibc-go/v7/modules/core/24-host" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + // transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + + ctypes "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types" + "github.com/osmosis-labs/mesh-security-sdk/x/types" +) + +// OnChanOpenInit implements the IBCModule interface +// this function is called by the relayer. +func (am AppModule) OnChanOpenInit( + ctx sdk.Context, + order channeltypes.Order, + connectionHops []string, + portID string, + channelID string, + chanCap *capabilitytypes.Capability, + counterparty channeltypes.Counterparty, + version string, +) (string, error) { + if strings.TrimSpace(version) == "" { + version = types.Version + } + + return version, nil +} + +// OnChanOpenTry implements the IBCModule interface +func (am AppModule) OnChanOpenTry( + ctx sdk.Context, + order channeltypes.Order, + connectionHops []string, + portID, + channelID string, + chanCap *capabilitytypes.Capability, + counterparty channeltypes.Counterparty, + counterpartyVersion string, +) (string, error) { + return "", errorsmod.Wrap(types.ErrInvalidChannelFlow, "channel handshake must be initiated by consumer chain") +} + +// OnChanOpenAck implements the IBCModule interface +func (am AppModule) OnChanOpenAck( + ctx sdk.Context, + portID, + channelID string, + _ string, // Counter party channel ID is unused per spec + counterpartyMetadata string, +) error { + + return nil +} + +// OnChanOpenConfirm implements the IBCModule interface +func (am AppModule) OnChanOpenConfirm( + ctx sdk.Context, + portID, + channelID string, +) error { + return errorsmod.Wrap(types.ErrInvalidChannelFlow, "channel handshake must be initiated by consumer chain") +} + +// OnChanCloseInit implements the IBCModule interface +func (am AppModule) OnChanCloseInit( + ctx sdk.Context, + portID, + channelID string, +) error { + // allow relayers to close duplicate OPEN channels, if the provider channel has already been established + // if providerChannel, ok := am.keeper.GetProviderChannel(ctx); ok && providerChannel != channelID { + // return nil + // } + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") +} + +// OnChanCloseConfirm implements the IBCModule interface +func (am AppModule) OnChanCloseConfirm( + ctx sdk.Context, + portID, + channelID string, +) error { + return nil +} + +// OnRecvPacket implements the IBCModule interface. A successful acknowledgement +// is returned if the packet data is successfully decoded and the receive application +// logic returns without error. +func (am AppModule) OnRecvPacket( + ctx sdk.Context, + packet channeltypes.Packet, + _ sdk.AccAddress, +) ibcexported.Acknowledgement { + ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) + // was successfully decoded + if ack.Success() { + //TODO: OnRecvPacket + } + + // NOTE: acknowledgement will be written synchronously during IBC handler execution. + return ack +} + +// OnAcknowledgementPacket implements the IBCModule interface +func (am AppModule) OnAcknowledgementPacket( + ctx sdk.Context, + packet channeltypes.Packet, + acknowledgement []byte, + _ sdk.AccAddress, +) error { + var ack channeltypes.Acknowledgement + if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal consumer packet acknowledgement: %v", err) + } + + if err := am.k.OnAcknowledgementPacket(ctx, packet, ack); err != nil { + return err + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypePacket, + sdk.NewAttribute(sdk.AttributeKeyModule, ctypes.ModuleName), + sdk.NewAttribute(types.AttributeKeyAck, ack.String()), + ), + ) + switch resp := ack.Response.(type) { + case *channeltypes.Acknowledgement_Result: + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypePacket, + sdk.NewAttribute(types.AttributeKeyAckSuccess, string(resp.Result)), + ), + ) + case *channeltypes.Acknowledgement_Error: + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypePacket, + sdk.NewAttribute(types.AttributeKeyAckError, resp.Error), + ), + ) + } + return nil +} + +// OnTimeoutPacket implements the IBCModule interface +func (am AppModule) OnTimeoutPacket( + ctx sdk.Context, + packet channeltypes.Packet, + _ sdk.AccAddress, +) error { + return nil +} diff --git a/x/meshsecurity/keeper/adapter.go b/x/meshsecurity/keeper/adapter.go index c7914979..1d2a9e0b 100644 --- a/x/meshsecurity/keeper/adapter.go +++ b/x/meshsecurity/keeper/adapter.go @@ -113,42 +113,6 @@ func NewStakingDecorator(stakingKeeper slashingtypes.StakingKeeper, k *Keeper) * return &StakingDecorator{StakingKeeper: stakingKeeper, k: k} } -// Slash captures the slash event and calls the decorated staking keeper slash method -func (s StakingDecorator) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, power int64, height int64, slashRatio sdk.Dec) math.Int { - val := s.StakingKeeper.ValidatorByConsAddr(ctx, consAddr) - totalSlashAmount := s.StakingKeeper.Slash(ctx, consAddr, power, height, slashRatio) - if val == nil { - ModuleLogger(ctx). - Error("can not propagate slash: validator not found", "validator", consAddr.String()) - } else if err := s.k.ScheduleSlashed(ctx, val.GetOperator(), power, height, totalSlashAmount, slashRatio); err != nil { - ModuleLogger(ctx). - Error("can not propagate slash: schedule event", - "cause", err, - "validator", consAddr.String()) - } - return totalSlashAmount -} - -// SlashWithInfractionReason implementation doesn't require the infraction (types.Infraction) to work but is required by Interchain Security. -func (s StakingDecorator) SlashWithInfractionReason(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight int64, power int64, slashFactor sdk.Dec, _ stakingtypes.Infraction) math.Int { - return s.Slash(ctx, consAddr, infractionHeight, power, slashFactor) -} - -// Jail captures the jail event and calls the decorated staking keeper jail method -func (s StakingDecorator) Jail(ctx sdk.Context, consAddr sdk.ConsAddress) { - val := s.StakingKeeper.ValidatorByConsAddr(ctx, consAddr) - if val == nil { - ModuleLogger(ctx). - Error("can not propagate jail: validator not found", "validator", consAddr.String()) - } else if err := s.k.ScheduleJailed(ctx, val.GetOperator()); err != nil { - ModuleLogger(ctx). - Error("can not propagate jail: schedule event", - "cause", err, - "validator", consAddr.String()) - } - s.StakingKeeper.Jail(ctx, consAddr) -} - // Unjail captures the unjail event and calls the decorated staking keeper unjail method func (s StakingDecorator) Unjail(ctx sdk.Context, consAddr sdk.ConsAddress) { val := s.StakingKeeper.ValidatorByConsAddr(ctx, consAddr) diff --git a/x/meshsecurity/keeper/adapter_test.go b/x/meshsecurity/keeper/adapter_test.go index 02948394..7b0168c6 100644 --- a/x/meshsecurity/keeper/adapter_test.go +++ b/x/meshsecurity/keeper/adapter_test.go @@ -10,8 +10,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" - - "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + "github.com/cosmos/cosmos-sdk/x/staking/types" + cptypes "github.com/osmosis-labs/mesh-security-sdk/x/types" ) func TestCaptureTombstone(t *testing.T) { @@ -28,12 +29,12 @@ func TestCaptureTombstone(t *testing.T) { specs := map[string]struct { addr sdk.ConsAddress expPassed []sdk.ConsAddress - expStored []types.PipedValsetOperation + expStored []cptypes.PipedValsetOperation }{ "with existing validator": { addr: myConsAddress, expPassed: []sdk.ConsAddress{myConsAddress}, - expStored: []types.PipedValsetOperation{types.ValidatorTombstoned}, + expStored: []cptypes.PipedValsetOperation{cptypes.PipedValsetOperation_VALIDATOR_TOMBSTONED}, }, "unknown consensus address": { addr: otherConsAddress, @@ -58,10 +59,18 @@ func TestCaptureTombstone(t *testing.T) { func TestCaptureStakingEvents(t *testing.T) { pCtx, keepers := CreateDefaultTestInput(t) + denom := keepers.StakingKeeper.BondDenom(pCtx) + coin := sdk.NewCoin(denom, sdk.NewIntFromUint64(1000000)) val := MinValidatorFixture(t) + val.Status = types.Bonded + val.Tokens = sdk.NewIntFromUint64(1000000) myConsAddress, err := val.GetConsAddr() require.NoError(t, err) + acc := sdk.AccAddress(rand.Bytes(32)) + keepers.BankKeeper.MintCoins(pCtx, minttypes.ModuleName, sdk.NewCoins([]sdk.Coin{coin}...)) + keepers.BankKeeper.SendCoinsFromModuleToAccount(pCtx, minttypes.ModuleName, acc, sdk.NewCoins([]sdk.Coin{coin}...)) + keepers.BankKeeper.DelegateCoinsFromAccountToModule(pCtx, acc, types.BondedPoolName, sdk.NewCoins([]sdk.Coin{coin}...)) keepers.StakingKeeper.SetValidatorByConsAddr(pCtx, val) keepers.StakingKeeper.SetValidator(pCtx, val) @@ -76,19 +85,26 @@ func TestCaptureStakingEvents(t *testing.T) { specs := map[string]struct { consAddr sdk.ConsAddress op func(sdk.Context, sdk.ConsAddress) - expStored []types.PipedValsetOperation + expStored []cptypes.PipedValsetOperation expJailed bool }{ - "jail": { - consAddr: myConsAddress, - op: decorator.Jail, - expStored: []types.PipedValsetOperation{types.ValidatorJailed}, + "slash and jail": { + consAddr: myConsAddress, + op: func(ctx sdk.Context, ca sdk.ConsAddress) { + decorator.Slash(ctx, ca, ctx.BlockHeight(), 1, sdk.MustNewDecFromStr("0.1")) + decorator.Jail(ctx, ca) + }, + expStored: []cptypes.PipedValsetOperation{ + cptypes.PipedValsetOperation_VALIDATOR_JAILED, + cptypes.PipedValsetOperation_VALIDATOR_MODIFIED, + cptypes.PipedValsetOperation_VALIDATOR_SLASHED, + }, expJailed: true, }, "unjail": { consAddr: myConsAddressJailed, op: decorator.Unjail, - expStored: []types.PipedValsetOperation{types.ValidatorUnjailed}, + expStored: []cptypes.PipedValsetOperation{cptypes.PipedValsetOperation_VALIDATOR_UNJAILED}, }, } for name, spec := range specs { @@ -99,7 +115,8 @@ func TestCaptureStakingEvents(t *testing.T) { spec.op(ctx, spec.consAddr) // then - loadedVal := keepers.StakingKeeper.ValidatorByConsAddr(ctx, spec.consAddr) + loadedVal, found := keepers.StakingKeeper.GetValidatorByConsAddr(ctx, spec.consAddr) + assert.True(t, found) assert.Equal(t, spec.expJailed, loadedVal.IsJailed()) // and stored for async propagation allStoredOps := FetchAllStoredOperations(t, ctx, keepers.MeshKeeper) diff --git a/x/meshsecurity/keeper/handler_plugin_test.go b/x/meshsecurity/keeper/handler_plugin_test.go index 95bd947e..de002a0a 100644 --- a/x/meshsecurity/keeper/handler_plugin_test.go +++ b/x/meshsecurity/keeper/handler_plugin_test.go @@ -52,7 +52,7 @@ func TestCustomMeshSecDispatchMsg(t *testing.T) { return &msKeeperMock{DelegateFn: fn}, asserts }, expEvents: []sdk.Event{sdk.NewEvent("instant_delegate", - sdk.NewAttribute("module", "meshsecurity"), + sdk.NewAttribute("module", types.ModuleName), sdk.NewAttribute("validator", myValidatorAddr.String()), sdk.NewAttribute("amount", myAmount.String()), sdk.NewAttribute("delegator", myContractAddr.String()), @@ -77,7 +77,7 @@ func TestCustomMeshSecDispatchMsg(t *testing.T) { return &msKeeperMock{UndelegateFn: fn}, asserts }, expEvents: []sdk.Event{sdk.NewEvent("instant_unbond", - sdk.NewAttribute("module", "meshsecurity"), + sdk.NewAttribute("module", types.ModuleName), sdk.NewAttribute("validator", myValidatorAddr.String()), sdk.NewAttribute("amount", myAmount.String()), sdk.NewAttribute("sender", myContractAddr.String()), diff --git a/x/meshsecurity/keeper/keeper.go b/x/meshsecurity/keeper/keeper.go index a9117790..2dc9dbec 100644 --- a/x/meshsecurity/keeper/keeper.go +++ b/x/meshsecurity/keeper/keeper.go @@ -8,6 +8,9 @@ import ( errorsmod "cosmossdk.io/errors" "cosmossdk.io/math" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v7/modules/core/24-host" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" storetypes "github.com/cosmos/cosmos-sdk/store/types" @@ -29,6 +32,9 @@ type Keeper struct { bank types.XBankKeeper Staking types.XStakingKeeper wasm types.WasmKeeper + + scopedKeeper types.ScopedKeeper + channelKeeper types.ChannelKeeper // the address capable of executing a MsgUpdateParams message. Typically, this // should be the x/gov module account. authority string @@ -42,10 +48,12 @@ func NewKeeper( bank types.SDKBankKeeper, staking types.SDKStakingKeeper, wasm types.WasmKeeper, + scopedKeeper types.ScopedKeeper, + channelKeeper types.ChannelKeeper, authority string, opts ...Option, ) *Keeper { - return NewKeeperX(cdc, storeKey, memoryStoreKey, NewBankKeeperAdapter(bank), NewStakingKeeperAdapter(staking, bank), wasm, authority, opts...) + return NewKeeperX(cdc, storeKey, memoryStoreKey, NewBankKeeperAdapter(bank), NewStakingKeeperAdapter(staking, bank), wasm, scopedKeeper, channelKeeper, authority, opts...) } // NewKeeperX constructor with extended Osmosis SDK keepers @@ -56,17 +64,21 @@ func NewKeeperX( bank types.XBankKeeper, staking types.XStakingKeeper, wasm types.WasmKeeper, + scopedKeeper types.ScopedKeeper, + channelKeeper types.ChannelKeeper, authority string, opts ...Option, ) *Keeper { k := &Keeper{ - storeKey: storeKey, - memKey: memoryStoreKey, - cdc: cdc, - bank: bank, - Staking: staking, - wasm: wasm, - authority: authority, + storeKey: storeKey, + memKey: memoryStoreKey, + cdc: cdc, + bank: bank, + Staking: staking, + wasm: wasm, + scopedKeeper: scopedKeeper, + channelKeeper: channelKeeper, + authority: authority, } for _, o := range opts { o.apply(k) @@ -185,3 +197,28 @@ func (k Keeper) IterateMaxCapLimit(ctx sdk.Context, cb func(sdk.AccAddress, math func ModuleLogger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } + +// GetProviderChannel gets the channelID for the channel to the provider. +func (k Keeper) GetProviderChannel(ctx sdk.Context) (string, bool) { + store := ctx.KVStore(k.storeKey) + channelIdBytes := store.Get(types.ProviderChannelKey()) + if len(channelIdBytes) == 0 { + return "", false + } + return string(channelIdBytes), true +} + +// SetProviderChannel sets the channelID for the channel to the provider. +func (k Keeper) SetProviderChannel(ctx sdk.Context, channelID string) { + store := ctx.KVStore(k.storeKey) + store.Set(types.ProviderChannelKey(), []byte(channelID)) +} + +func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string) error { + capName := host.ChannelCapabilityPath(portID, channelID) + chanCap, ok := k.scopedKeeper.GetCapability(ctx, capName) + if !ok { + return errorsmod.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName) + } + return k.channelKeeper.ChanCloseInit(ctx, portID, channelID, chanCap) +} diff --git a/x/meshsecurity/keeper/relay.go b/x/meshsecurity/keeper/relay.go new file mode 100644 index 00000000..366c8d75 --- /dev/null +++ b/x/meshsecurity/keeper/relay.go @@ -0,0 +1,93 @@ +package keeper + +import ( + errorsmod "cosmossdk.io/errors" + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + + ctypes "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types" + "github.com/osmosis-labs/mesh-security-sdk/x/types" +) + +func (k Keeper) SendPackets(ctx sdk.Context) { + channelID, ok := k.GetProviderChannel(ctx) + if !ok { + return + } + + // pending := k.GetAllPendingPacketsWithIdx(ctx) + ConsumerPackets := []types.ConsumerPacketData{} + k.iteratePipedValsetOperations(ctx, func(packet *types.ConsumerPacketData) bool { + ConsumerPackets = append(ConsumerPackets, *packet) + return false + }) + + for _, s := range ConsumerPackets { + // Send packet over IBC + err := ctypes.SendIBCPacket( + ctx, + k.scopedKeeper, + k.channelKeeper, + channelID, // source channel id + types.ConsumerPortID, // source port id + s.MarshalConsumerPacketData(), + k.GetParams(ctx).GetTimeoutPeriod(), + ) + if err != nil { + if clienttypes.ErrClientNotActive.Is(err) { + ModuleLogger(ctx).Info("IBC client is expired, cannot send IBC packet; leaving packet data stored:") + break + } + ModuleLogger(ctx).Error("cannot send IBC packet; leaving packet data stored:", "err", err.Error()) + break + } + } +} + +func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Packet, ack channeltypes.Acknowledgement) error { + if res := ack.GetResult(); res != nil { + if len(res) != 1 { + return fmt.Errorf("acknowledgement result length must be 1, got %d", len(res)) + } + + consumerPacket, err := types.UnmarshalConsumerPacketData(packet.GetData()) + if err != nil { + return err + } + if consumerPacket.Type != types.PipedValsetOperation_VALIDATOR_SLASHED { + return nil + } + k.ClearPipedValsetOperations(ctx) + } + + if err := ack.GetError(); err != "" { + // Reasons for ErrorAcknowledgment + // - packet data could not be successfully decoded + // - invalid Slash packet + // None of these should ever happen. + ModuleLogger(ctx).Error( + "recv ErrorAcknowledgement", + "channel", packet.SourceChannel, + "error", err, + ) + // Initiate ChanCloseInit using packet source (non-counterparty) port and channel + err := k.ChanCloseInit(ctx, packet.SourcePort, packet.SourceChannel) + if err != nil { + return fmt.Errorf("ChanCloseInit(%s) failed: %s", packet.SourceChannel, err.Error()) + } + // check if there is an established CCV channel to provider + channelID, found := k.GetProviderChannel(ctx) + if !found { + return errorsmod.Wrapf(ctypes.ErrNoProposerChannelId, "recv ErrorAcknowledgement on non-established channel %s", packet.SourceChannel) + } + if channelID != packet.SourceChannel { + // Close the established CCV channel as well + return k.ChanCloseInit(ctx, types.ConsumerPortID, channelID) + } + } + return nil +} diff --git a/x/meshsecurity/keeper/slash.go b/x/meshsecurity/keeper/slash.go new file mode 100644 index 00000000..99111a17 --- /dev/null +++ b/x/meshsecurity/keeper/slash.go @@ -0,0 +1,26 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (k Keeper) HandleBeforeValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress, slashRatio sdk.Dec) error { + if valAddr == nil { + ModuleLogger(ctx). + Error("can not propagate slash: validator not found", "validator", valAddr.String()) + } + if err := k.ScheduleSlashed(ctx, valAddr, slashRatio); err != nil { + ModuleLogger(ctx). + Error("can not propagate slash: schedule event", + "cause", err, + "validator", valAddr.String()) + } + if err := k.ScheduleJailed(ctx, valAddr); err != nil { + ModuleLogger(ctx). + Error("can not propagate jail: schedule event", + "cause", err, + "validator", valAddr.String()) + } + + return nil +} diff --git a/x/meshsecurity/keeper/staking_hooks.go b/x/meshsecurity/keeper/staking_hooks.go index c9b0df9b..12ac4255 100644 --- a/x/meshsecurity/keeper/staking_hooks.go +++ b/x/meshsecurity/keeper/staking_hooks.go @@ -29,6 +29,11 @@ func (h Hooks) AfterValidatorBeginUnbonding(ctx sdk.Context, _ sdk.ConsAddress, } func (h Hooks) BeforeValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress, fraction sdk.Dec) error { + if fraction.IsZero() { + return nil + } + h.k.HandleBeforeValidatorSlashed(ctx, valAddr, fraction) + return nil } diff --git a/x/meshsecurity/keeper/test_common.go b/x/meshsecurity/keeper/test_common.go index 6a97ac67..0b1964de 100644 --- a/x/meshsecurity/keeper/test_common.go +++ b/x/meshsecurity/keeper/test_common.go @@ -60,6 +60,7 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types" + cptypes "github.com/osmosis-labs/mesh-security-sdk/x/types" ) type encodingConfig struct { @@ -276,11 +277,19 @@ func CreateDefaultTestInput(t testing.TB, opts ...Option) (sdk.Context, TestKeep bankKeeper, stakingKeeper, wasmKeeper, + scopedWasmKeeper, + ibcKeeper.ChannelKeeper, authority, opts..., ) require.NoError(t, msKeeper.SetParams(ctx, types.DefaultParams(sdk.DefaultBondDenom))) + stakingKeeper.SetHooks( + stakingtypes.NewMultiStakingHooks( + slashingKeeper.Hooks(), + msKeeper.Hooks(), + ), + ) faucet := wasmkeeper.NewTestFaucet(t, ctx, bankKeeper, minttypes.ModuleName, sdk.NewInt64Coin(sdk.DefaultBondDenom, 1_000_000_000_000)) return ctx, TestKeepers{ AccountKeeper: accountKeeper, @@ -296,28 +305,30 @@ func CreateDefaultTestInput(t testing.TB, opts ...Option) (sdk.Context, TestKeep } // FetchAllStoredOperations load all ops from temp db -func FetchAllStoredOperations(t *testing.T, ctx sdk.Context, msKeeper *Keeper) map[string][]types.PipedValsetOperation { - index := make(map[string][]types.PipedValsetOperation, 1) - err := msKeeper.iteratePipedValsetOperations(ctx, func(valAddr sdk.ValAddress, op types.PipedValsetOperation, slashInfo *types.SlashInfo) bool { - ops, ok := index[valAddr.String()] - if !ok { - ops = []types.PipedValsetOperation{} +func FetchAllStoredOperations(t *testing.T, ctx sdk.Context, msKeeper *Keeper) map[string][]cptypes.PipedValsetOperation { + index := make(map[string][]cptypes.PipedValsetOperation, 1) + err := msKeeper.iteratePipedValsetOperations(ctx, func(packet *cptypes.ConsumerPacketData) bool { + if packet.Type != cptypes.PipedValsetOperation_VALIDATOR_SLASHED { + data := packet.GetSchedulePacketData() + ops, ok := index[data.Validator] + if !ok { + ops = []cptypes.PipedValsetOperation{} + } + index[data.Validator] = append(ops, packet.Type) + } else { + data := packet.GetSlashPacketData() + ops, ok := index[data.Validator] + if !ok { + ops = []cptypes.PipedValsetOperation{} + } + index[data.Validator] = append(ops, packet.Type) } - index[valAddr.String()] = append(ops, op) return false }) require.NoError(t, err) return index } -// for test code only -func must[t any](s t, err error) t { - if err != nil { - panic(err) - } - return s -} - // MinValidatorFixture creates minimal sdk validator object func MinValidatorFixture(t *testing.T) stakingtypes.Validator { t.Helper() diff --git a/x/meshsecurity/keeper/valset_updates.go b/x/meshsecurity/keeper/valset_updates.go index 50101d1a..0e19b096 100644 --- a/x/meshsecurity/keeper/valset_updates.go +++ b/x/meshsecurity/keeper/valset_updates.go @@ -8,58 +8,130 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + cptypes "github.com/osmosis-labs/mesh-security-sdk/x/types" + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/contract" "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types" - - outmessage "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/contract" ) // ScheduleBonded store a validator update to bonded status for the valset update report func (k Keeper) ScheduleBonded(ctx sdk.Context, addr sdk.ValAddress) error { - return k.sendAsync(ctx, types.ValidatorBonded, addr, nil) + packet := cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_BONDED, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: addr.String(), + Denom: k.Staking.BondDenom(ctx), + }, + }, + } + return k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_BONDED, addr, packet) } // ScheduleUnbonded store a validator update to unbonded status for the valset update report func (k Keeper) ScheduleUnbonded(ctx sdk.Context, addr sdk.ValAddress) error { - return k.sendAsync(ctx, types.ValidatorUnbonded, addr, nil) + packet := cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_UNBONDED, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: addr.String(), + Denom: k.Staking.BondDenom(ctx), + }, + }, + } + return k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_UNBONDED, addr, packet) } // ScheduleSlashed store a validator slash event / data for the valset update report -func (k Keeper) ScheduleSlashed(ctx sdk.Context, addr sdk.ValAddress, power int64, height int64, totalSlashAmount math.Int, slashRatio sdk.Dec) error { - var slashInfo = &types.SlashInfo{ +func (k Keeper) ScheduleSlashed(ctx sdk.Context, valAddr sdk.ValAddress, slashRatio sdk.Dec) error { + power := k.Staking.GetLastValidatorPower(ctx, valAddr) + infractionHeight := ctx.BlockHeight() - sdk.ValidatorUpdateDelay - 1 + validator, _ := k.Staking.GetValidator(ctx, valAddr) + totalSlashAmount := sdk.NewDecFromInt(validator.Tokens).MulTruncate(slashRatio).RoundInt() + // TODO: timeInfraction + + var slashInfo = &cptypes.SlashInfo{ + Validator: validator.OperatorAddress, Power: power, - InfractionHeight: height, + InfractionHeight: infractionHeight, TotalSlashAmount: totalSlashAmount.String(), SlashFraction: slashRatio.String(), + // TODO: timeInfraction + TimeInfraction: 0, } - return k.sendAsync(ctx, types.ValidatorSlashed, addr, slashInfo) + + packet := cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_SLASHED, + Data: &cptypes.ConsumerPacketData_SlashPacketData{ + SlashPacketData: slashInfo, + }, + } + return k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_SLASHED, valAddr, packet) } // ScheduleJailed store a validator update to jailed status for the valset update report func (k Keeper) ScheduleJailed(ctx sdk.Context, addr sdk.ValAddress) error { - return k.sendAsync(ctx, types.ValidatorJailed, addr, nil) + packet := cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_JAILED, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: addr.String(), + Denom: k.Staking.BondDenom(ctx), + }, + }, + } + return k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_JAILED, addr, packet) } // ScheduleTombstoned store a validator update to tombstoned status for the valset update report func (k Keeper) ScheduleTombstoned(ctx sdk.Context, addr sdk.ValAddress) error { - return k.sendAsync(ctx, types.ValidatorTombstoned, addr, nil) + packet := cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_TOMBSTONED, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: addr.String(), + Denom: k.Staking.BondDenom(ctx), + }, + }, + } + return k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_TOMBSTONED, addr, packet) } // ScheduleUnjailed store a validator update to unjailed status for the valset update report func (k Keeper) ScheduleUnjailed(ctx sdk.Context, addr sdk.ValAddress) error { - return k.sendAsync(ctx, types.ValidatorUnjailed, addr, nil) + packet := cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_UNJAILED, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: addr.String(), + Denom: k.Staking.BondDenom(ctx), + }, + }, + } + return k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_UNJAILED, addr, packet) } // ScheduleModified store a validator metadata update for the valset update report func (k Keeper) ScheduleModified(ctx sdk.Context, addr sdk.ValAddress) error { - return k.sendAsync(ctx, types.ValidatorModified, addr, nil) + packet := cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_MODIFIED, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: addr.String(), + Denom: k.Staking.BondDenom(ctx), + }, + }, + } + return k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_MODIFIED, addr, packet) } // instead of sync calls to the contracts for the different kind of valset changes in a block, we store them in the mem db // and async send to all registered contracts in the end blocker -func (k Keeper) sendAsync(ctx sdk.Context, op types.PipedValsetOperation, valAddr sdk.ValAddress, slashInfo *types.SlashInfo) error { +func (k Keeper) sendAsync(ctx sdk.Context, op cptypes.PipedValsetOperation, valAddr sdk.ValAddress, packet cptypes.ConsumerPacketData) error { + // if op ModuleLogger(ctx).Debug("storing for async update", "operation", int(op), "val", valAddr.String()) - ctx.KVStore(k.memKey).Set(types.BuildPipedValsetOpKey(op, valAddr, slashInfo), []byte{}) + value := packet.MarshalConsumerPacketData() + ctx.KVStore(k.memKey).Set(types.BuildPipedValsetOpKey(op, valAddr), value) // and schedule an update callback for all registered contracts var innerErr error k.IterateMaxCapLimit(ctx, func(contractAddr sdk.AccAddress, m math.Int) bool { @@ -88,9 +160,9 @@ func (k Keeper) ValsetUpdateReport(ctx sdk.Context) (contract.ValsetUpdate, erro *set = append(*set, ConvertSdkValidatorToWasm(val)) return false } - slashValidator := func(set *[]outmessage.ValidatorSlash, valAddr sdk.ValAddress, power int64, infractionHeight int64, + slashValidator := func(set *[]contract.ValidatorSlash, valAddr sdk.ValAddress, power int64, infractionHeight int64, infractionTime int64, slashAmount string, slashRatio string) bool { - valSlash := outmessage.ValidatorSlash{ + valSlash := contract.ValidatorSlash{ ValidatorAddr: valAddr.String(), Power: power, InfractionHeight: infractionHeight, @@ -112,26 +184,47 @@ func (k Keeper) ValsetUpdateReport(ctx sdk.Context) (contract.ValsetUpdate, erro Tombstoned: make([]contract.ValidatorAddr, 0), Slashed: make([]contract.ValidatorSlash, 0), } - err := k.iteratePipedValsetOperations(ctx, func(valAddr sdk.ValAddress, op types.PipedValsetOperation, slashInfo *types.SlashInfo) bool { - switch op { - case types.ValidatorBonded: + err := k.iteratePipedValsetOperations(ctx, func(packet *cptypes.ConsumerPacketData) bool { + switch packet.Type { + case cptypes.PipedValsetOperation_VALIDATOR_BONDED: + data := packet.GetSchedulePacketData() + valAddr, err := sdk.ValAddressFromBech32(data.Validator) + if err != nil { + innerErr = types.ErrUnknown.Wrapf("validator does not exist %v", err) + return true + } return appendValidator(&r.Additions, valAddr) - case types.ValidatorUnbonded: - r.Removals = append(r.Removals, valAddr.String()) - case types.ValidatorJailed: - r.Jailed = append(r.Jailed, valAddr.String()) - case types.ValidatorTombstoned: - r.Tombstoned = append(r.Tombstoned, valAddr.String()) - case types.ValidatorUnjailed: - r.Unjailed = append(r.Unjailed, valAddr.String()) - case types.ValidatorModified: + case cptypes.PipedValsetOperation_VALIDATOR_UNBONDED: + data := packet.GetSchedulePacketData() + r.Removals = append(r.Removals, data.Validator) + case cptypes.PipedValsetOperation_VALIDATOR_JAILED: + data := packet.GetSchedulePacketData() + r.Jailed = append(r.Jailed, data.Validator) + case cptypes.PipedValsetOperation_VALIDATOR_TOMBSTONED: + data := packet.GetSchedulePacketData() + r.Tombstoned = append(r.Tombstoned, data.Validator) + case cptypes.PipedValsetOperation_VALIDATOR_UNJAILED: + data := packet.GetSchedulePacketData() + r.Unjailed = append(r.Unjailed, data.Validator) + case cptypes.PipedValsetOperation_VALIDATOR_MODIFIED: + data := packet.GetSchedulePacketData() + valAddr, err := sdk.ValAddressFromBech32(data.Validator) + if err != nil { + innerErr = types.ErrUnknown.Wrapf("validator does not exist %v", err) + return true + } return appendValidator(&r.Updated, valAddr) - case types.ValidatorSlashed: - // TODO: Add / send the infraction time - return slashValidator(&r.Slashed, valAddr, slashInfo.Power, slashInfo.InfractionHeight, 0, - slashInfo.TotalSlashAmount, slashInfo.SlashFraction) + case cptypes.PipedValsetOperation_VALIDATOR_SLASHED: + data := packet.GetSlashPacketData() + valAddr, err := sdk.ValAddressFromBech32(data.Validator) + if err != nil { + innerErr = types.ErrUnknown.Wrapf("validator does not exist %v", err) + return true + } + return slashValidator(&r.Slashed, valAddr, data.Power, data.InfractionHeight, data.TimeInfraction, + data.TotalSlashAmount, data.SlashFraction) default: - innerErr = types.ErrInvalid.Wrapf("undefined operation type %X", op) + innerErr = types.ErrInvalid.Wrapf("undefined operation type %X", packet.Type) return true } return false @@ -157,27 +250,15 @@ func (k Keeper) ClearPipedValsetOperations(ctx sdk.Context) { } // iterate through all stored valset updates. Due to the storage key, there are no contract duplicates within an operation type. -func (k Keeper) iteratePipedValsetOperations(ctx sdk.Context, cb func(valAddress sdk.ValAddress, op types.PipedValsetOperation, slashInfo *types.SlashInfo) bool) error { +func (k Keeper) iteratePipedValsetOperations(ctx sdk.Context, cb func(packet *cptypes.ConsumerPacketData) bool) error { pStore := prefix.NewStore(ctx.KVStore(k.memKey), types.PipedValsetPrefix) iter := pStore.Iterator(nil, nil) for ; iter.Valid(); iter.Next() { - key := iter.Key() - addrLen := key[0] - addr, op := key[1:addrLen+1], key[addrLen+1] - var slashInfo *types.SlashInfo = nil - if types.PipedValsetOperation(op) == types.ValidatorSlashed { - if len(key) <= 1+int(addrLen)+1+8+8+1 { - return types.ErrInvalid.Wrapf("invalid slash key length %d", len(key)) - } - totalSlashAmountLen := key[addrLen+2+8+8] - slashInfo = &types.SlashInfo{ - Power: int64(sdk.BigEndianToUint64(key[addrLen+2 : addrLen+2+8])), - InfractionHeight: int64(sdk.BigEndianToUint64(key[addrLen+2+8 : addrLen+2+8+8])), - TotalSlashAmount: string(key[addrLen+2+8+8+1 : addrLen+2+8+8+1+totalSlashAmountLen]), - SlashFraction: string(key[addrLen+2+8+8+1+totalSlashAmountLen:]), - } + consumerPacket, err := cptypes.UnmarshalConsumerPacketData(iter.Value()) + if err != nil { + panic(err) } - if cb(addr, types.PipedValsetOperation(op), slashInfo) { + if cb(&consumerPacket) { break } } diff --git a/x/meshsecurity/keeper/valset_updates_test.go b/x/meshsecurity/keeper/valset_updates_test.go index 5d794593..74646a86 100644 --- a/x/meshsecurity/keeper/valset_updates_test.go +++ b/x/meshsecurity/keeper/valset_updates_test.go @@ -4,6 +4,7 @@ import ( "bytes" stdrand "math/rand" "testing" + "time" "github.com/cometbft/cometbft/libs/rand" "github.com/stretchr/testify/assert" @@ -13,10 +14,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/contract" "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types" + cptypes "github.com/osmosis-labs/mesh-security-sdk/x/types" ) func TestSendAsync(t *testing.T) { @@ -30,36 +33,60 @@ func TestSendAsync(t *testing.T) { ) specs := map[string]struct { setup func(t *testing.T, ctx sdk.Context) - assert func(t *testing.T, ctx sdk.Context, ops map[string][]types.PipedValsetOperation) + assert func(t *testing.T, ctx sdk.Context, ops map[string][]cptypes.PipedValsetOperation) }{ "no duplicates": { setup: func(t *testing.T, ctx sdk.Context) { - require.NoError(t, k.sendAsync(ctx, types.ValidatorModified, myValAddr, nil)) + packet := cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_MODIFIED, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: myValAddr.String(), + }, + }, + } + require.NoError(t, k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_MODIFIED, myValAddr, packet)) }, - assert: func(t *testing.T, ctx sdk.Context, ops map[string][]types.PipedValsetOperation) { + assert: func(t *testing.T, ctx sdk.Context, ops map[string][]cptypes.PipedValsetOperation) { assert.Len(t, ops, 1) - exp := []types.PipedValsetOperation{types.ValidatorModified} + exp := []cptypes.PipedValsetOperation{cptypes.PipedValsetOperation_VALIDATOR_MODIFIED} assert.Equal(t, exp, ops[myValAddr.String()]) }, }, "separated by validator": { setup: func(t *testing.T, ctx sdk.Context) { - require.NoError(t, k.sendAsync(ctx, types.ValidatorModified, myOtherValAddr, nil)) + packet := cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_MODIFIED, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: myOtherValAddr.String(), + }, + }, + } + require.NoError(t, k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_MODIFIED, myOtherValAddr, packet)) }, - assert: func(t *testing.T, ctx sdk.Context, ops map[string][]types.PipedValsetOperation) { + assert: func(t *testing.T, ctx sdk.Context, ops map[string][]cptypes.PipedValsetOperation) { assert.Len(t, ops, 2) - exp := []types.PipedValsetOperation{types.ValidatorModified} + exp := []cptypes.PipedValsetOperation{cptypes.PipedValsetOperation_VALIDATOR_MODIFIED} assert.Equal(t, exp, ops[myValAddr.String()]) assert.Equal(t, exp, ops[myOtherValAddr.String()]) }, }, "separated by type": { setup: func(t *testing.T, ctx sdk.Context) { - require.NoError(t, k.sendAsync(ctx, types.ValidatorBonded, myValAddr, nil)) + packet := cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_BONDED, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: myValAddr.String(), + }, + }, + } + require.NoError(t, k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_BONDED, myValAddr, packet)) }, - assert: func(t *testing.T, ctx sdk.Context, ops map[string][]types.PipedValsetOperation) { + assert: func(t *testing.T, ctx sdk.Context, ops map[string][]cptypes.PipedValsetOperation) { assert.Len(t, ops, 1) - exp := []types.PipedValsetOperation{types.ValidatorBonded, types.ValidatorModified} + exp := []cptypes.PipedValsetOperation{cptypes.PipedValsetOperation_VALIDATOR_BONDED, cptypes.PipedValsetOperation_VALIDATOR_MODIFIED} assert.Equal(t, exp, ops[myValAddr.String()]) }, }, @@ -70,7 +97,7 @@ func TestSendAsync(t *testing.T) { err = k.SetMaxCapLimit(ctx, myOtherVStakingContractAddr, sdk.NewCoin("stake", sdkmath.NewInt(100_000_000))) require.NoError(t, err) }, - assert: func(t *testing.T, ctx sdk.Context, ops map[string][]types.PipedValsetOperation) { + assert: func(t *testing.T, ctx sdk.Context, ops map[string][]cptypes.PipedValsetOperation) { isScheduled := k.HasScheduledTask(ctx, types.SchedulerTaskValsetUpdate, myVStakingContractAddr, false) assert.True(t, isScheduled) isScheduled = k.HasScheduledTask(ctx, types.SchedulerTaskValsetUpdate, myOtherVStakingContractAddr, false) @@ -82,7 +109,7 @@ func TestSendAsync(t *testing.T) { err := k.SetMaxCapLimit(ctx, myVStakingContractAddr, sdk.NewCoin("stake", sdkmath.NewInt(100_000_000))) require.NoError(t, err) }, - assert: func(t *testing.T, ctx sdk.Context, ops map[string][]types.PipedValsetOperation) { + assert: func(t *testing.T, ctx sdk.Context, ops map[string][]cptypes.PipedValsetOperation) { isScheduled := k.HasScheduledTask(ctx, types.SchedulerTaskValsetUpdate, myVStakingContractAddr, false) assert.True(t, isScheduled) isScheduled = k.HasScheduledTask(ctx, types.SchedulerTaskValsetUpdate, myOtherVStakingContractAddr, false) @@ -95,7 +122,15 @@ func TestSendAsync(t *testing.T) { ctx, _ := pCtx.CacheContext() spec.setup(t, ctx) // when - gotErr := k.sendAsync(ctx, types.ValidatorModified, myValAddr, nil) + packet := cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_MODIFIED, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: myValAddr.String(), + }, + }, + } + gotErr := k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_MODIFIED, myValAddr, packet) // then require.NoError(t, gotErr) allStoredOps := FetchAllStoredOperations(t, ctx, k) @@ -123,26 +158,34 @@ func TestBuildValsetUpdateReport(t *testing.T) { } type tuple struct { - op types.PipedValsetOperation + op cptypes.PipedValsetOperation valAddr sdk.ValAddress } allOps := []tuple{ - {op: types.ValidatorJailed, valAddr: val1}, - {op: types.ValidatorUnjailed, valAddr: val2}, - {op: types.ValidatorModified, valAddr: val2}, - {op: types.ValidatorUnbonded, valAddr: val3}, - {op: types.ValidatorJailed, valAddr: val3}, - {op: types.ValidatorTombstoned, valAddr: val3}, - {op: types.ValidatorModified, valAddr: val3}, - {op: types.ValidatorBonded, valAddr: val4}, - {op: types.ValidatorModified, valAddr: val4}, + {op: cptypes.PipedValsetOperation_VALIDATOR_JAILED, valAddr: val1}, + {op: cptypes.PipedValsetOperation_VALIDATOR_UNJAILED, valAddr: val2}, + {op: cptypes.PipedValsetOperation_VALIDATOR_MODIFIED, valAddr: val2}, + {op: cptypes.PipedValsetOperation_VALIDATOR_UNBONDED, valAddr: val3}, + {op: cptypes.PipedValsetOperation_VALIDATOR_JAILED, valAddr: val3}, + {op: cptypes.PipedValsetOperation_VALIDATOR_TOMBSTONED, valAddr: val3}, + {op: cptypes.PipedValsetOperation_VALIDATOR_MODIFIED, valAddr: val3}, + {op: cptypes.PipedValsetOperation_VALIDATOR_BONDED, valAddr: val4}, + {op: cptypes.PipedValsetOperation_VALIDATOR_MODIFIED, valAddr: val4}, } stdrand.Shuffle(len(allOps), func(i, j int) { allOps[i], allOps[j] = allOps[j], allOps[i] }) for _, v := range allOps { - require.NoError(t, k.sendAsync(ctx, v.op, v.valAddr, nil)) + packet := cptypes.ConsumerPacketData{ + Type: v.op, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: v.valAddr.String(), + }, + }, + } + require.NoError(t, k.sendAsync(ctx, v.op, v.valAddr, packet)) } // when got, err := k.ValsetUpdateReport(ctx) @@ -187,7 +230,8 @@ func TestBuildValsetUpdateReport(t *testing.T) { } func TestValsetUpdateReportErrors(t *testing.T) { - nonValAddr := sdk.ValAddress(bytes.Repeat([]byte{1}, address.Len)) + nonVal := MinValidatorFixture(t) + nonValAddr := nonVal.GetOperator() pCtx, keepers := CreateDefaultTestInput(t) k := keepers.MeshKeeper @@ -197,16 +241,47 @@ func TestValsetUpdateReportErrors(t *testing.T) { }{ "unknown val address": { setup: func(t *testing.T, ctx sdk.Context) { - require.NoError(t, k.sendAsync(ctx, types.ValidatorBonded, nonValAddr, nil)) + packet := cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_BONDED, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: nonValAddr.String(), + }, + }, + } + require.NoError(t, k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_BONDED, nonValAddr, packet)) }, expErr: types.ErrUnknown, }, "unsupported val operation": { setup: func(t *testing.T, ctx sdk.Context) { - require.NoError(t, k.sendAsync(ctx, 0xff, nonValAddr, nil)) + packet := cptypes.ConsumerPacketData{ + Type: 0xff, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: nonValAddr.String(), + }, + }, + } + require.NoError(t, k.sendAsync(ctx, 0xff, nonValAddr, packet)) }, expErr: types.ErrInvalid, }, + "success": { + setup: func(t *testing.T, ctx sdk.Context) { + packet := cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_BONDED, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: nonValAddr.String(), + }, + }, + } + keepers.StakingKeeper.SetValidator(pCtx, nonVal) + require.NoError(t, k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_BONDED, nonValAddr, packet)) + }, + expErr: nil, + }, } for name, spec := range specs { t.Run(name, func(t *testing.T) { @@ -214,8 +289,11 @@ func TestValsetUpdateReportErrors(t *testing.T) { spec.setup(t, ctx) // when _, gotErr := k.ValsetUpdateReport(ctx) - require.Error(t, gotErr) - assert.ErrorIs(t, spec.expErr, gotErr) + if spec.expErr != nil { + assert.ErrorIs(t, spec.expErr, gotErr) + } else { + assert.NoError(t, gotErr) + } }) } } @@ -223,12 +301,71 @@ func TestValsetUpdateReportErrors(t *testing.T) { func TestClearPipedValsetOperations(t *testing.T) { ctx, keepers := CreateDefaultTestInput(t) k := keepers.MeshKeeper - err := k.sendAsync(ctx, types.ValidatorModified, rand.Bytes(address.Len), nil) + val := rand.Bytes(address.Len) + packet := cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_MODIFIED, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: string(val), + }, + }, + } + err := k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_MODIFIED, val, packet) require.NoError(t, err) - err = k.sendAsync(ctx, types.ValidatorUnjailed, rand.Bytes(address.Len), nil) + + packet = cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_UNJAILED, + Data: &cptypes.ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &cptypes.ScheduleInfo{ + Validator: string(val), + }, + }, + } + err = k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_UNJAILED, val, packet) require.NoError(t, err) // when k.ClearPipedValsetOperations(ctx) // then assert.Empty(t, FetchAllStoredOperations(t, ctx, k)) } + +func TestSetAndGetScheduleSlashed(t *testing.T) { + ctx, keepers := CreateDefaultTestInput(t) + k := keepers.MeshKeeper + + valAdrees := sdk.ValAddress(rand.Bytes(address.Len)) + slashInfo := &cptypes.SlashInfo{ + Validator: valAdrees.String(), + Power: 12, + InfractionHeight: 123, + TotalSlashAmount: sdk.NewInt(1000).String(), + SlashFraction: sdk.NewDec(1).String(), + TimeInfraction: time.Now().Unix(), + } + + packet := cptypes.ConsumerPacketData{ + Type: cptypes.PipedValsetOperation_VALIDATOR_SLASHED, + Data: &cptypes.ConsumerPacketData_SlashPacketData{ + SlashPacketData: slashInfo, + }, + } + // set + err := k.sendAsync(ctx, cptypes.PipedValsetOperation_VALIDATOR_SLASHED, valAdrees, packet) + require.NoError(t, err) + // get + var getSlash cptypes.SlashInfo + err = k.iteratePipedValsetOperations(ctx, func(packet *cptypes.ConsumerPacketData) bool { + if packet.Type == cptypes.PipedValsetOperation_VALIDATOR_SLASHED { + getSlash = *packet.GetSlashPacketData() + return true + } + return false + }) + require.NoError(t, err) + // check + require.Equal(t, slashInfo.TimeInfraction, getSlash.TimeInfraction) + require.Equal(t, slashInfo.Power, getSlash.Power) + require.Equal(t, slashInfo.InfractionHeight, getSlash.InfractionHeight) + require.Equal(t, slashInfo.TotalSlashAmount, getSlash.TotalSlashAmount) + require.Equal(t, valAdrees.String(), getSlash.Validator) +} diff --git a/x/meshsecurity/types/errors.go b/x/meshsecurity/types/errors.go index da76a5a1..661c6e76 100644 --- a/x/meshsecurity/types/errors.go +++ b/x/meshsecurity/types/errors.go @@ -5,8 +5,10 @@ import ( ) var ( - ErrInvalid = errorsmod.Register(ModuleName, 1, "invalid") - ErrMaxCapExceeded = errorsmod.Register(ModuleName, 2, "max cap exceeded") - ErrUnsupported = errorsmod.Register(ModuleName, 3, "unsupported") - ErrUnknown = errorsmod.Register(ModuleName, 4, "unknown") + ErrInvalid = errorsmod.Register(ModuleName, 1, "invalid") + ErrMaxCapExceeded = errorsmod.Register(ModuleName, 2, "max cap exceeded") + ErrUnsupported = errorsmod.Register(ModuleName, 3, "unsupported") + ErrUnknown = errorsmod.Register(ModuleName, 4, "unknown") + ErrNoProposerChannelId = errorsmod.Register(ModuleName, 5, "no established meshsecurity channel") + ErrConsumerRewardDenomAlreadyRegistered = errorsmod.Register(ModuleName, 6, "consumer reward denom already registered") ) diff --git a/x/meshsecurity/types/expected_keepers.go b/x/meshsecurity/types/expected_keepers.go index 57d52a51..021d8318 100644 --- a/x/meshsecurity/types/expected_keepers.go +++ b/x/meshsecurity/types/expected_keepers.go @@ -8,6 +8,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" ) type SDKBankKeeper interface { @@ -39,6 +45,7 @@ type SDKStakingKeeper interface { TotalBondedTokens(ctx sdk.Context) math.Int IterateDelegations(ctx sdk.Context, delegator sdk.AccAddress, fn func(int64, stakingtypes.DelegationI) bool) GetValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) (stakingtypes.Validator, bool) + GetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress) int64 } type XStakingKeeper interface { @@ -62,3 +69,27 @@ type WasmKeeper interface { Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) HasContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) bool } + +// ChannelKeeper defines the expected IBC channel keeper +type ChannelKeeper interface { + GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) + GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) + SendPacket( + ctx sdk.Context, + chanCap *capabilitytypes.Capability, + sourcePort string, + sourceChannel string, + timeoutHeight clienttypes.Height, + timeoutTimestamp uint64, + data []byte, + ) (sequence uint64, err error) + WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error + ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error + GetChannelConnection(ctx sdk.Context, portID, channelID string) (string, ibcexported.ConnectionI, error) +} + +type ScopedKeeper interface { + GetCapability(ctx sdk.Context, name string) (*capabilitytypes.Capability, bool) + AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool + ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error +} diff --git a/x/meshsecurity/types/genesis.pb.go b/x/meshsecurity/types/genesis.pb.go index 5575e806..f0eb82ba 100644 --- a/x/meshsecurity/types/genesis.pb.go +++ b/x/meshsecurity/types/genesis.pb.go @@ -5,21 +5,18 @@ package types import ( fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. -var ( - _ = proto.Marshal - _ = fmt.Errorf - _ = math.Inf -) +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -38,11 +35,9 @@ func (*GenesisState) ProtoMessage() {} func (*GenesisState) Descriptor() ([]byte, []int) { return fileDescriptor_e38a457d5139d73a, []int{0} } - func (m *GenesisState) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } - func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) @@ -55,15 +50,12 @@ func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) return b[:n], nil } } - func (m *GenesisState) XXX_Merge(src proto.Message) { xxx_messageInfo_GenesisState.Merge(m, src) } - func (m *GenesisState) XXX_Size() int { return m.Size() } - func (m *GenesisState) XXX_DiscardUnknown() { xxx_messageInfo_GenesisState.DiscardUnknown(m) } @@ -122,7 +114,6 @@ func (this *GenesisState) Equal(that interface{}) bool { } return true } - func (m *GenesisState) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -167,7 +158,6 @@ func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } - func (m *GenesisState) Size() (n int) { if m == nil { return 0 @@ -182,11 +172,9 @@ func (m *GenesisState) Size() (n int) { func sovGenesis(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } - func sozGenesis(x uint64) (n int) { return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } - func (m *GenesisState) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -270,7 +258,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } return nil } - func skipGenesis(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/meshsecurity/types/keys.go b/x/meshsecurity/types/keys.go index fa21f06c..2e1eb428 100644 --- a/x/meshsecurity/types/keys.go +++ b/x/meshsecurity/types/keys.go @@ -1,20 +1,20 @@ package types import ( - "encoding/binary" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" + + cptypes "github.com/osmosis-labs/mesh-security-sdk/x/types" ) const ( // ModuleName defines the module name. - ModuleName = "meshsecurity" + ModuleName = "meshsecurity-consummer" // StoreKey defines the primary module store key. StoreKey = ModuleName // MemStoreKey defines the in-memory store key - MemStoreKey = "memory:meshsecurity" + MemStoreKey = "memory:meshsecurity-consummer" // RouterKey is the message route RouterKey = ModuleName @@ -30,29 +30,10 @@ var ( TotalDelegatedAmountKeyPrefix = []byte{0x3} SchedulerKeyPrefix = []byte{0x4} - PipedValsetPrefix = []byte{0x5} -) - -type PipedValsetOperation byte - -const ( - ValsetOperationUndefined PipedValsetOperation = iota - ValidatorBonded - ValidatorUnbonded - ValidatorJailed - ValidatorTombstoned - ValidatorUnjailed - ValidatorModified - ValidatorSlashed + PipedValsetPrefix = []byte{0x5} + ProviderChannelByteKey = []byte{0x6} ) -type SlashInfo struct { - InfractionHeight int64 - Power int64 - TotalSlashAmount string - SlashFraction string -} - // BuildMaxCapLimitKey build max cap limit store key func BuildMaxCapLimitKey(contractAddr sdk.AccAddress) []byte { return append(MaxCapLimitKeyPrefix, contractAddr.Bytes()...) @@ -90,32 +71,16 @@ func BuildSchedulerContractKey(tp SchedulerTaskType, blockHeight uint64, contrac } // BuildPipedValsetOpKey build store key for the temporary valset operation store -func BuildPipedValsetOpKey(op PipedValsetOperation, val sdk.ValAddress, slashInfo *SlashInfo) []byte { - if op == ValsetOperationUndefined { +func BuildPipedValsetOpKey(op cptypes.PipedValsetOperation, val sdk.ValAddress) []byte { + if op == cptypes.PipedValsetOperation_UNSPECIFIED { panic("empty operation") } - pn, an := len(PipedValsetPrefix), len(val) - sn := 0 - if op == ValidatorSlashed { - if slashInfo == nil { - panic("slash info is nil") - } - sn = 8 + 8 + 1 + len(slashInfo.TotalSlashAmount) + len(slashInfo.SlashFraction) // 8 for height, 8 for power, +1 for total amount length - } - r := make([]byte, pn+an+sn+1+1) // +1 for address prefix, +1 for op - copy(r, PipedValsetPrefix) - copy(r[pn:], address.MustLengthPrefix(val)) - r[pn+an+1] = byte(op) - if op == ValidatorSlashed { - b := make([]byte, 8) - binary.BigEndian.PutUint64(b, uint64(slashInfo.InfractionHeight)) - copy(r[pn+an+1+1:], b) - binary.BigEndian.PutUint64(b, uint64(slashInfo.Power)) - copy(r[pn+an+1+1+8:], b) - tn := len(slashInfo.TotalSlashAmount) - r[pn+an+1+1+8+8] = byte(tn) - copy(r[pn+an+1+1+8+8+1:], slashInfo.TotalSlashAmount) - copy(r[pn+an+1+1+8+8+1+tn:], slashInfo.SlashFraction) - } - return r + k := append(append(PipedValsetPrefix, byte(op)), val...) + // return + return k +} + +// ProviderChannelKey returns the key for storing channelID of the provider chain +func ProviderChannelKey() []byte { + return ProviderChannelByteKey } diff --git a/x/meshsecurity/types/meshsecurity.pb.go b/x/meshsecurity/types/meshsecurity.pb.go index 91e1950b..ae9df2e6 100644 --- a/x/meshsecurity/types/meshsecurity.pb.go +++ b/x/meshsecurity/types/meshsecurity.pb.go @@ -5,22 +5,19 @@ package types import ( fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. -var ( - _ = proto.Marshal - _ = fmt.Errorf - _ = math.Inf -) +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -45,11 +42,9 @@ func (*VirtualStakingMaxCapInfo) ProtoMessage() {} func (*VirtualStakingMaxCapInfo) Descriptor() ([]byte, []int) { return fileDescriptor_53771980e3e4256c, []int{0} } - func (m *VirtualStakingMaxCapInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } - func (m *VirtualStakingMaxCapInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_VirtualStakingMaxCapInfo.Marshal(b, m, deterministic) @@ -62,15 +57,12 @@ func (m *VirtualStakingMaxCapInfo) XXX_Marshal(b []byte, deterministic bool) ([] return b[:n], nil } } - func (m *VirtualStakingMaxCapInfo) XXX_Merge(src proto.Message) { xxx_messageInfo_VirtualStakingMaxCapInfo.Merge(m, src) } - func (m *VirtualStakingMaxCapInfo) XXX_Size() int { return m.Size() } - func (m *VirtualStakingMaxCapInfo) XXX_DiscardUnknown() { xxx_messageInfo_VirtualStakingMaxCapInfo.DiscardUnknown(m) } @@ -87,6 +79,7 @@ type Params struct { // MaxGasEndBlocker defines the maximum gas that can be spent in a contract // sudo callback MaxGasEndBlocker uint32 `protobuf:"varint,3,opt,name=max_gas_end_blocker,json=maxGasEndBlocker,proto3" json:"max_gas_end_blocker,omitempty"` + InfractionTime uint64 `protobuf:"varint,4,opt,name=infraction_time,json=infractionTime,proto3" json:"infraction_time,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -95,11 +88,9 @@ func (*Params) ProtoMessage() {} func (*Params) Descriptor() ([]byte, []int) { return fileDescriptor_53771980e3e4256c, []int{1} } - func (m *Params) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } - func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_Params.Marshal(b, m, deterministic) @@ -112,15 +103,12 @@ func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return b[:n], nil } } - func (m *Params) XXX_Merge(src proto.Message) { xxx_messageInfo_Params.Merge(m, src) } - func (m *Params) XXX_Size() int { return m.Size() } - func (m *Params) XXX_DiscardUnknown() { xxx_messageInfo_Params.DiscardUnknown(m) } @@ -137,33 +125,35 @@ func init() { } var fileDescriptor_53771980e3e4256c = []byte{ - // 416 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x41, 0x8b, 0xd3, 0x40, - 0x14, 0xce, 0xb8, 0xcb, 0xe2, 0xce, 0xba, 0xa0, 0xd9, 0x05, 0x63, 0x59, 0x66, 0xd7, 0x9e, 0x8a, - 0x90, 0x84, 0xea, 0xad, 0xa0, 0x87, 0x16, 0x11, 0x41, 0x41, 0x22, 0xf4, 0xe0, 0x25, 0xbe, 0x4c, - 0xc6, 0x64, 0x68, 0x32, 0x13, 0x32, 0x53, 0x49, 0xff, 0x82, 0x27, 0x7f, 0x82, 0x47, 0x4f, 0xe2, - 0xcf, 0xe8, 0xb1, 0x47, 0x4f, 0xa2, 0xe9, 0x41, 0x7f, 0x86, 0x64, 0xd2, 0x54, 0x72, 0xeb, 0x65, - 0x78, 0xf3, 0xbd, 0xf9, 0xbe, 0xf9, 0x3e, 0xde, 0xc3, 0xbe, 0x54, 0xb9, 0x54, 0x5c, 0xf9, 0x39, - 0x53, 0xa9, 0x62, 0x74, 0x59, 0x72, 0xbd, 0xf2, 0x3f, 0x8e, 0x23, 0xa6, 0x61, 0xdc, 0x03, 0xbd, - 0xa2, 0x94, 0x5a, 0xda, 0x57, 0x3b, 0x82, 0xd7, 0xeb, 0xed, 0x08, 0x03, 0x42, 0x4d, 0xdb, 0x8f, - 0x40, 0xb1, 0xbd, 0x0a, 0x95, 0x5c, 0xb4, 0xec, 0xc1, 0x65, 0x22, 0x13, 0x69, 0x4a, 0xbf, 0xa9, - 0x76, 0xe8, 0x3d, 0xc8, 0xb9, 0x90, 0xbe, 0x39, 0x5b, 0x68, 0xf8, 0x0d, 0x61, 0x67, 0xce, 0x4b, - 0xbd, 0x84, 0xec, 0xad, 0x86, 0x05, 0x17, 0xc9, 0x6b, 0xa8, 0x66, 0x50, 0xbc, 0x14, 0x1f, 0xa4, - 0x3d, 0xc0, 0xb7, 0xa9, 0x14, 0xba, 0x04, 0xaa, 0x1d, 0x74, 0x83, 0x46, 0xa7, 0xc1, 0xfe, 0x6e, - 0x3f, 0xc5, 0xa7, 0x31, 0xcb, 0x58, 0x02, 0x9a, 0xc5, 0xce, 0xad, 0x1b, 0x34, 0x3a, 0x7b, 0xfc, - 0xc0, 0x6b, 0x5d, 0x79, 0x8d, 0xab, 0xce, 0xaa, 0x37, 0x93, 0x5c, 0x4c, 0x8f, 0xd7, 0x3f, 0xaf, - 0xad, 0xe0, 0x3f, 0xc3, 0x1e, 0xe3, 0x23, 0x0a, 0x85, 0x73, 0x74, 0x18, 0xb1, 0x79, 0x3b, 0x39, - 0xfe, 0xfb, 0xe5, 0x1a, 0x0d, 0x37, 0x08, 0x9f, 0xbc, 0x81, 0x12, 0x72, 0x65, 0xcf, 0xf1, 0x7d, - 0x2d, 0x35, 0x64, 0x61, 0x67, 0x4a, 0x85, 0x39, 0x54, 0x61, 0xa3, 0x8b, 0x0e, 0xd3, 0xbd, 0x34, - 0xfc, 0x59, 0x47, 0x6f, 0xa3, 0xdb, 0x0f, 0xf1, 0x1d, 0x56, 0x48, 0x9a, 0x86, 0x19, 0x13, 0x89, - 0x4e, 0x4d, 0xba, 0xf3, 0xe0, 0xcc, 0x60, 0xaf, 0x0c, 0x64, 0xbb, 0xf8, 0xa2, 0xf9, 0x2a, 0x01, - 0x15, 0x32, 0x11, 0x87, 0x51, 0x26, 0xe9, 0x82, 0x95, 0x26, 0xce, 0x79, 0x70, 0x37, 0x87, 0xea, - 0x05, 0xa8, 0xe7, 0x22, 0x9e, 0xb6, 0xf8, 0xe4, 0xaa, 0xb1, 0xfe, 0xe9, 0xcf, 0xf7, 0x47, 0x17, - 0xbd, 0xf1, 0xb7, 0x39, 0xa6, 0xef, 0xd7, 0xbf, 0x89, 0xf5, 0xb5, 0x26, 0xd6, 0xba, 0x26, 0x68, - 0x53, 0x13, 0xf4, 0xab, 0x26, 0xe8, 0xf3, 0x96, 0x58, 0x9b, 0x2d, 0xb1, 0x7e, 0x6c, 0x89, 0xf5, - 0xee, 0x59, 0xc2, 0x75, 0xba, 0x8c, 0x3c, 0x2a, 0xf3, 0x6e, 0x91, 0xdc, 0x0c, 0xa2, 0x76, 0x9b, - 0xdc, 0x4e, 0xcf, 0x55, 0xf1, 0xc2, 0xaf, 0xfa, 0x1b, 0xa6, 0x57, 0x05, 0x53, 0xd1, 0x89, 0x19, - 0xf6, 0x93, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x98, 0xcb, 0x62, 0xae, 0x86, 0x02, 0x00, 0x00, + // 444 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x3f, 0x6f, 0xd3, 0x40, + 0x1c, 0xf5, 0xd1, 0xa8, 0xa2, 0x57, 0xca, 0x9f, 0x6b, 0x25, 0x4c, 0x54, 0x5d, 0x43, 0x17, 0x22, + 0xa4, 0xd8, 0x0a, 0x6c, 0x95, 0x60, 0x48, 0x84, 0x10, 0x12, 0x48, 0xc8, 0xa0, 0x0e, 0x2c, 0xe6, + 0xe7, 0xf3, 0xd5, 0x39, 0xc5, 0x77, 0x67, 0xf9, 0x2e, 0x28, 0xfd, 0x0a, 0x4c, 0x7c, 0x04, 0x46, + 0x26, 0xc4, 0xc7, 0xc8, 0xd8, 0x91, 0x09, 0x41, 0x32, 0xc0, 0x57, 0x60, 0xab, 0x7c, 0x8e, 0x5b, + 0x79, 0xcb, 0x62, 0xfd, 0xfc, 0x7e, 0xf7, 0xde, 0xef, 0x3d, 0xe9, 0xe1, 0x50, 0x1b, 0xa9, 0x8d, + 0x30, 0xa1, 0xe4, 0x66, 0x62, 0x38, 0x9b, 0x95, 0xc2, 0x9e, 0x87, 0x9f, 0x86, 0x09, 0xb7, 0x30, + 0x6c, 0x81, 0x41, 0x51, 0x6a, 0xab, 0xc9, 0xe1, 0x9a, 0x10, 0xb4, 0x76, 0x6b, 0x42, 0x97, 0x32, + 0xb7, 0x0e, 0x13, 0x30, 0xfc, 0x4a, 0x85, 0x69, 0xa1, 0x6a, 0x76, 0xf7, 0x20, 0xd3, 0x99, 0x76, + 0x63, 0x58, 0x4d, 0x6b, 0xf4, 0x1e, 0x48, 0xa1, 0x74, 0xe8, 0xbe, 0x35, 0x74, 0xfc, 0x1d, 0x61, + 0xff, 0x54, 0x94, 0x76, 0x06, 0xf9, 0x3b, 0x0b, 0x53, 0xa1, 0xb2, 0x37, 0x30, 0x1f, 0x43, 0xf1, + 0x4a, 0x9d, 0x69, 0xd2, 0xc5, 0x37, 0x99, 0x56, 0xb6, 0x04, 0x66, 0x7d, 0xd4, 0x43, 0xfd, 0x9d, + 0xe8, 0xea, 0x9f, 0x3c, 0xc3, 0x3b, 0x29, 0xcf, 0x79, 0x06, 0x96, 0xa7, 0xfe, 0x8d, 0x1e, 0xea, + 0xef, 0x3e, 0x79, 0x10, 0xd4, 0xae, 0x82, 0xca, 0x55, 0x63, 0x35, 0x18, 0x6b, 0xa1, 0x46, 0x9d, + 0xc5, 0xaf, 0x23, 0x2f, 0xba, 0x66, 0x90, 0x21, 0xde, 0x62, 0x50, 0xf8, 0x5b, 0x9b, 0x11, 0xab, + 0xb7, 0x27, 0x9d, 0x7f, 0x5f, 0x8f, 0xd0, 0xf1, 0x7f, 0x84, 0xb7, 0xdf, 0x42, 0x09, 0xd2, 0x90, + 0x53, 0x7c, 0xdf, 0x6a, 0x0b, 0x79, 0xdc, 0x98, 0x32, 0xb1, 0x84, 0x79, 0x5c, 0xe9, 0xa2, 0xcd, + 0x74, 0x0f, 0x1c, 0x7f, 0xdc, 0xd0, 0xeb, 0xe8, 0xe4, 0x21, 0xbe, 0xc5, 0x0b, 0xcd, 0x26, 0x71, + 0xce, 0x55, 0x66, 0x27, 0x2e, 0xdd, 0x5e, 0xb4, 0xeb, 0xb0, 0xd7, 0x0e, 0x22, 0x03, 0xbc, 0x5f, + 0x9d, 0xca, 0xc0, 0xc4, 0x5c, 0xa5, 0x71, 0x92, 0x6b, 0x36, 0xe5, 0xa5, 0x8b, 0xb3, 0x17, 0xdd, + 0x95, 0x30, 0x7f, 0x09, 0xe6, 0x85, 0x4a, 0x47, 0x35, 0x4e, 0x1e, 0xe1, 0x3b, 0x42, 0x9d, 0x55, + 0x37, 0x84, 0x56, 0xb1, 0x15, 0x92, 0xfb, 0x9d, 0x1e, 0xea, 0x77, 0xa2, 0xdb, 0xd7, 0xf0, 0x7b, + 0x21, 0xf9, 0xc9, 0x61, 0x95, 0xf1, 0xf3, 0xdf, 0x1f, 0x8f, 0xf7, 0x5b, 0x3d, 0xa9, 0x03, 0x8f, + 0x3e, 0x2e, 0xfe, 0x50, 0xef, 0xdb, 0x92, 0x7a, 0x8b, 0x25, 0x45, 0x17, 0x4b, 0x8a, 0x7e, 0x2f, + 0x29, 0xfa, 0xb2, 0xa2, 0xde, 0xc5, 0x8a, 0x7a, 0x3f, 0x57, 0xd4, 0xfb, 0xf0, 0x3c, 0x13, 0x76, + 0x32, 0x4b, 0x02, 0xa6, 0x65, 0xd3, 0xb8, 0x41, 0x0e, 0x49, 0x5d, 0xbb, 0x41, 0xa3, 0x37, 0x30, + 0xe9, 0x34, 0x9c, 0xb7, 0xab, 0x68, 0xcf, 0x0b, 0x6e, 0x92, 0x6d, 0xd7, 0x8a, 0xa7, 0x97, 0x01, + 0x00, 0x00, 0xff, 0xff, 0x95, 0xad, 0x29, 0xf1, 0xaf, 0x02, 0x00, 0x00, } func (this *VirtualStakingMaxCapInfo) Equal(that interface{}) bool { @@ -196,7 +186,6 @@ func (this *VirtualStakingMaxCapInfo) Equal(that interface{}) bool { } return true } - func (this *Params) Equal(that interface{}) bool { if that == nil { return this == nil @@ -225,9 +214,11 @@ func (this *Params) Equal(that interface{}) bool { if this.MaxGasEndBlocker != that1.MaxGasEndBlocker { return false } + if this.InfractionTime != that1.InfractionTime { + return false + } return true } - func (m *VirtualStakingMaxCapInfo) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -298,6 +289,11 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.InfractionTime != 0 { + i = encodeVarintMeshsecurity(dAtA, i, uint64(m.InfractionTime)) + i-- + dAtA[i] = 0x20 + } if m.MaxGasEndBlocker != 0 { i = encodeVarintMeshsecurity(dAtA, i, uint64(m.MaxGasEndBlocker)) i-- @@ -332,7 +328,6 @@ func encodeVarintMeshsecurity(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } - func (m *VirtualStakingMaxCapInfo) Size() (n int) { if m == nil { return 0 @@ -364,17 +359,18 @@ func (m *Params) Size() (n int) { if m.MaxGasEndBlocker != 0 { n += 1 + sovMeshsecurity(uint64(m.MaxGasEndBlocker)) } + if m.InfractionTime != 0 { + n += 1 + sovMeshsecurity(uint64(m.InfractionTime)) + } return n } func sovMeshsecurity(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } - func sozMeshsecurity(x uint64) (n int) { return sovMeshsecurity(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } - func (m *VirtualStakingMaxCapInfo) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -523,7 +519,6 @@ func (m *VirtualStakingMaxCapInfo) Unmarshal(dAtA []byte) error { } return nil } - func (m *Params) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -624,6 +619,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { break } } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field InfractionTime", wireType) + } + m.InfractionTime = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMeshsecurity + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.InfractionTime |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipMeshsecurity(dAtA[iNdEx:]) @@ -645,7 +659,6 @@ func (m *Params) Unmarshal(dAtA []byte) error { } return nil } - func skipMeshsecurity(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/meshsecurity/types/params.go b/x/meshsecurity/types/params.go index 25c3a1a4..022d834a 100644 --- a/x/meshsecurity/types/params.go +++ b/x/meshsecurity/types/params.go @@ -3,6 +3,7 @@ package types import ( errorsmod "cosmossdk.io/errors" "cosmossdk.io/math" + "time" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -13,6 +14,7 @@ func DefaultParams(denom string) Params { TotalContractsMaxCap: sdk.NewCoin(denom, math.NewInt(10_000_000_000)), EpochLength: 1_000, MaxGasEndBlocker: 500_000, + InfractionTime: 0, } } @@ -29,3 +31,9 @@ func (p Params) ValidateBasic() error { } return nil } + +// GetCCVTimeoutPeriod returns the timeout period for sent ccv related ibc packets +func (p Params) GetTimeoutPeriod() time.Duration { + // TODO: add TimeoutPeriod for params + return time.Duration(5) * time.Microsecond +} diff --git a/x/meshsecurity/types/query.pb.go b/x/meshsecurity/types/query.pb.go index c3287ff4..18bc2e46 100644 --- a/x/meshsecurity/types/query.pb.go +++ b/x/meshsecurity/types/query.pb.go @@ -6,10 +6,6 @@ package types import ( context "context" fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" @@ -19,14 +15,15 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. -var ( - _ = proto.Marshal - _ = fmt.Errorf - _ = math.Inf -) +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -47,11 +44,9 @@ func (*QueryVirtualStakingMaxCapLimitRequest) ProtoMessage() {} func (*QueryVirtualStakingMaxCapLimitRequest) Descriptor() ([]byte, []int) { return fileDescriptor_50c89ba006eed4fb, []int{0} } - func (m *QueryVirtualStakingMaxCapLimitRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } - func (m *QueryVirtualStakingMaxCapLimitRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_QueryVirtualStakingMaxCapLimitRequest.Marshal(b, m, deterministic) @@ -64,15 +59,12 @@ func (m *QueryVirtualStakingMaxCapLimitRequest) XXX_Marshal(b []byte, determinis return b[:n], nil } } - func (m *QueryVirtualStakingMaxCapLimitRequest) XXX_Merge(src proto.Message) { xxx_messageInfo_QueryVirtualStakingMaxCapLimitRequest.Merge(m, src) } - func (m *QueryVirtualStakingMaxCapLimitRequest) XXX_Size() int { return m.Size() } - func (m *QueryVirtualStakingMaxCapLimitRequest) XXX_DiscardUnknown() { xxx_messageInfo_QueryVirtualStakingMaxCapLimitRequest.DiscardUnknown(m) } @@ -94,11 +86,9 @@ func (*QueryVirtualStakingMaxCapLimitResponse) ProtoMessage() {} func (*QueryVirtualStakingMaxCapLimitResponse) Descriptor() ([]byte, []int) { return fileDescriptor_50c89ba006eed4fb, []int{1} } - func (m *QueryVirtualStakingMaxCapLimitResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } - func (m *QueryVirtualStakingMaxCapLimitResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_QueryVirtualStakingMaxCapLimitResponse.Marshal(b, m, deterministic) @@ -111,15 +101,12 @@ func (m *QueryVirtualStakingMaxCapLimitResponse) XXX_Marshal(b []byte, determini return b[:n], nil } } - func (m *QueryVirtualStakingMaxCapLimitResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_QueryVirtualStakingMaxCapLimitResponse.Merge(m, src) } - func (m *QueryVirtualStakingMaxCapLimitResponse) XXX_Size() int { return m.Size() } - func (m *QueryVirtualStakingMaxCapLimitResponse) XXX_DiscardUnknown() { xxx_messageInfo_QueryVirtualStakingMaxCapLimitResponse.DiscardUnknown(m) } @@ -128,7 +115,8 @@ var xxx_messageInfo_QueryVirtualStakingMaxCapLimitResponse proto.InternalMessage // QueryVirtualStakingMaxCapLimitsRequest is the request type for the // Query/VirtualStakingMaxCapLimits RPC method -type QueryVirtualStakingMaxCapLimitsRequest struct{} +type QueryVirtualStakingMaxCapLimitsRequest struct { +} func (m *QueryVirtualStakingMaxCapLimitsRequest) Reset() { *m = QueryVirtualStakingMaxCapLimitsRequest{} @@ -138,11 +126,9 @@ func (*QueryVirtualStakingMaxCapLimitsRequest) ProtoMessage() {} func (*QueryVirtualStakingMaxCapLimitsRequest) Descriptor() ([]byte, []int) { return fileDescriptor_50c89ba006eed4fb, []int{2} } - func (m *QueryVirtualStakingMaxCapLimitsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } - func (m *QueryVirtualStakingMaxCapLimitsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_QueryVirtualStakingMaxCapLimitsRequest.Marshal(b, m, deterministic) @@ -155,15 +141,12 @@ func (m *QueryVirtualStakingMaxCapLimitsRequest) XXX_Marshal(b []byte, determini return b[:n], nil } } - func (m *QueryVirtualStakingMaxCapLimitsRequest) XXX_Merge(src proto.Message) { xxx_messageInfo_QueryVirtualStakingMaxCapLimitsRequest.Merge(m, src) } - func (m *QueryVirtualStakingMaxCapLimitsRequest) XXX_Size() int { return m.Size() } - func (m *QueryVirtualStakingMaxCapLimitsRequest) XXX_DiscardUnknown() { xxx_messageInfo_QueryVirtualStakingMaxCapLimitsRequest.DiscardUnknown(m) } @@ -184,11 +167,9 @@ func (*QueryVirtualStakingMaxCapLimitsResponse) ProtoMessage() {} func (*QueryVirtualStakingMaxCapLimitsResponse) Descriptor() ([]byte, []int) { return fileDescriptor_50c89ba006eed4fb, []int{3} } - func (m *QueryVirtualStakingMaxCapLimitsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } - func (m *QueryVirtualStakingMaxCapLimitsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_QueryVirtualStakingMaxCapLimitsResponse.Marshal(b, m, deterministic) @@ -201,15 +182,12 @@ func (m *QueryVirtualStakingMaxCapLimitsResponse) XXX_Marshal(b []byte, determin return b[:n], nil } } - func (m *QueryVirtualStakingMaxCapLimitsResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_QueryVirtualStakingMaxCapLimitsResponse.Merge(m, src) } - func (m *QueryVirtualStakingMaxCapLimitsResponse) XXX_Size() int { return m.Size() } - func (m *QueryVirtualStakingMaxCapLimitsResponse) XXX_DiscardUnknown() { xxx_messageInfo_QueryVirtualStakingMaxCapLimitsResponse.DiscardUnknown(m) } @@ -218,7 +196,8 @@ var xxx_messageInfo_QueryVirtualStakingMaxCapLimitsResponse proto.InternalMessag // QueryParamsRequest is the request type for the // Query/Params RPC method -type QueryParamsRequest struct{} +type QueryParamsRequest struct { +} func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } @@ -226,11 +205,9 @@ func (*QueryParamsRequest) ProtoMessage() {} func (*QueryParamsRequest) Descriptor() ([]byte, []int) { return fileDescriptor_50c89ba006eed4fb, []int{4} } - func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } - func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) @@ -243,15 +220,12 @@ func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } - func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { xxx_messageInfo_QueryParamsRequest.Merge(m, src) } - func (m *QueryParamsRequest) XXX_Size() int { return m.Size() } - func (m *QueryParamsRequest) XXX_DiscardUnknown() { xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) } @@ -270,11 +244,9 @@ func (*QueryParamsResponse) ProtoMessage() {} func (*QueryParamsResponse) Descriptor() ([]byte, []int) { return fileDescriptor_50c89ba006eed4fb, []int{5} } - func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } - func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) @@ -287,15 +259,12 @@ func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } - func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_QueryParamsResponse.Merge(m, src) } - func (m *QueryParamsResponse) XXX_Size() int { return m.Size() } - func (m *QueryParamsResponse) XXX_DiscardUnknown() { xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) } @@ -384,10 +353,8 @@ func (this *QueryVirtualStakingMaxCapLimitResponse) Equal(that interface{}) bool } // Reference imports to suppress errors if they are not otherwise used. -var ( - _ context.Context - _ grpc.ClientConn -) +var _ context.Context +var _ grpc.ClientConn // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. @@ -451,16 +418,15 @@ type QueryServer interface { } // UnimplementedQueryServer can be embedded to have forward compatible implementations. -type UnimplementedQueryServer struct{} +type UnimplementedQueryServer struct { +} func (*UnimplementedQueryServer) VirtualStakingMaxCapLimit(ctx context.Context, req *QueryVirtualStakingMaxCapLimitRequest) (*QueryVirtualStakingMaxCapLimitResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method VirtualStakingMaxCapLimit not implemented") } - func (*UnimplementedQueryServer) VirtualStakingMaxCapLimits(ctx context.Context, req *QueryVirtualStakingMaxCapLimitsRequest) (*QueryVirtualStakingMaxCapLimitsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method VirtualStakingMaxCapLimits not implemented") } - func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") } @@ -744,7 +710,6 @@ func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } - func (m *QueryVirtualStakingMaxCapLimitRequest) Size() (n int) { if m == nil { return 0 @@ -818,11 +783,9 @@ func (m *QueryParamsResponse) Size() (n int) { func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } - func sozQuery(x uint64) (n int) { return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } - func (m *QueryVirtualStakingMaxCapLimitRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -905,7 +868,6 @@ func (m *QueryVirtualStakingMaxCapLimitRequest) Unmarshal(dAtA []byte) error { } return nil } - func (m *QueryVirtualStakingMaxCapLimitResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1022,7 +984,6 @@ func (m *QueryVirtualStakingMaxCapLimitResponse) Unmarshal(dAtA []byte) error { } return nil } - func (m *QueryVirtualStakingMaxCapLimitsRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1073,7 +1034,6 @@ func (m *QueryVirtualStakingMaxCapLimitsRequest) Unmarshal(dAtA []byte) error { } return nil } - func (m *QueryVirtualStakingMaxCapLimitsResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1158,7 +1118,6 @@ func (m *QueryVirtualStakingMaxCapLimitsResponse) Unmarshal(dAtA []byte) error { } return nil } - func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1209,7 +1168,6 @@ func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { } return nil } - func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1293,7 +1251,6 @@ func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { } return nil } - func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/meshsecurity/types/query.pb.gw.go b/x/meshsecurity/types/query.pb.gw.go index 7922edbd..b00a85c2 100644 --- a/x/meshsecurity/types/query.pb.gw.go +++ b/x/meshsecurity/types/query.pb.gw.go @@ -25,15 +25,13 @@ import ( ) // Suppress "imported and not used" errors -var ( - _ codes.Code - _ io.Reader - _ status.Status - _ = runtime.String - _ = utilities.NewDoubleArray - _ = descriptor.ForMessage - _ = metadata.Join -) +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join func request_Query_VirtualStakingMaxCapLimit_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryVirtualStakingMaxCapLimitRequest @@ -59,6 +57,7 @@ func request_Query_VirtualStakingMaxCapLimit_0(ctx context.Context, marshaler ru msg, err := client.VirtualStakingMaxCapLimit(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err + } func local_request_Query_VirtualStakingMaxCapLimit_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { @@ -85,6 +84,7 @@ func local_request_Query_VirtualStakingMaxCapLimit_0(ctx context.Context, marsha msg, err := server.VirtualStakingMaxCapLimit(ctx, &protoReq) return msg, metadata, err + } func request_Query_VirtualStakingMaxCapLimits_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { @@ -93,6 +93,7 @@ func request_Query_VirtualStakingMaxCapLimits_0(ctx context.Context, marshaler r msg, err := client.VirtualStakingMaxCapLimits(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err + } func local_request_Query_VirtualStakingMaxCapLimits_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { @@ -101,6 +102,7 @@ func local_request_Query_VirtualStakingMaxCapLimits_0(ctx context.Context, marsh msg, err := server.VirtualStakingMaxCapLimits(ctx, &protoReq) return msg, metadata, err + } func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { @@ -109,6 +111,7 @@ func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, cl msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err + } func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { @@ -117,6 +120,7 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal msg, err := server.Params(ctx, &protoReq) return msg, metadata, err + } // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". @@ -124,6 +128,7 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + mux.Handle("GET", pattern_Query_VirtualStakingMaxCapLimit_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -144,6 +149,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv } forward_Query_VirtualStakingMaxCapLimit_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) mux.Handle("GET", pattern_Query_VirtualStakingMaxCapLimits_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { @@ -166,6 +172,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv } forward_Query_VirtualStakingMaxCapLimits_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { @@ -188,6 +195,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv } forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) return nil @@ -230,6 +238,7 @@ func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc // doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in // "QueryClient" to call the correct interceptors. func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + mux.Handle("GET", pattern_Query_VirtualStakingMaxCapLimit_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -247,6 +256,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } forward_Query_VirtualStakingMaxCapLimit_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) mux.Handle("GET", pattern_Query_VirtualStakingMaxCapLimits_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { @@ -266,6 +276,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } forward_Query_VirtualStakingMaxCapLimits_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { @@ -285,6 +296,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) return nil diff --git a/x/meshsecurity/types/relay.go b/x/meshsecurity/types/relay.go new file mode 100644 index 00000000..2428f646 --- /dev/null +++ b/x/meshsecurity/types/relay.go @@ -0,0 +1,43 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v7/modules/core/24-host" +) + +// SendIBCPacket sends an IBC packet with packetData +// over the source channelID and portID +func SendIBCPacket( + ctx sdk.Context, + scopedKeeper ScopedKeeper, + channelKeeper ChannelKeeper, + sourceChannelID string, + sourcePortID string, + packetData []byte, + timeoutPeriod time.Duration, +) error { + _, ok := channelKeeper.GetChannel(ctx, sourcePortID, sourceChannelID) + if !ok { + return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "channel not found for channel ID: %s", sourceChannelID) + } + channelCap, ok := scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(sourcePortID, sourceChannelID)) + if !ok { + return errorsmod.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + } + + _, err := channelKeeper.SendPacket(ctx, + channelCap, + sourcePortID, + sourceChannelID, + clienttypes.Height{}, // timeout height disabled + uint64(ctx.BlockTime().Add(timeoutPeriod).UnixNano()), // timeout timestamp + packetData, + ) + return err +} diff --git a/x/meshsecurity/types/scheduler.pb.go b/x/meshsecurity/types/scheduler.pb.go index 83d6f939..df8bee24 100644 --- a/x/meshsecurity/types/scheduler.pb.go +++ b/x/meshsecurity/types/scheduler.pb.go @@ -5,21 +5,18 @@ package types import ( fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - _ "github.com/cosmos/cosmos-proto" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. -var ( - _ = proto.Marshal - _ = fmt.Errorf - _ = math.Inf -) +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -27,6 +24,43 @@ var ( // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type ScheduledWork struct { + Repeat bool `protobuf:"varint,1,opt,name=repeat,proto3" json:"repeat,omitempty"` +} + +func (m *ScheduledWork) Reset() { *m = ScheduledWork{} } +func (m *ScheduledWork) String() string { return proto.CompactTextString(m) } +func (*ScheduledWork) ProtoMessage() {} +func (*ScheduledWork) Descriptor() ([]byte, []int) { + return fileDescriptor_de3814df630b6218, []int{0} +} +func (m *ScheduledWork) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ScheduledWork) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ScheduledWork.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ScheduledWork) XXX_Merge(src proto.Message) { + xxx_messageInfo_ScheduledWork.Merge(m, src) +} +func (m *ScheduledWork) XXX_Size() int { + return m.Size() +} +func (m *ScheduledWork) XXX_DiscardUnknown() { + xxx_messageInfo_ScheduledWork.DiscardUnknown(m) +} + +var xxx_messageInfo_ScheduledWork proto.InternalMessageInfo + // ValidatorAddress payload data to be used with the scheduler type ValidatorAddress struct { // Address is the ValAddress bech32 string @@ -37,13 +71,11 @@ func (m *ValidatorAddress) Reset() { *m = ValidatorAddress{} } func (m *ValidatorAddress) String() string { return proto.CompactTextString(m) } func (*ValidatorAddress) ProtoMessage() {} func (*ValidatorAddress) Descriptor() ([]byte, []int) { - return fileDescriptor_de3814df630b6218, []int{0} + return fileDescriptor_de3814df630b6218, []int{1} } - func (m *ValidatorAddress) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } - func (m *ValidatorAddress) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_ValidatorAddress.Marshal(b, m, deterministic) @@ -56,15 +88,12 @@ func (m *ValidatorAddress) XXX_Marshal(b []byte, deterministic bool) ([]byte, er return b[:n], nil } } - func (m *ValidatorAddress) XXX_Merge(src proto.Message) { xxx_messageInfo_ValidatorAddress.Merge(m, src) } - func (m *ValidatorAddress) XXX_Size() int { return m.Size() } - func (m *ValidatorAddress) XXX_DiscardUnknown() { xxx_messageInfo_ValidatorAddress.DiscardUnknown(m) } @@ -72,6 +101,7 @@ func (m *ValidatorAddress) XXX_DiscardUnknown() { var xxx_messageInfo_ValidatorAddress proto.InternalMessageInfo func init() { + proto.RegisterType((*ScheduledWork)(nil), "osmosis.meshsecurity.v1beta1.ScheduledWork") proto.RegisterType((*ValidatorAddress)(nil), "osmosis.meshsecurity.v1beta1.ValidatorAddress") } @@ -80,22 +110,57 @@ func init() { } var fileDescriptor_de3814df630b6218 = []byte{ - // 236 bytes of a gzipped FileDescriptorProto + // 264 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0xc9, 0x2f, 0xce, 0xcd, 0x2f, 0xce, 0x2c, 0xd6, 0xcf, 0x4d, 0x2d, 0xce, 0x28, 0x4e, 0x4d, 0x2e, 0x2d, 0xca, 0x2c, 0xa9, 0xd4, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x2f, 0x4e, 0xce, 0x48, 0x4d, 0x29, 0xcd, 0x49, 0x2d, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x81, 0xaa, 0xd6, 0x43, 0x56, 0xad, 0x07, 0x55, 0x2d, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa8, 0x0f, 0x62, 0x41, 0xf4, 0x48, - 0x49, 0x26, 0x83, 0x35, 0xc5, 0x43, 0x24, 0x20, 0x1c, 0x88, 0x94, 0x92, 0x1b, 0x97, 0x40, 0x58, - 0x62, 0x4e, 0x66, 0x4a, 0x62, 0x49, 0x7e, 0x91, 0x63, 0x4a, 0x4a, 0x51, 0x6a, 0x71, 0xb1, 0x90, - 0x11, 0x17, 0x7b, 0x22, 0x84, 0x29, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0xe9, 0x24, 0x71, 0x69, 0x8b, - 0xae, 0x08, 0x54, 0x1b, 0x54, 0x51, 0x70, 0x49, 0x51, 0x66, 0x5e, 0x7a, 0x10, 0x4c, 0xa1, 0x53, - 0xc2, 0x89, 0x87, 0x72, 0x0c, 0x2b, 0x1e, 0xc9, 0x31, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, - 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, - 0xb1, 0x1c, 0x43, 0x94, 0x5d, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, - 0xd4, 0x0f, 0xba, 0x39, 0x89, 0x49, 0x10, 0x6f, 0xeb, 0xc2, 0x7c, 0xa2, 0x5b, 0x9c, 0x92, 0xad, - 0x5f, 0x81, 0x1a, 0x14, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0x07, 0x1b, 0x03, 0x02, - 0x00, 0x00, 0xff, 0xff, 0xb5, 0xc5, 0xe7, 0x2e, 0x2f, 0x01, 0x00, 0x00, + 0x49, 0x26, 0x83, 0x35, 0xc5, 0x43, 0x24, 0x20, 0x1c, 0x88, 0x94, 0x92, 0x3a, 0x17, 0x6f, 0x30, + 0xd4, 0x86, 0x94, 0xf0, 0xfc, 0xa2, 0x6c, 0x21, 0x31, 0x2e, 0xb6, 0xa2, 0xd4, 0x82, 0xd4, 0xc4, + 0x12, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x8e, 0x20, 0x28, 0x4f, 0xc9, 0x8d, 0x4b, 0x20, 0x2c, 0x31, + 0x27, 0x33, 0x25, 0xb1, 0x24, 0xbf, 0xc8, 0x31, 0x25, 0xa5, 0x28, 0xb5, 0xb8, 0x58, 0xc8, 0x88, + 0x8b, 0x3d, 0x11, 0xc2, 0x04, 0x2b, 0xe6, 0x74, 0x92, 0xb8, 0xb4, 0x45, 0x57, 0x04, 0x6a, 0x3e, + 0x54, 0x51, 0x70, 0x49, 0x51, 0x66, 0x5e, 0x7a, 0x10, 0x4c, 0xa1, 0x53, 0xc2, 0x89, 0x87, 0x72, + 0x0c, 0x2b, 0x1e, 0xc9, 0x31, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, + 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, + 0x5d, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0xd4, 0xb3, 0xba, 0x39, + 0x89, 0x49, 0x90, 0xf0, 0xd1, 0x85, 0x79, 0x59, 0xb7, 0x38, 0x25, 0x5b, 0xbf, 0x02, 0x35, 0xcc, + 0x4a, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0x3e, 0x33, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, + 0xf5, 0x6f, 0x77, 0x0e, 0x58, 0x01, 0x00, 0x00, +} + +func (m *ScheduledWork) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ScheduledWork) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ScheduledWork) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Repeat { + i-- + if m.Repeat { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil } func (m *ValidatorAddress) Marshal() (dAtA []byte, err error) { @@ -139,6 +204,17 @@ func encodeVarintScheduler(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *ScheduledWork) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Repeat { + n += 2 + } + return n +} func (m *ValidatorAddress) Size() (n int) { if m == nil { @@ -156,11 +232,79 @@ func (m *ValidatorAddress) Size() (n int) { func sovScheduler(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } - func sozScheduler(x uint64) (n int) { return sovScheduler(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *ScheduledWork) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowScheduler + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: ScheduledWork: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ScheduledWork: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Repeat", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowScheduler + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Repeat = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipScheduler(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthScheduler + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *ValidatorAddress) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -243,7 +387,6 @@ func (m *ValidatorAddress) Unmarshal(dAtA []byte) error { } return nil } - func skipScheduler(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/meshsecurity/types/tx.pb.go b/x/meshsecurity/types/tx.pb.go index 7147eeff..1372d1b9 100644 --- a/x/meshsecurity/types/tx.pb.go +++ b/x/meshsecurity/types/tx.pb.go @@ -6,10 +6,6 @@ package types import ( context "context" fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/cosmos-sdk/types/msgservice" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" @@ -19,14 +15,15 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. -var ( - _ = proto.Marshal - _ = fmt.Errorf - _ = math.Inf -) +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -53,11 +50,9 @@ func (*MsgSetVirtualStakingMaxCap) ProtoMessage() {} func (*MsgSetVirtualStakingMaxCap) Descriptor() ([]byte, []int) { return fileDescriptor_ca993316ec9770c4, []int{0} } - func (m *MsgSetVirtualStakingMaxCap) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } - func (m *MsgSetVirtualStakingMaxCap) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgSetVirtualStakingMaxCap.Marshal(b, m, deterministic) @@ -70,15 +65,12 @@ func (m *MsgSetVirtualStakingMaxCap) XXX_Marshal(b []byte, deterministic bool) ( return b[:n], nil } } - func (m *MsgSetVirtualStakingMaxCap) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgSetVirtualStakingMaxCap.Merge(m, src) } - func (m *MsgSetVirtualStakingMaxCap) XXX_Size() int { return m.Size() } - func (m *MsgSetVirtualStakingMaxCap) XXX_DiscardUnknown() { xxx_messageInfo_MsgSetVirtualStakingMaxCap.DiscardUnknown(m) } @@ -86,7 +78,8 @@ func (m *MsgSetVirtualStakingMaxCap) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSetVirtualStakingMaxCap proto.InternalMessageInfo // MsgSetVirtualStakingMaxCap returns result data. -type MsgSetVirtualStakingMaxCapResponse struct{} +type MsgSetVirtualStakingMaxCapResponse struct { +} func (m *MsgSetVirtualStakingMaxCapResponse) Reset() { *m = MsgSetVirtualStakingMaxCapResponse{} } func (m *MsgSetVirtualStakingMaxCapResponse) String() string { return proto.CompactTextString(m) } @@ -94,11 +87,9 @@ func (*MsgSetVirtualStakingMaxCapResponse) ProtoMessage() {} func (*MsgSetVirtualStakingMaxCapResponse) Descriptor() ([]byte, []int) { return fileDescriptor_ca993316ec9770c4, []int{1} } - func (m *MsgSetVirtualStakingMaxCapResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } - func (m *MsgSetVirtualStakingMaxCapResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_MsgSetVirtualStakingMaxCapResponse.Marshal(b, m, deterministic) @@ -111,15 +102,12 @@ func (m *MsgSetVirtualStakingMaxCapResponse) XXX_Marshal(b []byte, deterministic return b[:n], nil } } - func (m *MsgSetVirtualStakingMaxCapResponse) XXX_Merge(src proto.Message) { xxx_messageInfo_MsgSetVirtualStakingMaxCapResponse.Merge(m, src) } - func (m *MsgSetVirtualStakingMaxCapResponse) XXX_Size() int { return m.Size() } - func (m *MsgSetVirtualStakingMaxCapResponse) XXX_DiscardUnknown() { xxx_messageInfo_MsgSetVirtualStakingMaxCapResponse.DiscardUnknown(m) } @@ -164,10 +152,8 @@ var fileDescriptor_ca993316ec9770c4 = []byte{ } // Reference imports to suppress errors if they are not otherwise used. -var ( - _ context.Context - _ grpc.ClientConn -) +var _ context.Context +var _ grpc.ClientConn // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. @@ -207,7 +193,8 @@ type MsgServer interface { } // UnimplementedMsgServer can be embedded to have forward compatible implementations. -type UnimplementedMsgServer struct{} +type UnimplementedMsgServer struct { +} func (*UnimplementedMsgServer) SetVirtualStakingMaxCap(ctx context.Context, req *MsgSetVirtualStakingMaxCap) (*MsgSetVirtualStakingMaxCapResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SetVirtualStakingMaxCap not implemented") @@ -329,7 +316,6 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } - func (m *MsgSetVirtualStakingMaxCap) Size() (n int) { if m == nil { return 0 @@ -361,11 +347,9 @@ func (m *MsgSetVirtualStakingMaxCapResponse) Size() (n int) { func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } - func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } - func (m *MsgSetVirtualStakingMaxCap) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -513,7 +497,6 @@ func (m *MsgSetVirtualStakingMaxCap) Unmarshal(dAtA []byte) error { } return nil } - func (m *MsgSetVirtualStakingMaxCapResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -564,7 +547,6 @@ func (m *MsgSetVirtualStakingMaxCapResponse) Unmarshal(dAtA []byte) error { } return nil } - func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/meshsecurityprovider/client/cli/query.go b/x/meshsecurityprovider/client/cli/query.go new file mode 100644 index 00000000..68beafc2 --- /dev/null +++ b/x/meshsecurityprovider/client/cli/query.go @@ -0,0 +1,65 @@ +package cli + +import ( + "fmt" + "strings" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/version" + + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" +) + +func GetQueryCmd() *cobra.Command { + queryCmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Querying commands for the mesh security provider module", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + SilenceUsage: true, + } + queryCmd.AddCommand( + GetCmdQueryParams(), + ) + return queryCmd +} + +// GetCmdQueryParams implements the params query command. +func GetCmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Args: cobra.NoArgs, + Short: "Query the current mesh-security parameters information", + Long: strings.TrimSpace( + fmt.Sprintf(`Query values set as mesh-security parameters. + +Example: +$ %s query meshsecurity-provider params +`, + version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(&res.Params) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/meshsecurityprovider/client/cli/tx.go b/x/meshsecurityprovider/client/cli/tx.go new file mode 100644 index 00000000..d5077f3b --- /dev/null +++ b/x/meshsecurityprovider/client/cli/tx.go @@ -0,0 +1,162 @@ +package cli + +import ( + "fmt" + "github.com/spf13/cobra" + "strings" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/version" + + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + txCmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Mesh security transaction subcommands", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + SilenceUsage: true, + } + + txCmd.AddCommand(NewSetConsumerCommissionRateCmd()) + return txCmd +} + +func NewSetConsumerCommissionRateCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "set-consumer-commission-rate [consumer-chain-id] [commission-rate]", + Short: "set a per-consumer chain commission", + Long: strings.TrimSpace( + fmt.Sprintf(`Note that the "commission-rate" argument is a fraction and should be in the range [0,1]. + Example: + %s set-consumer-commission-rate consumer-1 0.5 --from node0 --home ../node0`, + version.AppName), + ), + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + txf, err := tx.NewFactoryCLI(clientCtx, cmd.Flags()) + if err != nil { + return err + } + txf = txf.WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever) + + providerValAddr := clientCtx.GetFromAddress() + + commission, err := sdk.NewDecFromStr(args[1]) + if err != nil { + return err + } + msg := types.NewMsgSetConsumerCommissionRate(args[0], commission, sdk.ValAddress(providerValAddr)) + if err := msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + _ = cmd.MarkFlagRequired(flags.FlagFrom) + + return cmd +} + +// NewDelegateCmd returns a CLI command handler for creating a MsgDelegate transaction. +func NewDelegateCmd() *cobra.Command { + bech32PrefixValAddr := sdk.GetConfig().GetBech32ValidatorAddrPrefix() + + cmd := &cobra.Command{ + Use: "delegate [validator-addr] [amount]", + Args: cobra.ExactArgs(2), + Short: "Delegate liquid tokens to a validator", + Long: strings.TrimSpace( + fmt.Sprintf(`Delegate an amount of liquid coins to a validator from your wallet. + +Example: +$ %s tx staking delegate %s1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 1000stake --from mykey +`, + version.AppName, bech32PrefixValAddr, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + amount, err := sdk.ParseCoinNormalized(args[1]) + if err != nil { + return err + } + + delAddr := clientCtx.GetFromAddress() + valAddr, err := sdk.ValAddressFromBech32(args[0]) + if err != nil { + return err + } + + msg := types.NewMsgDelegate(delAddr, valAddr, amount) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +func NewUnbondCmd() *cobra.Command { + bech32PrefixValAddr := sdk.GetConfig().GetBech32ValidatorAddrPrefix() + + cmd := &cobra.Command{ + Use: "unbond [validator-addr] [amount]", + Short: "Unbond shares from a validator", + Args: cobra.ExactArgs(2), + Long: strings.TrimSpace( + fmt.Sprintf(`Unbond an amount of bonded shares from a validator. + +Example: +$ %s tx staking unbond %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100stake --from mykey +`, + version.AppName, bech32PrefixValAddr, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + delAddr := clientCtx.GetFromAddress() + valAddr, err := sdk.ValAddressFromBech32(args[0]) + if err != nil { + return err + } + + amount, err := sdk.ParseCoinNormalized(args[1]) + if err != nil { + return err + } + + msg := types.NewMsgUndelegate(delAddr, valAddr, amount) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/meshsecurityprovider/contract/in_message.go b/x/meshsecurityprovider/contract/in_message.go new file mode 100644 index 00000000..f0ff1e43 --- /dev/null +++ b/x/meshsecurityprovider/contract/in_message.go @@ -0,0 +1,39 @@ +package contract + +import wasmvmtypes "github.com/CosmWasm/wasmvm/types" + +type ( + SudoMsg struct { + VaultSudoMsg *StakeMsg `json:"vault,omitempty"` + } + + StakeMsg struct { + StakeRemote `json:"stake_remote"` + StakeLocal `json:"stake_local"` + } + + StakeRemote struct { + Contract string `json:"contract"` + Amount wasmvmtypes.Coin `json:"amount"` + } + StakeLocal struct { + Amount wasmvmtypes.Coin `json:"amount"` + } +) + +type ( + CustomMsg struct { + VaultCustomMsg *VaultCustomMsg `json:"vault,omitempty"` + } + VaultCustomMsg struct { + Bond *BondMsg `json:"bond,omitempty"` + Unbond *UnbondMsg `json:"unbond,omitempty"` + } + BondMsg struct { + Amount wasmvmtypes.Coin `json:"amount"` + Validator string `json:"validator"` + } + UnbondMsg struct { + Amount wasmvmtypes.Coin `json:"amount"` + } +) diff --git a/x/meshsecurityprovider/ibc_module.go b/x/meshsecurityprovider/ibc_module.go new file mode 100644 index 00000000..ae7a90e4 --- /dev/null +++ b/x/meshsecurityprovider/ibc_module.go @@ -0,0 +1,291 @@ +package meshsecurityprovider + +import ( + "fmt" + // "strconv" + + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" + host "github.com/cosmos/ibc-go/v7/modules/core/24-host" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + + // transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/keeper" + types "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" + cptypes "github.com/osmosis-labs/mesh-security-sdk/x/types" +) + +// OnChanOpenInit implements the IBCModule interface +func (am AppModule) OnChanOpenInit( + ctx sdk.Context, + order channeltypes.Order, + connectionHops []string, + portID string, + channelID string, + channelCap *capabilitytypes.Capability, + counterparty channeltypes.Counterparty, + version string, +) (string, error) { + return version, errorsmod.Wrap(cptypes.ErrInvalidChannelFlow, "channel handshake must be initiated by consumer chain") +} + +// OnChanOpenTry implements the IBCModule interface + +func (am AppModule) OnChanOpenTry( + ctx sdk.Context, + order channeltypes.Order, + connectionHops []string, + portID, + channelID string, + chanCap *capabilitytypes.Capability, + counterparty channeltypes.Counterparty, + counterpartyVersion string, +) (metadata string, err error) { + if counterparty.PortId != cptypes.ConsumerPortID { + return "", errorsmod.Wrapf(porttypes.ErrInvalidPort, + "invalid counterparty port: %s, expected %s", counterparty.PortId, cptypes.ConsumerPortID) + } + + // ensure the counter party version matches the expected version + if counterpartyVersion != cptypes.Version { + return "", errorsmod.Wrapf( + cptypes.ErrInvalidVersion, "invalid counterparty version: got: %s, expected %s", + counterpartyVersion, cptypes.Version) + } + + // Claim channel capability + if err := am.k.ClaimCapability( + ctx, chanCap, host.ChannelCapabilityPath(portID, channelID), + ); err != nil { + return "", err + } + + if err := am.k.VerifyConsumerChain( + ctx, channelID, connectionHops, + ); err != nil { + return "", err + } + // TODO: ConsumerRewards + return "", nil +} + +// OnChanOpenAck implements the IBCModule interface +func (am AppModule) OnChanOpenAck( + ctx sdk.Context, + portID, + channelID string, + _ string, // Counter party channel ID is unused per spec + counterpartyMetadata string, +) error { + return errorsmod.Wrap(cptypes.ErrInvalidChannelFlow, "channel handshake must be initiated by consumer chain") +} + +// OnChanOpenConfirm implements the IBCModule interface +func (am AppModule) OnChanOpenConfirm( + ctx sdk.Context, + portID, + channelID string, +) error { + err := am.k.SetConsumerChain(ctx, channelID) + if err != nil { + return err + } + return nil +} + +// OnChanCloseInit implements the IBCModule interface +func (am AppModule) OnChanCloseInit( + ctx sdk.Context, + portID, + channelID string, +) error { + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") +} + +// OnChanCloseConfirm implements the IBCModule interface +func (am AppModule) OnChanCloseConfirm( + ctx sdk.Context, + portID, + channelID string, +) error { + return nil +} + +// OnRecvPacket implements the IBCModule interface. A successful acknowledgement +// is returned if the packet data is successfully decoded and the receive application +// logic returns without error. +func (am AppModule) OnRecvPacket( + ctx sdk.Context, + packet channeltypes.Packet, + _ sdk.AccAddress, +) ibcexported.Acknowledgement { + logger := keeper.ModuleLogger(ctx) + ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) + + var ackErr error + consumerPacket, err := UnmarshalConsumerPacket(packet) + if err != nil { + ackErr = errorsmod.Wrapf(sdkerrors.ErrInvalidType, "cannot unmarshal ConsumerPacket data") + logger.Error(fmt.Sprintf("%s sequence %d", ackErr.Error(), packet.Sequence)) + ack = channeltypes.NewErrorAcknowledgement(ackErr) + } + + eventAttributes := []sdk.Attribute{ + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + } + + if ack.Success() { + var err error + + switch consumerPacket.Type { + case cptypes.PipedValsetOperation_VALIDATOR_BONDED: + var ackResult cptypes.PacketAckResult + data := consumerPacket.GetSchedulePacketData() + ackResult, err = am.k.OnRecvBondedPacket(ctx, packet, data) + if err == nil { + ack = channeltypes.NewResultAcknowledgement(ackResult) + } + + case cptypes.PipedValsetOperation_VALIDATOR_UNBONDED: + var ackResult cptypes.PacketAckResult + data := consumerPacket.GetSchedulePacketData() + ackResult, err = am.k.OnRecvUnbondedPacket(ctx, packet, data) + if err == nil { + ack = channeltypes.NewResultAcknowledgement(ackResult) + } + case cptypes.PipedValsetOperation_VALIDATOR_JAILED: + var ackResult cptypes.PacketAckResult + data := consumerPacket.GetSchedulePacketData() + ackResult, err = am.k.OnRecvJailedPacket(ctx, packet, data) + if err == nil { + ack = channeltypes.NewResultAcknowledgement(ackResult) + } + case cptypes.PipedValsetOperation_VALIDATOR_TOMBSTONED: + var ackResult cptypes.PacketAckResult + data := consumerPacket.GetSchedulePacketData() + ackResult, err = am.k.OnRecvTombstonedPacket(ctx, packet, data) + if err == nil { + ack = channeltypes.NewResultAcknowledgement(ackResult) + } + case cptypes.PipedValsetOperation_VALIDATOR_UNJAILED: + var ackResult cptypes.PacketAckResult + data := consumerPacket.GetSchedulePacketData() + ackResult, err = am.k.OnRecvUnjailedPacket(ctx, packet, data) + if err == nil { + ack = channeltypes.NewResultAcknowledgement(ackResult) + } + case cptypes.PipedValsetOperation_VALIDATOR_MODIFIED: + var ackResult cptypes.PacketAckResult + data := consumerPacket.GetSchedulePacketData() + ackResult, err = am.k.OnRecvModifiedPacket(ctx, packet, data) + if err == nil { + ack = channeltypes.NewResultAcknowledgement(ackResult) + } + case cptypes.PipedValsetOperation_VALIDATOR_SLASHED: + var ackResult cptypes.PacketAckResult + data := consumerPacket.GetSlashPacketData() + ackResult, err = am.k.OnRecvSlashPacket(ctx, packet, *data) + if err == nil { + ack = channeltypes.NewResultAcknowledgement(ackResult) + } + default: + err = fmt.Errorf("invalid consumer packet type: %q", consumerPacket.Type) + } + + if err != nil { + ack = channeltypes.NewErrorAcknowledgement(err) + ackErr = err + logger.Error(fmt.Sprintf("%s sequence %d", ackErr.Error(), packet.Sequence)) + } + } + + eventAttributes = append(eventAttributes, sdk.NewAttribute(cptypes.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success()))) + if ackErr != nil { + eventAttributes = append(eventAttributes, sdk.NewAttribute(cptypes.AttributeKeyAckError, ackErr.Error())) + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + cptypes.EventTypePacket, + eventAttributes..., + ), + ) + + // NOTE: acknowledgement will be written synchronously during IBC handler execution. + return ack +} + +// OnAcknowledgementPacket implements the IBCModule interface +func (am AppModule) OnAcknowledgementPacket( + ctx sdk.Context, + packet channeltypes.Packet, + acknowledgement []byte, + _ sdk.AccAddress, +) error { + var ack channeltypes.Acknowledgement + if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal provider packet acknowledgement: %v", err) + } + + if err := am.k.OnAcknowledgementPacket(ctx, packet, ack); err != nil { + return err + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + cptypes.EventTypePacket, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(cptypes.AttributeKeyAck, ack.String()), + ), + ) + + switch resp := ack.Response.(type) { + case *channeltypes.Acknowledgement_Result: + ctx.EventManager().EmitEvent( + sdk.NewEvent( + cptypes.EventTypePacket, + sdk.NewAttribute(cptypes.AttributeKeyAckSuccess, string(resp.Result)), + ), + ) + case *channeltypes.Acknowledgement_Error: + ctx.EventManager().EmitEvent( + sdk.NewEvent( + cptypes.EventTypePacket, + sdk.NewAttribute(cptypes.AttributeKeyAckError, resp.Error), + ), + ) + } + + return nil +} + +// OnTimeoutPacket implements the IBCModule interface +func (am AppModule) OnTimeoutPacket( + ctx sdk.Context, + packet channeltypes.Packet, + _ sdk.AccAddress, +) error { + if err := am.k.OnTimeoutPacket(ctx, packet); err != nil { + return err + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + cptypes.EventTypeTimeout, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + ) + + return nil +} + +func UnmarshalConsumerPacket(packet channeltypes.Packet) (consumerPacket cptypes.ConsumerPacketData, err error) { + return cptypes.UnmarshalConsumerPacketData(packet.GetData()) +} diff --git a/x/meshsecurityprovider/keeper/delegate.go b/x/meshsecurityprovider/keeper/delegate.go new file mode 100644 index 00000000..a44a034c --- /dev/null +++ b/x/meshsecurityprovider/keeper/delegate.go @@ -0,0 +1,92 @@ +package keeper + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + // stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/contract" + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" +) + +func (k Keeper) LocalStake(ctx sdk.Context, token sdk.Coin, valAddr string) error { + amount := wasmkeeper.ConvertSdkCoinToWasmCoin(token) + providerStakeMsg := contract.StakeMsg{ + StakeLocal: contract.StakeLocal{ + Amount: amount, + }, + } + + err := k.SendVaultStake(ctx, providerStakeMsg) + if err != nil { + return err + } + + contractAddr := k.GetContractWithNativeDenom(ctx, token.Denom) + inter, found := k.GetIntermediary(ctx, token.Denom) + if !found { + inter = types.NewIntermediary(valAddr, ctx.ChainID(), contractAddr.String(), false, false, types.Bonded, &token) + } else { + newAmout := inter.Token.Add(token) + inter.Token = &newAmout + } + k.SetIntermediary(ctx, inter) + return nil +} + +func (k Keeper) RemoteStake(ctx sdk.Context, denomDelegate string, token sdk.Coin) error { + contractAddr := k.GetContractWithNativeDenom(ctx, denomDelegate) + + amount := wasmkeeper.ConvertSdkCoinToWasmCoin(token) + + providerStakeMsg := contract.StakeMsg{ + StakeRemote: contract.StakeRemote{ + Amount: amount, + Contract: contractAddr.String(), + }, + } + err := k.SendVaultStake(ctx, providerStakeMsg) + if err != nil { + return err + } + + // TODO: validator addresss on consumer chain + inter, found := k.GetIntermediary(ctx, token.Denom) + if !found { + inter = types.NewIntermediary("", ctx.ChainID(), contractAddr.String(), false, false, types.Bonded, &token) + } else { + newAmout := inter.Token.Add(token) + inter.Token = &newAmout + } + k.SetIntermediary(ctx, inter) + return nil +} + +func (k Keeper) Undelegate(ctx sdk.Context, msg types.MsgUndelegate) error { + amount := wasmkeeper.ConvertSdkCoinToWasmCoin(msg.Amount) + unbondMsg := contract.VaultCustomMsg{ + Unbond: &contract.UnbondMsg{ + Amount: amount, + }, + } + err := k.SendCustomUnbond(ctx, unbondMsg) + if err != nil { + return err + } + + inter, found := k.GetIntermediary(ctx, msg.Amount.Denom) + if !found { + return fmt.Errorf("can not found Intermediary by denom %s", msg.Amount.Denom) + } + if inter.Token.IsLT(msg.Amount) { + return fmt.Errorf("failed to undelegate; total inter token %s is smaller than %s", inter.Token, msg.Amount) + } + + newAmount := inter.Token.Sub(msg.Amount) + inter.Token = &newAmount + + k.SetIntermediary(ctx, inter) + return nil +} diff --git a/x/meshsecurityprovider/keeper/genesis.go b/x/meshsecurityprovider/keeper/genesis.go new file mode 100644 index 00000000..795a6daa --- /dev/null +++ b/x/meshsecurityprovider/keeper/genesis.go @@ -0,0 +1,18 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" +) + +func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { + if err := k.SetParams(ctx, data.Params); err != nil { + panic(err) + } +} + +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + params := k.GetParams(ctx) + return types.NewGenesisState(params) +} diff --git a/x/meshsecurityprovider/keeper/keeper.go b/x/meshsecurityprovider/keeper/keeper.go new file mode 100644 index 00000000..de4536a0 --- /dev/null +++ b/x/meshsecurityprovider/keeper/keeper.go @@ -0,0 +1,336 @@ +package keeper + +import ( + "encoding/binary" + "fmt" + + "github.com/cometbft/cometbft/libs/log" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/store/prefix" + + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + conntypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + ibchost "github.com/cosmos/ibc-go/v7/modules/core/exported" + ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" + + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" + cptypes "github.com/osmosis-labs/mesh-security-sdk/x/types" +) + +// Option is an extension point to instantiate keeper with non default values +type Option interface { + apply(*Keeper) +} + +type Keeper struct { + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + cdc codec.Codec + bank types.BankKeeper + Staking types.StakingKeeper + wasm types.WasmKeeper + + scopedKeeper types.ScopedKeeper + channelKeeper types.ChannelKeeper + connectionKeeper types.ConnectionKeeper + clientKeeper types.ClientKeeper + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string +} + +// NewKeeper constructor with vanilla sdk keepers +func NewKeeper( + cdc codec.Codec, + storeKey storetypes.StoreKey, + memoryStoreKey storetypes.StoreKey, + bank types.BankKeeper, + staking types.StakingKeeper, + wasm types.WasmKeeper, + scopedKeeper types.ScopedKeeper, + channelKeeper types.ChannelKeeper, + authority string, + opts ...Option, +) *Keeper { + k := &Keeper{ + storeKey: storeKey, + memKey: memoryStoreKey, + cdc: cdc, + bank: bank, + Staking: staking, + wasm: wasm, + scopedKeeper: scopedKeeper, + channelKeeper: channelKeeper, + authority: authority, + } + for _, o := range opts { + o.apply(k) + } + + return k +} + +// ModuleLogger returns logger with module attribute +func ModuleLogger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +// SetConsumerChain is called by OnChanOpenConfirm. +func (k Keeper) SetConsumerChain(ctx sdk.Context, channelID string) error { + channel, ok := k.channelKeeper.GetChannel(ctx, cptypes.ProviderPortID, channelID) + if !ok { + return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "channel not found for channel ID: %s", channelID) + } + if len(channel.ConnectionHops) != 1 { + return errorsmod.Wrap(channeltypes.ErrTooManyConnectionHops, "must have direct connection to consumer chain") + } + connectionID := channel.ConnectionHops[0] + clientID, tmClient, err := k.getUnderlyingClient(ctx, connectionID) + if err != nil { + return err + } + // Verify that there isn't already a CCV channel for the consumer chain + chainID := tmClient.ChainId + if prevChannelID, ok := k.GetChainToChannel(ctx, chainID); ok { + return errorsmod.Wrapf(cptypes.ErrDuplicateChannel, "CCV channel with ID: %s already created for consumer chain %s", prevChannelID, chainID) + } + + // the CCV channel is established: + // - set channel mappings + k.SetChainToChannel(ctx, chainID, channelID) + k.SetChannelToChain(ctx, channelID, chainID) + // - set current block height for the consumer chain initialization + k.SetInitChainHeight(ctx, chainID, uint64(ctx.BlockHeight())) + // - remove init timeout timestamp + k.DeleteInitTimeoutTimestamp(ctx, chainID) + + // emit event on successful addition + ctx.EventManager().EmitEvent( + sdk.NewEvent( + cptypes.EventTypeChannelEstablished, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(cptypes.AttributeChainID, chainID), + sdk.NewAttribute(conntypes.AttributeKeyClientID, clientID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, channelID), + sdk.NewAttribute(conntypes.AttributeKeyConnectionID, connectionID), + ), + ) + return nil +} + +// Retrieves the underlying client state corresponding to a connection ID. +func (k Keeper) getUnderlyingClient(ctx sdk.Context, connectionID string) ( + clientID string, tmClient *ibctmtypes.ClientState, err error, +) { + conn, ok := k.connectionKeeper.GetConnection(ctx, connectionID) + if !ok { + return "", nil, errorsmod.Wrapf(conntypes.ErrConnectionNotFound, + "connection not found for connection ID: %s", connectionID) + } + clientID = conn.ClientId + clientState, ok := k.clientKeeper.GetClientState(ctx, clientID) + if !ok { + return "", nil, errorsmod.Wrapf(clienttypes.ErrClientNotFound, + "client not found for client ID: %s", conn.ClientId) + } + tmClient, ok = clientState.(*ibctmtypes.ClientState) + if !ok { + return "", nil, errorsmod.Wrapf(clienttypes.ErrInvalidClientType, + "invalid client type. expected %s, got %s", ibchost.Tendermint, clientState.ClientType()) + } + return clientID, tmClient, nil +} + +func (k Keeper) GetChainToChannel(ctx sdk.Context, chainID string) (string, bool) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ChainToChannelKey(chainID)) + if bz == nil { + return "", false + } + return string(bz), true +} + +func (k Keeper) SetChainToChannel(ctx sdk.Context, chainID, channelID string) { + store := ctx.KVStore(k.storeKey) + store.Set(types.ChainToChannelKey(chainID), []byte(channelID)) +} + +func (k Keeper) SetChannelToChain(ctx sdk.Context, channelID, chainID string) { + store := ctx.KVStore(k.storeKey) + store.Set(types.ChannelToChainKey(channelID), []byte(chainID)) +} + +func (k Keeper) SetInitChainHeight(ctx sdk.Context, chainID string, height uint64) { + store := ctx.KVStore(k.storeKey) + heightBytes := make([]byte, 8) + binary.BigEndian.PutUint64(heightBytes, height) + + store.Set(types.InitChainHeightKey(chainID), heightBytes) +} + +func (k Keeper) GetInitChainHeight(ctx sdk.Context, chainID string) (uint64, bool) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.InitChainHeightKey(chainID)) + if bz == nil { + return 0, false + } + + return binary.BigEndian.Uint64(bz), true +} + +func (k Keeper) DeleteInitTimeoutTimestamp(ctx sdk.Context, chainID string) { + store := ctx.KVStore(k.storeKey) + store.Delete(types.InitTimeoutTimestampKey(chainID)) +} + +func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error { + return k.scopedKeeper.ClaimCapability(ctx, cap, name) +} + +func (k Keeper) VerifyConsumerChain(ctx sdk.Context, channelID string, connectionHops []string) error { + if len(connectionHops) != 1 { + return errorsmod.Wrap(channeltypes.ErrTooManyConnectionHops, "must have direct connection to provider chain") + } + connectionID := connectionHops[0] + clientID, tmClient, err := k.getUnderlyingClient(ctx, connectionID) + if err != nil { + return err + } + ccvClientId, found := k.GetConsumerClientId(ctx, tmClient.ChainId) + if !found { + return errorsmod.Wrapf(cptypes.ErrClientNotFound, "cannot find client for consumer chain %s", tmClient.ChainId) + } + if ccvClientId != clientID { + return errorsmod.Wrapf(types.ErrInvalidConsumerClient, "CCV channel must be built on top of CCV client. expected %s, got %s", ccvClientId, clientID) + } + + // Verify that there isn't already a CCV channel for the consumer chain + if prevChannel, ok := k.GetChainToChannel(ctx, tmClient.ChainId); ok { + return errorsmod.Wrapf(cptypes.ErrDuplicateChannel, "CCV channel with ID: %s already created for consumer chain %s", prevChannel, tmClient.ChainId) + } + return nil +} + +func (k Keeper) GetConsumerClientId(ctx sdk.Context, chainID string) (string, bool) { + store := ctx.KVStore(k.storeKey) + clientIdBytes := store.Get(types.ChainToClientKey(chainID)) + if clientIdBytes == nil { + return "", false + } + return string(clientIdBytes), true +} + +func (k Keeper) GetChannelToChain(ctx sdk.Context, channelID string) (string, bool) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ChannelToChainKey(channelID)) + if bz == nil { + return "", false + } + return string(bz), true +} + +func (k Keeper) SetConsumerCommissionRate( + ctx sdk.Context, + chainID string, + providerAddr types.ProviderConsAddress, + commissionRate sdk.Dec, +) error { + store := ctx.KVStore(k.storeKey) + bz, err := commissionRate.Marshal() + if err != nil { + err = fmt.Errorf("consumer commission rate marshalling failed: %s", err) + ModuleLogger(ctx).Error(err.Error()) + return err + } + + store.Set(types.ConsumerCommissionRateKey(chainID, providerAddr), bz) + return nil +} + +func (k Keeper) SetDepositors(ctx sdk.Context, del types.Depositors) error { + store := ctx.KVStore(k.storeKey) + bz, err := types.ModuleCdc.Marshal(&del) + if err != nil { + err = fmt.Errorf("external staker marshalling failed: %s", err) + ModuleLogger(ctx).Error(err.Error()) + return err + } + store.Set(types.DepositorsKey(del.Address), bz) + + return nil +} + +func (k Keeper) GetDepositors(ctx sdk.Context, del string) (types.Depositors, bool) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.DepositorsKey(del)) + if bz == nil { + return types.Depositors{}, false + } + var r types.Depositors + if err := r.Unmarshal(bz); err != nil { + panic(err) + } + return r, true +} + +func (k Keeper) iterateDepositors(ctx sdk.Context, cb func(depositors types.Depositors) bool) error { + pStore := prefix.NewStore(ctx.KVStore(k.memKey), types.DepositorsKeyPrefix) + iter := pStore.Iterator(nil, nil) + for ; iter.Valid(); iter.Next() { + var r types.Depositors + if err := r.Unmarshal(iter.Value()); err != nil { + panic(err) + } + if cb(r) { + break + } + } + return iter.Close() +} + +func (k Keeper) SetIntermediary(ctx sdk.Context, inter types.Intermediary) error { + store := ctx.KVStore(k.storeKey) + bz, err := types.ModuleCdc.Marshal(&inter) + if err != nil { + err = fmt.Errorf("external staker marshalling failed: %s", err) + ModuleLogger(ctx).Error(err.Error()) + return err + } + store.Set(types.IntermediaryKey(inter.Token.Denom), bz) + + return nil +} + +func (k Keeper) GetIntermediary(ctx sdk.Context, denom string) (types.Intermediary, bool) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.IntermediaryKey(denom)) + if bz == nil { + return types.Intermediary{}, false + } + var r types.Intermediary + if err := r.Unmarshal(bz); err != nil { + panic(err) + } + return r, true +} + +func (k Keeper) GetContractWithNativeDenom(ctx sdk.Context, denom string) sdk.AccAddress { + var contractAddr sdk.AccAddress + + store := ctx.KVStore(k.storeKey) + contractAddr = store.Get(types.ContractWithNativeDenomKey(denom)) + return contractAddr +} + +func (k Keeper) SetContractWithNativeDenom(ctx sdk.Context, denom string, contractAddr sdk.AccAddress) { + store := ctx.KVStore(k.storeKey) + store.Set(types.ContractWithNativeDenomKey(denom), contractAddr) +} diff --git a/x/meshsecurityprovider/keeper/keeper_test.go b/x/meshsecurityprovider/keeper/keeper_test.go new file mode 100644 index 00000000..1ff7f433 --- /dev/null +++ b/x/meshsecurityprovider/keeper/keeper_test.go @@ -0,0 +1,57 @@ +package keeper + +import ( + "testing" + + "github.com/cometbft/cometbft/libs/rand" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" + "github.com/stretchr/testify/require" +) + +func TestStoreDelegator(t *testing.T) { + pCtx, keepers := CreateDefaultTestInput(t) + k := keepers.MeshKeeperProvider + + d1 := types.Depositors{ + Address: sdk.AccAddress(rand.Bytes(32)).String(), + Tokens: sdk.NewCoins([]sdk.Coin{sdk.NewCoin("osmo", sdk.NewInt(123))}...), + } + err := k.SetDepositors(pCtx, d1) + require.NoError(t, err) + + d2, f := k.GetDepositors(pCtx, d1.Address) + require.True(t, f) + require.Equal(t, d1, d2) + + d2.Tokens = d2.Tokens.Add(sdk.NewCoin("juno", sdk.NewInt(10000))) + d2.Tokens = d2.Tokens.Add(sdk.NewCoin("juno", sdk.NewInt(10000))) + err = k.SetDepositors(pCtx, d2) + require.NoError(t, err) + + d3, f := k.GetDepositors(pCtx, d1.Address) + require.True(t, f) + require.Equal(t, sdk.NewInt(20000), d3.Tokens.AmountOf("juno")) +} + +func TestStoreIntermediary(t *testing.T) { + pCtx, keepers := CreateDefaultTestInput(t) + k := keepers.MeshKeeperProvider + + coin := sdk.NewCoin("osmo", sdk.NewInt(123)) + e1 := types.Intermediary{ + ConsumerValidator: sdk.ValAddress(rand.Bytes(32)).String(), + ChainId: "osmo-1", + ContractAddress: sdk.AccAddress(rand.Bytes(32)).String(), + Jailed: false, + Tombstoned: false, + Status: types.Bonded, + Token: &coin, + } + err := k.SetIntermediary(pCtx, e1) + require.NoError(t, err) + + e2, f := k.GetIntermediary(pCtx, e1.Token.Denom) + require.True(t, f) + require.Equal(t, e1, e2) +} diff --git a/x/meshsecurityprovider/keeper/msg_server.go b/x/meshsecurityprovider/keeper/msg_server.go new file mode 100644 index 00000000..197ede8c --- /dev/null +++ b/x/meshsecurityprovider/keeper/msg_server.go @@ -0,0 +1,135 @@ +package keeper + +import ( + "context" + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" +) + +type msgServer struct { + *Keeper +} + +func NewMsgServer(keeper *Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +func (k msgServer) SetConsumerCommissionRate(goCtx context.Context, msg *types.MsgSetConsumerCommissionRate) (*types.MsgSetConsumerCommissionRateResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // TODO: Handle set comissionRate + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeSetConsumerCommissionRate, + sdk.NewAttribute(types.AttributeConsumerChainID, msg.ChainId), + sdk.NewAttribute(types.AttributeProviderValidatorAddress, msg.ProviderAddr), + sdk.NewAttribute(types.AttributeConsumerCommissionRate, msg.Rate.String()), + ), + }) + + return &types.MsgSetConsumerCommissionRateResponse{}, nil +} + +func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*types.MsgDelegateResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + err := msg.Amount.Validate() + if err != nil { + return nil, fmt.Errorf("failed to delegate; Validate fail") + } + denomDelegate := msg.Amount.Denom + + vaultAdress := sdk.AccAddress(k.Keeper.GetParams(ctx).GetVaultContractAddress()) + delegatorAddress, err := sdk.AccAddressFromBech32(msg.DelegatorAddress) + if err != nil { + return nil, err + } + + balance := k.bank.GetBalance(ctx, delegatorAddress, denomDelegate) + + if balance.IsLT(msg.Amount) { + return nil, fmt.Errorf("failed to delegate; %s is smaller than %s", balance, msg.Amount) + } + + if err := k.bank.SendCoins(ctx, delegatorAddress, vaultAdress, sdk.NewCoins([]sdk.Coin{msg.Amount}...)); err != nil { + return nil, err + } + + bondDenom := k.Staking.BondDenom(ctx) + if denomDelegate == bondDenom { + // local stake + err = k.Keeper.LocalStake(ctx, msg.Amount, msg.ValidatorAddress) + if err != nil { + // if fail refunds + k.bank.SendCoins(ctx, vaultAdress, delegatorAddress, sdk.NewCoins([]sdk.Coin{msg.Amount}...)) + return nil, err + } + } else { + // remote stake + err := k.Keeper.RemoteStake(ctx, denomDelegate, msg.Amount) + if err != nil { + // if fail refunds + k.bank.SendCoins(ctx, vaultAdress, delegatorAddress, sdk.NewCoins([]sdk.Coin{msg.Amount}...)) + return nil, err + } + } + + depositors, found := k.Keeper.GetDepositors(ctx, msg.DelegatorAddress) + if !found { + depositors = types.NewDepositors(msg.DelegatorAddress, []sdk.Coin{msg.Amount}) + } else { + depositors.Tokens = depositors.Tokens.Add(msg.Amount) + } + err = k.Keeper.SetDepositors(ctx, depositors) + if err != nil { + return nil, err + } + + return &types.MsgDelegateResponse{}, nil +} + +func (k msgServer) Undelegate(goCtx context.Context, msg *types.MsgUndelegate) (*types.MsgUndelegateResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + err := msg.Amount.Validate() + if err != nil { + return nil, fmt.Errorf("failed to undelegate; Validate fail") + } + denomUndelegate := msg.Amount.Denom + + vaultAdress := sdk.AccAddress(k.Keeper.GetParams(ctx).GetVaultContractAddress()) + delegatorAddress, err := sdk.AccAddressFromBech32(msg.DelegatorAddress) + if err != nil { + return nil, err + } + + depositors, found := k.GetDepositors(ctx, msg.DelegatorAddress) + if !found { + return nil, fmt.Errorf("failed to undelegate; not found Depositors") + } + + found, totalDelegate := depositors.Tokens.Find(denomUndelegate) + if !found { + return nil, fmt.Errorf("failed to undelegate; not found token %s in Depositors", denomUndelegate) + } + + if totalDelegate.IsLT(msg.Amount) { + return nil, fmt.Errorf("failed to delegate; %s is smaller than %s", totalDelegate, msg.Amount) + } + + // call back contract and consumerchain + err = k.Keeper.Undelegate(ctx, *msg) + if err != nil { + return nil, err + } + + if err := k.bank.SendCoins(ctx, vaultAdress, delegatorAddress, sdk.NewCoins([]sdk.Coin{msg.Amount}...)); err != nil { + return nil, err + } + + return &types.MsgUndelegateResponse{}, nil +} diff --git a/x/meshsecurityprovider/keeper/params.go b/x/meshsecurityprovider/keeper/params.go new file mode 100644 index 00000000..bccc5161 --- /dev/null +++ b/x/meshsecurityprovider/keeper/params.go @@ -0,0 +1,30 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" +) + +// SetParams sets the module's parameters. +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { + store := ctx.KVStore(k.storeKey) + bz, err := k.cdc.Marshal(¶ms) + if err != nil { + return err + } + store.Set(types.ParamsKey, bz) + + return nil +} + +// GetParams gets the module's parameters. +func (k Keeper) GetParams(clientCtx sdk.Context) (params types.Params) { + store := clientCtx.KVStore(k.storeKey) + bz := store.Get(types.ParamsKey) + if bz == nil { + return params + } + + k.cdc.MustUnmarshal(bz, ¶ms) + return params +} diff --git a/x/meshsecurityprovider/keeper/querier.go b/x/meshsecurityprovider/keeper/querier.go new file mode 100644 index 00000000..0bab8edf --- /dev/null +++ b/x/meshsecurityprovider/keeper/querier.go @@ -0,0 +1,28 @@ +package keeper + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" +) + +var _ types.QueryServer = &querier{} + +type querier struct { + cdc codec.Codec + k *Keeper +} + +// NewQuerier constructor +func NewQuerier(cdc codec.Codec, k *Keeper) *querier { + return &querier{cdc: cdc, k: k} +} + +// Params implements the gRPC service handler for querying the mesh-security parameters. +func (q querier) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + params := q.k.GetParams(sdk.UnwrapSDKContext(ctx)) + return &types.QueryParamsResponse{Params: params}, nil +} diff --git a/x/meshsecurityprovider/keeper/relay.go b/x/meshsecurityprovider/keeper/relay.go new file mode 100644 index 00000000..cfc04359 --- /dev/null +++ b/x/meshsecurityprovider/keeper/relay.go @@ -0,0 +1,301 @@ +package keeper + +import ( + "fmt" + "strconv" + + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" + cptypes "github.com/osmosis-labs/mesh-security-sdk/x/types" +) + +func (k Keeper) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet) error { + chainID, found := k.GetChannelToChain(ctx, packet.SourceChannel) + if !found { + ModuleLogger(ctx).Error("packet timeout, unknown channel:", "channelID", packet.SourceChannel) + // abort transaction + return errorsmod.Wrap( + channeltypes.ErrInvalidChannelState, + packet.SourceChannel, + ) + } + ModuleLogger(ctx).Info("packet timeout, removing the consumer:", "chainID", chainID) + // stop consumer chain and release unbondings + return k.StopConsumerChain(ctx, chainID, false) +} + +func (k Keeper) StopConsumerChain(ctx sdk.Context, chainID string, closeChan bool) (err error) { + // check that a client for chainID exists + if _, found := k.GetConsumerClientId(ctx, chainID); !found { + return errorsmod.Wrap(types.ErrConsumerChainNotFound, + fmt.Sprintf("cannot stop non-existent consumer chain: %s", chainID)) + } + + // TODO: Stop consumerchain + + ModuleLogger(ctx).Info("consumer chain removed from provider", "chainID", chainID) + + return nil +} + +// OnAcknowledgementPacket handles acknowledgments for sent VSC packets +func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Packet, ack channeltypes.Acknowledgement) error { + if err := ack.GetError(); err != "" { + // The VSC packet data could not be successfully decoded. + // This should never happen. + ModuleLogger(ctx).Error( + "recv ErrorAcknowledgement", + "channelID", packet.SourceChannel, + "error", err, + ) + if chainID, ok := k.GetChannelToChain(ctx, packet.SourceChannel); ok { + // stop consumer chain and release unbonding + return k.StopConsumerChain(ctx, chainID, false) + } + return errorsmod.Wrapf(types.ErrUnknownConsumerChannelId, "recv ErrorAcknowledgement on unknown channel %s", packet.SourceChannel) + } + return nil +} + +func (k Keeper) OnRecvSlashPacket( + ctx sdk.Context, + packet channeltypes.Packet, + data cptypes.SlashInfo, +) (cptypes.PacketAckResult, error) { + chainID, found := k.GetChannelToChain(ctx, packet.DestinationChannel) + if !found { + ModuleLogger(ctx).Error("SlashPacket received on unknown channel", + "channelID", packet.DestinationChannel, + ) + panic(fmt.Errorf("SlashPacket received on unknown channel %s", packet.DestinationChannel)) + } + // validate packet data upon receiving + if err := data.Validate(); err != nil { + return nil, errorsmod.Wrapf(err, "error validating SlashPacket data") + } + + if err := k.ValidateSlashPacket(ctx, chainID); err != nil { + ModuleLogger(ctx).Error("invalid slash packet", + "error", err.Error(), + "chainID", chainID, + ) + return nil, err + } + + k.HandleSlashPacket(ctx, chainID, data) + + ModuleLogger(ctx).Info("slash packet received and handled", + "chainID", chainID, + "consumer val addr", data.Validator, + ) + return cptypes.SlashPacketHandledResult, nil +} + +func (k Keeper) OnRecvBondedPacket( + ctx sdk.Context, + packet channeltypes.Packet, + data *cptypes.ScheduleInfo, +) (cptypes.PacketAckResult, error) { + intermediary, found := k.GetIntermediary(ctx, data.Denom) + if !found { + ModuleLogger(ctx).Error("External Staker not found for validor", + data.Validator, + ) + panic(fmt.Errorf("external Staker not found for validor %s", data.Validator)) + } + + if intermediary.Status != types.Bonded { + intermediary.Status = types.Bonded + } + k.SetIntermediary(ctx, intermediary) + return cptypes.SlashPacketHandledResult, nil +} + +func (k Keeper) OnRecvUnbondedPacket( + ctx sdk.Context, + packet channeltypes.Packet, + data *cptypes.ScheduleInfo, +) (cptypes.PacketAckResult, error) { + intermediary, found := k.GetIntermediary(ctx, data.Denom) + if !found { + ModuleLogger(ctx).Error("External Staker not found for validor", + data.Validator, + ) + panic(fmt.Errorf("external Staker not found for validor %s", data.Validator)) + } + + if intermediary.Status != types.Unbonded { + intermediary.Status = types.Unbonded + } + k.SetIntermediary(ctx, intermediary) + return cptypes.SlashPacketHandledResult, nil +} + +func (k Keeper) OnRecvJailedPacket( + ctx sdk.Context, + packet channeltypes.Packet, + data *cptypes.ScheduleInfo, +) (cptypes.PacketAckResult, error) { + intermediary, found := k.GetIntermediary(ctx, data.Denom) + if !found { + ModuleLogger(ctx).Error("External Staker not found for validor", + data.Validator, + ) + panic(fmt.Errorf("external Staker not found for validor %s", data.Validator)) + } + + if intermediary.IsUnboned() { + ModuleLogger(ctx).Error("validator %s is unbonded", data.Validator) + return cptypes.SlashPacketHandledResult, nil + } + + if intermediary.IsTombstoned() { + ModuleLogger(ctx).Info( + "slash packet dropped because validator %s is already tombstoned", data.Validator, + ) + return cptypes.SlashPacketHandledResult, nil + } + if intermediary.IsJailed() { + ModuleLogger(ctx).Info("validator %s jailed", data.Validator) + return cptypes.SlashPacketHandledResult, nil + } + intermediary.Jailed = true + k.SetIntermediary(ctx, intermediary) + + return cptypes.SlashPacketHandledResult, nil +} + +func (k Keeper) OnRecvTombstonedPacket( + ctx sdk.Context, + packet channeltypes.Packet, + data *cptypes.ScheduleInfo, +) (cptypes.PacketAckResult, error) { + intermediary, found := k.GetIntermediary(ctx, data.Denom) + if !found { + ModuleLogger(ctx).Error("External Staker not found for validor", + data.Validator, + ) + panic(fmt.Errorf("external Staker not found for validor %s", data.Validator)) + } + + if intermediary.IsUnboned() { + ModuleLogger(ctx).Error("validator %s is unbonded", data.Validator) + return cptypes.SlashPacketHandledResult, nil + } + intermediary.Tombstoned = true + k.SetIntermediary(ctx, intermediary) + + return cptypes.SlashPacketHandledResult, nil +} +func (k Keeper) OnRecvUnjailedPacket( + ctx sdk.Context, + packet channeltypes.Packet, + data *cptypes.ScheduleInfo, +) (cptypes.PacketAckResult, error) { + intermediary, found := k.GetIntermediary(ctx, data.Denom) + if !found { + ModuleLogger(ctx).Error("External Staker not found for validor", + data.Validator, + ) + panic(fmt.Errorf("external Staker not found for validor %s", data.Validator)) + } + + if intermediary.IsUnboned() { + ModuleLogger(ctx).Error("validator %s is unbonded", data.Validator) + return cptypes.SlashPacketHandledResult, nil + } + if !intermediary.Jailed { + ModuleLogger(ctx).Error("validator %s is not jailed", data.Validator) + return cptypes.SlashPacketHandledResult, nil + } + + intermediary.Jailed = false + k.SetIntermediary(ctx, intermediary) + + return cptypes.SlashPacketHandledResult, nil +} +func (k Keeper) OnRecvModifiedPacket( + ctx sdk.Context, + packet channeltypes.Packet, + data *cptypes.ScheduleInfo, +) (cptypes.PacketAckResult, error) { + + return cptypes.SlashPacketHandledResult, nil +} + +func (k Keeper) HandleSlashPacket(ctx sdk.Context, chainID string, data cptypes.SlashInfo) { + totalSlashAmount, err := sdk.ParseCoinNormalized(data.TotalSlashAmount) + if err != nil { + ModuleLogger(ctx).Error("Handle slash packet fail: ParseCoinsNormalized fail") + return + } + denom := totalSlashAmount.Denom + intermediary, found := k.GetIntermediary(ctx, denom) + if !found { + ModuleLogger(ctx).Error("External Staker not found for validor", + data.Validator, + ) + panic(fmt.Errorf("external Staker not found for validor %s", data.Validator)) + } + + if intermediary.IsUnboned() { + ModuleLogger(ctx).Error("validator is unbonded") + return + } + + if intermediary.IsTombstoned() { + ModuleLogger(ctx).Info( + "slash packet dropped because validator is already tombstoned", + ) + return + } + if intermediary.IsJailed() { + ModuleLogger(ctx).Info("validator jailed") + return + } + + intermediary.Jailed = true + slashRatio := sdk.MustNewDecFromStr(data.SlashFraction) + amountSlash := slashRatio.MulInt(intermediary.Token.Amount).TruncateInt() + newAmount := sdk.NewCoin(denom, amountSlash) + intermediary.Token = &newAmount + k.SetIntermediary(ctx, intermediary) + + k.iterateDepositors(ctx, func(depositors types.Depositors) bool { + amout := depositors.Tokens.AmountOf(denom) + if amout.GT(sdk.ZeroInt()) { + amountSlash = slashRatio.MulInt(amout).TruncateInt() + tokenSlash := sdk.NewCoin(denom, amountSlash) + newTokens := depositors.Tokens.Sub(tokenSlash) + depositors.Tokens = newTokens + + k.SetDepositors(ctx, depositors) + } + return false + }) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeExecuteConsumerChainSlash, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(types.AttributeInfractionHeight, strconv.FormatInt(data.InfractionHeight, 10)), + sdk.NewAttribute(types.AttributeConsumerValidator, data.Validator), + ), + ) +} + +func (k Keeper) ValidateSlashPacket(ctx sdk.Context, chainID string, +) error { + _, found := k.GetInitChainHeight(ctx, chainID) + // return error if we cannot find infraction height matching the validator update id + if !found { + return fmt.Errorf("cannot find infraction height matching "+ + "for chain %s", chainID) + } + + return nil +} diff --git a/x/meshsecurityprovider/keeper/relay_test.go b/x/meshsecurityprovider/keeper/relay_test.go new file mode 100644 index 00000000..b55569d4 --- /dev/null +++ b/x/meshsecurityprovider/keeper/relay_test.go @@ -0,0 +1 @@ +package keeper diff --git a/x/meshsecurityprovider/keeper/test_common.go b/x/meshsecurityprovider/keeper/test_common.go new file mode 100644 index 00000000..184322f3 --- /dev/null +++ b/x/meshsecurityprovider/keeper/test_common.go @@ -0,0 +1,316 @@ +package keeper + +import ( + "testing" + "time" + + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + dbm "github.com/cometbft/cometbft-db" + "github.com/cometbft/cometbft/libs/log" + "github.com/cometbft/cometbft/libs/rand" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + codec2 "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/std" + "github.com/cosmos/cosmos-sdk/store" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/testutil/mock" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/auth" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + "github.com/cosmos/cosmos-sdk/x/auth/tx" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" + "github.com/cosmos/cosmos-sdk/x/bank" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" + "github.com/cosmos/cosmos-sdk/x/gov" + govclient "github.com/cosmos/cosmos-sdk/x/gov/client" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/cosmos-sdk/x/mint" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" + upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" +) + +type encodingConfig struct { + InterfaceRegistry codectypes.InterfaceRegistry + Marshaler codec.Codec + TxConfig client.TxConfig + Amino *codec.LegacyAmino +} + +var moduleBasics = module.NewBasicManager( + auth.AppModuleBasic{}, + bank.AppModuleBasic{}, + staking.AppModuleBasic{}, + mint.AppModuleBasic{}, + gov.NewAppModuleBasic([]govclient.ProposalHandler{ + paramsclient.ProposalHandler, + upgradeclient.LegacyProposalHandler, + upgradeclient.LegacyCancelProposalHandler, + }), +) + +func makeEncodingConfig(_ testing.TB) encodingConfig { + amino := codec.NewLegacyAmino() + interfaceRegistry := codectypes.NewInterfaceRegistry() + marshaler := codec.NewProtoCodec(interfaceRegistry) + std.RegisterInterfaces(interfaceRegistry) + std.RegisterLegacyAminoCodec(amino) + + moduleBasics.RegisterLegacyAminoCodec(amino) + moduleBasics.RegisterInterfaces(interfaceRegistry) + // add mesh-security types + types.RegisterInterfaces(interfaceRegistry) + types.RegisterLegacyAminoCodec(amino) + + return encodingConfig{ + InterfaceRegistry: interfaceRegistry, + Marshaler: marshaler, + TxConfig: tx.NewTxConfig(marshaler, tx.DefaultSignModes), + Amino: amino, + } +} + +type TestKeepers struct { + StakingKeeper *stakingkeeper.Keeper + SlashingKeeper slashingkeeper.Keeper + BankKeeper bankkeeper.Keeper + StoreKey *storetypes.KVStoreKey + EncodingConfig encodingConfig + MeshKeeperProvider *Keeper + AccountKeeper authkeeper.AccountKeeper + WasmKeeper *wasmkeeper.Keeper + Faucet *wasmkeeper.TestFaucet +} + +func CreateDefaultTestInput(t testing.TB, opts ...Option) (sdk.Context, TestKeepers) { + db := dbm.NewMemDB() + ms := store.NewCommitMultiStore(db) + keys := sdk.NewKVStoreKeys( + authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, + minttypes.StoreKey, distributiontypes.StoreKey, slashingtypes.StoreKey, + govtypes.StoreKey, paramstypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey, + evidencetypes.StoreKey, ibctransfertypes.StoreKey, + capabilitytypes.StoreKey, feegrant.StoreKey, authzkeeper.StoreKey, + wasmtypes.StoreKey, types.StoreKey, + ) + for _, v := range keys { + ms.MountStoreWithDB(v, storetypes.StoreTypeIAVL, db) + } + memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey, types.MemStoreKey) + for _, v := range memKeys { + ms.MountStoreWithDB(v, storetypes.StoreTypeMemory, db) + } + tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) + for _, v := range tkeys { + ms.MountStoreWithDB(v, storetypes.StoreTypeTransient, db) + } + require.NoError(t, ms.LoadLatestVersion()) + + encConfig := makeEncodingConfig(t) + appCodec := encConfig.Marshaler + + maccPerms := map[string][]string{ // module account permissions + authtypes.FeeCollectorName: nil, + distributiontypes.ModuleName: nil, + minttypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + types.ModuleName: {authtypes.Minter, authtypes.Burner}, + } + authority := authtypes.NewModuleAddress(govtypes.ModuleName).String() + accountKeeper := authkeeper.NewAccountKeeper( + appCodec, + keys[authtypes.StoreKey], // target store + authtypes.ProtoBaseAccount, // prototype + maccPerms, + sdk.Bech32MainPrefix, + authority, + ) + blockedAddrs := make(map[string]bool) + for acc := range maccPerms { + blockedAddrs[authtypes.NewModuleAddress(acc).String()] = true + } + ctx := sdk.NewContext(ms, tmproto.Header{ + Height: 1234567, + Time: time.Date(2020, time.April, 22, 12, 0, 0, 0, time.UTC), + }, false, log.NewNopLogger()) + + bankKeeper := bankkeeper.NewBaseKeeper( + appCodec, + keys[banktypes.StoreKey], + accountKeeper, + blockedAddrs, + authority, + ) + require.NoError(t, bankKeeper.SetParams(ctx, banktypes.DefaultParams())) + + stakingKeeper := stakingkeeper.NewKeeper( + appCodec, + keys[stakingtypes.StoreKey], + accountKeeper, + bankKeeper, + authority, + ) + require.NoError(t, stakingKeeper.SetParams(ctx, stakingtypes.DefaultParams())) + + slashingKeeper := slashingkeeper.NewKeeper( + appCodec, + encConfig.Amino, + keys[slashingtypes.StoreKey], + stakingKeeper, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + require.NoError(t, slashingKeeper.SetParams(ctx, slashingtypes.DefaultParams())) + + distKeeper := distributionkeeper.NewKeeper( + appCodec, + keys[distributiontypes.StoreKey], + accountKeeper, + bankKeeper, + stakingKeeper, + authtypes.FeeCollectorName, + authtypes.NewModuleAddress(distributiontypes.ModuleName).String(), + ) + require.NoError(t, distKeeper.SetParams(ctx, distributiontypes.DefaultParams())) + + querier := baseapp.NewGRPCQueryRouter() + querier.SetInterfaceRegistry(encConfig.InterfaceRegistry) + msgRouter := baseapp.NewMsgServiceRouter() + msgRouter.SetInterfaceRegistry(encConfig.InterfaceRegistry) + + capabilityKeeper := capabilitykeeper.NewKeeper( + appCodec, + keys[capabilitytypes.StoreKey], + memKeys[capabilitytypes.MemStoreKey], + ) + scopedIBCKeeper := capabilityKeeper.ScopeToModule(ibcexported.ModuleName) + scopedWasmKeeper := capabilityKeeper.ScopeToModule(types.ModuleName) + + paramsKeeper := paramskeeper.NewKeeper( + appCodec, + encConfig.Amino, + keys[paramstypes.StoreKey], + tkeys[paramstypes.TStoreKey], + ) + + upgradeKeeper := upgradekeeper.NewKeeper( + map[int64]bool{}, + keys[upgradetypes.StoreKey], + appCodec, + t.TempDir(), + nil, + authtypes.NewModuleAddress(upgradetypes.ModuleName).String(), + ) + + ibcKeeper := ibckeeper.NewKeeper( + appCodec, + keys[ibcexported.StoreKey], + paramsKeeper.Subspace(ibcexported.ModuleName), + stakingKeeper, + upgradeKeeper, + scopedIBCKeeper, + ) + + cfg := sdk.GetConfig() + cfg.SetAddressVerifier(wasmtypes.VerifyAddressLen()) + + wasmKeeper := wasmkeeper.NewKeeper( + appCodec, + keys[wasmtypes.StoreKey], + accountKeeper, + bankKeeper, + stakingKeeper, + distributionkeeper.NewQuerier(distKeeper), + ibcKeeper.ChannelKeeper, // ICS4Wrapper + ibcKeeper.ChannelKeeper, + &ibcKeeper.PortKeeper, + scopedWasmKeeper, + wasmtesting.MockIBCTransferKeeper{}, + msgRouter, + querier, + t.TempDir(), + wasmtypes.DefaultWasmConfig(), + "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,virtual_staking", + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + require.NoError(t, wasmKeeper.SetParams(ctx, wasmtypes.DefaultParams())) + + meshKeeperProvider := NewKeeper( + appCodec, + keys[types.StoreKey], + memKeys[types.MemStoreKey], + bankKeeper, + stakingKeeper, + wasmKeeper, + scopedWasmKeeper, + ibcKeeper.ChannelKeeper, + authority, + opts..., + ) + require.NoError(t, meshKeeperProvider.SetParams(ctx, types.DefaultParams(sdk.DefaultBondDenom))) + + faucet := wasmkeeper.NewTestFaucet(t, ctx, bankKeeper, minttypes.ModuleName, sdk.NewInt64Coin(sdk.DefaultBondDenom, 1_000_000_000_000)) + return ctx, TestKeepers{ + AccountKeeper: accountKeeper, + StakingKeeper: stakingKeeper, + SlashingKeeper: slashingKeeper, + BankKeeper: bankKeeper, + StoreKey: keys[types.StoreKey], + EncodingConfig: encConfig, + MeshKeeperProvider: meshKeeperProvider, + WasmKeeper: &wasmKeeper, + Faucet: faucet, + } +} + +// MinValidatorFixture creates minimal sdk validator object +func MinValidatorFixture(t *testing.T) stakingtypes.Validator { + t.Helper() + privVal := mock.NewPV() + pubKey, err := privVal.GetPubKey() + require.NoError(t, err) + + pk, err := codec2.FromTmPubKeyInterface(pubKey) + require.NoError(t, err) + pkAny, err := codectypes.NewAnyWithValue(pk) + require.NoError(t, err) + + return stakingtypes.Validator{ + ConsensusPubkey: pkAny, + OperatorAddress: sdk.ValAddress(rand.Bytes(address.Len)).String(), + } +} diff --git a/x/meshsecurityprovider/keeper/wasm.go b/x/meshsecurityprovider/keeper/wasm.go new file mode 100644 index 00000000..5fa3a394 --- /dev/null +++ b/x/meshsecurityprovider/keeper/wasm.go @@ -0,0 +1,44 @@ +package keeper + +import ( + "encoding/json" + + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/contract" +) + +func (k Keeper) SendVaultStake(ctx sdk.Context, v contract.StakeMsg) error { + msg := contract.SudoMsg{ + VaultSudoMsg: &v, + } + + return k.doSudoCall(ctx, k.GetParams(ctx).GetVaultContractAddress(), msg) +} + +func (k Keeper) doSudoCall(ctx sdk.Context, contractAddr sdk.AccAddress, msg contract.SudoMsg) error { + bz, err := json.Marshal(msg) + if err != nil { + return errorsmod.Wrap(err, "marshal sudo msg") + } + _, err = k.wasm.Sudo(ctx, contractAddr, bz) + return err +} + +func (k Keeper) SendCustomUnbond(ctx sdk.Context, v contract.VaultCustomMsg) error { + msg := contract.CustomMsg{ + VaultCustomMsg: &v, + } + return k.doExcCall(ctx, k.GetParams(ctx).GetVaultContractAddress(), msg) +} + +func (k Keeper) doExcCall(ctx sdk.Context, contractAddr sdk.AccAddress, msg contract.CustomMsg) error { + bz, err := json.Marshal(msg) + if err != nil { + return errorsmod.Wrap(err, "marshal sudo msg") + } + _, err = k.wasm.Sudo(ctx, contractAddr, bz) + return err +} diff --git a/x/meshsecurityprovider/module.go b/x/meshsecurityprovider/module.go new file mode 100644 index 00000000..aefb7763 --- /dev/null +++ b/x/meshsecurityprovider/module.go @@ -0,0 +1,145 @@ +package meshsecurityprovider + +import ( + "context" + "encoding/json" + "fmt" + + abci "github.com/cometbft/cometbft/abci/types" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" + + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/client/cli" + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/keeper" + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" +) + +var ( + _ porttypes.IBCModule = AppModule{} +) + +// ConsensusVersion defines the module's consensus version. +const ConsensusVersion = 1 + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// AppModuleBasic defines the basic application module used by the mesh-security module. +type AppModuleBasic struct{} + +func (b AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(amino) +} + +func (b AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, serveMux *runtime.ServeMux) { + err := types.RegisterQueryHandlerClient(context.Background(), serveMux, types.NewQueryClient(clientCtx)) + if err != nil { + panic(err) + } +} + +// Name returns the provider module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// DefaultGenesis returns default genesis state as raw bytes for the mesh-security +// module. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesisState(sdk.DefaultBondDenom)) +} + +// ValidateGenesis performs genesis state validation for the mesh-security module. +func (b AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var data types.GenesisState + if err := cdc.UnmarshalJSON(bz, &data); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + + return types.ValidateGenesis(&data) +} + +// GetTxCmd returns the root tx command for the mesh-security module. +func (b AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns no root query command for the mesh-security module. +func (b AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// RegisterInterfaces implements InterfaceModule +func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) +} + +// AppModule implements an application module interface +type AppModule struct { + AppModuleBasic + cdc codec.Codec + k *keeper.Keeper +} + +// NewAppModuleX extended constructor +func NewAppModule(cdc codec.Codec, k *keeper.Keeper) *AppModule { + return &AppModule{cdc: cdc, k: k} +} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + +// Name returns the module's name. +func (AppModule) Name() string { return types.ModuleName } + +// RegisterServices registers module services. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServer(am.k)) + types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.cdc, am.k)) +} + +// RegisterInvariants registers the module's invariants. +func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { +} + +// InitGenesis performs genesis initialization for the mesh-security module. It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate { + var data types.GenesisState + cdc.MustUnmarshalJSON(bz, &data) + am.k.InitGenesis(ctx, data) + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the exported genesis state as raw bytes for the mesh-security +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(am.k.ExportGenesis(ctx)) +} + +// QuerierRoute returns the bank module's querier route name. +func (AppModule) QuerierRoute() string { + return types.RouterKey +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { + return ConsensusVersion +} + +// BeginBlock executed before every block +func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { +} + +// EndBlock executed after every block. It returns no validator updates. +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return nil +} diff --git a/x/meshsecurityprovider/types/codec.go b/x/meshsecurityprovider/types/codec.go new file mode 100644 index 00000000..66763b8f --- /dev/null +++ b/x/meshsecurityprovider/types/codec.go @@ -0,0 +1,44 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +// RegisterLegacyAminoCodec register types with legacy amino +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgDelegate{}, "provider/MsgDelegate", nil) + cdc.RegisterConcrete(&MsgUndelegate{}, "provider/MsgUndelegate", nil) + cdc.RegisterConcrete(&MsgSetConsumerCommissionRate{}, "provider/MsgSetConsumerCommissionRate", nil) +} + +// RegisterInterfaces register types with interface registry +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgDelegate{}, + ) + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgUndelegate{}, + ) + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgSetConsumerCommissionRate{}, + ) + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) +} diff --git a/x/meshsecurityprovider/types/delegate.go b/x/meshsecurityprovider/types/delegate.go new file mode 100644 index 00000000..8689242a --- /dev/null +++ b/x/meshsecurityprovider/types/delegate.go @@ -0,0 +1,34 @@ +package types + +import sdk "github.com/cosmos/cosmos-sdk/types" + +func (e Intermediary) IsTombstoned() bool { + return e.Tombstoned +} + +func (e Intermediary) IsUnboned() bool { + return e.Status == Unbonded +} + +func (e Intermediary) IsJailed() bool { + return e.Jailed +} + +func NewIntermediary(consumerValidator, chainID, contractAddress string, jailed, tombstoned bool, status BondStatus, token *sdk.Coin) Intermediary { + return Intermediary{ + ConsumerValidator: consumerValidator, + ContractAddress: contractAddress, + ChainId: chainID, + Jailed: jailed, + Tombstoned: tombstoned, + Status: status, + Token: token, + } +} + +func NewDepositors(address string, tokens sdk.Coins) Depositors { + return Depositors{ + Address: address, + Tokens: tokens, + } +} diff --git a/x/meshsecurityprovider/types/delegate.pb.go b/x/meshsecurityprovider/types/delegate.pb.go new file mode 100644 index 00000000..53d1af93 --- /dev/null +++ b/x/meshsecurityprovider/types/delegate.pb.go @@ -0,0 +1,834 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: osmosis/meshsecurityprovider/v1beta1/delegate.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// BondStatus is the status of a validator. +type BondStatus int32 + +const ( + // UNSPECIFIED defines an invalid validator status. + Unspecified BondStatus = 0 + // UNBONDED defines a validator that is not bonded. + Unbonded BondStatus = 1 + // UNBONDING defines a validator that is unbonding. + Unbonding BondStatus = 2 + // BONDED defines a validator that is bonded. + Bonded BondStatus = 3 +) + +var BondStatus_name = map[int32]string{ + 0: "BOND_STATUS_UNSPECIFIED", + 1: "BOND_STATUS_UNBONDED", + 2: "BOND_STATUS_UNBONDING", + 3: "BOND_STATUS_BONDED", +} + +var BondStatus_value = map[string]int32{ + "BOND_STATUS_UNSPECIFIED": 0, + "BOND_STATUS_UNBONDED": 1, + "BOND_STATUS_UNBONDING": 2, + "BOND_STATUS_BONDED": 3, +} + +func (x BondStatus) String() string { + return proto.EnumName(BondStatus_name, int32(x)) +} + +func (BondStatus) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_ff7e9b6105b0114c, []int{0} +} + +// Params defines the parameters for the x/meshsecurity module. +type Depositors struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Tokens github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=tokens,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"tokens"` +} + +func (m *Depositors) Reset() { *m = Depositors{} } +func (m *Depositors) String() string { return proto.CompactTextString(m) } +func (*Depositors) ProtoMessage() {} +func (*Depositors) Descriptor() ([]byte, []int) { + return fileDescriptor_ff7e9b6105b0114c, []int{0} +} +func (m *Depositors) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Depositors) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Depositors.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Depositors) XXX_Merge(src proto.Message) { + xxx_messageInfo_Depositors.Merge(m, src) +} +func (m *Depositors) XXX_Size() int { + return m.Size() +} +func (m *Depositors) XXX_DiscardUnknown() { + xxx_messageInfo_Depositors.DiscardUnknown(m) +} + +var xxx_messageInfo_Depositors proto.InternalMessageInfo + +// vault-staker +type Intermediary struct { + ConsumerValidator string `protobuf:"bytes,1,opt,name=consumer_validator,json=consumerValidator,proto3" json:"consumer_validator,omitempty"` + ChainId string `protobuf:"bytes,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + ContractAddress string `protobuf:"bytes,3,opt,name=contract_address,json=contractAddress,proto3" json:"contract_address,omitempty"` + Jailed bool `protobuf:"varint,4,opt,name=jailed,proto3" json:"jailed,omitempty"` + Tombstoned bool `protobuf:"varint,5,opt,name=tombstoned,proto3" json:"tombstoned,omitempty"` + Status BondStatus `protobuf:"varint,6,opt,name=status,proto3,enum=osmosis.meshsecurityprovider.v1beta1.BondStatus" json:"status,omitempty"` + Token *types.Coin `protobuf:"bytes,7,opt,name=token,proto3" json:"token,omitempty"` +} + +func (m *Intermediary) Reset() { *m = Intermediary{} } +func (m *Intermediary) String() string { return proto.CompactTextString(m) } +func (*Intermediary) ProtoMessage() {} +func (*Intermediary) Descriptor() ([]byte, []int) { + return fileDescriptor_ff7e9b6105b0114c, []int{1} +} +func (m *Intermediary) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Intermediary) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Intermediary.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Intermediary) XXX_Merge(src proto.Message) { + xxx_messageInfo_Intermediary.Merge(m, src) +} +func (m *Intermediary) XXX_Size() int { + return m.Size() +} +func (m *Intermediary) XXX_DiscardUnknown() { + xxx_messageInfo_Intermediary.DiscardUnknown(m) +} + +var xxx_messageInfo_Intermediary proto.InternalMessageInfo + +func init() { + proto.RegisterEnum("osmosis.meshsecurityprovider.v1beta1.BondStatus", BondStatus_name, BondStatus_value) + proto.RegisterType((*Depositors)(nil), "osmosis.meshsecurityprovider.v1beta1.Depositors") + proto.RegisterType((*Intermediary)(nil), "osmosis.meshsecurityprovider.v1beta1.Intermediary") +} + +func init() { + proto.RegisterFile("osmosis/meshsecurityprovider/v1beta1/delegate.proto", fileDescriptor_ff7e9b6105b0114c) +} + +var fileDescriptor_ff7e9b6105b0114c = []byte{ + // 579 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xcd, 0x6e, 0xd3, 0x4c, + 0x14, 0xf5, 0xa4, 0xad, 0xdb, 0x4e, 0xfb, 0x7d, 0x4d, 0x47, 0x05, 0x5c, 0x2f, 0x5c, 0xab, 0x42, + 0xc8, 0x54, 0xc4, 0xa6, 0xad, 0x78, 0x80, 0xa6, 0x69, 0x21, 0x9b, 0x82, 0x92, 0x86, 0x05, 0x9b, + 0x68, 0xec, 0x19, 0x92, 0xa1, 0xf1, 0x4c, 0xe4, 0x99, 0x44, 0xe4, 0x0d, 0x50, 0x56, 0x7d, 0x81, + 0xac, 0xd8, 0x54, 0xac, 0x58, 0xf5, 0x19, 0xb2, 0xec, 0x92, 0x15, 0x3f, 0xc9, 0x82, 0xd7, 0x40, + 0x19, 0xdb, 0x10, 0x44, 0x85, 0xd8, 0xd8, 0x73, 0xef, 0x3d, 0xe7, 0xe8, 0xdc, 0x3b, 0x77, 0xe0, + 0xa1, 0x90, 0xb1, 0x90, 0x4c, 0x06, 0x31, 0x95, 0x6d, 0x49, 0xa3, 0x5e, 0xc2, 0xd4, 0xa0, 0x9b, + 0x88, 0x3e, 0x23, 0x34, 0x09, 0xfa, 0xfb, 0x21, 0x55, 0x78, 0x3f, 0x20, 0xb4, 0x43, 0x5b, 0x58, + 0x51, 0xbf, 0x9b, 0x08, 0x25, 0xd0, 0xfd, 0x8c, 0xe4, 0xdf, 0x46, 0xf2, 0x33, 0x92, 0xed, 0x44, + 0x1a, 0x16, 0x84, 0x58, 0xd2, 0x9f, 0x4a, 0x91, 0x60, 0x3c, 0x55, 0xb1, 0xb7, 0x5a, 0xa2, 0x25, + 0xf4, 0x31, 0x98, 0x9d, 0xb2, 0xec, 0x26, 0x8e, 0x19, 0x17, 0x81, 0xfe, 0xa6, 0xa9, 0xdd, 0x4b, + 0x00, 0x61, 0x85, 0x76, 0x85, 0x64, 0x4a, 0x24, 0x12, 0x59, 0x70, 0x19, 0x13, 0x92, 0x50, 0x29, + 0x2d, 0xe0, 0x02, 0x6f, 0xb5, 0x96, 0x87, 0xa8, 0x0d, 0x4d, 0x25, 0x2e, 0x28, 0x97, 0x56, 0xc1, + 0x5d, 0xf0, 0xd6, 0x0e, 0xb6, 0xfd, 0xd4, 0x82, 0x3f, 0xb3, 0x90, 0xfb, 0xf2, 0x8f, 0x05, 0xe3, + 0xe5, 0x27, 0xe3, 0xcf, 0x3b, 0xc6, 0x87, 0x2f, 0x3b, 0x5e, 0x8b, 0xa9, 0x76, 0x2f, 0xf4, 0x23, + 0x11, 0x07, 0x99, 0xdf, 0xf4, 0x57, 0x92, 0xe4, 0x22, 0x50, 0x83, 0x2e, 0x95, 0x9a, 0x20, 0xaf, + 0xbe, 0x7f, 0xdc, 0x03, 0xb5, 0x4c, 0x7f, 0xf7, 0xba, 0x00, 0xd7, 0xab, 0x5c, 0xd1, 0x24, 0xa6, + 0x84, 0xe1, 0x64, 0x80, 0x4a, 0x10, 0x45, 0x82, 0xcb, 0x5e, 0x4c, 0x93, 0x66, 0x1f, 0x77, 0x18, + 0xc1, 0x4a, 0x24, 0x99, 0xbf, 0xcd, 0xbc, 0xf2, 0x32, 0x2f, 0xa0, 0x6d, 0xb8, 0x12, 0xb5, 0x31, + 0xe3, 0x4d, 0x46, 0xac, 0x42, 0xda, 0x84, 0x8e, 0xab, 0x04, 0x3d, 0x84, 0xc5, 0x48, 0x70, 0x95, + 0xe0, 0x48, 0x35, 0xf3, 0x3e, 0x17, 0x34, 0x64, 0x23, 0xcf, 0x1f, 0x65, 0xfd, 0xde, 0x85, 0xe6, + 0x1b, 0xcc, 0x3a, 0x94, 0x58, 0x8b, 0x2e, 0xf0, 0x56, 0x6a, 0x59, 0x84, 0x1c, 0x08, 0x95, 0x88, + 0x43, 0xa9, 0x04, 0xa7, 0xc4, 0x5a, 0xd2, 0xb5, 0xb9, 0x0c, 0x7a, 0x06, 0x4d, 0xa9, 0xb0, 0xea, + 0x49, 0xcb, 0x74, 0x81, 0xf7, 0xff, 0xc1, 0x63, 0xff, 0x5f, 0x2e, 0xd4, 0x2f, 0x0b, 0x4e, 0xea, + 0x9a, 0x57, 0xcb, 0xf8, 0x28, 0x80, 0x4b, 0x7a, 0x22, 0xd6, 0xb2, 0x0b, 0xfe, 0x3a, 0xf0, 0x5a, + 0x8a, 0xdb, 0xbb, 0x06, 0x10, 0xfe, 0xd2, 0x41, 0x8f, 0xe0, 0xbd, 0xf2, 0xf3, 0xb3, 0x4a, 0xb3, + 0x7e, 0x7e, 0x74, 0xde, 0xa8, 0x37, 0x1b, 0x67, 0xf5, 0x17, 0x27, 0xc7, 0xd5, 0xd3, 0xea, 0x49, + 0xa5, 0x68, 0xd8, 0x1b, 0xc3, 0x91, 0xbb, 0xd6, 0xe0, 0xb2, 0x4b, 0x23, 0xf6, 0x9a, 0x51, 0x82, + 0x1e, 0xc0, 0xad, 0xdf, 0xd1, 0xb3, 0xe8, 0xa4, 0x52, 0x04, 0xf6, 0xfa, 0x70, 0xe4, 0xae, 0x34, + 0x78, 0x28, 0x38, 0xa1, 0x04, 0x79, 0xf0, 0xce, 0x9f, 0xb8, 0xea, 0xd9, 0xd3, 0x62, 0xc1, 0xfe, + 0x6f, 0x38, 0x72, 0x57, 0x53, 0x20, 0xe3, 0x2d, 0xb4, 0x0b, 0xd1, 0x3c, 0x32, 0xd3, 0x5b, 0xb0, + 0xe1, 0x70, 0xe4, 0x9a, 0x65, 0xad, 0x66, 0x2f, 0xbe, 0x7b, 0xef, 0x18, 0xe5, 0xf6, 0xf8, 0x9b, + 0x63, 0x5c, 0x4d, 0x1c, 0x63, 0x3c, 0x71, 0xc0, 0xcd, 0xc4, 0x01, 0x5f, 0x27, 0x0e, 0xb8, 0x9c, + 0x3a, 0xc6, 0xcd, 0xd4, 0x31, 0x3e, 0x4d, 0x1d, 0xe3, 0xd5, 0xe9, 0xdc, 0x2a, 0x65, 0xf3, 0x2c, + 0x75, 0x70, 0x98, 0x3e, 0xad, 0x52, 0x3e, 0x55, 0xbd, 0x57, 0x6f, 0x6f, 0x7f, 0x6e, 0x7a, 0xdd, + 0x42, 0x53, 0x6f, 0xfd, 0xe1, 0x8f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x27, 0x08, 0xab, 0x24, 0x9b, + 0x03, 0x00, 0x00, +} + +func (m *Depositors) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Depositors) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Depositors) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Tokens) > 0 { + for iNdEx := len(m.Tokens) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Tokens[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDelegate(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintDelegate(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Intermediary) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Intermediary) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Intermediary) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Token != nil { + { + size, err := m.Token.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDelegate(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + } + if m.Status != 0 { + i = encodeVarintDelegate(dAtA, i, uint64(m.Status)) + i-- + dAtA[i] = 0x30 + } + if m.Tombstoned { + i-- + if m.Tombstoned { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x28 + } + if m.Jailed { + i-- + if m.Jailed { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x20 + } + if len(m.ContractAddress) > 0 { + i -= len(m.ContractAddress) + copy(dAtA[i:], m.ContractAddress) + i = encodeVarintDelegate(dAtA, i, uint64(len(m.ContractAddress))) + i-- + dAtA[i] = 0x1a + } + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintDelegate(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0x12 + } + if len(m.ConsumerValidator) > 0 { + i -= len(m.ConsumerValidator) + copy(dAtA[i:], m.ConsumerValidator) + i = encodeVarintDelegate(dAtA, i, uint64(len(m.ConsumerValidator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintDelegate(dAtA []byte, offset int, v uint64) int { + offset -= sovDelegate(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Depositors) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovDelegate(uint64(l)) + } + if len(m.Tokens) > 0 { + for _, e := range m.Tokens { + l = e.Size() + n += 1 + l + sovDelegate(uint64(l)) + } + } + return n +} + +func (m *Intermediary) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ConsumerValidator) + if l > 0 { + n += 1 + l + sovDelegate(uint64(l)) + } + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovDelegate(uint64(l)) + } + l = len(m.ContractAddress) + if l > 0 { + n += 1 + l + sovDelegate(uint64(l)) + } + if m.Jailed { + n += 2 + } + if m.Tombstoned { + n += 2 + } + if m.Status != 0 { + n += 1 + sovDelegate(uint64(m.Status)) + } + if m.Token != nil { + l = m.Token.Size() + n += 1 + l + sovDelegate(uint64(l)) + } + return n +} + +func sovDelegate(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozDelegate(x uint64) (n int) { + return sovDelegate(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Depositors) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDelegate + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: Depositors: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Depositors: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDelegate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDelegate + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDelegate + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Tokens", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDelegate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDelegate + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDelegate + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Tokens = append(m.Tokens, types.Coin{}) + if err := m.Tokens[len(m.Tokens)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDelegate(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDelegate + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Intermediary) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDelegate + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: Intermediary: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Intermediary: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsumerValidator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDelegate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDelegate + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDelegate + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConsumerValidator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDelegate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDelegate + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDelegate + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ContractAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDelegate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDelegate + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDelegate + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ContractAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Jailed", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDelegate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Jailed = bool(v != 0) + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Tombstoned", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDelegate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Tombstoned = bool(v != 0) + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) + } + m.Status = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDelegate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Status |= BondStatus(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Token", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDelegate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDelegate + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDelegate + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Token == nil { + m.Token = &types.Coin{} + } + if err := m.Token.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDelegate(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDelegate + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipDelegate(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDelegate + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDelegate + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDelegate + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthDelegate + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupDelegate + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthDelegate + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthDelegate = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowDelegate = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupDelegate = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/meshsecurityprovider/types/errors.go b/x/meshsecurityprovider/types/errors.go new file mode 100644 index 00000000..2f243544 --- /dev/null +++ b/x/meshsecurityprovider/types/errors.go @@ -0,0 +1,13 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" +) + +var ( + ErrInvalid = errorsmod.Register(ModuleName, 1, "invalid") + ErrInvalidConsumerClient = errorsmod.Register(ModuleName, 16, "ccv channel is not built on correct client") + ErrConsumerChainNotFound = errorsmod.Register(ModuleName, 18, "consumer chain not found") + ErrUnknownConsumerChannelId = errorsmod.Register(ModuleName, 4, "no consumer chain with this channel id") + ErrUnknownConsumerChainId = errorsmod.Register(ModuleName, 3, "no consumer chain with this chain id") +) diff --git a/x/meshsecurityprovider/types/events.go b/x/meshsecurityprovider/types/events.go new file mode 100644 index 00000000..6024d0d6 --- /dev/null +++ b/x/meshsecurityprovider/types/events.go @@ -0,0 +1,26 @@ +package types + +// Provider events +const ( + EventTypeDelegate = "delegate" + EventTypeConsumerClientCreated = "consumer_client_created" + EventTypeAssignConsumerKey = "assign_consumer_key" + EventTypeAddConsumerRewardDenom = "add_consumer_reward_denom" + EventTypeRemoveConsumerRewardDenom = "remove_consumer_reward_denom" + EventTypeExecuteConsumerChainSlash = "execute_consumer_chain_slash" + EventTypeSetConsumerCommissionRate = "set_consumer_commission_rate" + EventTypeOptIn = "opt_in" + EventTypeOptOut = "opt_out" + AttributeInfractionHeight = "infraction_height" + AttributeInitialHeight = "initial_height" + AttributeInitializationTimeout = "initialization_timeout" + AttributeTrustingPeriod = "trusting_period" + AttributeUnbondingPeriod = "unbonding_period" + AttributeProviderValidatorAddress = "provider_validator_address" + AttributeConsumerConsensusPubKey = "consumer_consensus_pub_key" + AttributeConsumerRewardDenom = "consumer_reward_denom" + AttributeConsumerCommissionRate = "consumer_commission_rate" + AttributeConsumerChainID = "consumer_chain_id" + AttributeConsumerValidator = "consumer_validator" + AttributeKeyNewShares = "new_shares" +) diff --git a/x/meshsecurityprovider/types/expected_keepers.go b/x/meshsecurityprovider/types/expected_keepers.go new file mode 100644 index 00000000..6c849257 --- /dev/null +++ b/x/meshsecurityprovider/types/expected_keepers.go @@ -0,0 +1,107 @@ +package types + +import ( + "time" + + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + // transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + conntypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" +) + +type BankKeeper interface { + GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin + SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error + MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error + BurnCoins(ctx sdk.Context, moduleName string, amounts sdk.Coins) error + + SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error + SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + UndelegateCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + DelegateCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error +} + +// SDKStakingKeeper expected staking keeper. +type StakingKeeper interface { + BondDenom(ctx sdk.Context) string + GetAllValidators(ctx sdk.Context) (validators []stakingtypes.Validator) + GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, found bool) + ValidateUnbondAmount(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt math.Int) (shares sdk.Dec, err error) + Delegate(ctx sdk.Context, delAddr sdk.AccAddress, bondAmt math.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) + UnbondingTime(ctx sdk.Context) time.Duration + GetParams(ctx sdk.Context) stakingtypes.Params + Unbond(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, shares sdk.Dec) (amount math.Int, err error) + IterateBondedValidatorsByPower(ctx sdk.Context, fn func(int64, stakingtypes.ValidatorI) bool) + TotalBondedTokens(ctx sdk.Context) math.Int + IterateDelegations(ctx sdk.Context, delegator sdk.AccAddress, fn func(int64, stakingtypes.DelegationI) bool) + GetValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) (stakingtypes.Validator, bool) + MinCommissionRate(ctx sdk.Context) math.LegacyDec +} + +// CommunityPoolKeeper expected distribution keeper. +type CommunityPoolKeeper interface { + WithdrawDelegationRewards(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Coins, error) +} + +// AccountKeeper interface contains functions for getting accounts and the module address +type AccountKeeper interface { + GetModuleAddress(name string) sdk.AccAddress + GetModuleAccount(ctx sdk.Context, name string) authtypes.ModuleAccountI +} + +// WasmKeeper abstract wasm keeper +type WasmKeeper interface { + Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) + HasContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) bool +} + +// ChannelKeeper defines the expected IBC channel keeper +type ChannelKeeper interface { + GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) + GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) + SendPacket( + ctx sdk.Context, + chanCap *capabilitytypes.Capability, + sourcePort string, + sourceChannel string, + timeoutHeight clienttypes.Height, + timeoutTimestamp uint64, + data []byte, + ) (sequence uint64, err error) + WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error + ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error + GetChannelConnection(ctx sdk.Context, portID, channelID string) (string, ibcexported.ConnectionI, error) +} + +type ScopedKeeper interface { + GetCapability(ctx sdk.Context, name string) (*capabilitytypes.Capability, bool) + AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool + ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error +} + +// ConnectionKeeper defines the expected IBC connection keeper +type ConnectionKeeper interface { + GetConnection(ctx sdk.Context, connectionID string) (conntypes.ConnectionEnd, bool) +} + +// ClientKeeper defines the expected IBC client keeper +type ClientKeeper interface { + CreateClient(ctx sdk.Context, clientState ibcexported.ClientState, consensusState ibcexported.ConsensusState) (string, error) + GetClientState(ctx sdk.Context, clientID string) (ibcexported.ClientState, bool) + GetLatestClientConsensusState(ctx sdk.Context, clientID string) (ibcexported.ConsensusState, bool) + GetSelfConsensusState(ctx sdk.Context, height ibcexported.Height) (ibcexported.ConsensusState, error) + ClientStore(ctx sdk.Context, clientID string) sdk.KVStore + SetClientState(ctx sdk.Context, clientID string, clientState ibcexported.ClientState) + GetClientConsensusState(ctx sdk.Context, clientID string, height ibcexported.Height) (ibcexported.ConsensusState, bool) +} diff --git a/x/meshsecurityprovider/types/genesis.go b/x/meshsecurityprovider/types/genesis.go new file mode 100644 index 00000000..d8a4275d --- /dev/null +++ b/x/meshsecurityprovider/types/genesis.go @@ -0,0 +1,18 @@ +package types + +// NewGenesisState constructor +func NewGenesisState(params Params) *GenesisState { + return &GenesisState{ + Params: params, + } +} + +// DefaultGenesisState default genesis state +func DefaultGenesisState(denom string) *GenesisState { + return NewGenesisState(DefaultParams(denom)) +} + +// ValidateGenesis does basic validation on genesis state +func ValidateGenesis(gs *GenesisState) error { + return gs.Params.ValidateBasic() +} diff --git a/x/meshsecurityprovider/types/genesis.pb.go b/x/meshsecurityprovider/types/genesis.pb.go new file mode 100644 index 00000000..6e72cf54 --- /dev/null +++ b/x/meshsecurityprovider/types/genesis.pb.go @@ -0,0 +1,344 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: osmosis/meshsecurityprovider/v1beta1/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines meshsecurity module's genesis state. +type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_555788d51f2b67d4, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func init() { + proto.RegisterType((*GenesisState)(nil), "osmosis.meshsecurityprovider.v1beta1.GenesisState") +} + +func init() { + proto.RegisterFile("osmosis/meshsecurityprovider/v1beta1/genesis.proto", fileDescriptor_555788d51f2b67d4) +} + +var fileDescriptor_555788d51f2b67d4 = []byte{ + // 255 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0xca, 0x2f, 0xce, 0xcd, + 0x2f, 0xce, 0x2c, 0xd6, 0xcf, 0x4d, 0x2d, 0xce, 0x28, 0x4e, 0x4d, 0x2e, 0x2d, 0xca, 0x2c, 0xa9, + 0x2c, 0x28, 0xca, 0x2f, 0xcb, 0x4c, 0x49, 0x2d, 0xd2, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, + 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, + 0x81, 0xea, 0xd1, 0xc3, 0xa6, 0x47, 0x0f, 0xaa, 0x47, 0xca, 0x90, 0x28, 0x93, 0x0b, 0x12, 0x8b, + 0x12, 0x73, 0xa1, 0x06, 0x4b, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x99, 0xfa, 0x20, 0x16, 0x54, + 0x54, 0x30, 0x31, 0x37, 0x33, 0x2f, 0x5f, 0x1f, 0x4c, 0x42, 0x84, 0x94, 0x52, 0xb9, 0x78, 0xdc, + 0x21, 0x4e, 0x0a, 0x2e, 0x49, 0x2c, 0x49, 0x15, 0xf2, 0xe7, 0x62, 0x83, 0x18, 0x24, 0xc1, 0xa8, + 0xc0, 0xa8, 0xc1, 0x6d, 0xa4, 0xa3, 0x47, 0x8c, 0x13, 0xf5, 0x02, 0xc0, 0x7a, 0x9c, 0x38, 0x4f, + 0xdc, 0x93, 0x67, 0x58, 0xf1, 0x7c, 0x83, 0x16, 0x63, 0x10, 0xd4, 0x18, 0x2b, 0x96, 0x17, 0x0b, + 0xe4, 0x19, 0x9d, 0x32, 0x4e, 0x3c, 0x94, 0x63, 0x58, 0xf1, 0x48, 0x8e, 0xe1, 0xc4, 0x23, 0x39, + 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, + 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xdc, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, + 0xf3, 0x73, 0xf5, 0xa1, 0x56, 0xea, 0xe6, 0x24, 0x26, 0x41, 0x3c, 0xad, 0x0b, 0xb3, 0x58, 0xb7, + 0x38, 0x25, 0x5b, 0xbf, 0x02, 0x7b, 0x40, 0x94, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0xfd, + 0x65, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xa4, 0xc2, 0x57, 0x54, 0x8f, 0x01, 0x00, 0x00, +} + +func (this *GenesisState) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*GenesisState) + if !ok { + that2, ok := that.(GenesisState) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.Params.Equal(&that1.Params) { + return false + } + return true +} +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/meshsecurityprovider/types/keys.go b/x/meshsecurityprovider/types/keys.go new file mode 100644 index 00000000..d42c6286 --- /dev/null +++ b/x/meshsecurityprovider/types/keys.go @@ -0,0 +1,74 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + // ModuleName defines the module name. + ModuleName = "meshsecurity-provider" + // RouterKey is the message route + RouterKey = ModuleName + // StoreKey defines the primary module store key. + StoreKey = ModuleName + // MemStoreKey defines the in-memory store key + MemStoreKey = "memory:meshsecurity-provider" +) + +var ( + ChainToChannelBytePrefix = []byte{0x10} + ChannelToChainBytePrefix = []byte{0x2} + InitChainHeightBytePrefix = []byte{0x3} + InitTimeoutTimestampBytePrefix = []byte{0x4} + ChainToClientBytePrefix = []byte{0x5} + ConsumerCommissionRatePrefix = []byte{0x6} + ParamsKey = []byte{0x7} + DepositorsKeyPrefix = []byte{0x8} + ContractWithNativeDenomPrefix = []byte{0x9} + IntermediaryKeyPrefix = []byte{0x11} +) + +func ChainToChannelKey(chainID string) []byte { + return append(ChainToChannelBytePrefix, []byte(chainID)...) +} + +func ChannelToChainKey(channelID string) []byte { + return append(ChannelToChainBytePrefix, []byte(channelID)...) +} + +func InitChainHeightKey(chainID string) []byte { + return append(InitChainHeightBytePrefix, []byte(chainID)...) +} + +func InitTimeoutTimestampKey(chainID string) []byte { + return append(InitTimeoutTimestampBytePrefix, []byte(chainID)...) +} + +func ChainToClientKey(chainID string) []byte { + return append(ChainToClientBytePrefix, []byte(chainID)...) +} + +func ConsumerCommissionRateKey(chainID string, providerAddr ProviderConsAddress) []byte { + return append(append(ConsumerCommissionRatePrefix, []byte(chainID)...), providerAddr.Address...) +} + +func DepositorsKey(del string) []byte { + return append(DepositorsKeyPrefix, []byte(del)...) +} + +func ContractWithNativeDenomKey(denom string) []byte { + return append(ContractWithNativeDenomPrefix, []byte(denom)...) +} +func IntermediaryKey(denom string) []byte { + return append(IntermediaryKeyPrefix, []byte(denom)...) +} + +type ProviderConsAddress struct { + Address sdk.ConsAddress +} + +func NewProviderConsAddress(addr sdk.ConsAddress) ProviderConsAddress { + return ProviderConsAddress{ + Address: addr, + } +} diff --git a/x/meshsecurityprovider/types/params.go b/x/meshsecurityprovider/types/params.go new file mode 100644 index 00000000..0e844c3e --- /dev/null +++ b/x/meshsecurityprovider/types/params.go @@ -0,0 +1,30 @@ +package types + +import sdk "github.com/cosmos/cosmos-sdk/types" + +// DefaultParams returns default mesh-security parameters +func DefaultParams(denom string) Params { + return Params{ // todo: revisit and set proper defaults + TimeoutPeriod: 60, + VaultContractAddress: "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", + } +} + +// ValidateBasic performs basic validation on mesh-security parameters. +func (p Params) ValidateBasic() error { + if p.TimeoutPeriod <= 0 { + return ErrInvalid.Wrap("empty max gas end-blocker setting") + } + if p.VaultContractAddress == "" { + return ErrInvalid.Wrap("vault contract address cannot be empty") + } + return nil +} + +func (p Params) GetVaultContractAddress() sdk.AccAddress { + vaultContractAddress, err := sdk.AccAddressFromBech32(p.VaultContractAddress) + if err != nil { + panic("params error: VaultContractAddress") + } + return vaultContractAddress +} diff --git a/x/meshsecurityprovider/types/params.pb.go b/x/meshsecurityprovider/types/params.pb.go new file mode 100644 index 00000000..7e361c73 --- /dev/null +++ b/x/meshsecurityprovider/types/params.pb.go @@ -0,0 +1,378 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: osmosis/meshsecurityprovider/v1beta1/params.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Params defines the parameters for the x/meshsecurity module. +type Params struct { + // TimeoutPeriod has the unit time.Millisecond + TimeoutPeriod uint64 `protobuf:"varint,1,opt,name=timeout_period,json=timeoutPeriod,proto3" json:"timeout_period,omitempty"` + VaultContractAddress string `protobuf:"bytes,2,opt,name=vault_contract_address,json=vaultContractAddress,proto3" json:"vault_contract_address,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_6d51515613408cf3, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Params)(nil), "osmosis.meshsecurityprovider.v1beta1.Params") +} + +func init() { + proto.RegisterFile("osmosis/meshsecurityprovider/v1beta1/params.proto", fileDescriptor_6d51515613408cf3) +} + +var fileDescriptor_6d51515613408cf3 = []byte{ + // 302 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0x31, 0x4b, 0xfc, 0x30, + 0x18, 0xc6, 0x9b, 0x3f, 0x7f, 0x0e, 0x2c, 0x28, 0x78, 0x1c, 0x72, 0x9c, 0x10, 0x0f, 0x39, 0xe1, + 0x10, 0xda, 0x50, 0x74, 0x72, 0x53, 0xc1, 0xf9, 0xb8, 0xd1, 0xa5, 0xa4, 0x69, 0x68, 0x83, 0x97, + 0xbe, 0x25, 0x49, 0x8b, 0xf7, 0x15, 0x74, 0xf1, 0x23, 0x38, 0x3a, 0xfa, 0x31, 0x6e, 0xbc, 0xd1, + 0x51, 0xdb, 0x41, 0x3f, 0x86, 0x98, 0x46, 0xa7, 0x2e, 0xe1, 0xe5, 0x79, 0xf2, 0x3c, 0xc9, 0xfb, + 0xf3, 0x23, 0xd0, 0x12, 0xb4, 0xd0, 0x44, 0x72, 0x9d, 0x6b, 0xce, 0x2a, 0x25, 0xcc, 0xba, 0x54, + 0x50, 0x8b, 0x94, 0x2b, 0x52, 0x47, 0x09, 0x37, 0x34, 0x22, 0x25, 0x55, 0x54, 0xea, 0xb0, 0x54, + 0x60, 0x60, 0x38, 0x73, 0x91, 0xb0, 0x2f, 0x12, 0xba, 0xc8, 0x04, 0x33, 0x7b, 0x8d, 0x24, 0x54, + 0xf3, 0xbf, 0x1e, 0x06, 0xa2, 0xe8, 0x5a, 0x26, 0xa3, 0x0c, 0x32, 0xb0, 0x23, 0xf9, 0x99, 0x9c, + 0xba, 0x4f, 0xa5, 0x28, 0x80, 0xd8, 0xb3, 0x93, 0x8e, 0x1f, 0x91, 0x3f, 0x58, 0xd8, 0xf7, 0x87, + 0x27, 0xfe, 0x9e, 0x11, 0x92, 0x43, 0x65, 0xe2, 0x92, 0x2b, 0x01, 0xe9, 0x18, 0x4d, 0xd1, 0xfc, + 0xff, 0x72, 0xd7, 0xa9, 0x0b, 0x2b, 0x0e, 0xcf, 0xfd, 0x83, 0x9a, 0x56, 0x2b, 0x13, 0x33, 0x28, + 0x8c, 0xa2, 0xcc, 0xc4, 0x34, 0x4d, 0x15, 0xd7, 0x7a, 0xfc, 0x6f, 0x8a, 0xe6, 0x3b, 0xcb, 0x91, + 0x75, 0xaf, 0x9d, 0x79, 0xd9, 0x79, 0x17, 0xb3, 0xaf, 0xe7, 0x23, 0xf4, 0xf0, 0xf9, 0x7a, 0x7a, + 0xd8, 0x8b, 0xa2, 0xfb, 0xc2, 0x55, 0xbe, 0xf9, 0xc0, 0xde, 0x4b, 0x83, 0xbd, 0x4d, 0x83, 0xd1, + 0xb6, 0xc1, 0xe8, 0xbd, 0xc1, 0xe8, 0xa9, 0xc5, 0xde, 0xb6, 0xc5, 0xde, 0x5b, 0x8b, 0xbd, 0xdb, + 0x9b, 0x4c, 0x98, 0xbc, 0x4a, 0x42, 0x06, 0x92, 0x38, 0x52, 0xc1, 0x8a, 0x26, 0x1d, 0xe1, 0xe0, + 0xb7, 0x37, 0xd0, 0xe9, 0x1d, 0xb9, 0xef, 0xa7, 0x6e, 0xd6, 0x25, 0xd7, 0xc9, 0xc0, 0xae, 0x7f, + 0xf6, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x34, 0x89, 0x55, 0x25, 0xa2, 0x01, 0x00, 0x00, +} + +func (this *Params) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Params) + if !ok { + that2, ok := that.(Params) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.TimeoutPeriod != that1.TimeoutPeriod { + return false + } + if this.VaultContractAddress != that1.VaultContractAddress { + return false + } + return true +} +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.VaultContractAddress) > 0 { + i -= len(m.VaultContractAddress) + copy(dAtA[i:], m.VaultContractAddress) + i = encodeVarintParams(dAtA, i, uint64(len(m.VaultContractAddress))) + i-- + dAtA[i] = 0x12 + } + if m.TimeoutPeriod != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.TimeoutPeriod)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.TimeoutPeriod != 0 { + n += 1 + sovParams(uint64(m.TimeoutPeriod)) + } + l = len(m.VaultContractAddress) + if l > 0 { + n += 1 + l + sovParams(uint64(l)) + } + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeoutPeriod", wireType) + } + m.TimeoutPeriod = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TimeoutPeriod |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VaultContractAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.VaultContractAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/meshsecurityprovider/types/query.pb.go b/x/meshsecurityprovider/types/query.pb.go new file mode 100644 index 00000000..fe6f9118 --- /dev/null +++ b/x/meshsecurityprovider/types/query.pb.go @@ -0,0 +1,537 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: osmosis/meshsecurityprovider/v1beta1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryParamsRequest is the request type for the +// Query/Params RPC method +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9fa24ab7f9d99b32, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is the response type for the +// Query/Params RPC method +type QueryParamsResponse struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_9fa24ab7f9d99b32, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "osmosis.meshsecurityprovider.v1beta1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "osmosis.meshsecurityprovider.v1beta1.QueryParamsResponse") +} + +func init() { + proto.RegisterFile("osmosis/meshsecurityprovider/v1beta1/query.proto", fileDescriptor_9fa24ab7f9d99b32) +} + +var fileDescriptor_9fa24ab7f9d99b32 = []byte{ + // 344 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x91, 0xb1, 0x4a, 0x33, 0x41, + 0x10, 0xc7, 0x6f, 0x3f, 0xf8, 0x02, 0x9e, 0x95, 0x67, 0x0a, 0x09, 0xb2, 0x4a, 0xb0, 0x10, 0x49, + 0x76, 0x4d, 0xb4, 0xd0, 0x36, 0x85, 0xad, 0x9a, 0xd2, 0x6e, 0xef, 0xb2, 0x5e, 0x16, 0x73, 0x37, + 0x97, 0x9b, 0xbd, 0x60, 0x5a, 0x9f, 0x40, 0xf0, 0x25, 0x52, 0x0a, 0xd6, 0xf6, 0x29, 0x03, 0x36, + 0x56, 0xa2, 0x17, 0xc1, 0xd7, 0x90, 0xec, 0x5e, 0x04, 0x31, 0x45, 0xb4, 0x59, 0x96, 0x61, 0x7e, + 0xbf, 0x99, 0x3f, 0xe3, 0xee, 0x03, 0x46, 0x80, 0x0a, 0x79, 0x24, 0xb1, 0x8b, 0x32, 0xc8, 0x52, + 0xa5, 0x87, 0x49, 0x0a, 0x03, 0xd5, 0x91, 0x29, 0x1f, 0x34, 0x7c, 0xa9, 0x45, 0x83, 0xf7, 0x33, + 0x99, 0x0e, 0x59, 0x92, 0x82, 0x06, 0x6f, 0xa7, 0x20, 0xd8, 0x22, 0x82, 0x15, 0x44, 0x85, 0x06, + 0xa6, 0x8d, 0xfb, 0x02, 0xe5, 0x97, 0x26, 0x00, 0x15, 0x5b, 0x4b, 0xa5, 0xb1, 0xd4, 0xdc, 0x44, + 0xa4, 0x22, 0xc2, 0x02, 0x29, 0x87, 0x10, 0x82, 0xf9, 0xf2, 0xd9, 0xaf, 0xa8, 0x6e, 0x86, 0x00, + 0x61, 0x4f, 0x72, 0x91, 0x28, 0x2e, 0xe2, 0x18, 0xb4, 0xd0, 0x0a, 0xe2, 0x39, 0xb3, 0x26, 0x22, + 0x15, 0x03, 0x37, 0xaf, 0x2d, 0x55, 0xcb, 0xae, 0x77, 0x3e, 0x8b, 0x73, 0x66, 0xdc, 0x6d, 0xd9, + 0xcf, 0x24, 0xea, 0xea, 0xa5, 0xbb, 0xfe, 0xad, 0x8a, 0x09, 0xc4, 0x28, 0xbd, 0x53, 0xb7, 0x64, + 0x77, 0xd8, 0x20, 0xdb, 0x64, 0x77, 0xb5, 0x59, 0x63, 0xcb, 0xa4, 0x67, 0xd6, 0xd2, 0x5a, 0x19, + 0xbf, 0x6c, 0x39, 0xa3, 0x8f, 0xfb, 0x3d, 0xd2, 0x2e, 0x34, 0xcd, 0x47, 0xe2, 0xfe, 0x37, 0x83, + 0xbc, 0x07, 0xe2, 0x96, 0x6c, 0x9f, 0x77, 0xb4, 0x9c, 0xf5, 0xe7, 0xda, 0x95, 0xe3, 0x3f, 0x90, + 0x36, 0x5a, 0xf5, 0xf0, 0xe6, 0xe9, 0xfd, 0xee, 0x1f, 0xf3, 0x6a, 0xfc, 0x17, 0xa7, 0x68, 0x75, + 0xc7, 0x6f, 0xd4, 0x19, 0xe5, 0xd4, 0x19, 0xe7, 0x94, 0x4c, 0x72, 0x4a, 0x5e, 0x73, 0x4a, 0x6e, + 0xa7, 0xd4, 0x99, 0x4c, 0xa9, 0xf3, 0x3c, 0xa5, 0xce, 0xc5, 0x49, 0xa8, 0x74, 0x37, 0xf3, 0x59, + 0x00, 0xd1, 0xdc, 0x5c, 0xef, 0x09, 0xdf, 0xea, 0xeb, 0x73, 0x7f, 0x1d, 0x3b, 0x57, 0xfc, 0x7a, + 0xf1, 0x48, 0x3d, 0x4c, 0x24, 0xfa, 0x25, 0x73, 0xae, 0x83, 0xcf, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x4d, 0xfa, 0xb2, 0xe9, 0xa2, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Params queries the parameters of x/meshsecurity module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/osmosis.meshsecurityprovider.v1beta1.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Params queries the parameters of x/meshsecurity module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/osmosis.meshsecurityprovider.v1beta1.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "osmosis.meshsecurityprovider.v1beta1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "osmosis/meshsecurityprovider/v1beta1/query.proto", +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/meshsecurityprovider/types/query.pb.gw.go b/x/meshsecurityprovider/types/query.pb.gw.go new file mode 100644 index 00000000..9ae45777 --- /dev/null +++ b/x/meshsecurityprovider/types/query.pb.gw.go @@ -0,0 +1,153 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: osmosis/meshsecurityprovider/v1beta1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"osmosis", "meshsecurityprovider", "v1beta1", "params"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage +) diff --git a/x/meshsecurityprovider/types/tx.go b/x/meshsecurityprovider/types/tx.go new file mode 100644 index 00000000..cb15b5f9 --- /dev/null +++ b/x/meshsecurityprovider/types/tx.go @@ -0,0 +1,121 @@ +package types + +import ( + "strings" + + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) *MsgDelegate { + return &MsgDelegate{ + DelegatorAddress: delAddr.String(), + ValidatorAddress: valAddr.String(), + Amount: amount, + } +} + +// GetSignBytes implements the LegacyMsg interface. +func (msg MsgDelegate) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +// GetSigners returns the expected signers for MsgSoftwareUpgrade. +func (msg MsgDelegate) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) + return []sdk.AccAddress{addr} +} + +// ValidateBasic validate basic constraints +func (msg MsgDelegate) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.DelegatorAddress); err != nil { + return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", err) + } + if _, err := sdk.ValAddressFromBech32(msg.ValidatorAddress); err != nil { + return errorsmod.Wrap(err, "contract") + } + if err := msg.Amount.Validate(); err != nil { + return errorsmod.Wrap(err, "max cap") + } + return nil +} + +func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) *MsgUndelegate { + return &MsgUndelegate{ + DelegatorAddress: delAddr.String(), + ValidatorAddress: valAddr.String(), + Amount: amount, + } +} + +// GetSignBytes implements the LegacyMsg interface. +func (msg MsgUndelegate) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +// GetSigners returns the expected signers for MsgSoftwareUpgrade. +func (msg MsgUndelegate) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) + return []sdk.AccAddress{addr} +} + +// ValidateBasic validate basic constraints +func (msg MsgUndelegate) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.DelegatorAddress); err != nil { + return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", err) + } + if _, err := sdk.ValAddressFromBech32(msg.ValidatorAddress); err != nil { + return errorsmod.Wrap(err, "contract") + } + if err := msg.Amount.Validate(); err != nil { + return errorsmod.Wrap(err, "max cap") + } + return nil +} + +// NewMsgSetConsumerCommissionRate creates a new MsgSetConsumerCommissionRate msg instance. +func NewMsgSetConsumerCommissionRate(chainID string, commission sdk.Dec, providerValidatorAddress sdk.ValAddress) *MsgSetConsumerCommissionRate { + return &MsgSetConsumerCommissionRate{ + ChainId: chainID, + Rate: commission, + ProviderAddr: providerValidatorAddress.String(), + } +} + +// GetSignBytes implements the LegacyMsg interface. +func (msg MsgSetConsumerCommissionRate) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +// GetSigners returns the expected signers for MsgSoftwareUpgrade. +func (msg MsgSetConsumerCommissionRate) GetSigners() []sdk.AccAddress { + valAddr, err := sdk.ValAddressFromBech32(msg.ProviderAddr) + if err != nil { + // same behavior as in cosmos-sdk + panic(err) + } + return []sdk.AccAddress{valAddr.Bytes()} +} + +// ValidateBasic validate basic constraints +func (msg MsgSetConsumerCommissionRate) ValidateBasic() error { + if strings.TrimSpace(msg.ChainId) == "" { + panic("chainId cannot be blank") + } + + if 128 < len(msg.ChainId) { + panic("chainId cannot exceed 128 length") + } + _, err := sdk.ValAddressFromBech32(msg.ProviderAddr) + if err != nil { + panic(err) + } + + if msg.Rate.IsNegative() || msg.Rate.GT(sdk.OneDec()) { + panic("consumer commission rate should be in the range [0, 1]") + } + + return nil +} diff --git a/x/meshsecurityprovider/types/tx.pb.go b/x/meshsecurityprovider/types/tx.pb.go new file mode 100644 index 00000000..568d5f68 --- /dev/null +++ b/x/meshsecurityprovider/types/tx.pb.go @@ -0,0 +1,1454 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: osmosis/meshsecurityprovider/v1beta1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type MsgDelegate struct { + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` + ValidatorAddress string `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + Amount types.Coin `protobuf:"bytes,3,opt,name=amount,proto3" json:"amount"` +} + +func (m *MsgDelegate) Reset() { *m = MsgDelegate{} } +func (m *MsgDelegate) String() string { return proto.CompactTextString(m) } +func (*MsgDelegate) ProtoMessage() {} +func (*MsgDelegate) Descriptor() ([]byte, []int) { + return fileDescriptor_05534c9e44219747, []int{0} +} +func (m *MsgDelegate) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDelegate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDelegate.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgDelegate) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDelegate.Merge(m, src) +} +func (m *MsgDelegate) XXX_Size() int { + return m.Size() +} +func (m *MsgDelegate) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDelegate.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDelegate proto.InternalMessageInfo + +type MsgDelegateResponse struct { +} + +func (m *MsgDelegateResponse) Reset() { *m = MsgDelegateResponse{} } +func (m *MsgDelegateResponse) String() string { return proto.CompactTextString(m) } +func (*MsgDelegateResponse) ProtoMessage() {} +func (*MsgDelegateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_05534c9e44219747, []int{1} +} +func (m *MsgDelegateResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDelegateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDelegateResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgDelegateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDelegateResponse.Merge(m, src) +} +func (m *MsgDelegateResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgDelegateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDelegateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDelegateResponse proto.InternalMessageInfo + +type MsgUndelegate struct { + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` + ValidatorAddress string `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + Amount types.Coin `protobuf:"bytes,3,opt,name=amount,proto3" json:"amount"` +} + +func (m *MsgUndelegate) Reset() { *m = MsgUndelegate{} } +func (m *MsgUndelegate) String() string { return proto.CompactTextString(m) } +func (*MsgUndelegate) ProtoMessage() {} +func (*MsgUndelegate) Descriptor() ([]byte, []int) { + return fileDescriptor_05534c9e44219747, []int{2} +} +func (m *MsgUndelegate) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUndelegate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUndelegate.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUndelegate) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUndelegate.Merge(m, src) +} +func (m *MsgUndelegate) XXX_Size() int { + return m.Size() +} +func (m *MsgUndelegate) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUndelegate.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUndelegate proto.InternalMessageInfo + +// MsgUndelegateResponse defines the Msg/Undelegate response type. +type MsgUndelegateResponse struct { +} + +func (m *MsgUndelegateResponse) Reset() { *m = MsgUndelegateResponse{} } +func (m *MsgUndelegateResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUndelegateResponse) ProtoMessage() {} +func (*MsgUndelegateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_05534c9e44219747, []int{3} +} +func (m *MsgUndelegateResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUndelegateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUndelegateResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUndelegateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUndelegateResponse.Merge(m, src) +} +func (m *MsgUndelegateResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUndelegateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUndelegateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUndelegateResponse proto.InternalMessageInfo + +type MsgSetConsumerCommissionRate struct { + ProviderAddr string `protobuf:"bytes,1,opt,name=provider_addr,json=providerAddr,proto3" json:"provider_addr,omitempty" yaml:"address"` + ChainId string `protobuf:"bytes,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + Rate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=rate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"rate"` +} + +func (m *MsgSetConsumerCommissionRate) Reset() { *m = MsgSetConsumerCommissionRate{} } +func (m *MsgSetConsumerCommissionRate) String() string { return proto.CompactTextString(m) } +func (*MsgSetConsumerCommissionRate) ProtoMessage() {} +func (*MsgSetConsumerCommissionRate) Descriptor() ([]byte, []int) { + return fileDescriptor_05534c9e44219747, []int{4} +} +func (m *MsgSetConsumerCommissionRate) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSetConsumerCommissionRate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSetConsumerCommissionRate.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgSetConsumerCommissionRate) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSetConsumerCommissionRate.Merge(m, src) +} +func (m *MsgSetConsumerCommissionRate) XXX_Size() int { + return m.Size() +} +func (m *MsgSetConsumerCommissionRate) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSetConsumerCommissionRate.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSetConsumerCommissionRate proto.InternalMessageInfo + +type MsgSetConsumerCommissionRateResponse struct { +} + +func (m *MsgSetConsumerCommissionRateResponse) Reset() { *m = MsgSetConsumerCommissionRateResponse{} } +func (m *MsgSetConsumerCommissionRateResponse) String() string { return proto.CompactTextString(m) } +func (*MsgSetConsumerCommissionRateResponse) ProtoMessage() {} +func (*MsgSetConsumerCommissionRateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_05534c9e44219747, []int{5} +} +func (m *MsgSetConsumerCommissionRateResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSetConsumerCommissionRateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSetConsumerCommissionRateResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgSetConsumerCommissionRateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSetConsumerCommissionRateResponse.Merge(m, src) +} +func (m *MsgSetConsumerCommissionRateResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgSetConsumerCommissionRateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSetConsumerCommissionRateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSetConsumerCommissionRateResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgDelegate)(nil), "osmosis.meshsecurityprovider.v1beta1.MsgDelegate") + proto.RegisterType((*MsgDelegateResponse)(nil), "osmosis.meshsecurityprovider.v1beta1.MsgDelegateResponse") + proto.RegisterType((*MsgUndelegate)(nil), "osmosis.meshsecurityprovider.v1beta1.MsgUndelegate") + proto.RegisterType((*MsgUndelegateResponse)(nil), "osmosis.meshsecurityprovider.v1beta1.MsgUndelegateResponse") + proto.RegisterType((*MsgSetConsumerCommissionRate)(nil), "osmosis.meshsecurityprovider.v1beta1.MsgSetConsumerCommissionRate") + proto.RegisterType((*MsgSetConsumerCommissionRateResponse)(nil), "osmosis.meshsecurityprovider.v1beta1.MsgSetConsumerCommissionRateResponse") +} + +func init() { + proto.RegisterFile("osmosis/meshsecurityprovider/v1beta1/tx.proto", fileDescriptor_05534c9e44219747) +} + +var fileDescriptor_05534c9e44219747 = []byte{ + // 583 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x54, 0xcf, 0x6b, 0x13, 0x41, + 0x14, 0xde, 0x31, 0x52, 0x93, 0xa9, 0x15, 0xbb, 0xb6, 0x34, 0x09, 0xb2, 0x29, 0xa1, 0x94, 0x22, + 0xec, 0x2e, 0x69, 0x0f, 0x62, 0xed, 0xc5, 0x24, 0x0a, 0x0a, 0x01, 0xd9, 0xe2, 0xc5, 0x4b, 0x98, + 0xec, 0x0e, 0x9b, 0xc1, 0xec, 0x4e, 0xd8, 0x37, 0x09, 0xc9, 0xc5, 0xb3, 0x47, 0xff, 0x84, 0x1e, + 0x05, 0x11, 0x3c, 0xf4, 0x8f, 0xc8, 0x49, 0x4a, 0x4f, 0xe2, 0x21, 0x68, 0x82, 0xe8, 0xd9, 0xbf, + 0x40, 0x76, 0x77, 0x76, 0xdd, 0x42, 0xab, 0x51, 0x6f, 0xbd, 0xec, 0xfc, 0x7a, 0xdf, 0x37, 0xef, + 0x7b, 0xfb, 0xcd, 0xc3, 0x3a, 0x07, 0x8f, 0x03, 0x03, 0xd3, 0xa3, 0xd0, 0x05, 0x6a, 0x0f, 0x02, + 0x26, 0xc6, 0xfd, 0x80, 0x0f, 0x99, 0x43, 0x03, 0x73, 0x58, 0xeb, 0x50, 0x41, 0x6a, 0xa6, 0x18, + 0x19, 0xfd, 0x80, 0x0b, 0xae, 0x6e, 0xc9, 0x70, 0xe3, 0xbc, 0x70, 0x43, 0x86, 0x97, 0x4b, 0x76, + 0x14, 0xd6, 0x8e, 0x30, 0x66, 0xbc, 0x88, 0x09, 0xca, 0x1b, 0xf1, 0xca, 0xf4, 0xc0, 0x35, 0x87, + 0xb5, 0x70, 0x90, 0x07, 0x6b, 0x2e, 0x77, 0x79, 0x0c, 0x08, 0x67, 0x72, 0x77, 0x95, 0x78, 0xcc, + 0xe7, 0x66, 0xf4, 0x95, 0x5b, 0x9a, 0x64, 0xe8, 0x10, 0xa0, 0x69, 0x82, 0x36, 0x67, 0x7e, 0x7c, + 0x5e, 0x9d, 0x23, 0xbc, 0xdc, 0x02, 0xb7, 0x49, 0x7b, 0xd4, 0x25, 0x82, 0xaa, 0x0f, 0xf1, 0xaa, + 0x13, 0xcf, 0x79, 0xd0, 0x26, 0x8e, 0x13, 0x50, 0x80, 0x22, 0xda, 0x44, 0x3b, 0x85, 0x7a, 0xf1, + 0xf4, 0x58, 0x5f, 0x93, 0xe9, 0x3d, 0x88, 0x4f, 0x0e, 0x45, 0xc0, 0x7c, 0xd7, 0xba, 0x99, 0x42, + 0xe4, 0x7e, 0x48, 0x33, 0x24, 0x3d, 0xe6, 0x9c, 0xa1, 0xb9, 0xf2, 0x27, 0x9a, 0x14, 0x92, 0xd0, + 0x1c, 0xe0, 0x25, 0xe2, 0xf1, 0x81, 0x2f, 0x8a, 0xb9, 0x4d, 0xb4, 0xb3, 0xbc, 0x5b, 0x32, 0x24, + 0x30, 0x94, 0x93, 0x14, 0xd0, 0x68, 0x70, 0xe6, 0xd7, 0x0b, 0x93, 0x69, 0x45, 0x79, 0xf3, 0xed, + 0xfd, 0x1d, 0x64, 0x49, 0xcc, 0x7e, 0xfe, 0xd5, 0x51, 0x45, 0xf9, 0x7e, 0x54, 0x51, 0xaa, 0xeb, + 0xf8, 0x56, 0x46, 0xa4, 0x45, 0xa1, 0xcf, 0x7d, 0xa0, 0xd5, 0xaf, 0x08, 0xaf, 0xb4, 0xc0, 0x7d, + 0xe6, 0x3b, 0x97, 0x5b, 0xfe, 0x06, 0x5e, 0x3f, 0x23, 0x33, 0x2d, 0xc0, 0x07, 0x84, 0x6f, 0xb7, + 0xc0, 0x3d, 0xa4, 0xa2, 0xc1, 0x7d, 0x18, 0x78, 0x34, 0x68, 0x70, 0xcf, 0x63, 0x00, 0x8c, 0xfb, + 0x56, 0x58, 0x8f, 0xbb, 0x78, 0x25, 0xf1, 0x6b, 0xa4, 0x43, 0xd6, 0x42, 0xfd, 0x31, 0xad, 0xdc, + 0x18, 0x13, 0xaf, 0xb7, 0x5f, 0x95, 0xea, 0xaa, 0xd6, 0xf5, 0x24, 0x30, 0xcc, 0x5e, 0x2d, 0xe1, + 0xbc, 0xdd, 0x25, 0xcc, 0x6f, 0x33, 0x27, 0x16, 0x6e, 0x5d, 0x8b, 0xd6, 0x8f, 0x1d, 0xf5, 0x29, + 0xbe, 0x1a, 0x10, 0x41, 0x23, 0x4d, 0x85, 0xfa, 0x41, 0x98, 0xf8, 0xa7, 0x69, 0x65, 0xdb, 0x65, + 0xa2, 0x3b, 0xe8, 0x18, 0x36, 0xf7, 0xe4, 0x1b, 0x90, 0x83, 0x0e, 0xce, 0x0b, 0x53, 0x8c, 0xfb, + 0x14, 0x8c, 0x26, 0xb5, 0x4f, 0x8f, 0x75, 0x2c, 0x8b, 0xd0, 0xa4, 0xb6, 0x15, 0x31, 0x65, 0x94, + 0x6e, 0xe3, 0xad, 0xdf, 0xe9, 0x49, 0x84, 0xef, 0xbe, 0xcb, 0xe1, 0x5c, 0x0b, 0x5c, 0x75, 0x84, + 0xf3, 0xa9, 0xf5, 0x6b, 0xc6, 0x22, 0xcf, 0xd5, 0xc8, 0x18, 0xa9, 0x7c, 0xef, 0xaf, 0x21, 0x49, + 0x06, 0xea, 0x4b, 0x8c, 0x33, 0xbe, 0xdb, 0x5b, 0x98, 0xe8, 0x17, 0xa8, 0x7c, 0xff, 0x1f, 0x40, + 0xe9, 0xfd, 0x6f, 0x11, 0x2e, 0x5d, 0xfc, 0xdf, 0xeb, 0x0b, 0x53, 0x5f, 0xc8, 0x51, 0x7e, 0xf2, + 0xff, 0x1c, 0x49, 0xb6, 0x75, 0x67, 0xf2, 0x45, 0x53, 0x26, 0x33, 0x0d, 0x9d, 0xcc, 0x34, 0xf4, + 0x79, 0xa6, 0xa1, 0xd7, 0x73, 0x4d, 0x39, 0x99, 0x6b, 0xca, 0xc7, 0xb9, 0xa6, 0x3c, 0x7f, 0x94, + 0xf1, 0x8e, 0xbc, 0x53, 0xef, 0x91, 0x4e, 0xdc, 0xa6, 0xf5, 0xe4, 0xe6, 0xc8, 0x48, 0xa3, 0xf3, + 0x5b, 0x77, 0xe4, 0xaf, 0xce, 0x52, 0xd4, 0x13, 0xf7, 0x7e, 0x06, 0x00, 0x00, 0xff, 0xff, 0x5e, + 0xda, 0xf3, 0xe6, 0xe7, 0x05, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + Delegate(ctx context.Context, in *MsgDelegate, opts ...grpc.CallOption) (*MsgDelegateResponse, error) + Undelegate(ctx context.Context, in *MsgUndelegate, opts ...grpc.CallOption) (*MsgUndelegateResponse, error) + SetConsumerCommissionRate(ctx context.Context, in *MsgSetConsumerCommissionRate, opts ...grpc.CallOption) (*MsgSetConsumerCommissionRateResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) Delegate(ctx context.Context, in *MsgDelegate, opts ...grpc.CallOption) (*MsgDelegateResponse, error) { + out := new(MsgDelegateResponse) + err := c.cc.Invoke(ctx, "/osmosis.meshsecurityprovider.v1beta1.Msg/Delegate", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) Undelegate(ctx context.Context, in *MsgUndelegate, opts ...grpc.CallOption) (*MsgUndelegateResponse, error) { + out := new(MsgUndelegateResponse) + err := c.cc.Invoke(ctx, "/osmosis.meshsecurityprovider.v1beta1.Msg/Undelegate", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) SetConsumerCommissionRate(ctx context.Context, in *MsgSetConsumerCommissionRate, opts ...grpc.CallOption) (*MsgSetConsumerCommissionRateResponse, error) { + out := new(MsgSetConsumerCommissionRateResponse) + err := c.cc.Invoke(ctx, "/osmosis.meshsecurityprovider.v1beta1.Msg/SetConsumerCommissionRate", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + Delegate(context.Context, *MsgDelegate) (*MsgDelegateResponse, error) + Undelegate(context.Context, *MsgUndelegate) (*MsgUndelegateResponse, error) + SetConsumerCommissionRate(context.Context, *MsgSetConsumerCommissionRate) (*MsgSetConsumerCommissionRateResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) Delegate(ctx context.Context, req *MsgDelegate) (*MsgDelegateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delegate not implemented") +} +func (*UnimplementedMsgServer) Undelegate(ctx context.Context, req *MsgUndelegate) (*MsgUndelegateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Undelegate not implemented") +} +func (*UnimplementedMsgServer) SetConsumerCommissionRate(ctx context.Context, req *MsgSetConsumerCommissionRate) (*MsgSetConsumerCommissionRateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetConsumerCommissionRate not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_Delegate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgDelegate) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Delegate(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/osmosis.meshsecurityprovider.v1beta1.Msg/Delegate", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Delegate(ctx, req.(*MsgDelegate)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_Undelegate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUndelegate) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Undelegate(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/osmosis.meshsecurityprovider.v1beta1.Msg/Undelegate", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Undelegate(ctx, req.(*MsgUndelegate)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_SetConsumerCommissionRate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgSetConsumerCommissionRate) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).SetConsumerCommissionRate(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/osmosis.meshsecurityprovider.v1beta1.Msg/SetConsumerCommissionRate", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).SetConsumerCommissionRate(ctx, req.(*MsgSetConsumerCommissionRate)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "osmosis.meshsecurityprovider.v1beta1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Delegate", + Handler: _Msg_Delegate_Handler, + }, + { + MethodName: "Undelegate", + Handler: _Msg_Undelegate_Handler, + }, + { + MethodName: "SetConsumerCommissionRate", + Handler: _Msg_SetConsumerCommissionRate_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "osmosis/meshsecurityprovider/v1beta1/tx.proto", +} + +func (m *MsgDelegate) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgDelegate) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDelegate) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgDelegateResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgDelegateResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDelegateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgUndelegate) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUndelegate) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUndelegate) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUndelegateResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUndelegateResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUndelegateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgSetConsumerCommissionRate) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgSetConsumerCommissionRate) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSetConsumerCommissionRate) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Rate.Size() + i -= size + if _, err := m.Rate.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintTx(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0x12 + } + if len(m.ProviderAddr) > 0 { + i -= len(m.ProviderAddr) + copy(dAtA[i:], m.ProviderAddr) + i = encodeVarintTx(dAtA, i, uint64(len(m.ProviderAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgSetConsumerCommissionRateResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgSetConsumerCommissionRateResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSetConsumerCommissionRateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgDelegate) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgDelegateResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgUndelegate) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUndelegateResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgSetConsumerCommissionRate) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ProviderAddr) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Rate.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgSetConsumerCommissionRateResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgDelegate) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: MsgDelegate: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDelegate: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgDelegateResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: MsgDelegateResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDelegateResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUndelegate) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: MsgUndelegate: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUndelegate: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUndelegateResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: MsgUndelegateResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUndelegateResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgSetConsumerCommissionRate) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: MsgSetConsumerCommissionRate: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSetConsumerCommissionRate: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProviderAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ProviderAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Rate", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Rate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgSetConsumerCommissionRateResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: MsgSetConsumerCommissionRateResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSetConsumerCommissionRateResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/types/codec.go b/x/types/codec.go new file mode 100644 index 00000000..324b3ec0 --- /dev/null +++ b/x/types/codec.go @@ -0,0 +1,11 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" +) + +var ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) + +func init() { +} diff --git a/x/types/error.go b/x/types/error.go new file mode 100644 index 00000000..788482ba --- /dev/null +++ b/x/types/error.go @@ -0,0 +1,14 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" +) + +// meshsecurity sentinel errors +var ( + ErrInvalidVersion = errorsmod.Register(ModuleName, 2, "invalid meshsecurity version") + ErrInvalidChannelFlow = errorsmod.Register(ModuleName, 3, "invalid message sent to channel end") + ErrDuplicateChannel = errorsmod.Register(ModuleName, 5, "meshsecurity channel already exists") + ErrClientNotFound = errorsmod.Register(ModuleName, 10, "client not found") + ErrInvalidPacketData = errorsmod.Register(ModuleName, 1, "invalid CCV packet data") +) diff --git a/x/types/event.go b/x/types/event.go new file mode 100644 index 00000000..014831e1 --- /dev/null +++ b/x/types/event.go @@ -0,0 +1,12 @@ +package types + +const ( + EventTypeTimeout = "timeout" + EventTypePacket = "mesh_packet" + EventTypeChannelEstablished = "channel_established" + + AttributeKeyAckSuccess = "success" + AttributeKeyAck = "acknowledgement" + AttributeKeyAckError = "error" + AttributeChainID = "chain_id" +) diff --git a/x/types/key.go b/x/types/key.go new file mode 100644 index 00000000..72316279 --- /dev/null +++ b/x/types/key.go @@ -0,0 +1,13 @@ +package types + +const ( + ModuleName = "MeshSecurity" + + // ProviderPortID is the default port id the provider module binds to + ProviderPortID = "ms-provider" + + // ConsumerPortID is the default port id the consumer module binds to + ConsumerPortID = "ms-consumer" + + Version = "1" +) diff --git a/x/types/wire.go b/x/types/wire.go new file mode 100644 index 00000000..6da90e76 --- /dev/null +++ b/x/types/wire.go @@ -0,0 +1,100 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + "encoding/binary" +) + +func (c ConsumerPacketData) MarshalConsumerPacketData() []byte { + var bytes []byte + bytes = append(bytes, Int32ToBytes(int32(c.Type))...) + if c.Type != PipedValsetOperation_VALIDATOR_SLASHED { + packetScheduleInfo := c.GetSchedulePacketData() + bytes = append(bytes, ModuleCdc.MustMarshalJSON(packetScheduleInfo)...) + } else { + packetSlashInfo := c.GetSlashPacketData() + bytes = append(bytes, ModuleCdc.MustMarshalJSON(packetSlashInfo)...) + } + return bytes +} + +func UnmarshalConsumerPacketData(data []byte) (ConsumerPacketData, error) { + cp := PipedValsetOperation(BigEndianToInt32(data[:4])) + if cp != PipedValsetOperation_VALIDATOR_SLASHED { + var s ScheduleInfo + err := ModuleCdc.UnmarshalJSON(data[4:], &s) + if err != nil { + return ConsumerPacketData{}, err + } + return ConsumerPacketData{ + Type: cp, + Data: &ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &s, + }, + }, nil + } else { + var slash SlashInfo + err := ModuleCdc.UnmarshalJSON(data[4:], &slash) + if err != nil { + return ConsumerPacketData{}, err + } + return ConsumerPacketData{ + Type: cp, + Data: &ConsumerPacketData_SlashPacketData{ + SlashPacketData: &slash, + }, + }, nil + } +} + +func BigEndianToInt32(bz []byte) int32 { + if len(bz) == 0 { + return 0 + } + return int32(binary.BigEndian.Uint32(bz)) +} + +func Int32ToBytes(i int32) []byte { + data := make([]byte, 4) + binary.BigEndian.PutUint32(data, uint32(i)) + return data +} + +type PacketAckResult []byte + +var ( + // Slash packet handled result ack, sent by a throttling provider to indicate that a slash packet was handled. + SlashPacketHandledResult = PacketAckResult([]byte{byte(1)}) + // Slash packet bounced result ack, sent by a throttling provider to indicate that a slash packet was NOT handled + // and should eventually be retried. + SlashPacketBouncedResult = PacketAckResult([]byte{byte(2)}) +) + +func NewConsumerPacketData(cpdType PipedValsetOperation, data isConsumerPacketData_Data) ConsumerPacketData { + return ConsumerPacketData{ + Type: cpdType, + Data: data, + } +} + +func (s SlashInfo) Validate() error { + if s.Validator == "" { + return errorsmod.Wrap(ErrInvalidPacketData, "invalid validator") + } + if s.Power == 0 { + return errorsmod.Wrap(ErrInvalidPacketData, "validator power cannot be zero") + } + if s.InfractionHeight <= 0 { + return errorsmod.Wrap(ErrInvalidPacketData, "Infraction Height cannot be zero") + } + if s.SlashFraction == "0" { + return errorsmod.Wrap(ErrInvalidPacketData, "Slash Fraction cannot be zero") + } + if s.TotalSlashAmount == "0" { + return errorsmod.Wrap(ErrInvalidPacketData, "Total Slash Amount cannot be zero") + } + if s.TimeInfraction < 0 { + return errorsmod.Wrap(ErrInvalidPacketData, "TimeInfraction cannot be negative") + } + return nil +} diff --git a/x/types/wire.pb.go b/x/types/wire.pb.go new file mode 100644 index 00000000..9d6ee623 --- /dev/null +++ b/x/types/wire.pb.go @@ -0,0 +1,1198 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: osmosis/types/v1beta1/wire.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cometbft/cometbft/abci/types" + _ "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/cosmos-sdk/x/staking/types" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// enum PipedValsetOperation +type PipedValsetOperation int32 + +const ( + PipedValsetOperation_UNSPECIFIED PipedValsetOperation = 0 + PipedValsetOperation_VALIDATOR_BONDED PipedValsetOperation = 1 + PipedValsetOperation_VALIDATOR_UNBONDED PipedValsetOperation = 2 + PipedValsetOperation_VALIDATOR_JAILED PipedValsetOperation = 3 + PipedValsetOperation_VALIDATOR_TOMBSTONED PipedValsetOperation = 4 + PipedValsetOperation_VALIDATOR_UNJAILED PipedValsetOperation = 5 + PipedValsetOperation_VALIDATOR_MODIFIED PipedValsetOperation = 6 + PipedValsetOperation_VALIDATOR_SLASHED PipedValsetOperation = 7 +) + +var PipedValsetOperation_name = map[int32]string{ + 0: "UNSPECIFIED", + 1: "VALIDATOR_BONDED", + 2: "VALIDATOR_UNBONDED", + 3: "VALIDATOR_JAILED", + 4: "VALIDATOR_TOMBSTONED", + 5: "VALIDATOR_UNJAILED", + 6: "VALIDATOR_MODIFIED", + 7: "VALIDATOR_SLASHED", +} + +var PipedValsetOperation_value = map[string]int32{ + "UNSPECIFIED": 0, + "VALIDATOR_BONDED": 1, + "VALIDATOR_UNBONDED": 2, + "VALIDATOR_JAILED": 3, + "VALIDATOR_TOMBSTONED": 4, + "VALIDATOR_UNJAILED": 5, + "VALIDATOR_MODIFIED": 6, + "VALIDATOR_SLASHED": 7, +} + +func (x PipedValsetOperation) String() string { + return proto.EnumName(PipedValsetOperation_name, int32(x)) +} + +func (PipedValsetOperation) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_c573c9158aa3b788, []int{0} +} + +// InfractionType indicates the infraction type a validator committed. +// Note ccv.InfractionType to maintain compatibility between ICS versions +// using different versions of the cosmos-sdk and ibc-go modules. +type InfractionType int32 + +const ( + // UNSPECIFIED defines an empty infraction type. + InfractionEmpty InfractionType = 0 + // DOUBLE_SIGN defines a validator that double-signs a block. + DoubleSign InfractionType = 1 + // DOWNTIME defines a validator that missed signing too many blocks. + Downtime InfractionType = 2 +) + +var InfractionType_name = map[int32]string{ + 0: "INFRACTION_TYPE_UNSPECIFIED", + 1: "INFRACTION_TYPE_DOUBLE_SIGN", + 2: "INFRACTION_TYPE_DOWNTIME", +} + +var InfractionType_value = map[string]int32{ + "INFRACTION_TYPE_UNSPECIFIED": 0, + "INFRACTION_TYPE_DOUBLE_SIGN": 1, + "INFRACTION_TYPE_DOWNTIME": 2, +} + +func (x InfractionType) String() string { + return proto.EnumName(InfractionType_name, int32(x)) +} + +func (InfractionType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_c573c9158aa3b788, []int{1} +} + +// SlashInfo defines info event from slashing +type SlashInfo struct { + Validator string `protobuf:"bytes,1,opt,name=validator,proto3" json:"validator,omitempty"` + InfractionHeight int64 `protobuf:"varint,2,opt,name=infraction_height,json=infractionHeight,proto3" json:"infraction_height,omitempty"` + Power int64 `protobuf:"varint,3,opt,name=power,proto3" json:"power,omitempty"` + TotalSlashAmount string `protobuf:"bytes,4,opt,name=total_slash_amount,json=totalSlashAmount,proto3" json:"total_slash_amount,omitempty"` + SlashFraction string `protobuf:"bytes,5,opt,name=slash_fraction,json=slashFraction,proto3" json:"slash_fraction,omitempty"` + TimeInfraction int64 `protobuf:"varint,6,opt,name=time_infraction,json=timeInfraction,proto3" json:"time_infraction,omitempty"` +} + +func (m *SlashInfo) Reset() { *m = SlashInfo{} } +func (m *SlashInfo) String() string { return proto.CompactTextString(m) } +func (*SlashInfo) ProtoMessage() {} +func (*SlashInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_c573c9158aa3b788, []int{0} +} +func (m *SlashInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SlashInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SlashInfo.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SlashInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_SlashInfo.Merge(m, src) +} +func (m *SlashInfo) XXX_Size() int { + return m.Size() +} +func (m *SlashInfo) XXX_DiscardUnknown() { + xxx_messageInfo_SlashInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_SlashInfo proto.InternalMessageInfo + +// InfoSchedule +type ScheduleInfo struct { + Validator string `protobuf:"bytes,1,opt,name=validator,proto3" json:"validator,omitempty"` + Actor string `protobuf:"bytes,2,opt,name=actor,proto3" json:"actor,omitempty"` + Denom string `protobuf:"bytes,3,opt,name=denom,proto3" json:"denom,omitempty"` +} + +func (m *ScheduleInfo) Reset() { *m = ScheduleInfo{} } +func (m *ScheduleInfo) String() string { return proto.CompactTextString(m) } +func (*ScheduleInfo) ProtoMessage() {} +func (*ScheduleInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_c573c9158aa3b788, []int{1} +} +func (m *ScheduleInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ScheduleInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ScheduleInfo.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ScheduleInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_ScheduleInfo.Merge(m, src) +} +func (m *ScheduleInfo) XXX_Size() int { + return m.Size() +} +func (m *ScheduleInfo) XXX_DiscardUnknown() { + xxx_messageInfo_ScheduleInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_ScheduleInfo proto.InternalMessageInfo + +// ConsumerPacketData contains a consumer packet data and a type tag +type ConsumerPacketData struct { + Type PipedValsetOperation `protobuf:"varint,1,opt,name=type,proto3,enum=osmosis.types.v1beta1.PipedValsetOperation" json:"type,omitempty"` + // Types that are valid to be assigned to Data: + // *ConsumerPacketData_SlashPacketData + // *ConsumerPacketData_SchedulePacketData + Data isConsumerPacketData_Data `protobuf_oneof:"data"` +} + +func (m *ConsumerPacketData) Reset() { *m = ConsumerPacketData{} } +func (m *ConsumerPacketData) String() string { return proto.CompactTextString(m) } +func (*ConsumerPacketData) ProtoMessage() {} +func (*ConsumerPacketData) Descriptor() ([]byte, []int) { + return fileDescriptor_c573c9158aa3b788, []int{2} +} +func (m *ConsumerPacketData) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ConsumerPacketData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ConsumerPacketData.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ConsumerPacketData) XXX_Merge(src proto.Message) { + xxx_messageInfo_ConsumerPacketData.Merge(m, src) +} +func (m *ConsumerPacketData) XXX_Size() int { + return m.Size() +} +func (m *ConsumerPacketData) XXX_DiscardUnknown() { + xxx_messageInfo_ConsumerPacketData.DiscardUnknown(m) +} + +var xxx_messageInfo_ConsumerPacketData proto.InternalMessageInfo + +type isConsumerPacketData_Data interface { + isConsumerPacketData_Data() + MarshalTo([]byte) (int, error) + Size() int +} + +type ConsumerPacketData_SlashPacketData struct { + SlashPacketData *SlashInfo `protobuf:"bytes,2,opt,name=slashPacketData,proto3,oneof" json:"slashPacketData,omitempty"` +} +type ConsumerPacketData_SchedulePacketData struct { + SchedulePacketData *ScheduleInfo `protobuf:"bytes,3,opt,name=schedulePacketData,proto3,oneof" json:"schedulePacketData,omitempty"` +} + +func (*ConsumerPacketData_SlashPacketData) isConsumerPacketData_Data() {} +func (*ConsumerPacketData_SchedulePacketData) isConsumerPacketData_Data() {} + +func (m *ConsumerPacketData) GetData() isConsumerPacketData_Data { + if m != nil { + return m.Data + } + return nil +} + +func (m *ConsumerPacketData) GetSlashPacketData() *SlashInfo { + if x, ok := m.GetData().(*ConsumerPacketData_SlashPacketData); ok { + return x.SlashPacketData + } + return nil +} + +func (m *ConsumerPacketData) GetSchedulePacketData() *ScheduleInfo { + if x, ok := m.GetData().(*ConsumerPacketData_SchedulePacketData); ok { + return x.SchedulePacketData + } + return nil +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*ConsumerPacketData) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*ConsumerPacketData_SlashPacketData)(nil), + (*ConsumerPacketData_SchedulePacketData)(nil), + } +} + +func init() { + proto.RegisterEnum("osmosis.types.v1beta1.PipedValsetOperation", PipedValsetOperation_name, PipedValsetOperation_value) + proto.RegisterEnum("osmosis.types.v1beta1.InfractionType", InfractionType_name, InfractionType_value) + proto.RegisterType((*SlashInfo)(nil), "osmosis.types.v1beta1.SlashInfo") + proto.RegisterType((*ScheduleInfo)(nil), "osmosis.types.v1beta1.ScheduleInfo") + proto.RegisterType((*ConsumerPacketData)(nil), "osmosis.types.v1beta1.ConsumerPacketData") +} + +func init() { proto.RegisterFile("osmosis/types/v1beta1/wire.proto", fileDescriptor_c573c9158aa3b788) } + +var fileDescriptor_c573c9158aa3b788 = []byte{ + // 716 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0x4d, 0x4f, 0xe3, 0x46, + 0x18, 0xc7, 0xed, 0xbc, 0xb5, 0x19, 0x68, 0x62, 0xa6, 0xa1, 0xb2, 0x42, 0x65, 0x45, 0xb4, 0x55, + 0x11, 0x94, 0x58, 0xd0, 0xde, 0xab, 0x04, 0x9b, 0xc6, 0x55, 0xb0, 0x23, 0x3b, 0xa1, 0x2f, 0x17, + 0x6b, 0xe2, 0x0c, 0xc9, 0x88, 0xd8, 0x13, 0xd9, 0x13, 0x28, 0xd7, 0x9e, 0x56, 0x9c, 0xf6, 0x0b, + 0x70, 0xda, 0xcb, 0xee, 0x37, 0xe1, 0xb0, 0x07, 0x8e, 0x7b, 0xdc, 0x0d, 0xb7, 0xfd, 0x14, 0x2b, + 0x8f, 0xbd, 0x31, 0xaf, 0xd2, 0x5e, 0x2c, 0xcf, 0xef, 0xf9, 0xff, 0xff, 0xf3, 0x3c, 0x9e, 0x91, + 0x41, 0x83, 0x46, 0x3e, 0x8d, 0x48, 0xa4, 0xb2, 0x8b, 0x19, 0x8e, 0xd4, 0xb3, 0xbd, 0x21, 0x66, + 0x68, 0x4f, 0x3d, 0x27, 0x21, 0x6e, 0xce, 0x42, 0xca, 0x28, 0x5c, 0x4f, 0x15, 0x4d, 0xae, 0x68, + 0xa6, 0x8a, 0xba, 0xe2, 0x71, 0xae, 0x0e, 0x51, 0x84, 0x97, 0x36, 0x8f, 0x92, 0x20, 0xb1, 0xd5, + 0x6b, 0x63, 0x3a, 0xa6, 0xfc, 0x55, 0x8d, 0xdf, 0x52, 0xba, 0x86, 0x7c, 0x12, 0x50, 0x95, 0x3f, + 0x53, 0xf4, 0x63, 0x1a, 0x14, 0x31, 0x74, 0x4a, 0x82, 0xf1, 0x32, 0x2b, 0x5d, 0xa7, 0xaa, 0x0d, + 0x86, 0x83, 0x11, 0x0e, 0x7d, 0x12, 0x30, 0x15, 0x0d, 0x3d, 0x92, 0xf4, 0x9b, 0x14, 0x37, 0x3f, + 0x8a, 0xa0, 0xec, 0x4c, 0x51, 0x34, 0x31, 0x82, 0x13, 0x0a, 0xbf, 0x07, 0xe5, 0x33, 0x34, 0x25, + 0x23, 0xc4, 0x68, 0x28, 0x8b, 0x0d, 0x71, 0xab, 0x6c, 0x67, 0x00, 0xee, 0x80, 0x35, 0x12, 0x9c, + 0x84, 0xc8, 0x63, 0x84, 0x06, 0xee, 0x04, 0x93, 0xf1, 0x84, 0xc9, 0xb9, 0x86, 0xb8, 0x95, 0xb7, + 0xa5, 0xac, 0xd0, 0xe1, 0x1c, 0xd6, 0x40, 0x71, 0x46, 0xcf, 0x71, 0x28, 0xe7, 0xb9, 0x20, 0x59, + 0xc0, 0x5f, 0x00, 0x64, 0x94, 0xa1, 0xa9, 0x1b, 0xc5, 0x7b, 0xba, 0xc8, 0xa7, 0xf3, 0x80, 0xc9, + 0x05, 0xbe, 0x93, 0xc4, 0x2b, 0xbc, 0x99, 0x16, 0xe7, 0xf0, 0x27, 0x50, 0x49, 0x74, 0x9f, 0xb3, + 0xe5, 0x22, 0x57, 0x7e, 0xc3, 0xe9, 0x61, 0x0a, 0xe1, 0xcf, 0xa0, 0xca, 0x88, 0x8f, 0xdd, 0xac, + 0x07, 0xb9, 0xc4, 0x37, 0xad, 0xc4, 0xd8, 0x58, 0xd2, 0xcd, 0xbf, 0xc1, 0xaa, 0xe3, 0x4d, 0xf0, + 0x68, 0x3e, 0xc5, 0x5f, 0x30, 0x6e, 0x0d, 0x14, 0x91, 0x17, 0x57, 0x72, 0xbc, 0x92, 0x2c, 0x62, + 0x3a, 0xc2, 0x01, 0xf5, 0xf9, 0x5c, 0x65, 0x3b, 0x59, 0x6c, 0xfe, 0x9f, 0x03, 0xf0, 0x80, 0x06, + 0xd1, 0xdc, 0xc7, 0x61, 0x0f, 0x79, 0xa7, 0x98, 0x69, 0x88, 0x21, 0xf8, 0x3b, 0x28, 0xc4, 0x1f, + 0x9b, 0x67, 0x57, 0xf6, 0x77, 0x9a, 0x4f, 0xde, 0x87, 0x66, 0x8f, 0xcc, 0xf0, 0xe8, 0x18, 0x4d, + 0x23, 0xcc, 0xac, 0x19, 0x0e, 0x51, 0xdc, 0xab, 0xcd, 0x8d, 0xb0, 0x0b, 0xaa, 0x7c, 0xd6, 0x2c, + 0x93, 0x77, 0xb3, 0xb2, 0xdf, 0x78, 0x26, 0x6b, 0x79, 0x96, 0x1d, 0xc1, 0x7e, 0x68, 0x85, 0x03, + 0x00, 0xa3, 0x74, 0xfe, 0x3b, 0x81, 0x79, 0x1e, 0xf8, 0xc3, 0x73, 0x81, 0x77, 0x3e, 0x58, 0x47, + 0xb0, 0x9f, 0x08, 0x68, 0x97, 0x40, 0x61, 0x84, 0x18, 0xda, 0x7e, 0x2b, 0x82, 0xda, 0x53, 0xb3, + 0xc0, 0x2a, 0x58, 0x19, 0x98, 0x4e, 0x4f, 0x3f, 0x30, 0x0e, 0x0d, 0x5d, 0x93, 0x04, 0x58, 0x03, + 0xd2, 0x71, 0xab, 0x6b, 0x68, 0xad, 0xbe, 0x65, 0xbb, 0x6d, 0xcb, 0xd4, 0x74, 0x4d, 0x12, 0xe1, + 0x77, 0x00, 0x66, 0x74, 0x60, 0xa6, 0x3c, 0x77, 0x5f, 0xfd, 0x67, 0xcb, 0xe8, 0xea, 0x9a, 0x94, + 0x87, 0x32, 0xa8, 0x65, 0xb4, 0x6f, 0x1d, 0xb5, 0x9d, 0xbe, 0x65, 0xea, 0x9a, 0x54, 0x78, 0x98, + 0x93, 0x3a, 0x8a, 0xf7, 0xf9, 0x91, 0xa5, 0x25, 0xdd, 0x94, 0xe0, 0x3a, 0x58, 0xcb, 0xb8, 0xd3, + 0x6d, 0x39, 0x1d, 0x5d, 0x93, 0xbe, 0xda, 0x7e, 0x23, 0x82, 0x4a, 0x76, 0x79, 0xfa, 0xf1, 0x71, + 0xfc, 0x06, 0x36, 0x0c, 0xf3, 0xd0, 0x6e, 0x1d, 0xf4, 0x0d, 0xcb, 0x74, 0xfb, 0xff, 0xf4, 0x74, + 0xf7, 0xde, 0x60, 0xf5, 0x6f, 0x2f, 0xaf, 0x1a, 0xd5, 0xcc, 0xa4, 0xfb, 0x33, 0x76, 0x01, 0xd5, + 0xc7, 0x2e, 0xcd, 0x1a, 0xb4, 0xbb, 0xba, 0xeb, 0x18, 0x7f, 0x98, 0x92, 0x58, 0xaf, 0x5c, 0x5e, + 0x35, 0x80, 0x46, 0xe7, 0xc3, 0x29, 0x76, 0xc8, 0x38, 0x80, 0xdb, 0x40, 0x7e, 0x6c, 0xf8, 0xcb, + 0xec, 0x1b, 0x47, 0xba, 0x94, 0xab, 0xaf, 0x5e, 0x5e, 0x35, 0xbe, 0xd6, 0xe8, 0x79, 0x10, 0xdf, + 0xee, 0x7a, 0xe1, 0xc5, 0x2b, 0x45, 0x68, 0x3b, 0xd7, 0x1f, 0x14, 0xe1, 0xf5, 0x42, 0x11, 0xae, + 0x17, 0x8a, 0x78, 0xb3, 0x50, 0xc4, 0xf7, 0x0b, 0x45, 0x7c, 0x79, 0xab, 0x08, 0x37, 0xb7, 0x8a, + 0xf0, 0xee, 0x56, 0x11, 0xfe, 0xdd, 0x1b, 0x13, 0x36, 0x99, 0x0f, 0x9b, 0x1e, 0xf5, 0xd5, 0xf4, + 0xa4, 0x77, 0xa7, 0x68, 0x18, 0xa9, 0x3e, 0x8e, 0x26, 0xbb, 0x11, 0xf6, 0xe6, 0x21, 0x61, 0x17, + 0xbb, 0xd1, 0xe8, 0x54, 0xfd, 0x2f, 0xf9, 0x43, 0x0c, 0x4b, 0xfc, 0x17, 0xf1, 0xeb, 0xa7, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xb1, 0xd3, 0xdb, 0x96, 0xe9, 0x04, 0x00, 0x00, +} + +func (m *SlashInfo) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SlashInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SlashInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.TimeInfraction != 0 { + i = encodeVarintWire(dAtA, i, uint64(m.TimeInfraction)) + i-- + dAtA[i] = 0x30 + } + if len(m.SlashFraction) > 0 { + i -= len(m.SlashFraction) + copy(dAtA[i:], m.SlashFraction) + i = encodeVarintWire(dAtA, i, uint64(len(m.SlashFraction))) + i-- + dAtA[i] = 0x2a + } + if len(m.TotalSlashAmount) > 0 { + i -= len(m.TotalSlashAmount) + copy(dAtA[i:], m.TotalSlashAmount) + i = encodeVarintWire(dAtA, i, uint64(len(m.TotalSlashAmount))) + i-- + dAtA[i] = 0x22 + } + if m.Power != 0 { + i = encodeVarintWire(dAtA, i, uint64(m.Power)) + i-- + dAtA[i] = 0x18 + } + if m.InfractionHeight != 0 { + i = encodeVarintWire(dAtA, i, uint64(m.InfractionHeight)) + i-- + dAtA[i] = 0x10 + } + if len(m.Validator) > 0 { + i -= len(m.Validator) + copy(dAtA[i:], m.Validator) + i = encodeVarintWire(dAtA, i, uint64(len(m.Validator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ScheduleInfo) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ScheduleInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ScheduleInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintWire(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0x1a + } + if len(m.Actor) > 0 { + i -= len(m.Actor) + copy(dAtA[i:], m.Actor) + i = encodeVarintWire(dAtA, i, uint64(len(m.Actor))) + i-- + dAtA[i] = 0x12 + } + if len(m.Validator) > 0 { + i -= len(m.Validator) + copy(dAtA[i:], m.Validator) + i = encodeVarintWire(dAtA, i, uint64(len(m.Validator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ConsumerPacketData) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ConsumerPacketData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ConsumerPacketData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Data != nil { + { + size := m.Data.Size() + i -= size + if _, err := m.Data.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } + if m.Type != 0 { + i = encodeVarintWire(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *ConsumerPacketData_SlashPacketData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ConsumerPacketData_SlashPacketData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.SlashPacketData != nil { + { + size, err := m.SlashPacketData.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintWire(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + return len(dAtA) - i, nil +} +func (m *ConsumerPacketData_SchedulePacketData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ConsumerPacketData_SchedulePacketData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.SchedulePacketData != nil { + { + size, err := m.SchedulePacketData.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintWire(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + return len(dAtA) - i, nil +} +func encodeVarintWire(dAtA []byte, offset int, v uint64) int { + offset -= sovWire(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *SlashInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Validator) + if l > 0 { + n += 1 + l + sovWire(uint64(l)) + } + if m.InfractionHeight != 0 { + n += 1 + sovWire(uint64(m.InfractionHeight)) + } + if m.Power != 0 { + n += 1 + sovWire(uint64(m.Power)) + } + l = len(m.TotalSlashAmount) + if l > 0 { + n += 1 + l + sovWire(uint64(l)) + } + l = len(m.SlashFraction) + if l > 0 { + n += 1 + l + sovWire(uint64(l)) + } + if m.TimeInfraction != 0 { + n += 1 + sovWire(uint64(m.TimeInfraction)) + } + return n +} + +func (m *ScheduleInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Validator) + if l > 0 { + n += 1 + l + sovWire(uint64(l)) + } + l = len(m.Actor) + if l > 0 { + n += 1 + l + sovWire(uint64(l)) + } + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovWire(uint64(l)) + } + return n +} + +func (m *ConsumerPacketData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Type != 0 { + n += 1 + sovWire(uint64(m.Type)) + } + if m.Data != nil { + n += m.Data.Size() + } + return n +} + +func (m *ConsumerPacketData_SlashPacketData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SlashPacketData != nil { + l = m.SlashPacketData.Size() + n += 1 + l + sovWire(uint64(l)) + } + return n +} +func (m *ConsumerPacketData_SchedulePacketData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SchedulePacketData != nil { + l = m.SchedulePacketData.Size() + n += 1 + l + sovWire(uint64(l)) + } + return n +} + +func sovWire(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozWire(x uint64) (n int) { + return sovWire(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *SlashInfo) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWire + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: SlashInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SlashInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWire + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthWire + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthWire + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Validator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field InfractionHeight", wireType) + } + m.InfractionHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWire + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.InfractionHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Power", wireType) + } + m.Power = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWire + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Power |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalSlashAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWire + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthWire + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthWire + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TotalSlashAmount = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SlashFraction", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWire + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthWire + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthWire + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SlashFraction = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeInfraction", wireType) + } + m.TimeInfraction = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWire + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TimeInfraction |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipWire(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthWire + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ScheduleInfo) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWire + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: ScheduleInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ScheduleInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWire + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthWire + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthWire + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Validator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Actor", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWire + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthWire + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthWire + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Actor = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWire + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthWire + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthWire + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipWire(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthWire + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ConsumerPacketData) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWire + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: ConsumerPacketData: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ConsumerPacketData: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + m.Type = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWire + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Type |= PipedValsetOperation(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SlashPacketData", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWire + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthWire + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthWire + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &SlashInfo{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Data = &ConsumerPacketData_SlashPacketData{v} + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SchedulePacketData", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWire + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthWire + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthWire + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &ScheduleInfo{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Data = &ConsumerPacketData_SchedulePacketData{v} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipWire(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthWire + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipWire(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowWire + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowWire + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowWire + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthWire + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupWire + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthWire + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthWire = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowWire = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupWire = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/types/wire_test.go b/x/types/wire_test.go new file mode 100644 index 00000000..6473e42f --- /dev/null +++ b/x/types/wire_test.go @@ -0,0 +1,47 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestGetBytesAndUnmarshalConsumerPacketData(t *testing.T) { + c1 := ConsumerPacketData{ + Type: PipedValsetOperation_VALIDATOR_SLASHED, + Data: &ConsumerPacketData_SlashPacketData{ + SlashPacketData: &SlashInfo{ + InfractionHeight: 1, + Power: 2, + TotalSlashAmount: "3", + SlashFraction: "0.1", + TimeInfraction: 1000, + }, + }, + } + + data := c1.MarshalConsumerPacketData() + c2, err := UnmarshalConsumerPacketData(data) + require.NoError(t, err) + require.Equal(t, c1, c2) + + require.Equal(t, int64(1), c2.GetSlashPacketData().InfractionHeight) + require.Equal(t, int64(2), c2.GetSlashPacketData().Power) + require.Equal(t, "3", c2.GetSlashPacketData().TotalSlashAmount) + require.Equal(t, "0.1", c2.GetSlashPacketData().SlashFraction) + require.Equal(t, int64(1000), c2.GetSlashPacketData().TimeInfraction) + + s1 := ConsumerPacketData{ + Type: PipedValsetOperation_VALIDATOR_TOMBSTONED, + Data: &ConsumerPacketData_SchedulePacketData{ + SchedulePacketData: &ScheduleInfo{ + Validator: "val", + Actor: "contract", + }, + }, + } + data = s1.MarshalConsumerPacketData() + s2, err := UnmarshalConsumerPacketData(data) + require.NoError(t, err) + require.Equal(t, s1, s2) +}