Further clarification of nomenclature

This commit is contained in:
Christopher Goes 2018-10-15 21:20:37 +02:00
parent 6e0f3d6baf
commit 096a8bb9ec
3 changed files with 29 additions and 15 deletions

View File

@ -9,10 +9,10 @@ import (
// key prefix bytes
var (
ValidatorSigningInfoKey = []byte{0x01} // Prefix for signing info
ValidatorSigningBitArrayKey = []byte{0x02} // Prefix for signature bit array
ValidatorSlashingPeriodKey = []byte{0x03} // Prefix for slashing period
AddrPubkeyRelationKey = []byte{0x04} // Prefix for address-pubkey relation
ValidatorSigningInfoKey = []byte{0x01} // Prefix for signing info
ValidatorMissedBlockBitArrayKey = []byte{0x02} // Prefix for missed block bit array
ValidatorSlashingPeriodKey = []byte{0x03} // Prefix for slashing period
AddrPubkeyRelationKey = []byte{0x04} // Prefix for address-pubkey relation
)
// stored by *Tendermint* address (not operator address)
@ -21,10 +21,15 @@ func GetValidatorSigningInfoKey(v sdk.ConsAddress) []byte {
}
// 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)
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)

View File

@ -28,23 +28,32 @@ func (k Keeper) setValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress
}
// 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)
bz := store.Get(GetValidatorSigningBitArrayKey(address, index))
bz := store.Get(GetValidatorMissedBlockBitArrayKey(address, index))
if bz == nil {
// lazy: treat empty key as unsigned
signed = false
// lazy: treat empty key as not missed
missed = false
return
}
k.cdc.MustUnmarshalBinary(bz, &signed)
k.cdc.MustUnmarshalBinary(bz, &missed)
return
}
// 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)
bz := k.cdc.MustMarshalBinary(signed)
store.Set(GetValidatorSigningBitArrayKey(address, index), bz)
bz := k.cdc.MustMarshalBinary(missed)
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

View File

@ -28,7 +28,7 @@ func TestGetSetValidatorSigningInfo(t *testing.T) {
require.Equal(t, info.MissedBlocksCounter, int64(10))
}
func TestGetSetValidatorSigningBitArray(t *testing.T) {
func TestGetSetValidatorMissedBlockBitArray(t *testing.T) {
ctx, _, _, _, keeper := createTestInput(t, DefaultParams())
missed := keeper.getValidatorMissedBlockBitArray(ctx, sdk.ConsAddress(addrs[0]), 0)
require.False(t, missed) // treat empty key as not missed