mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-08 13:03:47 +00:00
Add legacy config file
This commit is contained in:
parent
449e6a517a
commit
e98379679f
6 changed files with 75 additions and 4 deletions
|
|
@ -53,7 +53,7 @@ var mainnetBor = &Chain{
|
||||||
Difficulty: big.NewInt(1),
|
Difficulty: big.NewInt(1),
|
||||||
Mixhash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
|
Mixhash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
|
||||||
Coinbase: common.HexToAddress("0x0000000000000000000000000000000000000000"),
|
Coinbase: common.HexToAddress("0x0000000000000000000000000000000000000000"),
|
||||||
Alloc: readPrealloc("allocs/bor_mainnet.json"),
|
Alloc: readPrealloc("allocs/mainnet.json"),
|
||||||
},
|
},
|
||||||
Bootnodes: []string{
|
Bootnodes: []string{
|
||||||
"enode://0cb82b395094ee4a2915e9714894627de9ed8498fb881cec6db7c65e8b9a5bd7f2f25cc84e71e89d0947e51c76e85d0847de848c7782b13c0255247a6758178c@44.232.55.71:30303",
|
"enode://0cb82b395094ee4a2915e9714894627de9ed8498fb881cec6db7c65e8b9a5bd7f2f25cc84e71e89d0947e51c76e85d0847de848c7782b13c0255247a6758178c@44.232.55.71:30303",
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,6 @@ func (c *Command) Run(args []string) int {
|
||||||
// TODO: Metrics
|
// TODO: Metrics
|
||||||
// TODO: apis
|
// TODO: apis
|
||||||
// TODO: Graphql
|
// TODO: Graphql
|
||||||
// TODO: embed
|
|
||||||
|
|
||||||
// register the ethereum backend
|
// register the ethereum backend
|
||||||
ethCfg, err := config.buildEth()
|
ethCfg, err := config.buildEth()
|
||||||
|
|
@ -143,6 +142,7 @@ func (c *Command) setupMetrics() error {
|
||||||
|
|
||||||
// Start system runtime metrics collection
|
// Start system runtime metrics collection
|
||||||
go metrics.CollectProcessMetrics(3 * time.Second)
|
go metrics.CollectProcessMetrics(3 * time.Second)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package server
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -50,6 +51,7 @@ type Config struct {
|
||||||
EthStats *string
|
EthStats *string
|
||||||
TxPool *TxPoolConfig
|
TxPool *TxPoolConfig
|
||||||
Sealer *SealerConfig
|
Sealer *SealerConfig
|
||||||
|
JsonRPC *JsonRPCConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
type P2PConfig struct {
|
type P2PConfig struct {
|
||||||
|
|
@ -92,6 +94,9 @@ type SealerConfig struct {
|
||||||
GasPrice *big.Int
|
GasPrice *big.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type JsonRPCConfig struct {
|
||||||
|
}
|
||||||
|
|
||||||
func DefaultConfig() *Config {
|
func DefaultConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
Chain: stringPtr("mainnet"),
|
Chain: stringPtr("mainnet"),
|
||||||
|
|
@ -137,7 +142,18 @@ func DefaultConfig() *Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
func readConfigFile(path string) (*Config, error) {
|
func readConfigFile(path string) (*Config, error) {
|
||||||
return nil, nil
|
data, err := ioutil.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// TODO: Use hcl as config format
|
||||||
|
ext := filepath.Ext(path)
|
||||||
|
switch ext {
|
||||||
|
case ".toml":
|
||||||
|
return readLegacyConfig(data)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("file path extension '%s' not found", ext)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) loadChain() error {
|
func (c *Config) loadChain() error {
|
||||||
|
|
@ -219,6 +235,7 @@ func (c *Config) buildNode() (*node.Config, error) {
|
||||||
Name: clientIdentifier,
|
Name: clientIdentifier,
|
||||||
DataDir: *c.DataDir,
|
DataDir: *c.DataDir,
|
||||||
Version: params.VersionWithCommit(gitCommit, gitDate),
|
Version: params.VersionWithCommit(gitCommit, gitDate),
|
||||||
|
IPCPath: clientIdentifier + ".ipc",
|
||||||
P2P: p2p.Config{
|
P2P: p2p.Config{
|
||||||
MaxPeers: int(*c.P2P.MaxPeers),
|
MaxPeers: int(*c.P2P.MaxPeers),
|
||||||
ListenAddr: *c.P2P.Bind + ":" + strconv.Itoa(int(*c.P2P.Port)),
|
ListenAddr: *c.P2P.Bind + ":" + strconv.Itoa(int(*c.P2P.Port)),
|
||||||
|
|
|
||||||
33
command/server/config_legacy.go
Normal file
33
command/server/config_legacy.go
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
|
||||||
|
"github.com/naoina/toml"
|
||||||
|
)
|
||||||
|
|
||||||
|
type legacyConfig struct {
|
||||||
|
Node struct {
|
||||||
|
P2P struct {
|
||||||
|
StaticNodes []string
|
||||||
|
TrustedNodes []string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *legacyConfig) Config() *Config {
|
||||||
|
c := DefaultConfig()
|
||||||
|
c.P2P.Discovery.StaticNodes = l.Node.P2P.StaticNodes
|
||||||
|
c.P2P.Discovery.TrustedNodes = l.Node.P2P.TrustedNodes
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func readLegacyConfig(data []byte) (*Config, error) {
|
||||||
|
var legacy legacyConfig
|
||||||
|
|
||||||
|
r := toml.NewDecoder(bytes.NewReader(data))
|
||||||
|
if err := r.Decode(&legacy); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return legacy.Config(), nil
|
||||||
|
}
|
||||||
21
command/server/config_legacy_test.go
Normal file
21
command/server/config_legacy_test.go
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestConfigLegacy(t *testing.T) {
|
||||||
|
toml := `[Node.P2P]
|
||||||
|
StaticNodes = ["node1"]
|
||||||
|
TrustedNodes = ["node2"]`
|
||||||
|
|
||||||
|
config, err := readLegacyConfig([]byte(toml))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, config.P2P.Discovery.StaticNodes, []string{"node1"})
|
||||||
|
assert.Equal(t, config.P2P.Discovery.TrustedNodes, []string{"node2"})
|
||||||
|
}
|
||||||
2
go.mod
2
go.mod
|
|
@ -1,6 +1,6 @@
|
||||||
module github.com/ethereum/go-ethereum
|
module github.com/ethereum/go-ethereum
|
||||||
|
|
||||||
go 1.15
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Azure/azure-pipeline-go v0.2.2 // indirect
|
github.com/Azure/azure-pipeline-go v0.2.2 // indirect
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue