mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
beacon/types: fixed fork sorting order
This commit is contained in:
parent
80bf2c0143
commit
c53ce79a3a
1 changed files with 7 additions and 9 deletions
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -109,10 +110,10 @@ func (f Forks) SigningRoot(header Header) (common.Hash, error) {
|
||||||
func (f Forks) Len() int { return len(f) }
|
func (f Forks) Len() int { return len(f) }
|
||||||
func (f Forks) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
|
func (f Forks) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
|
||||||
func (f Forks) Less(i, j int) bool {
|
func (f Forks) Less(i, j int) bool {
|
||||||
if f[i].knownIndex != f[j].knownIndex {
|
if f[i].Epoch != f[j].Epoch {
|
||||||
return f[i].knownIndex < f[j].knownIndex
|
|
||||||
}
|
|
||||||
return f[i].Epoch < f[j].Epoch
|
return f[i].Epoch < f[j].Epoch
|
||||||
|
}
|
||||||
|
return f[i].knownIndex < f[j].knownIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChainConfig contains the beacon chain configuration.
|
// ChainConfig contains the beacon chain configuration.
|
||||||
|
|
@ -134,12 +135,9 @@ func (c *ChainConfig) ForkAtEpoch(epoch uint64) Fork {
|
||||||
|
|
||||||
// AddFork adds a new item to the list of forks.
|
// AddFork adds a new item to the list of forks.
|
||||||
func (c *ChainConfig) AddFork(name string, epoch uint64, version []byte) *ChainConfig {
|
func (c *ChainConfig) AddFork(name string, epoch uint64, version []byte) *ChainConfig {
|
||||||
knownIndex := math.MaxInt
|
knownIndex := slices.Index(knownForks, name)
|
||||||
for i, fname := range knownForks {
|
if knownIndex == -1 {
|
||||||
if name == fname {
|
knownIndex = math.MaxInt // assume that the unknown fork happens after the known ones
|
||||||
knownIndex = i
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if knownIndex == math.MaxInt && epoch != math.MaxUint64 {
|
if knownIndex == math.MaxInt && epoch != math.MaxUint64 {
|
||||||
log.Warn("Unknown fork in config.yaml", "fork name", name, "known forks", knownForks)
|
log.Warn("Unknown fork in config.yaml", "fork name", name, "known forks", knownForks)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue