Request manager ignores non-critical errors while processing blocks. (#1569)

* Request manager ignores non-critical errors while processing blocks. Only BlockError.Invalid become critical error.

* Add some comments.
This commit is contained in:
Eugene Kabanov 2020-08-26 18:24:59 +03:00 committed by Mamy Ratsimbazafy
parent a29faadace
commit 5d744066e4
1 changed files with 14 additions and 2 deletions

View File

@ -74,7 +74,16 @@ proc fetchAncestorBlocksFromNetwork(rman: RequestManager,
if len(ublocks) > 0: if len(ublocks) > 0:
for b in ublocks: for b in ublocks:
res = await rman.validate(b) res = await rman.validate(b)
if not(res.isOk): # We are ignoring errors:
# `BlockError.MissingParent` - because the order of the blocks that
# we requested may be different from the order in which we need
# these blocks to apply.
# `BlockError.Old`, `BlockError.Duplicate` and `BlockError.Unviable`
# errors could occur due to the concurrent/parallel requests we are
# made.
if res.isErr() and (res.error == BlockError.Invalid):
# We stop processing blocks further to avoid DoS attack with big
# chunk of incorrect blocks.
break break
else: else:
res = Result[void, BlockError].ok() res = Result[void, BlockError].ok()
@ -82,7 +91,10 @@ proc fetchAncestorBlocksFromNetwork(rman: RequestManager,
if res.isOk(): if res.isOk():
peer.updateScore(PeerScoreGoodBlocks) peer.updateScore(PeerScoreGoodBlocks)
else: else:
peer.updateScore(PeerScoreBadBlocks) # We are not penalizing other errors because of the reasons described
# above.
if res.error == BlockError.Invalid:
peer.updateScore(PeerScoreBadBlocks)
else: else:
peer.updateScore(PeerScoreBadResponse) peer.updateScore(PeerScoreBadResponse)
else: else: