Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid a cyclic reference while printing EngineExchangeTransitionConfigurationParameter #4357

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -45,6 +48,8 @@ public class EngineExchangeTransitionConfiguration extends ExecutionEngineJsonRp
Difficulty.fromHexString(
"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc00");

private static final Supplier<ObjectMapper> mapperSupplier = Suppliers.memoize(ObjectMapper::new);

public EngineExchangeTransitionConfiguration(
final Vertx vertx,
final ProtocolContext protocolContext,
Expand All @@ -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<BlockHeader> maybeTerminalPoWBlockHeader =
mergeContextOptional.flatMap(MergeContext::getTerminalPoWBlock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down