Skip to content

Commit

Permalink
Refactoring around MiningParameters (hyperledger#7798)
Browse files Browse the repository at this point in the history
decoupled parent block header from block creators
optionalized some fields of ProtocolSchedule constructor, which will allow us to reduce number of constructors later.
Refactored JsonBlockImporterTest so it can provide a BesuComponent
ProtocolScheduleBuilder optionalizes the default chainid
Blocks SubCommand is now Dagger aware
Creates but rarely uses ProtocolSpec and ProtocolSchedule modules. Deeper adoption pending.
Adds a Coinbase module with fixed values for use in testing.
Introduces an EthereumCoreComponent, to be used as a subcomponent of BesuComponent in the future.
Introduces a MiningParameters module with common static values used by tests. Removes MiningParameters static constructor.

---------

Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: jflo <justin+github@florentine.us>
  • Loading branch information
jflo authored Oct 31, 2024
1 parent d846e37 commit 7eb7b87
Show file tree
Hide file tree
Showing 38 changed files with 537 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.hyperledger.besu.metrics.MetricCategoryRegistryImpl;
import org.hyperledger.besu.metrics.MetricsSystemModule;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.plugin.data.EnodeURL;
import org.hyperledger.besu.plugin.services.BesuConfiguration;
Expand Down Expand Up @@ -406,9 +407,18 @@ MetricCategoryRegistryImpl provideMetricCategoryRegistry() {
}
}

@Module
public static class ThreadBesuNodeRunnerModule {
@Provides
@Singleton
public ThreadBesuNodeRunner provideThreadBesuNodeRunner() {
return new ThreadBesuNodeRunner();
}
}

@Module
@SuppressWarnings("CloseableProvides")
static class BesuControllerModule {
public static class BesuControllerModule {
@Provides
@Singleton
public SynchronizerConfiguration provideSynchronizationConfiguration() {
Expand Down Expand Up @@ -579,7 +589,16 @@ BesuConfiguration provideBesuConfiguration(
}

@Module
static class MockBesuCommandModule {
public static class ObservableMetricsSystemModule {
@Provides
@Singleton
public ObservableMetricsSystem provideObservableMetricsSystem() {
return new NoOpMetricsSystem();
}
}

@Module
public static class MockBesuCommandModule {

@Provides
BesuCommand provideBesuCommand(final BesuPluginContextImpl pluginContext) {
Expand Down Expand Up @@ -610,6 +629,8 @@ Logger provideBesuCommandLogger() {
modules = {
ThreadBesuNodeRunner.BesuControllerModule.class,
ThreadBesuNodeRunner.MockBesuCommandModule.class,
ThreadBesuNodeRunner.ObservableMetricsSystemModule.class,
ThreadBesuNodeRunnerModule.class,
BonsaiCachedMerkleTrieLoaderModule.class,
MetricsSystemModule.class,
ThreadBesuNodeRunner.BesuNodeProviderModule.class,
Expand All @@ -625,5 +646,9 @@ public interface AcceptanceTestBesuComponent extends BesuComponent {
RpcEndpointServiceImpl rpcEndpointService();

BlockchainServiceImpl blockchainService();

ObservableMetricsSystem getObservableMetricsSystem();

ThreadBesuNodeRunner getThreadBesuNodeRunner();
}
}
4 changes: 4 additions & 0 deletions acceptance-tests/tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {
api 'org.slf4j:slf4j-api'

implementation project(':crypto:algorithms')
implementation project(':ethereum:eth')

testImplementation project(':acceptance-tests:dsl')
testImplementation project(':acceptance-tests:test-plugins')
Expand All @@ -42,6 +43,7 @@ dependencies {
testImplementation project(':ethereum:api')
testImplementation project(':ethereum:core')
testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
testImplementation project(':ethereum:eth')
testImplementation project(':ethereum:p2p')
testImplementation project(':ethereum:permissioning')
testImplementation project(':ethereum:rlp')
Expand Down Expand Up @@ -78,6 +80,8 @@ dependencies {
testImplementation 'org.web3j:besu'
testImplementation 'org.web3j:core'
testImplementation 'org.wiremock:wiremock'
testImplementation 'com.google.dagger:dagger'
testAnnotationProcessor 'com.google.dagger:dagger-compiler'
testImplementation project(path: ':acceptance-tests:tests:shanghai')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ protected ProtocolSchedule createProtocolSchedule() {
genesisConfigOptions,
forksSchedule,
nodeKey,
privacyParameters,
isRevertReasonEnabled,
evmConfiguration,
miningParameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;

import java.util.Optional;

/** The Mainnet besu controller builder. */
public class MainnetBesuControllerBuilder extends BesuControllerBuilder {

Expand Down Expand Up @@ -95,10 +97,10 @@ protected PluginServiceFactory createAdditionalPluginServices(
protected ProtocolSchedule createProtocolSchedule() {
return MainnetProtocolSchedule.fromConfig(
genesisConfigOptions,
privacyParameters,
isRevertReasonEnabled,
evmConfiguration,
miningParameters,
Optional.of(privacyParameters),
Optional.of(isRevertReasonEnabled),
Optional.of(evmConfiguration),
super.miningParameters,
badBlockManager,
isParallelTxProcessingEnabled,
metricsSystem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class BesuConfigurationImpl implements BesuConfiguration {
private DataStorageConfiguration dataStorageConfiguration;

// defaults
private MiningParameters miningParameters = MiningParameters.newDefault();
private MiningParameters miningParameters;
private Optional<String> rpcHttpHost = Optional.of("http://localhost");
private Optional<Integer> rpcHttpPort = Optional.of(8545);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;

import org.hyperledger.besu.components.BesuCommandModule;
import org.hyperledger.besu.components.BesuComponent;
import org.hyperledger.besu.components.BesuPluginContextModule;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.JsonUtil;
import org.hyperledger.besu.controller.BesuController;
Expand All @@ -36,12 +37,16 @@
import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.components.MiningParametersModule;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.sync.SyncMode;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
import org.hyperledger.besu.ethereum.eth.transactions.BlobCacheModule;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration;
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache.BonsaiCachedMerkleTrieLoader;
import org.hyperledger.besu.evm.internal.EvmConfiguration;
import org.hyperledger.besu.metrics.MetricsSystemModule;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.testutil.TestClock;

Expand All @@ -52,9 +57,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import javax.inject.Singleton;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.io.Resources;
import dagger.Component;
import dagger.Module;
import dagger.Provides;
import org.apache.tuweni.bytes.Bytes;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -465,7 +474,28 @@ protected BesuController createController(final GenesisConfigFile genesisConfigF
.gasLimitCalculator(GasLimitCalculator.constant())
.evmConfiguration(EvmConfiguration.DEFAULT)
.networkConfiguration(NetworkingConfiguration.create())
.besuComponent(mock(BesuComponent.class))
.besuComponent(DaggerJsonBlockImporterTest_JsonBlockImportComponent.builder().build())
.build();
}

@Module
public static class JsonBlockImporterModule {

@Provides
BonsaiCachedMerkleTrieLoader provideCachedMerkleTrieLoaderModule() {
return new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem());
}
}

@Singleton
@Component(
modules = {
BesuCommandModule.class,
MiningParametersModule.class,
MetricsSystemModule.class,
JsonBlockImporterModule.class,
BesuPluginContextModule.class,
BlobCacheModule.class
})
interface JsonBlockImportComponent extends BesuComponent {}
}
2 changes: 2 additions & 0 deletions config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ dependencies {

implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.google.guava:guava'
implementation 'com.google.dagger:dagger'
implementation 'info.picocli:picocli'
implementation 'io.tmio:tuweni-bytes'
implementation 'io.tmio:tuweni-units'
implementation "org.immutables:value-annotations"
annotationProcessor "org.immutables:value"
annotationProcessor 'com.google.dagger:dagger-compiler'

testImplementation project(':testutil')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static ProtocolSchedule create(

return new ProtocolScheduleBuilder(
config,
DEFAULT_CHAIN_ID,
Optional.of(DEFAULT_CHAIN_ID),
specAdapters,
privacyParameters,
isRevertReasonEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

/** Defines the protocol behaviours for a blockchain using a BFT consensus mechanism. */
Expand Down Expand Up @@ -90,7 +91,7 @@ public BftProtocolSchedule createProtocolSchedule(
final ProtocolSchedule protocolSchedule =
new ProtocolScheduleBuilder(
config,
DEFAULT_CHAIN_ID,
Optional.of(DEFAULT_CHAIN_ID),
specAdapters,
privacyParameters,
isRevertReasonEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private BftProtocolSchedule createProtocolSchedule(
final ProtocolScheduleBuilder protocolScheduleBuilder =
new ProtocolScheduleBuilder(
genesisConfigOptions,
BigInteger.ONE,
Optional.of(BigInteger.ONE),
ProtocolSpecAdapters.create(0, Function.identity()),
new PrivacyParameters(),
false,
Expand Down
2 changes: 2 additions & 0 deletions consensus/ibft/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.mockito:mockito-junit-jupiter'
testImplementation 'com.google.dagger:dagger'
testAnnotationProcessor 'com.google.dagger:dagger-compiler'
}
Loading

0 comments on commit 7eb7b87

Please sign in to comment.