remove LastCommitHeight

This commit is contained in:
Ethan Buchman 2016-11-16 20:58:53 -05:00
parent a3d863f83b
commit d7f6c0775a
3 changed files with 19 additions and 35 deletions

View File

@ -1522,7 +1522,8 @@ func (cs *ConsensusState) signVote(type_ byte, hash []byte, header types.PartSet
// sign the vote and publish on internalMsgQueue
func (cs *ConsensusState) signAddVote(type_ byte, hash []byte, header types.PartSetHeader) *types.Vote {
if cs.privValidator == nil || !cs.Validators.HasAddress(cs.privValidator.GetAddress()) {
// if we don't have a key or we're not in the validator set, do nothing
if cs.privValidator == nil || cs.privValidatorIndex < 0 {
return nil
}
vote, err := cs.signVote(type_, hash, header)

View File

@ -29,7 +29,9 @@ func (s *State) ExecBlock(eventCache types.Fireable, proxyAppConn proxy.AppConnC
// Update the validator set
valSet := s.Validators.Copy()
// Update valSet with signatures from block.
updateValidatorsWithBlock(s.LastValidators, valSet, block)
signed := commitBitArrayFromBlock(block)
_ = signed // TODO
// TODO: Update the validator set (e.g. block.Data.ValidatorUpdates?)
nextValSet := valSet.Copy()
@ -126,32 +128,17 @@ func (s *State) execBlockOnProxyApp(eventCache types.Fireable, proxyAppConn prox
return nil
}
// Updates the LastCommitHeight of the validators in valSet, in place.
// Assumes that lastValSet matches the valset of block.LastCommit
// CONTRACT: lastValSet is not mutated.
func updateValidatorsWithBlock(lastValSet *types.ValidatorSet, valSet *types.ValidatorSet, block *types.Block) {
// return a bit array of validators that signed the last commit
// NOTE: assumes commits have already been authenticated
func commitBitArrayFromBlock(block *types.Block) *BitArray {
signed := NewBitArray(len(block.LastCommit.Precommits))
for i, precommit := range block.LastCommit.Precommits {
if precommit == nil {
continue
}
_, val := lastValSet.GetByIndex(i)
if val == nil {
PanicCrisis(Fmt("Failed to fetch validator at index %v", i))
signed.SetIndex(i, true) // val_.LastCommitHeight = block.Height - 1
}
if _, val_ := valSet.GetByAddress(val.Address); val_ != nil {
val_.LastCommitHeight = block.Height - 1
updated := valSet.Update(val_)
if !updated {
PanicCrisis("Failed to update validator LastCommitHeight")
}
} else {
// XXX This is not an error if validator was removed.
// But, we don't mutate validators yet so go ahead and panic.
PanicCrisis("Could not find validator")
}
}
return signed
}
//-----------------------------------------------------

View File

@ -12,12 +12,10 @@ import (
// Volatile state for each Validator
// TODO: make non-volatile identity
// - Remove LastCommitHeight, send bitarray of vals that signed in BeginBlock
// - Remove Accum - it can be computed, and now valset becomes identifying
type Validator struct {
Address []byte `json:"address"`
PubKey crypto.PubKey `json:"pub_key"`
LastCommitHeight int `json:"last_commit_height"`
VotingPower int64 `json:"voting_power"`
Accum int64 `json:"accum"`
}
@ -57,7 +55,6 @@ func (v *Validator) String() string {
return fmt.Sprintf("Validator{%X %v %v VP:%v A:%v}",
v.Address,
v.PubKey,
v.LastCommitHeight,
v.VotingPower,
v.Accum)
}
@ -99,7 +96,6 @@ func RandValidator(randPower bool, minPower int64) (*Validator, *PrivValidator)
val := &Validator{
Address: privVal.Address,
PubKey: privVal.PubKey,
LastCommitHeight: 0,
VotingPower: votePower,
Accum: 0,
}