Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for new flags in new config.toml, which were present in old config.toml #612

Merged
merged 9 commits into from
Dec 5, 2022
4 changes: 4 additions & 0 deletions internal/cli/dumpconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,16 @@ func (c *DumpconfigCommand) Run(args []string) int {
userConfig := command.GetConfig()

// convert the big.Int and time.Duration fields to their corresponding Raw fields
userConfig.JsonRPC.HttpTimeout.ReadTimeoutRaw = userConfig.JsonRPC.HttpTimeout.ReadTimeout.String()
userConfig.JsonRPC.HttpTimeout.WriteTimeoutRaw = userConfig.JsonRPC.HttpTimeout.WriteTimeout.String()
userConfig.JsonRPC.HttpTimeout.IdleTimeoutRaw = userConfig.JsonRPC.HttpTimeout.IdleTimeout.String()
userConfig.TxPool.RejournalRaw = userConfig.TxPool.Rejournal.String()
userConfig.TxPool.LifeTimeRaw = userConfig.TxPool.LifeTime.String()
userConfig.Sealer.GasPriceRaw = userConfig.Sealer.GasPrice.String()
userConfig.Gpo.MaxPriceRaw = userConfig.Gpo.MaxPrice.String()
userConfig.Gpo.IgnorePriceRaw = userConfig.Gpo.IgnorePrice.String()
userConfig.Cache.RejournalRaw = userConfig.Cache.Rejournal.String()
userConfig.Cache.TrieTimeoutRaw = userConfig.Cache.TrieTimeout.String()

if err := toml.NewEncoder(os.Stdout).Encode(userConfig); err != nil {
c.UI.Error(err.Error())
Expand Down
50 changes: 50 additions & 0 deletions internal/cli/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/nat"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
)

type Config struct {
Expand Down Expand Up @@ -235,6 +236,8 @@ type JsonRPCConfig struct {

// Graphql has the json-rpc graphql related settings
Graphql *APIConfig `hcl:"graphql,block" toml:"graphql,block"`

HttpTimeout *HttpTimeouts `hcl:"timeouts,block" toml:"timeouts,block"`
}

type GRPCConfig struct {
Expand Down Expand Up @@ -268,6 +271,33 @@ type APIConfig struct {
Origins []string `hcl:"origins,optional" toml:"origins,optional"`
}

// Used from rpc.HTTPTimeouts
type HttpTimeouts struct {
// ReadTimeout is the maximum duration for reading the entire
// request, including the body.
//
// Because ReadTimeout does not let Handlers make per-request
// decisions on each request body's acceptable deadline or
// upload rate, most users will prefer to use
// ReadHeaderTimeout. It is valid to use them both.
ReadTimeout time.Duration `hcl:"-,optional" toml:"-"`
ReadTimeoutRaw string `hcl:"read,optional" toml:"read,optional"`

// WriteTimeout is the maximum duration before timing out
// writes of the response. It is reset whenever a new
// request's header is read. Like ReadTimeout, it does not
// let Handlers make decisions on a per-request basis.
WriteTimeout time.Duration `hcl:"-,optional" toml:"-"`
WriteTimeoutRaw string `hcl:"write,optional" toml:"write,optional"`

// IdleTimeout is the maximum amount of time to wait for the
// next request when keep-alives are enabled. If IdleTimeout
// is zero, the value of ReadTimeout is used. If both are
// zero, ReadHeaderTimeout is used.
IdleTimeout time.Duration `hcl:"-,optional" toml:"-"`
IdleTimeoutRaw string `hcl:"idle,optional" toml:"idle,optional"`
}

type GpoConfig struct {
// Blocks is the number of blocks to track to compute the price oracle
Blocks uint64 `hcl:"blocks,optional" toml:"blocks,optional"`
Expand Down Expand Up @@ -364,6 +394,10 @@ type CacheConfig struct {

// TxLookupLimit sets the maximum number of blocks from head whose tx indices are reserved.
TxLookupLimit uint64 `hcl:"txlookuplimit,optional" toml:"txlookuplimit,optional"`

// Time after which the Merkle Patricia Trie is stored to disc from memory
TrieTimeout time.Duration `hcl:"-,optional" toml:"-"`
TrieTimeoutRaw string `hcl:"timeout,optional" toml:"timeout,optional"`
}

type AccountsConfig struct {
Expand Down Expand Up @@ -476,6 +510,11 @@ func DefaultConfig() *Config {
Cors: []string{"localhost"},
VHost: []string{"localhost"},
},
HttpTimeout: &HttpTimeouts{
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 120 * time.Second,
},
},
Ethstats: "",
Telemetry: &TelemetryConfig{
Expand Down Expand Up @@ -507,6 +546,7 @@ func DefaultConfig() *Config {
NoPrefetch: false,
Preimages: false,
TxLookupLimit: 2350000,
TrieTimeout: 60 * time.Minute,
},
Accounts: &AccountsConfig{
Unlock: []string{},
Expand Down Expand Up @@ -566,9 +606,13 @@ func (c *Config) fillTimeDurations() error {
td *time.Duration
str *string
}{
{"jsonrpc.timeouts.read", &c.JsonRPC.HttpTimeout.ReadTimeout, &c.JsonRPC.HttpTimeout.ReadTimeoutRaw},
{"jsonrpc.timeouts.write", &c.JsonRPC.HttpTimeout.WriteTimeout, &c.JsonRPC.HttpTimeout.WriteTimeoutRaw},
{"jsonrpc.timeouts.idle", &c.JsonRPC.HttpTimeout.IdleTimeout, &c.JsonRPC.HttpTimeout.IdleTimeoutRaw},
{"txpool.lifetime", &c.TxPool.LifeTime, &c.TxPool.LifeTimeRaw},
{"txpool.rejournal", &c.TxPool.Rejournal, &c.TxPool.RejournalRaw},
{"cache.rejournal", &c.Cache.Rejournal, &c.Cache.RejournalRaw},
{"cache.timeout", &c.Cache.TrieTimeout, &c.Cache.TrieTimeoutRaw},
}

for _, x := range tds {
Expand Down Expand Up @@ -826,6 +870,7 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (*
n.NoPrefetch = c.Cache.NoPrefetch
n.Preimages = c.Cache.Preimages
n.TxLookupLimit = c.Cache.TxLookupLimit
n.TrieTimeout = c.Cache.TrieTimeout
}

n.RPCGasCap = c.JsonRPC.GasCap
Expand Down Expand Up @@ -920,6 +965,11 @@ func (c *Config) buildNode() (*node.Config, error) {
WSPathPrefix: c.JsonRPC.Ws.Prefix,
GraphQLCors: c.JsonRPC.Graphql.Cors,
GraphQLVirtualHosts: c.JsonRPC.Graphql.VHost,
HTTPTimeouts: rpc.HTTPTimeouts{
ReadTimeout: c.JsonRPC.HttpTimeout.ReadTimeout,
WriteTimeout: c.JsonRPC.HttpTimeout.WriteTimeout,
IdleTimeout: c.JsonRPC.HttpTimeout.IdleTimeout,
},
}

// dev mode
Expand Down
33 changes: 0 additions & 33 deletions internal/cli/server/config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package server

import (
"math/big"
"testing"
"time"

Expand Down Expand Up @@ -101,38 +100,6 @@ func TestDefaultDatatypeOverride(t *testing.T) {
assert.Equal(t, c0, expected)
}

func TestConfigLoadFile(t *testing.T) {
readFile := func(path string) {
config, err := readConfigFile(path)
assert.NoError(t, err)

assert.Equal(t, config, &Config{
DataDir: "./data",
P2P: &P2PConfig{
MaxPeers: 30,
},
TxPool: &TxPoolConfig{
LifeTime: 1 * time.Second,
},
Gpo: &GpoConfig{
MaxPrice: big.NewInt(100),
},
Sealer: &SealerConfig{},
Cache: &CacheConfig{},
})
}

// read file in hcl format
t.Run("hcl", func(t *testing.T) {
readFile("./testdata/test.hcl")
})

// read file in json format
t.Run("json", func(t *testing.T) {
readFile("./testdata/test.json")
})
}

var dummyEnodeAddr = "enode://0cb82b395094ee4a2915e9714894627de9ed8498fb881cec6db7c65e8b9a5bd7f2f25cc84e71e89d0947e51c76e85d0847de848c7782b13c0255247a6758178c@44.232.55.71:30303"

func TestConfigBootnodesDefault(t *testing.T) {
Expand Down
13 changes: 0 additions & 13 deletions internal/cli/server/testdata/test.hcl

This file was deleted.

12 changes: 0 additions & 12 deletions internal/cli/server/testdata/test.json

This file was deleted.

30 changes: 29 additions & 1 deletion scripts/getconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,34 @@ func writeTempStaticTrustedTOML(path string) {
log.Fatal(err)
}
}

if data.Has("Node.HTTPTimeouts.ReadTimeout") {
err = os.WriteFile("./tempHTTPTimeoutsReadTimeout.toml", []byte(data.Get("Node.HTTPTimeouts.ReadTimeout").(string)), 0600)
if err != nil {
log.Fatal(err)
}
}

if data.Has("Node.HTTPTimeouts.WriteTimeout") {
err = os.WriteFile("./tempHTTPTimeoutsWriteTimeout.toml", []byte(data.Get("Node.HTTPTimeouts.WriteTimeout").(string)), 0600)
if err != nil {
log.Fatal(err)
}
}

if data.Has("Node.HTTPTimeouts.IdleTimeout") {
err = os.WriteFile("./tempHTTPTimeoutsIdleTimeout.toml", []byte(data.Get("Node.HTTPTimeouts.IdleTimeout").(string)), 0600)
if err != nil {
log.Fatal(err)
}
}

if data.Has("Eth.TrieTimeout") {
err = os.WriteFile("./tempHTTPTimeoutsTrieTimeout.toml", []byte(data.Get("Eth.TrieTimeout").(string)), 0600)
if err != nil {
log.Fatal(err)
}
}
}

func getStaticTrustedNodes(args []string) {
Expand Down Expand Up @@ -574,7 +602,7 @@ func commentFlags(path string, updatedArgs []string) {
flag = strconv.Itoa(passwordFlag) + "-" + flag
}

if flag != "static-nodes" && flag != "trusted-nodes" {
if flag != "static-nodes" && flag != "trusted-nodes" && flag != "read" && flag != "write" && flag != "idle" && flag != "timeout" {
flag = nameTagMap[flag]

tempFlag := false
Expand Down
48 changes: 48 additions & 0 deletions scripts/getconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,54 @@ else
echo "neither JSON nor TOML TrustedNodes found"
fi

if [[ -f ./tempHTTPTimeoutsReadTimeout.toml ]]
then
echo "HTTPTimeouts.ReadTimeout found"
read=$(head -1 ./tempHTTPTimeoutsReadTimeout.toml)
shopt -s nocasematch; if [[ "$OS" == "darwin"* ]]; then
sed -i '' "s%read = \"30s\"%read = \"${read}\"%" $confPath
else
sed -i "s%read = \"30s\"%read = \"${read}\"%" $confPath
fi
rm ./tempHTTPTimeoutsReadTimeout.toml
fi

if [[ -f ./tempHTTPTimeoutsWriteTimeout.toml ]]
then
echo "HTTPTimeouts.WriteTimeout found"
write=$(head -1 ./tempHTTPTimeoutsWriteTimeout.toml)
shopt -s nocasematch; if [[ "$OS" == "darwin"* ]]; then
sed -i '' "s%write = \"30s\"%write = \"${write}\"%" $confPath
else
sed -i "s%write = \"30s\"%write = \"${write}\"%" $confPath
fi
rm ./tempHTTPTimeoutsWriteTimeout.toml
fi

if [[ -f ./tempHTTPTimeoutsIdleTimeout.toml ]]
then
echo "HTTPTimeouts.IdleTimeout found"
idle=$(head -1 ./tempHTTPTimeoutsIdleTimeout.toml)
shopt -s nocasematch; if [[ "$OS" == "darwin"* ]]; then
sed -i '' "s%idle = \"2m0s\"%idle = \"${idle}\"%" $confPath
else
sed -i "s%idle = \"2m0s\"%idle = \"${idle}\"%" $confPath
fi
rm ./tempHTTPTimeoutsIdleTimeout.toml
fi

if [[ -f ./tempHTTPTimeoutsTrieTimeout.toml ]]
then
echo "Eth.TrieTimeout found"
timeout=$(head -1 ./tempHTTPTimeoutsTrieTimeout.toml)
shopt -s nocasematch; if [[ "$OS" == "darwin"* ]]; then
sed -i '' "s%timeout = \"1h0m0s\"%timeout = \"${timeout}\"%" $confPath
else
sed -i "s%timeout = \"1h0m0s\"%timeout = \"${timeout}\"%" $confPath
fi
rm ./tempHTTPTimeoutsTrieTimeout.toml
fi

printf "\n"

# comment flags in $configPath that were not passed through $startPath
Expand Down