add exception handlers to transaction exchange code
This commit is contained in:
parent
342dbdea42
commit
c7b3c374f0
|
@ -67,6 +67,8 @@ proc addToKnownByPeer(ctx: EthWireRef, txHashes: openArray[Hash256], peer: Peer,
|
|||
proc sendNewTxHashes(ctx: EthWireRef,
|
||||
txHashes: seq[Hash256],
|
||||
peers: seq[Peer]): Future[void] {.async.} =
|
||||
try:
|
||||
|
||||
for peer in peers:
|
||||
# Add to known tx hashes and get hashes still to send to peer
|
||||
var hashesToSend: seq[Hash256]
|
||||
|
@ -76,16 +78,28 @@ proc sendNewTxHashes(ctx: EthWireRef,
|
|||
if hashesToSend.len > 0:
|
||||
await peer.newPooledTransactionHashes(hashesToSend)
|
||||
|
||||
except TransportError:
|
||||
debug "Transport got closed during sendNewTxHashes"
|
||||
except CatchableError as e:
|
||||
debug "Exception in sendNewTxHashes", exc = e.name, err = e.msg
|
||||
|
||||
proc sendTransactions(ctx: EthWireRef,
|
||||
txHashes: seq[Hash256],
|
||||
txs: seq[Transaction],
|
||||
peers: seq[Peer]): Future[void] {.async.} =
|
||||
try:
|
||||
|
||||
for peer in peers:
|
||||
# This is used to avoid re-sending along pooledTxHashes
|
||||
# announcements/re-broadcasts
|
||||
ctx.addToKnownByPeer(txHashes, peer)
|
||||
await peer.transactions(txs)
|
||||
|
||||
except TransportError:
|
||||
debug "Transport got closed during sendTransactions"
|
||||
except CatchableError as e:
|
||||
debug "Exception in sendTransactions", exc = e.name, err = e.msg
|
||||
|
||||
proc inPool(ctx: EthWireRef, txHash: Hash256): bool =
|
||||
let res = ctx.txPool.getItem(txHash)
|
||||
res.isOk
|
||||
|
@ -292,6 +306,8 @@ proc fetchTransactions(ctx: EthWireRef, reqHashes: seq[Hash256], peer: Peer): Fu
|
|||
debug "fetchTx: requesting txs",
|
||||
number = reqHashes.len
|
||||
|
||||
try:
|
||||
|
||||
let res = await peer.getPooledTransactions(reqHashes)
|
||||
if res.isNone:
|
||||
error "not able to get pooled transactions"
|
||||
|
@ -308,13 +324,20 @@ proc fetchTransactions(ctx: EthWireRef, reqHashes: seq[Hash256], peer: Peer): Fu
|
|||
|
||||
ctx.txPool.jobAddTxs(txs.transactions)
|
||||
|
||||
except TransportError:
|
||||
debug "Transport got closed during fetchTransactions"
|
||||
return
|
||||
except CatchableError as e:
|
||||
debug "Exception in fetchTransactions", exc = e.name, err = e.msg
|
||||
return
|
||||
|
||||
var newTxHashes = newSeqOfCap[Hash256](reqHashes.len)
|
||||
for txHash in reqHashes:
|
||||
if ctx.inPoolAndOk(txHash):
|
||||
newTxHashes.add txHash
|
||||
|
||||
let peers = ctx.getPeers(peer)
|
||||
if peers.len == 0:
|
||||
if peers.len == 0 or newTxHashes.len == 0:
|
||||
return
|
||||
|
||||
await ctx.sendNewTxHashes(newTxHashes, peers)
|
||||
|
|
Loading…
Reference in New Issue