diff --git a/eth/p2p/rlpx.nim b/eth/p2p/rlpx.nim index cf1c4f0..77a388a 100644 --- a/eth/p2p/rlpx.nim +++ b/eth/p2p/rlpx.nim @@ -554,7 +554,8 @@ proc dispatchMessages*(peer: Peer) {.async.} = try: await peer.invokeThunk(msgId, msgData) except RlpError: - debug "RlpError, ending dispatchMessages loop", peer + debug "RlpError, ending dispatchMessages loop", peer, + msg = peer.getMsgName(msgId) await peer.disconnect(BreachOfProtocol, true) return except CatchableError: @@ -636,7 +637,7 @@ macro p2pProtocolImpl(name: static[string], createPeerState = bindSym "createPeerState" finish = bindSym "finish" initRlpWriter = bindSym "initRlpWriter" - enterList = bindSym "enterList" + safeEnterList = bindSym "safeEnterList" messagePrinter = bindSym "messagePrinter" initProtocol = bindSym "initProtocol" nextMsgResolver = bindSym "nextMsgResolver" @@ -875,7 +876,7 @@ macro p2pProtocolImpl(name: static[string], let paramCount = paramsToWrite.len if paramCount > 1: - readParamsPrelude.add newCall(enterList, receivedRlp) + readParamsPrelude.add newCall(safeEnterList, receivedRlp) when tracingEnabled: readParams.add newCall(bindSym"logReceivedMsg", msgSender, receivedMsg) diff --git a/eth/p2p/rlpx_protocols/eth_protocol.nim b/eth/p2p/rlpx_protocols/eth_protocol.nim index 0ba5a29..ca479f1 100644 --- a/eth/p2p/rlpx_protocols/eth_protocol.nim +++ b/eth/p2p/rlpx_protocols/eth_protocol.nim @@ -90,7 +90,8 @@ p2pProtocol eth(version = protocolVersion, await peer.disconnect(BreachOfProtocol) return - await response.send(peer.network.chain.getBlockBodies(hashes)) + # TODO: implement `getBlockBodies` and reactivate this code + # await response.send(peer.network.chain.getBlockBodies(hashes)) proc blockBodies(peer: Peer, blocks: openarray[BlockBody]) @@ -106,8 +107,9 @@ p2pProtocol eth(version = protocolVersion, proc nodeData(peer: Peer, data: openarray[Blob]) requestResponse: - proc getReceipts(peer: Peer, hashes: openarray[KeccakHash]) = - await response.send(peer.network.chain.getReceipts(hashes)) + proc getReceipts(peer: Peer, hashes: openarray[KeccakHash]) = discard + # TODO: implement `getReceipts` and reactivate this code + # await response.send(peer.network.chain.getReceipts(hashes)) proc receipts(peer: Peer, receipts: openarray[Receipt]) diff --git a/eth/rlp.nim b/eth/rlp.nim index a10926d..96e5129 100644 --- a/eth/rlp.nim +++ b/eth/rlp.nim @@ -246,6 +246,11 @@ proc enterList*(self: var Rlp) = doAssert isList() position += payloadOffset() +proc safeEnterList*(self: var Rlp) = + if not isList(): + raise newException(RlpTypeMismatch, "List expected, but source RLP is not a list") + enterList() + proc skipElem*(rlp: var Rlp) = rlp.position = rlp.currentElemEnd