Search in sources :

Example 1 with GenesisConfigOptions

use of org.hyperledger.besu.config.GenesisConfigOptions in project besu by hyperledger.

the class JsonBlockImporter method createBlock.

private Block createBlock(final BlockData blockData, final BlockHeader parentHeader, final List<Transaction> transactions) {
    final MiningCoordinator miner = controller.getMiningCoordinator();
    final GenesisConfigOptions genesisConfigOptions = controller.getGenesisConfigOptions();
    setOptionalFields(miner, blockData, genesisConfigOptions);
    // Some MiningCoordinator's (specific to consensus type) do not support block-level imports
    return miner.createBlock(parentHeader, transactions, Collections.emptyList()).orElseThrow(() -> new IllegalArgumentException("Unable to create block using current consensus engine: " + genesisConfigOptions.getConsensusEngine()));
}
Also used : GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) MiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator)

Example 2 with GenesisConfigOptions

use of org.hyperledger.besu.config.GenesisConfigOptions in project besu by hyperledger.

the class EthNetworkConfig method getNetworkConfig.

public static EthNetworkConfig getNetworkConfig(final NetworkName networkName) {
    final String genesisContent = jsonConfig(networkName.getGenesisFile());
    final GenesisConfigOptions genesisConfigOptions = GenesisConfigFile.fromConfig(genesisContent).getConfigOptions();
    final Optional<List<String>> rawBootNodes = genesisConfigOptions.getDiscoveryOptions().getBootNodes();
    final List<EnodeURL> bootNodes = rawBootNodes.map(strings -> strings.stream().map(EnodeURLImpl::fromString).collect(Collectors.toList())).orElse(Collections.emptyList());
    return new EthNetworkConfig(genesisContent, networkName.getNetworkId(), bootNodes, genesisConfigOptions.getDiscoveryOptions().getDiscoveryDnsUrl().orElse(null));
}
Also used : EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) EnodeURLImpl(org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl) UTF_8(java.nio.charset.StandardCharsets.UTF_8) IOException(java.io.IOException) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) Collectors(java.util.stream.Collectors) EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) Objects(java.util.Objects) List(java.util.List) GenesisConfigFile(org.hyperledger.besu.config.GenesisConfigFile) Optional(java.util.Optional) BigInteger(java.math.BigInteger) Collections(java.util.Collections) InputStream(java.io.InputStream) List(java.util.List) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions)

Example 3 with GenesisConfigOptions

use of org.hyperledger.besu.config.GenesisConfigOptions in project besu by hyperledger.

the class GenerateBlockchainConfig method processEcCurve.

/**
 * Sets the selected signature algorithm instance in SignatureAlgorithmFactory.
 */
private void processEcCurve() {
    GenesisConfigOptions options = GenesisConfigFile.fromConfig(genesisConfig).getConfigOptions();
    Optional<String> ecCurve = options.getEcCurve();
    if (ecCurve.isEmpty()) {
        SignatureAlgorithmFactory.setInstance(SignatureAlgorithmType.createDefault());
        return;
    }
    try {
        SignatureAlgorithmFactory.setInstance(SignatureAlgorithmType.create(ecCurve.get()));
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(new StringBuilder().append("Invalid parameter for ecCurve in genesis config: ").append(e.getMessage()).toString());
    }
}
Also used : GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) JsonGenesisConfigOptions(org.hyperledger.besu.config.JsonGenesisConfigOptions)

Example 4 with GenesisConfigOptions

use of org.hyperledger.besu.config.GenesisConfigOptions in project besu by hyperledger.

the class CliqueProtocolScheduleTest method protocolSpecsAreCreatedAtBlockDefinedInJson.

@Test
public void protocolSpecsAreCreatedAtBlockDefinedInJson() {
    final String jsonInput = "{\"config\": " + "{\"chainId\": 4,\n" + "\"homesteadBlock\": 1,\n" + "\"eip150Block\": 2,\n" + "\"eip158Block\": 3,\n" + "\"byzantiumBlock\": 1035301}" + "}";
    final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions();
    final ProtocolSchedule protocolSchedule = CliqueProtocolSchedule.create(config, NODE_KEY, false, EvmConfiguration.DEFAULT);
    final ProtocolSpec homesteadSpec = protocolSchedule.getByBlockNumber(1);
    final ProtocolSpec tangerineWhistleSpec = protocolSchedule.getByBlockNumber(2);
    final ProtocolSpec spuriousDragonSpec = protocolSchedule.getByBlockNumber(3);
    final ProtocolSpec byzantiumSpec = protocolSchedule.getByBlockNumber(1035301);
    assertThat(homesteadSpec.equals(tangerineWhistleSpec)).isFalse();
    assertThat(tangerineWhistleSpec.equals(spuriousDragonSpec)).isFalse();
    assertThat(spuriousDragonSpec.equals(byzantiumSpec)).isFalse();
}
Also used : ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) Test(org.junit.Test)

Example 5 with GenesisConfigOptions

use of org.hyperledger.besu.config.GenesisConfigOptions in project besu by hyperledger.

the class CliqueProtocolScheduleTest method shouldValidateBaseFeeMarketTransition.

@Test
public void shouldValidateBaseFeeMarketTransition() {
    final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture();
    final String jsonInput = "{\"config\": " + "\t{\"chainId\": 1337,\n" + "\t\"londonBlock\": 2}\n" + "}";
    final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions();
    final ProtocolSchedule protocolSchedule = CliqueProtocolSchedule.create(config, NODE_KEY, false, EvmConfiguration.DEFAULT);
    BlockHeader emptyFrontierParent = headerBuilder.number(0).mixHash(Hash.fromHexStringLenient("0x0")).gasLimit(5000L).timestamp(Instant.now().getEpochSecond() - 30L).buildHeader();
    // legacy FeeMarket block
    BlockHeader emptyFrontierBlock1 = headerBuilder.number(1).timestamp(Instant.now().getEpochSecond() - 15L).parentHash(emptyFrontierParent.getHash()).buildHeader();
    // premature BaseFeeMarket block
    BlockHeader emptyLondonBlock1 = headerBuilder.baseFeePerGas(Wei.of(1000000000L)).gasLimit(10000L).buildHeader();
    // first BaseFeeMarket block
    BlockHeader emptyLondonBlock2 = headerBuilder.number(2).timestamp(Instant.now().getEpochSecond()).parentHash(emptyFrontierBlock1.getHash()).buildHeader();
    // assert block 1 validates (no fee market)
    assertThat(validateHeaderByProtocolSchedule(protocolSchedule, emptyFrontierBlock1, emptyFrontierParent)).isTrue();
    // assert block 1 with a base fee fails
    assertThat(validateHeaderByProtocolSchedule(protocolSchedule, emptyLondonBlock1, emptyFrontierParent)).isFalse();
    // assert block 2 with a base fee validates (has fee market)
    assertThat(validateHeaderByProtocolSchedule(protocolSchedule, emptyLondonBlock2, emptyFrontierBlock1)).isTrue();
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Test(org.junit.Test)

Aggregations

GenesisConfigOptions (org.hyperledger.besu.config.GenesisConfigOptions)24 Test (org.junit.Test)16 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)6 Address (org.hyperledger.besu.datatypes.Address)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 ExecutionContextTestFixture (org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture)4 ProtocolScheduleBuilder (org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder)4 BigInteger (java.math.BigInteger)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 BftConfigOptions (org.hyperledger.besu.config.BftConfigOptions)3 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)3 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)3 BaseFeePendingTransactionsSorter (org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter)3 EpochCalculator (org.hyperledger.besu.ethereum.mainnet.EpochCalculator)3 PoWSolver (org.hyperledger.besu.ethereum.mainnet.PoWSolver)3 FeeMarket (org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket)3 EvmConfiguration (org.hyperledger.besu.evm.internal.EvmConfiguration)3 IOException (java.io.IOException)2 Collections (java.util.Collections)2