Skip to content

Commit

Permalink
0.24.1 - Fix validator pubkey bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes committed Aug 21, 2018
1 parent d5652d9 commit e2691d9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.24.1

*August 21st, 2018*

BUG FIXES

* Gaia
- [x/slashing] Evidence tracking now uses validator address instead of validator pubkey

## 0.24.0

*August 13th, 2018*
Expand Down
4 changes: 2 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package version

const Maj = "0"
const Min = "24"
const Fix = "0"
const Fix = "1"

const Version = "0.24.0"
const Version = "0.24.1"

// GitCommit set by build flags
var GitCommit = ""
8 changes: 6 additions & 2 deletions x/slashing/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, vs sdk.ValidatorSet, params pa
}

// handle a validator signing two blocks at the same height
func (k Keeper) handleDoubleSign(ctx sdk.Context, pubkey crypto.PubKey, infractionHeight int64, timestamp time.Time, power int64) {
func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractionHeight int64, timestamp time.Time, power int64) {
logger := ctx.Logger().With("module", "x/slashing")
time := ctx.BlockHeader().Time
age := time.Sub(timestamp)
address := sdk.ValAddress(pubkey.Address())
address := sdk.ValAddress(addr)
pubkey, err := k.getPubkey(ctx, addr)
if err != nil {
panic(fmt.Sprintf("Validator address %v not found", addr))
}

// Double sign too old
maxEvidenceAge := k.MaxEvidenceAge(ctx)
Expand Down
4 changes: 2 additions & 2 deletions x/slashing/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestHandleDoubleSign(t *testing.T) {
keeper.handleValidatorSignature(ctx, val.Address(), amtInt, true)

// double sign less than max age
keeper.handleDoubleSign(ctx, val, 0, time.Unix(0, 0), amtInt)
keeper.handleDoubleSign(ctx, val.Address(), 0, time.Unix(0, 0), amtInt)

// should be revoked
require.True(t, sk.Validator(ctx, addr).GetRevoked())
Expand All @@ -48,7 +48,7 @@ func TestHandleDoubleSign(t *testing.T) {
ctx = ctx.WithBlockHeader(abci.Header{Time: time.Unix(1, 0).Add(keeper.MaxEvidenceAge(ctx))})

// double sign past max age
keeper.handleDoubleSign(ctx, val, 0, time.Unix(0, 0), amtInt)
keeper.handleDoubleSign(ctx, val.Address(), 0, time.Unix(0, 0), amtInt)
require.Equal(t, sdk.NewRatFromInt(amt).Mul(sdk.NewRat(19).Quo(sdk.NewRat(20))), sk.Validator(ctx, addr).GetPower())
}

Expand Down
6 changes: 1 addition & 5 deletions x/slashing/tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, sk Keeper) (tags
// Slash any validators (and since-unbonded stake within the unbonding period)
// who contributed to valid infractions
for _, evidence := range req.ByzantineValidators {
pk, err := tmtypes.PB2TM.PubKey(evidence.Validator.PubKey)
if err != nil {
panic(err)
}
switch evidence.Type {
case tmtypes.ABCIEvidenceTypeDuplicateVote:
sk.handleDoubleSign(ctx, pk, evidence.Height, evidence.Time, evidence.Validator.Power)
sk.handleDoubleSign(ctx, evidence.Validator.Address, evidence.Height, evidence.Time, evidence.Validator.Power)
default:
ctx.Logger().With("module", "x/slashing").Error(fmt.Sprintf("ignored unknown evidence type: %s", evidence.Type))
}
Expand Down

0 comments on commit e2691d9

Please sign in to comment.