Skip to content

Commit

Permalink
first look at setting accum to large negative number (-total_power):
Browse files Browse the repository at this point in the history
- commit to run all tests on circleci
- potential quick-fix for #2718

additional unrelated changes:
- do not capitalize error msgs
- fix typo
  • Loading branch information
liamsi committed Nov 8, 2018
1 parent 6e9aee5 commit 65ea068
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lite/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ If we cannot update directly from H -> H' because there was too much change to
the validator set, then we can look for some Hm (H < Hm < H') with a validator
set Vm. Then we try to update H -> Hm and then Hm -> H' in two steps. If one
of these steps doesn't work, then we continue bisecting, until we eventually
have to externally validate the valdiator set changes at every block.
have to externally validate the validator set changes at every block.
Since we never trust any server in this protocol, only the signatures
themselves, it doesn't matter if the seed comes from a (possibly malicious)
Expand Down
15 changes: 9 additions & 6 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,12 @@ func updateValidators(currentSet *types.ValidatorSet, abciUpdates []abci.Validat
if err != nil {
return err
}

// store the current total voting power before applying any updates
totalVotingPower := currentSet.TotalVotingPower()
// these are tendermint types now
for _, valUpdate := range updates {
if valUpdate.VotingPower < 0 {
return fmt.Errorf("Voting power can't be negative %v", valUpdate)
return fmt.Errorf("voting power can't be negative %v", valUpdate)
}

address := valUpdate.Address
Expand All @@ -339,19 +340,21 @@ func updateValidators(currentSet *types.ValidatorSet, abciUpdates []abci.Validat
// remove val
_, removed := currentSet.Remove(address)
if !removed {
return fmt.Errorf("Failed to remove validator %X", address)
return fmt.Errorf("failed to remove validator %X", address)
}
} else if val == nil {
// add val
// set accum to -totalVotingPower to make sure validators can't unbond/rebond to reset their accum to zero:
valUpdate.Accum = -totalVotingPower
// add validator
added := currentSet.Add(valUpdate)
if !added {
return fmt.Errorf("Failed to add new validator %v", valUpdate)
return fmt.Errorf("failed to add new validator %v", valUpdate)
}
} else {
// update val
updated := currentSet.Update(valUpdate)
if !updated {
return fmt.Errorf("Failed to update validator %X to %v", address, valUpdate)
return fmt.Errorf("failed to update validator %X to %v", address, valUpdate)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions types/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ func (v *Validator) Hash() []byte {
// as its redundant with the pubkey. This also excludes accum which changes
// every round.
func (v *Validator) Bytes() []byte {
return cdcEncode((struct {
return cdcEncode(struct {
PubKey crypto.PubKey
VotingPower int64
}{
v.PubKey,
v.VotingPower,
}))
})
}

//----------------------------------------
Expand Down

0 comments on commit 65ea068

Please sign in to comment.