GC-safety for Nimbus (#63)

This commit is contained in:
Ștefan Talpalaru 2019-01-15 15:39:42 +01:00 committed by Mamy Ratsimbazafy
parent 53e98faa74
commit 94d4ff50ad
3 changed files with 5 additions and 5 deletions

View File

@ -4,7 +4,7 @@ import
# TODO: Perhaps we can move this to eth-common # TODO: Perhaps we can move this to eth-common
proc getBlockHeaders*(db: AbstractChainDb, proc getBlockHeaders*(db: AbstractChainDb,
req: BlocksRequest): seq[BlockHeader] = req: BlocksRequest): seq[BlockHeader] {.gcsafe.} =
result = newSeqOfCap[BlockHeader](req.maxResults) result = newSeqOfCap[BlockHeader](req.maxResults)
var foundBlock: BlockHeader var foundBlock: BlockHeader
@ -18,7 +18,7 @@ proc getBlockHeaders*(db: AbstractChainDb,
template fetcher*(fetcherName, fetchingFunc, InputType, ResultType: untyped) = template fetcher*(fetcherName, fetchingFunc, InputType, ResultType: untyped) =
proc fetcherName*(db: AbstractChainDb, proc fetcherName*(db: AbstractChainDb,
lookups: openarray[InputType]): seq[ResultType] = lookups: openarray[InputType]): seq[ResultType] {.gcsafe.} =
for lookup in lookups: for lookup in lookups:
let fetched = fetchingFunc(db, lookup) let fetched = fetchingFunc(db, lookup)
if fetched.hasData: if fetched.hasData:

View File

@ -75,7 +75,7 @@ p2pProtocol eth(version = protocolVersion,
discard discard
requestResponse: requestResponse:
proc getBlockHeaders(peer: Peer, request: BlocksRequest) = proc getBlockHeaders(peer: Peer, request: BlocksRequest) {.gcsafe.} =
if request.maxResults > uint64(maxHeadersFetch): if request.maxResults > uint64(maxHeadersFetch):
await peer.disconnect(BreachOfProtocol) await peer.disconnect(BreachOfProtocol)
return return
@ -85,7 +85,7 @@ p2pProtocol eth(version = protocolVersion,
proc blockHeaders(p: Peer, headers: openarray[BlockHeader]) proc blockHeaders(p: Peer, headers: openarray[BlockHeader])
requestResponse: requestResponse:
proc getBlockBodies(peer: Peer, hashes: openarray[KeccakHash]) = proc getBlockBodies(peer: Peer, hashes: openarray[KeccakHash]) {.gcsafe.} =
if hashes.len > maxBodiesFetch: if hashes.len > maxBodiesFetch:
await peer.disconnect(BreachOfProtocol) await peer.disconnect(BreachOfProtocol)
return return

View File

@ -301,7 +301,7 @@ p2pProtocol les(version = lesVersion,
proc getBlockBodies( proc getBlockBodies(
peer: Peer, peer: Peer,
blocks: openarray[KeccakHash]) {. blocks: openarray[KeccakHash]) {.
costQuantity(blocks.len, max = maxBodiesFetch).} = costQuantity(blocks.len, max = maxBodiesFetch), gcsafe.} =
let blocks = peer.network.chain.getBlockBodies(blocks) let blocks = peer.network.chain.getBlockBodies(blocks)
await peer.blockBodies(reqId, updateBV(), blocks) await peer.blockBodies(reqId, updateBV(), blocks)