Add MiningCoordinator interface (#168)

tmohay 6 years ago committed by GitHub
parent 2f5f829c1d
commit 3569b0de78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java
  2. 13
      ethereum/blockcreation/src/main/java/tech/pegasys/pantheon/ethereum/blockcreation/AbstractMiningCoordinator.java
  3. 47
      ethereum/blockcreation/src/main/java/tech/pegasys/pantheon/ethereum/blockcreation/MiningCoordinator.java
  4. 14
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java
  5. 6
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthCoinbase.java
  6. 11
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthGasPrice.java
  7. 6
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthGetWork.java
  8. 11
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthMining.java
  9. 6
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/miner/MinerSetCoinbase.java
  10. 11
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/miner/MinerStart.java
  11. 11
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/miner/MinerStop.java
  12. 4
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthCoinbaseTest.java
  13. 5
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthGasPriceTest.java
  14. 5
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthMiningTest.java
  15. 4
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/miner/MinerSetCoinbaseTest.java
  16. 5
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/miner/MinerStartTest.java
  17. 5
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/miner/MinerStopTest.java
  18. 4
      pantheon/src/main/java/tech/pegasys/pantheon/Runner.java
  19. 11
      pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java
  20. 2
      pantheon/src/main/java/tech/pegasys/pantheon/cli/ExportPublicKeySubCommand.java
  21. 4
      pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java
  22. 2
      pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonControllerBuilder.java
  23. 14
      pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java
  24. 9
      pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java
  25. 15
      pantheon/src/main/java/tech/pegasys/pantheon/controller/MainnetPantheonController.java
  26. 11
      pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonController.java
  27. 2
      pantheon/src/main/java/tech/pegasys/pantheon/util/BlockImporter.java
  28. 22
      pantheon/src/main/java/tech/pegasys/pantheon/util/BlockchainImporter.java
  29. 7
      pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java
  30. 2
      pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java
  31. 2
      pantheon/src/test/java/tech/pegasys/pantheon/util/BlockImporterTest.java
  32. 3
      pantheon/src/test/java/tech/pegasys/pantheon/util/BlockchainImporterTest.java

@ -50,7 +50,7 @@ public class ThreadPantheonNodeRunner implements PantheonNodeRunner {
final PantheonControllerBuilder builder = new PantheonControllerBuilder();
final EthNetworkConfig ethNetworkConfig =
new EthNetworkConfig.Builder(mainnet()).setNetworkId(NETWORK_ID).build();
final PantheonController<?, ?> pantheonController;
final PantheonController<?> pantheonController;
try {
pantheonController =
builder.build(

@ -33,7 +33,7 @@ import org.apache.logging.log4j.Logger;
public abstract class AbstractMiningCoordinator<
C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
implements BlockAddedObserver {
implements BlockAddedObserver, MiningCoordinator {
private static final Logger LOG = getLogger();
protected boolean isEnabled = false;
protected volatile Optional<M> currentRunningMiner = Optional.empty();
@ -54,6 +54,7 @@ public abstract class AbstractMiningCoordinator<
syncState.addInSyncListener(this::inSyncChanged);
}
@Override
public void enable() {
synchronized (this) {
if (isEnabled) {
@ -66,6 +67,7 @@ public abstract class AbstractMiningCoordinator<
}
}
@Override
public void disable() {
synchronized (this) {
if (!isEnabled) {
@ -76,6 +78,7 @@ public abstract class AbstractMiningCoordinator<
}
}
@Override
public boolean isRunning() {
synchronized (this) {
return currentRunningMiner.isPresent();
@ -121,38 +124,46 @@ public abstract class AbstractMiningCoordinator<
}
// Required for JSON RPC, and are deemed to be valid for all mining mechanisms
@Override
public void setMinTransactionGasPrice(final Wei minGasPrice) {
executor.setMinTransactionGasPrice(minGasPrice);
}
@Override
public Wei getMinTransactionGasPrice() {
return executor.getMinTransactionGasPrice();
}
@Override
public void setExtraData(final BytesValue extraData) {
executor.setExtraData(extraData);
}
@Override
public void setCoinbase(final Address coinbase) {
throw new UnsupportedOperationException(
"Current consensus mechanism prevents setting coinbase.");
}
@Override
public Optional<Address> getCoinbase() {
throw new UnsupportedOperationException(
"Current consensus mechanism prevents querying of coinbase.");
}
@Override
public Optional<Long> hashesPerSecond() {
throw new UnsupportedOperationException(
"Current consensus mechanism prevents querying of hashrate.");
}
@Override
public Optional<EthHashSolverInputs> getWorkDefinition() {
throw new UnsupportedOperationException(
"Current consensus mechanism prevents querying work definition.");
}
@Override
public boolean submitWork(final EthHashSolution solution) {
throw new UnsupportedOperationException(
"Current consensus mechanism prevents submission of work solutions.");

@ -0,0 +1,47 @@
/*
* Copyright 2018 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.ethereum.blockcreation;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.EthHashSolution;
import tech.pegasys.pantheon.ethereum.mainnet.EthHashSolverInputs;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.util.Optional;
public interface MiningCoordinator {
void enable();
void disable();
boolean isRunning();
// Required for JSON RPC, and are deemed to be valid for all mining mechanisms
void setMinTransactionGasPrice(Wei minGasPrice);
Wei getMinTransactionGasPrice();
void setExtraData(BytesValue extraData);
void setCoinbase(Address coinbase);
Optional<Address> getCoinbase();
Optional<Long> hashesPerSecond();
Optional<EthHashSolverInputs> getWorkDefinition();
boolean submitWork(EthHashSolution solution);
}

@ -12,7 +12,7 @@
*/
package tech.pegasys.pantheon.ethereum.jsonrpc;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.chain.Blockchain;
import tech.pegasys.pantheon.ethereum.core.Synchronizer;
import tech.pegasys.pantheon.ethereum.core.TransactionPool;
@ -94,7 +94,7 @@ public class JsonRpcMethodsFactory {
final Synchronizer synchronizer,
final TransactionPool transactionPool,
final ProtocolSchedule<?> protocolSchedule,
final AbstractMiningCoordinator<?, ?> miningCoordinator,
final MiningCoordinator miningCoordinator,
final Set<Capability> supportedCapabilities,
final Collection<RpcApi> rpcApis,
final FilterManager filterManager) {
@ -123,7 +123,7 @@ public class JsonRpcMethodsFactory {
final ProtocolSchedule<?> protocolSchedule,
final FilterManager filterManager,
final TransactionPool transactionPool,
final AbstractMiningCoordinator<?, ?> miningCoordinator,
final MiningCoordinator miningCoordinator,
final Set<Capability> supportedCapabilities,
final Collection<RpcApi> rpcApis) {
final Map<String, JsonRpcMethod> enabledMethods = new HashMap<>();
@ -174,10 +174,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),
new EthGetWork(miningCoordinator));
}
if (rpcApis.contains(RpcApis.DEBUG)) {
@ -207,8 +207,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));
}

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

@ -12,21 +12,18 @@
*/
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractBlockCreator;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import tech.pegasys.pantheon.ethereum.blockcreation.BlockMiner;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.results.Quantity;
public class EthGasPrice<C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
implements JsonRpcMethod {
public class EthGasPrice implements JsonRpcMethod {
private final AbstractMiningCoordinator<C, M> miningCoordinator;
private final MiningCoordinator miningCoordinator;
public EthGasPrice(final AbstractMiningCoordinator<C, M> miningCoordinator) {
public EthGasPrice(final MiningCoordinator miningCoordinator) {
this.miningCoordinator = miningCoordinator;
}

@ -14,7 +14,7 @@ package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods;
import static org.apache.logging.log4j.LogManager.getLogger;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse;
@ -30,10 +30,10 @@ import org.apache.logging.log4j.Logger;
public class EthGetWork implements JsonRpcMethod {
private final AbstractMiningCoordinator<?, ?> miner;
private final MiningCoordinator miner;
private static final Logger LOG = getLogger();
public EthGetWork(final AbstractMiningCoordinator<?, ?> miner) {
public EthGetWork(final MiningCoordinator miner) {
this.miner = miner;
}

@ -12,19 +12,16 @@
*/
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractBlockCreator;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import tech.pegasys.pantheon.ethereum.blockcreation.BlockMiner;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
public class EthMining<C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
implements JsonRpcMethod {
public class EthMining implements JsonRpcMethod {
private final AbstractMiningCoordinator<C, M> miningCoordinator;
private final MiningCoordinator miningCoordinator;
public EthMining(final AbstractMiningCoordinator<C, M> miningCoordinator) {
public EthMining(final MiningCoordinator miningCoordinator) {
this.miningCoordinator = miningCoordinator;
}

@ -12,7 +12,7 @@
*/
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.miner;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
@ -24,11 +24,11 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessRe
public class MinerSetCoinbase implements JsonRpcMethod {
private final AbstractMiningCoordinator<?, ?> miningCoordinator;
private final MiningCoordinator miningCoordinator;
private final JsonRpcParameter parameters;
public MinerSetCoinbase(
final AbstractMiningCoordinator<?, ?> miningCoordinator, final JsonRpcParameter parameters) {
final MiningCoordinator miningCoordinator, final JsonRpcParameter parameters) {
this.miningCoordinator = miningCoordinator;
this.parameters = parameters;
}

@ -12,10 +12,8 @@
*/
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.miner;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractBlockCreator;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import tech.pegasys.pantheon.ethereum.blockcreation.BlockMiner;
import tech.pegasys.pantheon.ethereum.blockcreation.CoinbaseNotSetException;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError;
@ -23,12 +21,11 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResp
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
public class MinerStart<C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
implements JsonRpcMethod {
public class MinerStart implements JsonRpcMethod {
private final AbstractMiningCoordinator<C, M> miningCoordinator;
private final MiningCoordinator miningCoordinator;
public MinerStart(final AbstractMiningCoordinator<C, M> miningCoordinator) {
public MinerStart(final MiningCoordinator miningCoordinator) {
this.miningCoordinator = miningCoordinator;
}

@ -12,20 +12,17 @@
*/
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.miner;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractBlockCreator;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import tech.pegasys.pantheon.ethereum.blockcreation.BlockMiner;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
public class MinerStop<C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
implements JsonRpcMethod {
public class MinerStop implements JsonRpcMethod {
private final AbstractMiningCoordinator<C, M> miningCoordinator;
private final MiningCoordinator miningCoordinator;
public MinerStop(final AbstractMiningCoordinator<C, M> miningCoordinator) {
public MinerStop(final MiningCoordinator miningCoordinator) {
this.miningCoordinator = miningCoordinator;
}

@ -17,7 +17,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError;
@ -36,7 +36,7 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class EthCoinbaseTest {
@Mock private AbstractMiningCoordinator<?, ?> miningCoordinator;
@Mock private MiningCoordinator miningCoordinator;
private EthCoinbase method;
private final String JSON_RPC_VERSION = "2.0";
private final String ETH_METHOD = "eth_coinbase";

@ -17,7 +17,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashBlockMiner;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
@ -34,13 +33,13 @@ import org.mockito.junit.MockitoJUnitRunner;
public class EthGasPriceTest {
@Mock private EthHashMiningCoordinator miningCoordinator;
private EthGasPrice<Void, EthHashBlockMiner> method;
private EthGasPrice 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

@ -17,7 +17,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashBlockMiner;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
@ -33,13 +32,13 @@ import org.mockito.junit.MockitoJUnitRunner;
public class EthMiningTest {
@Mock private EthHashMiningCoordinator miningCoordinator;
private EthMining<Void, EthHashBlockMiner> method;
private EthMining 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

@ -19,7 +19,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.exception.InvalidJsonRpcParameters;
@ -40,7 +40,7 @@ public class MinerSetCoinbaseTest {
private MinerSetCoinbase method;
@Mock private AbstractMiningCoordinator<?, ?> miningCoordinator;
@Mock private MiningCoordinator miningCoordinator;
@Before
public void before() {

@ -16,7 +16,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doThrow;
import tech.pegasys.pantheon.ethereum.blockcreation.CoinbaseNotSetException;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashBlockMiner;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError;
@ -33,13 +32,13 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class MinerStartTest {
private MinerStart<Void, EthHashBlockMiner> method;
private MinerStart method;
@Mock private EthHashMiningCoordinator miningCoordinator;
@Before
public void before() {
method = new MinerStart<>(miningCoordinator);
method = new MinerStart(miningCoordinator);
}
@Test

@ -14,7 +14,6 @@ package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.miner;
import static org.assertj.core.api.Assertions.assertThat;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashBlockMiner;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
@ -29,13 +28,13 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class MinerStopTest {
private MinerStop<Void, EthHashBlockMiner> method;
private MinerStop method;
@Mock private EthHashMiningCoordinator miningCoordinator;
@Before
public void before() {
method = new MinerStop<>(miningCoordinator);
method = new MinerStop(miningCoordinator);
}
@Test

@ -45,7 +45,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(
@ -53,7 +53,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;

@ -19,7 +19,7 @@ import tech.pegasys.pantheon.consensus.ibft.jsonrpc.IbftJsonRpcMethodsFactory;
import tech.pegasys.pantheon.controller.PantheonController;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.chain.Blockchain;
import tech.pegasys.pantheon.ethereum.core.Synchronizer;
import tech.pegasys.pantheon.ethereum.core.TransactionPool;
@ -70,7 +70,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,
@ -139,8 +139,7 @@ public class RunnerBuilder {
final Synchronizer synchronizer = pantheonController.getSynchronizer();
final TransactionPool transactionPool = pantheonController.getTransactionPool();
final AbstractMiningCoordinator<?, ?> miningCoordinator =
pantheonController.getMiningCoordinator();
final MiningCoordinator miningCoordinator = pantheonController.getMiningCoordinator();
final FilterManager filterManager = createFilterManager(vertx, context, transactionPool);
@ -213,11 +212,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 AbstractMiningCoordinator<?, ?> miningCoordinator,
final MiningCoordinator miningCoordinator,
final Set<Capability> supportedCapabilities,
final Collection<RpcApi> jsonRpcApis,
final FilterManager filterManager) {

@ -51,7 +51,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

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

@ -29,7 +29,7 @@ import com.google.common.io.Resources;
public class PantheonControllerBuilder {
public PantheonController<?, ?> build(
public PantheonController<?> build(
final SynchronizerConfiguration synchronizerConfiguration,
final Path homePath,
final EthNetworkConfig ethNetworkConfig,

@ -17,7 +17,6 @@ import static org.apache.logging.log4j.LogManager.getLogger;
import tech.pegasys.pantheon.consensus.clique.CliqueContext;
import tech.pegasys.pantheon.consensus.clique.CliqueVoteTallyUpdater;
import tech.pegasys.pantheon.consensus.clique.VoteTallyCache;
import tech.pegasys.pantheon.consensus.clique.blockcreation.CliqueBlockMiner;
import tech.pegasys.pantheon.consensus.clique.blockcreation.CliqueBlockScheduler;
import tech.pegasys.pantheon.consensus.clique.blockcreation.CliqueMinerExecutor;
import tech.pegasys.pantheon.consensus.clique.blockcreation.CliqueMiningCoordinator;
@ -25,7 +24,7 @@ import tech.pegasys.pantheon.consensus.common.EpochManager;
import tech.pegasys.pantheon.consensus.common.VoteProposer;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.chain.GenesisConfig;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.BlockHashFunction;
@ -61,8 +60,7 @@ import java.util.concurrent.TimeUnit;
import io.vertx.core.json.JsonObject;
import org.apache.logging.log4j.Logger;
public class CliquePantheonController
implements PantheonController<CliqueContext, CliqueBlockMiner> {
public class CliquePantheonController implements PantheonController<CliqueContext> {
public static int RINKEBY_NETWORK_ID = 4;
private static final Logger LOG = getLogger();
private final GenesisConfig<CliqueContext> genesisConfig;
@ -75,7 +73,7 @@ public class CliquePantheonController
private static final long EPOCH_LENGTH_DEFAULT = 30_000L;
private static final long SECONDS_BETWEEN_BLOCKS_DEFAULT = 15L;
private final CliqueMiningCoordinator miningCoordinator;
private final MiningCoordinator miningCoordinator;
CliquePantheonController(
final GenesisConfig<CliqueContext> genesisConfig,
@ -84,7 +82,7 @@ public class CliquePantheonController
final Synchronizer synchronizer,
final KeyPair keyPair,
final TransactionPool transactionPool,
final CliqueMiningCoordinator miningCoordinator,
final MiningCoordinator miningCoordinator,
final Runnable closer) {
this.genesisConfig = genesisConfig;
@ -97,7 +95,7 @@ public class CliquePantheonController
this.miningCoordinator = miningCoordinator;
}
public static PantheonController<CliqueContext, CliqueBlockMiner> init(
public static PantheonController<CliqueContext> init(
final Path home,
final GenesisConfig<CliqueContext> genesisConfig,
final SynchronizerConfiguration taintedSyncConfig,
@ -229,7 +227,7 @@ public class CliquePantheonController
}
@Override
public AbstractMiningCoordinator<CliqueContext, CliqueBlockMiner> getMiningCoordinator() {
public MiningCoordinator getMiningCoordinator() {
return miningCoordinator;
}

@ -22,7 +22,6 @@ import tech.pegasys.pantheon.consensus.ibft.IbftContext;
import tech.pegasys.pantheon.consensus.ibft.IbftEventQueue;
import tech.pegasys.pantheon.consensus.ibft.IbftProcessor;
import tech.pegasys.pantheon.consensus.ibft.IbftStateMachine;
import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftBlockMiner;
import tech.pegasys.pantheon.consensus.ibft.network.IbftNetworkPeers;
import tech.pegasys.pantheon.consensus.ibft.protocol.IbftProtocolManager;
import tech.pegasys.pantheon.consensus.ibft.protocol.IbftSubProtocol;
@ -32,7 +31,7 @@ import tech.pegasys.pantheon.consensus.ibftlegacy.protocol.Istanbul64Protocol;
import tech.pegasys.pantheon.consensus.ibftlegacy.protocol.Istanbul64ProtocolManager;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractMiningCoordinator;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.chain.GenesisConfig;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.BlockHashFunction;
@ -67,7 +66,7 @@ import java.util.concurrent.TimeUnit;
import io.vertx.core.json.JsonObject;
import org.apache.logging.log4j.Logger;
public class IbftPantheonController implements PantheonController<IbftContext, IbftBlockMiner> {
public class IbftPantheonController implements PantheonController<IbftContext> {
private static final int DEFAULT_ROUND_EXPIRY_MILLISECONDS = 10000;
private static final Logger LOG = getLogger();
@ -106,7 +105,7 @@ public class IbftPantheonController implements PantheonController<IbftContext, I
this.closer = closer;
}
public static PantheonController<IbftContext, IbftBlockMiner> init(
public static PantheonController<IbftContext> init(
final Path home,
final GenesisConfig<IbftContext> genesisConfig,
final SynchronizerConfiguration taintedSyncConfig,
@ -243,7 +242,7 @@ public class IbftPantheonController implements PantheonController<IbftContext, I
}
@Override
public AbstractMiningCoordinator<IbftContext, IbftBlockMiner> getMiningCoordinator() {
public MiningCoordinator getMiningCoordinator() {
return null;
}

@ -17,9 +17,9 @@ import static tech.pegasys.pantheon.controller.KeyPairUtil.loadKeyPair;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.blockcreation.DefaultBlockScheduler;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashBlockMiner;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMinerExecutor;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.chain.GenesisConfig;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.BlockHashFunction;
@ -55,7 +55,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class MainnetPantheonController implements PantheonController<Void, EthHashBlockMiner> {
public class MainnetPantheonController implements PantheonController<Void> {
private static final Logger LOG = LogManager.getLogger();
public static final int MAINNET_NETWORK_ID = 1;
@ -67,7 +67,7 @@ public class MainnetPantheonController implements PantheonController<Void, EthHa
private final Synchronizer synchronizer;
private final TransactionPool transactionPool;
private final EthHashMiningCoordinator miningCoordinator;
private final MiningCoordinator miningCoordinator;
private final Runnable close;
public MainnetPantheonController(
@ -77,7 +77,7 @@ public class MainnetPantheonController implements PantheonController<Void, EthHa
final Synchronizer synchronizer,
final KeyPair keyPair,
final TransactionPool transactionPool,
final EthHashMiningCoordinator miningCoordinator,
final MiningCoordinator miningCoordinator,
final Runnable close) {
this.genesisConfig = genesisConfig;
this.protocolContext = protocolContext;
@ -89,8 +89,7 @@ public class MainnetPantheonController implements PantheonController<Void, EthHa
this.close = close;
}
public static PantheonController<Void, EthHashBlockMiner> mainnet(final Path home)
throws IOException {
public static PantheonController<Void> mainnet(final Path home) throws IOException {
final MiningParameters miningParams = new MiningParameters(null, null, null, false);
final KeyPair nodeKeys = loadKeyPair(home);
return init(
@ -101,7 +100,7 @@ public class MainnetPantheonController implements PantheonController<Void, EthHa
nodeKeys);
}
public static PantheonController<Void, EthHashBlockMiner> init(
public static PantheonController<Void> init(
final Path home,
final GenesisConfig<Void> genesisConfig,
final SynchronizerConfiguration taintedSyncConfig,
@ -216,7 +215,7 @@ public class MainnetPantheonController implements PantheonController<Void, EthHa
}
@Override
public EthHashMiningCoordinator getMiningCoordinator() {
public MiningCoordinator getMiningCoordinator() {
return miningCoordinator;
}

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

@ -52,7 +52,7 @@ public class BlockImporter {
*/
public <C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
BlockImporter.ImportResult importBlockchain(
final Path blocks, final PantheonController<C, M> pantheonController) throws IOException {
final Path blocks, final PantheonController<C> pantheonController) throws IOException {
final ProtocolSchedule<C> protocolSchedule = pantheonController.getProtocolSchedule();
final ProtocolContext<C> context = pantheonController.getProtocolContext();
final GenesisConfig<C> genesis = pantheonController.getGenesisConfig();

@ -17,8 +17,6 @@ import static java.lang.String.format;
import tech.pegasys.pantheon.controller.PantheonController;
import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractBlockCreator;
import tech.pegasys.pantheon.ethereum.blockcreation.BlockMiner;
import tech.pegasys.pantheon.ethereum.chain.GenesisConfig;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.Address;
@ -91,7 +89,6 @@ public class BlockchainImporter extends BlockImporter {
* Imports blockchain from file as concatenated RLP sections
*
* @param <C> the consensus context type
* @param <M> the type of miner being used within the executing pantheon
* @param dataFilePath Path to the file containing the dataFilePath
* @param pantheonController the PantheonController that defines blockchain behavior
* @param isSkipHeaderValidation if true, header validation is skipped. This must only be used
@ -105,10 +102,9 @@ public class BlockchainImporter extends BlockImporter {
* @return the import result
* @throws IOException On Failure
*/
public <C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
BlockImporter.ImportResult importBlockchain(
public <C> BlockImporter.ImportResult importBlockchain(
final Path dataFilePath,
final PantheonController<C, M> pantheonController,
final PantheonController<C> pantheonController,
final boolean isSkipHeaderValidation,
final int metricsIntervalSec,
final int accountCommitInterval,
@ -168,9 +164,8 @@ public class BlockchainImporter extends BlockImporter {
* combination with isSkipBlocks
* @return the import result
*/
private <C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
BlockImporter.ImportResult importBlockchain(
final PantheonController<C, M> pantheonController,
private <C> BlockImporter.ImportResult importBlockchain(
final PantheonController<C> pantheonController,
final FileRLPInput rlp,
final Boolean isSkipBlocks,
final int metricsIntervalSec,
@ -328,8 +323,8 @@ public class BlockchainImporter extends BlockImporter {
* @param <C> the consensus context type
* @return root hash of the world state
*/
private <C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>> Hash importWorldState(
final PantheonController<C, M> pantheonController,
private <C> Hash importWorldState(
final PantheonController<C> pantheonController,
final FileRLPInput rlp,
final int metricsIntervalSec,
final int accountCommitInterval) {
@ -487,9 +482,8 @@ public class BlockchainImporter extends BlockImporter {
* @param worldStateRootHash calculated world state's root hash
* @param <C> the consensus context type
*/
private <C, M extends BlockMiner<C, ? extends AbstractBlockCreator<C>>>
void validateWorldStateRootHash(
final PantheonController<C, M> pantheonController, final Hash worldStateRootHash) {
private <C> void validateWorldStateRootHash(
final PantheonController<C> pantheonController, final Hash worldStateRootHash) {
final ProtocolContext<C> context = pantheonController.getProtocolContext();
final MutableBlockchain blockchain = context.getBlockchain();
final Optional<BlockHeader> header = blockchain.getBlockHeader(blockchain.getChainHeadHash());

@ -19,7 +19,6 @@ import tech.pegasys.pantheon.controller.MainnetPantheonController;
import tech.pegasys.pantheon.controller.PantheonController;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashBlockMiner;
import tech.pegasys.pantheon.ethereum.chain.GenesisConfig;
import tech.pegasys.pantheon.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.core.BlockImporter;
@ -91,7 +90,7 @@ public final class RunnerTest {
.build();
// Setup state with block data
try (final PantheonController<Void, EthHashBlockMiner> controller =
try (final PantheonController<Void> controller =
MainnetPantheonController.init(
dbAhead,
GenesisConfig.mainnet(),
@ -102,7 +101,7 @@ public final class RunnerTest {
}
// Setup Runner with blocks
final PantheonController<Void, EthHashBlockMiner> controllerAhead =
final PantheonController<Void> controllerAhead =
MainnetPantheonController.init(
dbAhead,
GenesisConfig.mainnet(),
@ -135,7 +134,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, EthHashBlockMiner> controllerBehind =
final PantheonController<Void> controllerBehind =
MainnetPantheonController.init(
temp.newFolder().toPath(),
GenesisConfig.mainnet(),

@ -60,7 +60,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;

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

@ -18,7 +18,6 @@ import static tech.pegasys.pantheon.controller.KeyPairUtil.loadKeyPair;
import tech.pegasys.pantheon.controller.MainnetPantheonController;
import tech.pegasys.pantheon.controller.PantheonController;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashBlockMiner;
import tech.pegasys.pantheon.ethereum.chain.GenesisConfig;
import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder;
@ -66,7 +65,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, EthHashBlockMiner> ctrl =
final PantheonController<Void> ctrl =
MainnetPantheonController.init(
target,
genesisConfig,

Loading…
Cancel
Save