Skip to content

Commit eb1ac22

Browse files
perf!: Make slashing not write sign info every block (SDK: cosmos#19458) (#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>
1 parent f0739cd commit eb1ac22

File tree

15 files changed

+162
-149
lines changed

15 files changed

+162
-149
lines changed

api/cosmos/slashing/v1beta1/slashing.pulsar.go

Lines changed: 67 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/cosmos/slashing/v1beta1/slashing.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ message ValidatorSigningInfo {
1818
string address = 1 [(cosmos_proto.scalar) = "cosmos.ConsensusAddressString"];
1919
// Height at which validator was first a candidate OR was un-jailed
2020
int64 start_height = 2;
21-
// Index which is incremented every time a validator is bonded in a block and
21+
// DEPRECATED: Index which is incremented every time a validator is bonded in a block and
2222
// _may_ have signed a pre-commit or not. This in conjunction with the
2323
// signed_blocks_window param determines the index in the missed block bitmap.
24-
int64 index_offset = 3;
24+
int64 index_offset = 3 [deprecated = true];
2525
// Timestamp until which the validator is jailed due to liveness downtime.
2626
google.protobuf.Timestamp jailed_until = 4
2727
[(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (amino.dont_omitempty) = true];

tests/integration/slashing/keeper/keeper_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ func initFixture(t testing.TB) *fixture {
119119
addrDels := simtestutil.AddTestAddrsIncremental(bankKeeper, stakingKeeper, sdkCtx, 6, stakingKeeper.TokensFromConsensusPower(sdkCtx, 200))
120120
valAddrs := simtestutil.ConvertAddrsToValAddrs(addrDels)
121121

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

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

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

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

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

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

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

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

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

359-
info := slashingtypes.NewValidatorSigningInfo(consAddr, f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
358+
info := slashingtypes.NewValidatorSigningInfo(consAddr, f.ctx.BlockHeight(), time.Unix(0, 0), false, int64(0))
360359
assert.NilError(t, f.slashingKeeper.SetValidatorSigningInfo(f.ctx, consAddr, info))
361360

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

420-
info = slashingtypes.NewValidatorSigningInfo(consAddr, f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
419+
info = slashingtypes.NewValidatorSigningInfo(consAddr, f.ctx.BlockHeight(), time.Unix(0, 0), false, int64(0))
421420
err = f.slashingKeeper.SetValidatorSigningInfo(f.ctx, consAddr, info)
422421
assert.NilError(t, err)
423422

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

431429
// some blocks pass
432430
height = int64(5000)
433431
f.ctx = f.ctx.WithBlockHeight(height)
434432

435-
info = slashingtypes.NewValidatorSigningInfo(consAddr, f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
433+
info = slashingtypes.NewValidatorSigningInfo(consAddr, f.ctx.BlockHeight(), time.Unix(0, 0), false, int64(0))
436434
err = f.slashingKeeper.SetValidatorSigningInfo(f.ctx, consAddr, info)
437435
assert.NilError(t, err)
438436

0 commit comments

Comments
 (0)