Search in sources :

Example 6 with LogsBloomFilter

use of org.hyperledger.besu.evm.log.LogsBloomFilter in project besu by hyperledger.

the class DifficultyCalculatorTests method testDifficulty.

private void testDifficulty(final String testFile, final ProtocolSchedule protocolSchedule, final MainnetBlockHeaderFunctions blockHeaderFunctions, final ObjectNode testObject) {
    final var fields = testObject.fields();
    while (fields.hasNext()) {
        final var entry = fields.next();
        final JsonNode value = entry.getValue();
        final long currentBlockNumber = extractLong(value, "currentBlockNumber");
        String parentUncles = value.get("parentUncles").asText();
        final BlockHeader testHeader = BlockHeaderBuilder.create().parentHash(Hash.EMPTY).coinbase(Address.ZERO).gasLimit(Long.MAX_VALUE).stateRoot(Hash.EMPTY).transactionsRoot(Hash.EMPTY).receiptsRoot(Hash.EMPTY).logsBloom(new LogsBloomFilter()).gasUsed(0).extraData(Bytes.of()).mixHash(Hash.EMPTY).nonce(0).blockHeaderFunctions(blockHeaderFunctions).timestamp(extractLong(value, "parentTimestamp")).difficulty(Difficulty.fromHexString(value.get("parentDifficulty").asText())).ommersHash(parentUncles.equals("0x00") ? Hash.EMPTY_LIST_HASH : Hash.fromHexStringLenient(parentUncles)).number(currentBlockNumber).buildBlockHeader();
        final long currentTime = extractLong(value, "currentTimestamp");
        final UInt256 currentDifficulty = UInt256.fromHexString(value.get("currentDifficulty").asText());
        final var spec = protocolSchedule.getByBlockNumber(currentBlockNumber);
        final var calculator = spec.getDifficultyCalculator();
        assertThat(UInt256.valueOf(calculator.nextDifficulty(currentTime, testHeader, null))).describedAs("File %s Test %s", testFile, entry.getKey()).isEqualTo(currentDifficulty);
    }
}
Also used : LogsBloomFilter(org.hyperledger.besu.evm.log.LogsBloomFilter) JsonNode(com.fasterxml.jackson.databind.JsonNode) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) UInt256(org.apache.tuweni.units.bigints.UInt256)

Example 7 with LogsBloomFilter

use of org.hyperledger.besu.evm.log.LogsBloomFilter in project besu by hyperledger.

the class DifficultyCalculatorTests method testDifficultyCalculation.

@Test
public void testDifficultyCalculation() throws IOException {
    MainnetBlockHeaderFunctions blockHeaderFunctions = new MainnetBlockHeaderFunctions();
    final ObjectNode testObject = JsonUtil.objectNodeFromString(Resources.toString(DifficultyCalculatorTests.class.getResource(testFile), StandardCharsets.UTF_8));
    final var fields = testObject.fields();
    while (fields.hasNext()) {
        final var entry = fields.next();
        final JsonNode value = entry.getValue();
        final long currentBlockNumber = extractLong(value, "currentBlockNumber");
        final BlockHeader testHeader = BlockHeaderBuilder.create().parentHash(Hash.EMPTY).coinbase(Address.ZERO).gasLimit(Long.MAX_VALUE).stateRoot(Hash.EMPTY).transactionsRoot(Hash.EMPTY).receiptsRoot(Hash.EMPTY).logsBloom(new LogsBloomFilter()).gasUsed(0).extraData(Bytes.of()).mixHash(Hash.EMPTY).nonce(0).blockHeaderFunctions(blockHeaderFunctions).timestamp(extractLong(value, "parentTimestamp")).difficulty(Difficulty.fromHexString(value.get("parentDifficulty").asText())).ommersHash(Hash.fromHexString(value.get("parentUncles").asText())).number(currentBlockNumber).buildBlockHeader();
        final long currentTime = extractLong(value, "currentTimestamp");
        final UInt256 currentDifficulty = UInt256.fromHexString(value.get("currentDifficulty").asText());
        final var spec = protocolSchedule.getByBlockNumber(currentBlockNumber);
        final var calculator = spec.getDifficultyCalculator();
        assertThat(UInt256.valueOf(calculator.nextDifficulty(currentTime, testHeader, null))).describedAs("File %s Test %s", testFile, entry.getKey()).isEqualTo(currentDifficulty);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) LogsBloomFilter(org.hyperledger.besu.evm.log.LogsBloomFilter) JsonNode(com.fasterxml.jackson.databind.JsonNode) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) UInt256(org.apache.tuweni.units.bigints.UInt256) Test(org.junit.Test)

Aggregations

LogsBloomFilter (org.hyperledger.besu.evm.log.LogsBloomFilter)7 Bytes (org.apache.tuweni.bytes.Bytes)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Hash (org.hyperledger.besu.datatypes.Hash)3 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)3 ArrayList (java.util.ArrayList)2 UInt256 (org.apache.tuweni.units.bigints.UInt256)2 Address (org.hyperledger.besu.datatypes.Address)2 Wei (org.hyperledger.besu.datatypes.Wei)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ByteString (com.google.protobuf.ByteString)1 LogsBloomAggregator (com.hedera.mirror.common.aggregator.LogsBloomAggregator)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)1 BlockResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResult)1 BlockHeaderFunctions (org.hyperledger.besu.ethereum.core.BlockHeaderFunctions)1 Difficulty (org.hyperledger.besu.ethereum.core.Difficulty)1