Fix two AssertionErrors from being raised all the way up

This commit is contained in:
kdeme 2019-06-13 15:36:02 +02:00 committed by zah
parent f068a54312
commit dc02a5b28d
3 changed files with 14 additions and 6 deletions

View File

@ -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)

View File

@ -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])

View File

@ -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