Search in sources :

Example 1 with ForkId

use of org.hyperledger.besu.ethereum.eth.manager.ForkId in project besu by hyperledger.

the class StatusMessageTest method serializeDeserializeWithForkId.

@Test
public void serializeDeserializeWithForkId() {
    final int version = EthProtocol.EthVersion.V64;
    final BigInteger networkId = BigInteger.ONE;
    final Difficulty td = Difficulty.of(1000L);
    final Hash bestHash = randHash(1L);
    final Hash genesisHash = randHash(2L);
    final ForkId forkId = new ForkId(Bytes.fromHexString("0xa00bc334"), 0L);
    final MessageData msg = StatusMessage.create(version, networkId, td, bestHash, genesisHash, forkId);
    final StatusMessage copy = new StatusMessage(msg.getData());
    assertThat(copy.protocolVersion()).isEqualTo(version);
    assertThat(copy.networkId()).isEqualTo(networkId);
    assertThat(copy.totalDifficulty()).isEqualTo(td);
    assertThat(copy.bestHash()).isEqualTo(bestHash);
    assertThat(copy.genesisHash()).isEqualTo(genesisHash);
    assertThat(copy.forkId()).isEqualTo(forkId);
}
Also used : Difficulty(org.hyperledger.besu.ethereum.core.Difficulty) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) BigInteger(java.math.BigInteger) ForkId(org.hyperledger.besu.ethereum.eth.manager.ForkId) Hash(org.hyperledger.besu.datatypes.Hash) Test(org.junit.Test)

Example 2 with ForkId

use of org.hyperledger.besu.ethereum.eth.manager.ForkId in project besu by hyperledger.

the class ForkIdBackwardCompatibilityTest method assertBackwardCompatibilityWorks.

@Test
public void assertBackwardCompatibilityWorks() {
    LOG.info("Running test case {}", name);
    final ForkIdManager forkIdManager = new ForkIdManager(mockBlockchain(genesisHash, head), forks, legacyEth64);
    final ForkId legacyForkId = legacyEth64 ? new LegacyForkIdManager(mockBlockchain(genesisHash, head), forks).getLatestForkId() : null;
    assertThat(forkIdManager.getForkIdForChainHead()).isEqualTo(legacyEth64 ? legacyForkId : wantForkId);
}
Also used : ForkId(org.hyperledger.besu.ethereum.eth.manager.ForkId) ForkIdManager(org.hyperledger.besu.ethereum.eth.manager.ForkIdManager) Test(org.junit.Test)

Example 3 with ForkId

use of org.hyperledger.besu.ethereum.eth.manager.ForkId in project besu by hyperledger.

the class LegacyForkIdManager method readFrom.

public static ForkId readFrom(final RLPInput in) {
    in.enterList();
    final Bytes hash = in.readBytes();
    final Bytes next = in.readBytes();
    in.leaveList();
    return new ForkId(hash, next);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) ForkId(org.hyperledger.besu.ethereum.eth.manager.ForkId)

Example 4 with ForkId

use of org.hyperledger.besu.ethereum.eth.manager.ForkId in project besu by hyperledger.

the class LegacyForkIdManager method createForkIds.

private void createForkIds() {
    final CRC32 crc = new CRC32();
    crc.update(genesisHash.toArray());
    final List<Bytes> forkHashes = new ArrayList<>(List.of(getCurrentCrcHash(crc)));
    for (final Long fork : forks) {
        updateCrc(crc, fork);
        forkHashes.add(getCurrentCrcHash(crc));
    }
    final List<ForkId> forkIds = new ArrayList<>();
    // This loop is for all the fork hashes that have an associated "next fork"
    for (int i = 0; i < forks.size(); i++) {
        forkIds.add(new ForkId(forkHashes.get(i), forks.get(i)));
    }
    if (!forks.isEmpty()) {
        forkIds.add(new ForkId(forkHashes.get(forkHashes.size() - 1), 0));
    }
    this.forkAndHashList = forkIds;
    System.out.println(this.forkAndHashList);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) CRC32(java.util.zip.CRC32) ArrayList(java.util.ArrayList) ForkId(org.hyperledger.besu.ethereum.eth.manager.ForkId)

Example 5 with ForkId

use of org.hyperledger.besu.ethereum.eth.manager.ForkId in project besu by hyperledger.

the class StatusMessageTest method toStringHasExpectedInfo.

@Test
public void toStringHasExpectedInfo() {
    final int version = EthProtocol.EthVersion.V64;
    final BigInteger networkId = BigInteger.ONE;
    final Difficulty td = Difficulty.of(1000L);
    final Hash bestHash = randHash(1L);
    final Hash genesisHash = randHash(2L);
    final ForkId forkId = new ForkId(Bytes.fromHexString("0xa00bc334"), 0L);
    final MessageData msg = StatusMessage.create(version, networkId, td, bestHash, genesisHash, forkId);
    final StatusMessage copy = new StatusMessage(msg.getData());
    final String copyToString = copy.toString();
    assertThat(copyToString).contains("bestHash=" + bestHash);
    assertThat(copyToString).contains("genesisHash=" + genesisHash);
}
Also used : Difficulty(org.hyperledger.besu.ethereum.core.Difficulty) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) BigInteger(java.math.BigInteger) ForkId(org.hyperledger.besu.ethereum.eth.manager.ForkId) Hash(org.hyperledger.besu.datatypes.Hash) Test(org.junit.Test)

Aggregations

ForkId (org.hyperledger.besu.ethereum.eth.manager.ForkId)5 Test (org.junit.Test)3 BigInteger (java.math.BigInteger)2 Bytes (org.apache.tuweni.bytes.Bytes)2 Hash (org.hyperledger.besu.datatypes.Hash)2 Difficulty (org.hyperledger.besu.ethereum.core.Difficulty)2 MessageData (org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData)2 ArrayList (java.util.ArrayList)1 CRC32 (java.util.zip.CRC32)1 ForkIdManager (org.hyperledger.besu.ethereum.eth.manager.ForkIdManager)1