mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-31 16:21:21 +00:00
ea6b92b132
* Ignore pseudo random generators * Enable gosec linter
32 lines
754 B
Go
32 lines
754 B
Go
package parlia
|
|
|
|
import (
|
|
"math/rand"
|
|
|
|
"github.com/ledgerwatch/erigon/common"
|
|
)
|
|
|
|
func backOffTime(snap *Snapshot, val common.Address) uint64 {
|
|
if snap.inturn(val) {
|
|
return 0
|
|
} else {
|
|
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) // nolint: gosec
|
|
n := len(snap.Validators)
|
|
backOffSteps := make([]uint64, 0, n)
|
|
for idx := uint64(0); idx < uint64(n); idx++ {
|
|
backOffSteps = append(backOffSteps, idx)
|
|
}
|
|
r.Shuffle(n, func(i, j int) {
|
|
backOffSteps[i], backOffSteps[j] = backOffSteps[j], backOffSteps[i]
|
|
})
|
|
delay := initialBackOffTime + backOffSteps[idx]*wiggleTime
|
|
return delay
|
|
}
|
|
}
|