From d7f6c0775aa5563ce9f8aa86fd14bf618a21cf84 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 16 Nov 2016 20:58:53 -0500 Subject: [PATCH] remove LastCommitHeight --- consensus/state.go | 3 ++- state/execution.go | 31 +++++++++---------------------- types/validator.go | 20 ++++++++------------ 3 files changed, 19 insertions(+), 35 deletions(-) diff --git a/consensus/state.go b/consensus/state.go index 0442fb829..78a9b4f52 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -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) diff --git a/state/execution.go b/state/execution.go index c52be41dc..2b8461bed 100644 --- a/state/execution.go +++ b/state/execution.go @@ -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)) - } - 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") - } + signed.SetIndex(i, true) // val_.LastCommitHeight = block.Height - 1 } - + return signed } //----------------------------------------------------- diff --git a/types/validator.go b/types/validator.go index 2e45ebba9..7adb64dbb 100644 --- a/types/validator.go +++ b/types/validator.go @@ -12,14 +12,12 @@ 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"` + Address []byte `json:"address"` + PubKey crypto.PubKey `json:"pub_key"` + VotingPower int64 `json:"voting_power"` + Accum int64 `json:"accum"` } // Creates a new copy of the validator so we can mutate 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) } @@ -97,11 +94,10 @@ func RandValidator(randPower bool, minPower int64) (*Validator, *PrivValidator) votePower += int64(RandUint32()) } val := &Validator{ - Address: privVal.Address, - PubKey: privVal.PubKey, - LastCommitHeight: 0, - VotingPower: votePower, - Accum: 0, + Address: privVal.Address, + PubKey: privVal.PubKey, + VotingPower: votePower, + Accum: 0, } return val, privVal }