Skip to content

Commit dbf85f1

Browse files
authored
custom network support in nrpc (#3148)
* custom network support in for devnet testing * use single config * use joinPath
1 parent 7104c1f commit dbf85f1

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

nrpc/config.nim

+15-8
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,14 @@ type
7373
abbr: "i"
7474
name: "network" }: string
7575

76-
customNetwork {.
77-
desc: "Use custom genesis block for private Ethereum Network (as /path/to/genesis.json)"
78-
defaultValueDesc: ""
79-
abbr: "c"
80-
name: "custom-network" }: Option[NetworkParams]
76+
customNetworkFolder* {.
77+
desc: "Use custom config for private Ethereum Network (as /path/to/metadata)"
78+
longDesc:
79+
"Path to a folder containing custom network configuration files\n" &
80+
"such as genesis.json, config.yaml, etc.\n" &
81+
"config.yaml is the configuration file for the CL client"
82+
defaultValue: ""
83+
name: "custom-network" .}: string
8184

8285
networkId* {.
8386
ignore # this field is not processed by confutils
@@ -187,8 +190,12 @@ proc makeConfig*(cmdLine = commandLineParams()): NRpcConf
187190

188191
var networkId = result.getNetworkId()
189192

190-
if result.customNetwork.isSome:
191-
result.networkParams = result.customNetwork.get()
193+
if result.customNetworkFolder.len > 0:
194+
var networkParams = NetworkParams()
195+
if not loadNetworkParams(result.customNetworkFolder.joinPath("genesis.json"), networkParams):
196+
error "Failed to load customNetwork", path=result.customNetworkFolder
197+
quit QuitFailure
198+
result.networkParams = networkParams
192199
if networkId.isNone:
193200
# WARNING: networkId and chainId are two distinct things
194201
# they usage should not be mixed in other places.
@@ -204,7 +211,7 @@ proc makeConfig*(cmdLine = commandLineParams()): NRpcConf
204211

205212
result.networkId = networkId.get()
206213

207-
if result.customNetwork.isNone:
214+
if result.customNetworkFolder.len == 0:
208215
result.networkParams = networkParams(result.networkId)
209216

210217

nrpc/nrpc.nim

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# those terms.
99

1010
import
11-
std/sequtils,
11+
std/[sequtils, os],
1212
chronicles,
1313
../execution_chain/constants,
1414
../execution_chain/core/chain,
@@ -80,8 +80,14 @@ template loadNetworkConfig(conf: NRpcConf): (RuntimeConfig, uint64, uint64) =
8080
elif conf.networkId == HoodiNet:
8181
(getMetadataForNetwork("hoodi").cfg, 0'u64, 0'u64)
8282
else:
83-
error "Unsupported network", network = conf.networkId
84-
quit(QuitFailure)
83+
notice "Loading custom network, assuming post-merge"
84+
if conf.customNetworkFolder.len == 0:
85+
error "Custom network file not provided"
86+
quit(QuitFailure)
87+
let (cfg, unloaded) = readRuntimeConfig(conf.customNetworkFolder.joinPath("config.yaml"))
88+
debug "Fields unknown", unloaded = unloaded
89+
(cfg, 0'u64, 0'u64)
90+
8591

8692
# Slot Finding Mechanism
8793
# First it sets the initial lower bound to `firstSlotAfterMerge` + number of blocks after Era1

0 commit comments

Comments
 (0)