Skip to content

Commit

Permalink
fix: remove wrong validatorLimit local variable (#192)
Browse files Browse the repository at this point in the history
The len(snap.Validators) is not an invariant, it can be changed in the loop when
a new list of validators is loaded. This commit removes that variable and uses
len(snap.Validators)/2 + 1 instead.
  • Loading branch information
minh-bq authored Dec 19, 2022
1 parent 90efc9d commit 4abacb2
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions consensus/consortium/v2/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,10 @@ func (s *Snapshot) apply(headers []*types.Header, chain consensus.ChainHeaderRea

// Number of consecutive blocks out of which a validator may only sign one.
// Must be len(snap.Validators)/2 + 1 to enforce majority consensus on a chain
validatorLimit := len(snap.Validators)/2 + 1
for _, header := range headers {
number := header.Number.Uint64()
// Delete the oldest validators from the recent list to allow it signing again
if limit := uint64(validatorLimit); number >= limit {
if limit := uint64(len(snap.Validators)/2 + 1); number >= limit {
delete(snap.Recents, number-limit)
}
// Resolve the authorization key and check against signers
Expand Down Expand Up @@ -189,7 +188,7 @@ func (s *Snapshot) apply(headers []*types.Header, chain consensus.ChainHeaderRea
for _, val := range newValArr {
newVals[val] = struct{}{}
}
oldLimit := validatorLimit
oldLimit := len(snap.Validators)/2 + 1
newLimit := len(newVals)/2 + 1
if newLimit < oldLimit {
for i := 0; i < oldLimit-newLimit; i++ {
Expand Down

0 comments on commit 4abacb2

Please sign in to comment.