mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-24 08:54:51 +00:00
light: remove witnesses in order of decreasing index (#6065)
This commit is contained in:
+9
-2
@@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
@@ -1002,6 +1003,9 @@ func (c *Client) compareFirstHeaderWithWitnesses(ctx context.Context, h *types.S
|
|||||||
compareCtx, cancel := context.WithCancel(ctx)
|
compareCtx, cancel := context.WithCancel(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
c.providerMutex.Lock()
|
||||||
|
defer c.providerMutex.Unlock()
|
||||||
|
|
||||||
if len(c.witnesses) < 1 {
|
if len(c.witnesses) < 1 {
|
||||||
return errNoWitnesses{}
|
return errNoWitnesses{}
|
||||||
}
|
}
|
||||||
@@ -1035,8 +1039,11 @@ and remove witness. Otherwise, use the different primary`, e.WitnessIndex), "wit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, idx := range witnessesToRemove {
|
// we need to make sure that we remove witnesses by index in the reverse
|
||||||
c.removeWitness(idx)
|
// 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
|
return nil
|
||||||
|
|||||||
+6
-2
@@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/light/provider"
|
"github.com/tendermint/tendermint/light/provider"
|
||||||
@@ -121,8 +122,11 @@ func (c *Client) detectDivergence(ctx context.Context, primaryTrace []*types.Lig
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, idx := range witnessesToRemove {
|
// we need to make sure that we remove witnesses by index in the reverse
|
||||||
c.removeWitness(idx)
|
// 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
|
// 1. If we had at least one witness that returned the same header then we
|
||||||
|
|||||||
Reference in New Issue
Block a user