Further clarification of nomenclature
This commit is contained in:
parent
6e0f3d6baf
commit
096a8bb9ec
|
@ -9,10 +9,10 @@ import (
|
||||||
|
|
||||||
// key prefix bytes
|
// key prefix bytes
|
||||||
var (
|
var (
|
||||||
ValidatorSigningInfoKey = []byte{0x01} // Prefix for signing info
|
ValidatorSigningInfoKey = []byte{0x01} // Prefix for signing info
|
||||||
ValidatorSigningBitArrayKey = []byte{0x02} // Prefix for signature bit array
|
ValidatorMissedBlockBitArrayKey = []byte{0x02} // Prefix for missed block bit array
|
||||||
ValidatorSlashingPeriodKey = []byte{0x03} // Prefix for slashing period
|
ValidatorSlashingPeriodKey = []byte{0x03} // Prefix for slashing period
|
||||||
AddrPubkeyRelationKey = []byte{0x04} // Prefix for address-pubkey relation
|
AddrPubkeyRelationKey = []byte{0x04} // Prefix for address-pubkey relation
|
||||||
)
|
)
|
||||||
|
|
||||||
// stored by *Tendermint* address (not operator address)
|
// stored by *Tendermint* address (not operator address)
|
||||||
|
@ -21,10 +21,15 @@ func GetValidatorSigningInfoKey(v sdk.ConsAddress) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
// stored by *Tendermint* address (not operator address)
|
// stored by *Tendermint* address (not operator address)
|
||||||
func GetValidatorSigningBitArrayKey(v sdk.ConsAddress, i int64) []byte {
|
func GetValidatorMissedBlockBitArrayPrefixKey(v sdk.ConsAddress) []byte {
|
||||||
|
return append(ValidatorMissedBlockBitArrayKey, v.Bytes()...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// stored by *Tendermint* address (not operator address)
|
||||||
|
func GetValidatorMissedBlockBitArrayKey(v sdk.ConsAddress, i int64) []byte {
|
||||||
b := make([]byte, 8)
|
b := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(b, uint64(i))
|
binary.LittleEndian.PutUint64(b, uint64(i))
|
||||||
return append(ValidatorSigningBitArrayKey, append(v.Bytes(), b...)...)
|
return append(GetValidatorMissedBlockBitArrayPrefixKey(v), b...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// stored by *Tendermint* address (not operator address)
|
// stored by *Tendermint* address (not operator address)
|
||||||
|
|
|
@ -28,23 +28,32 @@ func (k Keeper) setValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stored by *validator* address (not operator address)
|
// Stored by *validator* address (not operator address)
|
||||||
func (k Keeper) getValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64) (signed bool) {
|
func (k Keeper) getValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64) (missed bool) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz := store.Get(GetValidatorSigningBitArrayKey(address, index))
|
bz := store.Get(GetValidatorMissedBlockBitArrayKey(address, index))
|
||||||
if bz == nil {
|
if bz == nil {
|
||||||
// lazy: treat empty key as unsigned
|
// lazy: treat empty key as not missed
|
||||||
signed = false
|
missed = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
k.cdc.MustUnmarshalBinary(bz, &signed)
|
k.cdc.MustUnmarshalBinary(bz, &missed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stored by *validator* address (not operator address)
|
// Stored by *validator* address (not operator address)
|
||||||
func (k Keeper) setValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64, signed bool) {
|
func (k Keeper) setValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64, missed bool) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz := k.cdc.MustMarshalBinary(signed)
|
bz := k.cdc.MustMarshalBinary(missed)
|
||||||
store.Set(GetValidatorSigningBitArrayKey(address, index), bz)
|
store.Set(GetValidatorMissedBlockBitArrayKey(address, index), bz)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stored by *validator* address (not operator address)
|
||||||
|
func (k Keeper) clearValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress) {
|
||||||
|
store := ctx.KVStore(k.storeKey)
|
||||||
|
iter := sdk.KVStorePrefixIterator(store, GetValidatorMissedBlockBitArrayPrefixKey(address))
|
||||||
|
for ; iter.Valid(); iter.Next() {
|
||||||
|
store.Delete(iter.Key())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct a new `ValidatorSigningInfo` struct
|
// Construct a new `ValidatorSigningInfo` struct
|
||||||
|
|
|
@ -28,7 +28,7 @@ func TestGetSetValidatorSigningInfo(t *testing.T) {
|
||||||
require.Equal(t, info.MissedBlocksCounter, int64(10))
|
require.Equal(t, info.MissedBlocksCounter, int64(10))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetSetValidatorSigningBitArray(t *testing.T) {
|
func TestGetSetValidatorMissedBlockBitArray(t *testing.T) {
|
||||||
ctx, _, _, _, keeper := createTestInput(t, DefaultParams())
|
ctx, _, _, _, keeper := createTestInput(t, DefaultParams())
|
||||||
missed := keeper.getValidatorMissedBlockBitArray(ctx, sdk.ConsAddress(addrs[0]), 0)
|
missed := keeper.getValidatorMissedBlockBitArray(ctx, sdk.ConsAddress(addrs[0]), 0)
|
||||||
require.False(t, missed) // treat empty key as not missed
|
require.False(t, missed) // treat empty key as not missed
|
||||||
|
|
Loading…
Reference in New Issue