Browse Source

[types] dont hash validator.Accum

pull/505/head
Ethan Buchman 7 years ago
parent
commit
6d83c60c40
4 changed files with 16 additions and 6 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +15
    -4
      types/validator.go
  3. +0
    -1
      types/validator_set.go
  4. +0
    -1
      types/vote_set_test.go

+ 1
- 0
CHANGELOG.md View File

@ -25,6 +25,7 @@ BREAKING CHANGES:
- Introduce EventDataInner for serializing events
- remove all use of go-wire around user interfaces
- rpc responses no longer have type information :)
- [types] Do not include the `Accum` field when computing the hash of a validator. This makes the ValidatorSetHash unique for a given validator set, rather than changing with every block (as the Accum changes)
FEATURES:


+ 15
- 4
types/validator.go View File

@ -12,13 +12,14 @@ import (
)
// Volatile state for each Validator
// TODO: make non-volatile identity
// - Remove Accum - it can be computed, and now valset becomes identifying
// NOTE: The Accum is not included in Validator.Hash();
// make sure to update that method if changes are made here
type Validator struct {
Address data.Bytes `json:"address"`
PubKey crypto.PubKey `json:"pub_key"`
VotingPower int64 `json:"voting_power"`
Accum int64 `json:"accum"`
Accum int64 `json:"accum"`
}
func NewValidator(pubKey crypto.PubKey, votingPower int64) *Validator {
@ -69,8 +70,18 @@ func (v *Validator) String() string {
v.Accum)
}
// Hash computes the unique ID of a validator with a given voting power.
// It exludes the Accum value, which changes with every round.
func (v *Validator) Hash() []byte {
return wire.BinaryRipemd160(v)
return wire.BinaryRipemd160(struct {
Address data.Bytes
PubKey crypto.PubKey
VotingPower int64
}{
v.Address,
v.PubKey,
v.VotingPower,
})
}
//-------------------------------------


+ 0
- 1
types/validator_set.go View File

@ -21,7 +21,6 @@ import (
// NOTE: Not goroutine-safe.
// NOTE: All get/set to validators should copy the value for safety.
// TODO: consider validator Accum overflow
// TODO: move valset into an iavl tree where key is 'blockbonded|pubkey'
type ValidatorSet struct {
// NOTE: persisted via reflect, must be exported.
Validators []*Validator `json:"validators"`


+ 0
- 1
types/vote_set_test.go View File

@ -11,7 +11,6 @@ import (
)
// NOTE: privValidators are in order
// TODO: Move it out?
func randVoteSet(height int, round int, type_ byte, numValidators int, votingPower int64) (*VoteSet, *ValidatorSet, []*PrivValidator) {
valSet, privValidators := RandValidatorSet(numValidators, votingPower)
return NewVoteSet("test_chain_id", height, round, type_, valSet), valSet, privValidators


Loading…
Cancel
Save