logging additions for better engine visibility (#4136)

Signed-off-by: garyschulte <garyschulte@gmail.com>
pull/4137/head
garyschulte 2 years ago committed by GitHub
parent 86197c449d
commit e139860549
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdated.java
  2. 6
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayload.java

@ -77,10 +77,11 @@ public class EngineForkchoiceUpdated extends ExecutionEngineJsonRpcMethod {
forkChoice.getHeadBlockHash(), maybeFinalizedHash, forkChoice.getSafeBlockHash()); forkChoice.getHeadBlockHash(), maybeFinalizedHash, forkChoice.getSafeBlockHash());
if (mergeContext.isSyncing()) { if (mergeContext.isSyncing()) {
return syncingResponse(requestId); return syncingResponse(requestId, forkChoice);
} }
if (mergeCoordinator.isBadBlock(forkChoice.getHeadBlockHash())) { if (mergeCoordinator.isBadBlock(forkChoice.getHeadBlockHash())) {
logForkchoiceUpdatedCall(INVALID, forkChoice);
return new JsonRpcSuccessResponse( return new JsonRpcSuccessResponse(
requestId, requestId,
new EngineUpdateForkchoiceResult( new EngineUpdateForkchoiceResult(
@ -96,25 +97,21 @@ public class EngineForkchoiceUpdated extends ExecutionEngineJsonRpcMethod {
mergeCoordinator.getOrSyncHeaderByHash(forkChoice.getHeadBlockHash()); mergeCoordinator.getOrSyncHeaderByHash(forkChoice.getHeadBlockHash());
if (newHead.isEmpty()) { if (newHead.isEmpty()) {
return syncingResponse(requestId); return syncingResponse(requestId, forkChoice);
} }
LOG.info(
"Consensus fork-choice-update: head: {}, finalized: {}, safeBlockHash: {}",
forkChoice.getHeadBlockHash(),
forkChoice.getFinalizedBlockHash(),
forkChoice.getSafeBlockHash());
maybePayloadAttributes.ifPresentOrElse( maybePayloadAttributes.ifPresentOrElse(
this::logPayload, () -> LOG.debug("Payload attributes are null")); this::logPayload, () -> LOG.debug("Payload attributes are null"));
if (!isValidForkchoiceState( if (!isValidForkchoiceState(
forkChoice.getSafeBlockHash(), forkChoice.getFinalizedBlockHash(), newHead.get())) { forkChoice.getSafeBlockHash(), forkChoice.getFinalizedBlockHash(), newHead.get())) {
logForkchoiceUpdatedCall(INVALID, forkChoice);
return new JsonRpcErrorResponse(requestId, JsonRpcError.INVALID_FORKCHOICE_STATE); return new JsonRpcErrorResponse(requestId, JsonRpcError.INVALID_FORKCHOICE_STATE);
} }
// TODO: post-merge cleanup, this should be unnecessary after merge // TODO: post-merge cleanup, this should be unnecessary after merge
if (!mergeCoordinator.latestValidAncestorDescendsFromTerminal(newHead.get())) { if (!mergeCoordinator.latestValidAncestorDescendsFromTerminal(newHead.get())) {
logForkchoiceUpdatedCall(INVALID, forkChoice);
return new JsonRpcSuccessResponse( return new JsonRpcSuccessResponse(
requestId, requestId,
new EngineUpdateForkchoiceResult( new EngineUpdateForkchoiceResult(
@ -137,6 +134,7 @@ public class EngineForkchoiceUpdated extends ExecutionEngineJsonRpcMethod {
payloadAttributes.getSuggestedFeeRecipient()))); payloadAttributes.getSuggestedFeeRecipient())));
if (!result.isValid()) { if (!result.isValid()) {
logForkchoiceUpdatedCall(INVALID, forkChoice);
return handleNonValidForkchoiceUpdate(requestId, result); return handleNonValidForkchoiceUpdate(requestId, result);
} }
@ -158,6 +156,7 @@ public class EngineForkchoiceUpdated extends ExecutionEngineJsonRpcMethod {
pid::toHexString, pid::toHexString,
() -> maybePayloadAttributes.map(EnginePayloadAttributesParameter::serialize))); () -> maybePayloadAttributes.map(EnginePayloadAttributesParameter::serialize)));
logForkchoiceUpdatedCall(VALID, forkChoice);
return new JsonRpcSuccessResponse( return new JsonRpcSuccessResponse(
requestId, requestId,
new EngineUpdateForkchoiceResult( new EngineUpdateForkchoiceResult(
@ -256,8 +255,20 @@ public class EngineForkchoiceUpdated extends ExecutionEngineJsonRpcMethod {
return mergeCoordinator.isDescendantOf(maybeSafeBlock.get(), newBlock); return mergeCoordinator.isDescendantOf(maybeSafeBlock.get(), newBlock);
} }
private JsonRpcResponse syncingResponse(final Object requestId) { private JsonRpcResponse syncingResponse(
final Object requestId, final EngineForkchoiceUpdatedParameter forkChoice) {
logForkchoiceUpdatedCall(SYNCING, forkChoice);
return new JsonRpcSuccessResponse( return new JsonRpcSuccessResponse(
requestId, new EngineUpdateForkchoiceResult(SYNCING, null, null, Optional.empty())); requestId, new EngineUpdateForkchoiceResult(SYNCING, null, null, Optional.empty()));
} }
private void logForkchoiceUpdatedCall(
final EngineStatus status, final EngineForkchoiceUpdatedParameter forkChoice) {
LOG.info(
"{} for fork-choice-update: head: {}, finalized: {}, safeBlockHash: {}",
status.name(),
forkChoice.getHeadBlockHash(),
forkChoice.getFinalizedBlockHash(),
forkChoice.getSafeBlockHash());
}
} }

@ -165,6 +165,11 @@ public class EngineNewPayload extends ExecutionEngineJsonRpcMethod {
new Block(newBlockHeader, new BlockBody(transactions, Collections.emptyList())); new Block(newBlockHeader, new BlockBody(transactions, Collections.emptyList()));
if (mergeContext.isSyncing() || parentHeader.isEmpty()) { if (mergeContext.isSyncing() || parentHeader.isEmpty()) {
LOG.info(
"isSyncing: {} parentHeaderMissing: {}, adding {} to backwardsync",
mergeContext.isSyncing(),
parentHeader.isEmpty(),
block.getHash());
mergeCoordinator mergeCoordinator
.appendNewPayloadToSync(block) .appendNewPayloadToSync(block)
.exceptionally( .exceptionally(
@ -177,6 +182,7 @@ public class EngineNewPayload extends ExecutionEngineJsonRpcMethod {
// TODO: post-merge cleanup // TODO: post-merge cleanup
if (!mergeCoordinator.latestValidAncestorDescendsFromTerminal(newBlockHeader)) { if (!mergeCoordinator.latestValidAncestorDescendsFromTerminal(newBlockHeader)) {
LOG.warn("payload did not descend from terminal: {}", newBlockHeader.toLogString());
mergeCoordinator.addBadBlock(block); mergeCoordinator.addBadBlock(block);
return respondWithInvalid( return respondWithInvalid(
reqId, reqId,

Loading…
Cancel
Save