Skip to content

Commit

Permalink
correct fallback ttd to correct value (hyperledger#4223)
Browse files Browse the repository at this point in the history
* correct fallback ttd to correct value

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
  • Loading branch information
daniellehrner and macfarla authored Aug 7, 2022
1 parent b02ae70 commit ca9a076
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

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

0 comments on commit ca9a076

Please sign in to comment.