mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2025-01-03 09:17:38 +00:00
fix index out of range
This commit is contained in:
parent
85ebea9e8c
commit
4f431e0843
@ -1145,7 +1145,11 @@ func backOffTime(snap *Snapshot, val common.Address) uint64 {
|
||||
if snap.inturn(val) {
|
||||
return 0
|
||||
} else {
|
||||
dis := snap.distanceToInTurn(val)
|
||||
idx := snap.indexOfVal(val)
|
||||
if idx < 0 {
|
||||
// The backOffTime does not matter when a validator is not authorized.
|
||||
return 0
|
||||
}
|
||||
s := rand.NewSource(int64(snap.Number))
|
||||
r := rand.New(s)
|
||||
n := len(snap.Validators)
|
||||
@ -1156,7 +1160,7 @@ func backOffTime(snap *Snapshot, val common.Address) uint64 {
|
||||
r.Shuffle(n, func(i, j int) {
|
||||
backOffSteps[i], backOffSteps[j] = backOffSteps[j], backOffSteps[i]
|
||||
})
|
||||
delay := initialBackOffTime + backOffSteps[dis]*wiggleTime
|
||||
delay := initialBackOffTime + backOffSteps[idx]*wiggleTime
|
||||
return delay
|
||||
}
|
||||
}
|
||||
|
@ -216,18 +216,14 @@ func (s *Snapshot) inturn(validator common.Address) bool {
|
||||
return validators[offset] == validator
|
||||
}
|
||||
|
||||
func (s *Snapshot) distanceToInTurn(validator common.Address) uint64 {
|
||||
func (s *Snapshot) indexOfVal(validator common.Address) int {
|
||||
validators := s.validators()
|
||||
offset := (s.Number + 1) % uint64(len(validators))
|
||||
idx := uint64(0)
|
||||
for idx < uint64(len(validator)) && validators[idx] != validator {
|
||||
idx++
|
||||
}
|
||||
if offset > idx {
|
||||
return uint64(len(validators)) + idx - offset
|
||||
} else {
|
||||
return idx - offset
|
||||
for idx, val := range validators {
|
||||
if val == validator {
|
||||
return idx
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func (s *Snapshot) supposeValidator() common.Address {
|
||||
|
@ -242,7 +242,7 @@ var (
|
||||
PetersburgBlock: big.NewInt(0),
|
||||
IstanbulBlock: big.NewInt(0),
|
||||
MuirGlacierBlock: big.NewInt(0),
|
||||
RamanujanBlock: big.NewInt(317974),
|
||||
RamanujanBlock: big.NewInt(400),
|
||||
Parlia: &ParliaConfig{
|
||||
Period: 3,
|
||||
Epoch: 200,
|
||||
|
Loading…
Reference in New Issue
Block a user