Skip to content

Commit c8ddf75

Browse files
committed
[tmpnet] Provide genesis, subnet and chain config via content flags
Previously supplied genesis, subnet and chain config to nodes via `--*-file-content` flags pointing to files on disk. Switching to use the equivalent `--*-content` flags simplifies configuring nodes deployed to kube where configuration via files is more complicated. To support this, Node.Flags is now used only for generated configuration like keys and user-supplied node-specific config. Network defaults and automatic configuration (like bootstrap IPs/IDs) are not included. Instead, flags.json for each node is generated each time a node is started to ensure that the configuration is up-to-date.
1 parent 20f9dcd commit c8ddf75

File tree

8 files changed

+204
-247
lines changed

8 files changed

+204
-247
lines changed

tests/fixture/tmpnet/README.md

+20-43
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ orchestrate the same temporary networks without the use of an rpc daemon.
2020
- [Configuration on disk](#configuration-on-disk)
2121
- [Common networking configuration](#common-networking-configuration)
2222
- [Genesis](#genesis)
23-
- [Subnet configuration](#subnet-configuration)
24-
- [Chain configuration](#chain-configuration)
23+
- [Subnet and Chain configuration](#subnet-and-chain-configuration)
2524
- [Network env](#network-env)
2625
- [Node configuration](#node-configuration)
2726
- [Runtime config](#runtime-config)
@@ -216,65 +215,43 @@ HOME
216215
│ ├── plugins
217216
│ │ └── ...
218217
│ └── process.json // Node process details (PID, API URI, staking address)
219-
├── chains
220-
│ ├── C
221-
│ │ └── config.json // C-Chain config for all nodes
222-
│ └── raZ51bwfepaSaZ1MNSRNYNs3ZPfj...U7pa3
223-
│ └── config.json // Custom chain configuration for all nodes
224-
├── config.json // Common configuration (including defaults and pre-funded keys)
218+
├── config.json // tmpnet configuration for the network
225219
├── genesis.json // Genesis for all nodes
226220
├── metrics.txt // Link for metrics and logs collected from the network (see: Monitoring)
227221
├── network.env // Sets network dir env var to simplify network usage
228-
└── subnets // Directory containing subnet config for both avalanchego and tmpnet
222+
└── subnets // Directory containing tmpnet subnet configuration
229223
├── subnet-a.json // tmpnet configuration for subnet-a and its chain(s)
230-
├── subnet-b.json // tmpnet configuration for subnet-b and its chain(s)
231-
└── 2jRbWtaonb2RP8DEM5DBsd7...RqNs9.json // avalanchego configuration for subnet with ID 2jRbWtao...RqNs9
224+
└── subnet-b.json // tmpnet configuration for subnet-b and its chain(s)
232225
```
233226

234227
### Common networking configuration
235228
[Top](#table-of-contents)
236229

237230
Network configuration such as default flags (e.g. `--log-level=`),
238231
runtime defaults (e.g. avalanchego path) and pre-funded private keys
239-
are stored at `[network-dir]/config.json`. A given default will only
240-
be applied to a new node on its addition to the network if the node
241-
does not explicitly set a given value.
232+
are stored at `[network-dir]/config.json`. A default for a given flag
233+
will only be applied to a node if that node does not itself set a
234+
value for that flag.
242235

243236
### Genesis
244237
[Top](#table-of-contents)
245238

246-
The genesis file is stored at `[network-dir]/genesis.json` and
247-
referenced by default by all nodes in the network. The genesis file
248-
content will be generated with reasonable defaults if not
249-
supplied. Each node in the network can override the default by setting
250-
an explicit value for `--genesis-file` or `--genesis-file-content`.
239+
The genesis file is stored at `[network-dir]/genesis.json`. The
240+
genesis file content will be generated with reasonable defaults if
241+
not supplied. The content of the file is provided to each node via
242+
the `--genesis-file-content` flag if a node does not set a value for
243+
the flag.
251244

252-
### Subnet configuration
245+
### Subnet and chain configuration
253246
[Top](#table-of-contents)
254247

255-
The subnet configuration for a temporary network is stored at
256-
`[network-dir]/subnets/[subnet ID].json` and referenced by all
257-
nodes in the network.
258-
259-
Each node in the network can override network-level subnet
260-
configuration by setting `--subnet-config-dir` to an explicit value
261-
and ensuring that configuration files for all chains exist at
262-
`[custom-subnet-config-dir]/[subnet ID].json`.
263-
264-
### Chain configuration
265-
[Top](#table-of-contents)
266-
267-
The chain configuration for a temporary network is stored at
268-
`[network-dir]/chains/[chain alias or ID]/config.json` and referenced
269-
by all nodes in the network. The C-Chain config will be generated with
270-
reasonable defaults if not supplied. X-Chain and P-Chain will use
271-
implicit defaults. The configuration for custom chains can be provided
272-
with subnet configuration and will be written to the appropriate path.
273-
274-
Each node in the network can override network-level chain
275-
configuration by setting `--chain-config-dir` to an explicit value and
276-
ensuring that configuration files for all chains exist at
277-
`[custom-chain-config-dir]/[chain alias or ID]/config.json`.
248+
tmpnet configuration for a given subnet and its chain(s) is stored at
249+
`[network-dir]/subnets/[subnet name].json`. Subnet configuration for
250+
all subnets is provided to each node via the
251+
`--subnet-config-content` flag if a node does not set a value for the
252+
flag. Chain configuration for all chains is provided to each node via
253+
the `--chain-config-content` flag where a node does not set a value
254+
for the flag.
278255

279256
### Network env
280257
[Top](#table-of-contents)

tests/fixture/tmpnet/defaults.go

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ func DefaultTestFlags() FlagsMap {
5050
func DefaultTmpnetFlags() FlagsMap {
5151
// Supply only non-default configuration to ensure that default values will be used.
5252
flags := FlagsMap{
53+
// Default to dynamic port allocation
54+
config.HTTPPortKey: "0",
55+
config.StakingPortKey: "0",
5356
// Specific to tmpnet deployment
5457
config.PublicIPKey: "127.0.0.1",
5558
config.HTTPHostKey: "127.0.0.1",

tests/fixture/tmpnet/flags.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,20 @@ func ReadFlagsMap(path string, description string) (FlagsMap, error) {
3030
return flagsMap, nil
3131
}
3232

33+
// SetDefault ensures the effectiveness of a flag override by only
34+
// setting a value supplied whose key is not already explicitly set.
35+
func (f FlagsMap) SetDefault(key string, value any) {
36+
if _, ok := f[key]; !ok {
37+
f[key] = value
38+
}
39+
}
40+
3341
// SetDefaults ensures the effectiveness of flag overrides by only
3442
// setting values supplied in the defaults map that are not already
3543
// explicitly set.
3644
func (f FlagsMap) SetDefaults(defaults FlagsMap) {
3745
for key, value := range defaults {
38-
if _, ok := f[key]; !ok {
39-
f[key] = value
40-
}
46+
f.SetDefault(key, value)
4147
}
4248
}
4349

0 commit comments

Comments
 (0)