Skip to content

Commit

Permalink
add tombstone field to SlashJailParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
stana-miric committed Dec 12, 2024
1 parent c6372ca commit 8262388
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 163 deletions.
12 changes: 8 additions & 4 deletions docs/docs/build/modules/02-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -2884,11 +2884,13 @@ grpcurl -plaintext -d '{"consumer_id": "0"}' localhost:9090 interchain_security.
"infraction_parameters":{
"double_sign":{
"slash_fraction":"0.050000000000000000",
"jail_duration":"9223372036.854775807s"
"jail_duration":"9223372036.854775807s",
"tombstone": true
},
"downtime":{
"slash_fraction":"0.000000000000000000",
"jail_duration":"600s"
"jail_duration":"600s",
"tombstone": false
}
},
"clientId": "07-tendermint-28"
Expand Down Expand Up @@ -3594,11 +3596,13 @@ Output:
"infraction_parameters":{
"double_sign":{
"slash_fraction":"0.050000000000000000",
"jail_duration":"9223372036.854775807s"
"jail_duration":"9223372036.854775807s",
"tombstone": true
},
"downtime":{
"slash_fraction":"0.000000000000000000",
"jail_duration":"600s"
"jail_duration":"600s",
"tombstone": false
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,6 @@ message SlashJailParameters {
// for permanent jailing use 9223372036854775807 which is the largest value a time.Duration can hold (approximately 292 years)
google.protobuf.Duration jail_duration = 2
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];
// Indicates whether the validator should be tombstoned when slashed
bool tombstone = 3;
}
12 changes: 8 additions & 4 deletions x/ccv/provider/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,13 @@ where create_consumer.json has the following structure:
"infraction_parameters":{
"double_sign":{
"slash_fraction": "0.05",
"jail_duration": 9223372036854775807
"jail_duration": 9223372036854775807,
"tombstone": true
},
"downtime":{
"slash_fraction": "0.0001",
"jail_duration": 600000000000
"jail_duration": 600000000000,
"tombstone": false
}
},
"allowlisted_reward_denoms": {
Expand Down Expand Up @@ -369,11 +371,13 @@ where update_consumer.json has the following structure:
"infraction_parameters":{
"double_sign":{
"slash_fraction": "0.05",
"jail_duration": 9223372036854775807
"jail_duration": 9223372036854775807,
"tombstone": true
},
"downtime":{
"slash_fraction": "0.0001",
"jail_duration": 600000000000
"jail_duration": 600000000000,
"tombstone": false
}
},
"allowlisted_reward_denoms": {
Expand Down
16 changes: 11 additions & 5 deletions x/ccv/provider/keeper/consumer_equivocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,17 @@ func (k Keeper) JailAndTombstoneValidator(ctx sdk.Context, providerAddr types.Pr
return fmt.Errorf("fail to set jail duration for validator: %s: %s", providerAddr.String(), err)
}

// Tombstone the validator so that we cannot slash the validator more than once
// Note that we cannot simply use the fact that a validator is jailed to avoid slashing more than once
// because then a validator could i) perform an equivocation, ii) get jailed (e.g., through downtime)
// and in such a case the validator would not get slashed when we call `SlashValidator`.
return k.slashingKeeper.Tombstone(ctx, providerAddr.ToSdkConsAddr())
if jailingParams.Tombstone {
// Tombstone the validator so that we cannot slash the validator more than once
// Note that we cannot simply use the fact that a validator is jailed to avoid slashing more than once
// because then a validator could i) perform an equivocation, ii) get jailed (e.g., through downtime)
// and in such a case the validator would not get slashed when we call `SlashValidator`.
if err = k.slashingKeeper.Tombstone(ctx, providerAddr.ToSdkConsAddr()); err != nil {
return fmt.Errorf("fail to tombstone validator: %s: %s", providerAddr.String(), err)
}
}

return nil
}

// ComputePowerToSlash computes the power to be slashed based on the tokens in non-matured `undelegations` and
Expand Down
2 changes: 2 additions & 0 deletions x/ccv/provider/keeper/consumer_equivocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,12 @@ func getTestInfractionParameters() *types.InfractionParameters {
DoubleSign: &types.SlashJailParameters{
JailDuration: 1200 * time.Second,
SlashFraction: math.LegacyNewDecWithPrec(5, 1), // 0.5
Tombstone: true,
},
Downtime: &types.SlashJailParameters{
JailDuration: 600 * time.Second,
SlashFraction: math.LegacyNewDec(0),
Tombstone: false,
},
}
}
3 changes: 3 additions & 0 deletions x/ccv/provider/keeper/infraction_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ func compareSlashJailParameters(param1, param2 *types.SlashJailParameters) bool
if param1 == nil || param2 == nil {
return false
}
if param1.Tombstone != param2.Tombstone {
return false
}
if !param1.SlashFraction.Equal(param2.SlashFraction) {
return false
}
Expand Down
9 changes: 9 additions & 0 deletions x/ccv/provider/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,15 @@ func (k Keeper) HandleSlashPacket(ctx sdk.Context, consumerId string, data ccv.S
k.Logger(ctx).Error("failed to set jail duration", "err", err.Error())
return
}

// tombstone validator
if infractionParams.Downtime.Tombstone {
if err = k.slashingKeeper.Tombstone(ctx, providerConsAddr.ToSdkConsAddr()); err != nil {
k.Logger(ctx).Error("failed to tombstone validator", "err", err.Error())
return
}
k.Logger(ctx).Info("HandleSlashPacket - validator tombstoned", "provider cons addr", providerConsAddr.String())
}
}

ctx.EventManager().EmitEvent(
Expand Down
2 changes: 2 additions & 0 deletions x/ccv/provider/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,12 @@ func TestMsgCreateConsumerValidateBasic(t *testing.T) {
DoubleSign: &types.SlashJailParameters{
JailDuration: time.Duration(1<<63 - 1), // max duration
SlashFraction: math.LegacyNewDecWithPrec(5, 2), // 0.05
Tombstone: true,
},
Downtime: &types.SlashJailParameters{
JailDuration: 600 * time.Second,
SlashFraction: math.LegacyNewDec(0),
Tombstone: false,
},
}, // valid infraction params
true,
Expand Down
2 changes: 2 additions & 0 deletions x/ccv/provider/types/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ func DefaultConsumerInfractionParameters(ctx context.Context, slashingKeeper ccv
DoubleSign: &SlashJailParameters{
JailDuration: time.Duration(1<<63 - 1), // the largest value a time.Duration can hold 9223372036854775807 (approximately 292 years)
SlashFraction: doubleSignSlashingFraction,
Tombstone: true,
},
Downtime: &SlashJailParameters{
JailDuration: jailDuration,
SlashFraction: math.LegacyNewDec(0),
Tombstone: false,
},
}, nil
}
Loading

0 comments on commit 8262388

Please sign in to comment.