Address PR comments: test descriptions & NewValidatorSigningInfo
This commit is contained in:
parent
b9c1bcbd74
commit
ee17b7c9cc
|
@ -58,8 +58,8 @@ func (k Keeper) handleValidatorSignature(ctx sdk.Context, pubkey crypto.PubKey,
|
||||||
// Will use the 0-value default signing info if not present, except for start height
|
// Will use the 0-value default signing info if not present, except for start height
|
||||||
signInfo, found := k.getValidatorSigningInfo(ctx, address)
|
signInfo, found := k.getValidatorSigningInfo(ctx, address)
|
||||||
if !found {
|
if !found {
|
||||||
// If this validator has never been seen before, set the start height
|
// If this validator has never been seen before, construct a new SigningInfo with the correct start height
|
||||||
signInfo.StartHeight = height
|
signInfo = NewValidatorSigningInfo(height, 0, 0, 0)
|
||||||
}
|
}
|
||||||
index := signInfo.IndexOffset % SignedBlocksWindow
|
index := signInfo.IndexOffset % SignedBlocksWindow
|
||||||
signInfo.IndexOffset++
|
signInfo.IndexOffset++
|
||||||
|
|
|
@ -11,6 +11,8 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Test that a validator is slashed correctly
|
||||||
|
// when we discover evidence of equivocation
|
||||||
func TestHandleDoubleSign(t *testing.T) {
|
func TestHandleDoubleSign(t *testing.T) {
|
||||||
|
|
||||||
// initial setup
|
// initial setup
|
||||||
|
@ -32,6 +34,8 @@ func TestHandleDoubleSign(t *testing.T) {
|
||||||
require.Equal(t, sdk.NewRat(amt).Mul(sdk.NewRat(19).Quo(sdk.NewRat(20))), sk.Validator(ctx, addr).GetPower())
|
require.Equal(t, sdk.NewRat(amt).Mul(sdk.NewRat(19).Quo(sdk.NewRat(20))), sk.Validator(ctx, addr).GetPower())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test a validator through uptime, downtime, revocation,
|
||||||
|
// unrevocation, starting height reset, and revocation again
|
||||||
func TestHandleAbsentValidator(t *testing.T) {
|
func TestHandleAbsentValidator(t *testing.T) {
|
||||||
|
|
||||||
// initial setup
|
// initial setup
|
||||||
|
@ -130,6 +134,9 @@ func TestHandleAbsentValidator(t *testing.T) {
|
||||||
require.Equal(t, sdk.Unbonded, validator.GetStatus())
|
require.Equal(t, sdk.Unbonded, validator.GetStatus())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test a new validator entering the validator set
|
||||||
|
// Ensure that SigningInfo.StartHeight is set correctly
|
||||||
|
// and that they are not immediately revoked
|
||||||
func TestHandleNewValidator(t *testing.T) {
|
func TestHandleNewValidator(t *testing.T) {
|
||||||
// initial setup
|
// initial setup
|
||||||
ctx, ck, sk, keeper := createTestInput(t)
|
ctx, ck, sk, keeper := createTestInput(t)
|
||||||
|
|
|
@ -47,6 +47,16 @@ func (k Keeper) setValidatorSigningBitArray(ctx sdk.Context, address sdk.Address
|
||||||
store.Set(GetValidatorSigningBitArrayKey(address, index), bz)
|
store.Set(GetValidatorSigningBitArrayKey(address, index), bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Construct a new `ValidatorSigningInfo` struct
|
||||||
|
func NewValidatorSigningInfo(startHeight int64, indexOffset int64, jailedUntil int64, signedBlocksCounter int64) ValidatorSigningInfo {
|
||||||
|
return ValidatorSigningInfo{
|
||||||
|
StartHeight: startHeight,
|
||||||
|
IndexOffset: indexOffset,
|
||||||
|
JailedUntil: jailedUntil,
|
||||||
|
SignedBlocksCounter: signedBlocksCounter,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Signing info for a validator
|
// Signing info for a validator
|
||||||
type ValidatorSigningInfo struct {
|
type ValidatorSigningInfo struct {
|
||||||
StartHeight int64 `json:"start_height"` // height at which validator was first a candidate OR was unrevoked
|
StartHeight int64 `json:"start_height"` // height at which validator was first a candidate OR was unrevoked
|
||||||
|
|
Loading…
Reference in New Issue