From e3b0edd397028741f7be061ef5b90b9b47dec762 Mon Sep 17 00:00:00 2001 From: Advaita Saha Date: Fri, 4 Oct 2024 07:07:24 +0530 Subject: [PATCH] Fix nrpc edge cases (#2692) * fix: engineAPI unable to connect * fix: pre-merge situation --- nrpc/nrpc.nim | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/nrpc/nrpc.nim b/nrpc/nrpc.nim index 054f6ce72..27fd1af42 100644 --- a/nrpc/nrpc.nim +++ b/nrpc/nrpc.nim @@ -130,20 +130,18 @@ proc syncToEngineApi(conf: NRpcConf) {.async.} = # And exchange the capabilities for a test communication web3 = await engineUrl.newWeb3() rpcClient = web3.provider - data = - try: - await rpcClient.exchangeCapabilities( - @[ - "engine_forkchoiceUpdatedV1", - "engine_getPayloadBodiesByHash", "engine_getPayloadBodiesByRangeV1", - "engine_getPayloadV1", "engine_newPayloadV1", - ] - ) - except CatchableError as exc: - error "Error Connecting to the EL Engine API", error = exc.msg - @[] - notice "Communication with the EL Success", data = data + try: + let data = await rpcClient.exchangeCapabilities( + @[ + "engine_forkchoiceUpdatedV1", "engine_getPayloadBodiesByHash", + "engine_getPayloadBodiesByRangeV1", "engine_getPayloadV1", "engine_newPayloadV1", + ] + ) + notice "Communication with the EL Success", data = data + except CatchableError as exc: + error "Error Connecting to the EL Engine API", error = exc.msg + quit(QuitFailure) # Get the latest block number from the EL rest api template elBlockNumber(): uint64 = @@ -163,6 +161,12 @@ proc syncToEngineApi(conf: NRpcConf) {.async.} = notice "Current block number", number = currentBlockNumber + # Check for pre-merge situation + if currentBlockNumber <= lastEra1Block: + notice "Pre-merge, nrpc syncer works post-merge", + blocknumber = currentBlockNumber, lastPoWBlock = lastEra1Block + quit(QuitSuccess) + # Load the latest state from the CL var (finalizedBlck, _) = client.getELBlockFromBeaconChain( @@ -216,9 +220,7 @@ proc syncToEngineApi(conf: NRpcConf) {.async.} = ) debug "Making new payload call for Deneb" payloadResponse = await rpcClient.newPayload( - payload, - versioned_hashes, - forkyBlck.message.parent_root.to(Hash32), + payload, versioned_hashes, forkyBlck.message.parent_root.to(Hash32) ) notice "Payload status", response = payloadResponse