stake efficiency case, return early below cliff
This commit is contained in:
parent
41458956a1
commit
26695afe9f
|
@ -227,7 +227,8 @@ func (k Keeper) updateValidator(ctx sdk.Context, validator Validator) Validator
|
||||||
if oldFound {
|
if oldFound {
|
||||||
store.Delete(GetValidatorsByPowerKey(oldValidator, pool))
|
store.Delete(GetValidatorsByPowerKey(oldValidator, pool))
|
||||||
}
|
}
|
||||||
store.Set(GetValidatorsByPowerKey(validator, pool), validator.Owner)
|
valPower := GetValidatorsByPowerKey(validator, pool)
|
||||||
|
store.Set(valPower, validator.Owner)
|
||||||
|
|
||||||
// efficiency case:
|
// efficiency case:
|
||||||
// if already bonded and power increasing only need to update tendermint
|
// if already bonded and power increasing only need to update tendermint
|
||||||
|
@ -237,8 +238,14 @@ func (k Keeper) updateValidator(ctx sdk.Context, validator Validator) Validator
|
||||||
return validator
|
return validator
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO efficiency case:
|
// efficiency case:
|
||||||
// if was unbonded/or is a new validator - and the new power is less than the cliff validator
|
// if was unbonded/or is a new validator - and the new power is less than the cliff validator
|
||||||
|
cliffPower := k.getCliffValidatorPower(ctx)
|
||||||
|
if cliffPower != nil &&
|
||||||
|
(!oldFound || (oldFound && oldValidator.Status() == sdk.Unbonded)) &&
|
||||||
|
bytes.Compare(valPower, cliffPower) == -1 { //(valPower < cliffPower
|
||||||
|
return validator
|
||||||
|
}
|
||||||
|
|
||||||
// update the validator set for this validator
|
// update the validator set for this validator
|
||||||
updatedVal := k.updateBondedValidatorsNew(ctx, store, validator)
|
updatedVal := k.updateBondedValidatorsNew(ctx, store, validator)
|
||||||
|
@ -282,8 +289,13 @@ func (k Keeper) updateBondedValidatorsNew(ctx sdk.Context, store sdk.KVStore,
|
||||||
maxValidators := k.GetParams(ctx).MaxValidators
|
maxValidators := k.GetParams(ctx).MaxValidators
|
||||||
iterator = store.ReverseSubspaceIterator(ValidatorsByPowerKey) // largest to smallest
|
iterator = store.ReverseSubspaceIterator(ValidatorsByPowerKey) // largest to smallest
|
||||||
i := 0
|
i := 0
|
||||||
|
var validator Validator
|
||||||
for ; ; i++ {
|
for ; ; i++ {
|
||||||
if !iterator.Valid() || i > int(maxValidators-1) {
|
if !iterator.Valid() || i > int(maxValidators-1) {
|
||||||
|
|
||||||
|
if i-1 == int(maxValidators-1) {
|
||||||
|
k.setCliffValidatorPower(ctx, validator, k.GetPool(ctx))
|
||||||
|
}
|
||||||
iterator.Close()
|
iterator.Close()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -293,7 +305,6 @@ func (k Keeper) updateBondedValidatorsNew(ctx sdk.Context, store sdk.KVStore,
|
||||||
// use the validator provided because it has not yet been updated
|
// use the validator provided because it has not yet been updated
|
||||||
// in the main validator store
|
// in the main validator store
|
||||||
ownerAddr := iterator.Value()
|
ownerAddr := iterator.Value()
|
||||||
var validator Validator
|
|
||||||
if bytes.Equal(ownerAddr, newValidator.Owner) {
|
if bytes.Equal(ownerAddr, newValidator.Owner) {
|
||||||
validator = newValidator
|
validator = newValidator
|
||||||
} else {
|
} else {
|
||||||
|
@ -562,6 +573,21 @@ func (k Keeper) setIntraTxCounter(ctx sdk.Context, counter int16) {
|
||||||
|
|
||||||
//__________________________________________________________________________
|
//__________________________________________________________________________
|
||||||
|
|
||||||
|
// get the current power of the validator on the cliff
|
||||||
|
func (k Keeper) getCliffValidatorPower(ctx sdk.Context) []byte {
|
||||||
|
store := ctx.KVStore(k.storeKey)
|
||||||
|
return store.Get(ValidatorCliffKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the current power of the validator on the cliff
|
||||||
|
func (k Keeper) setCliffValidatorPower(ctx sdk.Context, validator Validator, pool Pool) {
|
||||||
|
store := ctx.KVStore(k.storeKey)
|
||||||
|
bz := GetValidatorsByPowerKey(validator, pool)
|
||||||
|
store.Set(ValidatorCliffKey, bz)
|
||||||
|
}
|
||||||
|
|
||||||
|
//__________________________________________________________________________
|
||||||
|
|
||||||
// Implements ValidatorSet
|
// Implements ValidatorSet
|
||||||
|
|
||||||
var _ sdk.ValidatorSet = Keeper{}
|
var _ sdk.ValidatorSet = Keeper{}
|
||||||
|
|
|
@ -18,9 +18,10 @@ var (
|
||||||
ValidatorsKey = []byte{0x02} // prefix for each key to a validator
|
ValidatorsKey = []byte{0x02} // prefix for each key to a validator
|
||||||
ValidatorsBondedKey = []byte{0x03} // prefix for each key to bonded/actively validating validators
|
ValidatorsBondedKey = []byte{0x03} // prefix for each key to bonded/actively validating validators
|
||||||
ValidatorsByPowerKey = []byte{0x04} // prefix for each key to a validator sorted by power
|
ValidatorsByPowerKey = []byte{0x04} // prefix for each key to a validator sorted by power
|
||||||
TendermintUpdatesKey = []byte{0x05} // prefix for each key to a validator which is being updated
|
ValidatorCliffKey = []byte{0x05} // key for block-local tx index
|
||||||
DelegationKey = []byte{0x06} // prefix for each key to a delegator's bond
|
TendermintUpdatesKey = []byte{0x06} // prefix for each key to a validator which is being updated
|
||||||
IntraTxCounterKey = []byte{0x07} // key for block-local tx index
|
DelegationKey = []byte{0x07} // prefix for each key to a delegator's bond
|
||||||
|
IntraTxCounterKey = []byte{0x08} // key for block-local tx index
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxDigitsForAccount = 12 // ~220,000,000 atoms created at launch
|
const maxDigitsForAccount = 12 // ~220,000,000 atoms created at launch
|
||||||
|
@ -51,7 +52,7 @@ func GetValidatorsByPowerKey(validator Validator, pool Pool) []byte {
|
||||||
return append(ValidatorsByPowerKey,
|
return append(ValidatorsByPowerKey,
|
||||||
append(powerBytes,
|
append(powerBytes,
|
||||||
append(heightBytes,
|
append(heightBytes,
|
||||||
append(counterBytes, validator.Owner.Bytes()...)...)...)...)
|
append(counterBytes, validator.Owner.Bytes()...)...)...)...) // TODO don't technically need to store owner
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the key for the accumulated update validators
|
// get the key for the accumulated update validators
|
||||||
|
|
Loading…
Reference in New Issue