-
Notifications
You must be signed in to change notification settings - Fork 1
/
reth-config.go
154 lines (135 loc) · 4.97 KB
/
reth-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
142
143
144
145
146
147
148
149
150
151
152
153
154
package config
import (
"runtime"
"github.com/pbnjay/memory"
"github.com/rocket-pool/node-manager-core/config/ids"
)
// Constants
const (
rethTagProd string = "ghcr.io/paradigmxyz/reth:v0.2.0-beta.6"
rethTagTest string = "ghcr.io/paradigmxyz/reth:v0.2.0-beta.6"
)
// Configuration for Reth
type RethConfig struct {
// Size of Reth's Cache
CacheSize Parameter[uint64]
// Max number of P2P peers that can connect to this node
MaxInboundPeers Parameter[uint16]
// Max number of P2P peers to this node can connect to
MaxOutboundPeers Parameter[uint16]
// The Docker Hub tag for Reth
ContainerTag Parameter[string]
// Custom command line flags
AdditionalFlags Parameter[string]
}
// Generates a new Reth configuration
func NewRethConfig() *RethConfig {
return &RethConfig{
CacheSize: Parameter[uint64]{
ParameterCommon: &ParameterCommon{
ID: ids.CacheSizeID,
Name: "Cache Size",
Description: "The amount of RAM (in MB) you want Reth's cache to use. Larger values mean your disk space usage will increase slower, and you will have to prune less frequently. The default is based on how much total RAM your system has but you can adjust it manually.",
AffectsContainers: []ContainerID{ContainerID_ExecutionClient},
CanBeBlank: false,
OverwriteOnUpgrade: false,
},
Default: map[Network]uint64{
Network_All: calculateRethCache(),
},
},
MaxInboundPeers: Parameter[uint16]{
ParameterCommon: &ParameterCommon{
ID: ids.RethMaxInboundPeersID,
Name: "Max Inbound Peers",
Description: "The maximum number of inbound peers that should be allowed to connect to Reth (peers that request to connect to your node). This can be lowered to improve performance on low-power systems or constrained networks. Inbound peers requires you to have properly forwarded ports. We recommend keeping the sum of this and max outbound peers at 12 or higher.",
AffectsContainers: []ContainerID{ContainerID_ExecutionClient},
CanBeBlank: false,
OverwriteOnUpgrade: false,
},
Default: map[Network]uint16{Network_All: calculateRethPeers()},
},
MaxOutboundPeers: Parameter[uint16]{
ParameterCommon: &ParameterCommon{
ID: ids.RethMaxOutboundPeersID,
Name: "Max Outbound Peers",
Description: "The maximum number of outbound peers that Reth can connect to (peers that your node requests to connect to). This can be lowered to improve performance on low-power systems or constrained networks. Outbound peers do not require proper port forwarding, but are slower to accumulate than inbound peers. We recommend keeping the sum of this and max outbound peers at 12 or higher.",
AffectsContainers: []ContainerID{ContainerID_ExecutionClient},
CanBeBlank: false,
OverwriteOnUpgrade: false,
},
Default: map[Network]uint16{Network_All: calculateRethPeers()},
},
ContainerTag: Parameter[string]{
ParameterCommon: &ParameterCommon{
ID: ids.ContainerTagID,
Name: "Container Tag",
Description: "The tag name of the Reth container you want to use.",
AffectsContainers: []ContainerID{ContainerID_ExecutionClient},
CanBeBlank: false,
OverwriteOnUpgrade: true,
},
Default: map[Network]string{
Network_Mainnet: rethTagProd,
Network_Holesky: rethTagTest,
},
},
AdditionalFlags: Parameter[string]{
ParameterCommon: &ParameterCommon{
ID: ids.AdditionalFlagsID,
Name: "Additional Flags",
Description: "Additional custom command line flags you want to pass to Reth, to take advantage of other settings that aren't covered here.",
AffectsContainers: []ContainerID{ContainerID_ExecutionClient},
CanBeBlank: true,
OverwriteOnUpgrade: false,
},
Default: map[Network]string{
Network_All: "",
},
},
}
}
// Get the title for the config
func (cfg *RethConfig) GetTitle() string {
return "Reth"
}
// Get the config.Parameters for this config
func (cfg *RethConfig) GetParameters() []IParameter {
return []IParameter{
&cfg.CacheSize,
&cfg.MaxInboundPeers,
&cfg.MaxOutboundPeers,
&cfg.ContainerTag,
&cfg.AdditionalFlags,
}
}
// Get the sections underneath this one
func (cfg *RethConfig) GetSubconfigs() map[string]IConfigSection {
return map[string]IConfigSection{}
}
// Calculate the recommended size for Reth's cache based on the amount of system RAM
func calculateRethCache() uint64 {
totalMemoryGB := memory.TotalMemory() / 1024 / 1024 / 1024
if totalMemoryGB == 0 {
return 0
} else if totalMemoryGB < 9 {
return 256
} else if totalMemoryGB < 13 {
return 2048
} else if totalMemoryGB < 17 {
return 4096
} else if totalMemoryGB < 25 {
return 8192
} else if totalMemoryGB < 33 {
return 12288
} else {
return 16384
}
}
// Calculate the default number of Reth peers
func calculateRethPeers() uint16 {
if runtime.GOARCH == "arm64" {
return 12
}
return 25
}