mirror of
https://github.com/vacp2p/linea-besu.git
synced 2026-01-09 15:37:54 -05:00
Remove QuantityWrapper. Use the Difficulty class extending both UInt256 and Quantity instead. (#274)
Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>
This commit is contained in:
committed by
Adrian Sutton
parent
58f22eb9ed
commit
bf7493de29
@@ -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(),
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<BlockHeader> blockHeaderSupplier,
|
||||
final Supplier<UInt256> totalDifficultySupplier) {
|
||||
final Supplier<Difficulty> 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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<IbftContext> 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 =
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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<JsonNode> ommers = new ArrayList<>();
|
||||
|
||||
@@ -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<Transaction> transactionList = asList(transactionsToAdd);
|
||||
|
||||
@@ -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<UInt256> getDifficulty() {
|
||||
return Optional.of(header.internalGetDifficulty());
|
||||
public Optional<Difficulty> getDifficulty() {
|
||||
return Optional.of(header.getDifficulty());
|
||||
}
|
||||
|
||||
public Optional<Bytes32> getOmmerHash() {
|
||||
|
||||
@@ -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<UInt256> getTotalDifficulty() {
|
||||
public Optional<Difficulty> getTotalDifficulty() {
|
||||
return Optional.of(blockWithMetaData.getTotalDifficulty());
|
||||
}
|
||||
|
||||
|
||||
@@ -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<TransactionResult> transactions,
|
||||
final List<JsonNode> 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<TransactionResult> transactions,
|
||||
final List<JsonNode> 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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<T, O> {
|
||||
|
||||
private final BlockHeader header;
|
||||
private final List<T> transactions;
|
||||
private final List<O> ommers;
|
||||
private final UInt256 totalDifficulty;
|
||||
private final Difficulty totalDifficulty;
|
||||
private final int size;
|
||||
|
||||
/**
|
||||
@@ -39,7 +38,7 @@ public class BlockWithMetadata<T, O> {
|
||||
final BlockHeader header,
|
||||
final List<T> transactions,
|
||||
final List<O> ommers,
|
||||
final UInt256 totalDifficulty,
|
||||
final Difficulty totalDifficulty,
|
||||
final int size) {
|
||||
this.header = header;
|
||||
this.transactions = transactions;
|
||||
@@ -60,7 +59,7 @@ public class BlockWithMetadata<T, O> {
|
||||
return transactions;
|
||||
}
|
||||
|
||||
public UInt256 getTotalDifficulty() {
|
||||
public Difficulty getTotalDifficulty() {
|
||||
return totalDifficulty;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<TransactionWithMetadata, Hash> 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<Transaction> txs = block.getBody().getTransactions();
|
||||
@@ -1893,7 +1894,7 @@ public class JsonRpcHttpServiceTest {
|
||||
}
|
||||
|
||||
public BlockWithMetadata<Hash, Hash> 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<Hash> txs =
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -113,7 +113,7 @@ public class DebugTraceBlockTest {
|
||||
parentBlock.getHeader(),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList(),
|
||||
parentBlock.getHeader().internalGetDifficulty(),
|
||||
parentBlock.getHeader().getDifficulty(),
|
||||
parentBlock.calculateSize())));
|
||||
|
||||
final JsonRpcSuccessResponse response =
|
||||
|
||||
@@ -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<Hash> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Hash> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<TransactionWithMetadata> txHashList = transactionsWithMetadata();
|
||||
final BlockWithMetadata<TransactionWithMetadata, Hash> 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<Hash> objects) {
|
||||
final BlockWithMetadata<Hash, Hash> 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()))
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<TransactionReceipt> forkReceipts = gen.receipts(fork);
|
||||
|
||||
|
||||
@@ -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<C> implements AsyncBlockCreator {
|
||||
|
||||
@@ -256,7 +256,7 @@ public abstract class AbstractBlockCreator<C> implements AsyncBlockCreator {
|
||||
return BlockHeaderBuilder.create()
|
||||
.parentHash(parentHeader.getHash())
|
||||
.coinbase(coinbase)
|
||||
.difficulty(UInt256.valueOf(difficulty))
|
||||
.difficulty(Difficulty.of(difficulty))
|
||||
.number(newBlockNumber)
|
||||
.gasLimit(gasLimit)
|
||||
.timestamp(timestamp)
|
||||
|
||||
@@ -85,7 +85,7 @@ public class EthHashBlockCreator extends AbstractBlockCreator<Void> {
|
||||
|
||||
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
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<UInt256> getTotalDifficultyByHash(Hash blockHeaderHash);
|
||||
Optional<Difficulty> getTotalDifficultyByHash(Hash blockHeaderHash);
|
||||
|
||||
/**
|
||||
* Given a transaction hash, returns the location (block number and transaction index) of the
|
||||
|
||||
@@ -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<Hash> getChainHead();
|
||||
@@ -39,7 +38,7 @@ public interface BlockchainStorage {
|
||||
|
||||
Optional<Hash> getBlockHash(long blockNumber);
|
||||
|
||||
Optional<UInt256> getTotalDifficulty(Hash blockHash);
|
||||
Optional<Difficulty> getTotalDifficulty(Hash blockHash);
|
||||
|
||||
Optional<TransactionLocation> 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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<BlockAddedObserver> 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<UInt256> getTotalDifficultyByHash(final Hash blockHeaderHash) {
|
||||
public Optional<Difficulty> getTotalDifficultyByHash(final Hash blockHeaderHash) {
|
||||
return blockchainStorage.getTotalDifficulty(blockHeaderHash);
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ public class DefaultBlockchain implements MutableBlockchain {
|
||||
final Block block = blockWithReceipts.getBlock();
|
||||
final List<TransactionReceipt> 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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Difficulty> 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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -36,7 +36,7 @@ public class CalculatedDifficultyValidationRule<C> implements AttachedBlockHeade
|
||||
public boolean validate(
|
||||
final BlockHeader header, final BlockHeader parent, final ProtocolContext<C> 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);
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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<UInt256> getTotalDifficulty(final Hash blockHash) {
|
||||
return get(TOTAL_DIFFICULTY_PREFIX, blockHash).map(b -> UInt256.fromBytes(Bytes32.wrap(b, 0)));
|
||||
public Optional<Difficulty> 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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Hash> parentHash = Optional.empty();
|
||||
private Optional<Hash> stateRoot = Optional.empty();
|
||||
private Optional<UInt256> difficulty = Optional.empty();
|
||||
private Optional<Difficulty> difficulty = Optional.empty();
|
||||
private List<Transaction> transactions = new ArrayList<>();
|
||||
private Optional<Bytes> extraData = Optional.empty();
|
||||
private Optional<BlockHeaderFunctions> 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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<TransactionReceipt> forkReceipts = gen.receipts(fork);
|
||||
final List<Block> 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<List<TransactionReceipt>> 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<List<TransactionReceipt>> 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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<UInt256> uut =
|
||||
new ConstantFieldValidationRule<>(
|
||||
"Difficulty", BlockHeader::internalGetDifficulty, UInt256.ONE);
|
||||
final ConstantFieldValidationRule<Difficulty> 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();
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<UInt256> getTotalDifficultyByHash(final Hash blockHeaderHash) {
|
||||
public Optional<Difficulty> getTotalDifficultyByHash(final Hash blockHeaderHash) {
|
||||
// Deterministic, but just not implemented.
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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 <C> UInt256 totalDifficulty(final ProtocolSchedule<C> protocolSchedule) {
|
||||
public <C> Difficulty totalDifficulty(final ProtocolSchedule<C> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<C> {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
@@ -155,7 +155,7 @@ public class BlockPropagationManager<C> {
|
||||
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<C> {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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<PeerValidator> 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<PeerValidator> 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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<FastSyncState> result =
|
||||
fastSyncActions.selectPivotBlock(FastSyncState.EMPTY_SYNC_STATE);
|
||||
@@ -176,7 +176,7 @@ public class FastSyncActionsTest {
|
||||
// Create peers without chain height estimates
|
||||
List<RespondingEthPeer> 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<RespondingEthPeer> 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) {
|
||||
|
||||
@@ -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<FastSyncState> 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<FastSyncState> future = pivotBlockRetriever.downloadPivotBlockHeader();
|
||||
peerA.respond(responder);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<SyncTarget> 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<SyncTarget> result = syncTargetManager.findSyncTarget(Optional.empty());
|
||||
bestPeer.respond(responder);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Transaction> transactionList = asList(transactionsToAdd);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user