Skip to content

Commit f84bf70

Browse files
feat(config): map bee config 1:1 to bee flags (#602)
* feat(config): map bee config 1:1 to bee flags * fix: remove bootnodes from local config * fix: simplify config
1 parent e105d4c commit f84bf70

20 files changed

Lines changed: 422 additions & 257 deletions

cmd/beekeeper/cmd/cluster.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,13 @@ func setupBootnodes(ctx context.Context,
247247
nodeName = node.Name
248248
}
249249

250-
bConfig.Bootnodes = fmt.Sprintf(node.Bootnodes, clusterConfig.GetNamespace()) // TODO: improve bootnode management, support more than 2 bootnodes
251-
bootnodesOut = bConfig.Bootnodes
252-
nodeOpts := setupNodeOptions(node, &bConfig)
250+
// each node gets its own config copy, as the bootnode list is
251+
// node-specific and nodes are set up concurrently
252+
nodeConfig := bConfig
253+
bootnodes := fmt.Sprintf(node.Bootnodes, clusterConfig.GetNamespace()) // TODO: improve bootnode management, support more than 2 bootnodes
254+
nodeConfig.Bootnodes = &[]string{bootnodes}
255+
bootnodesOut = bootnodes
256+
nodeOpts := setupNodeOptions(node, &nodeConfig)
253257
nodeCount++
254258
go setupOrAddNode(ctx, startCluster, inCluster, ng, nodeName, nodeOpts, nodeResultChan, orchestration.WithNoOptions())
255259
}
@@ -299,8 +303,8 @@ func setupNodes(ctx context.Context,
299303
}
300304
bConfig := beeConfig.Export()
301305

302-
if bConfig.Bootnodes == "" {
303-
bConfig.Bootnodes = bootnodesIn
306+
if (bConfig.Bootnodes == nil || len(*bConfig.Bootnodes) == 0) && bootnodesIn != "" {
307+
bConfig.Bootnodes = &[]string{bootnodesIn}
304308
}
305309
ngOptions.BeeConfig = &bConfig
306310

config/config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ bee-configs:
9494
block-time: 1
9595
blockchain-rpc-endpoint: "ws://geth-swap.bee-playground.svc.swarm1.local:8546"
9696
bootnode-mode: false
97-
bootnodes: ""
97+
bootnode: []
9898
cache-capacity: 1000000
9999
chequebook-enable: true
100-
cors-allowed-origins: ""
100+
cors-allowed-origins: []
101101
data-dir: "/home/bee/.bee"
102102
db-block-cache-capacity: 33554432
103103
db-disable-seeks-compaction: false
@@ -117,19 +117,19 @@ bee-configs:
117117
postage-stamp-start-block: 1
118118
price-oracle-address: "0x5aFE06fcC0855a76a15c3544b0886EDBE3294d62"
119119
redistribution-address: "0x09Ad42a7d020244920309FfA14EA376dd2D3b7d5"
120-
resolver-options: ""
120+
resolver-options: []
121121
staking-address: "0xfc28330f1ecE0ef2371B724E0D19c1EE60B728b2"
122122
storage-incentives-enable: true
123123
swap-enable: true
124124
swap-factory-address: "0xdD661f2500bA5831e3d1FEbAc379Ea1bF80773Ac"
125125
swap-initial-deposit: 500000000000000000
126-
tracing-enabled: true
126+
tracing-enable: true
127127
tracing-endpoint: "10.10.11.199:6831"
128128
tracing-service-name: "bee"
129129
verbosity: 5 # 1=error, 2=warn, 3=info, 4=debug, 5=trace
130130
warmup-time: 0s
131131
welcome-message: "Welcome to the Swarm, you are Bee-ing connected!"
132-
withdrawal-addresses-whitelist: "0xec44cb15b1b033e74d55ac5d0e24d861bde54532"
132+
withdrawal-addresses-whitelist: ["0xec44cb15b1b033e74d55ac5d0e24d861bde54532"]
133133
bootnode:
134134
_inherit: "default"
135135
bootnode-mode: true

config/local.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ bee-configs:
152152
block-time: 1
153153
blockchain-rpc-endpoint: "ws://geth-swap:8546"
154154
bootnode-mode: false
155-
bootnodes: ""
155+
bootnode: []
156156
cache-capacity: 20000
157157
chequebook-enable: true
158-
cors-allowed-origins: ""
158+
cors-allowed-origins: []
159159
data-dir: "/home/bee/.bee"
160160
db-block-cache-capacity: 33554432
161161
db-disable-seeks-compaction: false
@@ -178,7 +178,7 @@ bee-configs:
178178
postage-stamp-start-block: 1
179179
price-oracle-address: "0x5aFE06fcC0855a76a15c3544b0886EDBE3294d62"
180180
redistribution-address: "0x09Ad42a7d020244920309FfA14EA376dd2D3b7d5"
181-
resolver-options: ""
181+
resolver-options: []
182182
staking-address: "0xfc28330f1ecE0ef2371B724E0D19c1EE60B728b2"
183183
storage-incentives-enable: true
184184
swap-enable: true
@@ -187,14 +187,13 @@ bee-configs:
187187
verbosity: 5
188188
warmup-time: 0s
189189
welcome-message: "Welcome to the Swarm, this is a local cluster!"
190-
withdrawal-addresses-whitelist: "0xec44cb15b1b033e74d55ac5d0e24d861bde54532"
190+
withdrawal-addresses-whitelist: ["0xec44cb15b1b033e74d55ac5d0e24d861bde54532"]
191191
bootnode-local-dns-autotls:
192192
_inherit: "bee-local-dns"
193193
bootnode-mode: true
194194
p2p-wss-enable: true
195195
bee-local-autotls:
196196
_inherit: "bee-local-dns"
197-
bootnode: /dnsaddr/bootnode-0-headless.local.svc.cluster.local
198197
p2p-wss-enable: true
199198
bee-local-light-autotls:
200199
_inherit: "bee-local-light"
@@ -209,14 +208,11 @@ bee-configs:
209208
bootnode-mode: true
210209
bee-local-dns:
211210
_inherit: "bee-local"
212-
bootnode: /dnsaddr/localhost
213211
bootnode-local-dns:
214212
_inherit: "bee-local"
215-
bootnode: /dnsaddr/localhost
216213
bootnode-mode: true
217214
bee-local-light:
218215
_inherit: "bee-local"
219-
bootnode: /dnsaddr/localhost
220216
full-node: false
221217
bee-local-gc:
222218
_inherit: "bee-local"

config/public-testnet.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ node-groups:
4646
bee-configs:
4747
sepolia:
4848
_inherit: ""
49-
bootnodes: "/dnsaddr/testnet.ethswarm.org"
49+
bootnode: ["/dnsaddr/testnet.ethswarm.org"]
5050
full-node: true
5151

5252
checks:

config/staging.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ clusters:
1818
mode: node
1919
bee-config: staging
2020
config: staging
21-
count: 5
21+
count: 1
2222

2323
# node-groups defines node groups that can be registered in the cluster
2424
# node-groups may inherit it's configuration from already defined node-group and override specific fields from it
@@ -34,14 +34,14 @@ bee-configs:
3434
_inherit: ""
3535
api-addr: ":1633"
3636
blockchain-rpc-endpoint: http://rpc-sepolia-haproxy.default.svc.swarm1.local
37-
bootnodes: /dnsaddr/testnet.ethswarm.org
37+
bootnode: ["/dnsaddr/testnet.ethswarm.org"]
3838
full-node: true
3939
mainnet: false
4040
network-id: 10
4141
p2p-addr: ":1634"
4242
password: "beekeeper"
4343
swap-enable: true
44-
tracing-enabled: true
44+
tracing-enable: true
4545
tracing-endpoint: "10.10.11.199:6831"
4646
tracing-service-name: "bee"
4747
verbosity: 4

config/testnet-bee-playground.yaml

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ clusters:
99
api-insecure-tls: true
1010
api-scheme: http
1111
funding:
12-
eth: 0.1
12+
eth: 0.01
1313
bzz: 3.0
1414
node-groups:
1515
bootnode:
@@ -44,33 +44,16 @@ bee-configs:
4444
api-addr: :1633
4545
block-time: 12
4646
blockchain-rpc-endpoint: http://rpc-sepolia-haproxy.default.svc.swarm1.local
47-
bootnode-mode: false
48-
bootnodes: # /dnsaddr/testnet.ethswarm.org
49-
cache-capacity: 1000000
47+
# bootnode: [dnsaddr/testnet.ethswarm.org]
5048
chequebook-enable: true
51-
cors-allowed-origins: ""
5249
data-dir: "/home/bee/.bee"
53-
db-block-cache-capacity: 33554432
54-
db-disable-seeks-compaction: true
55-
db-open-files-limit: 200
56-
db-write-buffer-size: 33554432
5750
full-node: true
5851
mainnet: false
59-
nat-addr: ""
6052
network-id: 5
6153
p2p-addr: :1634
62-
p2p-ws-enable: true
6354
password: "beekeeper"
64-
payment-early-percent: 50
65-
payment-threshold: 13500000
66-
payment-tolerance-percent: 25
67-
postage-stamp-start-block: 0
6855
storage-incentives-enable: true
6956
swap-enable: true
70-
swap-initial-deposit: 0
71-
tracing-enabled: false
72-
tracing-endpoint: "10.10.11.199:6831"
73-
tracing-service-name: "bee-playground"
7457
verbosity: 5
7558
warmup-time: 5m0s
7659
welcome-message: Welcome to the bee-playground!

pkg/check/autotls/autotls.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,10 @@ func (c *Check) forgeConfig(ctx context.Context, cluster orchestration.Cluster,
302302
continue
303303
}
304304
cfg := node.Config()
305-
forgeDomain = cfg.AutoTLSDomain
306-
if strings.Contains(cfg.AutoTLSCAEndpoint, "pebble") {
307-
mgmtURL := pebbleMgmtURL(cfg.AutoTLSCAEndpoint)
305+
forgeDomain = orchestration.Deref(cfg.AutoTLSDomain)
306+
caEndpoint := orchestration.Deref(cfg.AutoTLSCAEndpoint)
307+
if strings.Contains(caEndpoint, "pebble") {
308+
mgmtURL := pebbleMgmtURL(caEndpoint)
308309
if pebbleMgmtURLOverride != "" {
309310
mgmtURL = pebbleMgmtURLOverride
310311
}

pkg/config/bee.go

Lines changed: 15 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,24 @@
11
package config
22

33
import (
4-
"reflect"
5-
"time"
6-
74
"github.com/ethersphere/beekeeper/pkg/orchestration"
85
)
96

107
type Inheritable interface {
118
GetParentName() string
129
}
1310

14-
// BeeConfig represents Bee configuration
11+
// BeeConfig represents Bee configuration as read from Beekeeper's YAML config.
12+
//
13+
// It embeds orchestration.Config (the Bee flag set), so the flag fields are
14+
// defined in exactly one place and the same yaml tags — the Bee flag names —
15+
// are used both for reading the config here and for rendering the node's
16+
// .bee.yaml. The only thing BeeConfig adds is the config-file-only concern of
17+
// inheritance (_inherit). Export returns just the embedded Config, so neither
18+
// _inherit nor any other config-loading detail can leak into the rendered file.
1519
type BeeConfig struct {
16-
// parent to inherit settings from
17-
*Inherit `yaml:",inline"`
18-
// Bee configuration
19-
AllowPrivateCIDRs *bool `yaml:"allow-private-cidrs"`
20-
APIAddr *string `yaml:"api-addr"`
21-
AutoTLSCAEndpoint *string `yaml:"autotls-ca-endpoint"`
22-
AutoTLSDomain *string `yaml:"autotls-domain"`
23-
AutoTLSRegistrationEndpoint *string `yaml:"autotls-registration-endpoint"`
24-
BlockchainRPCEndpoint *string `yaml:"blockchain-rpc-endpoint"`
25-
BlockTime *uint64 `yaml:"block-time"`
26-
BootnodeMode *bool `yaml:"bootnode-mode"`
27-
Bootnodes *string `yaml:"bootnodes"`
28-
CacheCapacity *uint64 `yaml:"cache-capacity"`
29-
ChequebookEnable *bool `yaml:"chequebook-enable"`
30-
CORSAllowedOrigins *string `yaml:"cors-allowed-origins"`
31-
DataDir *string `yaml:"data-dir"`
32-
DbBlockCacheCapacity *int `yaml:"db-block-cache-capacity"`
33-
DbDisableSeeksCompaction *bool `yaml:"db-disable-seeks-compaction"`
34-
DbOpenFilesLimit *int `yaml:"db-open-files-limit"`
35-
DbWriteBufferSize *int `yaml:"db-write-buffer-size"`
36-
FullNode *bool `yaml:"full-node"`
37-
Mainnet *bool `yaml:"mainnet"`
38-
NATAddr *string `yaml:"nat-addr"`
39-
NATWSSAddr *string `yaml:"nat-wss-addr"`
40-
NetworkID *uint64 `yaml:"network-id"`
41-
P2PAddr *string `yaml:"p2p-addr"`
42-
P2PWSEnable *bool `yaml:"p2p-ws-enable"`
43-
P2PWSSAddr *string `yaml:"p2p-wss-addr"`
44-
P2PWSSEnable *bool `yaml:"p2p-wss-enable"`
45-
Password *string `yaml:"password"`
46-
PaymentEarly *uint64 `yaml:"payment-early-percent"`
47-
PaymentThreshold *uint64 `yaml:"payment-threshold"`
48-
PaymentTolerance *uint64 `yaml:"payment-tolerance-percent"`
49-
PostageContractStartBlock *uint64 `yaml:"postage-stamp-start-block"`
50-
PostageStampAddress *string `yaml:"postage-stamp-address"`
51-
PriceOracleAddress *string `yaml:"price-oracle-address"`
52-
RedistributionAddress *string `yaml:"redistribution-address"`
53-
ResolverOptions *string `yaml:"resolver-options"`
54-
StakingAddress *string `yaml:"staking-address"`
55-
StorageIncentivesEnable *string `yaml:"storage-incentives-enable"`
56-
SwapEnable *bool `yaml:"swap-enable"`
57-
SwapEndpoint *string `yaml:"swap-endpoint"` // deprecated: use blockchain-rpc-endpoint
58-
SwapFactoryAddress *string `yaml:"swap-factory-address"`
59-
SwapInitialDeposit *uint64 `yaml:"swap-initial-deposit"`
60-
TracingEnabled *bool `yaml:"tracing-enabled"`
61-
TracingEndpoint *string `yaml:"tracing-endpoint"`
62-
TracingServiceName *string `yaml:"tracing-service-name"`
63-
Verbosity *uint64 `yaml:"verbosity"`
64-
WarmupTime *time.Duration `yaml:"warmup-time"`
65-
WelcomeMessage *string `yaml:"welcome-message"`
66-
WithdrawAddress *string `yaml:"withdrawal-addresses-whitelist"`
20+
*Inherit `yaml:",inline"`
21+
orchestration.Config `yaml:",inline"`
6722
}
6823

6924
func (b BeeConfig) GetParentName() string {
@@ -73,30 +28,9 @@ func (b BeeConfig) GetParentName() string {
7328
return ""
7429
}
7530

76-
// Export exports BeeConfig to orchestration.Config
77-
func (b *BeeConfig) Export() (config orchestration.Config) {
78-
localVal := reflect.ValueOf(b).Elem()
79-
localType := reflect.TypeFor[BeeConfig]()
80-
remoteVal := reflect.ValueOf(&config).Elem()
81-
82-
for i := range localVal.NumField() {
83-
localField := localVal.Field(i)
84-
if localField.IsValid() && !localField.IsNil() {
85-
localFieldVal := localVal.Field(i).Elem()
86-
localFieldName := localType.Field(i).Name
87-
88-
remoteFieldVal := remoteVal.FieldByName(localFieldName)
89-
if remoteFieldVal.IsValid() && remoteFieldVal.Type() == localFieldVal.Type() {
90-
remoteFieldVal.Set(localFieldVal)
91-
}
92-
}
93-
}
94-
95-
config = remoteVal.Interface().(orchestration.Config)
96-
97-
if config.BlockchainRPCEndpoint == "" && b.SwapEndpoint != nil {
98-
config.BlockchainRPCEndpoint = *b.SwapEndpoint
99-
}
100-
101-
return config
31+
// Export returns the Bee flag configuration to be rendered into the node's
32+
// .bee.yaml. Inheritance has already been resolved during config loading and is
33+
// not part of the embedded Config.
34+
func (b *BeeConfig) Export() orchestration.Config {
35+
return b.Config
10236
}

0 commit comments

Comments
 (0)