Supporting 2 backends is hell.

This commit is contained in:
cheatfate 2020-02-26 15:40:12 +02:00 committed by zah
parent 5ae0026f72
commit 278b91d6ce
1 changed files with 19 additions and 18 deletions

View File

@ -33,25 +33,26 @@ proc fetchAncestorBlocksFromPeer(
debug "Error while fetching ancestor blocks",
err = err.msg, root = rec.root, peer
proc fetchAncestorBlocksFromNetwork(
network: Eth2Node,
rec: FetchRecord,
responseHandler: FetchAncestorsResponseHandler) {.async.} =
var peer: Peer
try:
peer = await network.peerPool.acquire()
let blocks = await peer.beaconBlocksByRoot([rec.root])
if blocks.isSome:
for b in blocks.get:
responseHandler(b)
except CatchableError as err:
debug "Error while fetching ancestor blocks",
err = err.msg, root = rec.root, peer = peer.info
finally:
if not(isNil(peer)):
network.peerPool.release(peer)
when networkBackend == libp2p:
proc fetchAncestorBlocksFromNetwork(
network: Eth2Node,
rec: FetchRecord,
responseHandler: FetchAncestorsResponseHandler) {.async.} =
var peer: Peer
try:
peer = await network.peerPool.acquire()
let blocks = await peer.beaconBlocksByRoot([rec.root])
if blocks.isSome:
for b in blocks.get:
responseHandler(b)
except CatchableError as err:
debug "Error while fetching ancestor blocks",
err = err.msg, root = rec.root, peer = peer.info
finally:
if not(isNil(peer)):
network.peerPool.release(peer)
proc fetchAncestorBlocks*(requestManager: RequestManager,
roots: seq[FetchRecord],
responseHandler: FetchAncestorsResponseHandler) =