Skip to content

Commit

Permalink
cr fix
Browse files Browse the repository at this point in the history
  • Loading branch information
stana-miric committed Nov 27, 2024
1 parent 1288a3f commit 69ec878
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `[x/provider]` Enable the customization of the slashing and jailing conditions for infractions committed by validators on consumer chains (as per [ADR 020](https://cosmos.github.io/interchain-security/adrs/adr-020-cutomizable_slashing_and_jailing)). Every consumer chain can decide the punishment for every type of infraction.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
- Allow consumer chains to customize the slashing and jailing conditions. Every consumer chain can decide the punishment for every type of infraction.
([\#2403](https://github.com/cosmos/interchain-security/pull/2403))
- `[x/provider]` Enable the customization of the slashing and jailing conditions for infractions committed by validators on consumer chains (as per [ADR 020](https://cosmos.github.io/interchain-security/adrs/adr-020-cutomizable_slashing_and_jailing)). Every consumer chain can decide the punishment for every type of infraction.
40 changes: 34 additions & 6 deletions docs/docs/build/modules/02-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ message MsgChangeRewardDenoms {
`MsgCreateConsumer` enables a user to create a consumer chain.

Both the `chain_id` and `metadata` fields are mandatory.
The `initialization_parameters`, `power_shaping_parameters`, and `allowlisted_reward_denoms` fields are optional.
The parameters not provided are set to their zero value.
The `initialization_parameters`, `power_shaping_parameters`, `infraction_parameters` and `allowlisted_reward_denoms` fields are optional.
The parameters not provided are set to their zero value. If `infraction_parameters` are not set, the default values currently configured on the provider are used.

The owner of the created consumer chain is the submitter of the message.
This message cannot be submitted as part of a governance proposal, i.e., the submitter cannot be the gov module account address.
Expand Down Expand Up @@ -516,6 +516,9 @@ message MsgCreateConsumer {
// allowlisted reward denoms by the consumer chain
AllowlistedRewardDenoms allowlisted_reward_denoms = 6;
// infraction parameters for slashing and jailing
InfractionParameters infraction_parameters = 7;
}
```

Expand All @@ -524,11 +527,11 @@ message MsgCreateConsumer {
`MsgUpdateConsumer` enables the owner of a consumer chain to update its parameters (e.g., set a new owner).

Note that only the `owner` (i.e., signer) and `consumer_id` fields are mandatory.
The others field are optional. Not providing one of them will leave the existing values unchanged.
Providing one of `metadata`, `initialization_parameters`, `power_shaping_parameters`, or `allowlisted_reward_denoms`
The others field are optional. Not providing one of them will leave the existing values unchanged. For `infraction_parameters` it is possible to update separately `downtime` and `double_sign` parameters by providing just desired one.
Providing one of `metadata`, `initialization_parameters`, `power_shaping_parameters`, `infraction_parameters.double_sign`, `infraction_parameters.downtime` or `allowlisted_reward_denoms`
will update all the containing fields.
If one of the containing fields is missing, it will be set to its zero value.
For example, updating the `initialization_parameters` without specifying the `spawn_time`, will set the `spawn_time` to zero.
For example, updating the `initialization_parameters` without specifying the `spawn_time`, will set the `spawn_time` to zero.

If the `initialization_parameters` field is set and `initialization_parameters.spawn_time > 0`, then the consumer chain will be scheduled to launch at `spawn_time`.
Updating the `spawn_time` from a positive value to zero will remove the consumer chain from the list of scheduled to launch chains.
Expand Down Expand Up @@ -568,6 +571,9 @@ message MsgUpdateConsumer {
// to update the chain id of the chain (can only be updated if the chain has not yet launched)
string new_chain_id = 8;
// infraction parameters for slashing and jailing
InfractionParameters infraction_parameters = 9;
}
```

Expand Down Expand Up @@ -829,6 +835,7 @@ In the `BeginBlock` of the provider module the following actions are performed:
- Remove every stopped consumer chain for which the removal time has passed.
- Replenish the throttling meter if necessary.
- Distribute ICS rewards to the opted in validators.
- Update consumer infraction parameters with the queued infraction parameters that were added to the queue before a time period greater than the unbonding time.

Note that for every consumer chain, the computation of its initial validator set is based on the consumer's [power shaping parameters](../../features/power-shaping.md)
and the [validators that opted in on that consumer](../../features/partial-set-security.md).
Expand Down Expand Up @@ -2873,7 +2880,17 @@ grpcurl -plaintext -d '{"consumer_id": "0"}' localhost:9090 interchain_security.
"validatorSetCap": 50,
"minStake": "1000",
"allowInactiveVals": true
}
},
"infraction_parameters":{
"double_sign":{
"slash_fraction":"0.050000000000000000",
"jail_duration":"9223372036.854775807s"
},
"downtime":{
"slash_fraction":"0.000000000000000000",
"jail_duration":"600s"
}
}
}
```

Expand Down Expand Up @@ -3572,6 +3589,17 @@ Output:
"minStake": "1000",
"allowInactiveVals": true
}
,
"infraction_parameters":{
"double_sign":{
"slash_fraction":"0.050000000000000000",
"jail_duration":"9223372036.854775807s"
},
"downtime":{
"slash_fraction":"0.000000000000000000",
"jail_duration":"600s"
}
}
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/features/slashing.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The ICS protocol differentiates between downtime and equivocation infractions.

Downtime infractions are reported by consumer chains and are acted upon on the provider as soon as they are received.
The provider will jail and slash the offending validator. The jailing duration and slashing fraction are determined by the consumer's downtime infraction parameters on the provider chain.
Note that validators are only slashed and jailed for downtime on consumer chains that they opted in to validate on,
By default, validators are **_only jailed_** for downtime on consumer chains that they opted in to validate on,
or in the case of Top N chains, where they are automatically opted in by being in the Top N% of the validator set on the provider.

For preventing malicious consumer chains from harming the provider, [slash throttling](../adrs/adr-002-throttle.md) (also known as _jail throttling_) ensures that only a fraction of the provider validator set can be jailed at any given time.
Expand Down
2 changes: 1 addition & 1 deletion proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,6 @@ message SlashJailParameters {
(amino.dont_omitempty) = true
];
// for permanent jailing use 9223372036854775807 which is the largest value a time.Duration can hold (approximately 292 years)
google.protobuf.Duration jail_duration = 8
google.protobuf.Duration jail_duration = 2
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];
}
6 changes: 3 additions & 3 deletions testutil/keeper/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ func GetMocksForHandleSlashPacket(ctx sdk.Context, mocks MockedKeepers,

mocks.MockSlashingKeeper.EXPECT().IsTombstoned(ctx,
expectedProviderValConsAddr.ToSdkConsAddr()).Return(false).Times(1),

mocks.MockStakingKeeper.EXPECT().SlashWithInfractionReason(ctx, expectedProviderValConsAddr.ToSdkConsAddr(), gomock.Any(),
gomock.Any(), gomock.Any(), gomock.Any()).Return(math.NewInt(0), nil).Times(1),
}

if expectJailing {
// slash
calls = append(calls, mocks.MockStakingKeeper.EXPECT().SlashWithInfractionReason(ctx, expectedProviderValConsAddr.ToSdkConsAddr(), gomock.Any(),
gomock.Any(), gomock.Any(), gomock.Any()).Return(math.NewInt(0), nil).Times(1))
// jail
calls = append(calls, mocks.MockStakingKeeper.EXPECT().Jail(
gomock.Eq(ctx),
Expand Down
9 changes: 5 additions & 4 deletions x/ccv/provider/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,11 @@ func (k msgServer) UpdateConsumer(goCtx context.Context, msg *types.MsgUpdateCon
return &resp, errorsmod.Wrapf(types.ErrInvalidConsumerInfractionParameters,
"cannot set infraction parameters")
}
}
if err = k.Keeper.UpdateQueuedInfractionParams(ctx, consumerId, newInfractionParams); err != nil {
return &resp, errorsmod.Wrapf(types.ErrInvalidConsumerInfractionParameters,
"cannot update consumer infraction time queue")
} else {
if err = k.Keeper.UpdateQueuedInfractionParams(ctx, consumerId, newInfractionParams); err != nil {
return &resp, errorsmod.Wrapf(types.ErrInvalidConsumerInfractionParameters,
"cannot update consumer infraction time queue")
}
}

}
Expand Down
18 changes: 9 additions & 9 deletions x/ccv/provider/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,16 +484,16 @@ func (k Keeper) HandleSlashPacket(ctx sdk.Context, consumerId string, data ccv.S
return
}

// slash validator
_, err = k.stakingKeeper.SlashWithInfractionReason(ctx, providerConsAddr.ToSdkConsAddr(), int64(infractionHeight),
data.Validator.Power, infractionParams.Downtime.SlashFraction, stakingtypes.Infraction_INFRACTION_DOWNTIME)
if err != nil {
k.Logger(ctx).Error("failed to slash vaidator", providerConsAddr.ToSdkConsAddr().String(), "err", err.Error())
return
}

// jail validator
if !validator.IsJailed() {
// slash validator
_, err = k.stakingKeeper.SlashWithInfractionReason(ctx, providerConsAddr.ToSdkConsAddr(), int64(infractionHeight),
data.Validator.Power, infractionParams.Downtime.SlashFraction, stakingtypes.Infraction_INFRACTION_DOWNTIME)
if err != nil {
k.Logger(ctx).Error("failed to slash vaidator", providerConsAddr.ToSdkConsAddr().String(), "err", err.Error())
return
}

// jail validator
err := k.stakingKeeper.Jail(ctx, providerConsAddr.ToSdkConsAddr())
if err != nil {
k.Logger(ctx).Error("failed to jail vaidator", providerConsAddr.ToSdkConsAddr().String(), "err", err.Error())
Expand Down
34 changes: 17 additions & 17 deletions x/ccv/provider/types/provider.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 69ec878

Please sign in to comment.