-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathnethermind-params.go
245 lines (209 loc) · 9.39 KB
/
nethermind-params.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
This work is licensed and released under GNU GPL v3 or any other later versions.
The full text of the license is below/ found at <http://www.gnu.org/licenses/>
(c) 2023 Rocket Pool Pty Ltd. Modified under GNU GPL v3. [1.4.7]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package config
import (
"runtime"
"github.com/pbnjay/memory"
"github.com/stader-labs/stader-node/shared/types/config"
)
// Constants
const (
nethermindTagProd string = "nethermind/nethermind:1.25.4"
nethermindTagTest string = "nethermind/nethermind:1.25.4"
nethermindEventLogInterval int = 1000
nethermindStopSignal string = "SIGTERM"
)
// Configuration for Nethermind
type NethermindConfig struct {
Title string `yaml:"-"`
// Common parameters that Nethermind doesn't support and should be hidden
UnsupportedCommonParams []string `yaml:"-"`
// Compatible consensus clients
CompatibleConsensusClients []config.ConsensusClient `yaml:"-"`
// The max number of events to query in a single event log query
EventLogInterval int `yaml:"-"`
// Nethermind's cache memory hint
CacheSize config.Parameter `yaml:"cacheSize,omitempty"`
// Max number of P2P peers to connect to
MaxPeers config.Parameter `yaml:"maxPeers,omitempty"`
// Nethermind's memory for pruning
PruneMemSize config.Parameter `yaml:"pruneMemSize,omitempty"`
// Additional modules to enable on the primary JSON RPC endpoint
AdditionalModules config.Parameter `yaml:"additionalModules,omitempty"`
// Additional JSON RPC URLs
AdditionalUrls config.Parameter `yaml:"additionalUrls,omitempty"`
// The Docker Hub tag for Nethermind
ContainerTag config.Parameter `yaml:"containerTag,omitempty"`
// Custom command line flags
AdditionalFlags config.Parameter `yaml:"additionalFlags,omitempty"`
}
// Generates a new Nethermind configuration
func NewNethermindConfig(cfg *StaderConfig) *NethermindConfig {
return &NethermindConfig{
Title: "Nethermind Settings",
UnsupportedCommonParams: []string{},
CompatibleConsensusClients: []config.ConsensusClient{
config.ConsensusClient_Lighthouse,
config.ConsensusClient_Nimbus,
config.ConsensusClient_Prysm,
config.ConsensusClient_Teku,
},
EventLogInterval: nethermindEventLogInterval,
CacheSize: config.Parameter{
ID: "cache",
Name: "Cache (Memory Hint) Size",
Description: "The amount of RAM (in MB) you want to suggest for Nethermind's cache. While there is no guarantee that Nethermind will stay under this limit, lower values are preferred for machines with less RAM.\n\nThe default value for this will be calculated dynamically based on your system's available RAM, but you can adjust it manually.",
Type: config.ParameterType_Uint,
Default: map[config.Network]interface{}{config.Network_All: calculateNethermindCache()},
AffectsContainers: []config.ContainerID{config.ContainerID_Eth1},
EnvironmentVariables: []string{"EC_CACHE_SIZE"},
CanBeBlank: false,
OverwriteOnUpgrade: false,
},
MaxPeers: config.Parameter{
ID: "maxPeers",
Name: "Max Peers",
Description: "The maximum number of peers Nethermind should connect to. This can be lowered to improve performance on low-power systems or constrained config.Networks. We recommend keeping it at 12 or higher.",
Type: config.ParameterType_Uint16,
Default: map[config.Network]interface{}{config.Network_All: calculateNethermindPeers()},
AffectsContainers: []config.ContainerID{config.ContainerID_Eth1},
EnvironmentVariables: []string{"EC_MAX_PEERS"},
CanBeBlank: false,
OverwriteOnUpgrade: false,
},
PruneMemSize: config.Parameter{
ID: "pruneMemSize",
Name: "In-Memory Pruning Cache Size",
Description: "The amount of RAM (in MB) you want to dedicate to Nethermind for its in-memory pruning system. Higher values mean less writes to your SSD and slower overall database growth.\n\nThe default value for this will be calculated dynamically based on your system's available RAM, but you can adjust it manually.",
Type: config.ParameterType_Uint,
Default: map[config.Network]interface{}{config.Network_All: calculateNethermindPruneMemSize()},
AffectsContainers: []config.ContainerID{config.ContainerID_Eth1},
EnvironmentVariables: []string{"NETHERMIND_PRUNE_MEM_SIZE"},
CanBeBlank: false,
OverwriteOnUpgrade: false,
},
AdditionalModules: config.Parameter{
ID: "additionalModules",
Name: "Additional Modules",
Description: "Additional modules you want to add to the primary JSON-RPC route. The defaults are Eth,Net,Personal,Web3. You can add any additional ones you need here; separate multiple modules with commas, and do not use spaces.",
Type: config.ParameterType_String,
Default: map[config.Network]interface{}{config.Network_All: ""},
AffectsContainers: []config.ContainerID{config.ContainerID_Eth1},
EnvironmentVariables: []string{"NETHERMIND_ADDITIONAL_MODULES"},
CanBeBlank: true,
OverwriteOnUpgrade: false,
},
AdditionalUrls: config.Parameter{
ID: "additionalUrls",
Name: "Additional URLs",
Description: "Additional JSON-RPC URLs you want to run alongside the primary URL. These will be added to the \"--JsonRpc.AdditionalRpcUrls\" argument. Wrap each additional URL in quotes, and separate multiple URLs with commas (no spaces). Please consult the Nethermind documentation for more information on this flag, its intended usage, and its expected formatting.\n\nFor advanced users only.",
Type: config.ParameterType_String,
Default: map[config.Network]interface{}{config.Network_All: ""},
AffectsContainers: []config.ContainerID{config.ContainerID_Eth1},
EnvironmentVariables: []string{"NETHERMIND_ADDITIONAL_URLS"},
CanBeBlank: true,
OverwriteOnUpgrade: false,
},
ContainerTag: config.Parameter{
ID: "containerTag",
Name: "Container Tag",
Description: "The tag name of the Nethermind container you want to use on Docker Hub.",
Type: config.ParameterType_String,
Default: map[config.Network]interface{}{
config.Network_Mainnet: nethermindTagProd,
config.Network_Prater: nethermindTagTest,
config.Network_Devnet: nethermindTagTest,
config.Network_Zhejiang: nethermindTagTest,
},
AffectsContainers: []config.ContainerID{config.ContainerID_Eth1},
EnvironmentVariables: []string{"EC_CONTAINER_TAG"},
CanBeBlank: false,
OverwriteOnUpgrade: true,
},
AdditionalFlags: config.Parameter{
ID: "additionalFlags",
Name: "Additional Flags",
Description: "Additional custom command line flags you want to pass to Nethermind, to take advantage of other settings that the Stadernode's configuration doesn't cover.",
Type: config.ParameterType_String,
Default: map[config.Network]interface{}{config.Network_All: ""},
AffectsContainers: []config.ContainerID{config.ContainerID_Eth1},
EnvironmentVariables: []string{"EC_ADDITIONAL_FLAGS"},
CanBeBlank: true,
OverwriteOnUpgrade: false,
},
}
}
// Calculate the recommended size for Nethermind's cache based on the amount of system RAM
func calculateNethermindCache() uint64 {
totalMemoryGB := memory.TotalMemory() / 1024 / 1024 / 1024
if totalMemoryGB == 0 {
return 0
} else if totalMemoryGB < 9 {
return 512
} else if totalMemoryGB < 13 {
return 512
} else if totalMemoryGB < 17 {
return 1024
} else if totalMemoryGB < 25 {
return 2048
} else if totalMemoryGB < 33 {
return 4096
} else {
return 8192
}
}
// Calculate the recommended size for Nethermind's in-memory pruning based on the amount of system RAM
func calculateNethermindPruneMemSize() uint64 {
totalMemoryGB := memory.TotalMemory() / 1024 / 1024 / 1024
if totalMemoryGB == 0 {
return 0
} else if totalMemoryGB < 9 {
return 256
} else if totalMemoryGB < 13 {
return 512
} else if totalMemoryGB < 17 {
return 1024
} else if totalMemoryGB < 25 {
return 2048
} else if totalMemoryGB < 33 {
return 4096
} else {
return 8192
}
}
// Calculate the default number of Nethermind peers
func calculateNethermindPeers() uint16 {
if runtime.GOARCH == "arm64" {
return 25
}
return 50
}
// Get the parameters for this config
func (cfg *NethermindConfig) GetParameters() []*config.Parameter {
return []*config.Parameter{
&cfg.CacheSize,
&cfg.MaxPeers,
&cfg.PruneMemSize,
&cfg.AdditionalModules,
&cfg.AdditionalUrls,
&cfg.ContainerTag,
&cfg.AdditionalFlags,
}
}
// The the title for the config
func (cfg *NethermindConfig) GetConfigTitle() string {
return cfg.Title
}