Delegate creation of consensus-specific JSON-RPC methods to the PantheonController instead of using instanceof and casting. (#289)

Adrian Sutton 6 years ago committed by GitHub
parent 7b2621060e
commit c5e78c369f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/jsonrpc/IbftJsonRpcMethodsFactory.java
  2. 24
      pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java
  3. 11
      pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java
  4. 11
      pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java
  5. 11
      pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonController.java

@ -34,7 +34,6 @@ public class IbftJsonRpcMethodsFactory {
final Map<String, JsonRpcMethod> rpcMethods = new HashMap<>();
if (jsonRpcApis.contains(IbftRpcApis.IBFT)) {
// @formatter:off
addMethods(
rpcMethods,
new IbftProposeValidatorVote(

@ -12,10 +12,6 @@
*/
package tech.pegasys.pantheon;
import tech.pegasys.pantheon.consensus.clique.CliqueContext;
import tech.pegasys.pantheon.consensus.clique.jsonrpc.CliqueJsonRpcMethodsFactory;
import tech.pegasys.pantheon.consensus.ibft.IbftContext;
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;
@ -155,6 +151,7 @@ public class RunnerBuilder {
jsonRpcMethods(
context,
protocolSchedule,
pantheonController,
networkRunner,
synchronizer,
transactionPool,
@ -172,6 +169,7 @@ public class RunnerBuilder {
jsonRpcMethods(
context,
protocolSchedule,
pantheonController,
networkRunner,
synchronizer,
transactionPool,
@ -216,6 +214,7 @@ public class RunnerBuilder {
private Map<String, JsonRpcMethod> jsonRpcMethods(
final ProtocolContext<?> context,
final ProtocolSchedule<?> protocolSchedule,
final PantheonController<?> pantheonController,
final NetworkRunner networkRunner,
final Synchronizer synchronizer,
final TransactionPool transactionPool,
@ -237,22 +236,7 @@ public class RunnerBuilder {
supportedCapabilities,
jsonRpcApis,
filterManager);
if (context.getConsensusState() instanceof CliqueContext) {
// This is checked before entering this if branch
@SuppressWarnings("unchecked")
final ProtocolContext<CliqueContext> cliqueProtocolContext =
(ProtocolContext<CliqueContext>) context;
methods.putAll(new CliqueJsonRpcMethodsFactory().methods(cliqueProtocolContext, jsonRpcApis));
}
if (context.getConsensusState() instanceof IbftContext) {
// This is checked before entering this if branch
@SuppressWarnings("unchecked")
final ProtocolContext<IbftContext> ibftProtocolContext =
(ProtocolContext<IbftContext>) context;
methods.putAll(new IbftJsonRpcMethodsFactory().methods(ibftProtocolContext, jsonRpcApis));
}
methods.putAll(pantheonController.getAdditionalJsonRpcMethods(jsonRpcApis));
return methods;
}

@ -23,6 +23,7 @@ import tech.pegasys.pantheon.consensus.clique.VoteTallyCache;
import tech.pegasys.pantheon.consensus.clique.blockcreation.CliqueBlockScheduler;
import tech.pegasys.pantheon.consensus.clique.blockcreation.CliqueMinerExecutor;
import tech.pegasys.pantheon.consensus.clique.blockcreation.CliqueMiningCoordinator;
import tech.pegasys.pantheon.consensus.clique.jsonrpc.CliqueJsonRpcMethodsFactory;
import tech.pegasys.pantheon.consensus.common.EpochManager;
import tech.pegasys.pantheon.consensus.common.VoteProposer;
import tech.pegasys.pantheon.consensus.common.VoteTallyUpdater;
@ -46,6 +47,8 @@ import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode;
import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState;
import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolFactory;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.p2p.api.ProtocolManager;
import tech.pegasys.pantheon.ethereum.p2p.config.SubProtocolConfiguration;
@ -54,6 +57,8 @@ import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage;
import java.io.IOException;
import java.time.Clock;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@ -234,6 +239,12 @@ public class CliquePantheonController implements PantheonController<CliqueContex
return miningCoordinator;
}
@Override
public Map<String, JsonRpcMethod> getAdditionalJsonRpcMethods(
final Collection<RpcApi> enabledRpcApis) {
return new CliqueJsonRpcMethodsFactory().methods(context, enabledRpcApis);
}
@Override
public void close() {
closer.run();

@ -27,6 +27,7 @@ import tech.pegasys.pantheon.consensus.ibft.IbftProcessor;
import tech.pegasys.pantheon.consensus.ibft.IbftStateMachine;
import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftBlockCreatorFactory;
import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftMiningCoordinator;
import tech.pegasys.pantheon.consensus.ibft.jsonrpc.IbftJsonRpcMethodsFactory;
import tech.pegasys.pantheon.consensus.ibft.network.IbftNetworkPeers;
import tech.pegasys.pantheon.consensus.ibft.protocol.IbftProtocolManager;
import tech.pegasys.pantheon.consensus.ibft.protocol.IbftSubProtocol;
@ -54,6 +55,8 @@ import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode;
import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState;
import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolFactory;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.p2p.api.ProtocolManager;
import tech.pegasys.pantheon.ethereum.p2p.config.SubProtocolConfiguration;
@ -62,6 +65,8 @@ import tech.pegasys.pantheon.ethereum.storage.StorageProvider;
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@ -267,6 +272,12 @@ public class IbftPantheonController implements PantheonController<IbftContext> {
return null;
}
@Override
public Map<String, JsonRpcMethod> getAdditionalJsonRpcMethods(
final Collection<RpcApi> enabledRpcApis) {
return new IbftJsonRpcMethodsFactory().methods(context, enabledRpcApis);
}
@Override
public void close() {
closer.run();

@ -12,6 +12,8 @@
*/
package tech.pegasys.pantheon.controller;
import static java.util.Collections.emptyMap;
import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.config.GenesisConfigOptions;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
@ -21,12 +23,16 @@ import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.Synchronizer;
import tech.pegasys.pantheon.ethereum.core.TransactionPool;
import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.p2p.config.SubProtocolConfiguration;
import tech.pegasys.pantheon.ethereum.storage.StorageProvider;
import java.io.Closeable;
import java.util.Collection;
import java.util.Map;
public interface PantheonController<C> extends Closeable {
@ -81,4 +87,9 @@ public interface PantheonController<C> extends Closeable {
TransactionPool getTransactionPool();
MiningCoordinator getMiningCoordinator();
default Map<String, JsonRpcMethod> getAdditionalJsonRpcMethods(
final Collection<RpcApi> enabledRpcApis) {
return emptyMap();
}
}

Loading…
Cancel
Save