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

refactor: revert changes in x/slashing proto #627

Merged
merged 13 commits into from
Aug 10, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (ostracon) [\#610](https://github.com/line/lbm-sdk/pull/610) apply change of prefix of key name in ostracon
* (ostracon) [\#614](https://github.com/line/lbm-sdk/pull/614) apply Ostracon's changes that replace `StakingPower` with `VotingPower` and `StakingPower` with `VotingPower`
* (proto) [\#617](https://github.com/line/lbm-sdk/pull/617) change wasm gRPC path to original `cosmwasm` path.
* (proto) [\#627](https://github.com/line/lbm-sdk/pull/627) revert changes in x/slashing proto

### Build, CI

Expand Down
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

101 changes: 81 additions & 20 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11370,6 +11370,24 @@ paths:
properties:
address:
type: string
start_height:
type: string
format: int64
title: >-
Height at which validator was first a candidate OR was
unjailed
index_offset:
type: string
format: int64
description: >-
Index which is incremented each time the validator was a
bonded

in a block and may have signed a precommit or not. This
in conjunction with the

`SignedBlocksWindow` param determines the index in the
`MissedBlocksBitArray`.
jailed_until:
type: string
format: date-time
Expand All @@ -11388,10 +11406,6 @@ paths:
title: >-
missed blocks counter (to avoid scanning the array every
time)
voter_set_counter:
type: string
format: int64
title: how many times the validator joined to voter set
description: >-
ValidatorSigningInfo defines a validator's signing info for
monitoring their
Expand Down Expand Up @@ -11528,6 +11542,24 @@ paths:
properties:
address:
type: string
start_height:
type: string
format: int64
title: >-
Height at which validator was first a candidate OR was
unjailed
index_offset:
type: string
format: int64
description: >-
Index which is incremented each time the validator was a
bonded

in a block and may have signed a precommit or not. This in
conjunction with the

`SignedBlocksWindow` param determines the index in the
`MissedBlocksBitArray`.
jailed_until:
type: string
format: date-time
Expand All @@ -11546,10 +11578,6 @@ paths:
title: >-
missed blocks counter (to avoid scanning the array every
time)
voter_set_counter:
type: string
format: int64
title: how many times the validator joined to voter set
description: >-
ValidatorSigningInfo defines a validator's signing info for
monitoring their
Expand Down Expand Up @@ -53860,6 +53888,21 @@ definitions:
properties:
address:
type: string
start_height:
type: string
format: int64
title: Height at which validator was first a candidate OR was unjailed
index_offset:
type: string
format: int64
description: >-
Index which is incremented each time the validator was a bonded

in a block and may have signed a precommit or not. This in
conjunction with the

`SignedBlocksWindow` param determines the index in the
`MissedBlocksBitArray`.
jailed_until:
type: string
format: date-time
Expand All @@ -53876,10 +53919,6 @@ definitions:
type: string
format: int64
title: missed blocks counter (to avoid scanning the array every time)
voter_set_counter:
type: string
format: int64
title: how many times the validator joined to voter set
description: >-
ValidatorSigningInfo defines a validator's signing info for monitoring
their
Expand All @@ -53901,6 +53940,21 @@ definitions:
properties:
address:
type: string
start_height:
type: string
format: int64
title: Height at which validator was first a candidate OR was unjailed
index_offset:
type: string
format: int64
description: >-
Index which is incremented each time the validator was a bonded

in a block and may have signed a precommit or not. This in
conjunction with the

`SignedBlocksWindow` param determines the index in the
`MissedBlocksBitArray`.
jailed_until:
type: string
format: date-time
Expand All @@ -53917,10 +53971,6 @@ definitions:
type: string
format: int64
title: missed blocks counter (to avoid scanning the array every time)
voter_set_counter:
type: string
format: int64
title: how many times the validator joined to voter set
description: >-
ValidatorSigningInfo defines a validator's signing info for
monitoring their
Expand Down Expand Up @@ -53962,6 +54012,21 @@ definitions:
properties:
address:
type: string
start_height:
type: string
format: int64
title: Height at which validator was first a candidate OR was unjailed
index_offset:
type: string
format: int64
description: >-
Index which is incremented each time the validator was a bonded

in a block and may have signed a precommit or not. This in conjunction
with the

`SignedBlocksWindow` param determines the index in the
`MissedBlocksBitArray`.
jailed_until:
type: string
format: date-time
Expand All @@ -53978,10 +54043,6 @@ definitions:
type: string
format: int64
title: missed blocks counter (to avoid scanning the array every time)
voter_set_counter:
type: string
format: int64
title: how many times the validator joined to voter set
description: >-
ValidatorSigningInfo defines a validator's signing info for monitoring
their
Expand Down
3 changes: 2 additions & 1 deletion docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6492,10 +6492,11 @@ liveness activity.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `address` | [string](#string) | | |
| `start_height` | [int64](#int64) | | Height at which validator was first a candidate OR was unjailed |
| `index_offset` | [int64](#int64) | | Index which is incremented each time the validator was a bonded in a block and may have signed a precommit or not. This in conjunction with the `SignedBlocksWindow` param determines the index in the `MissedBlocksBitArray`. |
| `jailed_until` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | timestamp validator cannot be unjailed until |
| `tombstoned` | [bool](#bool) | | whether or not a validator has been tombstoned (killed out of validator set) |
| `missed_blocks_counter` | [int64](#int64) | | missed blocks counter (to avoid scanning the array every time) |
| `voter_set_counter` | [int64](#int64) | | how many times the validator joined to voter set |



Expand Down
14 changes: 9 additions & 5 deletions proto/cosmos/slashing/v1beta1/slashing.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ message ValidatorSigningInfo {
option (gogoproto.goproto_stringer) = false;

string address = 1;
// Height at which validator was first a candidate OR was unjailed
int64 start_height = 2;
zemyblue marked this conversation as resolved.
Show resolved Hide resolved
// Index which is incremented each time the validator was a bonded
// in a block and may have signed a precommit or not. This in conjunction with the
// `SignedBlocksWindow` param determines the index in the `MissedBlocksBitArray`.
int64 index_offset = 3;
// timestamp validator cannot be unjailed until
google.protobuf.Timestamp jailed_until = 2
google.protobuf.Timestamp jailed_until = 4
[(gogoproto.moretags) = "yaml:\"jailed_until\"", (gogoproto.stdtime) = true, (gogoproto.nullable) = false];
// whether or not a validator has been tombstoned (killed out of validator
// set)
bool tombstoned = 3;
bool tombstoned = 5;
// missed blocks counter (to avoid scanning the array every time)
int64 missed_blocks_counter = 4 [(gogoproto.moretags) = "yaml:\"missed_blocks_counter\""];
// how many times the validator joined to voter set
int64 voter_set_counter = 5 [(gogoproto.moretags) = "yaml:\"voter_set_counter\""];
int64 missed_blocks_counter = 6 [(gogoproto.moretags) = "yaml:\"missed_blocks_counter\""];
}

// Params represents the parameters used for by the slashing module.
Expand Down
2 changes: 1 addition & 1 deletion simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
app.SlashingKeeper.IterateValidatorSigningInfos(
ctx,
func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) {
info.VoterSetCounter = 0
info.StartHeight = 0
zemyblue marked this conversation as resolved.
Show resolved Hide resolved
app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
return false
},
Expand Down
3 changes: 2 additions & 1 deletion x/slashing/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func TestBeginBlocker(t *testing.T) {

info, found := app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(pk.Address()))
require.True(t, found)
require.Equal(t, int64(1), info.VoterSetCounter)
require.Equal(t, ctx.BlockHeight(), info.StartHeight)
require.Equal(t, int64(1), info.IndexOffset)
require.Equal(t, time.Unix(0, 0).UTC(), info.JailedUntil)
require.Equal(t, int64(0), info.MissedBlocksCounter)

Expand Down
7 changes: 4 additions & 3 deletions x/slashing/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *IntegrationTestSuite) TestGetCmdQuerySigningInfo() {
fmt.Sprintf("--%s=1", flags.FlagHeight),
},
false,
fmt.Sprintf("{\"address\":\"%s\",\"jailed_until\":\"1970-01-01T00:00:00Z\",\"tombstoned\":false,\"missed_blocks_counter\":\"0\",\"voter_set_counter\":\"0\"}", sdk.ConsAddress(val.PubKey.Address())),
fmt.Sprintf("{\"address\":\"%s\",\"start_height\":\"0\",\"index_offset\":\"0\",\"jailed_until\":\"1970-01-01T00:00:00Z\",\"tombstoned\":false,\"missed_blocks_counter\":\"0\"}", sdk.ConsAddress(val.PubKey.Address())),
},
{
"valid address (text output)",
Expand All @@ -76,10 +76,11 @@ func (s *IntegrationTestSuite) TestGetCmdQuerySigningInfo() {
},
false,
fmt.Sprintf(`address: %s
index_offset: "0"
jailed_until: "1970-01-01T00:00:00Z"
missed_blocks_counter: "0"
tombstoned: false
voter_set_counter: "0"`, sdk.ConsAddress(val.PubKey.Address())),
start_height: "0"
tombstoned: false`, sdk.ConsAddress(val.PubKey.Address())),
},
}

Expand Down
8 changes: 4 additions & 4 deletions x/slashing/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func TestExportAndInitGenesis(t *testing.T) {
app.SlashingKeeper.SetParams(ctx, testslashing.TestParams())

addrDels := simapp.AddTestAddrsIncremental(app, ctx, 2, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))
info1 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[0]),
time.Now().UTC().Add(100000000000), false, int64(10), int64(3))
info2 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[1]),
time.Now().UTC().Add(10000000000), false, int64(10), int64(4))
info1 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[0]), int64(4), int64(3),
time.Now().UTC().Add(100000000000), false, int64(10))
info2 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[1]), int64(5), int64(4),
time.Now().UTC().Add(10000000000), false, int64(10))

app.SlashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0]), info1)
app.SlashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[1]), info2)
Expand Down
14 changes: 7 additions & 7 deletions x/slashing/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestJailedValidatorDelegations(t *testing.T) {
staking.EndBlocker(ctx, app.StakingKeeper)

// set dummy signing info
newInfo := types.NewValidatorSigningInfo(consAddr, time.Unix(0, 0), false, 0, 0)
newInfo := types.NewValidatorSigningInfo(consAddr, 0, 0, time.Unix(0, 0), false, 0)
app.SlashingKeeper.SetValidatorSigningInfo(ctx, consAddr, newInfo)

// delegate tokens to the validator
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestHandleAbsentValidator(t *testing.T) {
// will exist since the validator has been bonded
zemyblue marked this conversation as resolved.
Show resolved Hide resolved
info, found := app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(val.Address()))
require.True(t, found)
require.Equal(t, int64(0), info.VoterSetCounter)
require.Equal(t, int64(0), info.IndexOffset)
dudong2 marked this conversation as resolved.
Show resolved Hide resolved
require.Equal(t, int64(0), info.MissedBlocksCounter)
require.Equal(t, time.Unix(0, 0).UTC(), info.JailedUntil)
height := int64(0)
Expand All @@ -177,7 +177,7 @@ func TestHandleAbsentValidator(t *testing.T) {
}
info, found = app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(val.Address()))
require.True(t, found)
require.Equal(t, int64(1000), info.VoterSetCounter)
require.Equal(t, int64(1000), info.IndexOffset)
require.Equal(t, int64(0), info.MissedBlocksCounter)

// 500 blocks missed
Expand All @@ -187,7 +187,7 @@ func TestHandleAbsentValidator(t *testing.T) {
}
info, found = app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(val.Address()))
require.True(t, found)
require.Equal(t, int64(1500), info.VoterSetCounter)
require.Equal(t, int64(1500), info.IndexOffset)
require.Equal(t, app.SlashingKeeper.SignedBlocksWindow(ctx)-app.SlashingKeeper.MinSignedPerWindow(ctx), info.MissedBlocksCounter)

// validator should be bonded still
Expand All @@ -202,7 +202,7 @@ func TestHandleAbsentValidator(t *testing.T) {
app.SlashingKeeper.HandleValidatorSignature(ctx, val.Address(), power, false)
info, found = app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(val.Address()))
require.True(t, found)
require.Equal(t, int64(1501), info.VoterSetCounter)
require.Equal(t, int64(0), info.IndexOffset)
// counter now reset to zero
require.Equal(t, int64(0), info.MissedBlocksCounter)

Expand All @@ -224,7 +224,7 @@ func TestHandleAbsentValidator(t *testing.T) {
app.SlashingKeeper.HandleValidatorSignature(ctx, val.Address(), power, false)
info, found = app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(val.Address()))
require.True(t, found)
require.Equal(t, int64(1502), info.VoterSetCounter)
require.Equal(t, int64(1), info.IndexOffset)
require.Equal(t, int64(1), info.MissedBlocksCounter)

// end block
Expand Down Expand Up @@ -258,7 +258,7 @@ func TestHandleAbsentValidator(t *testing.T) {
// Validator voter set counter should not have been changed
info, found = app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(val.Address()))
require.True(t, found)
require.Equal(t, int64(1502), info.VoterSetCounter)
require.Equal(t, int64(1), info.IndexOffset)
zemyblue marked this conversation as resolved.
Show resolved Hide resolved
// we've missed 2 blocks more than the maximum, so the counter was reset to 0 at 1 block more and is now 1
require.Equal(t, int64(1), info.MissedBlocksCounter)

Expand Down
8 changes: 4 additions & 4 deletions x/slashing/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ func (suite *SlashingTestSuite) SetupTest() {

addrDels := simapp.AddTestAddrsIncremental(app, ctx, 2, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))

info1 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[0]),
time.Unix(2, 0), false, int64(10), int64(3))
info2 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[1]),
time.Unix(2, 0), false, int64(10), int64(4))
info1 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[0]), int64(4), int64(3),
time.Unix(2, 0), false, int64(10))
info2 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[1]), int64(5), int64(4),
time.Unix(2, 0), false, int64(10))

app.SlashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0]), info1)
app.SlashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[1]), info2)
Expand Down
3 changes: 2 additions & 1 deletion x/slashing/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ func (k Keeper) AfterValidatorBonded(ctx sdk.Context, address sdk.ConsAddress, _
if !found {
signingInfo := types.NewValidatorSigningInfo(
address,
ctx.BlockHeight(),
0,
time.Unix(0, 0),
false,
0,
0,
)
k.SetValidatorSigningInfo(ctx, address, signingInfo)
}
Expand Down
Loading