erigon-pulse/consensus/parlia/utils.go
Håvard Anda Estensen ea6b92b132
Enable gosec linter (#5083)
* Ignore pseudo random generators

* Enable gosec linter
2022-08-17 12:18:19 +07:00

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
}
}