mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
fixes
This commit is contained in:
parent
1ff3345d13
commit
0e0ddea458
3 changed files with 59 additions and 24 deletions
|
|
@ -20,10 +20,10 @@ import (
|
|||
"crypto/sha256"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"os"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/beacon/merkle"
|
||||
|
|
@ -90,11 +90,7 @@ func (c *ChainConfig) AddFork(name string, epoch uint64, version []byte) *ChainC
|
|||
|
||||
// LoadForks parses the beacon chain configuration file (config.yaml) and extracts
|
||||
// the list of forks.
|
||||
func (c *ChainConfig) LoadForks(path string) error {
|
||||
file, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read beacon chain config file: %v", err)
|
||||
}
|
||||
func (c *ChainConfig) LoadForks(file []byte) error {
|
||||
config := make(map[string]any)
|
||||
if err := yaml.Unmarshal(file, &config); err != nil {
|
||||
return fmt.Errorf("failed to parse beacon chain config file: %v", err)
|
||||
|
|
@ -108,26 +104,29 @@ func (c *ChainConfig) LoadForks(path string) error {
|
|||
for key, value := range config {
|
||||
if strings.HasSuffix(key, "_FORK_VERSION") {
|
||||
name := key[:len(key)-len("_FORK_VERSION")]
|
||||
version, ok := value.(string)
|
||||
if !ok {
|
||||
version = fmt.Sprintf("0x%x", value)
|
||||
}
|
||||
if v, err := hexutil.Decode(version); err == nil {
|
||||
versions[name] = v
|
||||
} else {
|
||||
switch version := value.(type) {
|
||||
case int:
|
||||
versions[name] = make([]byte, 4)
|
||||
big.NewInt(int64(version)).FillBytes(versions[name])
|
||||
case string:
|
||||
v, err := hexutil.Decode(version)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to decode hex fork id %q in beacon chain config file: %v", version, err)
|
||||
}
|
||||
versions[name] = v
|
||||
}
|
||||
}
|
||||
if strings.HasSuffix(key, "_FORK_EPOCH") {
|
||||
name := key[:len(key)-len("_FORK_EPOCH")]
|
||||
version, ok := value.(string)
|
||||
if !ok {
|
||||
version = fmt.Sprintf("0x%x", value)
|
||||
switch epoch := value.(type) {
|
||||
case int:
|
||||
epochs[name] = uint64(epoch)
|
||||
case string:
|
||||
v, err := hexutil.DecodeUint64(epoch)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse epoch number %q in beacon chain config file: %v", epoch, err)
|
||||
}
|
||||
if v, err := hexutil.DecodeUint64(version); err == nil {
|
||||
epochs[name] = v
|
||||
} else {
|
||||
return fmt.Errorf("failed to parse epoch number %q in beacon chain config file: %v", version, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
32
beacon/params/config_test.go
Normal file
32
beacon/params/config_test.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package params
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestChainConfig_LoadForksName(t *testing.T) {
|
||||
const config = `
|
||||
GENESIS_FORK_VERSION: 0x00000000
|
||||
|
||||
ALTAIR_FORK_VERSION: 0x00000001
|
||||
ALTAIR_FORK_EPOCH: 1
|
||||
|
||||
BLOB_SCHEDULE: []
|
||||
`
|
||||
c := &ChainConfig{}
|
||||
err := c.LoadForks([]byte(config))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, fork := range c.Forks {
|
||||
if fork.Name == "GENESIS" && (fork.Epoch != 0) {
|
||||
t.Errorf("unexpected genesis fork epoch %d", fork.Epoch)
|
||||
}
|
||||
if fork.Name == "ALTAIR" && (fork.Epoch != 1 || !bytes.Equal(fork.Version, []byte{0, 0, 0, 1})) {
|
||||
t.Errorf("unexpected altair fork epoch %d version %x", fork.Epoch, fork.Version)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1902,11 +1902,15 @@ func MakeBeaconLightConfig(ctx *cli.Context) bparams.ClientConfig {
|
|||
} else {
|
||||
Fatalf("Could not parse --%s: %v", BeaconGenesisRootFlag.Name, err)
|
||||
}
|
||||
configFile := ctx.String(BeaconConfigFlag.Name)
|
||||
if err := config.ChainConfig.LoadForks(configFile); err != nil {
|
||||
Fatalf("Could not load beacon chain config '%s': %v", configFile, err)
|
||||
configPath := ctx.String(BeaconConfigFlag.Name)
|
||||
file, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
Fatalf("failed to read beacon chain config file '%s': %v", configPath, err)
|
||||
}
|
||||
log.Info("Using custom beacon chain config", "file", configFile)
|
||||
if err := config.ChainConfig.LoadForks(file); err != nil {
|
||||
Fatalf("Could not load beacon chain config '%s': %v", configPath, err)
|
||||
}
|
||||
log.Info("Using custom beacon chain config", "file", configPath)
|
||||
} else {
|
||||
if ctx.IsSet(BeaconGenesisRootFlag.Name) {
|
||||
Fatalf("Genesis root is specified but custom beacon chain config is missing")
|
||||
|
|
|
|||
Loading…
Reference in a new issue