Further clarification of nomenclature
This commit is contained in:
parent
6e0f3d6baf
commit
096a8bb9ec
|
@ -10,7 +10,7 @@ import (
|
|||
// key prefix bytes
|
||||
var (
|
||||
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
|
||||
AddrPubkeyRelationKey = []byte{0x04} // Prefix for address-pubkey relation
|
||||
)
|
||||
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue