Skip to content

Commit

Permalink
rename GenesisConfigFile because it's not a file at all (#8050)
Browse files Browse the repository at this point in the history
Signed-off-by: jflo <[email protected]>
  • Loading branch information
jflo authored and garyschulte committed Dec 20, 2024
1 parent 91dd867 commit 1dec16c
Show file tree
Hide file tree
Showing 71 changed files with 439 additions and 461 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions.LATEST;

import org.hyperledger.besu.config.CliqueConfigOptions;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfig;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition;
import org.hyperledger.besu.tests.acceptance.dsl.condition.blockchain.ExpectBlockNotCreated;
Expand Down Expand Up @@ -89,9 +89,9 @@ public Condition awaitSignerSetChange(final Node node) {

private int cliqueBlockPeriod(final BesuNode node) {
final String config = node.getGenesisConfigProvider().create(emptyList()).get();
final GenesisConfigFile genesisConfigFile = GenesisConfigFile.fromConfig(config);
final GenesisConfig genesisConfig = GenesisConfig.fromConfig(config);
final CliqueConfigOptions cliqueConfigOptions =
genesisConfigFile.getConfigOptions().getCliqueConfigOptions();
genesisConfig.getConfigOptions().getCliqueConfigOptions();
return cliqueConfigOptions.getBlockPeriodSeconds();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.hyperledger.besu.cli.config.EthNetworkConfig;
import org.hyperledger.besu.cli.config.NetworkName;
import org.hyperledger.besu.components.BesuComponent;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfig;
import org.hyperledger.besu.controller.BesuController;
import org.hyperledger.besu.controller.BesuControllerBuilder;
import org.hyperledger.besu.crypto.KeyPairUtil;
Expand Down Expand Up @@ -155,8 +155,8 @@ public void startNode(final BesuNode node) {
networkConfigBuilder.setBootNodes(bootnodes);
node.getConfiguration()
.getGenesisConfig()
.map(GenesisConfigFile::fromConfig)
.ifPresent(networkConfigBuilder::setGenesisConfigFile);
.map(GenesisConfig::fromConfig)
.ifPresent(networkConfigBuilder::setGenesisConfig);
final EthNetworkConfig ethNetworkConfig = networkConfigBuilder.build();
final BesuControllerBuilder builder = component.besuControllerBuilder();
builder.isRevertReasonEnabled(node.isRevertReasonEnabled());
Expand All @@ -166,9 +166,7 @@ public void startNode(final BesuNode node) {
builder.nodeKey(new NodeKey(new KeyPairSecurityModule(KeyPairUtil.loadKeyPair(dataDir))));
builder.privacyParameters(node.getPrivacyParameters());

node.getGenesisConfig()
.map(GenesisConfigFile::fromConfig)
.ifPresent(builder::genesisConfigFile);
node.getGenesisConfig().map(GenesisConfig::fromConfig).ifPresent(builder::genesisConfig);

final BesuController besuController = component.besuController();

Expand Down
18 changes: 9 additions & 9 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
import org.hyperledger.besu.cli.util.VersionProvider;
import org.hyperledger.besu.components.BesuComponent;
import org.hyperledger.besu.config.CheckpointConfigOptions;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfig;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.config.MergeConfiguration;
import org.hyperledger.besu.controller.BesuController;
Expand Down Expand Up @@ -332,8 +332,8 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
new PreSynchronizationTaskRunner();

private final Set<Integer> allocatedPorts = new HashSet<>();
private final Supplier<GenesisConfigFile> genesisConfigFileSupplier =
Suppliers.memoize(this::readGenesisConfigFile);
private final Supplier<GenesisConfig> genesisConfigSupplier =
Suppliers.memoize(this::readGenesisConfig);
private final Supplier<GenesisConfigOptions> genesisConfigOptionsSupplier =
Suppliers.memoize(this::readGenesisConfigOptions);
private final Supplier<MiningConfiguration> miningParametersSupplier =
Expand Down Expand Up @@ -1587,21 +1587,21 @@ private void validateChainDataPruningParams() {
}
}

private GenesisConfigFile readGenesisConfigFile() {
GenesisConfigFile effectiveGenesisFile;
private GenesisConfig readGenesisConfig() {
GenesisConfig effectiveGenesisFile;
effectiveGenesisFile =
network.equals(EPHEMERY)
? EphemeryGenesisUpdater.updateGenesis(genesisConfigOverrides)
: genesisFile != null
? GenesisConfigFile.fromSource(genesisConfigSource(genesisFile))
: GenesisConfigFile.fromResource(
? GenesisConfig.fromSource(genesisConfigSource(genesisFile))
: GenesisConfig.fromResource(
Optional.ofNullable(network).orElse(MAINNET).getGenesisFile());
return effectiveGenesisFile.withOverrides(genesisConfigOverrides);
}

private GenesisConfigOptions readGenesisConfigOptions() {
try {
return genesisConfigFileSupplier.get().getConfigOptions();
return genesisConfigSupplier.get().getConfigOptions();
} catch (final Exception e) {
throw new ParameterException(
this.commandLine, "Unable to load genesis file. " + e.getCause());
Expand Down Expand Up @@ -2337,7 +2337,7 @@ private EthNetworkConfig updateNetworkConfig(final NetworkName network) {
builder.setDnsDiscoveryUrl(null);
}

builder.setGenesisConfigFile(genesisConfigFileSupplier.get());
builder.setGenesisConfig(genesisConfigSupplier.get());

if (networkId != null) {
builder.setNetworkId(networkId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.hyperledger.besu.cli.config;

import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfig;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl;
import org.hyperledger.besu.plugin.data.EnodeURL;
Expand All @@ -33,29 +33,29 @@
/**
* The Eth network config.
*
* @param genesisConfigFile Genesis Config File
* @param genesisConfig Genesis Config File
* @param networkId Network Id
* @param bootNodes Boot Nodes
* @param dnsDiscoveryUrl DNS Discovery URL
*/
public record EthNetworkConfig(
GenesisConfigFile genesisConfigFile,
GenesisConfig genesisConfig,
BigInteger networkId,
List<EnodeURL> bootNodes,
String dnsDiscoveryUrl) {

/**
* Validate parameters on new record creation
*
* @param genesisConfigFile the genesis config
* @param genesisConfig the genesis config
* @param networkId the network id
* @param bootNodes the boot nodes
* @param dnsDiscoveryUrl the dns discovery url
*/
@SuppressWarnings(
"MethodInputParametersMustBeFinal") // needed since record constructors are not yet supported
public EthNetworkConfig {
Objects.requireNonNull(genesisConfigFile);
Objects.requireNonNull(genesisConfig);
Objects.requireNonNull(bootNodes);
}

Expand All @@ -67,8 +67,8 @@ public record EthNetworkConfig(
*/
public static EthNetworkConfig getNetworkConfig(final NetworkName networkName) {
final URL genesisSource = jsonConfigSource(networkName.getGenesisFile());
final GenesisConfigFile genesisConfigFile = GenesisConfigFile.fromSource(genesisSource);
final GenesisConfigOptions genesisConfigOptions = genesisConfigFile.getConfigOptions();
final GenesisConfig genesisConfig = GenesisConfig.fromSource(genesisSource);
final GenesisConfigOptions genesisConfigOptions = genesisConfig.getConfigOptions();
final Optional<List<String>> rawBootNodes =
genesisConfigOptions.getDiscoveryOptions().getBootNodes();
final List<EnodeURL> bootNodes =
Expand All @@ -79,7 +79,7 @@ public static EthNetworkConfig getNetworkConfig(final NetworkName networkName) {
.orElse(Collections.emptyList());

return new EthNetworkConfig(
genesisConfigFile,
genesisConfig,
networkName.getNetworkId(),
bootNodes,
genesisConfigOptions.getDiscoveryOptions().getDiscoveryDnsUrl().orElse(null));
Expand Down Expand Up @@ -108,7 +108,7 @@ public static String jsonConfig(final NetworkName network) {
public static class Builder {

private String dnsDiscoveryUrl;
private GenesisConfigFile genesisConfigFile;
private GenesisConfig genesisConfig;
private BigInteger networkId;
private List<EnodeURL> bootNodes;

Expand All @@ -118,7 +118,7 @@ public static class Builder {
* @param ethNetworkConfig the eth network config
*/
public Builder(final EthNetworkConfig ethNetworkConfig) {
this.genesisConfigFile = ethNetworkConfig.genesisConfigFile;
this.genesisConfig = ethNetworkConfig.genesisConfig;
this.networkId = ethNetworkConfig.networkId;
this.bootNodes = ethNetworkConfig.bootNodes;
this.dnsDiscoveryUrl = ethNetworkConfig.dnsDiscoveryUrl;
Expand All @@ -127,11 +127,11 @@ public Builder(final EthNetworkConfig ethNetworkConfig) {
/**
* Sets genesis config file.
*
* @param genesisConfigFile the genesis config
* @param genesisConfig the genesis config
* @return this builder
*/
public Builder setGenesisConfigFile(final GenesisConfigFile genesisConfigFile) {
this.genesisConfigFile = genesisConfigFile;
public Builder setGenesisConfig(final GenesisConfig genesisConfig) {
this.genesisConfig = genesisConfig;
return this;
}

Expand Down Expand Up @@ -174,7 +174,7 @@ public Builder setDnsDiscoveryUrl(final String dnsDiscoveryUrl) {
* @return the eth network config
*/
public EthNetworkConfig build() {
return new EthNetworkConfig(genesisConfigFile, networkId, bootNodes, dnsDiscoveryUrl);
return new EthNetworkConfig(genesisConfig, networkId, bootNodes, dnsDiscoveryUrl);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import org.hyperledger.besu.cli.DefaultCommandValues;
import org.hyperledger.besu.cli.util.VersionProvider;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfig;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.config.JsonGenesisConfigOptions;
import org.hyperledger.besu.config.JsonUtil;
Expand Down Expand Up @@ -286,7 +286,7 @@ private void parseConfig() throws IOException {

/** Sets the selected signature algorithm instance in SignatureAlgorithmFactory. */
private void processEcCurve() {
GenesisConfigOptions options = GenesisConfigFile.fromConfig(genesisConfig).getConfigOptions();
GenesisConfigOptions options = GenesisConfig.fromConfig(genesisConfig).getConfigOptions();
Optional<String> ecCurve = options.getEcCurve();

if (ecCurve.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package org.hyperledger.besu.controller;

import org.hyperledger.besu.cli.config.EthNetworkConfig;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfig;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.config.PowAlgorithm;
import org.hyperledger.besu.config.QbftConfigOptions;
Expand Down Expand Up @@ -334,24 +334,24 @@ public Builder() {}
*/
public BesuControllerBuilder fromEthNetworkConfig(
final EthNetworkConfig ethNetworkConfig, final SyncMode syncMode) {
return fromGenesisFile(ethNetworkConfig.genesisConfigFile(), syncMode)
return fromGenesisFile(ethNetworkConfig.genesisConfig(), syncMode)
.networkId(ethNetworkConfig.networkId());
}

/**
* From genesis config besu controller builder.
*
* @param genesisConfigFile the genesis config file
* @param genesisConfig the genesis config file
* @param syncMode the sync mode
* @return the besu controller builder
*/
public BesuControllerBuilder fromGenesisFile(
final GenesisConfigFile genesisConfigFile, final SyncMode syncMode) {
final GenesisConfig genesisConfig, final SyncMode syncMode) {
final BesuControllerBuilder builder;
final var configOptions = genesisConfigFile.getConfigOptions();
final var configOptions = genesisConfig.getConfigOptions();

if (configOptions.isConsensusMigration()) {
return createConsensusScheduleBesuControllerBuilder(genesisConfigFile);
return createConsensusScheduleBesuControllerBuilder(genesisConfig);
}

if (configOptions.getPowAlgorithm() != PowAlgorithm.UNSUPPORTED) {
Expand All @@ -373,22 +373,22 @@ public BesuControllerBuilder fromGenesisFile(
if (configOptions.getTerminalTotalDifficulty().isPresent()) {
// Enable start with vanilla MergeBesuControllerBuilder for PoS checkpoint block
if (syncMode == SyncMode.CHECKPOINT && isCheckpointPoSBlock(configOptions)) {
return new MergeBesuControllerBuilder().genesisConfigFile(genesisConfigFile);
return new MergeBesuControllerBuilder().genesisConfig(genesisConfig);
} else {
// TODO this should be changed to vanilla MergeBesuControllerBuilder and the Transition*
// series of classes removed after we successfully transition to PoS
// https://github.com/hyperledger/besu/issues/2897
return new TransitionBesuControllerBuilder(builder, new MergeBesuControllerBuilder())
.genesisConfigFile(genesisConfigFile);
.genesisConfig(genesisConfig);
}

} else return builder.genesisConfigFile(genesisConfigFile);
} else return builder.genesisConfig(genesisConfig);
}

private BesuControllerBuilder createConsensusScheduleBesuControllerBuilder(
final GenesisConfigFile genesisConfigFile) {
final GenesisConfig genesisConfig) {
final Map<Long, BesuControllerBuilder> besuControllerBuilderSchedule = new HashMap<>();
final var configOptions = genesisConfigFile.getConfigOptions();
final var configOptions = genesisConfig.getConfigOptions();

final BesuControllerBuilder originalControllerBuilder;
if (configOptions.isIbft2()) {
Expand All @@ -407,7 +407,7 @@ private BesuControllerBuilder createConsensusScheduleBesuControllerBuilder(
besuControllerBuilderSchedule.put(qbftBlock, new QbftBesuControllerBuilder());

return new ConsensusScheduleBesuControllerBuilder(besuControllerBuilderSchedule)
.genesisConfigFile(genesisConfigFile);
.genesisConfig(genesisConfig);
}

private Long readQbftStartBlockConfig(final QbftConfigOptions qbftConfigOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import org.hyperledger.besu.components.BesuComponent;
import org.hyperledger.besu.config.CheckpointConfigOptions;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfig;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.consensus.merge.MergeContext;
import org.hyperledger.besu.consensus.merge.UnverifiedForkchoiceSupplier;
Expand Down Expand Up @@ -127,7 +127,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
private static final Logger LOG = LoggerFactory.getLogger(BesuControllerBuilder.class);

/** The genesis file */
protected GenesisConfigFile genesisConfigFile;
protected GenesisConfig genesisConfig;

/** The genesis config options; */
protected GenesisConfigOptions genesisConfigOptions;
Expand Down Expand Up @@ -250,8 +250,8 @@ public BesuControllerBuilder storageProvider(final StorageProvider storageProvid
* @param genesisConfig the genesis config
* @return the besu controller builder
*/
public BesuControllerBuilder genesisConfigFile(final GenesisConfigFile genesisConfig) {
this.genesisConfigFile = genesisConfig;
public BesuControllerBuilder genesisConfig(final GenesisConfig genesisConfig) {
this.genesisConfig = genesisConfig;
this.genesisConfigOptions = genesisConfig.getConfigOptions();
return this;
}
Expand Down Expand Up @@ -559,7 +559,7 @@ public BesuControllerBuilder isParallelTxProcessingEnabled(
* @return the besu controller
*/
public BesuController build() {
checkNotNull(genesisConfigFile, "Missing genesis config file");
checkNotNull(genesisConfig, "Missing genesis config file");
checkNotNull(genesisConfigOptions, "Missing genesis config options");
checkNotNull(syncConfig, "Missing sync config");
checkNotNull(ethereumWireProtocolConfiguration, "Missing ethereum protocol configuration");
Expand Down Expand Up @@ -840,11 +840,10 @@ private GenesisState getGenesisState(
return maybeGenesisStateRoot
.map(
genesisStateRoot ->
GenesisState.fromStorage(genesisStateRoot, genesisConfigFile, protocolSchedule))
GenesisState.fromStorage(genesisStateRoot, genesisConfig, protocolSchedule))
.orElseGet(
() ->
GenesisState.fromConfig(
dataStorageConfiguration, genesisConfigFile, protocolSchedule));
GenesisState.fromConfig(dataStorageConfiguration, genesisConfig, protocolSchedule));
}

private TrieLogPruner createTrieLogPruner(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import static org.hyperledger.besu.ethereum.core.BlockHeader.GENESIS_BLOCK_NUMBER;

import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfig;
import org.hyperledger.besu.consensus.common.CombinedProtocolScheduleFactory;
import org.hyperledger.besu.consensus.common.ForkSpec;
import org.hyperledger.besu.consensus.common.ForksSchedule;
Expand Down Expand Up @@ -264,9 +264,9 @@ public BesuControllerBuilder storageProvider(final StorageProvider storageProvid
}

@Override
public BesuControllerBuilder genesisConfigFile(final GenesisConfigFile genesisConfig) {
besuControllerBuilderSchedule.values().forEach(b -> b.genesisConfigFile(genesisConfig));
return super.genesisConfigFile(genesisConfig);
public BesuControllerBuilder genesisConfig(final GenesisConfig genesisConfig) {
besuControllerBuilderSchedule.values().forEach(b -> b.genesisConfig(genesisConfig));
return super.genesisConfig(genesisConfig);
}

@Override
Expand Down
Loading

0 comments on commit 1dec16c

Please sign in to comment.