From 94d4ff50ad6d89749dd4410250f7c3bc673f1559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Talpalaru?= Date: Tue, 15 Jan 2019 15:39:42 +0100 Subject: [PATCH] GC-safety for Nimbus (#63) --- eth_p2p/blockchain_utils.nim | 4 ++-- eth_p2p/rlpx_protocols/eth_protocol.nim | 4 ++-- eth_p2p/rlpx_protocols/les_protocol.nim | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eth_p2p/blockchain_utils.nim b/eth_p2p/blockchain_utils.nim index 3859c2e..35e4e83 100644 --- a/eth_p2p/blockchain_utils.nim +++ b/eth_p2p/blockchain_utils.nim @@ -4,7 +4,7 @@ import # TODO: Perhaps we can move this to eth-common proc getBlockHeaders*(db: AbstractChainDb, - req: BlocksRequest): seq[BlockHeader] = + req: BlocksRequest): seq[BlockHeader] {.gcsafe.} = result = newSeqOfCap[BlockHeader](req.maxResults) var foundBlock: BlockHeader @@ -18,7 +18,7 @@ proc getBlockHeaders*(db: AbstractChainDb, template fetcher*(fetcherName, fetchingFunc, InputType, ResultType: untyped) = proc fetcherName*(db: AbstractChainDb, - lookups: openarray[InputType]): seq[ResultType] = + lookups: openarray[InputType]): seq[ResultType] {.gcsafe.} = for lookup in lookups: let fetched = fetchingFunc(db, lookup) if fetched.hasData: diff --git a/eth_p2p/rlpx_protocols/eth_protocol.nim b/eth_p2p/rlpx_protocols/eth_protocol.nim index 96c4afa..b1886e9 100644 --- a/eth_p2p/rlpx_protocols/eth_protocol.nim +++ b/eth_p2p/rlpx_protocols/eth_protocol.nim @@ -75,7 +75,7 @@ p2pProtocol eth(version = protocolVersion, discard requestResponse: - proc getBlockHeaders(peer: Peer, request: BlocksRequest) = + proc getBlockHeaders(peer: Peer, request: BlocksRequest) {.gcsafe.} = if request.maxResults > uint64(maxHeadersFetch): await peer.disconnect(BreachOfProtocol) return @@ -85,7 +85,7 @@ p2pProtocol eth(version = protocolVersion, proc blockHeaders(p: Peer, headers: openarray[BlockHeader]) requestResponse: - proc getBlockBodies(peer: Peer, hashes: openarray[KeccakHash]) = + proc getBlockBodies(peer: Peer, hashes: openarray[KeccakHash]) {.gcsafe.} = if hashes.len > maxBodiesFetch: await peer.disconnect(BreachOfProtocol) return diff --git a/eth_p2p/rlpx_protocols/les_protocol.nim b/eth_p2p/rlpx_protocols/les_protocol.nim index c8a9640..80c9958 100644 --- a/eth_p2p/rlpx_protocols/les_protocol.nim +++ b/eth_p2p/rlpx_protocols/les_protocol.nim @@ -301,7 +301,7 @@ p2pProtocol les(version = lesVersion, proc getBlockBodies( peer: Peer, blocks: openarray[KeccakHash]) {. - costQuantity(blocks.len, max = maxBodiesFetch).} = + costQuantity(blocks.len, max = maxBodiesFetch), gcsafe.} = let blocks = peer.network.chain.getBlockBodies(blocks) await peer.blockBodies(reqId, updateBV(), blocks)