@@ -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
@@ -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
@@ -277,16 +264,14 @@ proc runExecutionClient(p: ExecutionThreadConfig) {.thread.} =
277264 com = setupCommonRef (config, taskpool)
278265
279266 dynamicLogScope (comp = " ec" ):
280- nimbus_execution_client.runExeClient (config, com, p.tsp.justWait ())
267+ nimbus_execution_client.runExeClient (
268+ config, com, p.tsp.justWait (), channel = Opt .some p.channel
269+ )
281270
282271 # Stop the other thread as well, in case `runExeClient` stopped early
283272 waitFor p.tsp.fire ()
284273
285274proc runCombinedClient () =
286- # Make it harder to connect to the (internal) engine - this will of course
287- # go away
288- discard randomBytes (distinctBase (jwtKey))
289-
290275 const banner = " Nimbus v0.0.1"
291276
292277 var config = NimbusConf .loadWithBanners (banner, copyright, [specBanner], true ).valueOr:
@@ -325,6 +310,9 @@ proc runCombinedClient() =
325310 " Baked-in KZG setup is correct"
326311 )
327312
313+ var channel: RpcChannel
314+ let pairs = channel.open ().expect (" working channel" )
315+
328316 var bnThread: Thread [BeaconThreadConfig ]
329317 let bnStop = ThreadSignalPtr .new ().expect (" working ThreadSignalPtr" )
330318 createThread (
@@ -335,6 +323,7 @@ proc runCombinedClient() =
335323 tcpPort: config.beaconTcpPort.get (config.tcpPort.get (Port defaultEth2TcpPort)),
336324 udpPort: config.beaconUdpPort.get (config.udpPort.get (Port defaultEth2TcpPort)),
337325 elSync: config.elSync,
326+ channel: pairs.client,
338327 ),
339328 )
340329
@@ -357,6 +346,7 @@ proc runCombinedClient() =
357346 some (Port (uint16 (config.udpPort.get ()) + 1 ))
358347 else :
359348 none (Port ),
349+ channel: pairs.server,
360350 ),
361351 )
362352
0 commit comments