Skip to content

Commit

Permalink
perf!: Make slashing not write sign info every block (SDK: cosmos#19458
Browse files Browse the repository at this point in the history
…) (#543)

* perf!: Make slashing not write sign info every block (SDK: cosmos#19458)

cosmos#19458

* change NewSignInfo API

* Bring back String() change

* Fix test

* Another test fix that didn't get committed

* merge conflict

---------

Co-authored-by: Adam Tucker <adam@osmosis.team>
Co-authored-by: Adam Tucker <adamleetucker@outlook.com>
  • Loading branch information
3 people committed May 9, 2024
1 parent f0739cd commit eb1ac22
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 149 deletions.
130 changes: 67 additions & 63 deletions api/cosmos/slashing/v1beta1/slashing.pulsar.go

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

4 changes: 2 additions & 2 deletions proto/cosmos/slashing/v1beta1/slashing.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ message ValidatorSigningInfo {
string address = 1 [(cosmos_proto.scalar) = "cosmos.ConsensusAddressString"];
// Height at which validator was first a candidate OR was un-jailed
int64 start_height = 2;
// Index which is incremented every time a validator is bonded in a block and
// DEPRECATED: Index which is incremented every time a validator is bonded in a block and
// _may_ have signed a pre-commit or not. This in conjunction with the
// signed_blocks_window param determines the index in the missed block bitmap.
int64 index_offset = 3;
int64 index_offset = 3 [deprecated = true];
// Timestamp until which the validator is jailed due to liveness downtime.
google.protobuf.Timestamp jailed_until = 4
[(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (amino.dont_omitempty) = true];
Expand Down
16 changes: 7 additions & 9 deletions tests/integration/slashing/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func initFixture(t testing.TB) *fixture {
addrDels := simtestutil.AddTestAddrsIncremental(bankKeeper, stakingKeeper, sdkCtx, 6, stakingKeeper.TokensFromConsensusPower(sdkCtx, 200))
valAddrs := simtestutil.ConvertAddrsToValAddrs(addrDels)

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

slashingKeeper.SetValidatorSigningInfo(sdkCtx, sdk.ConsAddress(addrDels[0]), info1)
slashingKeeper.SetValidatorSigningInfo(sdkCtx, sdk.ConsAddress(addrDels[1]), info2)
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestHandleNewValidator(t *testing.T) {

assert.NilError(t, f.slashingKeeper.AddPubkey(f.ctx, pks[0]))

info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(valpubkey.Address()), f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(valpubkey.Address()), f.ctx.BlockHeight(), time.Unix(0, 0), false, int64(0))
assert.NilError(t, f.slashingKeeper.SetValidatorSigningInfo(f.ctx, sdk.ConsAddress(valpubkey.Address()), info))

// Validator created
Expand Down Expand Up @@ -257,7 +257,6 @@ func TestHandleNewValidator(t *testing.T) {
info, found := f.slashingKeeper.GetValidatorSigningInfo(f.ctx, sdk.ConsAddress(valpubkey.Address()))
assert.Assert(t, found)
assert.Equal(t, signedBlocksWindow+1, info.StartHeight)
assert.Equal(t, int64(2), info.IndexOffset)
assert.Equal(t, int64(1), info.MissedBlocksCounter)
assert.Equal(t, time.Unix(0, 0).UTC(), info.JailedUntil)

Expand All @@ -283,7 +282,7 @@ func TestHandleAlreadyJailed(t *testing.T) {
err := f.slashingKeeper.AddPubkey(f.ctx, pks[0])
assert.NilError(t, err)

info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(val.Address()), f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(val.Address()), f.ctx.BlockHeight(), time.Unix(0, 0), false, int64(0))
assert.NilError(t, f.slashingKeeper.SetValidatorSigningInfo(f.ctx, sdk.ConsAddress(val.Address()), info))

amt := tstaking.CreateValidatorWithValPower(addr, val, power, true)
Expand Down Expand Up @@ -356,7 +355,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {

assert.NilError(t, f.slashingKeeper.AddPubkey(f.ctx, pks[0]))

info := slashingtypes.NewValidatorSigningInfo(consAddr, f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
info := slashingtypes.NewValidatorSigningInfo(consAddr, f.ctx.BlockHeight(), time.Unix(0, 0), false, int64(0))
assert.NilError(t, f.slashingKeeper.SetValidatorSigningInfo(f.ctx, consAddr, info))

tstaking.CreateValidatorWithValPower(valAddr, val, power, true)
Expand Down Expand Up @@ -417,7 +416,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
assert.NilError(t, err)
tstaking.CheckValidator(valAddr, stakingtypes.Unbonding, true)

info = slashingtypes.NewValidatorSigningInfo(consAddr, f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
info = slashingtypes.NewValidatorSigningInfo(consAddr, f.ctx.BlockHeight(), time.Unix(0, 0), false, int64(0))
err = f.slashingKeeper.SetValidatorSigningInfo(f.ctx, consAddr, info)
assert.NilError(t, err)

Expand All @@ -426,13 +425,12 @@ func TestValidatorDippingInAndOut(t *testing.T) {
assert.Assert(t, found)
assert.Equal(t, int64(700), signInfo.StartHeight)
assert.Equal(t, int64(0), signInfo.MissedBlocksCounter)
assert.Equal(t, int64(0), signInfo.IndexOffset)

// some blocks pass
height = int64(5000)
f.ctx = f.ctx.WithBlockHeight(height)

info = slashingtypes.NewValidatorSigningInfo(consAddr, f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
info = slashingtypes.NewValidatorSigningInfo(consAddr, f.ctx.BlockHeight(), time.Unix(0, 0), false, int64(0))
err = f.slashingKeeper.SetValidatorSigningInfo(f.ctx, consAddr, info)
assert.NilError(t, err)

Expand Down
Loading

0 comments on commit eb1ac22

Please sign in to comment.