bez updates
This commit is contained in:
parent
c21e6a0642
commit
e8e5e8c600
|
@ -191,9 +191,11 @@ func (k Keeper) ClearTendermintUpdates(ctx sdk.Context) {
|
||||||
|
|
||||||
//___________________________________________________________________________
|
//___________________________________________________________________________
|
||||||
|
|
||||||
// perfom all the nessisary steps for when a validator changes its power
|
// Perfom all the nessisary steps for when a validator changes its power. This
|
||||||
// updates all validator stores as well as tendermint update store
|
// function updates all validator stores as well as tendermint update store.
|
||||||
// may kick out validators if new validator is entering the bonded validator group
|
// It may kick out validators if new validator is entering the bonded validator
|
||||||
|
// group.
|
||||||
|
//
|
||||||
// nolint: gocyclo
|
// nolint: gocyclo
|
||||||
// TODO: Remove above nolint, function needs to be simplified
|
// TODO: Remove above nolint, function needs to be simplified
|
||||||
func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) types.Validator {
|
func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) types.Validator {
|
||||||
|
@ -203,7 +205,7 @@ func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) type
|
||||||
|
|
||||||
validator = k.updateForRevoking(ctx, oldFound, oldValidator, validator)
|
validator = k.updateForRevoking(ctx, oldFound, oldValidator, validator)
|
||||||
powerIncreasing := k.getPowerIncreasing(ctx, oldFound, oldValidator, validator)
|
powerIncreasing := k.getPowerIncreasing(ctx, oldFound, oldValidator, validator)
|
||||||
validator.BondHeight, validator.BondIntraTxCounter = k.getBondDetails(ctx, oldFound, oldValidator, validator)
|
validator.BondHeight, validator.BondIntraTxCounter = k.bondIncrement(ctx, oldFound, oldValidator, validator)
|
||||||
valPower := k.updateValidatorPower(ctx, oldFound, oldValidator, validator, pool)
|
valPower := k.updateValidatorPower(ctx, oldFound, oldValidator, validator, pool)
|
||||||
cliffPower := k.GetCliffValidatorPower(ctx)
|
cliffPower := k.GetCliffValidatorPower(ctx)
|
||||||
|
|
||||||
|
@ -228,8 +230,8 @@ func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) type
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// update the validator set for this validator
|
// update the validator set for this validator
|
||||||
updatedVal := k.UpdateBondedValidators(ctx, validator)
|
updatedVal, updated := k.UpdateBondedValidators(ctx, validator)
|
||||||
if updatedVal.Owner != nil { // updates to validator occurred to be updated
|
if updated { // updates to validator occurred to be updated
|
||||||
validator = updatedVal
|
validator = updatedVal
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -266,7 +268,8 @@ func (k Keeper) getPowerIncreasing(ctx sdk.Context, oldFound bool, oldValidator,
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Keeper) getBondDetails(ctx sdk.Context, oldFound bool, oldValidator,
|
// get the bond height and incremented intra-tx counter
|
||||||
|
func (k Keeper) bondIncrement(ctx sdk.Context, oldFound bool, oldValidator,
|
||||||
newValidator types.Validator) (height int64, intraTxCounter int16) {
|
newValidator types.Validator) (height int64, intraTxCounter int16) {
|
||||||
|
|
||||||
// if already a validator, copy the old block height and counter, else set them
|
// if already a validator, copy the old block height and counter, else set them
|
||||||
|
@ -296,25 +299,22 @@ func (k Keeper) updateValidatorPower(ctx sdk.Context, oldFound bool, oldValidato
|
||||||
return valPower
|
return valPower
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the validator group and kick out any old validators. In addition this
|
// Update the bonded validator group based on a change to the validator
|
||||||
// function adds (or doesn't add) a validator which has updated its bonded
|
// affectedValidator. This function potentially adds the affectedValidator to
|
||||||
// tokens to the validator group. -> this validator is specified through the
|
// the bonded validator group which kicks out the cliff validator. Under this
|
||||||
// updatedValidatorAddr term.
|
// situation this function returns the updated affectedValidator.
|
||||||
//
|
//
|
||||||
// The correct subset is retrieved by iterating through an index of the
|
// The correct bonded subset of validators is retrieved by iterating through an
|
||||||
// validators sorted by power, stored using the ValidatorsByPowerIndexKey.
|
// index of the validators sorted by power, stored using the
|
||||||
// Simultaneously the current validator records are updated in store with the
|
// ValidatorsByPowerIndexKey. Simultaneously the current validator records are
|
||||||
// ValidatorsBondedIndexKey. This store is used to determine if a validator is
|
// updated in store with the ValidatorsBondedIndexKey. This store is used to
|
||||||
// a validator without needing to iterate over the subspace as we do in
|
// determine if a validator is a validator without needing to iterate over all
|
||||||
// GetValidators.
|
// validators.
|
||||||
//
|
|
||||||
// Optionally also return the validator from a retrieve address if the
|
|
||||||
// validator has been bonded
|
|
||||||
//
|
//
|
||||||
// nolint: gocyclo
|
// nolint: gocyclo
|
||||||
// TODO: Remove the above golint
|
// TODO: Remove the above golint
|
||||||
func (k Keeper) UpdateBondedValidators(ctx sdk.Context,
|
func (k Keeper) UpdateBondedValidators(ctx sdk.Context,
|
||||||
affectedValidator types.Validator) (updatedVal types.Validator) {
|
affectedValidator types.Validator) (updatedVal types.Validator, updated bool) {
|
||||||
|
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
|
|
||||||
|
@ -322,6 +322,7 @@ func (k Keeper) UpdateBondedValidators(ctx sdk.Context,
|
||||||
maxValidators := k.GetParams(ctx).MaxValidators
|
maxValidators := k.GetParams(ctx).MaxValidators
|
||||||
bondedValidatorsCount := 0
|
bondedValidatorsCount := 0
|
||||||
var validator, validatorToBond types.Validator
|
var validator, validatorToBond types.Validator
|
||||||
|
newValidatorBonded := false
|
||||||
|
|
||||||
iterator := sdk.KVStoreReversePrefixIterator(store, ValidatorsByPowerIndexKey) // largest to smallest
|
iterator := sdk.KVStoreReversePrefixIterator(store, ValidatorsByPowerIndexKey) // largest to smallest
|
||||||
for {
|
for {
|
||||||
|
@ -347,6 +348,7 @@ func (k Keeper) UpdateBondedValidators(ctx sdk.Context,
|
||||||
if !validator.Revoked {
|
if !validator.Revoked {
|
||||||
if validator.Status() != sdk.Bonded {
|
if validator.Status() != sdk.Bonded {
|
||||||
validatorToBond = validator
|
validatorToBond = validator
|
||||||
|
newValidatorBonded = true
|
||||||
}
|
}
|
||||||
bondedValidatorsCount++
|
bondedValidatorsCount++
|
||||||
|
|
||||||
|
@ -366,8 +368,8 @@ func (k Keeper) UpdateBondedValidators(ctx sdk.Context,
|
||||||
k.clearCliffValidator(ctx)
|
k.clearCliffValidator(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform the validator swap for any new validators to add
|
// swap the cliff validator for a new validator if the affected validator was bonded
|
||||||
if len(validatorToBond.Owner) > 0 {
|
if newValidatorBonded {
|
||||||
|
|
||||||
// unbond the cliff validator
|
// unbond the cliff validator
|
||||||
if oldCliffValidatorAddr != nil {
|
if oldCliffValidatorAddr != nil {
|
||||||
|
@ -382,10 +384,10 @@ func (k Keeper) UpdateBondedValidators(ctx sdk.Context,
|
||||||
// bond the new validator
|
// bond the new validator
|
||||||
validator = k.bondValidator(ctx, validatorToBond)
|
validator = k.bondValidator(ctx, validatorToBond)
|
||||||
if bytes.Equal(validator.Owner, affectedValidator.Owner) {
|
if bytes.Equal(validator.Owner, affectedValidator.Owner) {
|
||||||
updatedVal = validator
|
return validator, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return Validator{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// full update of the bonded validator set, many can be added/kicked
|
// full update of the bonded validator set, many can be added/kicked
|
||||||
|
|
Loading…
Reference in New Issue