Skip to content

Commit

Permalink
Avoid a cyclic reference while printing EngineExchangeTransitionConfi…
Browse files Browse the repository at this point in the history
…gurationParameter (hyperledger#4357)

* avoids a cyclic reference while printing EngineExchangeTransitionConfigurationParameter

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
  • Loading branch information
daniellehrner authored and eum602 committed Nov 3, 2023
1 parent ff6021c commit 6da991d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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

0 comments on commit 6da991d

Please sign in to comment.