Skip to content

Commit

Permalink
rename Accum -> ProposerPriority: (#2932)
Browse files Browse the repository at this point in the history
- rename fields, methods, comments, tests
  • Loading branch information
liamsi authored and ebuchman committed Nov 28, 2018
1 parent 4039276 commit b30c34e
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 109 deletions.
2 changes: 1 addition & 1 deletion consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ func (cs *ConsensusState) enterNewRound(height int64, round int) {
validators := cs.Validators
if cs.Round < round {
validators = validators.Copy()
validators.IncrementAccum(round - cs.Round)
validators.IncrementProposerPriority(round - cs.Round)
}

// Setup new round
Expand Down
2 changes: 1 addition & 1 deletion docs/app-dev/subscribing-to-events-via-websocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Response:
"value": "ww0z4WaZ0Xg+YI10w43wTWbBmM3dpVza4mmSQYsd0ck="
},
"voting_power": "10",
"accum": "0"
"proposer_priority": "0"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion evidence/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func initializeValidatorState(valAddr []byte, height int64) dbm.DB {
LastBlockHeight: 0,
LastBlockTime: tmtime.Now(),
Validators: valSet,
NextValidators: valSet.CopyIncrementAccum(1),
NextValidators: valSet.CopyIncrementProposerPriority(1),
LastHeightValidatorsChanged: 1,
ConsensusParams: types.ConsensusParams{
Evidence: types.EvidenceParams{
Expand Down
2 changes: 1 addition & 1 deletion p2p/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func PrometheusMetrics(namespace string) *Metrics {
// NopMetrics returns no-op Metrics.
func NopMetrics() *Metrics {
return &Metrics{
Peers: discard.NewGauge(),
Peers: discard.NewGauge(),
PeerReceiveBytesTotal: discard.NewCounter(),
PeerSendBytesTotal: discard.NewCounter(),
PeerPendingSendBytes: discard.NewGauge(),
Expand Down
10 changes: 5 additions & 5 deletions rpc/core/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
// "result": {
// "validators": [
// {
// "accum": "0",
// "proposer_priority": "0",
// "voting_power": "10",
// "pub_key": {
// "data": "68DFDA7E50F82946E7E8546BED37944A422CD1B831E70DF66BA3B8430593944D",
Expand Down Expand Up @@ -92,7 +92,7 @@ func Validators(heightPtr *int64) (*ctypes.ResultValidators, error) {
// "value": "SBctdhRBcXtBgdI/8a/alTsUhGXqGs9k5ylV1u5iKHg="
// },
// "voting_power": "10",
// "accum": "0"
// "proposer_priority": "0"
// }
// ],
// "proposer": {
Expand All @@ -102,7 +102,7 @@ func Validators(heightPtr *int64) (*ctypes.ResultValidators, error) {
// "value": "SBctdhRBcXtBgdI/8a/alTsUhGXqGs9k5ylV1u5iKHg="
// },
// "voting_power": "10",
// "accum": "0"
// "proposer_priority": "0"
// }
// },
// "proposal": null,
Expand Down Expand Up @@ -138,7 +138,7 @@ func Validators(heightPtr *int64) (*ctypes.ResultValidators, error) {
// "value": "SBctdhRBcXtBgdI/8a/alTsUhGXqGs9k5ylV1u5iKHg="
// },
// "voting_power": "10",
// "accum": "0"
// "proposer_priority": "0"
// }
// ],
// "proposer": {
Expand All @@ -148,7 +148,7 @@ func Validators(heightPtr *int64) (*ctypes.ResultValidators, error) {
// "value": "SBctdhRBcXtBgdI/8a/alTsUhGXqGs9k5ylV1u5iKHg="
// },
// "voting_power": "10",
// "accum": "0"
// "proposer_priority": "0"
// }
// }
// },
Expand Down
14 changes: 7 additions & 7 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,14 @@ func updateValidators(currentSet *types.ValidatorSet, updates []*types.Validator
types.MaxTotalVotingPower)
}
// TODO: issue #1558 update spec according to the following:
// Set Accum to -C*totalVotingPower (with C ~= 1.125) to make sure validators can't
// unbond/rebond to reset their (potentially previously negative) Accum to zero.
// Set ProposerPriority to -C*totalVotingPower (with C ~= 1.125) to make sure validators can't
// unbond/rebond to reset their (potentially previously negative) ProposerPriority to zero.
//
// Contract: totalVotingPower < MaxTotalVotingPower to ensure Accum does
// Contract: totalVotingPower < MaxTotalVotingPower to ensure ProposerPriority does
// not exceed the bounds of int64.
//
// Compute Accum = -1.125*totalVotingPower == -(totalVotingPower + (totalVotingPower >> 3)).
valUpdate.Accum = -(totalVotingPower + (totalVotingPower >> 3))
// Compute ProposerPriority = -1.125*totalVotingPower == -(totalVotingPower + (totalVotingPower >> 3)).
valUpdate.ProposerPriority = -(totalVotingPower + (totalVotingPower >> 3))
added := currentSet.Add(valUpdate)
if !added {
return fmt.Errorf("Failed to add new validator %v", valUpdate)
Expand Down Expand Up @@ -431,8 +431,8 @@ func updateState(
lastHeightValsChanged = header.Height + 1 + 1
}

// Update validator accums and set state variables.
nValSet.IncrementAccum(1)
// Update validator proposer priority and set state variables.
nValSet.IncrementProposerPriority(1)

// Update the params with the latest abciResponses.
nextParams := state.ConsensusParams
Expand Down
2 changes: 1 addition & 1 deletion state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) {
validators[i] = types.NewValidator(val.PubKey, val.Power)
}
validatorSet = types.NewValidatorSet(validators)
nextValidatorSet = types.NewValidatorSet(validators).CopyIncrementAccum(1)
nextValidatorSet = types.NewValidatorSet(validators).CopyIncrementProposerPriority(1)
}

return State{
Expand Down
16 changes: 8 additions & 8 deletions state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ func TestABCIResponsesSaveLoad2(t *testing.T) {
{Code: 383},
{Data: []byte("Gotcha!"),
Tags: []cmn.KVPair{
cmn.KVPair{Key: []byte("a"), Value: []byte("1")},
cmn.KVPair{Key: []byte("build"), Value: []byte("stuff")},
{Key: []byte("a"), Value: []byte("1")},
{Key: []byte("build"), Value: []byte("stuff")},
}},
},
types.ABCIResults{
Expand Down Expand Up @@ -263,25 +263,25 @@ func TestOneValidatorChangesSaveLoad(t *testing.T) {
}
}

func TestStoreLoadValidatorsIncrementsAccum(t *testing.T) {
func TestStoreLoadValidatorsIncrementsProposerPriority(t *testing.T) {
const valSetSize = 2
tearDown, stateDB, state := setupTestCase(t)
state.Validators = genValSet(valSetSize)
state.NextValidators = state.Validators.CopyIncrementAccum(1)
state.NextValidators = state.Validators.CopyIncrementProposerPriority(1)
SaveState(stateDB, state)
defer tearDown(t)

nextHeight := state.LastBlockHeight + 1

v0, err := LoadValidators(stateDB, nextHeight)
assert.Nil(t, err)
acc0 := v0.Validators[0].Accum
acc0 := v0.Validators[0].ProposerPriority

v1, err := LoadValidators(stateDB, nextHeight+1)
assert.Nil(t, err)
acc1 := v1.Validators[0].Accum
acc1 := v1.Validators[0].ProposerPriority

assert.NotEqual(t, acc1, acc0, "expected Accum value to change between heights")
assert.NotEqual(t, acc1, acc0, "expected ProposerPriority value to change between heights")
}

// TestValidatorChangesSaveLoad tests saving and loading a validator set with
Expand All @@ -291,7 +291,7 @@ func TestManyValidatorChangesSaveLoad(t *testing.T) {
tearDown, stateDB, state := setupTestCase(t)
require.Equal(t, int64(0), state.LastBlockHeight)
state.Validators = genValSet(valSetSize)
state.NextValidators = state.Validators.CopyIncrementAccum(1)
state.NextValidators = state.Validators.CopyIncrementProposerPriority(1)
SaveState(stateDB, state)
defer tearDown(t)

Expand Down
2 changes: 1 addition & 1 deletion state/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func LoadValidators(db dbm.DB, height int64) (*types.ValidatorSet, error) {
),
)
}
valInfo2.ValidatorSet.IncrementAccum(int(height - valInfo.LastHeightChanged)) // mutate
valInfo2.ValidatorSet.IncrementProposerPriority(int(height - valInfo.LastHeightChanged)) // mutate
valInfo = valInfo2
}

Expand Down
30 changes: 15 additions & 15 deletions types/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,40 @@ import (
)

// Volatile state for each Validator
// NOTE: The Accum is not included in Validator.Hash();
// NOTE: The ProposerPriority is not included in Validator.Hash();
// make sure to update that method if changes are made here
type Validator struct {
Address Address `json:"address"`
PubKey crypto.PubKey `json:"pub_key"`
VotingPower int64 `json:"voting_power"`

Accum int64 `json:"accum"`
ProposerPriority int64 `json:"proposer_priority"`
}

func NewValidator(pubKey crypto.PubKey, votingPower int64) *Validator {
return &Validator{
Address: pubKey.Address(),
PubKey: pubKey,
VotingPower: votingPower,
Accum: 0,
Address: pubKey.Address(),
PubKey: pubKey,
VotingPower: votingPower,
ProposerPriority: 0,
}
}

// Creates a new copy of the validator so we can mutate accum.
// Creates a new copy of the validator so we can mutate ProposerPriority.
// Panics if the validator is nil.
func (v *Validator) Copy() *Validator {
vCopy := *v
return &vCopy
}

// Returns the one with higher Accum.
func (v *Validator) CompareAccum(other *Validator) *Validator {
// Returns the one with higher ProposerPriority.
func (v *Validator) CompareProposerPriority(other *Validator) *Validator {
if v == nil {
return other
}
if v.Accum > other.Accum {
if v.ProposerPriority > other.ProposerPriority {
return v
} else if v.Accum < other.Accum {
} else if v.ProposerPriority < other.ProposerPriority {
return other
} else {
result := bytes.Compare(v.Address, other.Address)
Expand All @@ -67,19 +67,19 @@ func (v *Validator) String() string {
v.Address,
v.PubKey,
v.VotingPower,
v.Accum)
v.ProposerPriority)
}

// Hash computes the unique ID of a validator with a given voting power.
// It excludes the Accum value, which changes with every round.
// It excludes the ProposerPriority value, which changes with every round.
func (v *Validator) Hash() []byte {
return tmhash.Sum(v.Bytes())
}

// Bytes computes the unique encoding of a validator with a given voting power.
// These are the bytes that gets hashed in consensus. It excludes address
// as its redundant with the pubkey. This also excludes accum which changes
// every round.
// as its redundant with the pubkey. This also excludes ProposerPriority
// which changes every round.
func (v *Validator) Bytes() []byte {
return cdcEncode(struct {
PubKey crypto.PubKey
Expand Down

0 comments on commit b30c34e

Please sign in to comment.