diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/BlockUtils.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/BlockUtils.java index 39385e504b..ab686920b3 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/BlockUtils.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/BlockUtils.java @@ -19,11 +19,11 @@ import static org.hyperledger.besu.ethereum.core.Hash.fromHexString; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.LogsBloomFilter; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; import org.web3j.protocol.core.methods.response.EthBlock.Block; public class BlockUtils { @@ -42,7 +42,7 @@ public class BlockUtils { fromHexString(block.getTransactionsRoot()), fromHexString(block.getReceiptsRoot()), LogsBloomFilter.fromHexString(block.getLogsBloom()), - UInt256.fromHexString(block.getDifficultyRaw()), + Difficulty.fromHexString(block.getDifficultyRaw()), block.getNumber().longValue(), block.getGasLimit().longValue(), block.getGasUsed().longValue(), diff --git a/besu/src/main/java/org/hyperledger/besu/chainimport/RlpBlockImporter.java b/besu/src/main/java/org/hyperledger/besu/chainimport/RlpBlockImporter.java index fef7acdcf9..37b34810c7 100644 --- a/besu/src/main/java/org/hyperledger/besu/chainimport/RlpBlockImporter.java +++ b/besu/src/main/java/org/hyperledger/besu/chainimport/RlpBlockImporter.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockImporter; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; @@ -42,7 +43,6 @@ import java.util.concurrent.Semaphore; import com.google.common.base.MoreObjects; import org.apache.logging.log4j.Logger; -import org.apache.tuweni.units.bigints.UInt256; /** Tool for importing rlp-encoded block data from files. */ public class RlpBlockImporter { @@ -204,11 +204,11 @@ public class RlpBlockImporter { public static final class ImportResult { - public final UInt256 td; + public final Difficulty td; final int count; - ImportResult(final UInt256 td, final int count) { + ImportResult(final Difficulty td, final int count) { this.td = td; this.count = count; } diff --git a/besu/src/main/java/org/hyperledger/besu/services/BesuEventsImpl.java b/besu/src/main/java/org/hyperledger/besu/services/BesuEventsImpl.java index 9f5e441168..7dc2578eb7 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/BesuEventsImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/BesuEventsImpl.java @@ -18,9 +18,9 @@ import static java.util.stream.Collectors.toUnmodifiableList; import org.hyperledger.besu.ethereum.api.query.LogsQuery; import org.hyperledger.besu.ethereum.chain.Blockchain; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.LogTopic; import org.hyperledger.besu.ethereum.core.LogWithMetadata; -import org.hyperledger.besu.ethereum.core.QuantityWrapper; import org.hyperledger.besu.ethereum.eth.sync.BlockBroadcaster; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -36,7 +36,6 @@ import java.util.List; import java.util.function.Supplier; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; public class BesuEventsImpl implements BesuEvents { private Blockchain blockchain; @@ -134,7 +133,7 @@ public class BesuEventsImpl implements BesuEvents { private static PropagatedBlockContext blockPropagatedContext( final Supplier blockHeaderSupplier, - final Supplier totalDifficultySupplier) { + final Supplier totalDifficultySupplier) { return new PropagatedBlockContext() { @Override public BlockHeader getBlockHeader() { @@ -143,7 +142,7 @@ public class BesuEventsImpl implements BesuEvents { @Override public Quantity getTotalDifficulty() { - return new QuantityWrapper(totalDifficultySupplier.get()); + return totalDifficultySupplier.get(); } }; } diff --git a/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java b/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java index 0592f4906b..4be9327e7f 100644 --- a/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java +++ b/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java @@ -28,6 +28,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.core.Wei; import org.hyperledger.besu.ethereum.core.WorldState; @@ -64,7 +65,6 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Stream; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -183,7 +183,7 @@ public class BesuEventsImplTest { serviceImpl.addBlockPropagatedListener(result::set); final Block block = generateBlock(); assertThat(result.get()).isNull(); - blockBroadcaster.propagate(block, UInt256.valueOf(1)); + blockBroadcaster.propagate(block, Difficulty.of(1)); assertThat(result.get()).isNotNull(); assertThat(result.get().getBlockHeader()).isEqualTo(block.getHeader()); @@ -197,7 +197,7 @@ public class BesuEventsImplTest { assertThat(result.get()).isNull(); final Block block = generateBlock(); - blockBroadcaster.propagate(block, UInt256.valueOf(2)); + blockBroadcaster.propagate(block, Difficulty.of(2)); assertThat(result.get()).isNotNull(); assertThat(result.get().getBlockHeader()).isEqualTo(block.getHeader()); @@ -205,13 +205,13 @@ public class BesuEventsImplTest { serviceImpl.removeBlockPropagatedListener(id); result.set(null); - blockBroadcaster.propagate(generateBlock(), UInt256.valueOf(1)); + blockBroadcaster.propagate(generateBlock(), Difficulty.of(1)); assertThat(result.get()).isNull(); } @Test public void propagationWithoutSubscriptionsCompletes() { - blockBroadcaster.propagate(generateBlock(), UInt256.valueOf(1)); + blockBroadcaster.propagate(generateBlock(), Difficulty.of(1)); } @Test diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueBlockHashing.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueBlockHashing.java index e92e702d34..013d633773 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueBlockHashing.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueBlockHashing.java @@ -84,7 +84,7 @@ public class CliqueBlockHashing { out.writeBytes(header.getTransactionsRoot()); out.writeBytes(header.getReceiptsRoot()); out.writeBytes(header.getLogsBloom().getBytes()); - out.writeBytes(header.internalGetDifficulty().toMinimalBytes()); + out.writeBytes(header.getDifficulty().toMinimalBytes()); out.writeLongScalar(header.getNumber()); out.writeLongScalar(header.getGasLimit()); out.writeLongScalar(header.getGasUsed()); diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRule.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRule.java index f804459637..2acaa9201c 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRule.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRule.java @@ -38,7 +38,7 @@ public class CliqueDifficultyValidationRule new CliqueDifficultyCalculator(actualBlockCreator); final BigInteger expectedDifficulty = diffCalculator.nextDifficulty(0, parent, protocolContext); - final BigInteger actualDifficulty = header.internalGetDifficulty().toBigInteger(); + final BigInteger actualDifficulty = header.getDifficulty().toBigInteger(); return expectedDifficulty.equals(actualDifficulty); } diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueBlockHashingTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueBlockHashingTest.java index b855cd275f..3676e0c820 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueBlockHashingTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueBlockHashingTest.java @@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.LogsBloomFilter; @@ -26,7 +27,6 @@ import java.util.Arrays; import java.util.List; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.Test; @@ -82,7 +82,7 @@ public class CliqueBlockHashingTest { // The following text was a dump from the geth console of the 30_000 block on Rinkeby. // eth.getBlock(30000) final BlockHeaderBuilder builder = new BlockHeaderBuilder(); - builder.difficulty(UInt256.valueOf(2)); + builder.difficulty(Difficulty.of(2)); builder.extraData( Bytes.fromHexString( "0xd783010600846765746887676f312e372e33856c696e7578000000000000000042eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f0c5bc40d0535af16266714ccb26fc49448c10bdf2969411514707d7442956b3397b09a980f4bea9347f70eea52183326247a0239b6d01fa0b07afc44e8a05463301")); @@ -117,7 +117,7 @@ public class CliqueBlockHashingTest { private BlockHeader createGenesisBlock() { // The following was taken from the Rinkeby genesis file final BlockHeaderBuilder builder = new BlockHeaderBuilder(); - builder.difficulty(UInt256.valueOf(1)); + builder.difficulty(Difficulty.ONE); builder.extraData( Bytes.fromHexString( "0x52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java index cd70044c29..e6f8c27d9d 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java @@ -31,12 +31,12 @@ import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.AddressHelpers; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Util; import java.util.List; import com.google.common.collect.Lists; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.Test; @@ -67,7 +67,7 @@ public class CliqueDifficultyValidationRuleTest { @Test public void isTrueIfInTurnValidatorSuppliesDifficultyOfTwo() { final long IN_TURN_BLOCK_NUMBER = validatorList.size(); // i.e. proposer is 'in turn' - final UInt256 REPORTED_DIFFICULTY = UInt256.valueOf(2); + final Difficulty REPORTED_DIFFICULTY = Difficulty.of(2); blockHeaderBuilder.number(IN_TURN_BLOCK_NUMBER - 1L); final BlockHeader parentHeader = @@ -86,7 +86,7 @@ public class CliqueDifficultyValidationRuleTest { @Test public void isTrueIfOutTurnValidatorSuppliesDifficultyOfOne() { final long OUT_OF_TURN_BLOCK_NUMBER = validatorList.size() - 1L; - final UInt256 REPORTED_DIFFICULTY = UInt256.ONE; + final Difficulty REPORTED_DIFFICULTY = Difficulty.ONE; blockHeaderBuilder.number(OUT_OF_TURN_BLOCK_NUMBER - 1L); final BlockHeader parentHeader = @@ -105,7 +105,7 @@ public class CliqueDifficultyValidationRuleTest { @Test public void isFalseIfOutTurnValidatorSuppliesDifficultyOfTwo() { final long OUT_OF_TURN_BLOCK_NUMBER = validatorList.size() - 1L; - final UInt256 REPORTED_DIFFICULTY = UInt256.valueOf(2); + final Difficulty REPORTED_DIFFICULTY = Difficulty.of(2); blockHeaderBuilder.number(OUT_OF_TURN_BLOCK_NUMBER - 1L); final BlockHeader parentHeader = @@ -125,7 +125,7 @@ public class CliqueDifficultyValidationRuleTest { @Test public void isFalseIfInTurnValidatorSuppliesDifficultyOfOne() { final long IN_TURN_BLOCK_NUMBER = validatorList.size(); - final UInt256 REPORTED_DIFFICULTY = UInt256.ONE; + final Difficulty REPORTED_DIFFICULTY = Difficulty.ONE; blockHeaderBuilder.number(IN_TURN_BLOCK_NUMBER - 1L); final BlockHeader parentHeader = diff --git a/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java b/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java index 28db22f1a1..f18f8f7c42 100644 --- a/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java +++ b/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java @@ -60,6 +60,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.core.Util; @@ -85,7 +86,6 @@ import java.util.stream.Collectors; import com.google.common.collect.Iterables; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; public class TestContextBuilder { @@ -240,7 +240,7 @@ public class TestContextBuilder { Bytes.wrap(new byte[32]), Collections.emptyList(), Optional.empty(), 0, validators); headerTestFixture.extraData(extraData.encode()); headerTestFixture.mixHash(IbftHelpers.EXPECTED_MIX_HASH); - headerTestFixture.difficulty(UInt256.ONE); + headerTestFixture.difficulty(Difficulty.ONE); headerTestFixture.ommersHash(Hash.EMPTY_LIST_HASH); headerTestFixture.nonce(0); headerTestFixture.timestamp(0); diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactory.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactory.java index e9db8625ae..35dfa0ae05 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactory.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactory.java @@ -54,7 +54,7 @@ public class IbftBlockHeaderValidationRulesetFactory { "OmmersHash", BlockHeader::getOmmersHash, Hash.EMPTY_LIST_HASH)) .addRule( new ConstantFieldValidationRule<>( - "Difficulty", BlockHeader::internalGetDifficulty, UInt256.ONE)) + "Difficulty", BlockHeader::getDifficulty, UInt256.ONE)) .addRule(new ConstantFieldValidationRule<>("Nonce", BlockHeader::getNonce, 0L)) .addRule(new IbftValidatorsValidationRule()) .addRule(new IbftCoinbaseValidationRule()) diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHashingTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHashingTest.java index fd88481e30..282978d6b6 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHashingTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHashingTest.java @@ -24,6 +24,7 @@ import org.hyperledger.besu.crypto.SECP256K1.Signature; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.LogsBloomFilter; import org.hyperledger.besu.ethereum.core.Util; @@ -120,7 +121,7 @@ public class IbftBlockHashingTest { + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "0000")); - builder.difficulty(UInt256.ONE); + builder.difficulty(Difficulty.ONE); builder.number(1); builder.gasLimit(4704588); builder.gasUsed(0); diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java index dfd9f0114c..a3c4410620 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java @@ -24,6 +24,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; @@ -34,7 +35,6 @@ import java.util.List; import java.util.Optional; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Test; public class IbftBlockHeaderValidationRulesetFactoryTest { @@ -211,7 +211,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest { getPresetHeaderBuilder(1, proposerKeyPair, validators, null).buildHeader(); final BlockHeader blockHeader = getPresetHeaderBuilder(2, proposerKeyPair, validators, parentHeader) - .difficulty(UInt256.valueOf(5)) + .difficulty(Difficulty.of(5)) .buildHeader(); final BlockHeaderValidator validator = @@ -308,7 +308,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest { Hash.fromHexString("0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365")); builder.ommersHash(Hash.EMPTY_LIST_HASH); builder.nonce(0); - builder.difficulty(UInt256.ONE); + builder.difficulty(Difficulty.ONE); builder.coinbase(Util.publicKeyToAddress(proposerKeyPair.getPublicKey())); final IbftExtraData ibftExtraData = diff --git a/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHashing.java b/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHashing.java index 581f240f49..e994451010 100644 --- a/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHashing.java +++ b/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHashing.java @@ -149,7 +149,7 @@ public class IbftBlockHashing { out.writeBytes(header.getTransactionsRoot()); out.writeBytes(header.getReceiptsRoot()); out.writeBytes(header.getLogsBloom().getBytes()); - out.writeBytes(header.internalGetDifficulty().toMinimalBytes()); + out.writeBytes(header.getDifficulty().toMinimalBytes()); out.writeLongScalar(header.getNumber()); out.writeLongScalar(header.getGasLimit()); out.writeLongScalar(header.getGasUsed()); diff --git a/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHeaderValidationRulesetFactory.java b/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHeaderValidationRulesetFactory.java index a2cd354915..a73fffb143 100644 --- a/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHeaderValidationRulesetFactory.java +++ b/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHeaderValidationRulesetFactory.java @@ -71,7 +71,7 @@ public class IbftBlockHeaderValidationRulesetFactory { "OmmersHash", BlockHeader::getOmmersHash, Hash.EMPTY_LIST_HASH)) .addRule( new ConstantFieldValidationRule<>( - "Difficulty", BlockHeader::internalGetDifficulty, UInt256.ONE)) + "Difficulty", BlockHeader::getDifficulty, UInt256.ONE)) .addRule(new VoteValidationRule()) .addRule(new IbftExtraDataValidationRule(validateCommitSeals)) .build(); diff --git a/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHashingTest.java b/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHashingTest.java index 9f303f15ae..a0e41e1220 100644 --- a/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHashingTest.java +++ b/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHashingTest.java @@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.LogsBloomFilter; @@ -26,7 +27,6 @@ import java.util.Arrays; import java.util.List; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; import org.assertj.core.api.Assertions; import org.junit.Test; @@ -117,7 +117,7 @@ public class IbftBlockHashingTest { + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "0000")); - builder.difficulty(UInt256.ONE); + builder.difficulty(Difficulty.ONE); builder.number(1); builder.gasLimit(4704588); builder.gasUsed(0); diff --git a/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHeaderValidationRulesetFactoryTest.java b/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHeaderValidationRulesetFactoryTest.java index f93313e1cb..2b930e8dbc 100644 --- a/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHeaderValidationRulesetFactoryTest.java +++ b/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHeaderValidationRulesetFactoryTest.java @@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; @@ -40,7 +41,6 @@ import java.util.Collection; import java.util.List; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Test; public class IbftBlockHeaderValidationRulesetFactoryTest { @@ -120,7 +120,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest { Hash.fromHexString("0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365")); builder.ommersHash(Hash.EMPTY_LIST_HASH); builder.nonce(IbftLegacyBlockInterface.DROP_NONCE); - builder.difficulty(UInt256.ONE); + builder.difficulty(Difficulty.ONE); // Construct an extraData block final IbftExtraData initialIbftExtraData = diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseUtils.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseUtils.java index cacfe7c276..1519a9e1d8 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseUtils.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseUtils.java @@ -44,6 +44,7 @@ import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.LogsBloomFilter; import org.hyperledger.besu.ethereum.core.Transaction; @@ -83,7 +84,7 @@ public class JsonRpcResponseUtils { final Hash transactionsRoot = hash(values.get(TRANSACTION_ROOT)); final Hash receiptsRoot = hash(values.get(RECEIPTS_ROOT)); final LogsBloomFilter logsBloom = logsBloom(values.get(LOGS_BLOOM)); - final UInt256 difficulty = unsignedInt256(values.get(DIFFICULTY)); + final Difficulty difficulty = Difficulty.of(unsignedInt256(values.get(DIFFICULTY))); final Bytes extraData = bytes(values.get(EXTRA_DATA)); final BlockHeaderFunctions blockHeaderFunctions = new MainnetBlockHeaderFunctions(); final long number = unsignedLong(values.get(NUMBER)); @@ -91,7 +92,7 @@ public class JsonRpcResponseUtils { final long gasUsed = unsignedLong(values.get(GAS_USED)); final long timestamp = unsignedLong(values.get(TIMESTAMP)); final long nonce = unsignedLong(values.get(NONCE)); - final UInt256 totalDifficulty = unsignedInt256(values.get(TOTAL_DIFFICULTY)); + final Difficulty totalDifficulty = Difficulty.of(unsignedInt256(values.get(TOTAL_DIFFICULTY))); final int size = unsignedInt(values.get(SIZE)); final List ommers = new ArrayList<>(); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java index 84d91cbcdd..54e5ed91ab 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java @@ -40,6 +40,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -61,7 +62,6 @@ import java.util.List; import java.util.Optional; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; import org.assertj.core.util.Lists; import org.junit.Before; import org.junit.Test; @@ -256,7 +256,7 @@ public class EthGetFilterChangesIntegrationTest { } private Block appendBlock(final Transaction... transactionsToAdd) { - return appendBlock(UInt256.ONE, getHeaderForCurrentChainHead(), transactionsToAdd); + return appendBlock(Difficulty.ONE, getHeaderForCurrentChainHead(), transactionsToAdd); } private BlockHeader getHeaderForCurrentChainHead() { @@ -264,7 +264,7 @@ public class EthGetFilterChangesIntegrationTest { } private Block appendBlock( - final UInt256 difficulty, + final Difficulty difficulty, final BlockHeader parentBlock, final Transaction... transactionsToAdd) { final List transactionList = asList(transactionsToAdd); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/BlockAdapterBase.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/BlockAdapterBase.java index 851cf7f9d7..6faa439d66 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/BlockAdapterBase.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/BlockAdapterBase.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.api.query.LogsQuery; import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.LogTopic; import org.hyperledger.besu.ethereum.core.LogWithMetadata; @@ -118,8 +119,8 @@ public class BlockAdapterBase extends AdapterBase { return Optional.of(header.getMixHash()); } - public Optional getDifficulty() { - return Optional.of(header.internalGetDifficulty()); + public Optional getDifficulty() { + return Optional.of(header.getDifficulty()); } public Optional getOmmerHash() { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/NormalBlockAdapter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/NormalBlockAdapter.java index 2e2bacd901..42e00a6cfc 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/NormalBlockAdapter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/NormalBlockAdapter.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import java.util.ArrayList; @@ -25,7 +26,6 @@ import java.util.List; import java.util.Optional; import graphql.schema.DataFetchingEnvironment; -import org.apache.tuweni.units.bigints.UInt256; @SuppressWarnings("unused") // reflected by GraphQL public class NormalBlockAdapter extends BlockAdapterBase { @@ -42,7 +42,7 @@ public class NormalBlockAdapter extends BlockAdapterBase { return Optional.of(blockWithMetaData.getTransactions().size()); } - public Optional getTotalDifficulty() { + public Optional getTotalDifficulty() { return Optional.of(blockWithMetaData.getTotalDifficulty()); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResult.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResult.java index e3e29bc6da..092fe2b8e7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResult.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResult.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.Difficulty; import java.util.List; @@ -23,7 +24,6 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.JsonNode; -import org.apache.tuweni.units.bigints.UInt256; @JsonPropertyOrder({ "number", @@ -73,7 +73,7 @@ public class BlockResult implements JsonRpcResult { final BlockHeader header, final List transactions, final List ommers, - final UInt256 totalDifficulty, + final Difficulty totalDifficulty, final int size) { this(header, transactions, ommers, totalDifficulty, size, false); } @@ -82,7 +82,7 @@ public class BlockResult implements JsonRpcResult { final BlockHeader header, final List transactions, final List ommers, - final UInt256 totalDifficulty, + final Difficulty totalDifficulty, final int size, final boolean includeCoinbase) { this.number = Quantity.create(header.getNumber()); @@ -95,7 +95,7 @@ public class BlockResult implements JsonRpcResult { this.stateRoot = header.getStateRoot().toString(); this.receiptsRoot = header.getReceiptsRoot().toString(); this.miner = header.getCoinbase().toString(); - this.difficulty = Quantity.create(header.internalGetDifficulty()); + this.difficulty = Quantity.create(header.getDifficulty()); this.totalDifficulty = Quantity.create(totalDifficulty); this.extraData = header.getExtraData().toString(); this.size = Quantity.create(size); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/UncleBlockResult.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/UncleBlockResult.java index 2b9198dec0..68a1c5ff6f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/UncleBlockResult.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/UncleBlockResult.java @@ -17,11 +17,10 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.Difficulty; import java.util.Collections; -import org.apache.tuweni.units.bigints.UInt256; - public class UncleBlockResult { /** @@ -34,6 +33,6 @@ public class UncleBlockResult { final BlockBody body = new BlockBody(Collections.emptyList(), Collections.emptyList()); final int size = new Block(header, body).calculateSize(); return new BlockResult( - header, Collections.emptyList(), Collections.emptyList(), UInt256.ZERO, size); + header, Collections.emptyList(), Collections.emptyList(), Difficulty.ZERO, size); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockWithMetadata.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockWithMetadata.java index 1623cf30c8..6551e8b161 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockWithMetadata.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockWithMetadata.java @@ -15,17 +15,16 @@ package org.hyperledger.besu.ethereum.api.query; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.Difficulty; import java.util.List; -import org.apache.tuweni.units.bigints.UInt256; - public class BlockWithMetadata { private final BlockHeader header; private final List transactions; private final List ommers; - private final UInt256 totalDifficulty; + private final Difficulty totalDifficulty; private final int size; /** @@ -39,7 +38,7 @@ public class BlockWithMetadata { final BlockHeader header, final List transactions, final List ommers, - final UInt256 totalDifficulty, + final Difficulty totalDifficulty, final int size) { this.header = header; this.transactions = transactions; @@ -60,7 +59,7 @@ public class BlockWithMetadata { return transactions; } - public UInt256 getTotalDifficulty() { + public Difficulty getTotalDifficulty() { return totalDifficulty; } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java index 0e3f991c7b..394e94e886 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java @@ -40,6 +40,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.DefaultSyncStatus; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; @@ -1722,7 +1723,7 @@ public class JsonRpcHttpServiceTest { private void verifyBlockResult( final Block block, - final UInt256 td, + final Difficulty td, final JsonObject result, final boolean shouldTransactionsBeHashed) { assertBlockResultMatchesBlock(result, block); @@ -1730,7 +1731,7 @@ public class JsonRpcHttpServiceTest { if (td == null) { assertThat(result.getJsonObject("totalDifficulty")).isNull(); } else { - assertThat(UInt256.fromHexString(result.getString("totalDifficulty"))).isEqualTo(td); + assertThat(Difficulty.fromHexString(result.getString("totalDifficulty"))).isEqualTo(td); } // Check ommers @@ -1812,8 +1813,8 @@ public class JsonRpcHttpServiceTest { assertThat(Hash.fromHexString(result.getString("receiptsRoot"))) .isEqualTo(header.getReceiptsRoot()); assertThat(Address.fromHexString(result.getString("miner"))).isEqualTo(header.getCoinbase()); - assertThat(UInt256.fromHexString(result.getString("difficulty"))) - .isEqualTo(header.internalGetDifficulty()); + assertThat(Difficulty.fromHexString(result.getString("difficulty"))) + .isEqualTo(header.getDifficulty()); assertThat(Bytes.fromHexStringLenient(result.getString("extraData"))) .isEqualTo(header.internalGetExtraData()); assertThat(hexStringToInt(result.getString("size"))).isEqualTo(block.calculateSize()); @@ -1877,7 +1878,7 @@ public class JsonRpcHttpServiceTest { } public BlockWithMetadata blockWithMetadata(final Block block) { - final UInt256 td = block.getHeader().internalGetDifficulty().add(10L); + final Difficulty td = block.getHeader().getDifficulty().add(10L); final int size = block.calculateSize(); final List txs = block.getBody().getTransactions(); @@ -1893,7 +1894,7 @@ public class JsonRpcHttpServiceTest { } public BlockWithMetadata blockWithMetadataAndTxHashes(final Block block) { - final UInt256 td = block.getHeader().internalGetDifficulty().add(10L); + final Difficulty td = block.getHeader().getDifficulty().add(10L); final int size = block.calculateSize(); final List txs = diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfoTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfoTest.java index 90261e0f6f..e16ee161c0 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfoTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfoTest.java @@ -29,6 +29,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSucces import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.ChainHead; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork; import org.hyperledger.besu.ethereum.p2p.peers.DefaultPeer; @@ -42,7 +43,6 @@ import java.util.Optional; import com.google.common.collect.ImmutableMap; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -61,7 +61,7 @@ public class AdminNodeInfoTest { private final Bytes nodeId = Bytes.fromHexString( "0x0f1b319e32017c3fcb221841f0f978701b4e9513fe6a567a2db43d43381a9c7e3dfe7cae13cbc2f56943400bacaf9082576ab087cd51983b17d729ae796f6807"); - private final ChainHead testChainHead = new ChainHead(Hash.EMPTY, UInt256.ONE, 1L); + private final ChainHead testChainHead = new ChainHead(Hash.EMPTY, Difficulty.ONE, 1L); private final GenesisConfigOptions genesisConfigOptions = new StubGenesisConfigOptions().chainId(BigInteger.valueOf(2019)); private final DefaultPeer defaultPeer = diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAtTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAtTest.java index 1bbf2a4470..62171eee16 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAtTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAtTest.java @@ -34,6 +34,7 @@ import org.hyperledger.besu.ethereum.core.Account; import org.hyperledger.besu.ethereum.core.AccountStorageEntry; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.Transaction; @@ -93,7 +94,7 @@ public class DebugStorageRangeAtTest { blockHeader, Collections.singletonList(transactionWithMetadata), Collections.emptyList(), - UInt256.ONE, + Difficulty.ONE, 1); final JsonRpcRequestContext request = new JsonRpcRequestContext( diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockTest.java index 5e973cc584..2122f1a59b 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockTest.java @@ -113,7 +113,7 @@ public class DebugTraceBlockTest { parentBlock.getHeader(), Collections.emptyList(), Collections.emptyList(), - parentBlock.getHeader().internalGetDifficulty(), + parentBlock.getHeader().getDifficulty(), parentBlock.calculateSize()))); final JsonRpcSuccessResponse response = diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndexTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndexTest.java index 4773fad697..4033465ec8 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndexTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndexTest.java @@ -33,6 +33,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; @@ -42,7 +43,6 @@ import java.util.Collections; import java.util.List; import java.util.Optional; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -150,7 +150,7 @@ public class EthGetUncleByBlockHashAndIndexTest { header, Collections.emptyList(), Collections.emptyList(), - UInt256.ZERO, + Difficulty.ZERO, block.calculateSize()); } @@ -172,6 +172,6 @@ public class EthGetUncleByBlockHashAndIndexTest { final List ommers = new ArrayList<>(); ommers.add(Hash.ZERO); - return new BlockWithMetadata<>(header, transactions, ommers, header.internalGetDifficulty(), 0); + return new BlockWithMetadata<>(header, transactions, ommers, header.getDifficulty(), 0); } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java index a9abd39932..10b3419a02 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java @@ -33,6 +33,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; @@ -42,7 +43,6 @@ import java.util.Collections; import java.util.List; import java.util.Optional; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -126,7 +126,7 @@ public class EthGetUncleByBlockNumberAndIndexTest { header, Collections.emptyList(), Collections.emptyList(), - UInt256.ZERO, + Difficulty.ZERO, block.calculateSize()); } @@ -148,6 +148,6 @@ public class EthGetUncleByBlockNumberAndIndexTest { final List ommers = new ArrayList<>(); ommers.add(Hash.ZERO); - return new BlockWithMetadata<>(header, transactions, ommers, header.internalGetDifficulty(), 0); + return new BlockWithMetadata<>(header, transactions, ommers, header.getDifficulty(), 0); } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/blockheaders/NewBlockHeadersSubscriptionServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/blockheaders/NewBlockHeadersSubscriptionServiceTest.java index cb2fcff916..38c051c44d 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/blockheaders/NewBlockHeadersSubscriptionServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/blockheaders/NewBlockHeadersSubscriptionServiceTest.java @@ -35,6 +35,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; @@ -45,7 +46,6 @@ import java.util.Optional; import java.util.function.Consumer; import com.google.common.collect.Lists; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -126,11 +126,7 @@ public class NewBlockHeadersSubscriptionServiceTest { final List txHashList = transactionsWithMetadata(); final BlockWithMetadata testBlockWithMetadata = new BlockWithMetadata<>( - blockHeader, - txHashList, - Collections.emptyList(), - blockHeader.internalGetDifficulty(), - 0); + blockHeader, txHashList, Collections.emptyList(), blockHeader.getDifficulty(), 0); final BlockResult expectedNewBlock = blockResultFactory.transactionComplete(testBlockWithMetadata); when(blockchainQueries.blockByHash(testBlockWithMetadata.getHeader().getHash())) @@ -178,7 +174,7 @@ public class NewBlockHeadersSubscriptionServiceTest { private BlockResult expectedBlockWithTransactions(final List objects) { final BlockWithMetadata testBlockWithMetadata = - new BlockWithMetadata<>(blockHeader, objects, Collections.emptyList(), UInt256.ONE, 1); + new BlockWithMetadata<>(blockHeader, objects, Collections.emptyList(), Difficulty.ONE, 1); final BlockResult expectedNewBlock = blockResultFactory.transactionHash(testBlockWithMetadata); when(blockchainQueries.blockByHashWithTxHashes(testBlockWithMetadata.getHeader().getHash())) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java index 357376b476..ffbf46e666 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java @@ -28,6 +28,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.Log; import org.hyperledger.besu.ethereum.core.LogsBloomFilter; @@ -43,7 +44,6 @@ import java.util.List; import java.util.Optional; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; @@ -104,7 +104,7 @@ public class BlockchainQueriesLogCacheTest { Hash.EMPTY, Hash.EMPTY, testLogsBloomFilter, - UInt256.ZERO, + Difficulty.ZERO, 0, 0, 0, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesTest.java index 8f943e63fb..19ed0cce6e 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesTest.java @@ -333,7 +333,7 @@ public class BlockchainQueriesTest { .setParentHash(data.blockchain.getBlockHashByNumber(commonAncestor).get()) .setBlockNumber(forkBlock) .setDifficulty( - data.blockchain.getBlockHeader(forkBlock).get().internalGetDifficulty().add(10L)); + data.blockchain.getBlockHeader(forkBlock).get().getDifficulty().add(10L)); final Block fork = gen.block(options); final List forkReceipts = gen.receipts(fork); diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java index 538ce5da6e..8e43f1bbde 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java @@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; import org.hyperledger.besu.ethereum.core.DefaultEvmAccount; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; @@ -49,7 +50,6 @@ import com.google.common.collect.Lists; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; public abstract class AbstractBlockCreator implements AsyncBlockCreator { @@ -256,7 +256,7 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator { return BlockHeaderBuilder.create() .parentHash(parentHeader.getHash()) .coinbase(coinbase) - .difficulty(UInt256.valueOf(difficulty)) + .difficulty(Difficulty.of(difficulty)) .number(newBlockNumber) .gasLimit(gasLimit) .timestamp(timestamp) diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockCreator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockCreator.java index c4d1eb957a..fec8b172b9 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockCreator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockCreator.java @@ -85,7 +85,7 @@ public class EthHashBlockCreator extends AbstractBlockCreator { private EthHashSolverInputs generateNonceSolverInputs( final SealableBlockHeader sealableBlockHeader) { - final BigInteger difficulty = sealableBlockHeader.internalGetDifficulty().toBigInteger(); + final BigInteger difficulty = sealableBlockHeader.getDifficulty().toBigInteger(); final UInt256 target = difficulty.equals(BigInteger.ONE) ? UInt256.MAX_VALUE diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockTransactionSelectorTest.java index 5f52318850..d047f9a3ce 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockTransactionSelectorTest.java @@ -27,6 +27,7 @@ import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.AddressHelpers; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.InMemoryStorageProvider; import org.hyperledger.besu.ethereum.core.LogSeries; @@ -59,7 +60,6 @@ import java.util.function.Supplier; import com.google.common.collect.Lists; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; import org.assertj.core.api.Assertions; import org.junit.Test; @@ -83,7 +83,7 @@ public class BlockTransactionSelectorTest { return BlockHeaderBuilder.create() .parentHash(Hash.EMPTY) .coinbase(Address.fromHexString(String.format("%020x", 1))) - .difficulty(UInt256.ONE) + .difficulty(Difficulty.ONE) .number(1) .gasLimit(gasLimit) .timestamp(Instant.now().toEpochMilli()) diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockCreatorTest.java index 9595acff2d..3a0ed0c08d 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/EthHashBlockCreatorTest.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.MutableWorldState; @@ -44,7 +45,6 @@ import java.util.function.Function; import com.google.common.collect.Lists; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Test; public class EthHashBlockCreatorTest { @@ -198,7 +198,7 @@ public class EthHashBlockCreatorTest { BlockHeaderBuilder.create() .parentHash(Hash.ZERO) .coinbase(BLOCK_1_COINBASE) - .difficulty(UInt256.ONE) + .difficulty(Difficulty.ONE) .number(1) .gasLimit(1) .timestamp(1) @@ -258,7 +258,7 @@ public class EthHashBlockCreatorTest { BlockHeaderBuilder.create() .parentHash(Hash.ZERO) .coinbase(BLOCK_1_COINBASE) - .difficulty(UInt256.ONE) + .difficulty(Difficulty.ONE) .number(1) .gasLimit(1) .timestamp(1) diff --git a/ethereum/core/src/jmh/java/org/hyperledger/besu/ethereum/vm/operations/OperationBenchmarkHelper.java b/ethereum/core/src/jmh/java/org/hyperledger/besu/ethereum/vm/operations/OperationBenchmarkHelper.java index 027bca2cea..52817faa48 100644 --- a/ethereum/core/src/jmh/java/org/hyperledger/besu/ethereum/vm/operations/OperationBenchmarkHelper.java +++ b/ethereum/core/src/jmh/java/org/hyperledger/besu/ethereum/vm/operations/OperationBenchmarkHelper.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; import org.hyperledger.besu.ethereum.core.MessageFrameTestFixture; import org.hyperledger.besu.ethereum.vm.MessageFrame; @@ -35,7 +36,6 @@ import java.nio.file.Path; import com.google.common.io.MoreFiles; import com.google.common.io.RecursiveDeleteOption; -import org.apache.tuweni.units.bigints.UInt256; public class OperationBenchmarkHelper { @@ -70,7 +70,7 @@ public class OperationBenchmarkHelper { new BlockHeaderTestFixture() .parentHash(blockchain.getChainHeadHash()) .number(i) - .difficulty(UInt256.ONE) + .difficulty(Difficulty.ONE) .buildHeader(), new BlockBody(emptyList(), emptyList())), emptyList()); @@ -82,7 +82,7 @@ public class OperationBenchmarkHelper { new BlockHeaderTestFixture() .parentHash(blockchain.getChainHeadHash()) .number(blockchain.getChainHeadBlockNumber() + 1) - .difficulty(UInt256.ONE) + .difficulty(Difficulty.ONE) .buildHeader()) .build(); return new OperationBenchmarkHelper(storageDirectory, keyValueStorage, messageFrame); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/Blockchain.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/Blockchain.java index f0a8b43be4..5e9e59816f 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/Blockchain.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/Blockchain.java @@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.chain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.LogWithMetadata; import org.hyperledger.besu.ethereum.core.Transaction; @@ -26,8 +27,6 @@ import java.util.List; import java.util.Optional; import java.util.function.Consumer; -import org.apache.tuweni.units.bigints.UInt256; - /** An interface for reading data from the blockchain. */ public interface Blockchain { /** @@ -160,7 +159,7 @@ public interface Blockchain { * @param blockHeaderHash The hash of the block header being queried. * @return The total difficulty of the corresponding block. */ - Optional getTotalDifficultyByHash(Hash blockHeaderHash); + Optional getTotalDifficultyByHash(Hash blockHeaderHash); /** * Given a transaction hash, returns the location (block number and transaction index) of the diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/BlockchainStorage.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/BlockchainStorage.java index 5209b48336..27206b06bb 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/BlockchainStorage.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/BlockchainStorage.java @@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.chain; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -23,8 +24,6 @@ import java.util.Collection; import java.util.List; import java.util.Optional; -import org.apache.tuweni.units.bigints.UInt256; - public interface BlockchainStorage { Optional getChainHead(); @@ -39,7 +38,7 @@ public interface BlockchainStorage { Optional getBlockHash(long blockNumber); - Optional getTotalDifficulty(Hash blockHash); + Optional getTotalDifficulty(Hash blockHash); Optional getTransactionLocation(Hash transactionHash); @@ -57,7 +56,7 @@ public interface BlockchainStorage { void putBlockHash(long blockNumber, Hash blockHash); - void putTotalDifficulty(Hash blockHash, UInt256 totalDifficulty); + void putTotalDifficulty(Hash blockHash, Difficulty totalDifficulty); void setChainHead(Hash blockHash); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/ChainHead.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/ChainHead.java index d583cf432b..70d5e17597 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/ChainHead.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/ChainHead.java @@ -14,20 +14,19 @@ */ package org.hyperledger.besu.ethereum.chain; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; -import org.apache.tuweni.units.bigints.UInt256; - /** Head of a blockchain. */ public final class ChainHead { private final Hash hash; - private final UInt256 totalDifficulty; + private final Difficulty totalDifficulty; private final long height; - public ChainHead(final Hash hash, final UInt256 totalDifficulty, final long height) { + public ChainHead(final Hash hash, final Difficulty totalDifficulty, final long height) { this.hash = hash; this.totalDifficulty = totalDifficulty; this.height = height; @@ -37,7 +36,7 @@ public final class ChainHead { return hash; } - public UInt256 getTotalDifficulty() { + public Difficulty getTotalDifficulty() { return totalDifficulty; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java index 8c5cb83a2f..dd66c543ee 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.LogWithMetadata; import org.hyperledger.besu.ethereum.core.Transaction; @@ -46,7 +47,6 @@ import java.util.stream.Stream; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Lists; -import org.apache.tuweni.units.bigints.UInt256; public class DefaultBlockchain implements MutableBlockchain { @@ -55,7 +55,7 @@ public class DefaultBlockchain implements MutableBlockchain { private final Subscribers blockAddedObservers = Subscribers.create(); private volatile BlockHeader chainHeader; - private volatile UInt256 totalDifficulty; + private volatile Difficulty totalDifficulty; private volatile int chainHeadTransactionCount; private volatile int chainHeadOmmerCount; @@ -194,7 +194,7 @@ public class DefaultBlockchain implements MutableBlockchain { } @Override - public Optional getTotalDifficultyByHash(final Hash blockHeaderHash) { + public Optional getTotalDifficultyByHash(final Hash blockHeaderHash) { return blockchainStorage.getTotalDifficulty(blockHeaderHash); } @@ -233,7 +233,7 @@ public class DefaultBlockchain implements MutableBlockchain { final Block block = blockWithReceipts.getBlock(); final List receipts = blockWithReceipts.getReceipts(); final Hash hash = block.getHash(); - final UInt256 td = calculateTotalDifficulty(block); + final Difficulty td = calculateTotalDifficulty(block); final BlockchainStorage.Updater updater = blockchainStorage.updater(); @@ -254,23 +254,23 @@ public class DefaultBlockchain implements MutableBlockchain { return blockAddedEvent; } - private UInt256 calculateTotalDifficulty(final Block block) { + private Difficulty calculateTotalDifficulty(final Block block) { if (block.getHeader().getNumber() == BlockHeader.GENESIS_BLOCK_NUMBER) { - return block.getHeader().internalGetDifficulty(); + return block.getHeader().getDifficulty(); } - final UInt256 parentTotalDifficulty = + final Difficulty parentTotalDifficulty = blockchainStorage .getTotalDifficulty(block.getHeader().getParentHash()) .orElseThrow( () -> new IllegalStateException("Blockchain is missing total difficulty data.")); - return block.getHeader().internalGetDifficulty().add(parentTotalDifficulty); + return block.getHeader().getDifficulty().add(parentTotalDifficulty); } private BlockAddedEvent updateCanonicalChainData( final BlockchainStorage.Updater updater, final BlockWithReceipts blockWithReceipts, - final UInt256 totalDifficulty) { + final Difficulty totalDifficulty) { final Block newBlock = blockWithReceipts.getBlock(); final Hash chainHead = blockchainStorage.getChainHead().orElse(null); if (newBlock.getHeader().getNumber() != BlockHeader.GENESIS_BLOCK_NUMBER && chainHead == null) { @@ -430,7 +430,7 @@ public class DefaultBlockchain implements MutableBlockchain { } } - void updateCacheForNewCanonicalHead(final Block block, final UInt256 uInt256) { + void updateCacheForNewCanonicalHead(final Block block, final Difficulty uInt256) { chainHeader = block.getHeader(); totalDifficulty = uInt256; chainHeadTransactionCount = block.getBody().getTransactions().size(); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java index e0229357c2..6e30e1ae60 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java @@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.LogsBloomFilter; import org.hyperledger.besu.ethereum.core.MutableAccount; @@ -189,8 +190,8 @@ public final class GenesisState { return withNiceErrorMessage("extraData", genesis.getExtraData(), Bytes::fromHexString); } - private static UInt256 parseDifficulty(final GenesisConfigFile genesis) { - return withNiceErrorMessage("difficulty", genesis.getDifficulty(), UInt256::fromHexString); + private static Difficulty parseDifficulty(final GenesisConfigFile genesis) { + return withNiceErrorMessage("difficulty", genesis.getDifficulty(), Difficulty::fromHexString); } private static Hash parseMixHash(final GenesisConfigFile genesis) { diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java index eb082a3b07..6f8219b771 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java @@ -22,7 +22,6 @@ import java.util.function.Supplier; import com.google.common.base.Suppliers; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; /** A mined Ethereum block header. */ public class BlockHeader extends SealableBlockHeader @@ -48,7 +47,7 @@ public class BlockHeader extends SealableBlockHeader final Hash transactionsRoot, final Hash receiptsRoot, final LogsBloomFilter logsBloom, - final UInt256 difficulty, + final Difficulty difficulty, final long number, final long gasLimit, final long gasUsed, @@ -159,7 +158,7 @@ public class BlockHeader extends SealableBlockHeader Hash.wrap(input.readBytes32()), Hash.wrap(input.readBytes32()), LogsBloomFilter.readFrom(input), - input.readUInt256Scalar(), + Difficulty.of(input.readUInt256Scalar()), input.readLongScalar(), input.readLongScalar(), input.readLongScalar(), @@ -224,7 +223,7 @@ public class BlockHeader extends SealableBlockHeader Hash.fromHexString(pluginBlockHeader.getTransactionsRoot().getHexString()), Hash.fromHexString(pluginBlockHeader.getReceiptsRoot().getHexString()), LogsBloomFilter.fromHexString(pluginBlockHeader.getLogsBloom().getHexString()), - UInt256.fromHexString(pluginBlockHeader.getDifficulty().getHexString()), + Difficulty.fromHexString(pluginBlockHeader.getDifficulty().getHexString()), pluginBlockHeader.getNumber(), pluginBlockHeader.getGasLimit(), pluginBlockHeader.getGasUsed(), diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeaderBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeaderBuilder.java index 7aa4af0ba3..6845c62c89 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeaderBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeaderBuilder.java @@ -22,7 +22,6 @@ import java.time.Instant; import java.util.OptionalLong; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; /** A utility class for building block headers. */ public class BlockHeaderBuilder { @@ -41,7 +40,7 @@ public class BlockHeaderBuilder { private LogsBloomFilter logsBloom; - private UInt256 difficulty; + private Difficulty difficulty; private long number = -1L; @@ -74,7 +73,7 @@ public class BlockHeaderBuilder { .transactionsRoot(header.getTransactionsRoot()) .receiptsRoot(header.getReceiptsRoot()) .logsBloom(header.getLogsBloom()) - .difficulty(header.internalGetDifficulty()) + .difficulty(header.getDifficulty()) .number(header.getNumber()) .gasLimit(header.getGasLimit()) .gasUsed(header.getGasUsed()) @@ -185,7 +184,7 @@ public class BlockHeaderBuilder { checkNotNull(processableBlockHeader); parentHash(processableBlockHeader.getParentHash()); coinbase(processableBlockHeader.getCoinbase()); - difficulty(processableBlockHeader.internalGetDifficulty()); + difficulty(processableBlockHeader.getDifficulty()); number(processableBlockHeader.getNumber()); gasLimit(processableBlockHeader.getGasLimit()); timestamp(processableBlockHeader.getTimestamp()); @@ -201,7 +200,7 @@ public class BlockHeaderBuilder { transactionsRoot(sealableBlockHeader.getTransactionsRoot()); receiptsRoot(sealableBlockHeader.getReceiptsRoot()); logsBloom(sealableBlockHeader.getLogsBloom()); - difficulty(sealableBlockHeader.internalGetDifficulty()); + difficulty(sealableBlockHeader.getDifficulty()); number(sealableBlockHeader.getNumber()); gasLimit(sealableBlockHeader.getGasLimit()); gasUsed(sealableBlockHeader.getGasUsed()); @@ -252,7 +251,7 @@ public class BlockHeaderBuilder { return this; } - public BlockHeaderBuilder difficulty(final UInt256 difficulty) { + public BlockHeaderBuilder difficulty(final Difficulty difficulty) { checkNotNull(difficulty); this.difficulty = difficulty; return this; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Difficulty.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Difficulty.java new file mode 100644 index 0000000000..768ffd26f1 --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Difficulty.java @@ -0,0 +1,94 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.core; + +import org.hyperledger.besu.plugin.data.Quantity; + +import java.math.BigInteger; + +import org.apache.tuweni.bytes.Bytes32; +import org.apache.tuweni.units.bigints.BaseUInt256Value; +import org.apache.tuweni.units.bigints.UInt256; + +/** A particular quantity of difficulty, the block difficulty to create new blocks. */ +public final class Difficulty extends BaseUInt256Value implements Quantity { + + public static final Difficulty ZERO = of(0); + + public static final Difficulty ONE = of(1); + + public static final Difficulty MAX_VALUE = wrap(Bytes32.ZERO.not()); + + protected Difficulty(final UInt256 value) { + super(value, Difficulty::new); + } + + private Difficulty(final long v) { + this(UInt256.valueOf(v)); + } + + private Difficulty(final BigInteger v) { + this(UInt256.valueOf(v)); + } + + private Difficulty(final String hexString) { + this(UInt256.fromHexString(hexString)); + } + + public static Difficulty of(final long value) { + return new Difficulty(value); + } + + public static Difficulty of(final BigInteger value) { + return new Difficulty(value); + } + + public static Difficulty of(final UInt256 value) { + return new Difficulty(value); + } + + public static Difficulty wrap(final Bytes32 value) { + return new Difficulty(UInt256.fromBytes(value)); + } + + public static Difficulty fromHexString(final String str) { + return new Difficulty(str); + } + + @Override + public Number getValue() { + return toBigInteger(); + } + + @Override + public byte[] getByteArray() { + return toBytes().toArray(); + } + + @Override + public String getHexString() { + return toHexString(); + } + + @Override + public int size() { + return toMinimalBytes().size(); + } + + @Override + public Difficulty copy() { + return super.copy(); + } +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/ProcessableBlockHeader.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/ProcessableBlockHeader.java index f3054beb99..fee5a095fa 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/ProcessableBlockHeader.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/ProcessableBlockHeader.java @@ -14,10 +14,6 @@ */ package org.hyperledger.besu.ethereum.core; -import org.hyperledger.besu.plugin.data.Quantity; - -import org.apache.tuweni.units.bigints.UInt256; - /** A block header capable of being processed. */ public class ProcessableBlockHeader { @@ -25,7 +21,7 @@ public class ProcessableBlockHeader { protected final Address coinbase; - protected final UInt256 difficulty; + protected final Difficulty difficulty; protected final long number; @@ -37,7 +33,7 @@ public class ProcessableBlockHeader { protected ProcessableBlockHeader( final Hash parentHash, final Address coinbase, - final UInt256 difficulty, + final Difficulty difficulty, final long number, final long gasLimit, final long timestamp) { @@ -72,11 +68,7 @@ public class ProcessableBlockHeader { * * @return the block difficulty */ - public Quantity getDifficulty() { - return new QuantityWrapper(difficulty); - } - - public UInt256 internalGetDifficulty() { + public Difficulty getDifficulty() { return difficulty; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/QuantityWrapper.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/QuantityWrapper.java deleted file mode 100644 index e5fd60d88e..0000000000 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/QuantityWrapper.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.core; - -import org.hyperledger.besu.plugin.data.Quantity; - -import org.apache.tuweni.units.bigints.UInt256; - -public class QuantityWrapper implements Quantity { - - private final UInt256 value; - - public QuantityWrapper(final UInt256 value) { - this.value = value; - } - - @Override - public Number getValue() { - return value.toBigInteger(); - } - - @Override - public byte[] getByteArray() { - return value.toBytes().toArrayUnsafe(); - } - - @Override - public String getHexString() { - return value.toHexString(); - } - - @Override - public int size() { - return value.toBytes().size(); - } -} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/SealableBlockHeader.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/SealableBlockHeader.java index f313f3dd51..4538597478 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/SealableBlockHeader.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/SealableBlockHeader.java @@ -17,7 +17,6 @@ package org.hyperledger.besu.ethereum.core; import org.hyperledger.besu.plugin.data.UnformattedData; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; /** A block header capable of being sealed. */ public class SealableBlockHeader extends ProcessableBlockHeader { @@ -43,7 +42,7 @@ public class SealableBlockHeader extends ProcessableBlockHeader { final Hash transactionsRoot, final Hash receiptsRoot, final LogsBloomFilter logsBloom, - final UInt256 difficulty, + final Difficulty difficulty, final long number, final long gasLimit, final long gasUsed, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHash.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHash.java index 73c68e2e8f..8a3f36612e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHash.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHash.java @@ -172,7 +172,7 @@ public final class EthHash { out.writeBytes(header.getTransactionsRoot()); out.writeBytes(header.getReceiptsRoot()); out.writeBytes(header.getLogsBloom().getBytes()); - out.writeUInt256Scalar(header.internalGetDifficulty()); + out.writeUInt256Scalar(header.getDifficulty()); out.writeLongScalar(header.getNumber()); out.writeLongScalar(header.getGasLimit()); out.writeLongScalar(header.getGasUsed()); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/CalculatedDifficultyValidationRule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/CalculatedDifficultyValidationRule.java index bfc783a121..e789cbab71 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/CalculatedDifficultyValidationRule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/CalculatedDifficultyValidationRule.java @@ -36,7 +36,7 @@ public class CalculatedDifficultyValidationRule implements AttachedBlockHeade public boolean validate( final BlockHeader header, final BlockHeader parent, final ProtocolContext context) { final BigInteger actualDifficulty = - new BigInteger(1, header.internalGetDifficulty().toBytes().toArray()); + new BigInteger(1, header.getDifficulty().toBytes().toArray()); final BigInteger expectedDifficulty = difficultyCalculator.nextDifficulty(header.getTimestamp(), parent, context); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRule.java index 39bd2a6010..fd4b2619c7 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRule.java @@ -42,11 +42,11 @@ public final class ProofOfWorkValidationRule implements DetachedBlockHeaderValid final Hash headerHash = hashHeader(header); HASHER.hash(hashBuffer, header.getNonce(), header.getNumber(), headerHash.getByteArray()); - if (header.internalGetDifficulty().isZero()) { + if (header.getDifficulty().isZero()) { LOG.trace("Rejecting header because difficulty is 0"); return false; } - final BigInteger difficulty = header.internalGetDifficulty().toBytes().toUnsignedBigInteger(); + final BigInteger difficulty = header.getDifficulty().toBytes().toUnsignedBigInteger(); final UInt256 target = difficulty.equals(BigInteger.ONE) ? UInt256.MAX_VALUE @@ -89,7 +89,7 @@ public final class ProofOfWorkValidationRule implements DetachedBlockHeaderValid out.writeBytes(header.getTransactionsRoot()); out.writeBytes(header.getReceiptsRoot()); out.writeBytes(header.getLogsBloom().getBytes()); - out.writeUInt256Scalar(header.internalGetDifficulty()); + out.writeUInt256Scalar(header.getDifficulty()); out.writeLongScalar(header.getNumber()); out.writeLongScalar(header.getGasLimit()); out.writeLongScalar(header.getGasUsed()); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStoragePrefixedKeyBlockchainStorage.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStoragePrefixedKeyBlockchainStorage.java index 7ce96aa2c2..729557f1b9 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStoragePrefixedKeyBlockchainStorage.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStoragePrefixedKeyBlockchainStorage.java @@ -19,6 +19,7 @@ import org.hyperledger.besu.ethereum.chain.TransactionLocation; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.rlp.RLP; @@ -94,8 +95,8 @@ public class KeyValueStoragePrefixedKeyBlockchainStorage implements BlockchainSt } @Override - public Optional getTotalDifficulty(final Hash blockHash) { - return get(TOTAL_DIFFICULTY_PREFIX, blockHash).map(b -> UInt256.fromBytes(Bytes32.wrap(b, 0))); + public Optional getTotalDifficulty(final Hash blockHash) { + return get(TOTAL_DIFFICULTY_PREFIX, blockHash).map(b -> Difficulty.wrap(Bytes32.wrap(b, 0))); } @Override @@ -157,7 +158,7 @@ public class KeyValueStoragePrefixedKeyBlockchainStorage implements BlockchainSt } @Override - public void putTotalDifficulty(final Hash blockHash, final UInt256 totalDifficulty) { + public void putTotalDifficulty(final Hash blockHash, final Difficulty totalDifficulty) { set(TOTAL_DIFFICULTY_PREFIX, blockHash, totalDifficulty.toBytes()); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/DifficultyOperation.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/DifficultyOperation.java index c59afb65dd..2d64e261de 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/DifficultyOperation.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/DifficultyOperation.java @@ -14,13 +14,12 @@ */ package org.hyperledger.besu.ethereum.vm.operations; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Gas; import org.hyperledger.besu.ethereum.vm.AbstractOperation; import org.hyperledger.besu.ethereum.vm.GasCalculator; import org.hyperledger.besu.ethereum.vm.MessageFrame; -import org.apache.tuweni.units.bigints.UInt256; - public class DifficultyOperation extends AbstractOperation { public DifficultyOperation(final GasCalculator gasCalculator) { @@ -34,7 +33,7 @@ public class DifficultyOperation extends AbstractOperation { @Override public void execute(final MessageFrame frame) { - final UInt256 difficulty = frame.getBlockHeader().internalGetDifficulty(); + final Difficulty difficulty = frame.getBlockHeader().getDifficulty(); frame.pushStackItem(difficulty.toBytes()); } } diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockDataGenerator.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockDataGenerator.java index 26b05e4cb6..be121c98c3 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockDataGenerator.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockDataGenerator.java @@ -260,7 +260,7 @@ public class BlockDataGenerator { .transactionsRoot(hash()) .receiptsRoot(hash()) .logsBloom(logsBloom()) - .difficulty(options.getDifficulty(uint256(4))) + .difficulty(options.getDifficulty(Difficulty.of(uint256(4)))) .number(number) .gasLimit(gasLimit) .gasUsed(gasUsed) @@ -486,7 +486,7 @@ public class BlockDataGenerator { private OptionalLong blockNumber = OptionalLong.empty(); private Optional parentHash = Optional.empty(); private Optional stateRoot = Optional.empty(); - private Optional difficulty = Optional.empty(); + private Optional difficulty = Optional.empty(); private List transactions = new ArrayList<>(); private Optional extraData = Optional.empty(); private Optional blockHeaderFunctions = Optional.empty(); @@ -511,7 +511,7 @@ public class BlockDataGenerator { return stateRoot.orElse(defaultValue); } - public UInt256 getDifficulty(final UInt256 defaultValue) { + public Difficulty getDifficulty(final Difficulty defaultValue) { return difficulty.orElse(defaultValue); } @@ -547,7 +547,7 @@ public class BlockDataGenerator { return this; } - public BlockOptions setDifficulty(final UInt256 difficulty) { + public BlockOptions setDifficulty(final Difficulty difficulty) { this.difficulty = Optional.of(difficulty); return this; } diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockHeaderTestFixture.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockHeaderTestFixture.java index 1bdadf2382..7e09cf1274 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockHeaderTestFixture.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockHeaderTestFixture.java @@ -17,7 +17,6 @@ package org.hyperledger.besu.ethereum.core; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; public class BlockHeaderTestFixture { @@ -30,7 +29,7 @@ public class BlockHeaderTestFixture { private Hash receiptsRoot = Hash.EMPTY_TRIE_HASH; private LogsBloomFilter logsBloom = LogsBloomFilter.empty(); - private UInt256 difficulty = UInt256.ZERO; + private Difficulty difficulty = Difficulty.ZERO; private long number = 0; private long gasLimit = 0; @@ -99,7 +98,7 @@ public class BlockHeaderTestFixture { return this; } - public BlockHeaderTestFixture difficulty(final UInt256 difficulty) { + public BlockHeaderTestFixture difficulty(final Difficulty difficulty) { this.difficulty = difficulty; return this; } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchainTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchainTest.java index 19540ec752..4291fc12eb 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchainTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchainTest.java @@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.LogWithMetadata; import org.hyperledger.besu.ethereum.core.Transaction; @@ -39,7 +40,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import com.google.common.collect.Lists; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Test; public class DefaultBlockchainTest { @@ -265,7 +265,7 @@ public class DefaultBlockchainTest { new BlockDataGenerator.BlockOptions() .setParentHash(chain.get(commonAncestor).getHash()) .setBlockNumber(forkBlock) - .setDifficulty(chain.get(forkBlock).getHeader().internalGetDifficulty().add(10L)); + .setDifficulty(chain.get(forkBlock).getHeader().getDifficulty().add(10L)); final Block fork = gen.block(options); final List forkReceipts = gen.receipts(fork); final List reorgedChain = new ArrayList<>(chain.subList(0, forkBlock)); @@ -341,15 +341,15 @@ public class DefaultBlockchainTest { new BlockDataGenerator.BlockOptions() .setParentHash(chain.get(commonAncestor).getHash()) .setBlockNumber(forkStart) - .setDifficulty(chain.get(forkStart).getHeader().internalGetDifficulty().subtract(5L)); + .setDifficulty(chain.get(forkStart).getHeader().getDifficulty().subtract(5L)); forkBlocks.add(gen.block(options)); // Generate second block - final UInt256 remainingDifficultyToOutpace = + final Difficulty remainingDifficultyToOutpace = chain .get(forkStart + 1) .getHeader() - .internalGetDifficulty() - .add(chain.get(forkStart + 2).getHeader().internalGetDifficulty()); + .getDifficulty() + .add(chain.get(forkStart + 2).getHeader().getDifficulty()); options = new BlockDataGenerator.BlockOptions() .setParentHash(forkBlocks.get(0).getHash()) @@ -461,14 +461,14 @@ public class DefaultBlockchainTest { new BlockDataGenerator.BlockOptions() .setParentHash(chain.get(commonAncestor).getHash()) .setBlockNumber(forkStart) - .setDifficulty(chain.get(forkStart).getHeader().internalGetDifficulty().subtract(5L)); + .setDifficulty(chain.get(forkStart).getHeader().getDifficulty().subtract(5L)); forkBlocks.add(gen.block(options)); // Generate second block options = new BlockDataGenerator.BlockOptions() .setParentHash(forkBlocks.get(0).getHash()) .setBlockNumber(forkStart + 1) - .setDifficulty(UInt256.valueOf(10L)); + .setDifficulty(Difficulty.of(10L)); forkBlocks.add(gen.block(options)); // Generate corresponding receipts final List> forkReceipts = @@ -570,7 +570,7 @@ public class DefaultBlockchainTest { new BlockDataGenerator.BlockOptions() .setParentHash(chain.get(commonAncestor).getHash()) .setBlockNumber(forkBlock) - .setDifficulty(chain.get(forkBlock).getHeader().internalGetDifficulty().add(10L)) + .setDifficulty(chain.get(forkBlock).getHeader().getDifficulty().add(10L)) .addTransaction(overlappingTx) .addTransaction(gen.transaction()); final Block fork = gen.block(options); @@ -683,15 +683,14 @@ public class DefaultBlockchainTest { new BlockDataGenerator.BlockOptions() .setParentHash(chain.get(commonAncestor).getHash()) .setBlockNumber(forkStart) - .setDifficulty(chain.get(forkStart).getHeader().internalGetDifficulty().subtract(5L)); + .setDifficulty(chain.get(forkStart).getHeader().getDifficulty().subtract(5L)); forkBlocks.add(gen.block(options)); // Generate second block options = new BlockDataGenerator.BlockOptions() .setParentHash(forkBlocks.get(0).getHash()) .setBlockNumber(forkStart + 1) - .setDifficulty( - chain.get(forkStart + 1).getHeader().internalGetDifficulty().subtract(5L)); + .setDifficulty(chain.get(forkStart + 1).getHeader().getDifficulty().subtract(5L)); forkBlocks.add(gen.block(options)); // Generate corresponding receipts final List> forkReceipts = @@ -725,7 +724,7 @@ public class DefaultBlockchainTest { new BlockDataGenerator.BlockOptions() .setParentHash(chain.get(commonAncestor).getHash()) .setBlockNumber(forkStart) - .setDifficulty(chain.get(forkStart).getHeader().internalGetDifficulty().subtract(5L)); + .setDifficulty(chain.get(forkStart).getHeader().getDifficulty().subtract(5L)); final Block secondFork = gen.block(options); blockchain.appendBlock(secondFork, gen.receipts(secondFork)); @@ -895,11 +894,11 @@ public class DefaultBlockchainTest { private void assertTotalDifficultiesAreConsistent(final Blockchain blockchain, final Block head) { // Check that total difficulties are summed correctly long num = BlockHeader.GENESIS_BLOCK_NUMBER; - UInt256 td = UInt256.ZERO; + Difficulty td = Difficulty.ZERO; while (num <= head.getHeader().getNumber()) { final Hash curHash = blockchain.getBlockHashByNumber(num).get(); final BlockHeader curHead = blockchain.getBlockHeader(curHash).get(); - td = td.add(curHead.internalGetDifficulty()); + td = td.add(curHead.getDifficulty()); assertThat(blockchain.getTotalDifficultyByHash(curHash).get()).isEqualTo(td); num += 1; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/BlockHeaderMock.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/BlockHeaderMock.java index b7025b36f8..0e911b7e02 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/BlockHeaderMock.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/BlockHeaderMock.java @@ -21,7 +21,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; /** A memory mock for testing. */ @JsonIgnoreProperties("previousHash") @@ -49,7 +48,7 @@ public class BlockHeaderMock extends BlockHeader { Hash.EMPTY, // transactionsRoot Hash.EMPTY, // receiptsRoot new LogsBloomFilter(), - UInt256.fromHexString(difficulty), + Difficulty.fromHexString(difficulty), Long.decode(number), Long.decode(gasLimit), 0L, diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java index b50231d21b..03efaeff16 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.config.JsonUtil; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.LogsBloomFilter; @@ -140,7 +141,7 @@ public class DifficultyCalculatorTests { .nonce(0) .blockHeaderFunctions(blockHeaderFunctions) .timestamp(extractLong(value, "parentTimestamp")) - .difficulty(UInt256.fromHexString(value.get("parentDifficulty").asText())) + .difficulty(Difficulty.fromHexString(value.get("parentDifficulty").asText())) .ommersHash(Hash.fromHexString(value.get("parentUncles").asText())) .number(currentBlockNumber) .buildBlockHeader(); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ConstantFieldValidationRuleTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ConstantFieldValidationRuleTest.java index 9f487bb52b..307a1c8779 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ConstantFieldValidationRuleTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ConstantFieldValidationRuleTest.java @@ -18,9 +18,9 @@ import static org.assertj.core.api.Assertions.assertThat; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Test; public class ConstantFieldValidationRuleTest { @@ -45,17 +45,16 @@ public class ConstantFieldValidationRuleTest { @Test public void difficultyFieldIsValidatedCorrectly() { - final ConstantFieldValidationRule uut = - new ConstantFieldValidationRule<>( - "Difficulty", BlockHeader::internalGetDifficulty, UInt256.ONE); + final ConstantFieldValidationRule uut = + new ConstantFieldValidationRule<>("Difficulty", BlockHeader::getDifficulty, Difficulty.ONE); final BlockHeaderTestFixture blockHeaderBuilder = new BlockHeaderTestFixture(); - blockHeaderBuilder.difficulty(UInt256.ONE); + blockHeaderBuilder.difficulty(Difficulty.ONE); BlockHeader header = blockHeaderBuilder.buildHeader(); assertThat(uut.validate(header, null)).isTrue(); - blockHeaderBuilder.difficulty(UInt256.ZERO); + blockHeaderBuilder.difficulty(Difficulty.ZERO); header = blockHeaderBuilder.buildHeader(); assertThat(uut.validate(header, null)).isFalse(); } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java index d2b7284971..0d780595ce 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java @@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -73,7 +74,7 @@ public class ProofOfWorkValidationRuleTest { public void failsBlockWithZeroValuedDifficulty() { final BlockHeader header = BlockHeaderBuilder.fromHeader(blockHeader) - .difficulty(UInt256.ZERO) + .difficulty(Difficulty.ZERO) .blockHeaderFunctions(mainnetBlockHashFunction()) .buildBlockHeader(); assertThat(validationRule.validate(header, parentHeader)).isFalse(); @@ -83,7 +84,7 @@ public class ProofOfWorkValidationRuleTest { public void passesBlockWithOneValuedDifficulty() { final BlockHeaderBuilder headerBuilder = BlockHeaderBuilder.fromHeader(blockHeader) - .difficulty(UInt256.ONE) + .difficulty(Difficulty.ONE) .blockHeaderFunctions(mainnetBlockHashFunction()) .timestamp(1); final BlockHeader preHeader = headerBuilder.buildBlockHeader(); @@ -102,7 +103,7 @@ public class ProofOfWorkValidationRuleTest { @Test public void failsWithVeryLargeDifficulty() { - final UInt256 largeDifficulty = UInt256.valueOf(BigInteger.valueOf(2).pow(255)); + final Difficulty largeDifficulty = Difficulty.of(BigInteger.valueOf(2).pow(255)); final BlockHeader header = BlockHeaderBuilder.fromHeader(blockHeader) .difficulty(largeDifficulty) diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/BlockchainUtilParameterizedTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/BlockchainUtilParameterizedTest.java index 108b7331ed..35f95f48b7 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/BlockchainUtilParameterizedTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/BlockchainUtilParameterizedTest.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.InMemoryStorageProvider; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -31,7 +32,6 @@ import java.util.List; import java.util.OptionalInt; import java.util.Random; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -97,7 +97,7 @@ public class BlockchainUtilParameterizedTest { final BlockDataGenerator.BlockOptions remoteOptions = new BlockDataGenerator.BlockOptions() - .setDifficulty(UInt256.ONE) // differentiator + .setDifficulty(Difficulty.ONE) // differentiator .setBlockNumber(i) .setParentHash(remoteBlockchain.getBlockHashByNumber(i - 1).get()); final Block remoteBlock = blockDataGenerator.block(remoteOptions); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/BlockchainReferenceTestCaseSpec.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/BlockchainReferenceTestCaseSpec.java index fe0ad66162..abcc45a31a 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/BlockchainReferenceTestCaseSpec.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/BlockchainReferenceTestCaseSpec.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.InMemoryStorageProvider; import org.hyperledger.besu.ethereum.core.LogsBloomFilter; @@ -41,7 +42,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; @JsonIgnoreProperties({"_info", "postState", "postStateHash"}) public class BlockchainReferenceTestCaseSpec { @@ -163,7 +163,7 @@ public class BlockchainReferenceTestCaseSpec { Hash.fromHexString(transactionsTrie), // transactionsRoot Hash.fromHexString(receiptTrie), // receiptTrie LogsBloomFilter.fromHexString(bloom), // bloom - UInt256.fromHexString(difficulty), // difficulty + Difficulty.fromHexString(difficulty), // difficulty Long.decode(number), // number Long.decode(gasLimit), // gasLimit Long.decode(gasUsed), // gasUsed diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/TestBlockchain.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/TestBlockchain.java index 20ad049232..4e9991549c 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/TestBlockchain.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/TestBlockchain.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.ethereum.chain.TransactionLocation; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -33,7 +34,6 @@ import java.util.Map; import java.util.Optional; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; /** * A blockchain mock for the Ethereum reference tests. @@ -128,7 +128,7 @@ public class TestBlockchain implements Blockchain { } @Override - public Optional getTotalDifficultyByHash(final Hash blockHeaderHash) { + public Optional getTotalDifficultyByHash(final Hash blockHeaderHash) { // Deterministic, but just not implemented. throw new UnsupportedOperationException(); } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ChainHeadEstimate.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ChainHeadEstimate.java index 95aabb772f..7e92c1c0a5 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ChainHeadEstimate.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ChainHeadEstimate.java @@ -16,12 +16,11 @@ package org.hyperledger.besu.ethereum.eth.manager; import org.hyperledger.besu.ethereum.chain.ChainHead; - -import org.apache.tuweni.units.bigints.UInt256; +import org.hyperledger.besu.ethereum.core.Difficulty; public interface ChainHeadEstimate { - UInt256 getEstimatedTotalDifficulty(); + Difficulty getEstimatedTotalDifficulty(); long getEstimatedHeight(); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ChainState.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ChainState.java index 53c1ca0bad..98733ba6b0 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ChainState.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ChainState.java @@ -15,11 +15,11 @@ package org.hyperledger.besu.ethereum.eth.manager; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.util.Subscribers; import com.google.common.base.MoreObjects; -import org.apache.tuweni.units.bigints.UInt256; public class ChainState implements ChainHeadEstimate { // The best block by total difficulty that we know about @@ -53,7 +53,7 @@ public class ChainState implements ChainHeadEstimate { } @Override - public UInt256 getEstimatedTotalDifficulty() { + public Difficulty getEstimatedTotalDifficulty() { return bestBlock.getTotalDifficulty(); } @@ -61,7 +61,7 @@ public class ChainState implements ChainHeadEstimate { return bestBlock; } - public void statusReceived(final Hash bestBlockHash, final UInt256 bestBlockTotalDifficulty) { + public void statusReceived(final Hash bestBlockHash, final Difficulty bestBlockTotalDifficulty) { synchronized (this) { bestBlock.totalDifficulty = bestBlockTotalDifficulty; bestBlock.hash = bestBlockHash; @@ -87,11 +87,11 @@ public class ChainState implements ChainHeadEstimate { } public void updateForAnnouncedBlock( - final BlockHeader blockHeader, final UInt256 totalDifficulty) { + final BlockHeader blockHeader, final Difficulty totalDifficulty) { synchronized (this) { // Blocks are announced before they're imported so their chain head must be the parent - final UInt256 parentTotalDifficulty = - totalDifficulty.subtract(blockHeader.internalGetDifficulty()); + final Difficulty parentTotalDifficulty = + totalDifficulty.subtract(blockHeader.getDifficulty()); final long parentBlockNumber = blockHeader.getNumber() - 1; if (parentTotalDifficulty.compareTo(bestBlock.totalDifficulty) >= 0) { bestBlock.totalDifficulty = parentTotalDifficulty; @@ -124,7 +124,7 @@ public class ChainState implements ChainHeadEstimate { public static class BestBlock { volatile long number = 0L; volatile Hash hash = null; - volatile UInt256 totalDifficulty = UInt256.ZERO; + volatile Difficulty totalDifficulty = Difficulty.ZERO; public long getNumber() { return number; @@ -134,7 +134,7 @@ public class ChainState implements ChainHeadEstimate { return hash; } - public UInt256 getTotalDifficulty() { + public Difficulty getTotalDifficulty() { return totalDifficulty; } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ChainStateSnapshot.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ChainStateSnapshot.java index 89ae26871d..fa7baa7c0a 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ChainStateSnapshot.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ChainStateSnapshot.java @@ -15,19 +15,19 @@ package org.hyperledger.besu.ethereum.eth.manager; -import org.apache.tuweni.units.bigints.UInt256; +import org.hyperledger.besu.ethereum.core.Difficulty; public class ChainStateSnapshot implements ChainHeadEstimate { - private final UInt256 totalDifficulty; + private final Difficulty totalDifficulty; private final long chainHeight; - public ChainStateSnapshot(final UInt256 totalDifficulty, final long chainHeight) { + public ChainStateSnapshot(final Difficulty totalDifficulty, final long chainHeight) { this.totalDifficulty = totalDifficulty; this.chainHeight = chainHeight; } @Override - public UInt256 getEstimatedTotalDifficulty() { + public Difficulty getEstimatedTotalDifficulty() { return totalDifficulty; } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeer.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeer.java index da501df2e7..5bf484e017 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeer.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeer.java @@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.eth.manager; import static com.google.common.base.Preconditions.checkArgument; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.eth.messages.EthPV62; import org.hyperledger.besu.ethereum.eth.messages.EthPV63; @@ -44,7 +45,6 @@ import java.util.function.Consumer; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; public class EthPeer { private static final Logger LOG = LogManager.getLogger(); @@ -283,7 +283,7 @@ public class EthPeer { maybeExecuteStatusesExchangedCallback(); } - public void registerStatusReceived(final Hash hash, final UInt256 td) { + public void registerStatusReceived(final Hash hash, final Difficulty td) { chainHeadState.statusReceived(hash, td); statusHasBeenReceivedFromPeer.set(true); maybeExecuteStatusesExchangedCallback(); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java index 8b93949154..6b024e4c5d 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java @@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkArgument; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; import org.hyperledger.besu.ethereum.core.Block; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.eth.EthProtocol; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; @@ -48,7 +49,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.tuweni.units.bigints.UInt256; public class EthProtocolManager implements ProtocolManager, MinedBlockObserver { private static final Logger LOG = LogManager.getLogger(); @@ -305,7 +305,7 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver { @Override public void blockMined(final Block block) { // This assumes the block has already been included in the chain - final UInt256 totalDifficulty = + final Difficulty totalDifficulty = blockchain .getTotalDifficultyByHash(block.getHash()) .orElseThrow( diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/NewBlockMessage.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/NewBlockMessage.java index ad471490b6..c2a70a7587 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/NewBlockMessage.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/NewBlockMessage.java @@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.eth.messages; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.AbstractMessageData; @@ -43,7 +44,7 @@ public class NewBlockMessage extends AbstractMessageData { return MESSAGE_CODE; } - public static NewBlockMessage create(final Block block, final UInt256 totalDifficulty) { + public static NewBlockMessage create(final Block block, final Difficulty totalDifficulty) { final NewBlockMessageData msgData = new NewBlockMessageData(block, totalDifficulty); final BytesValueRLPOutput out = new BytesValueRLPOutput(); msgData.writeTo(out); @@ -66,7 +67,7 @@ public class NewBlockMessage extends AbstractMessageData { return messageFields(protocolSchedule).block(); } - public UInt256 totalDifficulty(final ProtocolSchedule protocolSchedule) { + public Difficulty totalDifficulty(final ProtocolSchedule protocolSchedule) { return messageFields(protocolSchedule).totalDifficulty(); } @@ -81,9 +82,9 @@ public class NewBlockMessage extends AbstractMessageData { public static class NewBlockMessageData { private final Block block; - private final UInt256 totalDifficulty; + private final Difficulty totalDifficulty; - public NewBlockMessageData(final Block block, final UInt256 totalDifficulty) { + public NewBlockMessageData(final Block block, final Difficulty totalDifficulty) { this.block = block; this.totalDifficulty = totalDifficulty; } @@ -92,7 +93,7 @@ public class NewBlockMessage extends AbstractMessageData { return block; } - public UInt256 totalDifficulty() { + public Difficulty totalDifficulty() { return totalDifficulty; } @@ -110,7 +111,7 @@ public class NewBlockMessage extends AbstractMessageData { in.enterList(); final Block block = Block.readFrom(in, blockHeaderFunctions); final UInt256 totaldifficulty = in.readUInt256Scalar(); - return new NewBlockMessageData(block, totaldifficulty); + return new NewBlockMessageData(block, Difficulty.of(totaldifficulty)); } } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/StatusMessage.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/StatusMessage.java index 84d3b17ab7..306a28e415 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/StatusMessage.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/StatusMessage.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.eth.messages; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.AbstractMessageData; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; @@ -26,7 +27,6 @@ import java.math.BigInteger; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; public final class StatusMessage extends AbstractMessageData { @@ -39,7 +39,7 @@ public final class StatusMessage extends AbstractMessageData { public static StatusMessage create( final int protocolVersion, final BigInteger networkId, - final UInt256 totalDifficulty, + final Difficulty totalDifficulty, final Hash bestHash, final Hash genesisHash) { final EthStatus status = @@ -78,7 +78,7 @@ public final class StatusMessage extends AbstractMessageData { } /** @return The total difficulty of the head of the associated node's local blockchain. */ - public UInt256 totalDifficulty() { + public Difficulty totalDifficulty() { return status().totalDifficulty; } @@ -105,14 +105,14 @@ public final class StatusMessage extends AbstractMessageData { private static class EthStatus { private final int protocolVersion; private final BigInteger networkId; - private final UInt256 totalDifficulty; + private final Difficulty totalDifficulty; private final Hash bestHash; private final Hash genesisHash; EthStatus( final int protocolVersion, final BigInteger networkId, - final UInt256 totalDifficulty, + final Difficulty totalDifficulty, final Hash bestHash, final Hash genesisHash) { this.protocolVersion = protocolVersion; @@ -139,7 +139,7 @@ public final class StatusMessage extends AbstractMessageData { final int protocolVersion = in.readIntScalar(); final BigInteger networkId = in.readBigIntegerScalar(); - final UInt256 totalDifficulty = in.readUInt256Scalar(); + final Difficulty totalDifficulty = Difficulty.of(in.readUInt256Scalar()); final Hash bestHash = Hash.wrap(in.readBytes32()); final Hash genesisHash = Hash.wrap(in.readBytes32()); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockBroadcaster.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockBroadcaster.java index 6fe4e396ac..75b96ed7ea 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockBroadcaster.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockBroadcaster.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.eth.sync; import org.hyperledger.besu.ethereum.core.Block; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.messages.NewBlockMessage; import org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection; @@ -22,7 +23,6 @@ import org.hyperledger.besu.util.Subscribers; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.tuweni.units.bigints.UInt256; public class BlockBroadcaster { private static final Logger LOG = LogManager.getLogger(); @@ -43,7 +43,7 @@ public class BlockBroadcaster { blockPropagatedSubscribers.unsubscribe(id); } - public void propagate(final Block block, final UInt256 totalDifficulty) { + public void propagate(final Block block, final Difficulty totalDifficulty) { blockPropagatedSubscribers.forEach(listener -> listener.accept(block, totalDifficulty)); final NewBlockMessage newBlockMessage = NewBlockMessage.create(block, totalDifficulty); ethContext @@ -63,6 +63,6 @@ public class BlockBroadcaster { @FunctionalInterface public interface BlockPropagatedSubscriber { - void accept(Block block, UInt256 totalDifficulty); + void accept(Block block, Difficulty totalDifficulty); } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManager.java index 2810c3616f..de6801456d 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManager.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.ethereum.chain.BlockAddedEvent.EventType; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthMessage; @@ -56,7 +57,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Range; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.tuweni.units.bigints.UInt256; public class BlockPropagationManager { private static final Logger LOG = LogManager.getLogger(); @@ -155,7 +155,7 @@ public class BlockPropagationManager { final NewBlockMessage newBlockMessage = NewBlockMessage.readFrom(message.getData()); try { final Block block = newBlockMessage.block(protocolSchedule); - final UInt256 totalDifficulty = newBlockMessage.totalDifficulty(protocolSchedule); + final Difficulty totalDifficulty = newBlockMessage.totalDifficulty(protocolSchedule); message.getPeer().chainState().updateForAnnouncedBlock(block.getHeader(), totalDifficulty); @@ -249,12 +249,12 @@ public class BlockPropagationManager { } private void broadcastBlock(final Block block, final BlockHeader parent) { - final UInt256 totalDifficulty = + final Difficulty totalDifficulty = protocolContext .getBlockchain() .getTotalDifficultyByHash(parent.getHash()) .get() - .add(block.getHeader().internalGetDifficulty()); + .add(block.getHeader().getDifficulty()); blockBroadcaster.propagate(block, totalDifficulty); } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/BetterSyncTargetEvaluator.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/BetterSyncTargetEvaluator.java index ea380bf52d..d7c8f6e933 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/BetterSyncTargetEvaluator.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/BetterSyncTargetEvaluator.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.eth.sync.fullsync; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.eth.manager.ChainState; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; @@ -21,8 +22,6 @@ import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import java.util.Optional; -import org.apache.tuweni.units.bigints.UInt256; - public class BetterSyncTargetEvaluator { private final SynchronizerConfiguration config; @@ -48,7 +47,7 @@ public class BetterSyncTargetEvaluator { // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); - final UInt256 tdDifference = + final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ChainStateTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ChainStateTest.java index d7c536aab3..b8113ea523 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ChainStateTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ChainStateTest.java @@ -23,14 +23,14 @@ import org.hyperledger.besu.ethereum.chain.ChainHead; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Test; public class ChainStateTest { - private static final UInt256 INITIAL_TOTAL_DIFFICULTY = UInt256.valueOf(256); + private static final Difficulty INITIAL_TOTAL_DIFFICULTY = Difficulty.of(256); private final ChainState chainState = new ChainState(); @Test @@ -184,7 +184,7 @@ public class ChainStateTest { assertThat(chainState.getBestBlock().getNumber()).isEqualTo(0L); final long betterBlockNumber = blockNumber + 2; - final UInt256 betterTd = INITIAL_TOTAL_DIFFICULTY.add(100L); + final Difficulty betterTd = INITIAL_TOTAL_DIFFICULTY.add(100L); final BlockHeader betterBlock = new BlockHeaderTestFixture().number(betterBlockNumber).buildHeader(); chainState.updateForAnnouncedBlock(betterBlock, betterTd); @@ -205,7 +205,7 @@ public class ChainStateTest { assertThat(chainState.getBestBlock().getNumber()).isEqualTo(0L); final long otherBlockNumber = blockNumber + 2; - final UInt256 otherTd = INITIAL_TOTAL_DIFFICULTY.subtract(100L); + final Difficulty otherTd = INITIAL_TOTAL_DIFFICULTY.subtract(100L); final BlockHeader otherBlock = new BlockHeaderTestFixture().number(otherBlockNumber).buildHeader(); chainState.updateForAnnouncedBlock(otherBlock, otherTd); @@ -228,7 +228,7 @@ public class ChainStateTest { chainState.updateForAnnouncedBlock(bestBlockHeader, INITIAL_TOTAL_DIFFICULTY); final long otherBlockNumber = blockNumber - 2; - final UInt256 otherTd = INITIAL_TOTAL_DIFFICULTY.subtract(100L); + final Difficulty otherTd = INITIAL_TOTAL_DIFFICULTY.subtract(100L); final BlockHeader otherBlock = new BlockHeaderTestFixture().number(otherBlockNumber).buildHeader(); chainState.updateForAnnouncedBlock(otherBlock, otherTd); @@ -241,7 +241,7 @@ public class ChainStateTest { @Test public void shouldOnlyHaveHeightEstimateWhenHeightHasBeenSet() { - chainState.statusReceived(Hash.EMPTY_LIST_HASH, UInt256.ONE); + chainState.statusReceived(Hash.EMPTY_LIST_HASH, Difficulty.ONE); assertThat(chainState.hasEstimatedHeight()).isFalse(); chainState.update(new BlockHeaderTestFixture().number(12).buildHeader()); @@ -311,8 +311,8 @@ public class ChainStateTest { @Test public void chainIsBetterThan_chainStateIsLighterAndShorter() { final ChainState chainState = new ChainState(); - updateChainState(chainState, UInt256.valueOf(50), 50); - final ChainHead chainHead = new ChainHead(Hash.ZERO, UInt256.valueOf(100), 100); + updateChainState(chainState, Difficulty.of(50), 50); + final ChainHead chainHead = new ChainHead(Hash.ZERO, Difficulty.of(100), 100); assertThat(chainState.chainIsBetterThan(chainHead)).isFalse(); } @@ -320,8 +320,8 @@ public class ChainStateTest { @Test public void chainIsBetterThan_chainStateIsHeavierAndShorter() { final ChainState chainState = new ChainState(); - updateChainState(chainState, UInt256.valueOf(100), 50); - final ChainHead chainHead = new ChainHead(Hash.ZERO, UInt256.valueOf(50), 100); + updateChainState(chainState, Difficulty.of(100), 50); + final ChainHead chainHead = new ChainHead(Hash.ZERO, Difficulty.of(50), 100); assertThat(chainState.chainIsBetterThan(chainHead)).isTrue(); } @@ -329,8 +329,8 @@ public class ChainStateTest { @Test public void chainIsBetterThan_chainStateIsLighterAndTaller() { final ChainState chainState = new ChainState(); - updateChainState(chainState, UInt256.valueOf(50), 100); - final ChainHead chainHead = new ChainHead(Hash.ZERO, UInt256.valueOf(100), 50); + updateChainState(chainState, Difficulty.of(50), 100); + final ChainHead chainHead = new ChainHead(Hash.ZERO, Difficulty.of(100), 50); assertThat(chainState.chainIsBetterThan(chainHead)).isTrue(); } @@ -338,8 +338,8 @@ public class ChainStateTest { @Test public void chainIsBetterThan_chainStateIsHeavierAndTaller() { final ChainState chainState = new ChainState(); - updateChainState(chainState, UInt256.valueOf(100), 100); - final ChainHead chainHead = new ChainHead(Hash.ZERO, UInt256.valueOf(50), 50); + updateChainState(chainState, Difficulty.of(100), 100); + final ChainHead chainHead = new ChainHead(Hash.ZERO, Difficulty.of(50), 50); assertThat(chainState.chainIsBetterThan(chainHead)).isTrue(); } @@ -353,14 +353,14 @@ public class ChainStateTest { * @param blockHeight The target estimated block height */ private void updateChainState( - final ChainState chainState, final UInt256 totalDifficulty, final long blockHeight) { + final ChainState chainState, final Difficulty totalDifficulty, final long blockHeight) { // Chain state is updated based on the parent of the announced block // So, increment block number by 1 and set block difficulty to zero // in order to update to the values we want final BlockHeader header = new BlockHeaderTestFixture() .number(blockHeight + 1L) - .difficulty(UInt256.ZERO) + .difficulty(Difficulty.ZERO) .buildHeader(); chainState.updateForAnnouncedBlock(header, totalDifficulty); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthPeersTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthPeersTest.java index 018dd9f669..d200a3129d 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthPeersTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthPeersTest.java @@ -24,6 +24,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.eth.manager.exceptions.NoAvailablePeersException; import org.hyperledger.besu.ethereum.eth.manager.exceptions.PeerDisconnectedException; @@ -36,7 +37,6 @@ import java.util.OptionalLong; import java.util.concurrent.CancellationException; import java.util.function.Consumer; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.Test; @@ -59,10 +59,10 @@ public class EthPeersTest { public void comparesPeersWithHeightAndTd() { // Set peerA with better height, lower td final EthPeer peerA = - EthProtocolManagerTestUtil.createPeer(ethProtocolManager, UInt256.valueOf(50), 20) + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, Difficulty.of(50), 20) .getEthPeer(); final EthPeer peerB = - EthProtocolManagerTestUtil.createPeer(ethProtocolManager, UInt256.valueOf(100), 10) + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, Difficulty.of(100), 10) .getEthPeer(); assertThat(EthPeers.CHAIN_HEIGHT.compare(peerA, peerB)).isGreaterThan(0); @@ -82,11 +82,11 @@ public class EthPeersTest { public void comparesPeersWithTdAndNoHeight() { final EthPeer peerA = EthProtocolManagerTestUtil.createPeer( - ethProtocolManager, UInt256.valueOf(100), OptionalLong.empty()) + ethProtocolManager, Difficulty.of(100), OptionalLong.empty()) .getEthPeer(); final EthPeer peerB = EthProtocolManagerTestUtil.createPeer( - ethProtocolManager, UInt256.valueOf(50), OptionalLong.empty()) + ethProtocolManager, Difficulty.of(50), OptionalLong.empty()) .getEthPeer(); // Sanity check diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java index a2802696aa..bc8749344f 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java @@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -82,7 +83,6 @@ import java.util.stream.Collectors; import com.google.common.collect.Lists; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; import org.awaitility.Awaitility; import org.awaitility.core.ConditionTimeoutException; import org.junit.BeforeClass; @@ -968,7 +968,7 @@ public final class EthProtocolManagerTest { blockchain.getBlockHeader(chainHeadHash).get(), blockchain.getBlockBody(chainHeadHash).get()); - final UInt256 expectedTotalDifficulty = blockchain.getChainHead().getTotalDifficulty(); + final Difficulty expectedTotalDifficulty = blockchain.getChainHead().getTotalDifficulty(); reset(onSend); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestUtil.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestUtil.java index 68c285f7ee..29f31d1d01 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestUtil.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestUtil.java @@ -22,6 +22,7 @@ import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.ChainHead; import org.hyperledger.besu.ethereum.chain.GenesisState; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.eth.EthProtocol; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.DeterministicEthScheduler.TimeoutPolicy; @@ -38,8 +39,6 @@ import java.math.BigInteger; import java.util.Collections; import java.util.OptionalLong; -import org.apache.tuweni.units.bigints.UInt256; - public class EthProtocolManagerTestUtil { public static EthProtocolManager create( @@ -157,7 +156,7 @@ public class EthProtocolManagerTestUtil { } public static RespondingEthPeer createPeer( - final EthProtocolManager ethProtocolManager, final UInt256 td) { + final EthProtocolManager ethProtocolManager, final Difficulty td) { return RespondingEthPeer.builder() .ethProtocolManager(ethProtocolManager) .totalDifficulty(td) @@ -165,7 +164,9 @@ public class EthProtocolManagerTestUtil { } public static RespondingEthPeer createPeer( - final EthProtocolManager ethProtocolManager, final UInt256 td, final long estimatedHeight) { + final EthProtocolManager ethProtocolManager, + final Difficulty td, + final long estimatedHeight) { return RespondingEthPeer.builder() .ethProtocolManager(ethProtocolManager) .totalDifficulty(td) @@ -175,7 +176,7 @@ public class EthProtocolManagerTestUtil { public static RespondingEthPeer createPeer( final EthProtocolManager ethProtocolManager, - final UInt256 td, + final Difficulty td, final OptionalLong estimatedHeight) { return RespondingEthPeer.builder() .ethProtocolManager(ethProtocolManager) @@ -186,7 +187,7 @@ public class EthProtocolManagerTestUtil { public static RespondingEthPeer createPeer( final EthProtocolManager ethProtocolManager, - final UInt256 td, + final Difficulty td, final OptionalLong estimatedHeight, final PeerValidator... validators) { return RespondingEthPeer.builder() diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/RespondingEthPeer.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/RespondingEthPeer.java index 9ddc218852..ac9cc7c73b 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/RespondingEthPeer.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/RespondingEthPeer.java @@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -55,7 +56,6 @@ import java.util.stream.Stream; import com.google.common.collect.Lists; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; public class RespondingEthPeer { private static final BlockDataGenerator gen = new BlockDataGenerator(); @@ -108,7 +108,7 @@ public class RespondingEthPeer { private static RespondingEthPeer create( final EthProtocolManager ethProtocolManager, final Hash chainHeadHash, - final UInt256 totalDifficulty, + final Difficulty totalDifficulty, final OptionalLong estimatedHeight, final List peerValidators) { final EthPeers ethPeers = ethProtocolManager.ethContext().getEthPeers(); @@ -339,7 +339,7 @@ public class RespondingEthPeer { public static class Builder { private EthProtocolManager ethProtocolManager; private Hash chainHeadHash = gen.hash(); - private UInt256 totalDifficulty = UInt256.valueOf(1000L); + private Difficulty totalDifficulty = Difficulty.of(1000L); private OptionalLong estimatedHeight = OptionalLong.of(1000L); private List peerValidators = new ArrayList<>(); @@ -362,7 +362,7 @@ public class RespondingEthPeer { return this; } - public Builder totalDifficulty(final UInt256 totalDifficulty) { + public Builder totalDifficulty(final Difficulty totalDifficulty) { checkNotNull(totalDifficulty); this.totalDifficulty = totalDifficulty; return this; diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/NewBlockMessageTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/NewBlockMessageTest.java index 5721c2b136..3d37a77b52 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/NewBlockMessageTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/NewBlockMessageTest.java @@ -19,13 +19,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.RawMessage; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Test; public class NewBlockMessageTest { @@ -33,7 +33,7 @@ public class NewBlockMessageTest { @Test public void roundTripNewBlockMessage() { - final UInt256 totalDifficulty = UInt256.valueOf(98765); + final Difficulty totalDifficulty = Difficulty.of(98765); final BlockDataGenerator blockGenerator = new BlockDataGenerator(); final Block blockForInsertion = blockGenerator.block(); @@ -46,7 +46,7 @@ public class NewBlockMessageTest { @Test public void rawMessageUpCastsToANewBlockMessage() { - final UInt256 totalDifficulty = UInt256.valueOf(12345); + final Difficulty totalDifficulty = Difficulty.of(12345); final BlockDataGenerator blockGenerator = new BlockDataGenerator(); final Block blockForInsertion = blockGenerator.block(); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/StatusMessageTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/StatusMessageTest.java index ed074cb6eb..513321d257 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/StatusMessageTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/StatusMessageTest.java @@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.eth.messages; import static org.assertj.core.api.Assertions.assertThat; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.eth.EthProtocol; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; @@ -24,7 +25,6 @@ import java.math.BigInteger; import java.util.Random; import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Test; public class StatusMessageTest { @@ -33,7 +33,7 @@ public class StatusMessageTest { public void getters() { final int version = EthProtocol.EthVersion.V62; final BigInteger networkId = BigInteger.ONE; - final UInt256 td = UInt256.valueOf(1000L); + final Difficulty td = Difficulty.of(1000L); final Hash bestHash = randHash(1L); final Hash genesisHash = randHash(2L); @@ -50,7 +50,7 @@ public class StatusMessageTest { public void serializeDeserialize() { final int version = EthProtocol.EthVersion.V62; final BigInteger networkId = BigInteger.ONE; - final UInt256 td = UInt256.valueOf(1000L); + final Difficulty td = Difficulty.of(1000L); final Hash bestHash = randHash(1L); final Hash genesisHash = randHash(2L); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/BlockBroadcasterTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/BlockBroadcasterTest.java index 0115f92d2d..05c036de91 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/BlockBroadcasterTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/BlockBroadcasterTest.java @@ -24,6 +24,7 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; @@ -33,7 +34,6 @@ import org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection; import java.util.Collections; import java.util.stream.Stream; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Test; public class BlockBroadcasterTest { @@ -50,9 +50,9 @@ public class BlockBroadcasterTest { final BlockBroadcaster blockBroadcaster = new BlockBroadcaster(ethContext); final Block block = generateBlock(); final NewBlockMessage newBlockMessage = - NewBlockMessage.create(block, block.getHeader().internalGetDifficulty()); + NewBlockMessage.create(block, block.getHeader().getDifficulty()); - blockBroadcaster.propagate(block, UInt256.ZERO); + blockBroadcaster.propagate(block, Difficulty.ZERO); verify(ethPeer, times(1)).send(newBlockMessage); } @@ -73,9 +73,9 @@ public class BlockBroadcasterTest { final BlockBroadcaster blockBroadcaster = new BlockBroadcaster(ethContext); final Block block = generateBlock(); final NewBlockMessage newBlockMessage = - NewBlockMessage.create(block, block.getHeader().internalGetDifficulty()); + NewBlockMessage.create(block, block.getHeader().getDifficulty()); - blockBroadcaster.propagate(block, UInt256.ZERO); + blockBroadcaster.propagate(block, Difficulty.ZERO); verify(ethPeer0, never()).send(newBlockMessage); verify(ethPeer1, times(1)).send(newBlockMessage); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManagerTest.java index d4abea7cd0..4077f504c6 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManagerTest.java @@ -33,6 +33,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions; import org.hyperledger.besu.ethereum.core.BlockImporter; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthMessages; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; @@ -55,7 +56,6 @@ import java.util.Collections; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -496,7 +496,7 @@ public class BlockPropagationManagerTest { // Setup peer and messages final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 0); - final NewBlockMessage oldAnnouncement = NewBlockMessage.create(oldBlock, UInt256.ZERO); + final NewBlockMessage oldAnnouncement = NewBlockMessage.create(oldBlock, Difficulty.ZERO); // Broadcast EthProtocolManagerTestUtil.broadcastMessage(ethProtocolManager, peer, oldAnnouncement); @@ -532,7 +532,8 @@ public class BlockPropagationManagerTest { blockPropagationManager.start(); final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 0); - final NewBlockMessage blockAnnouncementMsg = NewBlockMessage.create(blockToPurge, UInt256.ZERO); + final NewBlockMessage blockAnnouncementMsg = + NewBlockMessage.create(blockToPurge, Difficulty.ZERO); // Broadcast EthProtocolManagerTestUtil.broadcastMessage(ethProtocolManager, peer, blockAnnouncementMsg); @@ -566,9 +567,9 @@ public class BlockPropagationManagerTest { // Setup peer and messages final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 0); - final UInt256 parentTotalDifficulty = + final Difficulty parentTotalDifficulty = fullBlockchain.getTotalDifficultyByHash(nextBlock.getHeader().getParentHash()).get(); - final UInt256 totalDifficulty = + final Difficulty totalDifficulty = fullBlockchain.getTotalDifficultyByHash(nextBlock.getHash()).get(); final NewBlockMessage nextAnnouncement = NewBlockMessage.create(nextBlock, totalDifficulty); @@ -623,7 +624,8 @@ public class BlockPropagationManagerTest { // Setup peer and messages final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 0); - final UInt256 totalDifficulty = fullBlockchain.getTotalDifficultyByHash(block.getHash()).get(); + final Difficulty totalDifficulty = + fullBlockchain.getTotalDifficultyByHash(block.getHash()).get(); final NewBlockMessage newBlockMessage = NewBlockMessage.create(block, totalDifficulty); // Broadcast message diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java index cda43ce853..806ffc6576 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java @@ -19,6 +19,7 @@ import static org.mockito.Mockito.mock; import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import org.hyperledger.besu.ethereum.eth.manager.ChainState; @@ -29,7 +30,6 @@ import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer.Responder; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import org.apache.tuweni.units.bigints.UInt256; import org.assertj.core.api.Assertions; import org.junit.Test; @@ -81,7 +81,7 @@ public class ChainHeadTrackerTest { chainHeadTracker.onPeerConnected(respondingPeer.getEthPeer()); // Change the hash of the current known head - respondingPeer.getEthPeer().chainState().statusReceived(Hash.EMPTY_TRIE_HASH, UInt256.ONE); + respondingPeer.getEthPeer().chainState().statusReceived(Hash.EMPTY_TRIE_HASH, Difficulty.ONE); respondingPeer.respond(responder); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/TrailingPeerLimiterTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/TrailingPeerLimiterTest.java index cf29fe5bbd..8c0a737790 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/TrailingPeerLimiterTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/TrailingPeerLimiterTest.java @@ -27,6 +27,7 @@ import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.eth.manager.ChainState; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; @@ -37,7 +38,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.Test; @@ -155,7 +155,7 @@ public class TrailingPeerLimiterTest { private EthPeer addPeerWithEstimatedHeight(final long height) { final EthPeer peer = mock(EthPeer.class); final ChainState chainState = new ChainState(); - chainState.statusReceived(Hash.EMPTY, UInt256.ONE); + chainState.statusReceived(Hash.EMPTY, Difficulty.ONE); chainState.update(Hash.EMPTY, height); when(peer.chainState()).thenReturn(chainState); peers.add(peer); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java index ac46f8b953..0513fe4a75 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java @@ -25,6 +25,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -43,7 +44,6 @@ import java.util.OptionalLong; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.Test; @@ -129,8 +129,8 @@ public class FastSyncActionsTest { syncConfig = syncConfigBuilder.build(); fastSyncActions = createFastSyncActions(syncConfig); - EthProtocolManagerTestUtil.createPeer(ethProtocolManager, UInt256.valueOf(1000), 5500); - EthProtocolManagerTestUtil.createPeer(ethProtocolManager, UInt256.valueOf(2000), 4000); + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, Difficulty.of(1000), 5500); + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, Difficulty.of(2000), 4000); final CompletableFuture result = fastSyncActions.selectPivotBlock(FastSyncState.EMPTY_SYNC_STATE); @@ -176,7 +176,7 @@ public class FastSyncActionsTest { // Create peers without chain height estimates List peers = new ArrayList<>(); for (int i = 0; i < minPeers; i++) { - final UInt256 td = UInt256.valueOf(i); + final Difficulty td = Difficulty.of(i); final OptionalLong height = OptionalLong.empty(); final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, td, height); @@ -222,7 +222,7 @@ public class FastSyncActionsTest { final OptionalLong height = OptionalLong.of(minPivotHeight + 10); List peers = new ArrayList<>(); for (int i = 0; i < minPeers; i++) { - final UInt256 td = UInt256.valueOf(i); + final Difficulty td = Difficulty.of(i); final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, td, height, validator); @@ -285,7 +285,7 @@ public class FastSyncActionsTest { for (int i = 0; i < peerCount; i++) { // Best peer by td is the first peer, td decreases as i increases final boolean isBest = i == 0; - final UInt256 td = UInt256.valueOf(peerCount - i); + final Difficulty td = Difficulty.of(peerCount - i); final OptionalLong height; if (isBest && bestMissingHeight) { diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java index 6ce1962b8c..0646df63ed 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java @@ -25,6 +25,7 @@ import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; @@ -40,7 +41,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.Test; @@ -215,11 +215,11 @@ public class PivotBlockRetrieverTest { RespondingEthPeer.blockchainResponder(blockchain, protocolContext.getWorldStateArchive()); final RespondingEthPeer peerA = - EthProtocolManagerTestUtil.createPeer(ethProtocolManager, UInt256.valueOf(1000), 1000); + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, Difficulty.of(1000), 1000); final RespondingEthPeer peerB = - EthProtocolManagerTestUtil.createPeer(ethProtocolManager, UInt256.valueOf(500), 500); + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, Difficulty.of(500), 500); final RespondingEthPeer peerC = - EthProtocolManagerTestUtil.createPeer(ethProtocolManager, UInt256.valueOf(1000), 1000); + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, Difficulty.of(1000), 1000); final CompletableFuture future = pivotBlockRetriever.downloadPivotBlockHeader(); @@ -243,11 +243,11 @@ public class PivotBlockRetrieverTest { final Responder emptyResponder = RespondingEthPeer.emptyResponder(); final RespondingEthPeer peerA = - EthProtocolManagerTestUtil.createPeer(ethProtocolManager, UInt256.valueOf(1000), 1000); + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, Difficulty.of(1000), 1000); final RespondingEthPeer peerB = - EthProtocolManagerTestUtil.createPeer(ethProtocolManager, UInt256.valueOf(1000), 1000); + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, Difficulty.of(1000), 1000); final RespondingEthPeer peerC = - EthProtocolManagerTestUtil.createPeer(ethProtocolManager, UInt256.valueOf(500), 500); + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, Difficulty.of(500), 500); final CompletableFuture future = pivotBlockRetriever.downloadPivotBlockHeader(); peerA.respond(responder); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/BetterSyncTargetEvaluatorTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/BetterSyncTargetEvaluatorTest.java index 11973577b0..c22ede83ac 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/BetterSyncTargetEvaluatorTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/BetterSyncTargetEvaluatorTest.java @@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.ethereum.eth.manager.ChainState; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; @@ -152,7 +153,7 @@ public class BetterSyncTargetEvaluatorTest { final EthPeer peer = mock(EthPeer.class); final ChainState chainState = new ChainState(); chainState.updateHeightEstimate(chainHeight); - chainState.statusReceived(Hash.EMPTY, UInt256.valueOf(totalDifficulty)); + chainState.statusReceived(Hash.EMPTY, Difficulty.of(totalDifficulty)); when(peer.chainState()).thenReturn(chainState); return peer; } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderForkTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderForkTest.java index 3ba5ec0e17..5dbdb962ce 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderForkTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderForkTest.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; @@ -33,7 +34,6 @@ import org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.Di import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -92,7 +92,7 @@ public class FullSyncChainDownloaderForkTest { @Test public void disconnectsFromPeerOnBadFork() { otherBlockchainSetup.importAllBlocks(); - final UInt256 localTd = localBlockchain.getChainHead().getTotalDifficulty(); + final Difficulty localTd = localBlockchain.getChainHead().getTotalDifficulty(); final RespondingEthPeer.Responder responder = RespondingEthPeer.blockchainResponder(otherBlockchain); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTest.java index 40b5502138..57f8d2d9a6 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTest.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -49,7 +50,6 @@ import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.function.Function; -import org.apache.tuweni.units.bigints.UInt256; import org.awaitility.Awaitility; import org.junit.After; import org.junit.Before; @@ -221,7 +221,8 @@ public class FullSyncChainDownloaderTest { localBlockchainSetup.importFirstBlocks(3); gen = new BlockDataGenerator(); final Block chainHead = localBlockchain.getChainHeadBlock(); - final Block forkBlock = gen.block(gen.nextBlockOptions(chainHead).setDifficulty(UInt256.ZERO)); + final Block forkBlock = + gen.block(gen.nextBlockOptions(chainHead).setDifficulty(Difficulty.ZERO)); localBlockchain.appendBlock(forkBlock, gen.receipts(forkBlock)); // Sanity check @@ -251,7 +252,7 @@ public class FullSyncChainDownloaderTest { @Test public void choosesBestPeerAsSyncTarget_byTd() { - final UInt256 localTd = localBlockchain.getChainHead().getTotalDifficulty(); + final Difficulty localTd = localBlockchain.getChainHead().getTotalDifficulty(); final RespondingEthPeer.Responder responder = RespondingEthPeer.blockchainResponder(otherBlockchain); @@ -273,7 +274,7 @@ public class FullSyncChainDownloaderTest { @Test public void choosesBestPeerAsSyncTarget_byTdAndHeight() { - final UInt256 localTd = localBlockchain.getChainHead().getTotalDifficulty(); + final Difficulty localTd = localBlockchain.getChainHead().getTotalDifficulty(); final RespondingEthPeer.Responder responder = RespondingEthPeer.blockchainResponder(otherBlockchain); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java index 7a4b9c2ce3..0e0eeb79bf 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java @@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; @@ -37,7 +38,6 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import java.util.Optional; import java.util.concurrent.CompletableFuture; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -88,7 +88,7 @@ public class FullSyncTargetManagerTest { when(localWorldState.isWorldStateAvailable(localBlockchain.getChainHeadHeader().getStateRoot())) .thenReturn(true); final RespondingEthPeer bestPeer = - EthProtocolManagerTestUtil.createPeer(ethProtocolManager, UInt256.MAX_VALUE, 1); + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, Difficulty.MAX_VALUE, 1); final CompletableFuture result = syncTargetManager.findSyncTarget(Optional.empty()); bestPeer.respond(responder); @@ -103,7 +103,7 @@ public class FullSyncTargetManagerTest { when(localWorldState.isWorldStateAvailable(localBlockchain.getChainHeadHeader().getStateRoot())) .thenReturn(true); final RespondingEthPeer bestPeer = - EthProtocolManagerTestUtil.createPeer(ethProtocolManager, UInt256.MAX_VALUE, 0); + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, Difficulty.MAX_VALUE, 0); final CompletableFuture result = syncTargetManager.findSyncTarget(Optional.empty()); bestPeer.respond(responder); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/state/SyncStateTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/state/SyncStateTest.java index f59e3aa3cb..e067ad85e6 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/state/SyncStateTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/state/SyncStateTest.java @@ -32,6 +32,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.InMemoryStorageProvider; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.core.Synchronizer.InSyncListener; @@ -50,7 +51,6 @@ import org.hyperledger.besu.plugin.services.BesuEvents.SyncStatusListener; import java.util.List; import java.util.Optional; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -61,13 +61,13 @@ import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class SyncStateTest { - private static final UInt256 standardDifficultyPerBlock = UInt256.ONE; + private static final Difficulty standardDifficultyPerBlock = Difficulty.ONE; private static final long OUR_CHAIN_HEAD_NUMBER = 20; - private static final UInt256 OUR_CHAIN_DIFFICULTY = + private static final Difficulty OUR_CHAIN_DIFFICULTY = standardDifficultyPerBlock.multiply(OUR_CHAIN_HEAD_NUMBER); private static final long TARGET_CHAIN_DELTA = 20; private static final long TARGET_CHAIN_HEIGHT = OUR_CHAIN_HEAD_NUMBER + TARGET_CHAIN_DELTA; - private static final UInt256 TARGET_DIFFICULTY = + private static final Difficulty TARGET_DIFFICULTY = standardDifficultyPerBlock.multiply(TARGET_CHAIN_HEIGHT); private final InSyncListener inSyncListener = mock(InSyncListener.class); @@ -76,7 +76,7 @@ public class SyncStateTest { private final BlockDataGenerator gen = new BlockDataGenerator(1); private final Block genesisBlock = - gen.genesisBlock(new BlockOptions().setDifficulty(UInt256.ZERO)); + gen.genesisBlock(new BlockOptions().setDifficulty(Difficulty.ZERO)); private final MutableBlockchain blockchain = InMemoryStorageProvider.createInMemoryBlockchain(genesisBlock); @@ -95,7 +95,7 @@ public class SyncStateTest { blockchain, InMemoryStorageProvider.createInMemoryWorldStateArchive()); ethPeers = spy(ethProtocolManager.ethContext().getEthPeers()); syncTargetPeer = createPeer(TARGET_DIFFICULTY, TARGET_CHAIN_HEIGHT); - otherPeer = createPeer(UInt256.ZERO, 0); + otherPeer = createPeer(Difficulty.ZERO, 0); advanceLocalChain(OUR_CHAIN_HEAD_NUMBER); @@ -561,7 +561,7 @@ public class SyncStateTest { assertThat(clearedEvent).isEmpty(); } - private RespondingEthPeer createPeer(final UInt256 totalDifficulty, final long blockHeight) { + private RespondingEthPeer createPeer(final Difficulty totalDifficulty, final long blockHeight) { return EthProtocolManagerTestUtil.createPeer(ethProtocolManager, totalDifficulty, blockHeight); } @@ -614,14 +614,14 @@ public class SyncStateTest { * @param totalDifficulty The total difficulty */ private void updateChainState( - final EthPeer peer, final long blockHeight, final UInt256 totalDifficulty) { + final EthPeer peer, final long blockHeight, final Difficulty totalDifficulty) { // Chain state is updated based on the parent of the announced block // So, increment block number by 1 and set block difficulty to zero // in order to update to the values we want final BlockHeader header = new BlockHeaderTestFixture() .number(blockHeight + 1L) - .difficulty(UInt256.ZERO) + .difficulty(Difficulty.ZERO) .buildHeader(); peer.chainState().updateForAnnouncedBlock(header, totalDifficulty); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java index ee99fa9f4f..f116f86f6a 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java @@ -24,6 +24,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -45,7 +46,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -130,7 +130,7 @@ public class DetermineCommonAncestorTaskParameterizedTest { final BlockDataGenerator.BlockOptions remoteOptions = new BlockDataGenerator.BlockOptions() - .setDifficulty(UInt256.ONE) // differentiator + .setDifficulty(Difficulty.ONE) // differentiator .setBlockNumber(i) .setParentHash(remoteBlockchain.getBlockHashByNumber(i - 1).get()); final Block remoteBlock = blockDataGenerator.block(remoteOptions); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolTest.java index 44658b11ef..9d4fbf8f87 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolTest.java @@ -43,6 +43,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -69,7 +70,6 @@ import java.util.List; import java.util.Optional; import java.util.Set; -import org.apache.tuweni.units.bigints.UInt256; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -185,8 +185,8 @@ public class TransactionPoolTest { public void shouldNotRemovePendingTransactionsWhenABlockAddedToAFork() { transactions.addRemoteTransaction(transaction1); final BlockHeader commonParent = getHeaderForCurrentChainHead(); - final Block canonicalHead = appendBlock(UInt256.valueOf(1000), commonParent); - appendBlock(UInt256.ONE, commonParent, transaction1); + final Block canonicalHead = appendBlock(Difficulty.of(1000), commonParent); + appendBlock(Difficulty.ONE, commonParent, transaction1); verifyChainHeadIs(canonicalHead); @@ -198,13 +198,12 @@ public class TransactionPoolTest { transactions.addRemoteTransaction(transaction1); transactions.addRemoteTransaction(transaction2); final BlockHeader commonParent = getHeaderForCurrentChainHead(); - final Block originalChainHead = appendBlock(UInt256.valueOf(1000), commonParent); + final Block originalChainHead = appendBlock(Difficulty.of(1000), commonParent); - final Block forkBlock1 = appendBlock(UInt256.ONE, commonParent, transaction1); + final Block forkBlock1 = appendBlock(Difficulty.ONE, commonParent, transaction1); verifyChainHeadIs(originalChainHead); - final Block forkBlock2 = - appendBlock(UInt256.valueOf(2000), forkBlock1.getHeader(), transaction2); + final Block forkBlock2 = appendBlock(Difficulty.of(2000), forkBlock1.getHeader(), transaction2); verifyChainHeadIs(forkBlock2); assertTransactionNotPending(transaction1); @@ -218,16 +217,17 @@ public class TransactionPoolTest { transactions.addRemoteTransaction(transaction1); transactions.addRemoteTransaction(transaction2); final BlockHeader commonParent = getHeaderForCurrentChainHead(); - final Block originalFork1 = appendBlock(UInt256.valueOf(1000), commonParent, transaction1); - final Block originalFork2 = appendBlock(UInt256.ONE, originalFork1.getHeader(), transaction2); + final Block originalFork1 = appendBlock(Difficulty.of(1000), commonParent, transaction1); + final Block originalFork2 = + appendBlock(Difficulty.ONE, originalFork1.getHeader(), transaction2); assertTransactionNotPending(transaction1); assertTransactionNotPending(transaction2); - final Block reorgFork1 = appendBlock(UInt256.ONE, commonParent); + final Block reorgFork1 = appendBlock(Difficulty.ONE, commonParent); verifyChainHeadIs(originalFork2); transactions.subscribePendingTransactions(listener); - final Block reorgFork2 = appendBlock(UInt256.valueOf(2000), reorgFork1.getHeader()); + final Block reorgFork2 = appendBlock(Difficulty.of(2000), reorgFork1.getHeader()); verifyChainHeadIs(reorgFork2); assertTransactionPending(transaction1); @@ -244,15 +244,16 @@ public class TransactionPoolTest { transactions.addRemoteTransaction(transaction1); transactions.addRemoteTransaction(transaction2); final BlockHeader commonParent = getHeaderForCurrentChainHead(); - final Block originalFork1 = appendBlock(UInt256.valueOf(1000), commonParent, transaction1); - final Block originalFork2 = appendBlock(UInt256.ONE, originalFork1.getHeader(), transaction2); + final Block originalFork1 = appendBlock(Difficulty.of(1000), commonParent, transaction1); + final Block originalFork2 = + appendBlock(Difficulty.ONE, originalFork1.getHeader(), transaction2); assertTransactionNotPending(transaction1); assertTransactionNotPending(transaction2); - final Block reorgFork1 = appendBlock(UInt256.ONE, commonParent, transaction1); + final Block reorgFork1 = appendBlock(Difficulty.ONE, commonParent, transaction1); verifyChainHeadIs(originalFork2); - final Block reorgFork2 = appendBlock(UInt256.valueOf(2000), reorgFork1.getHeader()); + final Block reorgFork2 = appendBlock(Difficulty.of(2000), reorgFork1.getHeader()); verifyChainHeadIs(reorgFork2); assertTransactionNotPending(transaction1); @@ -619,7 +620,7 @@ public class TransactionPoolTest { } private void appendBlock(final Transaction... transactionsToAdd) { - appendBlock(UInt256.ONE, getHeaderForCurrentChainHead(), transactionsToAdd); + appendBlock(Difficulty.ONE, getHeaderForCurrentChainHead(), transactionsToAdd); } private BlockHeader getHeaderForCurrentChainHead() { @@ -627,7 +628,7 @@ public class TransactionPoolTest { } private Block appendBlock( - final UInt256 difficulty, + final Difficulty difficulty, final BlockHeader parentBlock, final Transaction... transactionsToAdd) { final List transactionList = asList(transactionsToAdd); diff --git a/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParamsTest.java b/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParamsTest.java index aa88cff76a..508f262a22 100644 --- a/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParamsTest.java +++ b/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParamsTest.java @@ -65,7 +65,7 @@ public class TestSetChainParamsTest { "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); assertThat(blockHeader.getCoinbase().toString()) .isEqualTo("0x8888f1f195afa192cfee860698584c030f4c9db1"); - assertThat(blockHeader.internalGetDifficulty()).isEqualTo(UInt256.fromHexString("0x20000")); + assertThat(blockHeader.getDifficulty()).isEqualTo(UInt256.fromHexString("0x20000")); assertThat(blockHeader.getExtraData().getHexString()).isEqualTo("0x42"); assertThat(blockHeader.getGasLimit()).isEqualTo(3141592); assertThat(blockHeader.getGasUsed()).isEqualTo(0);