Remove use of generics in ProtocolContext consensus object (#1039)

ProtocolContext uses a generic for the consensus state, which has a very
large footprint across the code to accomplish what it intends to
accomplish.  For every call there are about 61 other lines per call that 
need to be updated, over 1300 lines total.

Instead replace it with java.lang.Class#cast, which provides runtime
security, and use generics to provide the compile time sugar that
allows for chained methods of the appropriate type.  Then remove its
(quite large) footprint from the rest of the code.

Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
pull/1055/head
Danno Ferrin 5 years ago committed by GitHub
parent 7371d56421
commit 01c02e0741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java
  2. 4
      besu/src/main/java/org/hyperledger/besu/Runner.java
  3. 16
      besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
  4. 14
      besu/src/main/java/org/hyperledger/besu/chainimport/JsonBlockImporter.java
  5. 27
      besu/src/main/java/org/hyperledger/besu/chainimport/RlpBlockImporter.java
  6. 14
      besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
  7. 2
      besu/src/main/java/org/hyperledger/besu/cli/presynctasks/PreSynchronizationTask.java
  8. 2
      besu/src/main/java/org/hyperledger/besu/cli/presynctasks/PreSynchronizationTaskRunner.java
  9. 2
      besu/src/main/java/org/hyperledger/besu/cli/presynctasks/PrivateDatabaseMigrationPreSyncTask.java
  10. 23
      besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java
  11. 2
      besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/GenerateLogBloomCache.java
  12. 24
      besu/src/main/java/org/hyperledger/besu/controller/BesuController.java
  13. 65
      besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java
  14. 14
      besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java
  15. 15
      besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java
  16. 12
      besu/src/main/java/org/hyperledger/besu/controller/IbftLegacyBesuControllerBuilder.java
  17. 8
      besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java
  18. 6
      besu/src/main/java/org/hyperledger/besu/util/PrivateStorageMigrationBuilder.java
  19. 10
      besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java
  20. 8
      besu/src/test/java/org/hyperledger/besu/PrivacyTest.java
  21. 14
      besu/src/test/java/org/hyperledger/besu/RunnerTest.java
  22. 8
      besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java
  23. 32
      besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java
  24. 8
      besu/src/test/java/org/hyperledger/besu/chainimport/RlpBlockImporterTest.java
  25. 17
      besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java
  26. 6
      besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java
  27. 4
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/BlockHeaderValidationRulesetFactory.java
  28. 6
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculator.java
  29. 9
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueHelpers.java
  30. 7
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueMiningTracker.java
  31. 25
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java
  32. 8
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreator.java
  33. 7
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockMiner.java
  34. 8
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java
  35. 4
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMiningCoordinator.java
  36. 8
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRule.java
  37. 12
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueExtraDataValidationRule.java
  38. 8
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/headervalidationrules/SignerRateLimitValidationRule.java
  39. 12
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java
  40. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java
  41. 12
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java
  42. 16
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/NodeCanProduceNextBlockTest.java
  43. 6
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java
  44. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java
  45. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMiningCoordinatorTest.java
  46. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java
  47. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueExtraDataValidationRuleTest.java
  48. 9
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java
  49. 8
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/round/IbftRoundIntegrationTest.java
  50. 4
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactory.java
  51. 25
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftProtocolSchedule.java
  52. 7
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/blockcreation/IbftBlockCreator.java
  53. 15
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/blockcreation/IbftBlockCreatorFactory.java
  54. 11
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/headervalidationrules/IbftCoinbaseValidationRule.java
  55. 12
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/headervalidationrules/IbftCommitSealsValidationRule.java
  56. 12
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/headervalidationrules/IbftValidatorsValidationRule.java
  57. 8
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/headervalidationrules/IbftVanityDataValidationRule.java
  58. 12
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/IbftJsonRpcMethods.java
  59. 9
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRound.java
  60. 9
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundFactory.java
  61. 9
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/validation/MessageValidator.java
  62. 12
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/validation/MessageValidatorFactory.java
  63. 26
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java
  64. 9
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/IbftBlockCreatorTest.java
  65. 9
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/headervalidationrules/IbftCoinbaseValidationRuleTest.java
  66. 21
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/headervalidationrules/IbftCommitSealsValidationRuleTest.java
  67. 13
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/headervalidationrules/IbftValidatorsValidationRuleTest.java
  68. 7
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java
  69. 8
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundTest.java
  70. 5
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/RoundChangeManagerTest.java
  71. 6
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/MessageValidatorTest.java
  72. 9
      consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHeaderValidationRulesetFactory.java
  73. 24
      consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftProtocolSchedule.java
  74. 7
      consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/blockcreation/IbftBlockCreator.java
  75. 11
      consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/headervalidationrules/IbftExtraDataValidationRule.java
  76. 9
      consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/IbftBlockHeaderValidationRulesetFactoryTest.java
  77. 9
      consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java
  78. 29
      consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/headervalidationrules/IbftExtraDataValidationRuleTest.java
  79. 4
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/BlockchainImporter.java
  80. 8
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java
  81. 2
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java
  82. 6
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLDataFetcherContext.java
  83. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/BlockAdapterBase.java
  84. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/PendingStateAdapter.java
  85. 4
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java
  86. 6
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java
  87. 6
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceTransaction.java
  88. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/processor/BlockReplay.java
  89. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/TraceFormatter.java
  90. 8
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/flat/FlatTraceGenerator.java
  91. 4
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/flat/RewardTraceGenerator.java
  92. 4
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/DebugJsonRpcMethods.java
  93. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EeaJsonRpcMethods.java
  94. 4
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java
  95. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java
  96. 4
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/NetJsonRpcMethods.java
  97. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivJsonRpcMethods.java
  98. 6
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java
  99. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivxJsonRpcMethods.java
  100. 4
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TraceJsonRpcMethods.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -137,7 +137,7 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
.setBootNodes(bootnodes);
node.getConfiguration().getGenesisConfig().ifPresent(networkConfigBuilder::setGenesisConfig);
final EthNetworkConfig ethNetworkConfig = networkConfigBuilder.build();
final BesuControllerBuilder<?> builder =
final BesuControllerBuilder builder =
new BesuController.Builder().fromEthNetworkConfig(ethNetworkConfig);
final KeyValueStorageProvider storageProvider =
@ -147,7 +147,7 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
.withMetricsSystem(metricsSystem)
.build();
final BesuController<?> besuController =
final BesuController besuController =
builder
.synchronizerConfiguration(new SynchronizerConfiguration.Builder().build())
.dataDirectory(node.homeDirectory())

@ -63,7 +63,7 @@ public class Runner implements AutoCloseable {
private final Optional<WebSocketService> websocketRpc;
private final Optional<MetricsService> metrics;
private final BesuController<?> besuController;
private final BesuController besuController;
private final Path dataDir;
private final Optional<StratumServer> stratumServer;
private final Optional<AutoTransactionLogBloomCachingService>
@ -78,7 +78,7 @@ public class Runner implements AutoCloseable {
final Optional<WebSocketService> websocketRpc,
final Optional<StratumServer> stratumServer,
final Optional<MetricsService> metrics,
final BesuController<?> besuController,
final BesuController besuController,
final Path dataDir,
final Optional<Path> pidPath,
final Optional<TransactionLogBloomCacher> transactionLogBloomCacher,

@ -126,7 +126,7 @@ public class RunnerBuilder {
private static final Logger LOG = LogManager.getLogger();
private Vertx vertx;
private BesuController<?> besuController;
private BesuController besuController;
private NetworkingConfiguration networkingConfiguration = NetworkingConfiguration.create();
private final Collection<Bytes> bannedNodeIds = new ArrayList<>();
@ -159,7 +159,7 @@ public class RunnerBuilder {
return this;
}
public RunnerBuilder besuController(final BesuController<?> besuController) {
public RunnerBuilder besuController(final BesuController besuController) {
this.besuController = besuController;
return this;
}
@ -316,8 +316,8 @@ public class RunnerBuilder {
final SubProtocolConfiguration subProtocolConfiguration =
besuController.getSubProtocolConfiguration();
final ProtocolSchedule<?> protocolSchedule = besuController.getProtocolSchedule();
final ProtocolContext<?> context = besuController.getProtocolContext();
final ProtocolSchedule protocolSchedule = besuController.getProtocolSchedule();
final ProtocolContext context = besuController.getProtocolContext();
final List<SubProtocol> subProtocols = subProtocolConfiguration.getSubProtocols();
final List<ProtocolManager> protocolManagers = subProtocolConfiguration.getProtocolManagers();
@ -597,7 +597,7 @@ public class RunnerBuilder {
private Optional<AccountPermissioningController> buildAccountPermissioningController(
final Optional<PermissioningConfiguration> permissioningConfiguration,
final BesuController<?> besuController,
final BesuController besuController,
final TransactionSimulator transactionSimulator) {
if (permissioningConfiguration.isPresent()) {
@ -646,8 +646,8 @@ public class RunnerBuilder {
}
private Map<String, JsonRpcMethod> jsonRpcMethods(
final ProtocolSchedule<?> protocolSchedule,
final BesuController<?> besuController,
final ProtocolSchedule protocolSchedule,
final BesuController besuController,
final P2PNetwork network,
final BlockchainQueries blockchainQueries,
final Synchronizer synchronizer,
@ -756,7 +756,7 @@ public class RunnerBuilder {
final SubscriptionManager subscriptionManager,
final Map<String, JsonRpcMethod> jsonRpcMethods,
final PrivacyParameters privacyParameters,
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final BlockchainQueries blockchainQueries,
final TransactionPool transactionPool) {

@ -43,18 +43,14 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tuweni.bytes.Bytes;
/**
* Tool for importing blocks with transactions from human-readable json.
*
* @param <C> The consensus algorithm context
*/
public class JsonBlockImporter<C> {
/** Tool for importing blocks with transactions from human-readable json. */
public class JsonBlockImporter {
private static final Logger LOG = LogManager.getLogger();
private final ObjectMapper mapper;
private final BesuController<C> controller;
private final BesuController controller;
public JsonBlockImporter(final BesuController<C> controller) {
public JsonBlockImporter(final BesuController controller) {
this.controller = controller;
mapper = new ObjectMapper();
// Jdk8Module allows us to easily parse {@code Optional} values from json
@ -143,7 +139,7 @@ public class JsonBlockImporter<C> {
}
private void importBlock(final Block block) {
final BlockImporter<C> importer =
final BlockImporter importer =
controller
.getProtocolSchedule()
.getByBlockNumber(block.getHeader().getNumber())

@ -61,15 +61,14 @@ public class RlpBlockImporter implements Closeable {
* @param blocks Path to the file containing the blocks
* @param besuController the BesuController that defines blockchain behavior
* @param skipPowValidation Skip proof of work validation (correct mix hash and difficulty)
* @param <C> the consensus context type
* @return the import result
* @throws IOException On Failure
*/
public <C> RlpBlockImporter.ImportResult importBlockchain(
final Path blocks, final BesuController<C> besuController, final boolean skipPowValidation)
public RlpBlockImporter.ImportResult importBlockchain(
final Path blocks, final BesuController besuController, final boolean skipPowValidation)
throws IOException {
final ProtocolSchedule<C> protocolSchedule = besuController.getProtocolSchedule();
final ProtocolContext<C> context = besuController.getProtocolContext();
final ProtocolSchedule protocolSchedule = besuController.getProtocolSchedule();
final ProtocolContext context = besuController.getProtocolContext();
final MutableBlockchain blockchain = context.getBlockchain();
int count = 0;
@ -96,7 +95,7 @@ public class RlpBlockImporter implements Closeable {
if (previousHeader == null) {
previousHeader = lookupPreviousHeader(blockchain, header);
}
final ProtocolSpec<C> protocolSpec = protocolSchedule.getByBlockNumber(header.getNumber());
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(header.getNumber());
final BlockHeader lastHeader = previousHeader;
final CompletableFuture<Void> validationFuture =
@ -148,13 +147,13 @@ public class RlpBlockImporter implements Closeable {
}
}
private <C> void validateBlock(
final ProtocolSpec<C> protocolSpec,
final ProtocolContext<C> context,
private void validateBlock(
final ProtocolSpec protocolSpec,
final ProtocolContext context,
final BlockHeader previousHeader,
final BlockHeader header,
final boolean skipPowValidation) {
final BlockHeaderValidator<C> blockHeaderValidator = protocolSpec.getBlockHeaderValidator();
final BlockHeaderValidator blockHeaderValidator = protocolSpec.getBlockHeaderValidator();
final boolean validHeader =
blockHeaderValidator.validateHeader(
header,
@ -168,14 +167,14 @@ public class RlpBlockImporter implements Closeable {
}
}
private <C> void evaluateBlock(
final ProtocolContext<C> context,
private void evaluateBlock(
final ProtocolContext context,
final Block block,
final BlockHeader header,
final ProtocolSpec<C> protocolSpec,
final ProtocolSpec protocolSpec,
final boolean skipPowValidation) {
try {
final BlockImporter<C> blockImporter = protocolSpec.getBlockImporter();
final BlockImporter blockImporter = protocolSpec.getBlockImporter();
final boolean blockImported =
blockImporter.importBlock(
context,

@ -198,7 +198,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
private CommandLine commandLine;
private final Supplier<RlpBlockImporter> rlpBlockImporter;
private final Function<BesuController<?>, JsonBlockImporter<?>> jsonBlockImporterFactory;
private final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory;
private final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory;
final NetworkingOptions networkingOptions = NetworkingOptions.create();
@ -995,7 +995,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
private MetricsConfiguration metricsConfiguration;
private Optional<PermissioningConfiguration> permissioningConfiguration;
private Collection<EnodeURL> staticNodes;
private BesuController<?> besuController;
private BesuController besuController;
private BesuConfiguration pluginCommonConfiguration;
private final Supplier<ObservableMetricsSystem> metricsSystem =
Suppliers.memoize(() -> PrometheusMetricsSystem.init(metricsConfiguration()));
@ -1004,7 +1004,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
public BesuCommand(
final Logger logger,
final Supplier<RlpBlockImporter> rlpBlockImporter,
final Function<BesuController<?>, JsonBlockImporter<?>> jsonBlockImporterFactory,
final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory,
final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory,
final RunnerBuilder runnerBuilder,
final BesuController.Builder controllerBuilderFactory,
@ -1027,7 +1027,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
protected BesuCommand(
final Logger logger,
final Supplier<RlpBlockImporter> rlpBlockImporter,
final Function<BesuController<?>, JsonBlockImporter<?>> jsonBlockImporterFactory,
final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory,
final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory,
final RunnerBuilder runnerBuilder,
final BesuController.Builder controllerBuilderFactory,
@ -1389,7 +1389,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
return this;
}
public BesuController<?> buildController() {
public BesuController buildController() {
try {
return getControllerBuilder().build();
} catch (final Exception e) {
@ -1397,7 +1397,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
}
}
public BesuControllerBuilder<?> getControllerBuilder() {
public BesuControllerBuilder getControllerBuilder() {
addConfigurationService();
return controllerBuilderFactory
.fromEthNetworkConfig(updateNetworkConfig(getNetwork()), genesisConfigOverrides)
@ -1898,7 +1898,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
// Blockchain synchronisation from peers.
private void synchronize(
final BesuController<?> controller,
final BesuController controller,
final boolean p2pEnabled,
final boolean peerDiscoveryEnabled,
final EthNetworkConfig ethNetworkConfig,

@ -23,5 +23,5 @@ import org.hyperledger.besu.controller.BesuController;
*/
public interface PreSynchronizationTask {
void run(final BesuController<?> besuController);
void run(final BesuController besuController);
}

@ -27,7 +27,7 @@ public class PreSynchronizationTaskRunner {
tasks.add(task);
}
public void runTasks(final BesuController<?> besuController) {
public void runTasks(final BesuController besuController) {
tasks.forEach(t -> t.run(besuController));
}
}

@ -31,7 +31,7 @@ public class PrivateDatabaseMigrationPreSyncTask implements PreSynchronizationTa
}
@Override
public void run(final BesuController<?> besuController) {
public void run(final BesuController besuController) {
final PrivateStorageMigrationBuilder privateStorageMigrationBuilder =
new PrivateStorageMigrationBuilder(besuController, privacyParameters);
final PrivateStorageMigrationService privateStorageMigrationService =

@ -85,14 +85,14 @@ public class BlocksSubCommand implements Runnable {
private CommandSpec spec; // Picocli injects reference to command spec
private final Supplier<RlpBlockImporter> rlpBlockImporter;
private final Function<BesuController<?>, JsonBlockImporter<?>> jsonBlockImporterFactory;
private final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory;
private final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory;
private final PrintStream out;
public BlocksSubCommand(
final Supplier<RlpBlockImporter> rlpBlockImporter,
final Function<BesuController<?>, JsonBlockImporter<?>> jsonBlockImporterFactory,
final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory,
final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory,
final PrintStream out) {
this.rlpBlockImporter = rlpBlockImporter;
@ -172,7 +172,7 @@ public class BlocksSubCommand implements Runnable {
LOG.info("Import {} block data from {} files", format, blockImportFiles.size());
final Optional<MetricsService> metricsService = initMetrics(parentCommand);
try (final BesuController<?> controller = createController()) {
try (final BesuController controller = createController()) {
for (final Path path : blockImportFiles) {
try {
LOG.info("Importing from {}", path);
@ -214,7 +214,7 @@ public class BlocksSubCommand implements Runnable {
checkNotNull(parentCommand.parentCommand);
}
private BesuController<?> createController() {
private BesuController createController() {
try {
// Set some defaults
return parentCommand
@ -247,16 +247,15 @@ public class BlocksSubCommand implements Runnable {
0.0);
}
private void importJsonBlocks(final BesuController<?> controller, final Path path)
private void importJsonBlocks(final BesuController controller, final Path path)
throws IOException {
final JsonBlockImporter<?> importer =
parentCommand.jsonBlockImporterFactory.apply(controller);
final JsonBlockImporter importer = parentCommand.jsonBlockImporterFactory.apply(controller);
final String jsonData = Files.readString(path);
importer.importChain(jsonData);
}
private void importRlpBlocks(final BesuController<?> controller, final Path path)
private void importRlpBlocks(final BesuController controller, final Path path)
throws IOException {
try (final RlpBlockImporter rlpBlockImporter = parentCommand.rlpBlockImporter.get()) {
rlpBlockImporter.importBlockchain(path, controller, skipPow);
@ -321,7 +320,7 @@ public class BlocksSubCommand implements Runnable {
checkCommand(this, startBlock, endBlock);
final Optional<MetricsService> metricsService = initMetrics(parentCommand);
final BesuController<?> controller = createBesuController();
final BesuController controller = createBesuController();
try {
if (format == BlockExportFormat.RLP) {
exportRlpFormat(controller);
@ -337,12 +336,12 @@ public class BlocksSubCommand implements Runnable {
}
}
private BesuController<?> createBesuController() {
private BesuController createBesuController() {
return parentCommand.parentCommand.buildController();
}
private void exportRlpFormat(final BesuController<?> controller) throws IOException {
final ProtocolContext<?> context = controller.getProtocolContext();
private void exportRlpFormat(final BesuController controller) throws IOException {
final ProtocolContext context = controller.getProtocolContext();
final RlpBlockExporter exporter =
parentCommand.rlpBlockExporterFactory.apply(context.getBlockchain());
exporter.exportBlocks(blocksExportFile, getStartBlock(), getEndBlock());

@ -90,7 +90,7 @@ public class GenerateLogBloomCache implements Runnable {
BLOCKS_PER_BLOOM_CACHE);
}
private BesuController<?> createBesuController() {
private BesuController createBesuController() {
return parentCommand.parentCommand.buildController();
}
}

@ -42,13 +42,13 @@ import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class BesuController<C> implements java.io.Closeable {
public class BesuController implements java.io.Closeable {
private static final Logger LOG = LogManager.getLogger();
public static final String DATABASE_PATH = "database";
public static final String CACHE_PATH = "caches";
private final ProtocolSchedule<C> protocolSchedule;
private final ProtocolContext<C> protocolContext;
private final ProtocolSchedule protocolSchedule;
private final ProtocolContext protocolContext;
private final EthProtocolManager ethProtocolManager;
private final GenesisConfigOptions genesisConfigOptions;
private final SubProtocolConfiguration subProtocolConfiguration;
@ -65,8 +65,8 @@ public class BesuController<C> implements java.io.Closeable {
private final SyncState syncState;
BesuController(
final ProtocolSchedule<C> protocolSchedule,
final ProtocolContext<C> protocolContext,
final ProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext,
final EthProtocolManager ethProtocolManager,
final GenesisConfigOptions genesisConfigOptions,
final SubProtocolConfiguration subProtocolConfiguration,
@ -97,11 +97,11 @@ public class BesuController<C> implements java.io.Closeable {
this.additionalPluginServices = additionalPluginServices;
}
public ProtocolContext<C> getProtocolContext() {
public ProtocolContext getProtocolContext() {
return protocolContext;
}
public ProtocolSchedule<C> getProtocolSchedule() {
public ProtocolSchedule getProtocolSchedule() {
return protocolSchedule;
}
@ -169,11 +169,11 @@ public class BesuController<C> implements java.io.Closeable {
public static class Builder {
public BesuControllerBuilder<?> fromEthNetworkConfig(final EthNetworkConfig ethNetworkConfig) {
public BesuControllerBuilder fromEthNetworkConfig(final EthNetworkConfig ethNetworkConfig) {
return fromEthNetworkConfig(ethNetworkConfig, Collections.emptyMap());
}
public BesuControllerBuilder<?> fromEthNetworkConfig(
public BesuControllerBuilder fromEthNetworkConfig(
final EthNetworkConfig ethNetworkConfig, final Map<String, String> genesisConfigOverrides) {
return fromGenesisConfig(
GenesisConfigFile.fromConfig(ethNetworkConfig.getGenesisConfig()),
@ -181,15 +181,15 @@ public class BesuController<C> implements java.io.Closeable {
.networkId(ethNetworkConfig.getNetworkId());
}
public BesuControllerBuilder<?> fromGenesisConfig(final GenesisConfigFile genesisConfig) {
public BesuControllerBuilder fromGenesisConfig(final GenesisConfigFile genesisConfig) {
return fromGenesisConfig(genesisConfig, Collections.emptyMap());
}
public BesuControllerBuilder<?> fromGenesisConfig(
BesuControllerBuilder fromGenesisConfig(
final GenesisConfigFile genesisConfig, final Map<String, String> genesisConfigOverrides) {
final GenesisConfigOptions configOptions =
genesisConfig.getConfigOptions(genesisConfigOverrides);
final BesuControllerBuilder<?> builder;
final BesuControllerBuilder builder;
if (configOptions.isEthHash()) {
builder = new MainnetBesuControllerBuilder();

@ -72,7 +72,7 @@ import java.util.OptionalLong;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public abstract class BesuControllerBuilder<C> {
public abstract class BesuControllerBuilder {
private static final Logger LOG = LogManager.getLogger();
protected GenesisConfigFile genesisConfig;
@ -94,102 +94,101 @@ public abstract class BesuControllerBuilder<C> {
Map<String, String> genesisConfigOverrides;
private Map<Long, Hash> requiredBlocks = Collections.emptyMap();
public BesuControllerBuilder<C> storageProvider(final StorageProvider storageProvider) {
public BesuControllerBuilder storageProvider(final StorageProvider storageProvider) {
this.storageProvider = storageProvider;
return this;
}
public BesuControllerBuilder<C> genesisConfigFile(final GenesisConfigFile genesisConfig) {
public BesuControllerBuilder genesisConfigFile(final GenesisConfigFile genesisConfig) {
this.genesisConfig = genesisConfig;
return this;
}
public BesuControllerBuilder<C> synchronizerConfiguration(
public BesuControllerBuilder synchronizerConfiguration(
final SynchronizerConfiguration synchronizerConfig) {
this.syncConfig = synchronizerConfig;
return this;
}
public BesuControllerBuilder<C> ethProtocolConfiguration(
public BesuControllerBuilder ethProtocolConfiguration(
final EthProtocolConfiguration ethProtocolConfiguration) {
this.ethereumWireProtocolConfiguration = ethProtocolConfiguration;
return this;
}
public BesuControllerBuilder<C> networkId(final BigInteger networkId) {
public BesuControllerBuilder networkId(final BigInteger networkId) {
this.networkId = networkId;
return this;
}
public BesuControllerBuilder<C> miningParameters(final MiningParameters miningParameters) {
public BesuControllerBuilder miningParameters(final MiningParameters miningParameters) {
this.miningParameters = miningParameters;
return this;
}
public BesuControllerBuilder<C> nodeKey(final NodeKey nodeKey) {
public BesuControllerBuilder nodeKey(final NodeKey nodeKey) {
this.nodeKey = nodeKey;
return this;
}
public BesuControllerBuilder<C> metricsSystem(final ObservableMetricsSystem metricsSystem) {
public BesuControllerBuilder metricsSystem(final ObservableMetricsSystem metricsSystem) {
this.metricsSystem = metricsSystem;
return this;
}
public BesuControllerBuilder<C> privacyParameters(final PrivacyParameters privacyParameters) {
public BesuControllerBuilder privacyParameters(final PrivacyParameters privacyParameters) {
this.privacyParameters = privacyParameters;
return this;
}
public BesuControllerBuilder<C> dataDirectory(final Path dataDirectory) {
public BesuControllerBuilder dataDirectory(final Path dataDirectory) {
this.dataDirectory = dataDirectory;
return this;
}
public BesuControllerBuilder<C> clock(final Clock clock) {
public BesuControllerBuilder clock(final Clock clock) {
this.clock = clock;
return this;
}
public BesuControllerBuilder<C> transactionPoolConfiguration(
public BesuControllerBuilder transactionPoolConfiguration(
final TransactionPoolConfiguration transactionPoolConfiguration) {
this.transactionPoolConfiguration = transactionPoolConfiguration;
return this;
}
public BesuControllerBuilder<C> isRevertReasonEnabled(final boolean isRevertReasonEnabled) {
public BesuControllerBuilder isRevertReasonEnabled(final boolean isRevertReasonEnabled) {
this.isRevertReasonEnabled = isRevertReasonEnabled;
return this;
}
public BesuControllerBuilder<C> isPruningEnabled(final boolean isPruningEnabled) {
public BesuControllerBuilder isPruningEnabled(final boolean isPruningEnabled) {
this.isPruningEnabled = isPruningEnabled;
return this;
}
public BesuControllerBuilder<C> pruningConfiguration(
final PrunerConfiguration prunerConfiguration) {
public BesuControllerBuilder pruningConfiguration(final PrunerConfiguration prunerConfiguration) {
this.prunerConfiguration = prunerConfiguration;
return this;
}
public BesuControllerBuilder<C> genesisConfigOverrides(
public BesuControllerBuilder genesisConfigOverrides(
final Map<String, String> genesisConfigOverrides) {
this.genesisConfigOverrides = genesisConfigOverrides;
return this;
}
public BesuControllerBuilder<C> targetGasLimit(final Optional<Long> targetGasLimit) {
public BesuControllerBuilder targetGasLimit(final Optional<Long> targetGasLimit) {
this.gasLimitCalculator = new GasLimitCalculator(targetGasLimit);
return this;
}
public BesuControllerBuilder<C> requiredBlocks(final Map<Long, Hash> requiredBlocks) {
public BesuControllerBuilder requiredBlocks(final Map<Long, Hash> requiredBlocks) {
this.requiredBlocks = requiredBlocks;
return this;
}
public BesuController<C> build() {
public BesuController build() {
checkNotNull(genesisConfig, "Missing genesis config");
checkNotNull(syncConfig, "Missing sync config");
checkNotNull(ethereumWireProtocolConfiguration, "Missing ethereum protocol configuration");
@ -206,9 +205,9 @@ public abstract class BesuControllerBuilder<C> {
prepForBuild();
final ProtocolSchedule<C> protocolSchedule = createProtocolSchedule();
final ProtocolSchedule protocolSchedule = createProtocolSchedule();
final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule);
final ProtocolContext<C> protocolContext =
final ProtocolContext protocolContext =
ProtocolContext.init(
storageProvider,
genesisState,
@ -287,7 +286,7 @@ public abstract class BesuControllerBuilder<C> {
createPeerValidators(protocolSchedule));
final Synchronizer synchronizer =
new DefaultSynchronizer<>(
new DefaultSynchronizer(
syncConfig,
protocolSchedule,
protocolContext,
@ -324,7 +323,7 @@ public abstract class BesuControllerBuilder<C> {
closeables.add(privacyParameters.getPrivateStorageProvider());
}
return new BesuController<>(
return new BesuController(
protocolSchedule,
protocolContext,
ethProtocolManager,
@ -345,7 +344,7 @@ public abstract class BesuControllerBuilder<C> {
protected void prepForBuild() {}
protected JsonRpcMethods createAdditionalJsonRpcMethodFactory(
final ProtocolContext<C> protocolContext) {
final ProtocolContext protocolContext) {
return apis -> Collections.emptyMap();
}
@ -355,18 +354,18 @@ public abstract class BesuControllerBuilder<C> {
}
protected abstract MiningCoordinator createMiningCoordinator(
ProtocolSchedule<C> protocolSchedule,
ProtocolContext<C> protocolContext,
ProtocolSchedule protocolSchedule,
ProtocolContext protocolContext,
TransactionPool transactionPool,
MiningParameters miningParameters,
SyncState syncState,
EthProtocolManager ethProtocolManager);
protected abstract ProtocolSchedule<C> createProtocolSchedule();
protected abstract ProtocolSchedule createProtocolSchedule();
protected void validateContext(final ProtocolContext<C> context) {}
protected void validateContext(final ProtocolContext context) {}
protected abstract C createConsensusContext(
protected abstract Object createConsensusContext(
Blockchain blockchain, WorldStateArchive worldStateArchive);
protected String getSupportedProtocol() {
@ -374,7 +373,7 @@ public abstract class BesuControllerBuilder<C> {
}
protected EthProtocolManager createEthProtocolManager(
final ProtocolContext<C> protocolContext,
final ProtocolContext protocolContext,
final boolean fastSyncEnabled,
final TransactionPool transactionPool,
final EthProtocolConfiguration ethereumWireProtocolConfiguration,
@ -398,7 +397,7 @@ public abstract class BesuControllerBuilder<C> {
genesisConfig.getForks());
}
private List<PeerValidator> createPeerValidators(final ProtocolSchedule<C> protocolSchedule) {
private List<PeerValidator> createPeerValidators(final ProtocolSchedule protocolSchedule) {
final List<PeerValidator> validators = new ArrayList<>();
final OptionalLong daoBlock =

@ -45,7 +45,7 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class CliqueBesuControllerBuilder extends BesuControllerBuilder<CliqueContext> {
public class CliqueBesuControllerBuilder extends BesuControllerBuilder {
private static final Logger LOG = LogManager.getLogger();
@ -67,14 +67,14 @@ public class CliqueBesuControllerBuilder extends BesuControllerBuilder<CliqueCon
@Override
protected JsonRpcMethods createAdditionalJsonRpcMethodFactory(
final ProtocolContext<CliqueContext> protocolContext) {
final ProtocolContext protocolContext) {
return new CliqueJsonRpcMethods(protocolContext);
}
@Override
protected MiningCoordinator createMiningCoordinator(
final ProtocolSchedule<CliqueContext> protocolSchedule,
final ProtocolContext<CliqueContext> protocolContext,
final ProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext,
final TransactionPool transactionPool,
final MiningParameters miningParameters,
final SyncState syncState,
@ -88,7 +88,7 @@ public class CliqueBesuControllerBuilder extends BesuControllerBuilder<CliqueCon
miningParameters,
new CliqueBlockScheduler(
clock,
protocolContext.getConsensusState().getVoteTallyCache(),
protocolContext.getConsensusState(CliqueContext.class).getVoteTallyCache(),
localAddress,
secondsBetweenBlocks),
epochManager,
@ -107,7 +107,7 @@ public class CliqueBesuControllerBuilder extends BesuControllerBuilder<CliqueCon
}
@Override
protected ProtocolSchedule<CliqueContext> createProtocolSchedule() {
protected ProtocolSchedule createProtocolSchedule() {
return CliqueProtocolSchedule.create(
genesisConfig.getConfigOptions(genesisConfigOverrides),
nodeKey,
@ -116,7 +116,7 @@ public class CliqueBesuControllerBuilder extends BesuControllerBuilder<CliqueCon
}
@Override
protected void validateContext(final ProtocolContext<CliqueContext> context) {
protected void validateContext(final ProtocolContext context) {
final BlockHeader genesisBlockHeader = context.getBlockchain().getGenesisBlock().getHeader();
if (blockInterface.validatorsInBlock(genesisBlockHeader).isEmpty()) {

@ -78,7 +78,7 @@ import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class IbftBesuControllerBuilder extends BesuControllerBuilder<IbftContext> {
public class IbftBesuControllerBuilder extends BesuControllerBuilder {
private static final Logger LOG = LogManager.getLogger();
private IbftEventQueue ibftEventQueue;
@ -94,7 +94,7 @@ public class IbftBesuControllerBuilder extends BesuControllerBuilder<IbftContext
@Override
protected JsonRpcMethods createAdditionalJsonRpcMethodFactory(
final ProtocolContext<IbftContext> protocolContext) {
final ProtocolContext protocolContext) {
return new IbftJsonRpcMethods(protocolContext);
}
@ -108,8 +108,8 @@ public class IbftBesuControllerBuilder extends BesuControllerBuilder<IbftContext
@Override
protected MiningCoordinator createMiningCoordinator(
final ProtocolSchedule<IbftContext> protocolSchedule,
final ProtocolContext<IbftContext> protocolContext,
final ProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext,
final TransactionPool transactionPool,
final MiningParameters miningParameters,
final SyncState syncState,
@ -128,7 +128,8 @@ public class IbftBesuControllerBuilder extends BesuControllerBuilder<IbftContext
// NOTE: peers should not be used for accessing the network as it does not enforce the
// "only send once" filter applied by the UniqueMessageMulticaster.
final VoteTallyCache voteTallyCache = protocolContext.getConsensusState().getVoteTallyCache();
final VoteTallyCache voteTallyCache =
protocolContext.getConsensusState(IbftContext.class).getVoteTallyCache();
final ProposerSelector proposerSelector =
new ProposerSelector(blockchain, blockInterface, true, voteTallyCache);
@ -208,7 +209,7 @@ public class IbftBesuControllerBuilder extends BesuControllerBuilder<IbftContext
}
@Override
protected ProtocolSchedule<IbftContext> createProtocolSchedule() {
protected ProtocolSchedule createProtocolSchedule() {
return IbftProtocolSchedule.create(
genesisConfig.getConfigOptions(genesisConfigOverrides),
privacyParameters,
@ -216,7 +217,7 @@ public class IbftBesuControllerBuilder extends BesuControllerBuilder<IbftContext
}
@Override
protected void validateContext(final ProtocolContext<IbftContext> context) {
protected void validateContext(final ProtocolContext context) {
final BlockHeader genesisBlockHeader = context.getBlockchain().getGenesisBlock().getHeader();
if (blockInterface.validatorsInBlock(genesisBlockHeader).isEmpty()) {

@ -49,7 +49,7 @@ import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class IbftLegacyBesuControllerBuilder extends BesuControllerBuilder<IbftContext> {
public class IbftLegacyBesuControllerBuilder extends BesuControllerBuilder {
private static final Logger LOG = LogManager.getLogger();
private final BlockInterface blockInterface = new IbftLegacyBlockInterface();
@ -63,8 +63,8 @@ public class IbftLegacyBesuControllerBuilder extends BesuControllerBuilder<IbftC
@Override
protected MiningCoordinator createMiningCoordinator(
final ProtocolSchedule<IbftContext> protocolSchedule,
final ProtocolContext<IbftContext> protocolContext,
final ProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext,
final TransactionPool transactionPool,
final MiningParameters miningParameters,
final SyncState syncState,
@ -73,7 +73,7 @@ public class IbftLegacyBesuControllerBuilder extends BesuControllerBuilder<IbftC
}
@Override
protected ProtocolSchedule<IbftContext> createProtocolSchedule() {
protected ProtocolSchedule createProtocolSchedule() {
return IbftProtocolSchedule.create(
genesisConfig.getConfigOptions(genesisConfigOverrides),
privacyParameters,
@ -103,7 +103,7 @@ public class IbftLegacyBesuControllerBuilder extends BesuControllerBuilder<IbftC
}
@Override
protected void validateContext(final ProtocolContext<IbftContext> context) {
protected void validateContext(final ProtocolContext context) {
final BlockHeader genesisBlockHeader = context.getBlockchain().getGenesisBlock().getHeader();
if (blockInterface.validatorsInBlock(genesisBlockHeader).isEmpty()) {
@ -118,7 +118,7 @@ public class IbftLegacyBesuControllerBuilder extends BesuControllerBuilder<IbftC
@Override
protected EthProtocolManager createEthProtocolManager(
final ProtocolContext<IbftContext> protocolContext,
final ProtocolContext protocolContext,
final boolean fastSyncEnabled,
final TransactionPool transactionPool,
final EthProtocolConfiguration ethereumWireProtocolConfiguration,

@ -29,12 +29,12 @@ import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
public class MainnetBesuControllerBuilder extends BesuControllerBuilder<Void> {
public class MainnetBesuControllerBuilder extends BesuControllerBuilder {
@Override
protected MiningCoordinator createMiningCoordinator(
final ProtocolSchedule<Void> protocolSchedule,
final ProtocolContext<Void> protocolContext,
final ProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext,
final TransactionPool transactionPool,
final MiningParameters miningParameters,
final SyncState syncState,
@ -74,7 +74,7 @@ public class MainnetBesuControllerBuilder extends BesuControllerBuilder<Void> {
}
@Override
protected ProtocolSchedule<Void> createProtocolSchedule() {
protected ProtocolSchedule createProtocolSchedule() {
return MainnetProtocolSchedule.fromConfig(
genesisConfig.getConfigOptions(genesisConfigOverrides),
privacyParameters,

@ -28,11 +28,11 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
public class PrivateStorageMigrationBuilder {
private final BesuController<?> besuController;
private final BesuController besuController;
private final PrivacyParameters privacyParameters;
public PrivateStorageMigrationBuilder(
final BesuController<?> besuController, final PrivacyParameters privacyParameters) {
final BesuController besuController, final PrivacyParameters privacyParameters) {
this.besuController = besuController;
this.privacyParameters = privacyParameters;
}
@ -41,7 +41,7 @@ public class PrivateStorageMigrationBuilder {
final Blockchain blockchain = besuController.getProtocolContext().getBlockchain();
final Address privacyPrecompileAddress =
Address.privacyPrecompiled(privacyParameters.getPrivacyAddress());
final ProtocolSchedule<?> protocolSchedule = besuController.getProtocolSchedule();
final ProtocolSchedule protocolSchedule = besuController.getProtocolSchedule();
final WorldStateArchive publicWorldStateArchive =
besuController.getProtocolContext().getWorldStateArchive();
final PrivateStateStorage privateStateStorage = privacyParameters.getPrivateStateStorage();

@ -178,7 +178,7 @@ public class PrivacyReorgTest {
@Test
public void privacyGroupHeadIsTracked() {
// Setup an initial blockchain with one private transaction
final ProtocolContext<?> protocolContext = besuController.getProtocolContext();
final ProtocolContext protocolContext = besuController.getProtocolContext();
final DefaultBlockchain blockchain = (DefaultBlockchain) protocolContext.getBlockchain();
final PrivateStateStorage privateStateStorage = privacyParameters.getPrivateStateStorage();
@ -220,7 +220,7 @@ public class PrivacyReorgTest {
@Test
public void reorgToChainAtEqualHeight() {
// Setup an initial blockchain with one private transaction
final ProtocolContext<?> protocolContext = besuController.getProtocolContext();
final ProtocolContext protocolContext = besuController.getProtocolContext();
final DefaultBlockchain blockchain = (DefaultBlockchain) protocolContext.getBlockchain();
final Block firstBlock =
@ -253,7 +253,7 @@ public class PrivacyReorgTest {
@Test
public void reorgToShorterChain() {
// Setup an initial blockchain with one private transaction
final ProtocolContext<?> protocolContext = besuController.getProtocolContext();
final ProtocolContext protocolContext = besuController.getProtocolContext();
final DefaultBlockchain blockchain = (DefaultBlockchain) protocolContext.getBlockchain();
final String firstBlockStateRoot =
@ -308,7 +308,7 @@ public class PrivacyReorgTest {
@Test
public void reorgToLongerChain() {
// Setup an initial blockchain with one private transaction
final ProtocolContext<?> protocolContext = besuController.getProtocolContext();
final ProtocolContext protocolContext = besuController.getProtocolContext();
final DefaultBlockchain blockchain = (DefaultBlockchain) protocolContext.getBlockchain();
final Block firstBlock =
@ -377,7 +377,7 @@ public class PrivacyReorgTest {
private void appendBlock(
final BesuController besuController,
final DefaultBlockchain blockchain,
final ProtocolContext<?> protocolContext,
final ProtocolContext protocolContext,
final Block block) {
besuController
.getProtocolSchedule()

@ -71,7 +71,7 @@ public class PrivacyTest {
@Test
public void defaultPrivacy() throws IOException, URISyntaxException {
final BesuController<?> besuController = setUpControllerWithPrivacyEnabled(false);
final BesuController besuController = setUpControllerWithPrivacyEnabled(false);
final PrecompiledContract precompiledContract =
getPrecompile(besuController, Address.DEFAULT_PRIVACY);
@ -81,7 +81,7 @@ public class PrivacyTest {
@Test
public void onchainEnabledPrivacy() throws IOException, URISyntaxException {
final BesuController<?> besuController = setUpControllerWithPrivacyEnabled(true);
final BesuController besuController = setUpControllerWithPrivacyEnabled(true);
final PrecompiledContract privacyPrecompiledContract =
getPrecompile(besuController, Address.DEFAULT_PRIVACY);
@ -94,7 +94,7 @@ public class PrivacyTest {
assertThat(onchainPrecompiledContract.getName()).isEqualTo("OnChainPrivacy");
}
private BesuController<?> setUpControllerWithPrivacyEnabled(final boolean onChainEnabled)
private BesuController setUpControllerWithPrivacyEnabled(final boolean onChainEnabled)
throws IOException, URISyntaxException {
final Path dataDir = folder.newFolder().toPath();
final Path dbDir = dataDir.resolve("database");
@ -144,7 +144,7 @@ public class PrivacyTest {
}
private PrecompiledContract getPrecompile(
final BesuController<?> besuController, final Address defaultPrivacy) {
final BesuController besuController, final Address defaultPrivacy) {
return besuController
.getProtocolSchedule()
.getByBlockNumber(1)

@ -152,7 +152,7 @@ public final class RunnerTest {
final BigInteger networkId = BigInteger.valueOf(2929);
// Setup state with block data
try (final BesuController<Void> controller =
try (final BesuController controller =
new MainnetBesuControllerBuilder()
.genesisConfigFile(genesisConfig)
.synchronizerConfiguration(syncConfigAhead)
@ -172,7 +172,7 @@ public final class RunnerTest {
}
// Setup Runner with blocks
final BesuController<Void> controllerAhead =
final BesuController controllerAhead =
new MainnetBesuControllerBuilder()
.genesisConfigFile(genesisConfig)
.synchronizerConfiguration(syncConfigAhead)
@ -235,7 +235,7 @@ public final class RunnerTest {
final MetricsConfiguration behindMetricsConfiguration = metricsConfiguration();
// Setup runner with no block data
final BesuController<Void> controllerBehind =
final BesuController controllerBehind =
new MainnetBesuControllerBuilder()
.genesisConfigFile(genesisConfig)
.synchronizerConfiguration(syncConfigBehind)
@ -424,15 +424,15 @@ public final class RunnerTest {
private static void setupState(
final int count,
final ProtocolSchedule<Void> protocolSchedule,
final ProtocolContext<Void> protocolContext) {
final ProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext) {
final List<Block> blocks = BlockSyncTestUtils.firstBlocks(count + 1);
for (int i = 1; i < count + 1; ++i) {
final Block block = blocks.get(i);
final ProtocolSpec<Void> protocolSpec =
final ProtocolSpec protocolSpec =
protocolSchedule.getByBlockNumber(block.getHeader().getNumber());
final BlockImporter<Void> blockImporter = protocolSpec.getBlockImporter();
final BlockImporter blockImporter = protocolSpec.getBlockImporter();
final boolean result =
blockImporter.importBlock(protocolContext, block, HeaderValidationMode.FULL);
if (!result) {

@ -56,11 +56,11 @@ public final class RlpBlockExporterTest {
@ClassRule public static final TemporaryFolder folder = new TemporaryFolder();
private static Blockchain blockchain;
private static long chainHead;
private static ProtocolSchedule<?> protocolSchedule;
private static ProtocolSchedule protocolSchedule;
@BeforeClass
public static void setupBlockchain() throws IOException {
final BesuController<?> controller = createController();
final BesuController controller = createController();
final Path blocks = folder.newFile("1000.blocks").toPath();
BlockTestUtil.write1000Blocks(blocks);
blockchain = importBlocks(controller, blocks);
@ -68,7 +68,7 @@ public final class RlpBlockExporterTest {
protocolSchedule = controller.getProtocolSchedule();
}
private static Blockchain importBlocks(final BesuController<?> controller, final Path blocksFile)
private static Blockchain importBlocks(final BesuController controller, final Path blocksFile)
throws IOException {
final RlpBlockImporter blockImporter = new RlpBlockImporter();
@ -76,7 +76,7 @@ public final class RlpBlockExporterTest {
return controller.getProtocolContext().getBlockchain();
}
private static BesuController<?> createController() throws IOException {
private static BesuController createController() throws IOException {
final Path dataDir = folder.newFolder().toPath();
return new BesuController.Builder()
.fromGenesisConfig(GenesisConfigFile.mainnet())

@ -80,8 +80,8 @@ public abstract class JsonBlockImporterTest {
@Test
public void importChain_unsupportedConsensusAlgorithm() throws IOException {
final BesuController<?> controller = createController();
final JsonBlockImporter<?> importer = new JsonBlockImporter<>(controller);
final BesuController controller = createController();
final JsonBlockImporter importer = new JsonBlockImporter(controller);
final String jsonData = getFileContents("clique", "blocks-import-valid.json");
@ -108,8 +108,8 @@ public abstract class JsonBlockImporterTest {
@Test
public void importChain_validJson_withBlockNumbers() throws IOException {
final BesuController<?> controller = createController();
final JsonBlockImporter<?> importer = new JsonBlockImporter<>(controller);
final BesuController controller = createController();
final JsonBlockImporter importer = new JsonBlockImporter(controller);
final String jsonData = getFileContents("blocks-import-valid.json");
importer.importChain(jsonData);
@ -199,8 +199,8 @@ public abstract class JsonBlockImporterTest {
@Test
public void importChain_validJson_noBlockIdentifiers() throws IOException {
final BesuController<?> controller = createController();
final JsonBlockImporter<?> importer = new JsonBlockImporter<>(controller);
final BesuController controller = createController();
final JsonBlockImporter importer = new JsonBlockImporter(controller);
final String jsonData = getFileContents("blocks-import-valid-no-block-identifiers.json");
importer.importChain(jsonData);
@ -290,8 +290,8 @@ public abstract class JsonBlockImporterTest {
@Test
public void importChain_validJson_withParentHashes() throws IOException {
final BesuController<?> controller = createController();
final JsonBlockImporter<?> importer = new JsonBlockImporter<>(controller);
final BesuController controller = createController();
final JsonBlockImporter importer = new JsonBlockImporter(controller);
String jsonData = getFileContents("blocks-import-valid.json");
@ -341,8 +341,8 @@ public abstract class JsonBlockImporterTest {
@Test
public void importChain_invalidParent() throws IOException {
final BesuController<?> controller = createController();
final JsonBlockImporter<?> importer = new JsonBlockImporter<>(controller);
final BesuController controller = createController();
final JsonBlockImporter importer = new JsonBlockImporter(controller);
final String jsonData = getFileContents("blocks-import-invalid-bad-parent.json");
@ -353,8 +353,8 @@ public abstract class JsonBlockImporterTest {
@Test
public void importChain_invalidTransaction() throws IOException {
final BesuController<?> controller = createController();
final JsonBlockImporter<?> importer = new JsonBlockImporter<>(controller);
final BesuController controller = createController();
final JsonBlockImporter importer = new JsonBlockImporter(controller);
final String jsonData = getFileContents("blocks-import-invalid-bad-tx.json");
@ -366,8 +366,8 @@ public abstract class JsonBlockImporterTest {
@Test
public void importChain_specialFields() throws IOException {
final BesuController<?> controller = createController();
final JsonBlockImporter<?> importer = new JsonBlockImporter<>(controller);
final BesuController controller = createController();
final JsonBlockImporter importer = new JsonBlockImporter(controller);
final String jsonData = getFileContents("blocks-import-special-fields.json");
@ -404,11 +404,11 @@ public abstract class JsonBlockImporterTest {
return Resources.toString(fileURL, UTF_8);
}
protected BesuController<?> createController() throws IOException {
protected BesuController createController() throws IOException {
return createController(genesisConfigFile);
}
protected BesuController<?> createController(final GenesisConfigFile genesisConfigFile)
protected BesuController createController(final GenesisConfigFile genesisConfigFile)
throws IOException {
final Path dataDir = folder.newFolder().toPath();
return new BesuController.Builder()

@ -57,7 +57,7 @@ public final class RlpBlockImporterTest {
final Path dataDir = folder.newFolder().toPath();
final Path source = dataDir.resolve("1000.blocks");
BlockTestUtil.write1000Blocks(source);
final BesuController<?> targetController =
final BesuController targetController =
new BesuController.Builder()
.fromGenesisConfig(GenesisConfigFile.mainnet())
.synchronizerConfiguration(SynchronizerConfiguration.builder().build())
@ -85,7 +85,7 @@ public final class RlpBlockImporterTest {
final Path dataDir = folder.newFolder().toPath();
final Path source = dataDir.resolve("badpow.blocks");
BlockTestUtil.writeBadPowBlocks(source);
final BesuController<?> targetController =
final BesuController targetController =
new BesuController.Builder()
.fromGenesisConfig(GenesisConfigFile.mainnet())
.synchronizerConfiguration(SynchronizerConfiguration.builder().build())
@ -113,7 +113,7 @@ public final class RlpBlockImporterTest {
final Path dataDir = folder.newFolder().toPath();
final Path source = dataDir.resolve("badpow.blocks");
BlockTestUtil.writeBadPowBlocks(source);
final BesuController<?> targetController =
final BesuController targetController =
new BesuController.Builder()
.fromGenesisConfig(GenesisConfigFile.mainnet())
.synchronizerConfiguration(SynchronizerConfiguration.builder().build())
@ -153,7 +153,7 @@ public final class RlpBlockImporterTest {
throw new IllegalStateException(ex);
}
final BesuController<?> controller =
final BesuController controller =
new BesuController.Builder()
.fromGenesisConfig(GenesisConfigFile.fromConfig(config))
.synchronizerConfiguration(SynchronizerConfiguration.builder().build())

@ -120,14 +120,14 @@ public abstract class CommandTestAbstract {
@Mock protected BesuController.Builder mockControllerBuilderFactory;
@Mock protected BesuControllerBuilder<Void> mockControllerBuilder;
@Mock protected BesuControllerBuilder mockControllerBuilder;
@Mock protected EthProtocolManager mockEthProtocolManager;
@Mock protected ProtocolSchedule<Object> mockProtocolSchedule;
@Mock protected ProtocolContext<Object> mockProtocolContext;
@Mock protected ProtocolSchedule mockProtocolSchedule;
@Mock protected ProtocolContext mockProtocolContext;
@Mock protected BlockBroadcaster mockBlockBroadcaster;
@Mock protected BesuController<Object> mockController;
@Mock protected BesuController mockController;
@Mock protected RlpBlockExporter rlpBlockExporter;
@Mock protected JsonBlockImporter<?> jsonBlockImporter;
@Mock protected JsonBlockImporter jsonBlockImporter;
@Mock protected RlpBlockImporter rlpBlockImporter;
@Mock protected StorageServiceImpl storageService;
@Mock protected SecurityModuleServiceImpl securityModuleService;
@ -277,9 +277,8 @@ public abstract class CommandTestAbstract {
return parseCommand(System.in, args);
}
@SuppressWarnings("unchecked")
private <T> JsonBlockImporter<T> jsonBlockImporterFactory(final BesuController<T> controller) {
return (JsonBlockImporter<T>) jsonBlockImporter;
private JsonBlockImporter jsonBlockImporterFactory(final BesuController controller) {
return jsonBlockImporter;
}
protected TestBesuCommand parseCommand(final InputStream in, final String... args) {
@ -326,7 +325,7 @@ public abstract class CommandTestAbstract {
final NodeKey mockNodeKey,
final SECP256K1.KeyPair keyPair,
final Supplier<RlpBlockImporter> mockBlockImporter,
final Function<BesuController<?>, JsonBlockImporter<?>> jsonBlockImporterFactory,
final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory,
final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory,
final RunnerBuilder mockRunnerBuilder,
final BesuController.Builder controllerBuilderFactory,

@ -80,15 +80,15 @@ public class BesuEventsImplTest {
private static final org.hyperledger.besu.ethereum.core.Transaction TX1 = createTransaction(1);
private static final org.hyperledger.besu.ethereum.core.Transaction TX2 = createTransaction(2);
@Mock private ProtocolSchedule<Void> mockProtocolSchedule;
@Mock private ProtocolContext<Void> mockProtocolContext;
@Mock private ProtocolSchedule mockProtocolSchedule;
@Mock private ProtocolContext mockProtocolContext;
private SyncState syncState;
@Mock private EthPeers mockEthPeers;
@Mock private EthContext mockEthContext;
@Mock private EthMessages mockEthMessages;
@Mock private EthScheduler mockEthScheduler;
@Mock private TransactionValidator mockTransactionValidator;
@Mock private ProtocolSpec<Void> mockProtocolSpec;
@Mock private ProtocolSpec mockProtocolSpec;
@Mock private WorldStateArchive mockWorldStateArchive;
@Mock private WorldState mockWorldState;
private TransactionPool transactionPool;

@ -42,10 +42,10 @@ public class BlockHeaderValidationRulesetFactory {
* @param epochManager an object which determines if a given block is an epoch block.
* @return the header validator.
*/
public static BlockHeaderValidator.Builder<CliqueContext> cliqueBlockHeaderValidator(
public static BlockHeaderValidator.Builder cliqueBlockHeaderValidator(
final long secondsBetweenBlocks, final EpochManager epochManager) {
return new BlockHeaderValidator.Builder<CliqueContext>()
return new BlockHeaderValidator.Builder()
.addRule(new AncestryValidationRule())
.addRule(new GasUsageValidationRule())
.addRule(new GasLimitRangeAndDeltaValidationRule(5000, 0x7fffffffffffffffL))

@ -21,7 +21,7 @@ import org.hyperledger.besu.ethereum.mainnet.DifficultyCalculator;
import java.math.BigInteger;
public class CliqueDifficultyCalculator implements DifficultyCalculator<CliqueContext> {
public class CliqueDifficultyCalculator implements DifficultyCalculator {
private final Address localAddress;
@ -34,11 +34,11 @@ public class CliqueDifficultyCalculator implements DifficultyCalculator<CliqueCo
@Override
public BigInteger nextDifficulty(
final long time, final BlockHeader parent, final ProtocolContext<CliqueContext> context) {
final long time, final BlockHeader parent, final ProtocolContext context) {
final Address nextProposer =
CliqueHelpers.getProposerForBlockAfter(
parent, context.getConsensusState().getVoteTallyCache());
parent, context.getConsensusState(CliqueContext.class).getVoteTallyCache());
return nextProposer.equals(localAddress) ? IN_TURN_DIFFICULTY : OUT_OF_TURN_DIFFICULTY;
}
}

@ -37,11 +37,12 @@ public class CliqueHelpers {
}
public static boolean addressIsAllowedToProduceNextBlock(
final Address candidate,
final ProtocolContext<CliqueContext> protocolContext,
final BlockHeader parent) {
final Address candidate, final ProtocolContext protocolContext, final BlockHeader parent) {
final VoteTally validatorProvider =
protocolContext.getConsensusState().getVoteTallyCache().getVoteTallyAfterBlock(parent);
protocolContext
.getConsensusState(CliqueContext.class)
.getVoteTallyCache()
.getVoteTallyAfterBlock(parent);
if (!validatorProvider.getValidators().contains(candidate)) {
return false;

@ -21,10 +21,9 @@ import org.hyperledger.besu.ethereum.core.BlockHeader;
public class CliqueMiningTracker {
private final Address localAddress;
private final ProtocolContext<CliqueContext> protocolContext;
private final ProtocolContext protocolContext;
public CliqueMiningTracker(
final Address localAddress, final ProtocolContext<CliqueContext> protocolContext) {
public CliqueMiningTracker(final Address localAddress, final ProtocolContext protocolContext) {
this.localAddress = localAddress;
this.protocolContext = protocolContext;
}
@ -32,7 +31,7 @@ public class CliqueMiningTracker {
public boolean isProposerAfter(final BlockHeader header) {
final Address nextProposer =
CliqueHelpers.getProposerForBlockAfter(
header, protocolContext.getConsensusState().getVoteTallyCache());
header, protocolContext.getConsensusState(CliqueContext.class).getVoteTallyCache());
return localAddress.equals(nextProposer);
}

@ -36,7 +36,7 @@ public class CliqueProtocolSchedule {
private static final BigInteger DEFAULT_CHAIN_ID = BigInteger.valueOf(4);
public static ProtocolSchedule<CliqueContext> create(
public static ProtocolSchedule create(
final GenesisConfigOptions config,
final NodeKey nodeKey,
final PrivacyParameters privacyParameters,
@ -47,7 +47,7 @@ public class CliqueProtocolSchedule {
final Address localNodeAddress = Util.publicKeyToAddress(nodeKey.getPublicKey());
final EpochManager epochManager = new EpochManager(cliqueConfig.getEpochLength());
return new ProtocolScheduleBuilder<>(
return new ProtocolScheduleBuilder(
config,
DEFAULT_CHAIN_ID,
builder ->
@ -58,28 +58,29 @@ public class CliqueProtocolSchedule {
.createProtocolSchedule();
}
public static ProtocolSchedule<CliqueContext> create(
public static ProtocolSchedule create(
final GenesisConfigOptions config,
final NodeKey nodeKey,
final boolean isRevertReasonEnabled) {
return create(config, nodeKey, PrivacyParameters.DEFAULT, isRevertReasonEnabled);
}
private static ProtocolSpecBuilder<CliqueContext> applyCliqueSpecificModifications(
private static ProtocolSpecBuilder applyCliqueSpecificModifications(
final EpochManager epochManager,
final long secondsBetweenBlocks,
final Address localNodeAddress,
final ProtocolSpecBuilder<Void> specBuilder) {
final ProtocolSpecBuilder specBuilder) {
return specBuilder
.changeConsensusContextType(
.blockHeaderValidatorBuilder(
BlockHeaderValidationRulesetFactory.cliqueBlockHeaderValidator(
secondsBetweenBlocks, epochManager),
secondsBetweenBlocks, epochManager))
.ommerHeaderValidatorBuilder(
BlockHeaderValidationRulesetFactory.cliqueBlockHeaderValidator(
secondsBetweenBlocks, epochManager),
MainnetBlockBodyValidator::new,
MainnetBlockValidator::new,
MainnetBlockImporter::new,
new CliqueDifficultyCalculator(localNodeAddress))
secondsBetweenBlocks, epochManager))
.blockBodyValidatorBuilder(MainnetBlockBodyValidator::new)
.blockValidatorBuilder(MainnetBlockValidator::new)
.blockImporterBuilder(MainnetBlockImporter::new)
.difficultyCalculator(new CliqueDifficultyCalculator(localNodeAddress))
.blockReward(Wei.ZERO)
.skipZeroBlockRewards(true)
.miningBeneficiaryCalculator(CliqueHelpers::getProposerOfBlock)

@ -39,7 +39,7 @@ import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions;
import java.util.Optional;
import java.util.function.Function;
public class CliqueBlockCreator extends AbstractBlockCreator<CliqueContext> {
public class CliqueBlockCreator extends AbstractBlockCreator {
private final NodeKey nodeKey;
private final EpochManager epochManager;
@ -48,8 +48,8 @@ public class CliqueBlockCreator extends AbstractBlockCreator<CliqueContext> {
final Address coinbase,
final ExtraDataCalculator extraDataCalculator,
final PendingTransactions pendingTransactions,
final ProtocolContext<CliqueContext> protocolContext,
final ProtocolSchedule<CliqueContext> protocolSchedule,
final ProtocolContext protocolContext,
final ProtocolSchedule protocolSchedule,
final Function<Long, Long> gasLimitCalculator,
final NodeKey nodeKey,
final Wei minTransactionGasPrice,
@ -105,7 +105,7 @@ public class CliqueBlockCreator extends AbstractBlockCreator<CliqueContext> {
if (epochManager.isEpochBlock(sealableBlockHeader.getNumber())) {
return Optional.empty();
} else {
final CliqueContext cliqueContext = protocolContext.getConsensusState();
final CliqueContext cliqueContext = protocolContext.getConsensusState(CliqueContext.class);
final VoteTally voteTally =
cliqueContext.getVoteTallyCache().getVoteTallyAfterBlock(parentHeader);
return cliqueContext

@ -14,7 +14,6 @@
*/
package org.hyperledger.besu.consensus.clique.blockcreation;
import org.hyperledger.besu.consensus.clique.CliqueContext;
import org.hyperledger.besu.consensus.clique.CliqueHelpers;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.AbstractBlockScheduler;
@ -27,14 +26,14 @@ import org.hyperledger.besu.util.Subscribers;
import java.util.function.Function;
public class CliqueBlockMiner extends BlockMiner<CliqueContext, CliqueBlockCreator> {
public class CliqueBlockMiner extends BlockMiner<CliqueBlockCreator> {
private final Address localAddress;
public CliqueBlockMiner(
final Function<BlockHeader, CliqueBlockCreator> blockCreator,
final ProtocolSchedule<CliqueContext> protocolSchedule,
final ProtocolContext<CliqueContext> protocolContext,
final ProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext,
final Subscribers<MinedBlockObserver> observers,
final AbstractBlockScheduler scheduler,
final BlockHeader parentHeader,

@ -41,15 +41,15 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import org.apache.tuweni.bytes.Bytes;
public class CliqueMinerExecutor extends AbstractMinerExecutor<CliqueContext, CliqueBlockMiner> {
public class CliqueMinerExecutor extends AbstractMinerExecutor<CliqueBlockMiner> {
private final Address localAddress;
private final NodeKey nodeKey;
private final EpochManager epochManager;
public CliqueMinerExecutor(
final ProtocolContext<CliqueContext> protocolContext,
final ProtocolSchedule<CliqueContext> protocolSchedule,
final ProtocolContext protocolContext,
final ProtocolSchedule protocolSchedule,
final PendingTransactions pendingTransactions,
final NodeKey nodeKey,
final MiningParameters miningParams,
@ -113,7 +113,7 @@ public class CliqueMinerExecutor extends AbstractMinerExecutor<CliqueContext, Cl
if (epochManager.isEpochBlock(parentHeader.getNumber() + 1)) {
final VoteTally voteTally =
protocolContext
.getConsensusState()
.getConsensusState(CliqueContext.class)
.getVoteTallyCache()
.getVoteTallyAfterBlock(parentHeader);
validators.addAll(voteTally.getValidators());

@ -14,15 +14,13 @@
*/
package org.hyperledger.besu.consensus.clique.blockcreation;
import org.hyperledger.besu.consensus.clique.CliqueContext;
import org.hyperledger.besu.consensus.clique.CliqueMiningTracker;
import org.hyperledger.besu.ethereum.blockcreation.AbstractMiningCoordinator;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;
public class CliqueMiningCoordinator
extends AbstractMiningCoordinator<CliqueContext, CliqueBlockMiner> {
public class CliqueMiningCoordinator extends AbstractMiningCoordinator<CliqueBlockMiner> {
private final CliqueMiningTracker miningTracker;

@ -14,7 +14,6 @@
*/
package org.hyperledger.besu.consensus.clique.headervalidationrules;
import org.hyperledger.besu.consensus.clique.CliqueContext;
import org.hyperledger.besu.consensus.clique.CliqueDifficultyCalculator;
import org.hyperledger.besu.consensus.clique.CliqueHelpers;
import org.hyperledger.besu.ethereum.ProtocolContext;
@ -24,14 +23,11 @@ import org.hyperledger.besu.ethereum.mainnet.AttachedBlockHeaderValidationRule;
import java.math.BigInteger;
public class CliqueDifficultyValidationRule
implements AttachedBlockHeaderValidationRule<CliqueContext> {
public class CliqueDifficultyValidationRule implements AttachedBlockHeaderValidationRule {
@Override
public boolean validate(
final BlockHeader header,
final BlockHeader parent,
final ProtocolContext<CliqueContext> protocolContext) {
final BlockHeader header, final BlockHeader parent, final ProtocolContext protocolContext) {
final Address actualBlockCreator = CliqueHelpers.getProposerOfBlock(header);
final CliqueDifficultyCalculator diffCalculator =

@ -30,8 +30,7 @@ import com.google.common.collect.Iterables;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class CliqueExtraDataValidationRule
implements AttachedBlockHeaderValidationRule<CliqueContext> {
public class CliqueExtraDataValidationRule implements AttachedBlockHeaderValidationRule {
private static final Logger LOG = LogManager.getLogger();
@ -55,12 +54,13 @@ public class CliqueExtraDataValidationRule
*/
@Override
public boolean validate(
final BlockHeader header,
final BlockHeader parent,
final ProtocolContext<CliqueContext> protocolContext) {
final BlockHeader header, final BlockHeader parent, final ProtocolContext protocolContext) {
try {
final VoteTally validatorProvider =
protocolContext.getConsensusState().getVoteTallyCache().getVoteTallyAfterBlock(parent);
protocolContext
.getConsensusState(CliqueContext.class)
.getVoteTallyCache()
.getVoteTallyAfterBlock(parent);
final Collection<Address> storedValidators = validatorProvider.getValidators();
return extraDataIsValid(storedValidators, header);

@ -14,21 +14,17 @@
*/
package org.hyperledger.besu.consensus.clique.headervalidationrules;
import org.hyperledger.besu.consensus.clique.CliqueContext;
import org.hyperledger.besu.consensus.clique.CliqueHelpers;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.mainnet.AttachedBlockHeaderValidationRule;
public class SignerRateLimitValidationRule
implements AttachedBlockHeaderValidationRule<CliqueContext> {
public class SignerRateLimitValidationRule implements AttachedBlockHeaderValidationRule {
@Override
public boolean validate(
final BlockHeader header,
final BlockHeader parent,
final ProtocolContext<CliqueContext> protocolContext) {
final BlockHeader header, final BlockHeader parent, final ProtocolContext protocolContext) {
final Address blockSigner = CliqueHelpers.getProposerOfBlock(header);
return CliqueHelpers.addressIsAllowedToProduceNextBlock(blockSigner, protocolContext, parent);

@ -37,9 +37,9 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import java.util.Map;
public class CliqueJsonRpcMethods extends ApiGroupJsonRpcMethods {
private final ProtocolContext<CliqueContext> context;
private final ProtocolContext context;
public CliqueJsonRpcMethods(final ProtocolContext<CliqueContext> context) {
public CliqueJsonRpcMethods(final ProtocolContext context) {
this.context = context;
}
@ -54,7 +54,8 @@ public class CliqueJsonRpcMethods extends ApiGroupJsonRpcMethods {
final WorldStateArchive worldStateArchive = context.getWorldStateArchive();
final BlockchainQueries blockchainQueries =
new BlockchainQueries(blockchain, worldStateArchive);
final VoteProposer voteProposer = context.getConsensusState().getVoteProposer();
final VoteProposer voteProposer =
context.getConsensusState(CliqueContext.class).getVoteProposer();
// Must create our own voteTallyCache as using this would pollute the main voteTallyCache
final VoteTallyCache voteTallyCache = createVoteTallyCache(context, blockchain);
@ -69,8 +70,9 @@ public class CliqueJsonRpcMethods extends ApiGroupJsonRpcMethods {
}
private VoteTallyCache createVoteTallyCache(
final ProtocolContext<CliqueContext> context, final MutableBlockchain blockchain) {
final EpochManager epochManager = context.getConsensusState().getEpochManager();
final ProtocolContext context, final MutableBlockchain blockchain) {
final EpochManager epochManager =
context.getConsensusState(CliqueContext.class).getEpochManager();
final CliqueBlockInterface cliqueBlockInterface = new CliqueBlockInterface();
final VoteTallyUpdater voteTallyUpdater =
new VoteTallyUpdater(epochManager, cliqueBlockInterface);

@ -43,7 +43,7 @@ public class CliqueDifficultyCalculatorTest {
private Address localAddr;
private final List<Address> validatorList = Lists.newArrayList();
private ProtocolContext<CliqueContext> cliqueProtocolContext;
private ProtocolContext cliqueProtocolContext;
private BlockHeaderTestFixture blockHeaderBuilder;
private final CliqueBlockInterface blockInterface = new CliqueBlockInterface();
@ -60,7 +60,7 @@ public class CliqueDifficultyCalculatorTest {
final CliqueContext cliqueContext =
new CliqueContext(voteTallyCache, voteProposer, null, blockInterface);
cliqueProtocolContext = new ProtocolContext<>(null, null, cliqueContext);
cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext);
blockHeaderBuilder = new BlockHeaderTestFixture();
}

@ -43,13 +43,13 @@ public class CliqueProtocolScheduleTest {
+ "}";
final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions();
final ProtocolSchedule<CliqueContext> protocolSchedule =
final ProtocolSchedule protocolSchedule =
CliqueProtocolSchedule.create(config, NODE_KEY, false);
final ProtocolSpec<CliqueContext> homesteadSpec = protocolSchedule.getByBlockNumber(1);
final ProtocolSpec<CliqueContext> tangerineWhistleSpec = protocolSchedule.getByBlockNumber(2);
final ProtocolSpec<CliqueContext> spuriousDragonSpec = protocolSchedule.getByBlockNumber(3);
final ProtocolSpec<CliqueContext> byzantiumSpec = protocolSchedule.getByBlockNumber(1035301);
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();
@ -58,7 +58,7 @@ public class CliqueProtocolScheduleTest {
@Test
public void parametersAlignWithMainnetWithAdjustments() {
final ProtocolSpec<CliqueContext> homestead =
final ProtocolSpec homestead =
CliqueProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions(), NODE_KEY, false)
.getByBlockNumber(0);

@ -50,7 +50,7 @@ public class NodeCanProduceNextBlockTest {
private final KeyPair otherNodeKeyPair = KeyPair.generate();
private final List<Address> validatorList = Lists.newArrayList();
private final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture();
private ProtocolContext<CliqueContext> cliqueProtocolContext;
private ProtocolContext cliqueProtocolContext;
private final CliqueBlockInterface blockInterface = new CliqueBlockInterface();
MutableBlockchain blockChain;
@ -81,7 +81,7 @@ public class NodeCanProduceNextBlockTest {
final VoteProposer voteProposer = new VoteProposer();
final CliqueContext cliqueContext =
new CliqueContext(voteTallyCache, voteProposer, null, blockInterface);
cliqueProtocolContext = new ProtocolContext<>(blockChain, null, cliqueContext);
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext);
headerBuilder.number(1).parentHash(genesisBlock.getHash());
final Block block_1 = createEmptyBlock(proposerKeyPair);
@ -107,7 +107,7 @@ public class NodeCanProduceNextBlockTest {
final VoteProposer voteProposer = new VoteProposer();
final CliqueContext cliqueContext =
new CliqueContext(voteTallyCache, voteProposer, null, blockInterface);
cliqueProtocolContext = new ProtocolContext<>(blockChain, null, cliqueContext);
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext);
headerBuilder.number(1).parentHash(genesisBlock.getHash());
final Block block_1 = createEmptyBlock(proposerKeyPair);
@ -142,7 +142,7 @@ public class NodeCanProduceNextBlockTest {
final VoteProposer voteProposer = new VoteProposer();
final CliqueContext cliqueContext =
new CliqueContext(voteTallyCache, voteProposer, null, blockInterface);
cliqueProtocolContext = new ProtocolContext<>(blockChain, null, cliqueContext);
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext);
headerBuilder.parentHash(genesisBlock.getHash()).number(1);
final Block block_1 = createEmptyBlock(proposerKeyPair);
@ -173,7 +173,7 @@ public class NodeCanProduceNextBlockTest {
final VoteProposer voteProposer = new VoteProposer();
final CliqueContext cliqueContext =
new CliqueContext(voteTallyCache, voteProposer, null, blockInterface);
cliqueProtocolContext = new ProtocolContext<>(blockChain, null, cliqueContext);
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext);
headerBuilder.parentHash(genesisBlock.getHash()).number(1);
final Block block_1 = createEmptyBlock(proposerKeyPair);
@ -219,7 +219,7 @@ public class NodeCanProduceNextBlockTest {
final VoteProposer voteProposer = new VoteProposer();
final CliqueContext cliqueContext =
new CliqueContext(voteTallyCache, voteProposer, null, blockInterface);
cliqueProtocolContext = new ProtocolContext<>(blockChain, null, cliqueContext);
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext);
headerBuilder.parentHash(genesisBlock.getHash()).number(1);
final Block block_1 = createEmptyBlock(otherNodeKeyPair);
@ -249,7 +249,7 @@ public class NodeCanProduceNextBlockTest {
final VoteProposer voteProposer = new VoteProposer();
final CliqueContext cliqueContext =
new CliqueContext(voteTallyCache, voteProposer, null, blockInterface);
cliqueProtocolContext = new ProtocolContext<>(blockChain, null, cliqueContext);
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext);
headerBuilder.parentHash(Hash.ZERO).number(3);
final BlockHeader parentHeader =
@ -274,7 +274,7 @@ public class NodeCanProduceNextBlockTest {
final VoteProposer voteProposer = new VoteProposer();
final CliqueContext cliqueContext =
new CliqueContext(voteTallyCache, voteProposer, null, blockInterface);
cliqueProtocolContext = new ProtocolContext<>(blockChain, null, cliqueContext);
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext);
headerBuilder.parentHash(Hash.ZERO).number(3);
final BlockHeader parentHeader = headerBuilder.buildHeader();

@ -71,11 +71,11 @@ public class CliqueBlockCreatorTest {
private final MetricsSystem metricsSystem = new NoOpMetricsSystem();
private final CliqueBlockInterface blockInterface = new CliqueBlockInterface();
private ProtocolSchedule<CliqueContext> protocolSchedule;
private ProtocolSchedule protocolSchedule;
private final WorldStateArchive stateArchive = createInMemoryWorldStateArchive();
private MutableBlockchain blockchain;
private ProtocolContext<CliqueContext> protocolContext;
private ProtocolContext protocolContext;
private VoteProposer voteProposer;
private EpochManager epochManager;
@ -97,7 +97,7 @@ public class CliqueBlockCreatorTest {
final Block genesis =
GenesisState.fromConfig(GenesisConfigFile.mainnet(), protocolSchedule).getBlock();
blockchain = createInMemoryBlockchain(genesis);
protocolContext = new ProtocolContext<>(blockchain, stateArchive, cliqueContext);
protocolContext = new ProtocolContext(blockchain, stateArchive, cliqueContext);
epochManager = new EpochManager(10);
// Add a block above the genesis

@ -65,7 +65,7 @@ public class CliqueMinerExecutorTest {
private final Random random = new Random(21341234L);
private Address localAddress;
private final List<Address> validatorList = Lists.newArrayList();
private ProtocolContext<CliqueContext> cliqueProtocolContext;
private ProtocolContext cliqueProtocolContext;
private BlockHeaderTestFixture blockHeaderBuilder;
private final MetricsSystem metricsSystem = new NoOpMetricsSystem();
private final CliqueBlockInterface blockInterface = new CliqueBlockInterface();
@ -84,7 +84,7 @@ public class CliqueMinerExecutorTest {
final CliqueContext cliqueContext =
new CliqueContext(voteTallyCache, voteProposer, null, blockInterface);
cliqueProtocolContext = new ProtocolContext<>(null, null, cliqueContext);
cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext);
blockHeaderBuilder = new BlockHeaderTestFixture();
}

@ -69,7 +69,7 @@ public class CliqueMiningCoordinatorTest {
private final CliqueBlockInterface blockInterface = new CliqueBlockInterface();
@Mock private MutableBlockchain blockChain;
@Mock private ProtocolContext<CliqueContext> protocolContext;
@Mock private ProtocolContext protocolContext;
@Mock private CliqueMinerExecutor minerExecutor;
@Mock private CliqueBlockMiner blockMiner;
@Mock private SyncState syncState;
@ -88,7 +88,7 @@ public class CliqueMiningCoordinatorTest {
final CliqueContext cliqueContext =
new CliqueContext(voteTallyCache, null, null, blockInterface);
when(protocolContext.getConsensusState()).thenReturn(cliqueContext);
when(protocolContext.getConsensusState(CliqueContext.class)).thenReturn(cliqueContext);
when(protocolContext.getBlockchain()).thenReturn(blockChain);
when(minerExecutor.startAsyncMining(any(), any(), any())).thenReturn(Optional.of(blockMiner));
when(syncState.isInSync()).thenReturn(true);

@ -44,7 +44,7 @@ public class CliqueDifficultyValidationRuleTest {
private final KeyPair proposerKeyPair = KeyPair.generate();
private final List<Address> validatorList = Lists.newArrayList();
private ProtocolContext<CliqueContext> cliqueProtocolContext;
private ProtocolContext cliqueProtocolContext;
private BlockHeaderTestFixture blockHeaderBuilder;
private final CliqueBlockInterface blockInterface = new CliqueBlockInterface();
@ -60,7 +60,7 @@ public class CliqueDifficultyValidationRuleTest {
final CliqueContext cliqueContext =
new CliqueContext(voteTallyCache, voteProposer, null, blockInterface);
cliqueProtocolContext = new ProtocolContext<>(null, null, cliqueContext);
cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext);
blockHeaderBuilder = new BlockHeaderTestFixture();
}

@ -48,7 +48,7 @@ public class CliqueExtraDataValidationRuleTest {
private final CliqueBlockInterface blockInterface = new CliqueBlockInterface();
private final List<Address> validatorList = Lists.newArrayList();
private ProtocolContext<CliqueContext> cliqueProtocolContext;
private ProtocolContext cliqueProtocolContext;
@Before
public void setup() {
@ -62,7 +62,7 @@ public class CliqueExtraDataValidationRuleTest {
final CliqueContext cliqueContext =
new CliqueContext(voteTallyCache, null, null, blockInterface);
cliqueProtocolContext = new ProtocolContext<>(null, null, cliqueContext);
cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext);
}
@Test

@ -272,8 +272,7 @@ public class TestContextBuilder {
final StubGenesisConfigOptions genesisConfigOptions = new StubGenesisConfigOptions();
genesisConfigOptions.byzantiumBlock(0);
final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(genesisConfigOptions);
final ProtocolSchedule protocolSchedule = IbftProtocolSchedule.create(genesisConfigOptions);
/////////////////////////////////////////////////////////////////////////////////////
// From here down is BASICALLY taken from IbftBesuController
@ -290,8 +289,8 @@ public class TestContextBuilder {
final VoteProposer voteProposer = new VoteProposer();
final ProtocolContext<IbftContext> protocolContext =
new ProtocolContext<>(
final ProtocolContext protocolContext =
new ProtocolContext(
blockChain,
worldStateArchive,
new IbftContext(voteTallyCache, voteProposer, epochManager, blockInterface));
@ -322,7 +321,7 @@ public class TestContextBuilder {
final IbftExecutors ibftExecutors = IbftExecutors.create(new NoOpMetricsSystem());
final IbftFinalState finalState =
new IbftFinalState(
protocolContext.getConsensusState().getVoteTallyCache(),
protocolContext.getConsensusState(IbftContext.class).getVoteTallyCache(),
nodeKey,
Util.publicKeyToAddress(nodeKey.getPublicKey()),
proposerSelector,

@ -24,7 +24,6 @@ import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.consensus.ibft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibft.IbftExtraData;
import org.hyperledger.besu.consensus.ibft.RoundTimer;
import org.hyperledger.besu.consensus.ibft.blockcreation.IbftBlockCreator;
@ -66,11 +65,11 @@ public class IbftRoundIntegrationTest {
private final MessageFactory peerMessageFactory = new MessageFactory(NodeKeyUtils.generate());
private final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(1, 0);
private final Subscribers<MinedBlockObserver> subscribers = Subscribers.create();
private ProtocolContext<IbftContext> protocolContext;
private ProtocolContext protocolContext;
@Mock private MutableBlockchain blockChain;
@Mock private WorldStateArchive worldStateArchive;
@Mock private BlockImporter<IbftContext> blockImporter;
@Mock private BlockImporter blockImporter;
@Mock private IbftBlockCreator blockCreator;
@Mock private MessageValidator messageValidator;
@ -88,8 +87,7 @@ public class IbftRoundIntegrationTest {
@Before
public void setup() {
protocolContext =
new ProtocolContext<>(
blockChain, worldStateArchive, setupContextWithValidators(emptyList()));
new ProtocolContext(blockChain, worldStateArchive, setupContextWithValidators(emptyList()));
when(messageValidator.validateProposal(any())).thenReturn(true);
when(messageValidator.validatePrepare(any())).thenReturn(true);

@ -38,9 +38,9 @@ public class IbftBlockHeaderValidationRulesetFactory {
* @param secondsBetweenBlocks the minimum number of seconds which must elapse between blocks.
* @return BlockHeaderValidator configured for assessing ibft block headers
*/
public static BlockHeaderValidator.Builder<IbftContext> ibftBlockHeaderValidator(
public static BlockHeaderValidator.Builder ibftBlockHeaderValidator(
final long secondsBetweenBlocks) {
return new BlockHeaderValidator.Builder<IbftContext>()
return new BlockHeaderValidator.Builder()
.addRule(new AncestryValidationRule())
.addRule(new GasUsageValidationRule())
.addRule(new GasLimitRangeAndDeltaValidationRule(5000, 0x7fffffffffffffffL))

@ -34,14 +34,14 @@ public class IbftProtocolSchedule {
private static final BigInteger DEFAULT_CHAIN_ID = BigInteger.ONE;
public static ProtocolSchedule<IbftContext> create(
public static ProtocolSchedule create(
final GenesisConfigOptions config,
final PrivacyParameters privacyParameters,
final boolean isRevertReasonEnabled) {
final IbftConfigOptions ibftConfig = config.getIbftLegacyConfigOptions();
final long blockPeriod = ibftConfig.getBlockPeriodSeconds();
return new ProtocolScheduleBuilder<>(
return new ProtocolScheduleBuilder(
config,
DEFAULT_CHAIN_ID,
builder -> applyIbftChanges(blockPeriod, builder),
@ -50,25 +50,24 @@ public class IbftProtocolSchedule {
.createProtocolSchedule();
}
public static ProtocolSchedule<IbftContext> create(
public static ProtocolSchedule create(
final GenesisConfigOptions config, final boolean isRevertReasonEnabled) {
return create(config, PrivacyParameters.DEFAULT, isRevertReasonEnabled);
}
public static ProtocolSchedule<IbftContext> create(final GenesisConfigOptions config) {
public static ProtocolSchedule create(final GenesisConfigOptions config) {
return create(config, PrivacyParameters.DEFAULT, false);
}
private static ProtocolSpecBuilder<IbftContext> applyIbftChanges(
final long secondsBetweenBlocks, final ProtocolSpecBuilder<Void> builder) {
private static ProtocolSpecBuilder applyIbftChanges(
final long secondsBetweenBlocks, final ProtocolSpecBuilder builder) {
return builder
.changeConsensusContextType(
ibftBlockHeaderValidator(secondsBetweenBlocks),
ibftBlockHeaderValidator(secondsBetweenBlocks),
MainnetBlockBodyValidator::new,
MainnetBlockValidator::new,
MainnetBlockImporter::new,
(time, parent, protocolContext) -> BigInteger.ONE)
.blockHeaderValidatorBuilder(ibftBlockHeaderValidator(secondsBetweenBlocks))
.ommerHeaderValidatorBuilder(ibftBlockHeaderValidator(secondsBetweenBlocks))
.blockBodyValidatorBuilder(MainnetBlockBodyValidator::new)
.blockValidatorBuilder(MainnetBlockValidator::new)
.blockImporterBuilder(MainnetBlockImporter::new)
.difficultyCalculator((time, parent, protocolContext) -> BigInteger.ONE)
.blockReward(Wei.ZERO)
.skipZeroBlockRewards(true)
.blockHeaderFunctions(IbftBlockHeaderFunctions.forOnChainBlock());

@ -15,7 +15,6 @@
package org.hyperledger.besu.consensus.ibft.blockcreation;
import org.hyperledger.besu.consensus.ibft.IbftBlockHeaderFunctions;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibft.IbftHelpers;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.AbstractBlockCreator;
@ -31,14 +30,14 @@ import java.util.function.Function;
// This class is responsible for creating a block without committer seals (basically it was just
// too hard to coordinate with the state machine).
public class IbftBlockCreator extends AbstractBlockCreator<IbftContext> {
public class IbftBlockCreator extends AbstractBlockCreator {
public IbftBlockCreator(
final Address localAddress,
final ExtraDataCalculator extraDataCalculator,
final PendingTransactions pendingTransactions,
final ProtocolContext<IbftContext> protocolContext,
final ProtocolSchedule<IbftContext> protocolSchedule,
final ProtocolContext protocolContext,
final ProtocolSchedule protocolSchedule,
final Function<Long, Long> gasLimitCalculator,
final Wei minTransactionGasPrice,
final Double minBlockOccupancyRatio,

@ -40,8 +40,8 @@ public class IbftBlockCreatorFactory {
private final Function<Long, Long> gasLimitCalculator;
private final PendingTransactions pendingTransactions;
protected final ProtocolContext<IbftContext> protocolContext;
protected final ProtocolSchedule<IbftContext> protocolSchedule;
protected final ProtocolContext protocolContext;
protected final ProtocolSchedule protocolSchedule;
private final Address localAddress;
private volatile Bytes vanityData;
@ -51,8 +51,8 @@ public class IbftBlockCreatorFactory {
public IbftBlockCreatorFactory(
final Function<Long, Long> gasLimitCalculator,
final PendingTransactions pendingTransactions,
final ProtocolContext<IbftContext> protocolContext,
final ProtocolSchedule<IbftContext> protocolSchedule,
final ProtocolContext protocolContext,
final ProtocolSchedule protocolSchedule,
final MiningParameters miningParams,
final Address localAddress) {
this.gasLimitCalculator = gasLimitCalculator;
@ -93,12 +93,15 @@ public class IbftBlockCreatorFactory {
public Bytes createExtraData(final int round, final BlockHeader parentHeader) {
final VoteTally voteTally =
protocolContext
.getConsensusState()
.getConsensusState(IbftContext.class)
.getVoteTallyCache()
.getVoteTallyAfterBlock(parentHeader);
final Optional<ValidatorVote> proposal =
protocolContext.getConsensusState().getVoteProposer().getVote(localAddress, voteTally);
protocolContext
.getConsensusState(IbftContext.class)
.getVoteProposer()
.getVote(localAddress, voteTally);
final List<Address> validators = new ArrayList<>(voteTally.getValidators());

@ -30,18 +30,19 @@ import org.apache.logging.log4j.Logger;
* Ensures that the coinbase (which corresponds to the block proposer) is included in the list of
* validators
*/
public class IbftCoinbaseValidationRule implements AttachedBlockHeaderValidationRule<IbftContext> {
public class IbftCoinbaseValidationRule implements AttachedBlockHeaderValidationRule {
private static final Logger LOGGER = LogManager.getLogger(IbftCoinbaseValidationRule.class);
@Override
public boolean validate(
final BlockHeader header,
final BlockHeader parent,
final ProtocolContext<IbftContext> context) {
final BlockHeader header, final BlockHeader parent, final ProtocolContext context) {
final ValidatorProvider validatorProvider =
context.getConsensusState().getVoteTallyCache().getVoteTallyAfterBlock(parent);
context
.getConsensusState(IbftContext.class)
.getVoteTallyCache()
.getVoteTallyAfterBlock(parent);
final Address proposer = header.getCoinbase();
final Collection<Address> storedValidators = validatorProvider.getValidators();

@ -39,18 +39,18 @@ import org.apache.logging.log4j.Logger;
*
* <p>This also ensures sufficient commit seals exist in the block to make it valid.
*/
public class IbftCommitSealsValidationRule
implements AttachedBlockHeaderValidationRule<IbftContext> {
public class IbftCommitSealsValidationRule implements AttachedBlockHeaderValidationRule {
private static final Logger LOGGER = LogManager.getLogger();
@Override
public boolean validate(
final BlockHeader header,
final BlockHeader parent,
final ProtocolContext<IbftContext> protocolContext) {
final BlockHeader header, final BlockHeader parent, final ProtocolContext protocolContext) {
final ValidatorProvider validatorProvider =
protocolContext.getConsensusState().getVoteTallyCache().getVoteTallyAfterBlock(parent);
protocolContext
.getConsensusState(IbftContext.class)
.getVoteTallyCache()
.getVoteTallyAfterBlock(parent);
final IbftExtraData ibftExtraData = IbftExtraData.decode(header);
final List<Address> committers =

@ -35,19 +35,19 @@ import org.apache.logging.log4j.Logger;
* Ensures the Validators listed in the block header match that tracked in memory (which was in-turn
* created by tracking votes included on the block chain).
*/
public class IbftValidatorsValidationRule
implements AttachedBlockHeaderValidationRule<IbftContext> {
public class IbftValidatorsValidationRule implements AttachedBlockHeaderValidationRule {
private static final Logger LOGGER = LogManager.getLogger();
@Override
public boolean validate(
final BlockHeader header,
final BlockHeader parent,
final ProtocolContext<IbftContext> context) {
final BlockHeader header, final BlockHeader parent, final ProtocolContext context) {
try {
final ValidatorProvider validatorProvider =
context.getConsensusState().getVoteTallyCache().getVoteTallyAfterBlock(parent);
context
.getConsensusState(IbftContext.class)
.getVoteTallyCache()
.getVoteTallyAfterBlock(parent);
final IbftExtraData ibftExtraData = IbftExtraData.decode(header);
final SortedSet<Address> sortedReportedValidators =

@ -14,7 +14,6 @@
*/
package org.hyperledger.besu.consensus.ibft.headervalidationrules;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibft.IbftExtraData;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.BlockHeader;
@ -23,16 +22,13 @@ import org.hyperledger.besu.ethereum.mainnet.AttachedBlockHeaderValidationRule;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class IbftVanityDataValidationRule
implements AttachedBlockHeaderValidationRule<IbftContext> {
public class IbftVanityDataValidationRule implements AttachedBlockHeaderValidationRule {
private static final Logger LOG = LogManager.getLogger();
@Override
public boolean validate(
final BlockHeader header,
final BlockHeader parent,
final ProtocolContext<IbftContext> protocolContext) {
final BlockHeader header, final BlockHeader parent, final ProtocolContext protocolContext) {
final IbftExtraData extraData = IbftExtraData.decode(header);
if (extraData.getVanityData().size() != IbftExtraData.EXTRA_VANITY_LENGTH) {

@ -38,9 +38,9 @@ import java.util.Map;
public class IbftJsonRpcMethods extends ApiGroupJsonRpcMethods {
private final ProtocolContext<IbftContext> context;
private final ProtocolContext context;
public IbftJsonRpcMethods(final ProtocolContext<IbftContext> context) {
public IbftJsonRpcMethods(final ProtocolContext context) {
this.context = context;
}
@ -54,7 +54,8 @@ public class IbftJsonRpcMethods extends ApiGroupJsonRpcMethods {
final MutableBlockchain mutableBlockchain = context.getBlockchain();
final BlockchainQueries blockchainQueries =
new BlockchainQueries(context.getBlockchain(), context.getWorldStateArchive());
final VoteProposer voteProposer = context.getConsensusState().getVoteProposer();
final VoteProposer voteProposer =
context.getConsensusState(IbftContext.class).getVoteProposer();
final BlockInterface blockInterface = new IbftBlockInterface();
final VoteTallyCache voteTallyCache = createVoteTallyCache(context, mutableBlockchain);
@ -69,8 +70,9 @@ public class IbftJsonRpcMethods extends ApiGroupJsonRpcMethods {
}
private VoteTallyCache createVoteTallyCache(
final ProtocolContext<IbftContext> context, final MutableBlockchain blockchain) {
final EpochManager epochManager = context.getConsensusState().getEpochManager();
final ProtocolContext context, final MutableBlockchain blockchain) {
final EpochManager epochManager =
context.getConsensusState(IbftContext.class).getEpochManager();
final IbftBlockInterface ibftBlockInterface = new IbftBlockInterface();
final VoteTallyUpdater voteTallyUpdater =
new VoteTallyUpdater(epochManager, ibftBlockInterface);

@ -18,7 +18,6 @@ import org.hyperledger.besu.consensus.ibft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.IbftBlockHashing;
import org.hyperledger.besu.consensus.ibft.IbftBlockHeaderFunctions;
import org.hyperledger.besu.consensus.ibft.IbftBlockInterface;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibft.IbftExtraData;
import org.hyperledger.besu.consensus.ibft.IbftHelpers;
import org.hyperledger.besu.consensus.ibft.RoundTimer;
@ -53,8 +52,8 @@ public class IbftRound {
private final Subscribers<MinedBlockObserver> observers;
private final RoundState roundState;
private final IbftBlockCreator blockCreator;
private final ProtocolContext<IbftContext> protocolContext;
private final BlockImporter<IbftContext> blockImporter;
private final ProtocolContext protocolContext;
private final BlockImporter blockImporter;
private final NodeKey nodeKey;
private final MessageFactory messageFactory; // used only to create stored local msgs
private final IbftMessageTransmitter transmitter;
@ -62,8 +61,8 @@ public class IbftRound {
public IbftRound(
final RoundState roundState,
final IbftBlockCreator blockCreator,
final ProtocolContext<IbftContext> protocolContext,
final BlockImporter<IbftContext> blockImporter,
final ProtocolContext protocolContext,
final BlockImporter blockImporter,
final Subscribers<MinedBlockObserver> observers,
final NodeKey nodeKey,
final MessageFactory messageFactory,

@ -15,7 +15,6 @@
package org.hyperledger.besu.consensus.ibft.statemachine;
import org.hyperledger.besu.consensus.ibft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibft.blockcreation.IbftBlockCreator;
import org.hyperledger.besu.consensus.ibft.blockcreation.IbftBlockCreatorFactory;
import org.hyperledger.besu.consensus.ibft.validation.MessageValidatorFactory;
@ -28,15 +27,15 @@ import org.hyperledger.besu.util.Subscribers;
public class IbftRoundFactory {
private final IbftFinalState finalState;
private final IbftBlockCreatorFactory blockCreatorFactory;
private final ProtocolContext<IbftContext> protocolContext;
private final ProtocolSchedule<IbftContext> protocolSchedule;
private final ProtocolContext protocolContext;
private final ProtocolSchedule protocolSchedule;
private final Subscribers<MinedBlockObserver> minedBlockObservers;
private final MessageValidatorFactory messageValidatorFactory;
public IbftRoundFactory(
final IbftFinalState finalState,
final ProtocolContext<IbftContext> protocolContext,
final ProtocolSchedule<IbftContext> protocolSchedule,
final ProtocolContext protocolContext,
final ProtocolSchedule protocolSchedule,
final Subscribers<MinedBlockObserver> minedBlockObservers,
final MessageValidatorFactory messageValidatorFactory) {
this.finalState = finalState;

@ -15,7 +15,6 @@
package org.hyperledger.besu.consensus.ibft.validation;
import org.hyperledger.besu.consensus.ibft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Commit;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal;
@ -37,15 +36,15 @@ public class MessageValidator {
private final SignedDataValidator signedDataValidator;
private final ProposalBlockConsistencyValidator proposalConsistencyValidator;
private final BlockValidator<IbftContext> blockValidator;
private final ProtocolContext<IbftContext> protocolContext;
private final BlockValidator blockValidator;
private final ProtocolContext protocolContext;
private final RoundChangeCertificateValidator roundChangeCertificateValidator;
public MessageValidator(
final SignedDataValidator signedDataValidator,
final ProposalBlockConsistencyValidator proposalConsistencyValidator,
final BlockValidator<IbftContext> blockValidator,
final ProtocolContext<IbftContext> protocolContext,
final BlockValidator blockValidator,
final ProtocolContext protocolContext,
final RoundChangeCertificateValidator roundChangeCertificateValidator) {
this.signedDataValidator = signedDataValidator;
this.proposalConsistencyValidator = proposalConsistencyValidator;

@ -29,13 +29,13 @@ import java.util.Collection;
public class MessageValidatorFactory {
private final ProposerSelector proposerSelector;
private final ProtocolContext<IbftContext> protocolContext;
private final ProtocolSchedule<IbftContext> protocolSchedule;
private final ProtocolContext protocolContext;
private final ProtocolSchedule protocolSchedule;
public MessageValidatorFactory(
final ProposerSelector proposerSelector,
final ProtocolSchedule<IbftContext> protocolSchedule,
final ProtocolContext<IbftContext> protocolContext) {
final ProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext) {
this.proposerSelector = proposerSelector;
this.protocolSchedule = protocolSchedule;
this.protocolContext = protocolContext;
@ -43,7 +43,7 @@ public class MessageValidatorFactory {
private Collection<Address> getValidatorsAfterBlock(final BlockHeader parentHeader) {
return protocolContext
.getConsensusState()
.getConsensusState(IbftContext.class)
.getVoteTallyCache()
.getVoteTallyAfterBlock(parentHeader)
.getValidators();
@ -60,7 +60,7 @@ public class MessageValidatorFactory {
public MessageValidator createMessageValidator(
final ConsensusRoundIdentifier roundIdentifier, final BlockHeader parentHeader) {
final BlockValidator<IbftContext> blockValidator =
final BlockValidator blockValidator =
protocolSchedule.getByBlockNumber(roundIdentifier.getSequenceNumber()).getBlockValidator();
final Collection<Address> validators = getValidatorsAfterBlock(parentHeader);

@ -40,8 +40,8 @@ import org.junit.Test;
public class IbftBlockHeaderValidationRulesetFactoryTest {
private final ProtocolContext<IbftContext> protocolContext(final Collection<Address> validators) {
return new ProtocolContext<>(null, null, setupContextWithValidators(validators));
private final ProtocolContext protocolContext(final Collection<Address> validators) {
return new ProtocolContext(null, null, setupContextWithValidators(validators));
}
@Test
@ -56,7 +56,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
final BlockHeader blockHeader =
getPresetHeaderBuilder(2, proposerNodeKey, validators, parentHeader).buildHeader();
final BlockHeaderValidator<IbftContext> validator =
final BlockHeaderValidator validator =
IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5).build();
assertThat(
@ -77,7 +77,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
final BlockHeader blockHeader =
getPresetHeaderBuilder(2, proposerNodeKey, emptyList(), parentHeader).buildHeader();
final BlockHeaderValidator<IbftContext> validator =
final BlockHeaderValidator validator =
IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5).build();
assertThat(
@ -103,7 +103,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
.coinbase(nonProposerAddress)
.buildHeader();
final BlockHeaderValidator<IbftContext> validator =
final BlockHeaderValidator validator =
IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5).build();
assertThat(
@ -124,7 +124,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
final BlockHeader blockHeader =
getPresetHeaderBuilder(2, proposerNodeKey, validators, parentHeader).nonce(3).buildHeader();
final BlockHeaderValidator<IbftContext> validator =
final BlockHeaderValidator validator =
IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5).build();
assertThat(
@ -147,7 +147,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
.timestamp(100)
.buildHeader();
final BlockHeaderValidator<IbftContext> validator =
final BlockHeaderValidator validator =
IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5).build();
assertThat(
@ -170,7 +170,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
.mixHash(Hash.EMPTY_TRIE_HASH)
.buildHeader();
final BlockHeaderValidator<IbftContext> validator =
final BlockHeaderValidator validator =
IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5).build();
assertThat(
@ -193,7 +193,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
.ommersHash(Hash.EMPTY_TRIE_HASH)
.buildHeader();
final BlockHeaderValidator<IbftContext> validator =
final BlockHeaderValidator validator =
IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5).build();
assertThat(
@ -216,7 +216,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
.difficulty(Difficulty.of(5))
.buildHeader();
final BlockHeaderValidator<IbftContext> validator =
final BlockHeaderValidator validator =
IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5).build();
assertThat(
@ -237,7 +237,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
final BlockHeader blockHeader =
getPresetHeaderBuilder(2, proposerNodeKey, validators, null).buildHeader();
final BlockHeaderValidator<IbftContext> validator =
final BlockHeaderValidator validator =
IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5).build();
assertThat(
@ -261,7 +261,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
.gasUsed(6_000)
.buildHeader();
final BlockHeaderValidator<IbftContext> validator =
final BlockHeaderValidator validator =
IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5).build();
assertThat(
@ -284,7 +284,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
.gasLimit(4999)
.buildHeader();
final BlockHeaderValidator<IbftContext> validator =
final BlockHeaderValidator validator =
IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5).build();
assertThat(

@ -24,7 +24,6 @@ import static org.mockito.Mockito.when;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.consensus.ibft.IbftBlockHashing;
import org.hyperledger.besu.consensus.ibft.IbftBlockHeaderValidationRulesetFactory;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibft.IbftExtraData;
import org.hyperledger.besu.consensus.ibft.IbftProtocolSchedule;
import org.hyperledger.besu.ethereum.ProtocolContext;
@ -73,12 +72,12 @@ public class IbftBlockCreatorTest {
initialValidatorList.add(AddressHelpers.ofValue(i));
}
final ProtocolSchedule<IbftContext> protocolSchedule =
final ProtocolSchedule protocolSchedule =
IbftProtocolSchedule.create(
GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}")
.getConfigOptions());
final ProtocolContext<IbftContext> protContext =
new ProtocolContext<>(
final ProtocolContext protContext =
new ProtocolContext(
blockchain,
createInMemoryWorldStateArchive(),
setupContextWithValidators(initialValidatorList));
@ -116,7 +115,7 @@ public class IbftBlockCreatorTest {
final int secondsBetweenBlocks = 1;
final Block block = blockCreator.createBlock(parentHeader.getTimestamp() + 1);
final BlockHeaderValidator<IbftContext> rules =
final BlockHeaderValidator rules =
IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(secondsBetweenBlocks)
.build();

@ -17,7 +17,6 @@ package org.hyperledger.besu.consensus.ibft.headervalidationrules;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.consensus.ibft.IbftContextBuilder.setupContextWithValidators;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibft.IbftExtraData;
import org.hyperledger.besu.consensus.ibft.IbftExtraDataFixture;
import org.hyperledger.besu.consensus.ibft.Vote;
@ -71,8 +70,8 @@ public class IbftCoinbaseValidationRuleTest {
final List<NodeKey> committers = Lists.newArrayList(proposerNodeKey);
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(validators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators));
final IbftCoinbaseValidationRule coinbaseValidationRule = new IbftCoinbaseValidationRule();
@ -93,8 +92,8 @@ public class IbftCoinbaseValidationRuleTest {
final List<NodeKey> committers = Lists.newArrayList(otherValidatorNodeKey);
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(validators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators));
final IbftCoinbaseValidationRule coinbaseValidationRule = new IbftCoinbaseValidationRule();

@ -20,7 +20,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.consensus.ibft.IbftContextBuilder.setupContextWithValidators;
import static org.hyperledger.besu.consensus.ibft.headervalidationrules.HeaderValidationTestHelpers.createProposedBlockHeader;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibft.IbftExtraData;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
@ -54,8 +53,8 @@ public class IbftCommitSealsValidationRuleTest {
.sorted()
.collect(Collectors.toList());
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(committerAddresses));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(committerAddresses));
BlockHeader header = createProposedBlockHeader(committerAddresses, committerNodeKeys, false);
@ -69,8 +68,8 @@ public class IbftCommitSealsValidationRuleTest {
Address.extract(Hash.hash(committerNodeKey.getPublicKey().getEncodedBytes()));
final List<Address> validators = singletonList(committerAddress);
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(validators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators));
final BlockHeader header = createProposedBlockHeader(validators, emptyList(), false);
@ -94,8 +93,8 @@ public class IbftCommitSealsValidationRuleTest {
final BlockHeader header =
createProposedBlockHeader(validators, singletonList(nonValidatorNodeKey), false);
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(validators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators));
assertThat(commitSealsValidationRule.validate(header, null, context)).isFalse();
}
@ -148,8 +147,8 @@ public class IbftCommitSealsValidationRuleTest {
createProposedBlockHeader(
validators, Lists.newArrayList(committerNodeKey, committerNodeKey), false);
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(validators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators));
assertThat(commitSealsValidationRule.validate(header, null, context)).isFalse();
}
@ -175,8 +174,8 @@ public class IbftCommitSealsValidationRuleTest {
committerKeys.subList(0, committerCount),
useDifferentRoundNumbersForCommittedSeals);
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(validators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators));
return commitSealsValidationRule.validate(header, null, context);
}

@ -18,7 +18,6 @@ import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.consensus.ibft.IbftContextBuilder.setupContextWithValidators;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
@ -40,8 +39,8 @@ public class IbftValidatorsValidationRuleTest {
Lists.newArrayList(
AddressHelpers.ofValue(1), AddressHelpers.ofValue(2), AddressHelpers.ofValue(3));
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(validators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators));
final BlockHeader header =
HeaderValidationTestHelpers.createProposedBlockHeader(validators, emptyList(), false);
@ -56,8 +55,8 @@ public class IbftValidatorsValidationRuleTest {
Lists.newArrayList(
AddressHelpers.ofValue(1), AddressHelpers.ofValue(2), AddressHelpers.ofValue(3));
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(validators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators));
final BlockHeader header =
HeaderValidationTestHelpers.createProposedBlockHeader(
@ -76,8 +75,8 @@ public class IbftValidatorsValidationRuleTest {
Lists.newArrayList(
AddressHelpers.ofValue(2), AddressHelpers.ofValue(3), AddressHelpers.ofValue(4));
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(storedValidators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(storedValidators));
final BlockHeader header =
HeaderValidationTestHelpers.createProposedBlockHeader(

@ -32,7 +32,6 @@ import static org.mockito.Mockito.when;
import org.hyperledger.besu.consensus.ibft.BlockTimer;
import org.hyperledger.besu.consensus.ibft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibft.IbftExtraData;
import org.hyperledger.besu.consensus.ibft.RoundTimer;
import org.hyperledger.besu.consensus.ibft.blockcreation.IbftBlockCreator;
@ -92,7 +91,7 @@ public class IbftBlockHeightManagerTest {
@Mock private Clock clock;
@Mock private MessageValidatorFactory messageValidatorFactory;
@Mock private IbftBlockCreator blockCreator;
@Mock private BlockImporter<IbftContext> blockImporter;
@Mock private BlockImporter blockImporter;
@Mock private BlockTimer blockTimer;
@Mock private RoundTimer roundTimer;
@Mock private FutureRoundProposalMessageValidator futureRoundProposalMessageValidator;
@ -102,7 +101,7 @@ public class IbftBlockHeightManagerTest {
private final List<Address> validators = Lists.newArrayList();
private final List<MessageFactory> validatorMessageFactory = Lists.newArrayList();
private ProtocolContext<IbftContext> protocolContext;
private ProtocolContext protocolContext;
private final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(1, 0);
private Block createdBlock;
@ -141,7 +140,7 @@ public class IbftBlockHeightManagerTest {
.thenReturn(futureRoundProposalMessageValidator);
when(messageValidatorFactory.createMessageValidator(any(), any())).thenReturn(messageValidator);
protocolContext = new ProtocolContext<>(null, null, setupContextWithValidators(validators));
protocolContext = new ProtocolContext(null, null, setupContextWithValidators(validators));
// Ensure the created IbftRound has the valid ConsensusRoundIdentifier;
when(roundFactory.createNewRound(any(), anyInt()))

@ -30,7 +30,6 @@ import static org.mockito.Mockito.when;
import org.hyperledger.besu.consensus.ibft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.IbftBlockHashing;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibft.IbftExtraData;
import org.hyperledger.besu.consensus.ibft.RoundTimer;
import org.hyperledger.besu.consensus.ibft.blockcreation.IbftBlockCreator;
@ -74,11 +73,11 @@ public class IbftRoundTest {
private final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(1, 0);
private final MessageFactory messageFactory = new MessageFactory(nodeKey);
private final Subscribers<MinedBlockObserver> subscribers = Subscribers.create();
private ProtocolContext<IbftContext> protocolContext;
private ProtocolContext protocolContext;
@Mock private MutableBlockchain blockChain;
@Mock private WorldStateArchive worldStateArchive;
@Mock private BlockImporter<IbftContext> blockImporter;
@Mock private BlockImporter blockImporter;
@Mock private IbftMessageTransmitter transmitter;
@Mock private MinedBlockObserver minedBlockObserver;
@Mock private IbftBlockCreator blockCreator;
@ -96,8 +95,7 @@ public class IbftRoundTest {
@Before
public void setup() {
protocolContext =
new ProtocolContext<>(
blockChain, worldStateArchive, setupContextWithValidators(emptyList()));
new ProtocolContext(blockChain, worldStateArchive, setupContextWithValidators(emptyList()));
when(messageValidator.validateProposal(any())).thenReturn(true);
when(messageValidator.validatePrepare(any())).thenReturn(true);

@ -20,7 +20,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.consensus.ibft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibft.IbftHelpers;
import org.hyperledger.besu.consensus.ibft.TestHelpers;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare;
@ -72,9 +71,7 @@ public class RoundChangeManagerTest {
validators.add(Util.publicKeyToAddress(validator1Key.getPublicKey()));
validators.add(Util.publicKeyToAddress(validator2Key.getPublicKey()));
@SuppressWarnings("unchecked")
final BlockValidator<IbftContext> blockValidator =
(BlockValidator<IbftContext>) mock(BlockValidator.class);
final BlockValidator blockValidator = mock(BlockValidator.class);
when(blockValidator.validateAndProcessBlock(any(), any(), any(), any()))
.thenReturn(Optional.of(new BlockProcessingOutputs(null, null)));

@ -63,8 +63,8 @@ public class MessageValidatorTest {
private final ProposalBlockConsistencyValidator proposalBlockConsistencyValidator =
mock(ProposalBlockConsistencyValidator.class);
@Mock private BlockValidator<IbftContext> blockValidator;
private ProtocolContext<IbftContext> protocolContext;
@Mock private BlockValidator blockValidator;
private ProtocolContext protocolContext;
private final RoundChangeCertificateValidator roundChangeCertificateValidator =
mock(RoundChangeCertificateValidator.class);
@ -89,7 +89,7 @@ public class MessageValidatorTest {
.thenReturn(true);
protocolContext =
new ProtocolContext<>(
new ProtocolContext(
mock(MutableBlockchain.class), mock(WorldStateArchive.class), mock(IbftContext.class));
when(blockValidator.validateAndProcessBlock(any(), any(), any(), any()))

@ -14,7 +14,6 @@
*/
package org.hyperledger.besu.consensus.ibftlegacy;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibftlegacy.headervalidationrules.IbftExtraDataValidationRule;
import org.hyperledger.besu.consensus.ibftlegacy.headervalidationrules.VoteValidationRule;
import org.hyperledger.besu.ethereum.core.BlockHeader;
@ -38,7 +37,7 @@ public class IbftBlockHeaderValidationRulesetFactory {
* @param secondsBetweenBlocks the minimum number of seconds which must elapse between blocks.
* @return BlockHeaderValidator configured for assessing ibft block headers
*/
public static BlockHeaderValidator.Builder<IbftContext> ibftBlockHeaderValidator(
public static BlockHeaderValidator.Builder ibftBlockHeaderValidator(
final long secondsBetweenBlocks) {
return createValidator(secondsBetweenBlocks, true);
}
@ -50,14 +49,14 @@ public class IbftBlockHeaderValidationRulesetFactory {
* @param secondsBetweenBlocks the minimum number of seconds which must elapse between blocks.
* @return BlockHeaderValidator configured for assessing ibft block headers
*/
public static BlockHeaderValidator.Builder<IbftContext> ibftProposedBlockValidator(
public static BlockHeaderValidator.Builder ibftProposedBlockValidator(
final long secondsBetweenBlocks) {
return createValidator(secondsBetweenBlocks, false);
}
private static BlockHeaderValidator.Builder<IbftContext> createValidator(
private static BlockHeaderValidator.Builder createValidator(
final long secondsBetweenBlocks, final boolean validateCommitSeals) {
return new BlockHeaderValidator.Builder<IbftContext>()
return new BlockHeaderValidator.Builder()
.addRule(new AncestryValidationRule())
.addRule(new GasUsageValidationRule())
.addRule(new GasLimitRangeAndDeltaValidationRule(5000, 0x7fffffffffffffffL))

@ -18,7 +18,6 @@ import static org.hyperledger.besu.consensus.ibftlegacy.IbftBlockHeaderValidatio
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.config.IbftConfigOptions;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.ethereum.MainnetBlockValidator;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Wei;
@ -35,14 +34,14 @@ public class IbftProtocolSchedule {
private static final BigInteger DEFAULT_CHAIN_ID = BigInteger.ONE;
public static ProtocolSchedule<IbftContext> create(
public static ProtocolSchedule create(
final GenesisConfigOptions config,
final PrivacyParameters privacyParameters,
final boolean isRevertReasonEnabled) {
final IbftConfigOptions ibftConfig = config.getIbftLegacyConfigOptions();
final long blockPeriod = ibftConfig.getBlockPeriodSeconds();
return new ProtocolScheduleBuilder<>(
return new ProtocolScheduleBuilder(
config,
DEFAULT_CHAIN_ID,
builder -> applyIbftChanges(blockPeriod, builder),
@ -51,21 +50,20 @@ public class IbftProtocolSchedule {
.createProtocolSchedule();
}
public static ProtocolSchedule<IbftContext> create(
public static ProtocolSchedule create(
final GenesisConfigOptions config, final boolean isRevertReasonEnabled) {
return create(config, PrivacyParameters.DEFAULT, isRevertReasonEnabled);
}
private static ProtocolSpecBuilder<IbftContext> applyIbftChanges(
final long secondsBetweenBlocks, final ProtocolSpecBuilder<Void> builder) {
private static ProtocolSpecBuilder applyIbftChanges(
final long secondsBetweenBlocks, final ProtocolSpecBuilder builder) {
return builder
.changeConsensusContextType(
ibftBlockHeaderValidator(secondsBetweenBlocks),
ibftBlockHeaderValidator(secondsBetweenBlocks),
MainnetBlockBodyValidator::new,
MainnetBlockValidator::new,
MainnetBlockImporter::new,
(time, parent, protocolContext) -> BigInteger.ONE)
.blockHeaderValidatorBuilder(ibftBlockHeaderValidator(secondsBetweenBlocks))
.ommerHeaderValidatorBuilder(ibftBlockHeaderValidator(secondsBetweenBlocks))
.blockBodyValidatorBuilder(MainnetBlockBodyValidator::new)
.blockValidatorBuilder(MainnetBlockValidator::new)
.blockImporterBuilder(MainnetBlockImporter::new)
.difficultyCalculator((time, parent, protocolContext) -> BigInteger.ONE)
.blockReward(Wei.ZERO)
.skipZeroBlockRewards(true)
.blockHeaderFunctions(new LegacyIbftBlockHeaderFunctions());

@ -14,7 +14,6 @@
*/
package org.hyperledger.besu.consensus.ibftlegacy.blockcreation;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibftlegacy.IbftBlockHashing;
import org.hyperledger.besu.consensus.ibftlegacy.IbftExtraData;
import org.hyperledger.besu.consensus.ibftlegacy.IbftHelpers;
@ -41,7 +40,7 @@ import java.util.function.Function;
* commit seals). Transactions and associated Hashes (stateroot, receipts etc.) are loaded into the
* Block in the base class as part of the transaction selection process.
*/
public class IbftBlockCreator extends AbstractBlockCreator<IbftContext> {
public class IbftBlockCreator extends AbstractBlockCreator {
private final KeyPair nodeKeys;
@ -49,8 +48,8 @@ public class IbftBlockCreator extends AbstractBlockCreator<IbftContext> {
final Address coinbase,
final ExtraDataCalculator extraDataCalculator,
final PendingTransactions pendingTransactions,
final ProtocolContext<IbftContext> protocolContext,
final ProtocolSchedule<IbftContext> protocolSchedule,
final ProtocolContext protocolContext,
final ProtocolSchedule protocolSchedule,
final Function<Long, Long> gasLimitCalculator,
final KeyPair nodeKeys,
final Wei minTransactionGasPrice,

@ -39,7 +39,7 @@ import org.apache.logging.log4j.Logger;
* structure, and that the structure created contains data matching expectations from preceding
* blocks.
*/
public class IbftExtraDataValidationRule implements AttachedBlockHeaderValidationRule<IbftContext> {
public class IbftExtraDataValidationRule implements AttachedBlockHeaderValidationRule {
private static final Logger LOG = LogManager.getLogger();
@ -51,12 +51,13 @@ public class IbftExtraDataValidationRule implements AttachedBlockHeaderValidatio
@Override
public boolean validate(
final BlockHeader header,
final BlockHeader parent,
final ProtocolContext<IbftContext> context) {
final BlockHeader header, final BlockHeader parent, final ProtocolContext context) {
try {
final ValidatorProvider validatorProvider =
context.getConsensusState().getVoteTallyCache().getVoteTallyAfterBlock(parent);
context
.getConsensusState(IbftContext.class)
.getVoteTallyCache()
.getVoteTallyAfterBlock(parent);
final IbftExtraData ibftExtraData = IbftExtraData.decode(header);
final Address proposer = IbftBlockHashing.recoverProposerAddress(header, ibftExtraData);

@ -45,8 +45,7 @@ import org.junit.Test;
public class IbftBlockHeaderValidationRulesetFactoryTest {
private ProtocolContext<IbftContext> setupContextWithValidators(
final Collection<Address> validators) {
private ProtocolContext setupContextWithValidators(final Collection<Address> validators) {
final IbftContext ibftContext = mock(IbftContext.class);
final VoteTallyCache mockCache = mock(VoteTallyCache.class);
final VoteTally mockVoteTally = mock(VoteTally.class);
@ -54,7 +53,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
when(mockCache.getVoteTallyAfterBlock(any())).thenReturn(mockVoteTally);
when(mockVoteTally.getValidators()).thenReturn(validators);
return new ProtocolContext<>(null, null, ibftContext);
return new ProtocolContext(null, null, ibftContext);
}
@Test
@ -68,7 +67,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
final BlockHeader parentHeader = buildBlockHeader(1, proposerKeyPair, validators, null);
final BlockHeader blockHeader = buildBlockHeader(2, proposerKeyPair, validators, parentHeader);
final BlockHeaderValidator<IbftContext> validator =
final BlockHeaderValidator validator =
IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5).build();
assertThat(
@ -91,7 +90,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
final BlockHeader parentHeader = buildBlockHeader(1, proposerKeyPair, validators, null);
final BlockHeader blockHeader = buildBlockHeader(2, proposerKeyPair, validators, null);
final BlockHeaderValidator<IbftContext> validator =
final BlockHeaderValidator validator =
IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5).build();
assertThat(

@ -22,7 +22,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibftlegacy.IbftBlockHeaderValidationRulesetFactory;
import org.hyperledger.besu.consensus.ibftlegacy.IbftExtraData;
import org.hyperledger.besu.consensus.ibftlegacy.IbftProtocolSchedule;
@ -80,13 +79,13 @@ public class IbftBlockCreatorTest {
Address.fromHexString(String.format("%020d", 4)),
localAddr);
final ProtocolSchedule<IbftContext> protocolSchedule =
final ProtocolSchedule protocolSchedule =
IbftProtocolSchedule.create(
GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}")
.getConfigOptions(),
false);
final ProtocolContext<IbftContext> protContext =
new ProtocolContext<>(
final ProtocolContext protContext =
new ProtocolContext(
blockchain,
createInMemoryWorldStateArchive(),
setupContextWithValidators(initialValidatorList));
@ -117,7 +116,7 @@ public class IbftBlockCreatorTest {
final Block block = blockCreator.createBlock(Instant.now().getEpochSecond());
final BlockHeaderValidator<IbftContext> rules =
final BlockHeaderValidator rules =
IbftBlockHeaderValidationRulesetFactory.ibftProposedBlockValidator(0).build();
final boolean validationResult =

@ -19,7 +19,6 @@ import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.consensus.ibft.IbftContextBuilder.setupContextWithValidators;
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibftlegacy.IbftBlockHashing;
import org.hyperledger.besu.consensus.ibftlegacy.IbftExtraData;
import org.hyperledger.besu.crypto.SECP256K1;
@ -102,8 +101,8 @@ public class IbftExtraDataValidationRuleTest {
Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes()));
final List<Address> validators = singletonList(proposerAddress);
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(validators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators));
final IbftExtraDataValidationRule extraDataValidationRule =
new IbftExtraDataValidationRule(true);
@ -128,8 +127,8 @@ public class IbftExtraDataValidationRuleTest {
Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes()));
final List<Address> validators = singletonList(proposerAddress);
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(validators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators));
final IbftExtraDataValidationRule extraDataValidationRule =
new IbftExtraDataValidationRule(true);
@ -155,8 +154,8 @@ public class IbftExtraDataValidationRuleTest {
Lists.newArrayList(
AddressHelpers.calculateAddressWithRespectTo(proposerAddress, 1), proposerAddress);
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(validators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators));
final IbftExtraDataValidationRule extraDataValidationRule =
new IbftExtraDataValidationRule(true);
@ -184,8 +183,8 @@ public class IbftExtraDataValidationRuleTest {
Lists.newArrayList(
AddressHelpers.calculateAddressWithRespectTo(proposerAddress, 1), proposerAddress);
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(validators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators));
final IbftExtraDataValidationRule extraDataValidationRule =
new IbftExtraDataValidationRule(true);
@ -211,8 +210,8 @@ public class IbftExtraDataValidationRuleTest {
final List<Address> validators = Lists.newArrayList(proposerAddress);
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(validators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators));
final IbftExtraDataValidationRule extraDataValidationRule =
new IbftExtraDataValidationRule(true);
@ -251,8 +250,8 @@ public class IbftExtraDataValidationRuleTest {
builder.extraData(commitedExtraData.encode());
header = builder.buildHeader();
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(validators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators));
final IbftExtraDataValidationRule extraDataValidationRule =
new IbftExtraDataValidationRule(true);
@ -316,8 +315,8 @@ public class IbftExtraDataValidationRuleTest {
builder.extraData(commitedExtraData.encode());
header = builder.buildHeader();
final ProtocolContext<IbftContext> context =
new ProtocolContext<>(null, null, setupContextWithValidators(validators));
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators));
final IbftExtraDataValidationRule extraDataValidationRule =
new IbftExtraDataValidationRule(true);

@ -33,7 +33,7 @@ public class BlockchainImporter {
private final GenesisState genesisState;
private final ProtocolSchedule<Void> protocolSchedule;
private final ProtocolSchedule protocolSchedule;
private final List<Block> blocks;
@ -64,7 +64,7 @@ public class BlockchainImporter {
return genesisState;
}
public ProtocolSchedule<Void> getProtocolSchedule() {
public ProtocolSchedule getProtocolSchedule() {
return protocolSchedule;
}

@ -72,13 +72,13 @@ public class JsonRpcTestMethodsFactory {
importer.getGenesisState().writeStateTo(stateArchive.getMutable());
final MutableBlockchain blockchain = createInMemoryBlockchain(importer.getGenesisBlock());
final ProtocolContext<Void> context = new ProtocolContext<>(blockchain, stateArchive, null);
final ProtocolContext context = new ProtocolContext(blockchain, stateArchive, null);
for (final Block block : importer.getBlocks()) {
final ProtocolSchedule<Void> protocolSchedule = importer.getProtocolSchedule();
final ProtocolSpec<Void> protocolSpec =
final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule();
final ProtocolSpec protocolSpec =
protocolSchedule.getByBlockNumber(block.getHeader().getNumber());
final BlockImporter<Void> blockImporter = protocolSpec.getBlockImporter();
final BlockImporter blockImporter = protocolSpec.getBlockImporter();
blockImporter.importBlock(context, block, HeaderValidationMode.FULL);
}

@ -104,7 +104,7 @@ public class EthGetFilterChangesIntegrationTest {
blockchain::getChainHeadHeader,
Optional.empty(),
TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
final ProtocolContext<Void> protocolContext = executionContext.getProtocolContext();
final ProtocolContext protocolContext = executionContext.getProtocolContext();
PeerTransactionTracker peerTransactionTracker = mock(PeerTransactionTracker.class);
PeerPendingTransactionTracker peerPendingTransactionTracker =

@ -25,12 +25,12 @@ public class GraphQLDataFetcherContext {
private final BlockchainQueries blockchainQueries;
private final MiningCoordinator miningCoordinator;
private final Synchronizer synchronizer;
private final ProtocolSchedule<?> protocolSchedule;
private final ProtocolSchedule protocolSchedule;
private final TransactionPool transactionPool;
public GraphQLDataFetcherContext(
final BlockchainQueries blockchainQueries,
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final TransactionPool transactionPool,
final MiningCoordinator miningCoordinator,
final Synchronizer synchronizer) {
@ -57,7 +57,7 @@ public class GraphQLDataFetcherContext {
return synchronizer;
}
public ProtocolSchedule<?> getProtocolSchedule() {
public ProtocolSchedule getProtocolSchedule() {
return protocolSchedule;
}
}

@ -191,7 +191,7 @@ public class BlockAdapterBase extends AdapterBase {
final Bytes data = (Bytes) callData.get("data");
final BlockchainQueries query = getBlockchainQueries(environment);
final ProtocolSchedule<?> protocolSchedule =
final ProtocolSchedule protocolSchedule =
((GraphQLDataFetcherContext) environment.getContext()).getProtocolSchedule();
final long bn = header.getNumber();

@ -91,7 +91,7 @@ public class PendingStateAdapter extends AdapterBase {
final Bytes data = (Bytes) callData.get("data");
final BlockchainQueries query = getBlockchainQueries(environment);
final ProtocolSchedule<?> protocolSchedule =
final ProtocolSchedule protocolSchedule =
((GraphQLDataFetcherContext) environment.getContext()).getProtocolSchedule();
final TransactionSimulator transactionSimulator =

@ -38,11 +38,11 @@ public class TraceBlock extends AbstractBlockParameterMethod {
private static final ObjectMapper MAPPER = new ObjectMapper();
private final Supplier<BlockTracer> blockTracerSupplier;
private final ProtocolSchedule<?> protocolSchedule;
private final ProtocolSchedule protocolSchedule;
public TraceBlock(
final Supplier<BlockTracer> blockTracerSupplier,
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final BlockchainQueries queries) {
super(queries);
this.blockTracerSupplier = blockTracerSupplier;

@ -52,11 +52,11 @@ public class TraceReplayBlockTransactions extends AbstractBlockParameterMethod {
private final Supplier<BlockTracer> blockTracerSupplier;
private final Supplier<StateDiffGenerator> stateDiffGenerator =
Suppliers.memoize(StateDiffGenerator::new);
private final ProtocolSchedule<?> protocolSchedule;
private final ProtocolSchedule protocolSchedule;
public TraceReplayBlockTransactions(
final Supplier<BlockTracer> blockTracerSupplier,
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final BlockchainQueries queries) {
super(queries);
this.blockTracerSupplier = blockTracerSupplier;
@ -171,7 +171,7 @@ public class TraceReplayBlockTransactions extends AbstractBlockParameterMethod {
private void generateTracesFromTransactionTrace(
final TraceWriter writer,
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final TransactionTrace transactionTrace,
final Block block,
final TraceFormatter formatter,

@ -41,11 +41,11 @@ public class TraceTransaction implements JsonRpcMethod {
private final Supplier<BlockTracer> blockTracerSupplier;
private final BlockchainQueries blockchainQueries;
private final ProtocolSchedule<?> protocolSchedule;
private final ProtocolSchedule protocolSchedule;
public TraceTransaction(
final Supplier<BlockTracer> blockTracerSupplier,
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final BlockchainQueries blockchainQueries) {
this.blockTracerSupplier = blockTracerSupplier;
this.blockchainQueries = blockchainQueries;
@ -87,7 +87,7 @@ public class TraceTransaction implements JsonRpcMethod {
}
private JsonNode generateTracesFromTransactionTraceAndBlock(
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final TransactionTrace transactionTrace,
final Block block) {
final ObjectMapper mapper = new ObjectMapper();

@ -34,12 +34,12 @@ import java.util.stream.Collectors;
public class BlockReplay {
private final ProtocolSchedule<?> protocolSchedule;
private final ProtocolSchedule protocolSchedule;
private final Blockchain blockchain;
private final WorldStateArchive worldStateArchive;
public BlockReplay(
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final Blockchain blockchain,
final WorldStateArchive worldStateArchive) {
this.protocolSchedule = protocolSchedule;
@ -85,7 +85,7 @@ public class BlockReplay {
action.performAction(
transaction, header, blockchain, mutableWorldState, transactionProcessor));
} else {
final ProtocolSpec<?> spec = protocolSchedule.getByBlockNumber(header.getNumber());
final ProtocolSpec spec = protocolSchedule.getByBlockNumber(header.getNumber());
transactionProcessor.processTransaction(
blockchain,
mutableWorldState.updater(),
@ -107,7 +107,7 @@ public class BlockReplay {
blockHash,
transactionHash,
(transaction, blockHeader, blockchain, worldState, transactionProcessor) -> {
final ProtocolSpec<?> spec = protocolSchedule.getByBlockNumber(blockHeader.getNumber());
final ProtocolSpec spec = protocolSchedule.getByBlockNumber(blockHeader.getNumber());
transactionProcessor.processTransaction(
blockchain,
worldState.updater(),
@ -136,7 +136,7 @@ public class BlockReplay {
if (body == null) {
return Optional.empty();
}
final ProtocolSpec<?> protocolSpec = protocolSchedule.getByBlockNumber(header.getNumber());
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(header.getNumber());
final TransactionProcessor transactionProcessor = protocolSpec.getTransactionProcessor();
final BlockHeader previous = blockchain.getBlockHeader(header.getParentHash()).orElse(null);
if (previous == null) {

@ -25,7 +25,7 @@ import java.util.stream.Stream;
public interface TraceFormatter {
Stream<Trace> format(
ProtocolSchedule<?> protocolSchedule,
ProtocolSchedule protocolSchedule,
TransactionTrace transactionTrace,
Block block,
AtomicInteger traceCounter);

@ -64,7 +64,7 @@ public class FlatTraceGenerator {
* @return a stream of generated traces {@link Trace}
*/
public static Stream<Trace> generateFromTransactionTrace(
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final TransactionTrace transactionTrace,
final Block block,
final AtomicInteger traceCounter,
@ -186,7 +186,7 @@ public class FlatTraceGenerator {
* @return a stream of generated traces {@link Trace}
*/
public static Stream<Trace> generateFromTransactionTrace(
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final TransactionTrace transactionTrace,
final Block block,
final AtomicInteger traceCounter) {
@ -208,7 +208,7 @@ public class FlatTraceGenerator {
* @return a stream of generated traces {@link Trace}
*/
public static Stream<Trace> generateFromTransactionTraceAndBlock(
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final TransactionTrace transactionTrace,
final Block block) {
return generateFromTransactionTrace(
@ -269,7 +269,7 @@ public class FlatTraceGenerator {
}
private static FlatTrace.Context handleReturn(
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final TransactionTrace transactionTrace,
final Block block,
final TraceFrame traceFrame,

@ -40,13 +40,13 @@ public class RewardTraceGenerator {
* @return a stream of generated reward traces {@link Trace}
*/
public static Stream<Trace> generateFromBlock(
final ProtocolSchedule<?> protocolSchedule, final Block block) {
final ProtocolSchedule protocolSchedule, final Block block) {
final List<Trace> flatTraces = new ArrayList<>();
final BlockHeader blockHeader = block.getHeader();
final List<BlockHeader> ommers = block.getBody().getOmmers();
final ProtocolSpec<?> protocolSpec = protocolSchedule.getByBlockNumber(blockHeader.getNumber());
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(blockHeader.getNumber());
final Wei blockReward = protocolSpec.getBlockReward();
final MiningBeneficiaryCalculator miningBeneficiaryCalculator =
protocolSpec.getMiningBeneficiaryCalculator();

@ -37,12 +37,12 @@ import java.util.Map;
public class DebugJsonRpcMethods extends ApiGroupJsonRpcMethods {
private final BlockchainQueries blockchainQueries;
private final ProtocolSchedule<?> protocolSchedule;
private final ProtocolSchedule protocolSchedule;
private final ObservableMetricsSystem metricsSystem;
DebugJsonRpcMethods(
final BlockchainQueries blockchainQueries,
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final ObservableMetricsSystem metricsSystem) {
this.blockchainQueries = blockchainQueries;
this.protocolSchedule = protocolSchedule;

@ -32,7 +32,7 @@ public class EeaJsonRpcMethods extends PrivacyApiGroupJsonRpcMethods {
public EeaJsonRpcMethods(
final BlockchainQueries blockchainQueries,
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final TransactionPool transactionPool,
final PrivacyParameters privacyParameters) {
super(blockchainQueries, protocolSchedule, transactionPool, privacyParameters);

@ -75,7 +75,7 @@ public class EthJsonRpcMethods extends ApiGroupJsonRpcMethods {
private final BlockchainQueries blockchainQueries;
private final Synchronizer synchronizer;
private final ProtocolSchedule<?> protocolSchedule;
private final ProtocolSchedule protocolSchedule;
private final FilterManager filterManager;
private final TransactionPool transactionPool;
private final MiningCoordinator miningCoordinator;
@ -84,7 +84,7 @@ public class EthJsonRpcMethods extends ApiGroupJsonRpcMethods {
public EthJsonRpcMethods(
final BlockchainQueries blockchainQueries,
final Synchronizer synchronizer,
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final FilterManager filterManager,
final TransactionPool transactionPool,
final MiningCoordinator miningCoordinator,

@ -53,7 +53,7 @@ public class JsonRpcMethodsFactory {
final P2PNetwork p2pNetwork,
final BlockchainQueries blockchainQueries,
final Synchronizer synchronizer,
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final FilterManager filterManager,
final TransactionPool transactionPool,
final MiningCoordinator miningCoordinator,

@ -33,14 +33,14 @@ import java.util.Map;
public class NetJsonRpcMethods extends ApiGroupJsonRpcMethods {
private final P2PNetwork p2pNetwork;
private final ProtocolSchedule<?> protocolSchedule;
private final ProtocolSchedule protocolSchedule;
private final JsonRpcConfiguration jsonRpcConfiguration;
private final WebSocketConfiguration webSocketConfiguration;
private final MetricsConfiguration metricsConfiguration;
public NetJsonRpcMethods(
final P2PNetwork p2pNetwork,
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final JsonRpcConfiguration jsonRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
final MetricsConfiguration metricsConfiguration) {

@ -48,7 +48,7 @@ public class PrivJsonRpcMethods extends PrivacyApiGroupJsonRpcMethods {
public PrivJsonRpcMethods(
final BlockchainQueries blockchainQueries,
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final TransactionPool transactionPool,
final PrivacyParameters privacyParameters,
final FilterManager filterManager) {

@ -45,7 +45,7 @@ import java.util.stream.Collectors;
public abstract class PrivacyApiGroupJsonRpcMethods extends ApiGroupJsonRpcMethods {
private final BlockchainQueries blockchainQueries;
private final ProtocolSchedule<?> protocolSchedule;
private final ProtocolSchedule protocolSchedule;
private final TransactionPool transactionPool;
private final PrivacyParameters privacyParameters;
private final PrivateNonceProvider privateNonceProvider;
@ -53,7 +53,7 @@ public abstract class PrivacyApiGroupJsonRpcMethods extends ApiGroupJsonRpcMetho
public PrivacyApiGroupJsonRpcMethods(
final BlockchainQueries blockchainQueries,
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final TransactionPool transactionPool,
final PrivacyParameters privacyParameters) {
this.blockchainQueries = blockchainQueries;
@ -75,7 +75,7 @@ public abstract class PrivacyApiGroupJsonRpcMethods extends ApiGroupJsonRpcMetho
return blockchainQueries;
}
public ProtocolSchedule<?> getProtocolSchedule() {
public ProtocolSchedule getProtocolSchedule() {
return protocolSchedule;
}

@ -31,7 +31,7 @@ public class PrivxJsonRpcMethods extends PrivacyApiGroupJsonRpcMethods {
public PrivxJsonRpcMethods(
final BlockchainQueries blockchainQueries,
final ProtocolSchedule<?> protocolSchedule,
final ProtocolSchedule protocolSchedule,
final TransactionPool transactionPool,
final PrivacyParameters privacyParameters) {
super(blockchainQueries, protocolSchedule, transactionPool, privacyParameters);

@ -30,10 +30,10 @@ import java.util.Map;
public class TraceJsonRpcMethods extends ApiGroupJsonRpcMethods {
private final BlockchainQueries blockchainQueries;
private final ProtocolSchedule<?> protocolSchedule;
private final ProtocolSchedule protocolSchedule;
TraceJsonRpcMethods(
final BlockchainQueries blockchainQueries, final ProtocolSchedule<?> protocolSchedule) {
final BlockchainQueries blockchainQueries, final ProtocolSchedule protocolSchedule) {
this.blockchainQueries = blockchainQueries;
this.protocolSchedule = protocolSchedule;
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save