Skip to content

Commit

Permalink
WIP remove use of global quorum config
Browse files Browse the repository at this point in the history
Signed-off-by: Taccat Isid <taccatisid@protonmail.com>
  • Loading branch information
taccatisid committed Oct 11, 2021
1 parent 2591f11 commit b6dd25e
Show file tree
Hide file tree
Showing 163 changed files with 1,077 additions and 433 deletions.
4 changes: 3 additions & 1 deletion besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,9 @@ public Runner build() {
if (graphQLConfiguration.isEnabled()) {
final GraphQLDataFetchers fetchers =
new GraphQLDataFetchers(
supportedCapabilities, privacyParameters.getGoQuorumPrivacyParameters());
supportedCapabilities,
besuController.getGenesisConfigOptions(),
privacyParameters.getGoQuorumPrivacyParameters());
final GraphQLDataFetcherContextImpl dataFetcherContext =
new GraphQLDataFetcherContextImpl(
blockchainQueries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public RlpBlockImporter.ImportResult importBlockchain(
blocks,
rlp ->
BlockHeader.readFrom(
rlp, ScheduleBasedBlockHeaderFunctions.create(protocolSchedule)))) {
rlp, ScheduleBasedBlockHeaderFunctions.create(protocolSchedule)),
besuController.getGenesisConfigOptions())) {
BlockHeader previousHeader = null;
CompletableFuture<Void> previousBlockFuture = null;
final AtomicReference<Throwable> threadedException = new AtomicReference<>();
Expand Down
44 changes: 26 additions & 18 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
import org.hyperledger.besu.cli.util.VersionProvider;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.config.GoQuorumOptions;
import org.hyperledger.besu.consensus.qbft.pki.PkiBlockCreationConfiguration;
import org.hyperledger.besu.consensus.qbft.pki.PkiBlockCreationConfigurationProvider;
import org.hyperledger.besu.controller.BesuController;
Expand Down Expand Up @@ -1204,10 +1203,8 @@ public void run() {

// Set the goquorum compatibility mode based on the genesis file
if (genesisFile != null) {
genesisConfigOptions = readGenesisConfigOptions();
genesisConfigOptions = readGenesisConfigOptions(false);
if (genesisConfigOptions.isQuorum()) {
// this static flag is read by the RLP decoder
GoQuorumOptions.goQuorumCompatibilityMode = true;
isGoQuorumCompatibilityMode = true;
}
}
Expand Down Expand Up @@ -1517,18 +1514,6 @@ private void validateDnsOptionsParams() {
}
}

private GenesisConfigOptions readGenesisConfigOptions() {
final GenesisConfigOptions genesisConfigOptions;
try {
final GenesisConfigFile genesisConfigFile = GenesisConfigFile.fromConfig(genesisConfig());
genesisConfigOptions = genesisConfigFile.getConfigOptions(genesisConfigOverrides);
} catch (final Exception e) {
throw new ParameterException(
this.commandLine, "Unable to load genesis file. " + e.getCause());
}
return genesisConfigOptions;
}

private void issueOptionWarnings() {
// Check that P2P options are able to work
CommandLineUtils.checkOptionDependencies(
Expand Down Expand Up @@ -2276,7 +2261,7 @@ private KeyValueStorageProvider keyValueStorageProvider(final String name) {
"No KeyValueStorageFactory found for key: " + name)))
.withCommonConfiguration(pluginCommonConfiguration)
.withMetricsSystem(getMetricsSystem())
.isGoQuorumCompatibilityMode(isGoQuorumCompatibilityMode.booleanValue())
.withGenesisOptions(readGenesisConfigOptions(true))
.build();
}
return this.keyValueStorageProvider;
Expand Down Expand Up @@ -2512,8 +2497,23 @@ private EthNetworkConfig updateNetworkConfig(final NetworkName network) {
return builder.build();
}

private GenesisConfigOptions readGenesisConfigOptions(final boolean enableDefaultFallback) {
try {
GenesisConfigFile genesisConfigFile = getGenesisConfigFile(enableDefaultFallback);
return genesisConfigFile.getConfigOptions(genesisConfigOverrides);
} catch (final Exception e) {
throw new ParameterException(
this.commandLine, "Unable to load genesis file. " + e.getCause());
}
}

private GenesisConfigFile getGenesisConfigFile() {
return GenesisConfigFile.fromConfig(genesisConfig());
return getGenesisConfigFile(false);
}

private GenesisConfigFile getGenesisConfigFile(final boolean enableDefaultFallback) {
String genesisConfig = enableDefaultFallback ? genesisConfigOrDefault() : genesisConfig();
return GenesisConfigFile.fromConfig(genesisConfig);
}

private String genesisConfig() {
Expand All @@ -2525,6 +2525,14 @@ private String genesisConfig() {
}
}

private String genesisConfigOrDefault() {
if (genesisFile == null) {
return updateNetworkConfig(getNetwork()).getGenesisConfig();
} else {
return genesisConfig();
}
}

// dataDir() is public because it is accessed by subcommands
public Path dataDir() {
return dataPath.toAbsolutePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,13 @@ private void restoreBlocks() throws IOException {
final BlockHeader header =
BlockHeader.readFrom(
new BytesValueRLPInput(Bytes.wrap(headerEntry), false, true), functions);
final boolean goQuorumCompatibilityMode =
besuController.getGenesisConfigOptions().isQuorum();
final BlockBody body =
BlockBody.readFrom(
new BytesValueRLPInput(Bytes.wrap(bodyEntry), false, true), functions);
new BytesValueRLPInput(Bytes.wrap(bodyEntry), false, true),
functions,
goQuorumCompatibilityMode);
final RLPInput receiptsRlp = new BytesValueRLPInput(Bytes.wrap(receiptEntry), false, true);
final int receiptsCount = receiptsRlp.enterList();
final List<TransactionReceipt> receipts = new ArrayList<>(receiptsCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static com.google.common.base.Preconditions.checkNotNull;

import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.consensus.qbft.pki.PkiBlockCreationConfiguration;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.datatypes.Hash;
Expand Down Expand Up @@ -103,6 +104,7 @@ public abstract class BesuControllerBuilder {
private boolean isPruningEnabled;
private PrunerConfiguration prunerConfiguration;
Map<String, String> genesisConfigOverrides;
GenesisConfigOptions genesisConfigOptions;
private Map<Long, Hash> requiredBlocks = Collections.emptyMap();
private long reorgLoggingThreshold;
private DataStorageConfiguration dataStorageConfiguration =
Expand All @@ -117,6 +119,8 @@ public BesuControllerBuilder storageProvider(final StorageProvider storageProvid

public BesuControllerBuilder genesisConfigFile(final GenesisConfigFile genesisConfig) {
this.genesisConfig = genesisConfig;
genesisConfigOptions = genesisConfig.getConfigOptions(genesisConfigOverrides);

return this;
}

Expand Down Expand Up @@ -203,6 +207,7 @@ public BesuControllerBuilder pruningConfiguration(final PrunerConfiguration prun
public BesuControllerBuilder genesisConfigOverrides(
final Map<String, String> genesisConfigOverrides) {
this.genesisConfigOverrides = genesisConfigOverrides;
genesisConfigOptions = genesisConfig.getConfigOptions(genesisConfigOverrides);
return this;
}

Expand Down Expand Up @@ -341,7 +346,8 @@ public BesuController build() {
syncState,
dataDirectory,
clock,
metricsSystem);
metricsSystem,
genesisConfigOptions);

final MiningCoordinator miningCoordinator =
createMiningCoordinator(
Expand Down Expand Up @@ -434,6 +440,7 @@ protected EthProtocolManager createEthProtocolManager(
protocolContext.getWorldStateArchive(),
transactionPool,
ethereumWireProtocolConfiguration,
genesisConfigOptions,
ethPeers,
ethMessages,
ethContext,
Expand All @@ -460,16 +467,14 @@ private WorldStateArchive createWorldStateArchive(
private List<PeerValidator> createPeerValidators(final ProtocolSchedule protocolSchedule) {
final List<PeerValidator> validators = new ArrayList<>();

final OptionalLong daoBlock =
genesisConfig.getConfigOptions(genesisConfigOverrides).getDaoForkBlock();
final OptionalLong daoBlock = genesisConfigOptions.getDaoForkBlock();
if (daoBlock.isPresent()) {
// Setup dao validator
validators.add(
new DaoForkPeerValidator(protocolSchedule, metricsSystem, daoBlock.getAsLong()));
}

final OptionalLong classicBlock =
genesisConfig.getConfigOptions(genesisConfigOverrides).getClassicForkBlock();
final OptionalLong classicBlock = genesisConfigOptions.getClassicForkBlock();
// setup classic validator
if (classicBlock.isPresent()) {
validators.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected MiningCoordinator createMiningCoordinator(
final UniqueMessageMulticaster uniqueMessageMulticaster =
new UniqueMessageMulticaster(peers, bftConfig.getGossipedHistoryLimit());

final IbftGossip gossiper = new IbftGossip(uniqueMessageMulticaster);
final IbftGossip gossiper = new IbftGossip(protocolSchedule, uniqueMessageMulticaster);

final BftFinalState finalState =
new BftFinalState(
Expand Down Expand Up @@ -183,9 +183,11 @@ protected MiningCoordinator createMiningCoordinator(

final BftEventHandler ibftController =
new IbftController(
protocolSchedule,
blockchain,
finalState,
new IbftBlockHeightManagerFactory(
protocolSchedule,
finalState,
new IbftRoundFactory(
finalState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,15 @@ protected MiningCoordinator createMiningCoordinator(
@Override
protected ProtocolSchedule createProtocolSchedule() {
return IbftProtocolSchedule.create(
genesisConfig.getConfigOptions(genesisConfigOverrides),
privacyParameters,
isRevertReasonEnabled);
genesisConfigOptions, privacyParameters, isRevertReasonEnabled);
}

@Override
protected IbftLegacyContext createConsensusContext(
final Blockchain blockchain,
final WorldStateArchive worldStateArchive,
final ProtocolSchedule protocolSchedule) {
final IbftLegacyConfigOptions ibftConfig =
genesisConfig.getConfigOptions(genesisConfigOverrides).getIbftLegacyConfigOptions();
final IbftLegacyConfigOptions ibftConfig = genesisConfigOptions.getIbftLegacyConfigOptions();
final EpochManager epochManager = new EpochManager(ibftConfig.getEpochLength());
final ValidatorProvider validatorProvider =
BlockValidatorProvider.nonForkingValidatorProvider(
Expand Down Expand Up @@ -132,6 +129,7 @@ protected EthProtocolManager createEthProtocolManager(
protocolContext.getWorldStateArchive(),
transactionPool,
ethereumWireProtocolConfiguration,
genesisConfigOptions,
ethPeers,
ethMessages,
ethContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ protected MiningCoordinator createMiningCoordinator(
final UniqueMessageMulticaster uniqueMessageMulticaster =
new UniqueMessageMulticaster(peers, qbftConfig.getGossipedHistoryLimit());

final QbftGossip gossiper = new QbftGossip(uniqueMessageMulticaster, bftExtraDataCodec().get());
final QbftGossip gossiper =
new QbftGossip(protocolSchedule, uniqueMessageMulticaster, bftExtraDataCodec().get());

final BftFinalState finalState =
new BftFinalState(
Expand Down Expand Up @@ -207,9 +208,11 @@ protected MiningCoordinator createMiningCoordinator(

final BftEventHandler qbftController =
new QbftController(
protocolSchedule,
blockchain,
finalState,
new QbftBlockHeightManagerFactory(
protocolSchedule,
finalState,
new QbftRoundFactory(
finalState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.mockito.Mockito.when;

import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.controller.BesuController;
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.NodeKeyUtils;
Expand Down Expand Up @@ -173,7 +174,7 @@ public void setUp() throws IOException {
.fromGenesisConfig(GenesisConfigFile.development())
.synchronizerConfiguration(SynchronizerConfiguration.builder().build())
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.storageProvider(new InMemoryKeyValueStorageProvider())
.storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions()))
.networkId(BigInteger.ONE)
.miningParameters(
new MiningParameters.Builder()
Expand Down
3 changes: 2 additions & 1 deletion besu/src/test/java/org/hyperledger/besu/PrivacyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.hyperledger.besu.ethereum.core.PrivacyParameters.ONCHAIN_PRIVACY;

import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.controller.BesuController;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.datatypes.Address;
Expand Down Expand Up @@ -105,7 +106,7 @@ private BesuController setUpControllerWithPrivacyEnabled(final boolean onchainEn
.fromGenesisConfig(GenesisConfigFile.mainnet())
.synchronizerConfiguration(SynchronizerConfiguration.builder().build())
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.storageProvider(new InMemoryKeyValueStorageProvider())
.storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions()))
.networkId(BigInteger.ONE)
.miningParameters(new MiningParameters.Builder().enabled(false).build())
.nodeKey(NodeKeyUtils.generate())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.mockito.Mockito.when;

import org.hyperledger.besu.cli.config.EthNetworkConfig;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.consensus.common.bft.BftEventQueue;
import org.hyperledger.besu.consensus.common.bft.network.PeerConnectionTracker;
import org.hyperledger.besu.consensus.common.bft.protocol.BftProtocolManager;
Expand Down Expand Up @@ -160,10 +161,12 @@ public void movingAcrossProtocolSpecsUpdatesNodeRecord() {
final BlockDataGenerator gen = new BlockDataGenerator();
final String p2pAdvertisedHost = "172.0.0.1";
final int p2pListenPort = 30301;
final StorageProvider storageProvider = new InMemoryKeyValueStorageProvider();
final StorageProvider storageProvider =
new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions());
final Block genesisBlock = gen.genesisBlock();
final MutableBlockchain blockchain =
createInMemoryBlockchain(genesisBlock, new MainnetBlockHeaderFunctions());
createInMemoryBlockchain(
new StubGenesisConfigOptions(), genesisBlock, new MainnetBlockHeaderFunctions());
when(besuController.getProtocolContext().getBlockchain()).thenReturn(blockchain);
final Runner runner =
new RunnerBuilder()
Expand Down
6 changes: 4 additions & 2 deletions besu/src/test/java/org/hyperledger/besu/RunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.hyperledger.besu.cli.config.EthNetworkConfig;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.JsonUtil;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.controller.BesuController;
import org.hyperledger.besu.controller.MainnetBesuControllerBuilder;
import org.hyperledger.besu.crypto.KeyPairUtil;
Expand Down Expand Up @@ -207,7 +208,7 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi
.metricsSystem(noOpMetricsSystem)
.permissioningService(new PermissioningServiceImpl())
.staticNodes(emptySet())
.storageProvider(new InMemoryKeyValueStorageProvider())
.storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions()))
.forkIdSupplier(() -> Collections.singletonList(Bytes.EMPTY));

Runner runnerBehind = null;
Expand Down Expand Up @@ -251,7 +252,7 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi
.networkId(networkId)
.miningParameters(new MiningParameters.Builder().enabled(false).build())
.nodeKey(NodeKeyUtils.generate())
.storageProvider(new InMemoryKeyValueStorageProvider())
.storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions()))
.metricsSystem(noOpMetricsSystem)
.privacyParameters(PrivacyParameters.DEFAULT)
.clock(TestClock.fixed())
Expand Down Expand Up @@ -401,6 +402,7 @@ private StorageProvider createKeyValueStorageProvider(final Path dataDir, final
RocksDBMetricsFactory.PUBLIC_ROCKS_DB_METRICS))
.withCommonConfiguration(new BesuConfigurationImpl(dataDir, dbDir))
.withMetricsSystem(new NoOpMetricsSystem())
.withGenesisOptions(new StubGenesisConfigOptions())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.hyperledger.besu.chainimport.RlpBlockImporter;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.controller.BesuController;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.GasLimitCalculator;
Expand Down Expand Up @@ -82,7 +83,7 @@ private static BesuController createController() throws IOException {
.fromGenesisConfig(GenesisConfigFile.mainnet())
.synchronizerConfiguration(SynchronizerConfiguration.builder().build())
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.storageProvider(new InMemoryKeyValueStorageProvider())
.storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions()))
.networkId(BigInteger.ONE)
.miningParameters(new MiningParameters.Builder().enabled(false).build())
.nodeKey(NodeKeyUtils.generate())
Expand Down Expand Up @@ -239,7 +240,8 @@ private RawBlockIterator getBlockIterator(final Path blocks) throws IOException
return new RawBlockIterator(
blocks,
rlp ->
BlockHeader.readFrom(rlp, ScheduleBasedBlockHeaderFunctions.create(protocolSchedule)));
BlockHeader.readFrom(rlp, ScheduleBasedBlockHeaderFunctions.create(protocolSchedule)),
new StubGenesisConfigOptions());
}

private Block getBlock(final Blockchain blockchain, final long blockNumber) {
Expand Down
Loading

0 comments on commit b6dd25e

Please sign in to comment.