Skip to content

Commit

Permalink
add debug logging for invalid case (hyperledger#4520)
Browse files Browse the repository at this point in the history
Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
Co-authored-by: mark-terry <36909937+mark-terry@users.noreply.github.com>
  • Loading branch information
macfarla and mark-terry authored Oct 12, 2022
1 parent 97cf43b commit 32125fb
Showing 1 changed file with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.VALID;
import static org.hyperledger.besu.util.Slf4jLambdaHelper.debugLambda;
import static org.hyperledger.besu.util.Slf4jLambdaHelper.traceLambda;
import static org.hyperledger.besu.util.Slf4jLambdaHelper.warnLambda;

import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
import org.hyperledger.besu.datatypes.Hash;
Expand Down Expand Up @@ -251,24 +250,28 @@ JsonRpcResponse respondWith(
}

// engine api calls are synchronous, no need for volatile
private long lastInvalidWarn = System.currentTimeMillis();
private long lastInvalidWarn = 0;

JsonRpcResponse respondWithInvalid(
final Object requestId,
final EnginePayloadParameter param,
final Hash latestValidHash,
final String validationError) {
final String invalidBlockLogMessage =
String.format(
"Invalid new payload: number: %s, hash: %s, parentHash: %s, latestValidHash: %s, status: %s, validationError: %s",
param.getBlockNumber(),
param.getBlockHash(),
param.getParentHash(),
latestValidHash == null ? null : latestValidHash.toHexString(),
INVALID.name(),
validationError);
// always log invalid at DEBUG
LOG.debug(invalidBlockLogMessage);
// periodically log at WARN
if (lastInvalidWarn + ENGINE_API_LOGGING_THRESHOLD < System.currentTimeMillis()) {
lastInvalidWarn = System.currentTimeMillis();
warnLambda(
LOG,
"Invalid new payload: number: {}, hash: {}, parentHash: {}, latestValidHash: {}, status: {}, validationError: {}",
() -> param.getBlockNumber(),
() -> param.getBlockHash(),
() -> param.getParentHash(),
() -> latestValidHash == null ? null : latestValidHash.toHexString(),
INVALID::name,
() -> validationError);
LOG.warn(invalidBlockLogMessage);
}
return new JsonRpcSuccessResponse(
requestId,
Expand Down

0 comments on commit 32125fb

Please sign in to comment.