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()));
}
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));
}
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());
}
}
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();
}
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();
}
Aggregations