From 5d744066e4dde9c2f8963fdcbca353f7bf1e4f3d Mon Sep 17 00:00:00 2001 From: Eugene Kabanov Date: Wed, 26 Aug 2020 18:24:59 +0300 Subject: [PATCH] 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. --- beacon_chain/request_manager.nim | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/beacon_chain/request_manager.nim b/beacon_chain/request_manager.nim index ed4cb7445..eceed8602 100644 --- a/beacon_chain/request_manager.nim +++ b/beacon_chain/request_manager.nim @@ -74,7 +74,16 @@ proc fetchAncestorBlocksFromNetwork(rman: RequestManager, if len(ublocks) > 0: for b in ublocks: 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 else: res = Result[void, BlockError].ok() @@ -82,7 +91,10 @@ proc fetchAncestorBlocksFromNetwork(rman: RequestManager, if res.isOk(): peer.updateScore(PeerScoreGoodBlocks) 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: peer.updateScore(PeerScoreBadResponse) else: