Skip to content

Commit 2defb9c

Browse files
author
Jaap van der Plas
committed
log block body validation errors
1 parent beb46af commit 2defb9c

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/main/scala/io/iohk/ethereum/blockchain/sync/fast/SyncBlocksValidator.scala

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@ trait SyncBlocksValidator {
1414
def blockchain: Blockchain
1515
def validators: Validators
1616

17-
def validateBlocks(requestedHashes: Seq[ByteString], blockBodies: Seq[BlockBody]): BlockBodyValidationResult = {
18-
var result: BlockBodyValidationResult = Valid
17+
def validateBlocks(requestedHashes: Seq[ByteString], blockBodies: Seq[BlockBody]): BlockBodyValidationResult =
1918
(requestedHashes zip blockBodies)
2019
.map { case (hash, body) => (blockchain.getBlockHeaderByHash(hash), body) }
21-
.forall {
22-
case (Some(header), body) =>
23-
val validationResult: Either[StdBlockValidator.BlockError, BlockValid] =
24-
validators.blockValidator.validateHeaderAndBody(header, body)
25-
result = validationResult.fold(_ => Invalid, _ => Valid)
26-
validationResult.isRight
27-
case _ =>
28-
result = DbError
29-
false
20+
.foldLeft(Valid) {
21+
case (Valid, (Some(header), body)) =>
22+
validators.blockValidator
23+
.validateHeaderAndBody(header, body)
24+
.fold(
25+
{ error =>
26+
log.error(s"Block body validation failed with error $error")
27+
Invalid
28+
},
29+
_ => Valid
30+
)
31+
case (Valid, _) => DbError
32+
case (invalid, _) => invalid
3033
}
31-
result
32-
}
3334

3435
def validateHeaderOnly(blockHeader: BlockHeader): Either[BlockHeaderError, BlockHeaderValid] =
3536
validators.blockHeaderValidator.validateHeaderOnly(blockHeader)

0 commit comments

Comments
 (0)