Browse Source

remove witnesses in order of decreasing index (#6058)

pull/6062/head
Callum Waters 4 years ago
committed by GitHub
parent
commit
1608484de8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions
  1. +9
    -2
      light/client.go
  2. +6
    -2
      light/detector.go

+ 9
- 2
light/client.go View File

@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"sort"
"time"
"github.com/tendermint/tendermint/libs/log"
@ -983,6 +984,9 @@ func (c *Client) compareFirstHeaderWithWitnesses(ctx context.Context, h *types.S
compareCtx, cancel := context.WithCancel(ctx)
defer cancel()
c.providerMutex.Lock()
defer c.providerMutex.Unlock()
if len(c.witnesses) < 1 {
return ErrNoWitnesses
}
@ -1016,8 +1020,11 @@ and remove witness. Otherwise, use the different primary`, e.WitnessIndex), "wit
}
}
for _, idx := range witnessesToRemove {
c.removeWitness(idx)
// we need to make sure that we remove witnesses by index in the reverse
// order so as to not affect the indexes themselves
sort.Ints(witnessesToRemove)
for i := len(witnessesToRemove) - 1; i >= 0; i-- {
c.removeWitness(witnessesToRemove[i])
}
return nil


+ 6
- 2
light/detector.go View File

@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"sort"
"time"
"github.com/tendermint/tendermint/light/provider"
@ -127,8 +128,11 @@ func (c *Client) detectDivergence(ctx context.Context, primaryTrace []*types.Lig
}
}
for _, idx := range witnessesToRemove {
c.removeWitness(idx)
// we need to make sure that we remove witnesses by index in the reverse
// order so as to not affect the indexes themselves
sort.Ints(witnessesToRemove)
for i := len(witnessesToRemove) - 1; i >= 0; i-- {
c.removeWitness(witnessesToRemove[i])
}
// 1. If we had at least one witness that returned the same header then we


Loading…
Cancel
Save