From 5dec71c9255889797b980378cf419627fdb1e255 Mon Sep 17 00:00:00 2001 From: Daniel Lehrner Date: Wed, 12 Oct 2022 10:19:10 +0200 Subject: [PATCH] Avoid a cyclic reference while printing EngineExchangeTransitionConfigurationParameter (#4357) * avoids a cyclic reference while printing EngineExchangeTransitionConfigurationParameter Signed-off-by: Daniel Lehrner --- CHANGELOG.md | 1 + .../EngineExchangeTransitionConfiguration.java | 15 +++++++++++++-- ...eExchangeTransitionConfigurationParameter.java | 10 ++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c86e28b93a2..a8115aa3193 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ ### Bug Fixes - Corrects emission of blockadded events when rewinding during a re-org. Fix for [#4495](https://github.com/hyperledger/besu/issues/4495) - Always return a transaction type for pending transactions [#4364](https://github.com/hyperledger/besu/pull/4364) +- Avoid a cyclic reference while printing EngineExchangeTransitionConfigurationParameter [#4357](https://github.com/hyperledger/besu/pull/4357) ### Download Links diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java index 0633a438380..83686f60f62 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java @@ -30,9 +30,12 @@ import org.hyperledger.besu.ethereum.core.Difficulty; import java.util.Optional; +import java.util.function.Supplier; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Suppliers; import io.vertx.core.Vertx; -import io.vertx.core.json.Json; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,6 +48,8 @@ public class EngineExchangeTransitionConfiguration extends ExecutionEngineJsonRp Difficulty.fromHexString( "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc00"); + private static final Supplier mapperSupplier = Suppliers.memoize(ObjectMapper::new); + public EngineExchangeTransitionConfiguration( final Vertx vertx, final ProtocolContext protocolContext, @@ -69,7 +74,13 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) traceLambda( LOG, "received transitionConfiguration: {}", - () -> Json.encodePrettily(remoteTransitionConfiguration)); + () -> { + try { + return mapperSupplier.get().writeValueAsString(remoteTransitionConfiguration); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + }); final Optional maybeTerminalPoWBlockHeader = mergeContextOptional.flatMap(MergeContext::getTerminalPoWBlock); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EngineExchangeTransitionConfigurationParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EngineExchangeTransitionConfigurationParameter.java index 61e7ccd982d..3833fa80c4f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EngineExchangeTransitionConfigurationParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EngineExchangeTransitionConfigurationParameter.java @@ -39,10 +39,20 @@ public Difficulty getTerminalTotalDifficulty() { return terminalTotalDifficulty; } + @JsonProperty("terminalTotalDifficulty") + public String getTerminalTotalDifficultyAsHexString() { + return terminalTotalDifficulty.toShortHexString(); + } + public Hash getTerminalBlockHash() { return terminalBlockHash; } + @JsonProperty("terminalBlockHash") + public String getTerminalBlockHashAsHexString() { + return terminalBlockHash.toShortHexString(); + } + public long getTerminalBlockNumber() { return terminalBlockNumber; }