From ca9a07691a5426c7f02f29b36e6cd757dc17c284 Mon Sep 17 00:00:00 2001 From: Daniel Lehrner Date: Mon, 8 Aug 2022 01:17:58 +0200 Subject: [PATCH] correct fallback ttd to correct value (#4223) * correct fallback ttd to correct value Signed-off-by: Daniel Lehrner Co-authored-by: Sally MacFarlane --- CHANGELOG.md | 2 ++ .../engine/EngineExchangeTransitionConfiguration.java | 5 +++-- .../EngineExchangeTransitionConfigurationTest.java | 10 ++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbfe8a1b5d1..e55536c6bde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ ### Additions and Improvements ### Bug Fixes +- Fixes off-by-one error for mainnet TTD fallback [#4223](https://github.com/hyperledger/besu/pull/4223) + ## 22.7.0 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 e4db64e5226..90be85e4654 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 @@ -34,7 +34,6 @@ import io.vertx.core.Vertx; import io.vertx.core.json.Json; -import org.apache.tuweni.units.bigints.UInt256; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,7 +43,9 @@ public class EngineExchangeTransitionConfiguration extends ExecutionEngineJsonRp // use (2^256 - 2^10) if engine is enabled in the absence of a TTD configuration static final Difficulty FALLBACK_TTD_DEFAULT = - Difficulty.MAX_VALUE.subtract(UInt256.valueOf(1024L)); + Difficulty.fromHexString( + "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc00"); + static final long QOS_TIMEOUT_MILLIS = 120000L; private final QosTimer qosTimer; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfigurationTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfigurationTest.java index bc60a44d2be..09b39d08187 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfigurationTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfigurationTest.java @@ -15,7 +15,6 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine; import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineExchangeTransitionConfiguration.FALLBACK_TTD_DEFAULT; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; @@ -44,6 +43,7 @@ import org.hyperledger.besu.ethereum.core.ParsedExtraData; import org.hyperledger.besu.evm.log.LogsBloomFilter; +import java.math.BigInteger; import java.util.Map; import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; @@ -56,6 +56,7 @@ import io.vertx.ext.unit.junit.VertxUnitRunner; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; +import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -126,7 +127,12 @@ public void shouldReturnDefaultOnNoTerminalTotalDifficultyConfigured() { "0", Hash.ZERO.toHexString(), new UnsignedLongParameter(0L))); var result = fromSuccessResp(response); - assertThat(result.getTerminalTotalDifficulty()).isEqualTo(FALLBACK_TTD_DEFAULT); + assertThat(result.getTerminalTotalDifficulty()) + .isEqualTo( + UInt256.valueOf( + new BigInteger( + "115792089237316195423570985008687907853269984665640564039457584007913129638912", + 10))); assertThat(result.getTerminalBlockHash()).isEqualTo(Hash.ZERO); assertThat(result.getTerminalBlockNumber()).isEqualTo(0L); }