mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 15:04:22 +00:00
IncrementAccum upon RPC /validators; Sanity checks and comments (#2808)
This commit is contained in:
@@ -62,7 +62,11 @@ func (vals *ValidatorSet) CopyIncrementAccum(times int) *ValidatorSet {
|
||||
|
||||
// IncrementAccum increments accum of each validator and updates the
|
||||
// proposer. Panics if validator set is empty.
|
||||
// `times` must be positive.
|
||||
func (vals *ValidatorSet) IncrementAccum(times int) {
|
||||
if times <= 0 {
|
||||
panic("Cannot call IncrementAccum with non-positive times")
|
||||
}
|
||||
|
||||
// Add VotingPower * times to each validator and order into heap.
|
||||
validatorsHeap := cmn.NewHeap()
|
||||
|
||||
@@ -86,6 +86,19 @@ func TestCopy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test that IncrementAccum requires positive times.
|
||||
func TestIncrementAccumPositiveTimes(t *testing.T) {
|
||||
vset := NewValidatorSet([]*Validator{
|
||||
newValidator([]byte("foo"), 1000),
|
||||
newValidator([]byte("bar"), 300),
|
||||
newValidator([]byte("baz"), 330),
|
||||
})
|
||||
|
||||
assert.Panics(t, func() { vset.IncrementAccum(-1) })
|
||||
assert.Panics(t, func() { vset.IncrementAccum(0) })
|
||||
vset.IncrementAccum(1)
|
||||
}
|
||||
|
||||
func BenchmarkValidatorSetCopy(b *testing.B) {
|
||||
b.StopTimer()
|
||||
vset := NewValidatorSet([]*Validator{})
|
||||
@@ -239,7 +252,7 @@ func TestProposerSelection3(t *testing.T) {
|
||||
mod := (cmn.RandInt() % 5) + 1
|
||||
if cmn.RandInt()%mod > 0 {
|
||||
// sometimes its up to 5
|
||||
times = cmn.RandInt() % 5
|
||||
times = (cmn.RandInt() % 4) + 1
|
||||
}
|
||||
vset.IncrementAccum(times)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user