/
config.go
141 lines (120 loc) · 5.42 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package evm
import (
"encoding/json"
"time"
"github.com/Toinounet21/coreth-trafficked-v0.8.5-rc.0/eth"
"github.com/spf13/cast"
)
const (
defaultPruningEnabled = true
defaultSnapshotAsync = true
defaultRpcGasCap = 50_000_000 // Default to 50M Gas Limit
defaultRpcTxFeeCap = 100 // 100 AVAX
defaultMetricsEnabled = false
defaultMetricsExpensiveEnabled = false
defaultApiMaxDuration = 0 // Default to no maximum API call duration
defaultWsCpuRefillRate = 0 // Default to no maximum WS CPU usage
defaultWsCpuMaxStored = 0 // Default to no maximum WS CPU usage
defaultMaxBlocksPerRequest = 0 // Default to no maximum on the number of blocks per getLogs request
defaultContinuousProfilerFrequency = 15 * time.Minute
defaultContinuousProfilerMaxFiles = 5
defaultTxRegossipFrequency = 1 * time.Minute
defaultTxRegossipMaxSize = 15
defaultOfflinePruningBloomFilterSize uint64 = 512 // Default size (MB) for the offline pruner to use
defaultLogLevel = "info"
)
var defaultEnabledAPIs = []string{
"public-eth",
"public-eth-filter",
"net",
"web3",
"internal-public-eth",
"internal-public-blockchain",
"internal-public-transaction-pool",
}
type Duration struct {
time.Duration
}
// Config ...
type Config struct {
// Coreth APIs
SnowmanAPIEnabled bool `json:"snowman-api-enabled"`
CorethAdminAPIEnabled bool `json:"coreth-admin-api-enabled"`
CorethAdminAPIDir string `json:"coreth-admin-api-dir"`
// EnabledEthAPIs is a list of Ethereum services that should be enabled
// If none is specified, then we use the default list [defaultEnabledAPIs]
EnabledEthAPIs []string `json:"eth-apis"`
// Continuous Profiler
ContinuousProfilerDir string `json:"continuous-profiler-dir"` // If set to non-empty string creates a continuous profiler
ContinuousProfilerFrequency Duration `json:"continuous-profiler-frequency"` // Frequency to run continuous profiler if enabled
ContinuousProfilerMaxFiles int `json:"continuous-profiler-max-files"` // Maximum number of files to maintain
// Coreth API Gas/Price Caps
RPCGasCap uint64 `json:"rpc-gas-cap"`
RPCTxFeeCap float64 `json:"rpc-tx-fee-cap"`
// Eth Settings
Preimages bool `json:"preimages-enabled"`
Pruning bool `json:"pruning-enabled"`
SnapshotAsync bool `json:"snapshot-async"`
SnapshotVerify bool `json:"snapshot-verification-enabled"`
// Metric Settings
MetricsEnabled bool `json:"metrics-enabled"`
MetricsExpensiveEnabled bool `json:"metrics-expensive-enabled"`
// API Settings
LocalTxsEnabled bool `json:"local-txs-enabled"`
APIMaxDuration Duration `json:"api-max-duration"`
WSCPURefillRate Duration `json:"ws-cpu-refill-rate"`
WSCPUMaxStored Duration `json:"ws-cpu-max-stored"`
MaxBlocksPerRequest int64 `json:"api-max-blocks-per-request"`
AllowUnfinalizedQueries bool `json:"allow-unfinalized-queries"`
AllowUnprotectedTxs bool `json:"allow-unprotected-txs"`
// Keystore Settings
KeystoreDirectory string `json:"keystore-directory"` // both absolute and relative supported
KeystoreExternalSigner string `json:"keystore-external-signer"`
KeystoreInsecureUnlockAllowed bool `json:"keystore-insecure-unlock-allowed"`
// Gossip Settings
RemoteTxGossipOnlyEnabled bool `json:"remote-tx-gossip-only-enabled"`
TxRegossipFrequency Duration `json:"tx-regossip-frequency"`
TxRegossipMaxSize int `json:"tx-regossip-max-size"`
// Log level
LogLevel string `json:"log-level"`
// Offline Pruning Settings
OfflinePruning bool `json:"offline-pruning-enabled"`
OfflinePruningBloomFilterSize uint64 `json:"offline-pruning-bloom-filter-size"`
OfflinePruningDataDirectory string `json:"offline-pruning-data-directory"`
}
// EthAPIs returns an array of strings representing the Eth APIs that should be enabled
func (c Config) EthAPIs() []string {
return c.EnabledEthAPIs
}
func (c Config) EthBackendSettings() eth.Settings {
return eth.Settings{MaxBlocksPerRequest: c.MaxBlocksPerRequest}
}
func (c *Config) SetDefaults() {
c.EnabledEthAPIs = defaultEnabledAPIs
c.RPCGasCap = defaultRpcGasCap
c.RPCTxFeeCap = defaultRpcTxFeeCap
c.MetricsEnabled = defaultMetricsEnabled
c.MetricsExpensiveEnabled = defaultMetricsExpensiveEnabled
c.APIMaxDuration.Duration = defaultApiMaxDuration
c.WSCPURefillRate.Duration = defaultWsCpuRefillRate
c.WSCPUMaxStored.Duration = defaultWsCpuMaxStored
c.MaxBlocksPerRequest = defaultMaxBlocksPerRequest
c.ContinuousProfilerFrequency.Duration = defaultContinuousProfilerFrequency
c.ContinuousProfilerMaxFiles = defaultContinuousProfilerMaxFiles
c.Pruning = defaultPruningEnabled
c.SnapshotAsync = defaultSnapshotAsync
c.TxRegossipFrequency.Duration = defaultTxRegossipFrequency
c.TxRegossipMaxSize = defaultTxRegossipMaxSize
c.OfflinePruningBloomFilterSize = defaultOfflinePruningBloomFilterSize
c.LogLevel = defaultLogLevel
}
func (d *Duration) UnmarshalJSON(data []byte) (err error) {
var v interface{}
if err := json.Unmarshal(data, &v); err != nil {
return err
}
d.Duration, err = cast.ToDurationE(v)
return err
}