Extract common components from MiningCoordinator (#21)

The MiningCoordinator has been split into common, and ethhash
specific funcationality.

This adversely affects the JSON RPC, in that all mining related
RPCs are now generic based on the type of miner being used.
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
tmohay 6 years ago committed by GitHub
parent 02eb60fa47
commit 76a50ee180
  1. 2
      acceptance-tests/src/test/java/net/consensys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java
  2. 2
      consensus/clique/src/main/java/net/consensys/pantheon/consensus/clique/blockcreation/CliqueBlockMiner.java
  3. 2
      consensus/clique/src/main/java/net/consensys/pantheon/consensus/clique/blockcreation/CliqueMinerExecutor.java
  4. 25
      consensus/ibft/src/main/java/net/consensys/pantheon/consensus/ibft/blockcreation/IbftBlockMiner.java
  5. 2
      ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/AbstractMinerExecutor.java
  6. 131
      ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/AbstractMiningCoordinator.java
  7. 2
      ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/BlockMiner.java
  8. 2
      ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/EthHashBlockMiner.java
  9. 2
      ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/EthHashMinerExecutor.java
  10. 83
      ethereum/core/src/main/java/net/consensys/pantheon/ethereum/blockcreation/EthHashMiningCoordinator.java
  11. 2
      ethereum/core/src/test/java/net/consensys/pantheon/ethereum/blockcreation/BlockMinerTest.java
  12. 10
      ethereum/core/src/test/java/net/consensys/pantheon/ethereum/blockcreation/EthHashMiningCoordinatorTest.java
  13. 2
      ethereum/eth/src/main/java/net/consensys/pantheon/ethereum/eth/manager/EthProtocolManager.java
  14. 4
      ethereum/jsonrpc/src/integration-test/java/net/consensys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java
  15. 14
      ethereum/jsonrpc/src/main/java/net/consensys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java
  16. 6
      ethereum/jsonrpc/src/main/java/net/consensys/pantheon/ethereum/jsonrpc/internal/methods/EthCoinbase.java
  17. 11
      ethereum/jsonrpc/src/main/java/net/consensys/pantheon/ethereum/jsonrpc/internal/methods/EthGasPrice.java
  18. 11
      ethereum/jsonrpc/src/main/java/net/consensys/pantheon/ethereum/jsonrpc/internal/methods/EthMining.java
  19. 6
      ethereum/jsonrpc/src/main/java/net/consensys/pantheon/ethereum/jsonrpc/internal/methods/miner/MinerSetCoinbase.java
  20. 11
      ethereum/jsonrpc/src/main/java/net/consensys/pantheon/ethereum/jsonrpc/internal/methods/miner/MinerStart.java
  21. 11
      ethereum/jsonrpc/src/main/java/net/consensys/pantheon/ethereum/jsonrpc/internal/methods/miner/MinerStop.java
  22. 4
      ethereum/jsonrpc/src/test/java/net/consensys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java
  23. 4
      ethereum/jsonrpc/src/test/java/net/consensys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java
  24. 4
      ethereum/jsonrpc/src/test/java/net/consensys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java
  25. 4
      ethereum/jsonrpc/src/test/java/net/consensys/pantheon/ethereum/jsonrpc/internal/methods/EthCoinbaseTest.java
  26. 9
      ethereum/jsonrpc/src/test/java/net/consensys/pantheon/ethereum/jsonrpc/internal/methods/EthGasPriceTest.java
  27. 9
      ethereum/jsonrpc/src/test/java/net/consensys/pantheon/ethereum/jsonrpc/internal/methods/EthMiningTest.java
  28. 4
      ethereum/jsonrpc/src/test/java/net/consensys/pantheon/ethereum/jsonrpc/internal/methods/miner/MinerSetCoinbaseTest.java
  29. 9
      ethereum/jsonrpc/src/test/java/net/consensys/pantheon/ethereum/jsonrpc/internal/methods/miner/MinerStartTest.java
  30. 9
      ethereum/jsonrpc/src/test/java/net/consensys/pantheon/ethereum/jsonrpc/internal/methods/miner/MinerStopTest.java
  31. 4
      pantheon/src/main/java/net/consensys/pantheon/Runner.java
  32. 11
      pantheon/src/main/java/net/consensys/pantheon/RunnerBuilder.java
  33. 2
      pantheon/src/main/java/net/consensys/pantheon/cli/ExportPublicKeySubCommand.java
  34. 4
      pantheon/src/main/java/net/consensys/pantheon/cli/PantheonCommand.java
  35. 2
      pantheon/src/main/java/net/consensys/pantheon/cli/PantheonControllerBuilder.java
  36. 10
      pantheon/src/main/java/net/consensys/pantheon/controller/CliquePantheonController.java
  37. 9
      pantheon/src/main/java/net/consensys/pantheon/controller/IbftPantheonController.java
  38. 20
      pantheon/src/main/java/net/consensys/pantheon/controller/MainnetPantheonController.java
  39. 11
      pantheon/src/main/java/net/consensys/pantheon/controller/PantheonController.java
  40. 7
      pantheon/src/main/java/net/consensys/pantheon/util/BlockImporter.java
  41. 45
      pantheon/src/main/java/net/consensys/pantheon/util/BlockchainImporter.java
  42. 7
      pantheon/src/test/java/net/consensys/pantheon/RunnerTest.java
  43. 2
      pantheon/src/test/java/net/consensys/pantheon/cli/CommandTestAbstract.java
  44. 2
      pantheon/src/test/java/net/consensys/pantheon/util/BlockImporterTest.java
  45. 3
      pantheon/src/test/java/net/consensys/pantheon/util/BlockchainImporterTest.java

@ -33,7 +33,7 @@ public class ThreadPantheonNodeRunner implements PantheonNodeRunner {
}
final PantheonControllerBuilder builder = new PantheonControllerBuilder();
PantheonController<?> pantheonController;
PantheonController<?, ?> pantheonController;
try {
pantheonController =
builder.build(

@ -5,8 +5,8 @@ import net.consensys.pantheon.consensus.clique.CliqueHelpers;
import net.consensys.pantheon.consensus.common.ValidatorProvider;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.AbstractBlockScheduler;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.blockcreation.BlockMiner;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.core.Address;
import net.consensys.pantheon.ethereum.core.BlockHeader;
import net.consensys.pantheon.ethereum.mainnet.ProtocolSchedule;

@ -8,7 +8,7 @@ import net.consensys.pantheon.crypto.SECP256K1.KeyPair;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.AbstractBlockScheduler;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMinerExecutor;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.blockcreation.MiningParameters;
import net.consensys.pantheon.ethereum.core.Address;
import net.consensys.pantheon.ethereum.core.BlockHeader;

@ -0,0 +1,25 @@
package net.consensys.pantheon.consensus.ibft.blockcreation;
import net.consensys.pantheon.consensus.ibft.IbftContext;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.AbstractBlockScheduler;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.blockcreation.BlockMiner;
import net.consensys.pantheon.ethereum.core.BlockHeader;
import net.consensys.pantheon.ethereum.mainnet.ProtocolSchedule;
import net.consensys.pantheon.util.Subscribers;
public class IbftBlockMiner extends BlockMiner<IbftContext, IbftBlockCreator> {
// TODO(tmm): Currently a place holder to allow infrastructure code to continue to operate
// with the advent of multiple consensus methods.
public IbftBlockMiner(
final IbftBlockCreator blockCreator,
final ProtocolSchedule<IbftContext> protocolSchedule,
final ProtocolContext<IbftContext> protocolContext,
final Subscribers<MinedBlockObserver> observers,
final AbstractBlockScheduler scheduler,
final BlockHeader parentHeader) {
super(blockCreator, protocolSchedule, protocolContext, observers, scheduler, parentHeader);
}
}

@ -1,7 +1,7 @@
package net.consensys.pantheon.ethereum.blockcreation;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.core.BlockHeader;
import net.consensys.pantheon.ethereum.core.PendingTransactions;
import net.consensys.pantheon.ethereum.core.Wei;

@ -15,61 +15,66 @@ import net.consensys.pantheon.util.bytes.BytesValue;
import java.util.Optional;
/**
* Responsible for determining when a block mining operation should be started/stopped, then
* creating an appropriate miner and starting it running in a thread.
*/
public class MiningCoordinator implements BlockAddedObserver {
public abstract class AbstractMiningCoordinator<
C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
implements BlockAddedObserver {
private final Subscribers<MinedBlockObserver> minedBlockObservers = new Subscribers<>();
private final EthHashMinerExecutor executor;
protected boolean isEnabled = false;
protected volatile Optional<M> currentRunningMiner = Optional.empty();
private volatile Optional<EthHashBlockMiner> currentRunningMiner = Optional.empty();
private volatile Optional<Long> cachedHashesPerSecond = Optional.empty();
private boolean isEnabled = false;
private final Blockchain blockchain;
private final Subscribers<MinedBlockObserver> minedBlockObservers = new Subscribers<>();
private final AbstractMinerExecutor<C, M> executor;
protected final Blockchain blockchain;
public MiningCoordinator(final Blockchain blockchain, final EthHashMinerExecutor executor) {
public AbstractMiningCoordinator(
final Blockchain blockchain, final AbstractMinerExecutor<C, M> executor) {
this.executor = executor;
this.blockchain = blockchain;
this.blockchain.observeBlockAdded(this);
}
public void enable() {
public abstract void enable();
public abstract void disable();
public boolean isRunning() {
synchronized (this) {
if (isEnabled) {
return;
}
startAsyncMiningOperation();
isEnabled = true;
return isEnabled;
}
}
public void disable() {
protected void startAsyncMiningOperation() {
final BlockHeader parentHeader = blockchain.getChainHeadHeader();
currentRunningMiner = Optional.of(executor.startAsyncMining(minedBlockObservers, parentHeader));
}
protected void haltCurrentMiningOperation() {
currentRunningMiner.ifPresent(M::cancel);
}
@Override
public void onBlockAdded(final BlockAddedEvent event, final Blockchain blockchain) {
synchronized (this) {
if (!isEnabled) {
return;
if (isEnabled && shouldStartNewMiner(event)) {
haltCurrentMiningOperation();
startAsyncMiningOperation();
}
haltCurrentMiningOperation();
isEnabled = false;
}
}
public boolean isRunning() {
synchronized (this) {
return isEnabled;
}
private boolean shouldStartNewMiner(final BlockAddedEvent event) {
return event.getEventType() != EventType.FORK;
}
public void setCoinbase(final Address coinbase) {
executor.setCoinbase(coinbase);
public void removeMinedBlockObserver(final long id) {
minedBlockObservers.unsubscribe(id);
}
public Optional<Address> getCoinbase() {
return executor.getCoinbase();
public long addMinedBlockObserver(final MinedBlockObserver obs) {
return minedBlockObservers.subscribe(obs);
}
// Required for JSON RPC, and are deemed to be valid for all mining mechanisms
public void setMinTransactionGasPrice(final Wei minGasPrice) {
executor.setMinTransactionGasPrice(minGasPrice);
}
@ -82,61 +87,29 @@ public class MiningCoordinator implements BlockAddedObserver {
executor.setExtraData(extraData);
}
public Optional<Long> hashesPerSecond() {
final Optional<Long> currentHashesPerSecond =
currentRunningMiner.flatMap(EthHashBlockMiner::getHashesPerSecond);
if (currentHashesPerSecond.isPresent()) {
cachedHashesPerSecond = currentHashesPerSecond;
return currentHashesPerSecond;
} else {
return cachedHashesPerSecond;
}
}
public Optional<EthHashSolverInputs> getWorkDefinition() {
return currentRunningMiner.flatMap(EthHashBlockMiner::getWorkDefinition);
}
public boolean submitWork(final EthHashSolution solution) {
synchronized (this) {
return currentRunningMiner.map(miner -> miner.submitWork(solution)).orElse(false);
}
}
@Override
public void onBlockAdded(final BlockAddedEvent event, final Blockchain blockchain) {
synchronized (this) {
if (isEnabled && shouldStartNewMiner(event)) {
haltCurrentMiningOperation();
startAsyncMiningOperation();
}
}
}
private boolean shouldStartNewMiner(final BlockAddedEvent event) {
return event.getEventType() != EventType.FORK;
public void setCoinbase(final Address coinbase) {
throw new UnsupportedOperationException(
"Current consensus mechanism prevents" + " setting coinbase.");
}
private void startAsyncMiningOperation() {
final BlockHeader parentHeader = blockchain.getChainHeadHeader();
currentRunningMiner = Optional.of(executor.startAsyncMining(minedBlockObservers, parentHeader));
public Optional<Address> getCoinbase() {
throw new UnsupportedOperationException(
"Current consensus mechanism prevents" + " querying of coinbase.");
}
private void haltCurrentMiningOperation() {
currentRunningMiner.ifPresent(
miner -> {
miner.cancel();
miner.getHashesPerSecond().ifPresent(val -> cachedHashesPerSecond = Optional.of(val));
});
public Optional<Long> hashesPerSecond() {
throw new UnsupportedOperationException(
"Current consensus mechanism prevents querying " + "of hashrate.");
}
public long addMinedBlockObserver(final MinedBlockObserver obs) {
return minedBlockObservers.subscribe(obs);
public Optional<EthHashSolverInputs> getWorkDefinition() {
throw new UnsupportedOperationException(
"Current consensus mechanism prevents querying " + "work definition.");
}
public void removeMinedBlockObserver(final long id) {
minedBlockObservers.unsubscribe(id);
public boolean submitWork(final EthHashSolution solution) {
throw new UnsupportedOperationException(
"Current consensus mechanism prevents submission of work" + " solutions.");
}
public interface MinedBlockObserver {

@ -1,7 +1,7 @@
package net.consensys.pantheon.ethereum.blockcreation;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.core.Block;
import net.consensys.pantheon.ethereum.core.BlockHeader;
import net.consensys.pantheon.ethereum.core.BlockImporter;

@ -1,7 +1,7 @@
package net.consensys.pantheon.ethereum.blockcreation;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.core.BlockHeader;
import net.consensys.pantheon.ethereum.mainnet.EthHashBlockCreator;
import net.consensys.pantheon.ethereum.mainnet.EthHashSolution;

@ -1,7 +1,7 @@
package net.consensys.pantheon.ethereum.blockcreation;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.core.Address;
import net.consensys.pantheon.ethereum.core.BlockHeader;
import net.consensys.pantheon.ethereum.core.PendingTransactions;

@ -0,0 +1,83 @@
package net.consensys.pantheon.ethereum.blockcreation;
import net.consensys.pantheon.ethereum.chain.BlockAddedObserver;
import net.consensys.pantheon.ethereum.chain.Blockchain;
import net.consensys.pantheon.ethereum.core.Address;
import net.consensys.pantheon.ethereum.mainnet.EthHashSolution;
import net.consensys.pantheon.ethereum.mainnet.EthHashSolverInputs;
import java.util.Optional;
/**
* Responsible for determining when a block mining operation should be started/stopped, then
* creating an appropriate miner and starting it running in a thread.
*/
public class EthHashMiningCoordinator extends AbstractMiningCoordinator<Void, EthHashBlockMiner>
implements BlockAddedObserver {
private final EthHashMinerExecutor executor;
private volatile Optional<Long> cachedHashesPerSecond = Optional.empty();
public EthHashMiningCoordinator(
final Blockchain blockchain, final EthHashMinerExecutor executor) {
super(blockchain, executor);
this.executor = executor;
}
@Override
public void enable() {
synchronized (this) {
if (isEnabled) {
return;
}
startAsyncMiningOperation();
isEnabled = true;
}
}
@Override
public void disable() {
synchronized (this) {
if (!isEnabled) {
return;
}
haltCurrentMiningOperation();
isEnabled = false;
}
}
@Override
public void setCoinbase(final Address coinbase) {
executor.setCoinbase(coinbase);
}
@Override
public Optional<Address> getCoinbase() {
return executor.getCoinbase();
}
@Override
public Optional<Long> hashesPerSecond() {
final Optional<Long> currentHashesPerSecond =
currentRunningMiner.flatMap(EthHashBlockMiner::getHashesPerSecond);
if (currentHashesPerSecond.isPresent()) {
cachedHashesPerSecond = currentHashesPerSecond;
return currentHashesPerSecond;
} else {
return cachedHashesPerSecond;
}
}
@Override
public Optional<EthHashSolverInputs> getWorkDefinition() {
return currentRunningMiner.flatMap(EthHashBlockMiner::getWorkDefinition);
}
@Override
public boolean submitWork(final EthHashSolution solution) {
synchronized (this) {
return currentRunningMiner.map(miner -> miner.submitWork(solution)).orElse(false);
}
}
}

@ -8,7 +8,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.core.Block;
import net.consensys.pantheon.ethereum.core.BlockBody;
import net.consensys.pantheon.ethereum.core.BlockHeaderTestFixture;

@ -14,15 +14,15 @@ import java.util.Optional;
import org.junit.Test;
public class MiningCoordinatorTest {
public class EthHashMiningCoordinatorTest {
private final ExecutionContextTestFixture executionContext = new ExecutionContextTestFixture();
@Test
public void miningCoordinatorIsCreatedDisabledWithNoReportableMiningStatistics() {
final EthHashMinerExecutor executor = mock(EthHashMinerExecutor.class);
final MiningCoordinator miningCoordinator =
new MiningCoordinator(executionContext.getBlockchain(), executor);
final EthHashMiningCoordinator miningCoordinator =
new EthHashMiningCoordinator(executionContext.getBlockchain(), executor);
final EthHashSolution solution = new EthHashSolution(1L, Hash.EMPTY, new byte[Bytes32.SIZE]);
assertThat(miningCoordinator.isRunning()).isFalse();
@ -46,8 +46,8 @@ public class MiningCoordinatorTest {
final EthHashMinerExecutor executor = mock(EthHashMinerExecutor.class);
when(executor.startAsyncMining(any(), any())).thenReturn(miner);
final MiningCoordinator miningCoordinator =
new MiningCoordinator(executionContext.getBlockchain(), executor);
final EthHashMiningCoordinator miningCoordinator =
new EthHashMiningCoordinator(executionContext.getBlockchain(), executor);
miningCoordinator.enable(); // Must enable prior returning data
assertThat(miningCoordinator.hashesPerSecond()).isEqualTo(hashRate1);

@ -2,7 +2,7 @@ package net.consensys.pantheon.ethereum.eth.manager;
import static com.google.common.base.Preconditions.checkArgument;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator.MinedBlockObserver;
import net.consensys.pantheon.ethereum.chain.Blockchain;
import net.consensys.pantheon.ethereum.core.Block;
import net.consensys.pantheon.ethereum.core.Hash;

@ -3,7 +3,7 @@ package net.consensys.pantheon.ethereum.jsonrpc;
import static org.mockito.Mockito.mock;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import net.consensys.pantheon.ethereum.chain.MutableBlockchain;
import net.consensys.pantheon.ethereum.core.Block;
import net.consensys.pantheon.ethereum.core.BlockImporter;
@ -67,7 +67,7 @@ public class JsonRpcTestMethodsFactory {
final TransactionPool transactionPool = mock(TransactionPool.class);
final FilterManager filterManager =
new FilterManager(blockchainQueries, transactionPool, new FilterIdGenerator());
final MiningCoordinator miningCoordinator = mock(MiningCoordinator.class);
final EthHashMiningCoordinator miningCoordinator = mock(EthHashMiningCoordinator.class);
return new JsonRpcMethodsFactory()
.methods(

@ -1,6 +1,6 @@
package net.consensys.pantheon.ethereum.jsonrpc;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import net.consensys.pantheon.ethereum.chain.Blockchain;
import net.consensys.pantheon.ethereum.core.Synchronizer;
import net.consensys.pantheon.ethereum.core.TransactionPool;
@ -83,7 +83,7 @@ public class JsonRpcMethodsFactory {
final Synchronizer synchronizer,
final TransactionPool transactionPool,
final ProtocolSchedule<?> protocolSchedule,
final MiningCoordinator miningCoordinator,
final AbstractMiningCoordinator<?, ?> miningCoordinator,
final Set<Capability> supportedCapabilities,
final Collection<RpcApis> rpcApis) {
final BlockchainQueries blockchainQueries =
@ -113,7 +113,7 @@ public class JsonRpcMethodsFactory {
final ProtocolSchedule<?> protocolSchedule,
final FilterManager filterManager,
final TransactionPool transactionPool,
final MiningCoordinator miningCoordinator,
final AbstractMiningCoordinator<?, ?> miningCoordinator,
final Set<Capability> supportedCapabilities,
final Collection<RpcApis> rpcApis) {
final Map<String, JsonRpcMethod> enabledMethods = new HashMap<>();
@ -164,10 +164,10 @@ public class JsonRpcMethodsFactory {
blockchainQueries.getWorldStateArchive(),
protocolSchedule),
parameter),
new EthMining(miningCoordinator),
new EthMining<>(miningCoordinator),
new EthCoinbase(miningCoordinator),
new EthProtocolVersion(supportedCapabilities),
new EthGasPrice(miningCoordinator));
new EthGasPrice<>(miningCoordinator));
}
if (rpcApis.contains(RpcApis.DEBUG)) {
final BlockReplay blockReplay =
@ -196,8 +196,8 @@ public class JsonRpcMethodsFactory {
final MinerSetCoinbase minerSetCoinbase = new MinerSetCoinbase(miningCoordinator, parameter);
addMethods(
enabledMethods,
new MinerStart(miningCoordinator),
new MinerStop(miningCoordinator),
new MinerStart<>(miningCoordinator),
new MinerStop<>(miningCoordinator),
minerSetCoinbase,
new MinerSetEtherbase(minerSetCoinbase));
}

@ -1,6 +1,6 @@
package net.consensys.pantheon.ethereum.jsonrpc.internal.methods;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import net.consensys.pantheon.ethereum.core.Address;
import net.consensys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError;
@ -12,9 +12,9 @@ import java.util.Optional;
public class EthCoinbase implements JsonRpcMethod {
private final MiningCoordinator miningCoordinator;
private final AbstractMiningCoordinator<?, ?> miningCoordinator;
public EthCoinbase(final MiningCoordinator miningCoordinator) {
public EthCoinbase(final AbstractMiningCoordinator<?, ?> miningCoordinator) {
this.miningCoordinator = miningCoordinator;
}

@ -1,17 +1,20 @@
package net.consensys.pantheon.ethereum.jsonrpc.internal.methods;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.AbstractBlockCreator;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.BlockMiner;
import net.consensys.pantheon.ethereum.core.Wei;
import net.consensys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import net.consensys.pantheon.ethereum.jsonrpc.internal.results.Quantity;
public class EthGasPrice implements JsonRpcMethod {
public class EthGasPrice<C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
implements JsonRpcMethod {
private final MiningCoordinator miningCoordinator;
private final AbstractMiningCoordinator<C, M> miningCoordinator;
public EthGasPrice(final MiningCoordinator miningCoordinator) {
public EthGasPrice(final AbstractMiningCoordinator<C, M> miningCoordinator) {
this.miningCoordinator = miningCoordinator;
}

@ -1,15 +1,18 @@
package net.consensys.pantheon.ethereum.jsonrpc.internal.methods;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.AbstractBlockCreator;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.BlockMiner;
import net.consensys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
public class EthMining implements JsonRpcMethod {
public class EthMining<C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
implements JsonRpcMethod {
private final MiningCoordinator miningCoordinator;
private final AbstractMiningCoordinator<C, M> miningCoordinator;
public EthMining(final MiningCoordinator miningCoordinator) {
public EthMining(final AbstractMiningCoordinator<C, M> miningCoordinator) {
this.miningCoordinator = miningCoordinator;
}

@ -1,6 +1,6 @@
package net.consensys.pantheon.ethereum.jsonrpc.internal.methods.miner;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import net.consensys.pantheon.ethereum.core.Address;
import net.consensys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import net.consensys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
@ -10,11 +10,11 @@ import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessR
public class MinerSetCoinbase implements JsonRpcMethod {
private final MiningCoordinator miningCoordinator;
private final AbstractMiningCoordinator<?, ?> miningCoordinator;
private final JsonRpcParameter parameters;
public MinerSetCoinbase(
final MiningCoordinator miningCoordinator, final JsonRpcParameter parameters) {
final AbstractMiningCoordinator<?, ?> miningCoordinator, final JsonRpcParameter parameters) {
this.miningCoordinator = miningCoordinator;
this.parameters = parameters;
}

@ -1,7 +1,9 @@
package net.consensys.pantheon.ethereum.jsonrpc.internal.methods.miner;
import net.consensys.pantheon.ethereum.blockcreation.AbstractBlockCreator;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.BlockMiner;
import net.consensys.pantheon.ethereum.blockcreation.CoinbaseNotSetException;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import net.consensys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError;
@ -9,11 +11,12 @@ import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorRes
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
public class MinerStart implements JsonRpcMethod {
public class MinerStart<C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
implements JsonRpcMethod {
private final MiningCoordinator miningCoordinator;
private final AbstractMiningCoordinator<C, M> miningCoordinator;
public MinerStart(final MiningCoordinator miningCoordinator) {
public MinerStart(final AbstractMiningCoordinator<C, M> miningCoordinator) {
this.miningCoordinator = miningCoordinator;
}

@ -1,16 +1,19 @@
package net.consensys.pantheon.ethereum.jsonrpc.internal.methods.miner;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.AbstractBlockCreator;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.BlockMiner;
import net.consensys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import net.consensys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
public class MinerStop implements JsonRpcMethod {
public class MinerStop<C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
implements JsonRpcMethod {
private final MiningCoordinator miningCoordinator;
private final AbstractMiningCoordinator<C, M> miningCoordinator;
public MinerStop(final MiningCoordinator miningCoordinator) {
public MinerStop(final AbstractMiningCoordinator<C, M> miningCoordinator) {
this.miningCoordinator = miningCoordinator;
}

@ -7,7 +7,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import net.consensys.pantheon.ethereum.chain.GenesisConfig;
import net.consensys.pantheon.ethereum.chain.MutableBlockchain;
import net.consensys.pantheon.ethereum.core.Block;
@ -130,7 +130,7 @@ public abstract class AbstractEthJsonRpcHttpServiceTest {
final Synchronizer synchronizerMock = mock(Synchronizer.class);
final P2PNetwork peerDiscoveryMock = mock(P2PNetwork.class);
final TransactionPool transactionPoolMock = mock(TransactionPool.class);
final MiningCoordinator miningCoordinatorMock = mock(MiningCoordinator.class);
final EthHashMiningCoordinator miningCoordinatorMock = mock(EthHashMiningCoordinator.class);
when(transactionPoolMock.addLocalTransaction(any(Transaction.class)))
.thenReturn(ValidationResult.valid());
final PendingTransactions pendingTransactionsMock = mock(PendingTransactions.class);

@ -5,7 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import net.consensys.pantheon.ethereum.core.Synchronizer;
import net.consensys.pantheon.ethereum.core.TransactionPool;
import net.consensys.pantheon.ethereum.eth.EthProtocol;
@ -162,7 +162,7 @@ public class JsonRpcHttpServiceRpcApisTest {
MainnetProtocolSchedule.create(),
mock(FilterManager.class),
mock(TransactionPool.class),
mock(MiningCoordinator.class),
mock(EthHashMiningCoordinator.class),
supportedCapabilities,
config.getRpcApis()));
final JsonRpcHttpService jsonRpcHttpService = new JsonRpcHttpService(vertx, config, rpcMethods);

@ -7,7 +7,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import net.consensys.pantheon.ethereum.core.Address;
import net.consensys.pantheon.ethereum.core.Block;
import net.consensys.pantheon.ethereum.core.BlockHeader;
@ -102,7 +102,7 @@ public class JsonRpcHttpServiceTest {
MainnetProtocolSchedule.create(),
mock(FilterManager.class),
mock(TransactionPool.class),
mock(MiningCoordinator.class),
mock(EthHashMiningCoordinator.class),
supportedCapabilities,
JSON_RPC_APIS));
service = createJsonRpcHttpService();

@ -5,7 +5,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import net.consensys.pantheon.ethereum.core.Address;
import net.consensys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError;
@ -24,7 +24,7 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class EthCoinbaseTest {
@Mock private MiningCoordinator miningCoordinator;
@Mock private EthHashMiningCoordinator miningCoordinator;
private EthCoinbase method;
private final String JSON_RPC_VERSION = "2.0";
private final String ETH_METHOD = "eth_coinbase";

@ -5,7 +5,8 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.EthHashBlockMiner;
import net.consensys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import net.consensys.pantheon.ethereum.core.Wei;
import net.consensys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
@ -20,14 +21,14 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class EthGasPriceTest {
@Mock private MiningCoordinator miningCoordinator;
private EthGasPrice method;
@Mock private EthHashMiningCoordinator miningCoordinator;
private EthGasPrice<Void, EthHashBlockMiner> method;
private final String JSON_RPC_VERSION = "2.0";
private final String ETH_METHOD = "eth_gasPrice";
@Before
public void setUp() {
method = new EthGasPrice(miningCoordinator);
method = new EthGasPrice<>(miningCoordinator);
}
@Test

@ -5,7 +5,8 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.EthHashBlockMiner;
import net.consensys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import net.consensys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
@ -19,14 +20,14 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class EthMiningTest {
@Mock private MiningCoordinator miningCoordinator;
private EthMining method;
@Mock private EthHashMiningCoordinator miningCoordinator;
private EthMining<Void, EthHashBlockMiner> method;
private final String JSON_RPC_VERSION = "2.0";
private final String ETH_METHOD = "eth_mining";
@Before
public void setUp() {
method = new EthMining(miningCoordinator);
method = new EthMining<>(miningCoordinator);
}
@Test

@ -5,7 +5,7 @@ import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import net.consensys.pantheon.ethereum.core.Address;
import net.consensys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import net.consensys.pantheon.ethereum.jsonrpc.internal.exception.InvalidJsonRpcParameters;
@ -24,7 +24,7 @@ public class MinerSetCoinbaseTest {
private MinerSetCoinbase method;
@Mock private MiningCoordinator miningCoordinator;
@Mock private EthHashMiningCoordinator miningCoordinator;
@Before
public void before() {

@ -4,7 +4,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doThrow;
import net.consensys.pantheon.ethereum.blockcreation.CoinbaseNotSetException;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.EthHashBlockMiner;
import net.consensys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import net.consensys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse;
@ -20,13 +21,13 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class MinerStartTest {
private MinerStart method;
private MinerStart<Void, EthHashBlockMiner> method;
@Mock private MiningCoordinator miningCoordinator;
@Mock private EthHashMiningCoordinator miningCoordinator;
@Before
public void before() {
method = new MinerStart(miningCoordinator);
method = new MinerStart<>(miningCoordinator);
}
@Test

@ -2,7 +2,8 @@ package net.consensys.pantheon.ethereum.jsonrpc.internal.methods.miner;
import static org.assertj.core.api.Assertions.assertThat;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.EthHashBlockMiner;
import net.consensys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import net.consensys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import net.consensys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
@ -16,13 +17,13 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class MinerStopTest {
private MinerStop method;
private MinerStop<Void, EthHashBlockMiner> method;
@Mock private MiningCoordinator miningCoordinator;
@Mock private EthHashMiningCoordinator miningCoordinator;
@Before
public void before() {
method = new MinerStop(miningCoordinator);
method = new MinerStop<>(miningCoordinator);
}
@Test

@ -33,7 +33,7 @@ public class Runner implements AutoCloseable {
private final Optional<JsonRpcHttpService> jsonRpc;
private final Optional<WebSocketService> websocketRpc;
private final PantheonController<?> pantheonController;
private final PantheonController<?, ?> pantheonController;
private final Path dataDir;
Runner(
@ -41,7 +41,7 @@ public class Runner implements AutoCloseable {
final NetworkRunner networkRunner,
final Optional<JsonRpcHttpService> jsonRpc,
final Optional<WebSocketService> websocketRpc,
final PantheonController<?> pantheonController,
final PantheonController<?, ?> pantheonController,
final Path dataDir) {
this.vertx = vertx;
this.networkRunner = networkRunner;

@ -7,7 +7,7 @@ import net.consensys.pantheon.consensus.ibft.jsonrpc.IbftJsonRpcMethodsFactory;
import net.consensys.pantheon.controller.PantheonController;
import net.consensys.pantheon.crypto.SECP256K1.KeyPair;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import net.consensys.pantheon.ethereum.chain.Blockchain;
import net.consensys.pantheon.ethereum.core.Synchronizer;
import net.consensys.pantheon.ethereum.core.TransactionPool;
@ -55,7 +55,7 @@ public class RunnerBuilder {
public Runner build(
final Vertx vertx,
final PantheonController<?> pantheonController,
final PantheonController<?, ?> pantheonController,
final boolean discovery,
final Collection<?> bootstrapPeers,
final String discoveryHost,
@ -124,7 +124,8 @@ public class RunnerBuilder {
final Synchronizer synchronizer = pantheonController.getSynchronizer();
final TransactionPool transactionPool = pantheonController.getTransactionPool();
final MiningCoordinator miningCoordinator = pantheonController.getMiningCoordinator();
final AbstractMiningCoordinator<?, ?> miningCoordinator =
pantheonController.getMiningCoordinator();
Optional<JsonRpcHttpService> jsonRpcHttpService = Optional.empty();
if (jsonRpcConfiguration.isEnabled()) {
@ -181,11 +182,11 @@ public class RunnerBuilder {
private Map<String, JsonRpcMethod> jsonRpcMethods(
final ProtocolContext<?> context,
final ProtocolSchedule<?> protocolSchedule,
final PantheonController<?> pantheonController,
final PantheonController<?, ?> pantheonController,
final NetworkRunner networkRunner,
final Synchronizer synchronizer,
final TransactionPool transactionPool,
final MiningCoordinator miningCoordinator,
final AbstractMiningCoordinator<?, ?> miningCoordinator,
final Set<Capability> supportedCapabilities,
final Collection<RpcApis> jsonRpcApis) {
final Map<String, JsonRpcMethod> methods =

@ -39,7 +39,7 @@ class ExportPublicKeySubCommand implements Runnable {
@Override
public void run() {
final PantheonController<?> controller = parentCommand.buildController();
final PantheonController<?, ?> controller = parentCommand.buildController();
final KeyPair keyPair = controller.getLocalNodeKeyPair();
// this publicKeyExportFile can never be null because of Picocli arity requirement

@ -375,7 +375,7 @@ public class PantheonCommand implements Runnable {
webSocketConfiguration());
}
PantheonController<?> buildController() {
PantheonController<?, ?> buildController() {
try {
return controllerBuilder.build(
buildSyncConfig(syncMode),
@ -418,7 +418,7 @@ public class PantheonCommand implements Runnable {
// Blockchain synchronisation from peers.
private void synchronize(
final PantheonController<?> controller,
final PantheonController<?, ?> controller,
final boolean noPeerDiscovery,
final Collection<String> bootstrapNodes,
final int maxPeers,

@ -17,7 +17,7 @@ import java.nio.file.Path;
public class PantheonControllerBuilder {
public PantheonController<?> build(
public PantheonController<?, ?> build(
final SynchronizerConfiguration synchronizerConfiguration,
final File genesisFile,
final Path homePath,

@ -5,11 +5,12 @@ import static org.apache.logging.log4j.LogManager.getLogger;
import net.consensys.pantheon.consensus.clique.CliqueContext;
import net.consensys.pantheon.consensus.clique.CliqueVoteTallyUpdater;
import net.consensys.pantheon.consensus.clique.VoteTallyCache;
import net.consensys.pantheon.consensus.clique.blockcreation.CliqueBlockMiner;
import net.consensys.pantheon.consensus.common.EpochManager;
import net.consensys.pantheon.consensus.common.VoteProposer;
import net.consensys.pantheon.crypto.SECP256K1.KeyPair;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import net.consensys.pantheon.ethereum.chain.GenesisConfig;
import net.consensys.pantheon.ethereum.chain.MutableBlockchain;
import net.consensys.pantheon.ethereum.core.BlockHashFunction;
@ -37,7 +38,8 @@ import java.nio.file.Path;
import org.apache.logging.log4j.Logger;
public class CliquePantheonController implements PantheonController<CliqueContext> {
public class CliquePantheonController
implements PantheonController<CliqueContext, CliqueBlockMiner> {
private static final Logger LOG = getLogger();
private final GenesisConfig<CliqueContext> genesisConfig;
@ -66,7 +68,7 @@ public class CliquePantheonController implements PantheonController<CliqueContex
this.closer = closer;
}
public static PantheonController<CliqueContext> init(
public static PantheonController<CliqueContext, CliqueBlockMiner> init(
final Path home,
final GenesisConfig<CliqueContext> genesisConfig,
final SynchronizerConfiguration taintedSyncConfig,
@ -152,7 +154,7 @@ public class CliquePantheonController implements PantheonController<CliqueContex
}
@Override
public MiningCoordinator getMiningCoordinator() {
public AbstractMiningCoordinator<CliqueContext, CliqueBlockMiner> getMiningCoordinator() {
return null;
}

@ -11,13 +11,14 @@ import net.consensys.pantheon.consensus.ibft.IbftProcessor;
import net.consensys.pantheon.consensus.ibft.IbftProtocolSchedule;
import net.consensys.pantheon.consensus.ibft.IbftStateMachine;
import net.consensys.pantheon.consensus.ibft.VoteTallyUpdater;
import net.consensys.pantheon.consensus.ibft.blockcreation.IbftBlockMiner;
import net.consensys.pantheon.consensus.ibft.protocol.IbftProtocolManager;
import net.consensys.pantheon.consensus.ibft.protocol.IbftSubProtocol;
import net.consensys.pantheon.consensus.ibft.protocol.Istanbul64Protocol;
import net.consensys.pantheon.consensus.ibft.protocol.Istanbul64ProtocolManager;
import net.consensys.pantheon.crypto.SECP256K1.KeyPair;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import net.consensys.pantheon.ethereum.chain.GenesisConfig;
import net.consensys.pantheon.ethereum.chain.MutableBlockchain;
import net.consensys.pantheon.ethereum.core.BlockHashFunction;
@ -51,7 +52,7 @@ import java.util.concurrent.TimeUnit;
import io.vertx.core.json.JsonObject;
import org.apache.logging.log4j.Logger;
public class IbftPantheonController implements PantheonController<IbftContext> {
public class IbftPantheonController implements PantheonController<IbftContext, IbftBlockMiner> {
private static final int DEFAULT_ROUND_EXPIRY_MILLISECONDS = 10000;
private static final Logger LOG = getLogger();
@ -90,7 +91,7 @@ public class IbftPantheonController implements PantheonController<IbftContext> {
this.closer = closer;
}
public static PantheonController<IbftContext> init(
public static PantheonController<IbftContext, IbftBlockMiner> init(
final Path home,
final GenesisConfig<IbftContext> genesisConfig,
final SynchronizerConfiguration taintedSyncConfig,
@ -215,7 +216,7 @@ public class IbftPantheonController implements PantheonController<IbftContext> {
}
@Override
public MiningCoordinator getMiningCoordinator() {
public AbstractMiningCoordinator<IbftContext, IbftBlockMiner> getMiningCoordinator() {
return null;
}

@ -6,8 +6,9 @@ import static org.apache.logging.log4j.LogManager.getLogger;
import net.consensys.pantheon.crypto.SECP256K1.KeyPair;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.DefaultBlockScheduler;
import net.consensys.pantheon.ethereum.blockcreation.EthHashBlockMiner;
import net.consensys.pantheon.ethereum.blockcreation.EthHashMinerExecutor;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.MiningParameters;
import net.consensys.pantheon.ethereum.chain.GenesisConfig;
import net.consensys.pantheon.ethereum.chain.MutableBlockchain;
@ -41,7 +42,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.logging.log4j.Logger;
public class MainnetPantheonController implements PantheonController<Void> {
public class MainnetPantheonController implements PantheonController<Void, EthHashBlockMiner> {
private static final Logger LOG = getLogger();
public static final int MAINNET_NETWORK_ID = 1;
@ -53,7 +54,7 @@ public class MainnetPantheonController implements PantheonController<Void> {
private final Synchronizer synchronizer;
private final TransactionPool transactionPool;
private final MiningCoordinator miningCoordinator;
private final EthHashMiningCoordinator miningCoordinator;
private final Runnable close;
public MainnetPantheonController(
@ -63,7 +64,7 @@ public class MainnetPantheonController implements PantheonController<Void> {
final Synchronizer synchronizer,
final KeyPair keyPair,
final TransactionPool transactionPool,
final MiningCoordinator miningCoordinator,
final EthHashMiningCoordinator miningCoordinator,
final Runnable close) {
this.genesisConfig = genesisConfig;
this.protocolContext = protocolContext;
@ -75,7 +76,8 @@ public class MainnetPantheonController implements PantheonController<Void> {
this.close = close;
}
public static PantheonController<Void> mainnet(final Path home) throws IOException {
public static PantheonController<Void, EthHashBlockMiner> mainnet(final Path home)
throws IOException {
final MiningParameters miningParams = new MiningParameters(null, null, null, false);
final KeyPair nodeKeys = loadKeyPair(home);
return init(
@ -87,7 +89,7 @@ public class MainnetPantheonController implements PantheonController<Void> {
nodeKeys);
}
public static PantheonController<Void> init(
public static PantheonController<Void, EthHashBlockMiner> init(
final Path home,
final GenesisConfig<Void> genesisConfig,
final SynchronizerConfiguration taintedSyncConfig,
@ -138,8 +140,8 @@ public class MainnetPantheonController implements PantheonController<Void> {
MainnetBlockHeaderValidator.TIMESTAMP_TOLERANCE_S,
new SystemClock()));
final MiningCoordinator miningCoordinator =
new MiningCoordinator(protocolContext.getBlockchain(), executor);
final EthHashMiningCoordinator miningCoordinator =
new EthHashMiningCoordinator(protocolContext.getBlockchain(), executor);
miningCoordinator.addMinedBlockObserver(ethProtocolManager);
if (miningParams.isMiningEnabled()) {
miningCoordinator.enable();
@ -196,7 +198,7 @@ public class MainnetPantheonController implements PantheonController<Void> {
}
@Override
public MiningCoordinator getMiningCoordinator() {
public EthHashMiningCoordinator getMiningCoordinator() {
return miningCoordinator;
}

@ -4,7 +4,9 @@ import net.consensys.pantheon.consensus.clique.CliqueProtocolSchedule;
import net.consensys.pantheon.consensus.ibft.IbftProtocolSchedule;
import net.consensys.pantheon.crypto.SECP256K1.KeyPair;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.MiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.AbstractBlockCreator;
import net.consensys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import net.consensys.pantheon.ethereum.blockcreation.BlockMiner;
import net.consensys.pantheon.ethereum.blockcreation.MiningParameters;
import net.consensys.pantheon.ethereum.chain.GenesisConfig;
import net.consensys.pantheon.ethereum.core.Synchronizer;
@ -20,11 +22,12 @@ import java.nio.file.Path;
import io.vertx.core.json.JsonObject;
public interface PantheonController<C> extends Closeable {
public interface PantheonController<C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
extends Closeable {
String DATABASE_PATH = "database";
static PantheonController<?> fromConfig(
static PantheonController<?, ?> fromConfig(
final SynchronizerConfiguration syncConfig,
final String configContents,
final Path pantheonHome,
@ -82,5 +85,5 @@ public interface PantheonController<C> extends Closeable {
TransactionPool getTransactionPool();
MiningCoordinator getMiningCoordinator();
AbstractMiningCoordinator<C, M> getMiningCoordinator();
}

@ -4,6 +4,8 @@ import static org.apache.logging.log4j.LogManager.getLogger;
import net.consensys.pantheon.controller.PantheonController;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.AbstractBlockCreator;
import net.consensys.pantheon.ethereum.blockcreation.BlockMiner;
import net.consensys.pantheon.ethereum.chain.GenesisConfig;
import net.consensys.pantheon.ethereum.chain.MutableBlockchain;
import net.consensys.pantheon.ethereum.core.Block;
@ -35,8 +37,9 @@ public class BlockImporter {
* @return the import result
* @throws IOException On Failure
*/
public <C> BlockImporter.ImportResult importBlockchain(
final Path blocks, final PantheonController<C> pantheonController) throws IOException {
public <C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
BlockImporter.ImportResult importBlockchain(
final Path blocks, final PantheonController<C, M> pantheonController) throws IOException {
final ProtocolSchedule<C> protocolSchedule = pantheonController.getProtocolSchedule();
final ProtocolContext<C> context = pantheonController.getProtocolContext();
final GenesisConfig<C> genesis = pantheonController.getGenesisConfig();

@ -5,6 +5,8 @@ import static java.lang.String.format;
import net.consensys.pantheon.controller.PantheonController;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.AbstractBlockCreator;
import net.consensys.pantheon.ethereum.blockcreation.BlockMiner;
import net.consensys.pantheon.ethereum.chain.GenesisConfig;
import net.consensys.pantheon.ethereum.chain.MutableBlockchain;
import net.consensys.pantheon.ethereum.core.Address;
@ -90,16 +92,17 @@ public class BlockchainImporter extends BlockImporter {
* @return the import result
* @throws IOException On Failure
*/
public <C> BlockImporter.ImportResult importBlockchain(
final Path dataFilePath,
final PantheonController<C> pantheonController,
final boolean isSkipHeaderValidation,
final int metricsIntervalSec,
final int accountCommitInterval,
final boolean isSkipBlocks,
final boolean isSkipAccounts,
final Long worldStateOffset)
throws IOException {
public <C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
BlockImporter.ImportResult importBlockchain(
final Path dataFilePath,
final PantheonController<C, M> pantheonController,
final boolean isSkipHeaderValidation,
final int metricsIntervalSec,
final int accountCommitInterval,
final boolean isSkipBlocks,
final boolean isSkipAccounts,
final Long worldStateOffset)
throws IOException {
checkNotNull(dataFilePath);
checkNotNull(pantheonController);
this.isSkipHeaderValidation = isSkipHeaderValidation;
@ -152,12 +155,13 @@ public class BlockchainImporter extends BlockImporter {
* combination with isSkipBlocks
* @return the import result
*/
private <C> BlockImporter.ImportResult importBlockchain(
final PantheonController<C> pantheonController,
final FileRLPInput rlp,
final Boolean isSkipBlocks,
final int metricsIntervalSec,
final Long worldStateOffset) {
private <C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
BlockImporter.ImportResult importBlockchain(
final PantheonController<C, M> pantheonController,
final FileRLPInput rlp,
final Boolean isSkipBlocks,
final int metricsIntervalSec,
final Long worldStateOffset) {
final ProtocolSchedule<C> protocolSchedule = pantheonController.getProtocolSchedule();
final ProtocolContext<C> context = pantheonController.getProtocolContext();
final GenesisConfig<C> genesis = pantheonController.getGenesisConfig();
@ -311,8 +315,8 @@ public class BlockchainImporter extends BlockImporter {
* @param <C> the consensus context type
* @return root hash of the world state
*/
private <C> Hash importWorldState(
final PantheonController<C> pantheonController,
private <C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>> Hash importWorldState(
final PantheonController<C, M> pantheonController,
final FileRLPInput rlp,
final int metricsIntervalSec,
final int accountCommitInterval) {
@ -470,8 +474,9 @@ public class BlockchainImporter extends BlockImporter {
* @param worldStateRootHash calculated world state's root hash
* @param <C> the consensus context type
*/
private <C> void validateWorldStateRootHash(
final PantheonController<C> pantheonController, final Hash worldStateRootHash) {
private <C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
void validateWorldStateRootHash(
final PantheonController<C, M> pantheonController, final Hash worldStateRootHash) {
final ProtocolContext<C> context = pantheonController.getProtocolContext();
final MutableBlockchain blockchain = context.getBlockchain();
final Optional<BlockHeader> header = blockchain.getBlockHeader(blockchain.getChainHeadHash());

@ -7,6 +7,7 @@ import net.consensys.pantheon.controller.MainnetPantheonController;
import net.consensys.pantheon.controller.PantheonController;
import net.consensys.pantheon.crypto.SECP256K1.KeyPair;
import net.consensys.pantheon.ethereum.ProtocolContext;
import net.consensys.pantheon.ethereum.blockcreation.EthHashBlockMiner;
import net.consensys.pantheon.ethereum.chain.GenesisConfig;
import net.consensys.pantheon.ethereum.core.Block;
import net.consensys.pantheon.ethereum.core.BlockImporter;
@ -78,7 +79,7 @@ public final class RunnerTest {
.build();
// Setup state with block data
try (final PantheonController<Void> controller =
try (final PantheonController<Void, EthHashBlockMiner> controller =
MainnetPantheonController.init(
dbAhead,
GenesisConfig.mainnet(),
@ -90,7 +91,7 @@ public final class RunnerTest {
}
// Setup Runner with blocks
final PantheonController<Void> controllerAhead =
final PantheonController<Void, EthHashBlockMiner> controllerAhead =
MainnetPantheonController.init(
dbAhead,
GenesisConfig.mainnet(),
@ -124,7 +125,7 @@ public final class RunnerTest {
// Setup runner with no block data
final Path dbBehind = temp.newFolder().toPath();
final KeyPair behindDbNodeKeys = loadKeyPair(dbBehind);
final PantheonController<Void> controllerBehind =
final PantheonController<Void, EthHashBlockMiner> controllerBehind =
MainnetPantheonController.init(
temp.newFolder().toPath(),
GenesisConfig.mainnet(),

@ -50,7 +50,7 @@ public abstract class CommandTestAbstract {
@Mock PantheonControllerBuilder mockControllerBuilder;
@Mock SynchronizerConfiguration.Builder mockSyncConfBuilder;
@Mock SynchronizerConfiguration mockSyncConf;
@Mock PantheonController<?> mockController;
@Mock PantheonController<?, ?> mockController;
@Mock BlockImporter mockBlockImporter;
@Captor ArgumentCaptor<Collection<String>> stringListArgumentCaptor;

@ -55,7 +55,7 @@ public final class BlockImporterTest {
throw new IllegalStateException(ex);
}
final PantheonController<?> controller =
final PantheonController<?, ?> controller =
PantheonController.fromConfig(
SynchronizerConfiguration.builder().build(),
config,

@ -6,6 +6,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import net.consensys.pantheon.controller.MainnetPantheonController;
import net.consensys.pantheon.controller.PantheonController;
import net.consensys.pantheon.crypto.SECP256K1.KeyPair;
import net.consensys.pantheon.ethereum.blockcreation.EthHashBlockMiner;
import net.consensys.pantheon.ethereum.blockcreation.MiningParameters;
import net.consensys.pantheon.ethereum.chain.GenesisConfig;
import net.consensys.pantheon.ethereum.core.MiningParametersTestBuilder;
@ -53,7 +54,7 @@ public final class BlockchainImporterTest {
final ProtocolSchedule<Void> protocolSchedule = MainnetProtocolSchedule.create();
final MiningParameters miningParams = new MiningParametersTestBuilder().enabled(false).build();
final GenesisConfig<Void> genesisConfig = GenesisConfig.fromJson(genesisJson, protocolSchedule);
final PantheonController<Void> ctrl =
final PantheonController<Void, EthHashBlockMiner> ctrl =
MainnetPantheonController.init(
target,
genesisConfig,

Loading…
Cancel
Save