@@ -16,15 +16,15 @@ proc workaround*(): int {.exportc.} =
1616 return int (Future [Quantity ]().internalValue)
1717
1818import
19- std/ [os, net, options, strformat, terminal, typetraits],
19+ std/ [os, net, options, terminal, typetraits],
2020 stew/ io2,
2121 chronos/ threadsync,
2222 chronicles,
2323 metrics,
2424 metrics/ chronos_httpserver,
25- nimcrypto/ sysrand,
2625 eth/ enr/ enr,
2726 eth/ net/ nat,
27+ json_rpc/ rpcchannels,
2828 eth/ p2p/ discoveryv5/ random2,
2929 beacon_chain/ spec/ [engine_authentication],
3030 beacon_chain/ validators/ keystore_management,
3636 nimbus_binary_common,
3737 process_state,
3838 ],
39- ./ rpc/ jwt_auth,
4039 ./ [
4140 constants,
4241 conf as ecconf,
@@ -170,13 +169,13 @@ type
170169 tcpPort: Port
171170 udpPort: Port
172171 elSync: bool
172+ channel: RpcChannelPtrs
173173
174174 ExecutionThreadConfig = object
175175 tsp: ThreadSignalPtr
176176 tcpPort: Port
177177 udpPort: Option [Port ]
178-
179- var jwtKey: JwtSharedKey
178+ channel: RpcChannelPtrs
180179
181180proc dataDir * (config: NimbusConf ): string =
182181 string config.dataDirFlag.get (
@@ -190,14 +189,14 @@ proc justWait(tsp: ThreadSignalPtr) {.async: (raises: [CancelledError]).} =
190189 notice " Waiting failed" , err = exc.msg
191190
192191proc elSyncLoop (
193- dag: ChainDAGRef , url: EngineApiUrl
192+ dag: ChainDAGRef , elManager: ELManager
194193) {.async : (raises: [CancelledError ]).} =
195194 while true :
196195 await sleepAsync (12 .seconds)
197196
198197 # TODO trigger only when the EL needs syncing
199198 try :
200- await syncToEngineApi (dag, url )
199+ await syncToEngineApi (dag, elManager. channel () )
201200 except CatchableError as exc:
202201 # This can happen when the EL is busy doing some work, specially on
203202 # startup
@@ -208,17 +207,8 @@ proc runBeaconNode(p: BeaconThreadConfig) {.thread.} =
208207 stderr.writeLine error # Logging not yet set up
209208 quit QuitFailure
210209
211- let engineUrl = EngineApiUrl .init (
212- & " http://127.0.0.1:{ defaultEngineApiPort} / " , Opt .some (@ (distinctBase (jwtKey)))
213- )
214-
215210 config.metricsEnabled = false
216- config.elUrls =
217- @ [
218- EngineApiUrlConfigValue (
219- url: engineUrl.url, jwtSecret: some toHex (distinctBase (jwtKey))
220- )
221- ]
211+ config.elUrls = @ [EngineApiUrlConfigValue (channel: Opt .some (p.channel))]
222212 config.statusBarEnabled = false # Multi-threading issues due to logging
223213 config.tcpPort = p.tcpPort
224214 config.udpPort = p.udpPort
@@ -244,7 +234,7 @@ proc runBeaconNode(p: BeaconThreadConfig) {.thread.} =
244234 return
245235
246236 if p.elSync:
247- discard elSyncLoop (node.dag, engineUrl )
237+ discard elSyncLoop (node.dag, node.elManager )
248238
249239 dynamicLogScope (comp = " bn" ):
250240 if node.nickname != " " :
@@ -259,11 +249,8 @@ proc runBeaconNode(p: BeaconThreadConfig) {.thread.} =
259249proc runExecutionClient (p: ExecutionThreadConfig ) {.thread .} =
260250 var config = makeConfig (ignoreUnknown = true )
261251 config.metricsEnabled = false
262- config.engineApiEnabled = true
263- config.engineApiPort = Port (defaultEngineApiPort)
264- config.engineApiAddress = defaultAdminListenAddress
265- config.jwtSecret.reset ()
266- config.jwtSecretValue = some toHex (distinctBase (jwtKey))
252+ config.engineApiEnabled = false
253+ config.engineApiChannelEnabled = true
267254 config.agentString = " nimbus"
268255 config.tcpPort = p.tcpPort
269256 config.udpPortFlag = p.udpPort
@@ -281,16 +268,14 @@ proc runExecutionClient(p: ExecutionThreadConfig) {.thread.} =
281268 let com = setupCommonRef (config)
282269
283270 dynamicLogScope (comp = " ec" ):
284- nimbus_execution_client.runExeClient (config, com, p.tsp.justWait ())
271+ nimbus_execution_client.runExeClient (
272+ config, com, p.tsp.justWait (), channel = Opt .some p.channel
273+ )
285274
286275 # Stop the other thread as well, in case `runExeClient` stopped early
287276 waitFor p.tsp.fire ()
288277
289278proc runCombinedClient () =
290- # Make it harder to connect to the (internal) engine - this will of course
291- # go away
292- discard randomBytes (distinctBase (jwtKey))
293-
294279 const banner = " Nimbus v0.0.1"
295280
296281 var config = NimbusConf .loadWithBanners (banner, copyright, [specBanner], true ).valueOr:
@@ -329,6 +314,9 @@ proc runCombinedClient() =
329314 " Baked-in KZG setup is correct"
330315 )
331316
317+ var channel: RpcChannel
318+ let pairs = channel.open ().expect (" working channel" )
319+
332320 var bnThread: Thread [BeaconThreadConfig ]
333321 let bnStop = ThreadSignalPtr .new ().expect (" working ThreadSignalPtr" )
334322 createThread (
@@ -339,6 +327,7 @@ proc runCombinedClient() =
339327 tcpPort: config.beaconTcpPort.get (config.tcpPort.get (Port defaultEth2TcpPort)),
340328 udpPort: config.beaconUdpPort.get (config.udpPort.get (Port defaultEth2TcpPort)),
341329 elSync: config.elSync,
330+ channel: pairs,
342331 ),
343332 )
344333
@@ -361,6 +350,7 @@ proc runCombinedClient() =
361350 some (Port (uint16 (config.udpPort.get ()) + 1 ))
362351 else :
363352 none (Port ),
353+ channel: pairs,
364354 ),
365355 )
366356
0 commit comments