Skip to content

Commit

Permalink
logging additions for better engine visibility (hyperledger#4136)
Browse files Browse the repository at this point in the history
Signed-off-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
garyschulte authored and eum602 committed Nov 3, 2023
1 parent 0e36a6f commit 1c87162
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
forkChoice.getHeadBlockHash(), maybeFinalizedHash, forkChoice.getSafeBlockHash());

if (mergeContext.isSyncing()) {
return syncingResponse(requestId);
return syncingResponse(requestId, forkChoice);
}

if (mergeCoordinator.isBadBlock(forkChoice.getHeadBlockHash())) {
logForkchoiceUpdatedCall(INVALID, forkChoice);
return new JsonRpcSuccessResponse(
requestId,
new EngineUpdateForkchoiceResult(
Expand All @@ -96,25 +97,21 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
mergeCoordinator.getOrSyncHeaderByHash(forkChoice.getHeadBlockHash());

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(
this::logPayload, () -> LOG.debug("Payload attributes are null"));

if (!isValidForkchoiceState(
forkChoice.getSafeBlockHash(), forkChoice.getFinalizedBlockHash(), newHead.get())) {
logForkchoiceUpdatedCall(INVALID, forkChoice);
return new JsonRpcErrorResponse(requestId, JsonRpcError.INVALID_FORKCHOICE_STATE);
}

// TODO: post-merge cleanup, this should be unnecessary after merge
if (!mergeCoordinator.latestValidAncestorDescendsFromTerminal(newHead.get())) {
logForkchoiceUpdatedCall(INVALID, forkChoice);
return new JsonRpcSuccessResponse(
requestId,
new EngineUpdateForkchoiceResult(
Expand All @@ -137,6 +134,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
payloadAttributes.getSuggestedFeeRecipient())));

if (!result.isValid()) {
logForkchoiceUpdatedCall(INVALID, forkChoice);
return handleNonValidForkchoiceUpdate(requestId, result);
}

Expand All @@ -158,6 +156,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
pid::toHexString,
() -> maybePayloadAttributes.map(EnginePayloadAttributesParameter::serialize)));

logForkchoiceUpdatedCall(VALID, forkChoice);
return new JsonRpcSuccessResponse(
requestId,
new EngineUpdateForkchoiceResult(
Expand Down Expand Up @@ -256,8 +255,20 @@ private boolean isValidForkchoiceState(
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(
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
new Block(newBlockHeader, new BlockBody(transactions, Collections.emptyList()));

if (mergeContext.isSyncing() || parentHeader.isEmpty()) {
LOG.info(
"isSyncing: {} parentHeaderMissing: {}, adding {} to backwardsync",
mergeContext.isSyncing(),
parentHeader.isEmpty(),
block.getHash());
mergeCoordinator
.appendNewPayloadToSync(block)
.exceptionally(
Expand All @@ -177,6 +182,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)

// TODO: post-merge cleanup
if (!mergeCoordinator.latestValidAncestorDescendsFromTerminal(newBlockHeader)) {
LOG.warn("payload did not descend from terminal: {}", newBlockHeader.toLogString());
mergeCoordinator.addBadBlock(block);
return respondWithInvalid(
reqId,
Expand Down

0 comments on commit 1c87162

Please sign in to comment.