cwgoes comments, validator.VotingPower -> validator.Power

This commit is contained in:
rigelrozanski 2018-04-05 18:34:25 -04:00
parent 6a10283eaa
commit 27087bb064
3 changed files with 25 additions and 23 deletions

View File

@ -111,7 +111,7 @@ func (k Keeper) setCandidate(ctx sdk.Context, candidate Candidate) {
if oldFound {
store.Delete(GetValidatorKey(address, oldCandidate.Assets, k.cdc))
}
store.Set(GetValidatorKey(address, validator.VotingPower, k.cdc), bz)
store.Set(GetValidatorKey(address, validator.Power, k.cdc), bz)
// add to the validators to update list if is already a validator
// or is a new validator
@ -161,10 +161,12 @@ func (k Keeper) removeCandidate(ctx sdk.Context, address sdk.Address) {
//___________________________________________________________________________
// get the most recent updated validator set from the Candidates. These bonds
// are already sorted by Assets from the UpdateVotingPower function which
// is the only function which is to modify the Assets
// this function also updaates the most recent validators saved in store
// Get the validator set from the candidates. The correct subset is retrieved
// by iterating through an index of the candidates sorted by power, stored
// using the ValidatorsKey. Simultaniously the most recent the validator
// records are updated in store with the RecentValidatorsKey. This store is
// used to determine if a candidate is a validator without needing to iterate
// over the subspace as we do in GetValidators
func (k Keeper) GetValidators(ctx sdk.Context) (validators []Validator) {
store := ctx.KVStore(k.storeKey)

View File

@ -218,11 +218,11 @@ func TestGetValidators(t *testing.T) {
// first make sure everything as normal is ordered
validators := keeper.GetValidators(ctx)
require.Equal(t, len(validators), n)
assert.Equal(t, sdk.NewRat(400), validators[0].VotingPower, "%v", validators)
assert.Equal(t, sdk.NewRat(200), validators[1].VotingPower, "%v", validators)
assert.Equal(t, sdk.NewRat(100), validators[2].VotingPower, "%v", validators)
assert.Equal(t, sdk.NewRat(1), validators[3].VotingPower, "%v", validators)
assert.Equal(t, sdk.NewRat(0), validators[4].VotingPower, "%v", validators)
assert.Equal(t, sdk.NewRat(400), validators[0].Power, "%v", validators)
assert.Equal(t, sdk.NewRat(200), validators[1].Power, "%v", validators)
assert.Equal(t, sdk.NewRat(100), validators[2].Power, "%v", validators)
assert.Equal(t, sdk.NewRat(1), validators[3].Power, "%v", validators)
assert.Equal(t, sdk.NewRat(0), validators[4].Power, "%v", validators)
assert.Equal(t, candidates[3].Address, validators[0].Address, "%v", validators)
assert.Equal(t, candidates[4].Address, validators[1].Address, "%v", validators)
assert.Equal(t, candidates[1].Address, validators[2].Address, "%v", validators)
@ -234,7 +234,7 @@ func TestGetValidators(t *testing.T) {
keeper.setCandidate(ctx, candidates[3])
validators = keeper.GetValidators(ctx)
require.Equal(t, len(validators), n)
assert.Equal(t, sdk.NewRat(500), validators[0].VotingPower, "%v", validators)
assert.Equal(t, sdk.NewRat(500), validators[0].Power, "%v", validators)
assert.Equal(t, candidates[3].Address, validators[0].Address, "%v", validators)
// test a decrease in voting power
@ -242,7 +242,7 @@ func TestGetValidators(t *testing.T) {
keeper.setCandidate(ctx, candidates[3])
validators = keeper.GetValidators(ctx)
require.Equal(t, len(validators), n)
assert.Equal(t, sdk.NewRat(300), validators[0].VotingPower, "%v", validators)
assert.Equal(t, sdk.NewRat(300), validators[0].Power, "%v", validators)
assert.Equal(t, candidates[3].Address, validators[0].Address, "%v", validators)
// test a swap in voting power
@ -250,9 +250,9 @@ func TestGetValidators(t *testing.T) {
keeper.setCandidate(ctx, candidates[0])
validators = keeper.GetValidators(ctx)
require.Equal(t, len(validators), n)
assert.Equal(t, sdk.NewRat(600), validators[0].VotingPower, "%v", validators)
assert.Equal(t, sdk.NewRat(600), validators[0].Power, "%v", validators)
assert.Equal(t, candidates[0].Address, validators[0].Address, "%v", validators)
assert.Equal(t, sdk.NewRat(300), validators[1].VotingPower, "%v", validators)
assert.Equal(t, sdk.NewRat(300), validators[1].Power, "%v", validators)
assert.Equal(t, candidates[3].Address, validators[1].Address, "%v", validators)
// test the max validators term
@ -262,9 +262,9 @@ func TestGetValidators(t *testing.T) {
keeper.setParams(ctx, params)
validators = keeper.GetValidators(ctx)
require.Equal(t, len(validators), n)
assert.Equal(t, sdk.NewRat(600), validators[0].VotingPower, "%v", validators)
assert.Equal(t, sdk.NewRat(600), validators[0].Power, "%v", validators)
assert.Equal(t, candidates[0].Address, validators[0].Address, "%v", validators)
assert.Equal(t, sdk.NewRat(300), validators[1].VotingPower, "%v", validators)
assert.Equal(t, sdk.NewRat(300), validators[1].Power, "%v", validators)
assert.Equal(t, candidates[3].Address, validators[1].Address, "%v", validators)
}

View File

@ -106,9 +106,9 @@ func (c Candidate) delegatorShareExRate() sdk.Rat {
// Should only be called when the Candidate qualifies as a validator.
func (c Candidate) validator() Validator {
return Validator{
Address: c.Address,
PubKey: c.PubKey,
VotingPower: c.Assets,
Address: c.Address,
PubKey: c.PubKey,
Power: c.Assets,
}
}
@ -119,9 +119,9 @@ func (c Candidate) validator() Validator {
// Validator is one of the top Candidates
type Validator struct {
Address sdk.Address `json:"address"`
PubKey crypto.PubKey `json:"PubKey"`
VotingPower sdk.Rat `json:"voting_power"`
Address sdk.Address `json:"address"`
PubKey crypto.PubKey `json:"pub_key"`
Power sdk.Rat `json:"voting_power"`
}
// abci validator from stake validator type
@ -132,7 +132,7 @@ func (v Validator) abciValidator(cdc *wire.Codec) abci.Validator {
}
return abci.Validator{
PubKey: pkBytes,
Power: v.VotingPower.Evaluate(),
Power: v.Power.Evaluate(),
}
}