mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 23:02:16 +00:00
remove LastCommitHeight
This commit is contained in:
parent
a3d863f83b
commit
d7f6c0775a
@ -1522,7 +1522,8 @@ func (cs *ConsensusState) signVote(type_ byte, hash []byte, header types.PartSet
|
|||||||
|
|
||||||
// sign the vote and publish on internalMsgQueue
|
// sign the vote and publish on internalMsgQueue
|
||||||
func (cs *ConsensusState) signAddVote(type_ byte, hash []byte, header types.PartSetHeader) *types.Vote {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
vote, err := cs.signVote(type_, hash, header)
|
vote, err := cs.signVote(type_, hash, header)
|
||||||
|
@ -29,7 +29,9 @@ func (s *State) ExecBlock(eventCache types.Fireable, proxyAppConn proxy.AppConnC
|
|||||||
// Update the validator set
|
// Update the validator set
|
||||||
valSet := s.Validators.Copy()
|
valSet := s.Validators.Copy()
|
||||||
// Update valSet with signatures from block.
|
// 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?)
|
// TODO: Update the validator set (e.g. block.Data.ValidatorUpdates?)
|
||||||
nextValSet := valSet.Copy()
|
nextValSet := valSet.Copy()
|
||||||
|
|
||||||
@ -126,32 +128,17 @@ func (s *State) execBlockOnProxyApp(eventCache types.Fireable, proxyAppConn prox
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates the LastCommitHeight of the validators in valSet, in place.
|
// return a bit array of validators that signed the last commit
|
||||||
// Assumes that lastValSet matches the valset of block.LastCommit
|
// NOTE: assumes commits have already been authenticated
|
||||||
// CONTRACT: lastValSet is not mutated.
|
func commitBitArrayFromBlock(block *types.Block) *BitArray {
|
||||||
func updateValidatorsWithBlock(lastValSet *types.ValidatorSet, valSet *types.ValidatorSet, block *types.Block) {
|
signed := NewBitArray(len(block.LastCommit.Precommits))
|
||||||
|
|
||||||
for i, precommit := range block.LastCommit.Precommits {
|
for i, precommit := range block.LastCommit.Precommits {
|
||||||
if precommit == nil {
|
if precommit == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
_, val := lastValSet.GetByIndex(i)
|
signed.SetIndex(i, true) // val_.LastCommitHeight = block.Height - 1
|
||||||
if val == nil {
|
|
||||||
PanicCrisis(Fmt("Failed to fetch validator at index %v", i))
|
|
||||||
}
|
}
|
||||||
if _, val_ := valSet.GetByAddress(val.Address); val_ != nil {
|
return signed
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
|
@ -12,12 +12,10 @@ import (
|
|||||||
|
|
||||||
// Volatile state for each Validator
|
// Volatile state for each Validator
|
||||||
// TODO: make non-volatile identity
|
// 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
|
// - Remove Accum - it can be computed, and now valset becomes identifying
|
||||||
type Validator struct {
|
type Validator struct {
|
||||||
Address []byte `json:"address"`
|
Address []byte `json:"address"`
|
||||||
PubKey crypto.PubKey `json:"pub_key"`
|
PubKey crypto.PubKey `json:"pub_key"`
|
||||||
LastCommitHeight int `json:"last_commit_height"`
|
|
||||||
VotingPower int64 `json:"voting_power"`
|
VotingPower int64 `json:"voting_power"`
|
||||||
Accum int64 `json:"accum"`
|
Accum int64 `json:"accum"`
|
||||||
}
|
}
|
||||||
@ -57,7 +55,6 @@ func (v *Validator) String() string {
|
|||||||
return fmt.Sprintf("Validator{%X %v %v VP:%v A:%v}",
|
return fmt.Sprintf("Validator{%X %v %v VP:%v A:%v}",
|
||||||
v.Address,
|
v.Address,
|
||||||
v.PubKey,
|
v.PubKey,
|
||||||
v.LastCommitHeight,
|
|
||||||
v.VotingPower,
|
v.VotingPower,
|
||||||
v.Accum)
|
v.Accum)
|
||||||
}
|
}
|
||||||
@ -99,7 +96,6 @@ func RandValidator(randPower bool, minPower int64) (*Validator, *PrivValidator)
|
|||||||
val := &Validator{
|
val := &Validator{
|
||||||
Address: privVal.Address,
|
Address: privVal.Address,
|
||||||
PubKey: privVal.PubKey,
|
PubKey: privVal.PubKey,
|
||||||
LastCommitHeight: 0,
|
|
||||||
VotingPower: votePower,
|
VotingPower: votePower,
|
||||||
Accum: 0,
|
Accum: 0,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user