Files
prysm/runtime/version/fork.go
Manu NALEPA c48d40907c Add Fulu fork boilerplate (#14771)
* Prepare for future fork boilerplate.

* Implement the Fulu fork boilerplate.

* `Upgraded state to <fork> log`: Move from debug to info.

Rationale:
This log is the only one notifying the user a new fork happened.
A new fork is always a little bit stressful for a node operator.
Having at least one log indicating the client switched fork is something useful.

* Update testing/util/helpers.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Fix Radek's comment.

* Fix Radek's comment.

* Update beacon-chain/state/state-native/state_trie.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update beacon-chain/state/state-native/state_trie.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Fix Radek's comment.

* Fix Radek's comment.

* Fix Radek's comment.

* Remove Electra struct type aliasing.

---------

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
2025-01-07 20:09:12 +00:00

67 lines
1.4 KiB
Go

package version
import (
"github.com/pkg/errors"
)
const (
Phase0 = iota
Altair
Bellatrix
Capella
Deneb
Electra
Fulu
)
var versionToString = map[int]string{
Phase0: "phase0",
Altair: "altair",
Bellatrix: "bellatrix",
Capella: "capella",
Deneb: "deneb",
Electra: "electra",
Fulu: "fulu",
}
// stringToVersion and allVersions are populated in init()
var stringToVersion = map[string]int{}
var allVersions []int
// ErrUnrecognizedVersionName means a string does not match the list of canonical version names.
var ErrUnrecognizedVersionName = errors.New("version name doesn't map to a known value in the enum")
// FromString translates a canonical version name to the version number.
func FromString(name string) (int, error) {
v, ok := stringToVersion[name]
if !ok {
return 0, errors.Wrap(ErrUnrecognizedVersionName, name)
}
return v, nil
}
// String returns the canonical string form of a version.
// Unrecognized versions won't generate an error and are represented by the string "unknown version".
func String(version int) string {
name, ok := versionToString[version]
if !ok {
return "unknown version"
}
return name
}
// All returns a list of all known fork versions.
func All() []int {
return allVersions
}
func init() {
allVersions = make([]int, len(versionToString))
i := 0
for v, s := range versionToString {
allVersions[i] = v
stringToVersion[s] = v
i++
}
}