more cwgoes updates

This commit is contained in:
rigelrozanski 2018-05-17 15:48:47 -04:00
parent d442fc5fa9
commit 4cbf253c14
3 changed files with 17 additions and 11 deletions

View File

@ -167,8 +167,8 @@ func (k Keeper) removeValidator(ctx sdk.Context, address sdk.Address) {
store.Delete(GetValidatorKey(address)) store.Delete(GetValidatorKey(address))
store.Delete(GetValidatorsBondedByPowerKey(validator, pool)) store.Delete(GetValidatorsBondedByPowerKey(validator, pool))
// delete from current and power weighted validator groups if the validator // delete from the current and power weighted validator groups if the validator
// exists and add validator with zero power to the validator updates // is bonded - and add validator with zero power to the validator updates
if store.Get(GetValidatorsBondedKey(validator.PubKey)) == nil { if store.Get(GetValidatorsBondedKey(validator.PubKey)) == nil {
return return
} }
@ -190,6 +190,11 @@ func (k Keeper) GetValidatorsBonded(ctx sdk.Context) (validators []Validator) {
iterator := store.SubspaceIterator(ValidatorsBondedKey) iterator := store.SubspaceIterator(ValidatorsBondedKey)
i := 0 i := 0
for ; iterator.Valid(); iterator.Next() { for ; iterator.Valid(); iterator.Next() {
// sanity check
if i > int(maxValidators-1) {
panic("maxValidators is less than the number of records in ValidatorsBonded Store, store should have been updated")
}
bz := iterator.Value() bz := iterator.Value()
var validator Validator var validator Validator
k.cdc.MustUnmarshalBinary(bz, &validator) k.cdc.MustUnmarshalBinary(bz, &validator)
@ -276,7 +281,7 @@ func (k Keeper) updateBondedValidators(ctx sdk.Context, store sdk.KVStore, pool
if found { if found {
// remove from ToKickOut group // remove from ToKickOut group
toKickOut[string(validator.Address)] = nil delete(toKickOut, string(validator.Address))
} else { } else {
// if it wasn't in the toKickOut group it means // if it wasn't in the toKickOut group it means
@ -299,9 +304,6 @@ func (k Keeper) updateBondedValidators(ctx sdk.Context, store sdk.KVStore, pool
// perform the actual kicks // perform the actual kicks
for _, value := range toKickOut { for _, value := range toKickOut {
if value == nil {
continue
}
var validator Validator var validator Validator
k.cdc.MustUnmarshalBinary(value, &validator) k.cdc.MustUnmarshalBinary(value, &validator)
k.unbondValidator(ctx, store, validator) k.unbondValidator(ctx, store, validator)
@ -336,6 +338,9 @@ func (k Keeper) unbondValidator(ctx sdk.Context, store sdk.KVStore, validator Va
// perform all the store operations for when a validator status becomes bonded // perform all the store operations for when a validator status becomes bonded
func (k Keeper) bondValidator(ctx sdk.Context, store sdk.KVStore, validator Validator, pool Pool) Validator { func (k Keeper) bondValidator(ctx sdk.Context, store sdk.KVStore, validator Validator, pool Pool) Validator {
// first delete the old record in the pool
store.Delete(GetValidatorsBondedByPowerKey(validator, pool))
// set the status // set the status
validator.Status = sdk.Bonded validator.Status = sdk.Bonded
validator, pool = validator.UpdateSharesLocation(pool) validator, pool = validator.UpdateSharesLocation(pool)
@ -343,7 +348,6 @@ func (k Keeper) bondValidator(ctx sdk.Context, store sdk.KVStore, validator Vali
// save the now bonded validator record to the three referened stores // save the now bonded validator record to the three referened stores
bzVal := k.cdc.MustMarshalBinary(validator) bzVal := k.cdc.MustMarshalBinary(validator)
store.Delete(GetValidatorsBondedByPowerKey(validator, pool))
store.Set(GetValidatorKey(validator.Address), bzVal) store.Set(GetValidatorKey(validator.Address), bzVal)
store.Set(GetValidatorsBondedByPowerKey(validator, pool), bzVal) store.Set(GetValidatorsBondedByPowerKey(validator, pool), bzVal)
store.Set(GetValidatorsBondedKey(validator.PubKey), bzVal) store.Set(GetValidatorsBondedKey(validator.PubKey), bzVal)

View File

@ -134,6 +134,7 @@ func (s PoolShares) Tokens(p Pool) sdk.Rat {
return p.unbondedShareExRate().Mul(s.Amount) return p.unbondedShareExRate().Mul(s.Amount)
case ShareUnbonded: case ShareUnbonded:
return p.unbondedShareExRate().Mul(s.Amount) return p.unbondedShareExRate().Mul(s.Amount)
default:
panic("unknown share kind")
} }
return sdk.ZeroRat()
} }

View File

@ -7,14 +7,14 @@ prefixed areas of the staking store which are accessed in `x/stake/keeper.go`.
## Validators ## Validators
- Prefix Key Space: ValidatorsKey - Prefix Key Space: ValidatorsKey
- Key/Sort: Validator Owner Address - Key/Sort: Validator Owner Address
- Contains: All Validator records whether independent of being bonded or not - Contains: All Validator records independent of being bonded or not
- Used For: Retrieve validator from owner address, general validator retrieval - Used For: Retrieve validator from owner address, general validator retrieval
## Validators By Power ## Validators By Power
- Prefix Key Space: ValidatorsByPowerKey - Prefix Key Space: ValidatorsByPowerKey
- Key/Sort: Validator Power (equivalent bonded shares) then Block - Key/Sort: Validator Power (equivalent bonded shares) then Block
Height then Transaction Order Height then Transaction Order
- Contains: All Validator records whether independent of being bonded or not - Contains: All Validator records independent of being bonded or not
- Used For: Determining who the top validators are whom should be bonded - Used For: Determining who the top validators are whom should be bonded
## Validators Bonded ## Validators Bonded
@ -30,4 +30,5 @@ prefixed areas of the staking store which are accessed in `x/stake/keeper.go`.
- Prefix Key Space: TendermintUpdatesKey - Prefix Key Space: TendermintUpdatesKey
- Key/Sort: Validator Owner Address - Key/Sort: Validator Owner Address
- Contains: Validators are queued to affect the consensus validation set in Tendermint - Contains: Validators are queued to affect the consensus validation set in Tendermint
- Used For: Informing Tendermint of the validator set updates - Used For: Informing Tendermint of the validator set updates, is used only intra-block, as the
updates are applied then cleared on endblock