Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: New module provider and handle slash #177

Closed
69 changes: 36 additions & 33 deletions demo/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) | | |



Expand Down Expand Up @@ -238,6 +240,21 @@ Query provides defines the gRPC querier service



<a name="osmosis.meshsecurity.v1beta1.ScheduledWork"></a>

### ScheduledWork



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `repeat` | [bool](#bool) | | |






<a name="osmosis.meshsecurity.v1beta1.ValidatorAddress"></a>

### ValidatorAddress
Expand Down
2 changes: 2 additions & 0 deletions proto/osmosis/meshsecurity/v1beta1/meshsecurity.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
45 changes: 45 additions & 0 deletions proto/osmosis/meshsecurityprovider/v1beta1/delegate.proto
Original file line number Diff line number Diff line change
@@ -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"];
}
18 changes: 18 additions & 0 deletions proto/osmosis/meshsecurityprovider/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -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 ];
}
22 changes: 22 additions & 0 deletions proto/osmosis/meshsecurityprovider/v1beta1/params.proto
Original file line number Diff line number Diff line change
@@ -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;
}

30 changes: 30 additions & 0 deletions proto/osmosis/meshsecurityprovider/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -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 ];
}
61 changes: 61 additions & 0 deletions proto/osmosis/meshsecurityprovider/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -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 {}
66 changes: 66 additions & 0 deletions proto/osmosis/types/v1beta1/wire.proto
Original file line number Diff line number Diff line change
@@ -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"];
}
Loading
Loading