Skip to content

Commit

Permalink
refactored because of changes in return value of validateAndProcessBlock
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
  • Loading branch information
daniellehrner authored and garyschulte committed Nov 12, 2022
1 parent df1a7f0 commit 74ade8c
Showing 1 changed file with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.INTERNAL_ERROR;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.UNKNOWN_BLOCK;

import org.hyperledger.besu.ethereum.BlockValidator;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod;
Expand Down Expand Up @@ -73,20 +72,19 @@ protected Object resultByBlockNumber(
// rewind to the block before the one we want to replay
protocolContext.getBlockchain().rewindToBlock(blockNumber - 1);

// replay block and persist it
final BlockValidator.Result result =
protocolSchedule
.getByBlockNumber(blockNumber)
.getBlockValidator()
.validateAndProcessBlock(
protocolContext,
maybeBlock.get(),
HeaderValidationMode.FULL,
HeaderValidationMode.NONE,
true);

if (!result.isValid) {
LOG.error(result.errorMessage.orElse("Empty error response"));
try {
// replay block and persist it
protocolSchedule
.getByBlockNumber(blockNumber)
.getBlockValidator()
.validateAndProcessBlock(
protocolContext,
maybeBlock.get(),
HeaderValidationMode.FULL,
HeaderValidationMode.NONE,
true);
} catch (Exception e) {
LOG.error(e.getMessage());
return new JsonRpcErrorResponse(request.getRequest().getId(), INTERNAL_ERROR);
}

Expand Down

0 comments on commit 74ade8c

Please sign in to comment.