Skip to content

Commit

Permalink
Log blob count when importing a block via Engine API (hyperledger#6466)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
fab-10 authored Jan 25, 2024
1 parent 16016ec commit efbd840
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
### Additions and Improvements
- Add `OperationTracer.tracePrepareTransaction`, where the sender account has not yet been altered[#6453](https://github.com/hyperledger/besu/pull/6453)
- Improve the high spec flag by limiting it to a few column families [#6354](https://github.com/hyperledger/besu/pull/6354)

- Log blob count when importing a block via Engine API [#6466](https://github.com/hyperledger/besu/pull/6466)

### Bug fixes
- Fix the way an advertised host configured with `--p2p-host` is treated when communicating with the originator of a PING packet [#6225](https://github.com/hyperledger/besu/pull/6225)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,12 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
return respondWithInvalid(reqId, blockParam, null, getInvalidBlockHashStatus(), errorMessage);
}

final var blobTransactions =
transactions.stream().filter(transaction -> transaction.getType().supportsBlob()).toList();

ValidationResult<RpcErrorType> blobValidationResult =
validateBlobs(
transactions,
blobTransactions,
newBlockHeader,
maybeParentHeader,
maybeVersionedHashes,
Expand Down Expand Up @@ -302,7 +305,8 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
final BlockProcessingResult executionResult = mergeCoordinator.rememberBlock(block);

if (executionResult.isSuccessful()) {
logImportedBlockInfo(block, (System.currentTimeMillis() - startTimeMs) / 1000.0);
logImportedBlockInfo(
block, blobTransactions.size(), (System.currentTimeMillis() - startTimeMs) / 1000.0);
return respondWith(reqId, blockParam, newBlockHeader.getHash(), VALID);
} else {
if (executionResult.causedBy().isPresent()) {
Expand Down Expand Up @@ -380,10 +384,6 @@ JsonRpcResponse respondWithInvalid(
invalidStatus, latestValidHash, Optional.of(validationError)));
}

protected boolean requireTerminalPoWBlockValidation() {
return false;
}

protected EngineStatus getInvalidBlockHashStatus() {
return INVALID;
}
Expand All @@ -396,15 +396,12 @@ protected ValidationResult<RpcErrorType> validateParameters(
}

protected ValidationResult<RpcErrorType> validateBlobs(
final List<Transaction> transactions,
final List<Transaction> blobTransactions,
final BlockHeader header,
final Optional<BlockHeader> maybeParentHeader,
final Optional<List<VersionedHash>> maybeVersionedHashes,
final ProtocolSpec protocolSpec) {

var blobTransactions =
transactions.stream().filter(transaction -> transaction.getType().supportsBlob()).toList();

final List<VersionedHash> transactionVersionedHashes = new ArrayList<>();
for (Transaction transaction : blobTransactions) {
var versionedHashes = transaction.getVersionedHashes();
Expand Down Expand Up @@ -489,7 +486,7 @@ private Optional<List<VersionedHash>> extractVersionedHashes(
.collect(Collectors.toList()));
}

private void logImportedBlockInfo(final Block block, final double timeInS) {
private void logImportedBlockInfo(final Block block, final int blobCount, final double timeInS) {
final StringBuilder message = new StringBuilder();
message.append("Imported #%,d / %d tx");
final List<Object> messageArgs =
Expand All @@ -503,9 +500,10 @@ private void logImportedBlockInfo(final Block block, final double timeInS) {
message.append(" / %d ds");
messageArgs.add(block.getBody().getDeposits().get().size());
}
message.append(" / base fee %s / %,d (%01.1f%%) gas / (%s) in %01.3fs. Peers: %d");
message.append(" / %d blobs / base fee %s / %,d (%01.1f%%) gas / (%s) in %01.3fs. Peers: %d");
messageArgs.addAll(
List.of(
blobCount,
block.getHeader().getBaseFee().map(Wei::toHumanReadableString).orElse("N/A"),
block.getHeader().getGasUsed(),
(block.getHeader().getGasUsed() * 100.0) / block.getHeader().getGasLimit(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ public String getName() {
return RpcMethod.ENGINE_NEW_PAYLOAD_V1.getMethodName();
}

@Override
protected boolean requireTerminalPoWBlockValidation() {
return true;
}

@Override
protected EngineStatus getInvalidBlockHashStatus() {
return INVALID_BLOCK_HASH;
Expand Down

0 comments on commit efbd840

Please sign in to comment.