mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-24 18:21:38 +00:00
remove privValIndex; Stale->AppHashIsStale
This commit is contained in:
@ -43,7 +43,7 @@ func (s *State) ExecBlock(eventCache types.Fireable, proxyAppConn proxy.AppConnC
|
||||
}
|
||||
|
||||
// update the validator set
|
||||
s.valAddedOrRemoved, err = updateValidators(nextValSet, changedValidators)
|
||||
err = updateValidators(nextValSet, changedValidators)
|
||||
if err != nil {
|
||||
log.Warn("Error changing validator set", "error", err)
|
||||
// TODO: err or carry on?
|
||||
@ -135,22 +135,20 @@ func execBlockOnProxyApp(eventCache types.Fireable, proxyAppConn proxy.AppConnCo
|
||||
return changedValidators, nil
|
||||
}
|
||||
|
||||
func updateValidators(validators *types.ValidatorSet, changedValidators []*tmsp.Validator) (bool, error) {
|
||||
func updateValidators(validators *types.ValidatorSet, changedValidators []*tmsp.Validator) error {
|
||||
// TODO: prevent change of 1/3+ at once
|
||||
|
||||
var addedOrRemoved bool
|
||||
|
||||
for _, v := range changedValidators {
|
||||
pubkey, err := crypto.PubKeyFromBytes(v.PubKey) // NOTE: expects go-wire encoded pubkey
|
||||
if err != nil {
|
||||
return false, err
|
||||
return err
|
||||
}
|
||||
|
||||
address := pubkey.Address()
|
||||
power := int64(v.Power)
|
||||
// mind the overflow from uint64
|
||||
if power < 0 {
|
||||
return false, errors.New(Fmt("Power (%d) overflows int64", v.Power))
|
||||
return errors.New(Fmt("Power (%d) overflows int64", v.Power))
|
||||
}
|
||||
|
||||
_, val := validators.GetByAddress(address)
|
||||
@ -158,26 +156,24 @@ func updateValidators(validators *types.ValidatorSet, changedValidators []*tmsp.
|
||||
// add val
|
||||
added := validators.Add(types.NewValidator(pubkey, power))
|
||||
if !added {
|
||||
return false, errors.New(Fmt("Failed to add new validator %X with voting power %d", address, power))
|
||||
return errors.New(Fmt("Failed to add new validator %X with voting power %d", address, power))
|
||||
}
|
||||
addedOrRemoved = true
|
||||
} else if v.Power == 0 {
|
||||
// remove val
|
||||
_, removed := validators.Remove(address)
|
||||
if !removed {
|
||||
return false, errors.New(Fmt("Failed to remove validator %X)"))
|
||||
return errors.New(Fmt("Failed to remove validator %X)"))
|
||||
}
|
||||
addedOrRemoved = true
|
||||
} else {
|
||||
// update val
|
||||
val.VotingPower = power
|
||||
updated := validators.Update(val)
|
||||
if !updated {
|
||||
return false, errors.New(Fmt("Failed to update validator %X with voting power %d", address, power))
|
||||
return errors.New(Fmt("Failed to update validator %X with voting power %d", address, power))
|
||||
}
|
||||
}
|
||||
}
|
||||
return addedOrRemoved, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// return a bit array of validators that signed the last commit
|
||||
@ -363,8 +359,8 @@ func (h *Handshaker) ReplayBlocks(appHash []byte, appBlockHeight int, appConnCon
|
||||
// if we crashed between Commit and SaveState,
|
||||
// the state's app hash is stale
|
||||
// otherwise we're synced
|
||||
if h.state.Stale {
|
||||
h.state.Stale = false
|
||||
if h.state.AppHashIsStale {
|
||||
h.state.AppHashIsStale = false
|
||||
h.state.AppHash = appHash
|
||||
}
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user