[FIX] Refactored permissioning components to be Optional. (#747)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
mark-terry 6 years ago committed by GitHub
parent 04a5aa001d
commit 52d6675f63
  1. 6
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java
  2. 6
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java
  3. 8
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonFactoryConfiguration.java
  4. 5
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonFactoryConfigurationBuilder.java
  5. 21
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonNodeFactory.java
  6. 5
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/perm/PermAddNodesToWhitelistAcceptanceTest.java
  7. 1
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/perm/PermGetNodesWhitelistAcceptanceTest.java
  8. 2
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/core/TransactionPoolTest.java
  9. 5
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java
  10. 5
      ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java
  11. 5
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java
  12. 48
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/permissioning/PermAddAccountsToWhitelist.java
  13. 55
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/permissioning/PermAddNodesToWhitelist.java
  14. 13
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/permissioning/PermGetAccountsWhitelist.java
  15. 8
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/permissioning/PermGetNodesWhitelist.java
  16. 47
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromWhitelist.java
  17. 56
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/permissioning/PermRemoveNodesFromWhitelist.java
  18. 4
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/response/JsonRpcError.java
  19. 8
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java
  20. 3
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java
  21. 3
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceLoginTest.java
  22. 3
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java
  23. 2
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java
  24. 4
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/permissioning/PermAddAccountsToWhitelistTest.java
  25. 18
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/permissioning/PermAddNodesToWhitelistTest.java
  26. 17
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/permissioning/PermGetAccountsWhitelistTest.java
  27. 27
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/permissioning/PermGetNodesWhitelistTest.java
  28. 4
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromWhitelistTest.java
  29. 15
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/permissioning/PermRemoveNodesFromWhitelistTest.java
  30. 6
      ethereum/mock-p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/testing/MockNetwork.java
  31. 3
      ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NoopP2PNetwork.java
  32. 8
      ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/api/P2PNetwork.java
  33. 4
      ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/PeerDiscoveryAgent.java
  34. 3
      ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java
  35. 18
      ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryController.java
  36. 23
      ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyP2PNetwork.java
  37. 15
      ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/permissioning/NodeWhitelistController.java
  38. 37
      ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NettyP2PNetworkTest.java
  39. 25
      ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NetworkingServiceLifecycleTest.java
  40. 7
      ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/PeerDiscoveryTestHelper.java
  41. 5
      ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/PeerDiscoveryTimestampsTest.java
  42. 3
      ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/MockPeerDiscoveryAgent.java
  43. 16
      ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryControllerTest.java
  44. 4
      ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryTableRefreshTest.java
  45. 11
      ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/AccountWhitelistController.java
  46. 16
      ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfiguration.java
  47. 29
      ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/AccountWhitelistControllerTest.java
  48. 12
      ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfigurationTest.java
  49. 27
      pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java
  50. 17
      pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java
  51. 2
      pantheon/src/main/java/tech/pegasys/pantheon/util/PermissioningConfigurationValidator.java
  52. 24
      pantheon/src/test/java/tech/pegasys/pantheon/PermissioningConfigurationBuilderTest.java
  53. 3
      pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java

@ -78,7 +78,7 @@ public class PantheonNode implements Node, NodeConfiguration, RunnableNode, Auto
private final JsonRpcConfiguration jsonRpcConfiguration;
private final WebSocketConfiguration webSocketConfiguration;
private final MetricsConfiguration metricsConfiguration;
private final PermissioningConfiguration permissioningConfiguration;
private final Optional<PermissioningConfiguration> permissioningConfiguration;
private final GenesisConfigProvider genesisConfigProvider;
private final boolean devMode;
private final boolean discoveryEnabled;
@ -93,7 +93,7 @@ public class PantheonNode implements Node, NodeConfiguration, RunnableNode, Auto
final JsonRpcConfiguration jsonRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
final MetricsConfiguration metricsConfiguration,
final PermissioningConfiguration permissioningConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
final boolean devMode,
final GenesisConfigProvider genesisConfigProvider,
final int p2pPort,
@ -348,7 +348,7 @@ public class PantheonNode implements Node, NodeConfiguration, RunnableNode, Auto
return discoveryEnabled;
}
PermissioningConfiguration getPermissioningConfiguration() {
Optional<PermissioningConfiguration> getPermissioningConfiguration() {
return permissioningConfiguration;
}

@ -78,8 +78,11 @@ public class ThreadPantheonNodeRunner implements PantheonNodeRunner {
throw new RuntimeException("Error building PantheonController", e);
}
RunnerBuilder runnerBuilder = new RunnerBuilder();
node.getPermissioningConfiguration().ifPresent(runnerBuilder::permissioningConfiguration);
final Runner runner =
new RunnerBuilder()
runnerBuilder
.vertx(Vertx.vertx())
.pantheonController(pantheonController)
.discovery(node.isDiscoveryEnabled())
@ -93,7 +96,6 @@ public class ThreadPantheonNodeRunner implements PantheonNodeRunner {
.bannedNodeIds(Collections.emptySet())
.metricsSystem(noOpMetricsSystem)
.metricsConfiguration(node.metricsConfiguration())
.permissioningConfiguration(node.getPermissioningConfiguration())
.p2pEnabled(node.p2pEnabled())
.build();

@ -19,6 +19,8 @@ import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.GenesisConfigProvider;
import java.util.Optional;
class PantheonFactoryConfiguration {
private final String name;
@ -26,7 +28,7 @@ class PantheonFactoryConfiguration {
private final JsonRpcConfiguration jsonRpcConfiguration;
private final WebSocketConfiguration webSocketConfiguration;
private final MetricsConfiguration metricsConfiguration;
private final PermissioningConfiguration permissioningConfiguration;
private final Optional<PermissioningConfiguration> permissioningConfiguration;
private final boolean devMode;
private final GenesisConfigProvider genesisConfigProvider;
private final Boolean p2pEnabled;
@ -38,7 +40,7 @@ class PantheonFactoryConfiguration {
final JsonRpcConfiguration jsonRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
final MetricsConfiguration metricsConfiguration,
final PermissioningConfiguration permissioningConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
final boolean devMode,
final GenesisConfigProvider genesisConfigProvider,
final Boolean p2pEnabled,
@ -75,7 +77,7 @@ class PantheonFactoryConfiguration {
return metricsConfiguration;
}
public PermissioningConfiguration getPermissioningConfiguration() {
public Optional<PermissioningConfiguration> getPermissioningConfiguration() {
return permissioningConfiguration;
}

@ -32,8 +32,7 @@ public class PantheonFactoryConfigurationBuilder {
private JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault();
private WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault();
private MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault();
private PermissioningConfiguration permissioningConfiguration =
PermissioningConfiguration.createDefault();
private Optional<PermissioningConfiguration> permissioningConfiguration = Optional.empty();
private boolean devMode = true;
private GenesisConfigProvider genesisConfigProvider = ignore -> Optional.empty();
private Boolean p2pEnabled = true;
@ -94,7 +93,7 @@ public class PantheonFactoryConfigurationBuilder {
public PantheonFactoryConfigurationBuilder setPermissioningConfiguration(
final PermissioningConfiguration permissioningConfiguration) {
this.permissioningConfiguration = permissioningConfiguration;
this.permissioningConfiguration = Optional.of(permissioningConfiguration);
return this;
}

@ -190,27 +190,6 @@ public class PantheonNodeFactory {
.build());
}
public PantheonNode createNodeWithNodesWhitelistAndPermRPC(
final String name, final List<URI> nodesWhitelist) throws IOException {
PermissioningConfiguration permissioningConfiguration =
PermissioningConfiguration.createDefault();
permissioningConfiguration.setNodeWhitelist(nodesWhitelist);
JsonRpcConfiguration rpcConfig = JsonRpcConfiguration.createDefault();
rpcConfig.setEnabled(true);
rpcConfig.setPort(0);
rpcConfig.setHostsWhitelist(singletonList("*"));
rpcConfig.addRpcApi(RpcApis.PERM);
return create(
new PantheonFactoryConfigurationBuilder()
.setName(name)
.setJsonRpcConfiguration(rpcConfig)
.setPermissioningConfiguration(permissioningConfiguration)
.build());
}
public PantheonNode createNodeWithNoDiscovery(final String name) throws IOException {
return create(
new PantheonFactoryConfigurationBuilder().setName(name).setDiscoveryEnabled(false).build());

@ -12,10 +12,11 @@
*/
package tech.pegasys.pantheon.tests.acceptance.jsonrpc.perm;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis;
import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;
import java.util.ArrayList;
import org.assertj.core.util.Lists;
import org.junit.Before;
import org.junit.Test;
@ -33,7 +34,7 @@ public class PermAddNodesToWhitelistAcceptanceTest extends AcceptanceTestBase {
@Before
public void setUp() throws Exception {
node = pantheon.createArchiveNodeWithRpcApis("node1", RpcApis.WEB3, RpcApis.NET, RpcApis.PERM);
node = pantheon.createNodeWithNodesWhitelist("node1", new ArrayList<>());
cluster.start(node);
}

@ -36,7 +36,6 @@ public class PermGetNodesWhitelistAcceptanceTest extends AcceptanceTestBase {
@Before
public void setUp() throws Exception {
node = pantheon.createNodeWithNodesWhitelist("node1", nodesWhitelist);
cluster.start(node);
}

@ -364,7 +364,6 @@ public class TransactionPoolTest {
transactionPool.setAccountWhitelist(accountWhitelistController);
givenTransactionIsValid(transaction1);
when(accountWhitelistController.isAccountWhiteListSet()).thenReturn(true);
when(accountWhitelistController.contains(transaction1.getSender().toString())).thenReturn(true);
assertThat(transactionPool.addLocalTransaction(transaction1)).isEqualTo(valid());
@ -377,7 +376,6 @@ public class TransactionPoolTest {
transactionPool.setAccountWhitelist(accountWhitelistController);
givenTransactionIsValid(transaction1);
when(accountWhitelistController.isAccountWhiteListSet()).thenReturn(true);
when(accountWhitelistController.contains(transaction1.getSender().toString()))
.thenReturn(false);

@ -43,9 +43,7 @@ import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer;
import tech.pegasys.pantheon.ethereum.p2p.peers.Endpoint;
import tech.pegasys.pantheon.ethereum.p2p.peers.Peer;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
import tech.pegasys.pantheon.ethereum.p2p.permissioning.NodeWhitelistController;
import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.bytes.BytesValue;
@ -55,6 +53,7 @@ import java.io.IOException;
import java.net.InetAddress;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.concurrent.CompletableFuture;
@ -121,7 +120,7 @@ public class TestNode implements Closeable {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault())))
Optional.empty()))
.metricsSystem(new NoOpMetricsSystem())
.build();
network = networkRunner.getNetwork();

@ -42,6 +42,7 @@ import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
/** Provides a facade to construct the JSON-RPC component. */
public class JsonRpcTestMethodsFactory {
@ -80,8 +81,8 @@ public class JsonRpcTestMethodsFactory {
blockchainQueries, transactionPool, new FilterIdGenerator(), new FilterRepository());
final EthHashMiningCoordinator miningCoordinator = mock(EthHashMiningCoordinator.class);
final MetricsSystem metricsSystem = new NoOpMetricsSystem();
final AccountWhitelistController accountWhitelistController =
mock(AccountWhitelistController.class);
final Optional<AccountWhitelistController> accountWhitelistController =
Optional.of(mock(AccountWhitelistController.class));
final PrivateTransactionHandler privateTransactionHandler =
mock(PrivateTransactionHandler.class);

@ -92,6 +92,7 @@ import tech.pegasys.pantheon.metrics.MetricsSystem;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
public class JsonRpcMethodsFactory {
@ -112,7 +113,7 @@ public class JsonRpcMethodsFactory {
final Set<Capability> supportedCapabilities,
final Collection<RpcApi> rpcApis,
final FilterManager filterManager,
final AccountWhitelistController accountsWhitelistController,
final Optional<AccountWhitelistController> accountsWhitelistController,
final PrivateTransactionHandler privateTransactionHandler) {
final BlockchainQueries blockchainQueries =
new BlockchainQueries(blockchain, worldStateArchive);
@ -143,7 +144,7 @@ public class JsonRpcMethodsFactory {
final MiningCoordinator miningCoordinator,
final MetricsSystem metricsSystem,
final Set<Capability> supportedCapabilities,
final AccountWhitelistController accountsWhitelistController,
final Optional<AccountWhitelistController> accountsWhitelistController,
final Collection<RpcApi> rpcApis,
final PrivateTransactionHandler privateTransactionHandler) {
final Map<String, JsonRpcMethod> enabledMethods = new HashMap<>();

@ -23,14 +23,16 @@ import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.WhitelistOperationResult;
import java.util.List;
import java.util.Optional;
public class PermAddAccountsToWhitelist implements JsonRpcMethod {
private final JsonRpcParameter parameters;
private final AccountWhitelistController whitelistController;
private final Optional<AccountWhitelistController> whitelistController;
public PermAddAccountsToWhitelist(
final AccountWhitelistController whitelistController, final JsonRpcParameter parameters) {
final Optional<AccountWhitelistController> whitelistController,
final JsonRpcParameter parameters) {
this.whitelistController = whitelistController;
this.parameters = parameters;
}
@ -44,25 +46,31 @@ public class PermAddAccountsToWhitelist implements JsonRpcMethod {
@SuppressWarnings("unchecked")
public JsonRpcResponse response(final JsonRpcRequest request) {
final List<String> accountsList = parameters.required(request.getParams(), 0, List.class);
final WhitelistOperationResult addResult = whitelistController.addAccounts(accountsList);
switch (addResult) {
case ERROR_EMPTY_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_EMPTY_ENTRY);
case ERROR_INVALID_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_INVALID_ENTRY);
case ERROR_EXISTING_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_EXISTING_ENTRY);
case ERROR_DUPLICATED_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_DUPLICATED_ENTRY);
case SUCCESS:
return new JsonRpcSuccessResponse(request.getId());
default:
throw new IllegalStateException("Unmapped result from AccountWhitelistController");
if (whitelistController.isPresent()) {
final WhitelistOperationResult addResult =
whitelistController.get().addAccounts(accountsList);
switch (addResult) {
case ERROR_EMPTY_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_EMPTY_ENTRY);
case ERROR_INVALID_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_INVALID_ENTRY);
case ERROR_EXISTING_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_EXISTING_ENTRY);
case ERROR_DUPLICATED_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_DUPLICATED_ENTRY);
case SUCCESS:
return new JsonRpcSuccessResponse(request.getId());
default:
throw new IllegalStateException("Unmapped result from AccountWhitelistController");
}
} else {
return new JsonRpcErrorResponse(request.getId(), JsonRpcError.ACCOUNT_WHITELIST_NOT_ENABLED);
}
}
}

@ -49,35 +49,42 @@ public class PermAddNodesToWhitelist implements JsonRpcMethod {
parameters.required(req.getParams(), 0, StringListParameter.class);
try {
List<DefaultPeer> peers =
enodeListParam
.getStringList()
.parallelStream()
.map(this::parsePeer)
.collect(Collectors.toList());
if (p2pNetwork.getNodeWhitelistController().isPresent()) {
try {
List<DefaultPeer> peers =
enodeListParam
.getStringList()
.parallelStream()
.map(this::parsePeer)
.collect(Collectors.toList());
NodeWhitelistController.NodesWhitelistResult nodesWhitelistResult =
p2pNetwork.getNodeWhitelistController().addNodes(peers);
NodeWhitelistController.NodesWhitelistResult nodesWhitelistResult =
p2pNetwork.getNodeWhitelistController().get().addNodes(peers);
switch (nodesWhitelistResult.result()) {
case SUCCESS:
return new JsonRpcSuccessResponse(req.getId());
case ERROR_EMPTY_ENTRY:
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.NODE_WHITELIST_EMPTY_ENTRY);
case ERROR_EXISTING_ENTRY:
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.NODE_WHITELIST_EXISTING_ENTRY);
case ERROR_DUPLICATED_ENTRY:
return new JsonRpcErrorResponse(
req.getId(), JsonRpcError.NODE_WHITELIST_DUPLICATED_ENTRY);
default:
throw new Exception();
switch (nodesWhitelistResult.result()) {
case SUCCESS:
return new JsonRpcSuccessResponse(req.getId());
case ERROR_EMPTY_ENTRY:
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.NODE_WHITELIST_EMPTY_ENTRY);
case ERROR_EXISTING_ENTRY:
return new JsonRpcErrorResponse(
req.getId(), JsonRpcError.NODE_WHITELIST_EXISTING_ENTRY);
case ERROR_DUPLICATED_ENTRY:
return new JsonRpcErrorResponse(
req.getId(), JsonRpcError.NODE_WHITELIST_DUPLICATED_ENTRY);
default:
throw new Exception();
}
} catch (IllegalArgumentException e) {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.NODE_WHITELIST_INVALID_ENTRY);
} catch (Exception e) {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.INTERNAL_ERROR);
}
} else {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.NODE_WHITELIST_NOT_ENABLED);
}
} catch (IllegalArgumentException e) {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.NODE_WHITELIST_INVALID_ENTRY);
} catch (P2pDisabledException e) {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.P2P_DISABLED);
} catch (Exception e) {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.INTERNAL_ERROR);
}
}

@ -20,11 +20,13 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import java.util.Optional;
public class PermGetAccountsWhitelist implements JsonRpcMethod {
private final AccountWhitelistController whitelistController;
private final Optional<AccountWhitelistController> whitelistController;
public PermGetAccountsWhitelist(final AccountWhitelistController whitelistController) {
public PermGetAccountsWhitelist(final Optional<AccountWhitelistController> whitelistController) {
this.whitelistController = whitelistController;
}
@ -35,10 +37,11 @@ public class PermGetAccountsWhitelist implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequest request) {
if (!whitelistController.isAccountWhiteListSet()) {
return new JsonRpcErrorResponse(request.getId(), JsonRpcError.ACCOUNT_WHITELIST_NOT_SET);
if (whitelistController.isPresent()) {
return new JsonRpcSuccessResponse(
request.getId(), whitelistController.get().getAccountWhitelist());
} else {
return new JsonRpcSuccessResponse(request.getId(), whitelistController.getAccountWhitelist());
return new JsonRpcErrorResponse(request.getId(), JsonRpcError.ACCOUNT_WHITELIST_NOT_ENABLED);
}
}
}

@ -45,15 +45,15 @@ public class PermGetNodesWhitelist implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequest req) {
try {
if (p2pNetwork.getNodeWhitelistController().nodeWhitelistSet()) {
List<Peer> nodesWhitelist = p2pNetwork.getNodeWhitelistController().getNodesWhitelist();
if (p2pNetwork.getNodeWhitelistController().isPresent()) {
List<Peer> nodesWhitelist =
p2pNetwork.getNodeWhitelistController().get().getNodesWhitelist();
List<String> enodeList =
nodesWhitelist.parallelStream().map(this::buildEnodeURI).collect(Collectors.toList());
return new JsonRpcSuccessResponse(req.getId(), enodeList);
} else {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.NODE_WHITELIST_NOT_SET);
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.NODE_WHITELIST_NOT_ENABLED);
}
} catch (P2pDisabledException e) {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.P2P_DISABLED);

@ -23,14 +23,16 @@ import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.WhitelistOperationResult;
import java.util.List;
import java.util.Optional;
public class PermRemoveAccountsFromWhitelist implements JsonRpcMethod {
private final JsonRpcParameter parameters;
private final AccountWhitelistController whitelistController;
private final Optional<AccountWhitelistController> whitelistController;
public PermRemoveAccountsFromWhitelist(
final AccountWhitelistController whitelistController, final JsonRpcParameter parameters) {
final Optional<AccountWhitelistController> whitelistController,
final JsonRpcParameter parameters) {
this.whitelistController = whitelistController;
this.parameters = parameters;
}
@ -44,25 +46,30 @@ public class PermRemoveAccountsFromWhitelist implements JsonRpcMethod {
@SuppressWarnings("unchecked")
public JsonRpcResponse response(final JsonRpcRequest request) {
final List<String> accountsList = parameters.required(request.getParams(), 0, List.class);
final WhitelistOperationResult removeResult = whitelistController.removeAccounts(accountsList);
if (whitelistController.isPresent()) {
final WhitelistOperationResult removeResult =
whitelistController.get().removeAccounts(accountsList);
switch (removeResult) {
case ERROR_EMPTY_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_EMPTY_ENTRY);
case ERROR_INVALID_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_INVALID_ENTRY);
case ERROR_ABSENT_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_ABSENT_ENTRY);
case ERROR_DUPLICATED_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_DUPLICATED_ENTRY);
case SUCCESS:
return new JsonRpcSuccessResponse(request.getId());
default:
throw new IllegalStateException("Unmapped result from AccountWhitelistController");
switch (removeResult) {
case ERROR_EMPTY_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_EMPTY_ENTRY);
case ERROR_INVALID_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_INVALID_ENTRY);
case ERROR_ABSENT_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_ABSENT_ENTRY);
case ERROR_DUPLICATED_ENTRY:
return new JsonRpcErrorResponse(
request.getId(), JsonRpcError.ACCOUNT_WHITELIST_DUPLICATED_ENTRY);
case SUCCESS:
return new JsonRpcSuccessResponse(request.getId());
default:
throw new IllegalStateException("Unmapped result from AccountWhitelistController");
}
} else {
return new JsonRpcErrorResponse(request.getId(), JsonRpcError.ACCOUNT_WHITELIST_NOT_ENABLED);
}
}
}

@ -48,37 +48,43 @@ public class PermRemoveNodesFromWhitelist implements JsonRpcMethod {
public JsonRpcResponse response(final JsonRpcRequest req) {
final StringListParameter enodeListParam =
parameters.required(req.getParams(), 0, StringListParameter.class);
try {
List<DefaultPeer> peers =
enodeListParam
.getStringList()
.parallelStream()
.map(this::parsePeer)
.collect(Collectors.toList());
if (p2pNetwork.getNodeWhitelistController().isPresent()) {
try {
List<DefaultPeer> peers =
enodeListParam
.getStringList()
.parallelStream()
.map(this::parsePeer)
.collect(Collectors.toList());
NodeWhitelistController.NodesWhitelistResult nodesWhitelistResult =
p2pNetwork.getNodeWhitelistController().removeNodes(peers);
NodeWhitelistController.NodesWhitelistResult nodesWhitelistResult =
p2pNetwork.getNodeWhitelistController().get().removeNodes(peers);
switch (nodesWhitelistResult.result()) {
case SUCCESS:
return new JsonRpcSuccessResponse(req.getId());
case ERROR_EMPTY_ENTRY:
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.NODE_WHITELIST_EMPTY_ENTRY);
case ERROR_ABSENT_ENTRY:
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.NODE_WHITELIST_MISSING_ENTRY);
case ERROR_DUPLICATED_ENTRY:
return new JsonRpcErrorResponse(
req.getId(), JsonRpcError.NODE_WHITELIST_DUPLICATED_ENTRY);
default:
throw new Exception();
switch (nodesWhitelistResult.result()) {
case SUCCESS:
return new JsonRpcSuccessResponse(req.getId());
case ERROR_EMPTY_ENTRY:
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.NODE_WHITELIST_EMPTY_ENTRY);
case ERROR_ABSENT_ENTRY:
return new JsonRpcErrorResponse(
req.getId(), JsonRpcError.NODE_WHITELIST_MISSING_ENTRY);
case ERROR_DUPLICATED_ENTRY:
return new JsonRpcErrorResponse(
req.getId(), JsonRpcError.NODE_WHITELIST_DUPLICATED_ENTRY);
default:
throw new Exception();
}
} catch (IllegalArgumentException e) {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.NODE_WHITELIST_INVALID_ENTRY);
} catch (Exception e) {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.INTERNAL_ERROR);
}
} else {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.NODE_WHITELIST_NOT_ENABLED);
}
} catch (IllegalArgumentException e) {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.NODE_WHITELIST_INVALID_ENTRY);
} catch (P2pDisabledException e) {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.P2P_DISABLED);
} catch (Exception e) {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.INTERNAL_ERROR);
}
}

@ -50,7 +50,7 @@ public enum JsonRpcError {
COINBASE_NOT_SPECIFIED(-32000, "Coinbase must be explicitly specified"),
// Permissioning errors
ACCOUNT_WHITELIST_NOT_SET(-32000, "Account whitelist has not been set"),
ACCOUNT_WHITELIST_NOT_ENABLED(-32000, "Account whitelisting has not been enabled"),
ACCOUNT_WHITELIST_EMPTY_ENTRY(-32000, "Request contains an empty list of accounts"),
ACCOUNT_WHITELIST_INVALID_ENTRY(-32000, "Request contains an invalid account"),
ACCOUNT_WHITELIST_DUPLICATED_ENTRY(-32000, "Request contains duplicate accounts"),
@ -58,7 +58,7 @@ public enum JsonRpcError {
ACCOUNT_WHITELIST_ABSENT_ENTRY(-32000, "Cannot remove an absent account from whitelist"),
// Node whitelist errors
NODE_WHITELIST_NOT_SET(-32000, "Node whitelist has not been set"),
NODE_WHITELIST_NOT_ENABLED(-32000, "Node whitelisting has not been enabled"),
NODE_WHITELIST_EMPTY_ENTRY(-32000, "Request contains an empty list of nodes"),
NODE_WHITELIST_INVALID_ENTRY(-32000, "Request contains an invalid node"),
NODE_WHITELIST_DUPLICATED_ENTRY(-32000, "Request contains duplicate nodes"),

@ -45,8 +45,6 @@ import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec;
import tech.pegasys.pantheon.ethereum.mainnet.ValidationResult;
import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork;
import tech.pegasys.pantheon.ethereum.p2p.wire.Capability;
import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.ethereum.privacy.PrivateTransactionHandler;
import tech.pegasys.pantheon.ethereum.util.RawBlockIterator;
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive;
@ -60,6 +58,7 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import com.google.common.base.Charsets;
@ -170,9 +169,6 @@ public abstract class AbstractEthJsonRpcHttpServiceTest {
supportedCapabilities.add(EthProtocol.ETH62);
supportedCapabilities.add(EthProtocol.ETH63);
final AccountWhitelistController accountWhitelistController =
new AccountWhitelistController(PermissioningConfiguration.createDefault());
final Map<String, JsonRpcMethod> methods =
new JsonRpcMethodsFactory()
.methods(
@ -186,7 +182,7 @@ public abstract class AbstractEthJsonRpcHttpServiceTest {
miningCoordinatorMock,
new NoOpMetricsSystem(),
supportedCapabilities,
accountWhitelistController,
Optional.empty(),
JSON_RPC_APIS,
privateTransactionHandlerMock);
final JsonRpcConfiguration config = JsonRpcConfiguration.createDefault();

@ -39,6 +39,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import io.vertx.core.Vertx;
@ -97,7 +98,7 @@ public class JsonRpcHttpServiceHostWhitelistTest {
mock(EthHashMiningCoordinator.class),
new NoOpMetricsSystem(),
supportedCapabilities,
mock(AccountWhitelistController.class),
Optional.of(mock(AccountWhitelistController.class)),
JSON_RPC_APIS,
mock(PrivateTransactionHandler.class)));
service = createJsonRpcHttpService();

@ -29,7 +29,6 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.queries.BlockchainQueries
import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule;
import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork;
import tech.pegasys.pantheon.ethereum.p2p.wire.Capability;
import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import tech.pegasys.pantheon.ethereum.privacy.PrivateTransactionHandler;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
@ -148,7 +147,7 @@ public class JsonRpcHttpServiceLoginTest {
mock(EthHashMiningCoordinator.class),
new NoOpMetricsSystem(),
supportedCapabilities,
mock(AccountWhitelistController.class),
Optional.empty(),
JSON_RPC_APIS,
mock(PrivateTransactionHandler.class)));
service = createJsonRpcHttpService();

@ -34,6 +34,7 @@ import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import com.google.common.collect.Lists;
@ -177,7 +178,7 @@ public class JsonRpcHttpServiceRpcApisTest {
mock(EthHashMiningCoordinator.class),
new NoOpMetricsSystem(),
supportedCapabilities,
mock(AccountWhitelistController.class),
Optional.of(mock(AccountWhitelistController.class)),
config.getRpcApis(),
mock(PrivateTransactionHandler.class)));
final JsonRpcHttpService jsonRpcHttpService =

@ -126,7 +126,7 @@ public class JsonRpcHttpServiceTest {
mock(EthHashMiningCoordinator.class),
new NoOpMetricsSystem(),
supportedCapabilities,
mock(AccountWhitelistController.class),
Optional.of(mock(AccountWhitelistController.class)),
JSON_RPC_APIS,
mock(PrivateTransactionHandler.class)));
service = createJsonRpcHttpService();

@ -46,7 +46,9 @@ public class PermAddAccountsToWhitelistTest {
@Before
public void before() {
method = new PermAddAccountsToWhitelist(accountWhitelist, new JsonRpcParameter());
method =
new PermAddAccountsToWhitelist(
java.util.Optional.of(accountWhitelist), new JsonRpcParameter());
}
@Test

@ -34,6 +34,7 @@ import tech.pegasys.pantheon.ethereum.permissioning.WhitelistOperationResult;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.assertj.core.util.Lists;
import org.junit.Before;
@ -76,6 +77,9 @@ public class PermAddNodesToWhitelistTest {
final JsonRpcRequest request = buildRequest(Lists.newArrayList(badEnode));
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NODE_WHITELIST_INVALID_ENTRY);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
final JsonRpcResponse actual = method.response(request);
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
@ -86,6 +90,9 @@ public class PermAddNodesToWhitelistTest {
final JsonRpcRequest request = buildRequest(Lists.newArrayList(enode2, badEnode, enode1));
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NODE_WHITELIST_INVALID_ENTRY);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
final JsonRpcResponse actual = method.response(request);
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
@ -96,6 +103,9 @@ public class PermAddNodesToWhitelistTest {
final JsonRpcRequest request = buildRequest(Lists.newArrayList(""));
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NODE_WHITELIST_INVALID_ENTRY);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
final JsonRpcResponse actual = method.response(request);
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
@ -107,7 +117,7 @@ public class PermAddNodesToWhitelistTest {
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NODE_WHITELIST_DUPLICATED_ENTRY);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(nodeWhitelistController);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.addNodes(any()))
.thenReturn(new NodesWhitelistResult(WhitelistOperationResult.ERROR_DUPLICATED_ENTRY));
@ -122,7 +132,7 @@ public class PermAddNodesToWhitelistTest {
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NODE_WHITELIST_EMPTY_ENTRY);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(nodeWhitelistController);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.addNodes(eq(new ArrayList<>())))
.thenReturn(new NodesWhitelistResult(WhitelistOperationResult.ERROR_EMPTY_ENTRY));
@ -136,7 +146,7 @@ public class PermAddNodesToWhitelistTest {
final JsonRpcRequest request = buildRequest(Lists.newArrayList(enode1));
final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getId());
when(p2pNetwork.getNodeWhitelistController()).thenReturn(nodeWhitelistController);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.addNodes(any()))
.thenReturn(new NodesWhitelistResult(WhitelistOperationResult.SUCCESS));
@ -153,7 +163,7 @@ public class PermAddNodesToWhitelistTest {
final JsonRpcRequest request = buildRequest(Lists.newArrayList(enode1, enode2, enode3));
final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getId());
when(p2pNetwork.getNodeWhitelistController()).thenReturn(nodeWhitelistController);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.addNodes(any()))
.thenReturn(new NodesWhitelistResult(WhitelistOperationResult.SUCCESS));

@ -16,8 +16,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
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;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
@ -43,7 +41,7 @@ public class PermGetAccountsWhitelistTest {
@Before
public void before() {
method = new PermGetAccountsWhitelist(accountWhitelist);
method = new PermGetAccountsWhitelist(java.util.Optional.of(accountWhitelist));
}
@Test
@ -54,7 +52,6 @@ public class PermGetAccountsWhitelistTest {
@Test
public void shouldReturnExpectedListOfAccountsWhenWhitelistHasBeenSet() {
List<String> accountsList = Arrays.asList("0x0", "0x1");
when(accountWhitelist.isAccountWhiteListSet()).thenReturn(true);
when(accountWhitelist.getAccountWhitelist()).thenReturn(accountsList);
JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, accountsList);
@ -66,7 +63,6 @@ public class PermGetAccountsWhitelistTest {
@Test
public void shouldReturnEmptyListOfAccountsWhenWhitelistHasBeenSetAndIsEmpty() {
List<String> emptyAccountsList = new ArrayList<>();
when(accountWhitelist.isAccountWhiteListSet()).thenReturn(true);
when(accountWhitelist.getAccountWhitelist()).thenReturn(emptyAccountsList);
JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, emptyAccountsList);
@ -74,15 +70,4 @@ public class PermGetAccountsWhitelistTest {
assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse);
}
@Test
public void shouldReturnErrorWhenWhitelistHasNotBeenSet() {
when(accountWhitelist.isAccountWhiteListSet()).thenReturn(false);
JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, JsonRpcError.ACCOUNT_WHITELIST_NOT_SET);
JsonRpcResponse actualResponse = method.response(request);
assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse);
}
}

@ -31,6 +31,7 @@ import tech.pegasys.pantheon.ethereum.p2p.permissioning.NodeWhitelistController;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.assertj.core.util.Lists;
@ -72,8 +73,7 @@ public class PermGetNodesWhitelistTest {
final JsonRpcResponse expected =
new JsonRpcSuccessResponse(request.getId(), Lists.newArrayList(enode1, enode2, enode3));
when(p2pNetwork.getNodeWhitelistController()).thenReturn(nodeWhitelistController);
when(nodeWhitelistController.nodeWhitelistSet()).thenReturn(true);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.getNodesWhitelist())
.thenReturn(buildNodesList(enode1, enode2, enode3));
@ -81,7 +81,6 @@ public class PermGetNodesWhitelistTest {
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
verify(nodeWhitelistController, times(1)).nodeWhitelistSet();
verify(nodeWhitelistController, times(1)).getNodesWhitelist();
verifyNoMoreInteractions(nodeWhitelistController);
}
@ -91,36 +90,18 @@ public class PermGetNodesWhitelistTest {
final JsonRpcRequest request = buildRequest();
final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getId(), Lists.emptyList());
when(p2pNetwork.getNodeWhitelistController()).thenReturn(nodeWhitelistController);
when(nodeWhitelistController.nodeWhitelistSet()).thenReturn(true);
when(p2pNetwork.getNodeWhitelistController())
.thenReturn(java.util.Optional.of(nodeWhitelistController));
when(nodeWhitelistController.getNodesWhitelist()).thenReturn(buildNodesList());
final JsonRpcResponse actual = method.response(request);
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
verify(nodeWhitelistController, times(1)).nodeWhitelistSet();
verify(nodeWhitelistController, times(1)).getNodesWhitelist();
verifyNoMoreInteractions(nodeWhitelistController);
}
@Test
public void shouldReturnFailResponseWhenListNotSet() {
final JsonRpcRequest request = buildRequest();
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NODE_WHITELIST_NOT_SET);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(nodeWhitelistController);
when(nodeWhitelistController.nodeWhitelistSet()).thenReturn(false);
final JsonRpcResponse actual = method.response(request);
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
verify(nodeWhitelistController, times(1)).nodeWhitelistSet();
verifyNoMoreInteractions(nodeWhitelistController);
}
@Test
public void shouldFailWhenP2pDisabled() {
when(p2pNetwork.getNodeWhitelistController())

@ -46,7 +46,9 @@ public class PermRemoveAccountsFromWhitelistTest {
@Before
public void before() {
method = new PermRemoveAccountsFromWhitelist(accountWhitelist, new JsonRpcParameter());
method =
new PermRemoveAccountsFromWhitelist(
java.util.Optional.of(accountWhitelist), new JsonRpcParameter());
}
@Test

@ -34,6 +34,7 @@ import tech.pegasys.pantheon.ethereum.permissioning.WhitelistOperationResult;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.assertj.core.util.Lists;
import org.junit.Before;
@ -76,6 +77,9 @@ public class PermRemoveNodesFromWhitelistTest {
final JsonRpcRequest request = buildRequest(Lists.newArrayList(badEnode));
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NODE_WHITELIST_INVALID_ENTRY);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
final JsonRpcResponse actual = method.response(request);
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
@ -86,6 +90,9 @@ public class PermRemoveNodesFromWhitelistTest {
final JsonRpcRequest request = buildRequest(Lists.newArrayList(""));
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NODE_WHITELIST_INVALID_ENTRY);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
final JsonRpcResponse actual = method.response(request);
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
@ -96,7 +103,7 @@ public class PermRemoveNodesFromWhitelistTest {
final JsonRpcRequest request = buildRequest(Lists.newArrayList(enode1));
final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getId());
when(p2pNetwork.getNodeWhitelistController()).thenReturn(nodeWhitelistController);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.removeNodes(any()))
.thenReturn(new NodesWhitelistResult(WhitelistOperationResult.SUCCESS));
@ -113,7 +120,7 @@ public class PermRemoveNodesFromWhitelistTest {
final JsonRpcRequest request = buildRequest(Lists.newArrayList(enode1, enode2, enode3));
final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getId());
when(p2pNetwork.getNodeWhitelistController()).thenReturn(nodeWhitelistController);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.removeNodes(any()))
.thenReturn(new NodesWhitelistResult(WhitelistOperationResult.SUCCESS));
@ -143,7 +150,7 @@ public class PermRemoveNodesFromWhitelistTest {
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NODE_WHITELIST_DUPLICATED_ENTRY);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(nodeWhitelistController);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.removeNodes(any()))
.thenReturn(new NodesWhitelistResult(WhitelistOperationResult.ERROR_DUPLICATED_ENTRY));
@ -158,7 +165,7 @@ public class PermRemoveNodesFromWhitelistTest {
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NODE_WHITELIST_EMPTY_ENTRY);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(nodeWhitelistController);
when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.removeNodes(eq(new ArrayList<>())))
.thenReturn(new NodesWhitelistResult(WhitelistOperationResult.ERROR_EMPTY_ENTRY));

@ -23,7 +23,6 @@ import tech.pegasys.pantheon.ethereum.p2p.wire.Capability;
import tech.pegasys.pantheon.ethereum.p2p.wire.DefaultMessage;
import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo;
import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.util.Subscribers;
import java.net.InetSocketAddress;
@ -34,6 +33,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
@ -204,8 +204,8 @@ public final class MockNetwork {
}
@Override
public NodeWhitelistController getNodeWhitelistController() {
return new NodeWhitelistController(PermissioningConfiguration.createDefault());
public Optional<NodeWhitelistController> getNodeWhitelistController() {
return Optional.empty();
}
}

@ -24,6 +24,7 @@ import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
@ -83,7 +84,7 @@ public class NoopP2PNetwork implements P2PNetwork {
}
@Override
public NodeWhitelistController getNodeWhitelistController() {
public Optional<NodeWhitelistController> getNodeWhitelistController() {
throw new P2pDisabledException("P2P networking disabled. Node whitelist unavailable.");
}

@ -20,6 +20,7 @@ import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo;
import java.io.Closeable;
import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
@ -109,5 +110,10 @@ public interface P2PNetwork extends Closeable, Runnable {
*/
boolean isP2pEnabled();
NodeWhitelistController getNodeWhitelistController();
/**
* Returns the node whitelist controller
*
* @return an instance of NodeWhitelistController, if set.
*/
Optional<NodeWhitelistController> getNodeWhitelistController();
}

@ -69,7 +69,7 @@ public abstract class PeerDiscoveryAgent implements DisconnectCallback {
protected final List<DiscoveryPeer> bootstrapPeers;
private final PeerRequirement peerRequirement;
private final PeerBlacklist peerBlacklist;
private final NodeWhitelistController nodeWhitelistController;
private final Optional<NodeWhitelistController> nodeWhitelistController;
/* The peer controller, which takes care of the state machine of peers. */
protected Optional<PeerDiscoveryController> controller = Optional.empty();
@ -92,7 +92,7 @@ public abstract class PeerDiscoveryAgent implements DisconnectCallback {
final DiscoveryConfiguration config,
final PeerRequirement peerRequirement,
final PeerBlacklist peerBlacklist,
final NodeWhitelistController nodeWhitelistController) {
final Optional<NodeWhitelistController> nodeWhitelistController) {
checkArgument(keyPair != null, "keypair cannot be null");
checkArgument(config != null, "provided configuration cannot be null");

@ -31,6 +31,7 @@ import java.io.IOException;
import java.net.BindException;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.concurrent.CompletableFuture;
@ -55,7 +56,7 @@ public class VertxPeerDiscoveryAgent extends PeerDiscoveryAgent {
final DiscoveryConfiguration config,
final PeerRequirement peerRequirement,
final PeerBlacklist peerBlacklist,
final NodeWhitelistController nodeWhitelistController) {
final Optional<NodeWhitelistController> nodeWhitelistController) {
super(keyPair, config, peerRequirement, peerBlacklist, nodeWhitelistController);
checkArgument(vertx != null, "vertx instance cannot be null");
this.vertx = vertx;

@ -108,7 +108,7 @@ public class PeerDiscoveryController {
private final DiscoveryPeer localPeer;
private final OutboundMessageHandler outboundMessageHandler;
private final PeerBlacklist peerBlacklist;
private final NodeWhitelistController nodeWhitelist;
private final Optional<NodeWhitelistController> nodeWhitelistController;
private RetryDelayFunction retryDelayFunction = RetryDelayFunction.linear(1.5, 2000, 60000);
@ -133,7 +133,7 @@ public class PeerDiscoveryController {
final long tableRefreshIntervalMs,
final PeerRequirement peerRequirement,
final PeerBlacklist peerBlacklist,
final NodeWhitelistController nodeWhitelist,
final Optional<NodeWhitelistController> nodeWhitelistController,
final Subscribers<Consumer<PeerBondedEvent>> peerBondedObservers) {
this.timerUtil = timerUtil;
this.keypair = keypair;
@ -143,7 +143,7 @@ public class PeerDiscoveryController {
this.tableRefreshIntervalMs = tableRefreshIntervalMs;
this.peerRequirement = peerRequirement;
this.peerBlacklist = peerBlacklist;
this.nodeWhitelist = nodeWhitelist;
this.nodeWhitelistController = nodeWhitelistController;
this.outboundMessageHandler = outboundMessageHandler;
this.peerBondedObservers = peerBondedObservers;
}
@ -156,7 +156,7 @@ public class PeerDiscoveryController {
bootstrapNodes
.stream()
.filter(node -> peerTable.tryAdd(node).getOutcome() == Outcome.ADDED)
.filter(node -> nodeWhitelist.isPermitted(node))
.filter(node -> whitelistIfPresentIsNodePermitted(node))
.forEach(node -> bond(node, true));
final long timerId =
@ -180,6 +180,12 @@ public class PeerDiscoveryController {
return CompletableFuture.completedFuture(null);
}
private boolean whitelistIfPresentIsNodePermitted(final DiscoveryPeer sender) {
return nodeWhitelistController
.map(nodeWhitelistController1 -> nodeWhitelistController1.isPermitted(sender))
.orElse(true);
}
/**
* Handles an incoming message and processes it based on the state machine for the {@link
* DiscoveryPeer}.
@ -204,7 +210,7 @@ public class PeerDiscoveryController {
return;
}
if (!nodeWhitelist.isPermitted(sender)) {
if (!whitelistIfPresentIsNodePermitted(sender)) {
return;
}
@ -253,7 +259,7 @@ public class PeerDiscoveryController {
for (final DiscoveryPeer neighbor : neighbors) {
// If the peer is not whitelisted, is blacklisted, is already known, or
// represents this node, skip bonding
if (!nodeWhitelist.isPermitted(neighbor)
if (!whitelistIfPresentIsNodePermitted(neighbor)
|| peerBlacklist.contains(neighbor)
|| peerTable.get(neighbor).isPresent()
|| neighbor.getId().equals(localPeer.getId())) {

@ -44,6 +44,7 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
@ -149,7 +150,7 @@ public class NettyP2PNetwork implements P2PNetwork {
private final LabelledMetric<Counter> outboundMessagesCounter;
private final NodeWhitelistController nodeWhitelistController;
private final Optional<NodeWhitelistController> nodeWhitelistController;
/**
* Creates a peer networking service for production purposes.
@ -175,7 +176,7 @@ public class NettyP2PNetwork implements P2PNetwork {
final PeerRequirement peerRequirement,
final PeerBlacklist peerBlacklist,
final MetricsSystem metricsSystem,
final NodeWhitelistController nodeWhitelistController) {
final Optional<NodeWhitelistController> nodeWhitelistController) {
connections = new PeerConnectionRegistry(metricsSystem);
this.peerBlacklist = peerBlacklist;
@ -298,12 +299,16 @@ public class NettyP2PNetwork implements P2PNetwork {
}
private boolean isPeerWhitelisted(final PeerConnection connection, final SocketChannel ch) {
return nodeWhitelistController.contains(
new DefaultPeer(
connection.getPeer().getNodeId(),
ch.remoteAddress().getAddress().getHostAddress(),
connection.getPeer().getPort(),
connection.getPeer().getPort()));
return nodeWhitelistController
.map(
nwc ->
nwc.isPermitted(
new DefaultPeer(
connection.getPeer().getNodeId(),
ch.remoteAddress().getAddress().getHostAddress(),
connection.getPeer().getPort(),
connection.getPeer().getPort())))
.orElse(true);
}
@Override
@ -506,7 +511,7 @@ public class NettyP2PNetwork implements P2PNetwork {
}
@Override
public NodeWhitelistController getNodeWhitelistController() {
public Optional<NodeWhitelistController> getNodeWhitelistController() {
return nodeWhitelistController;
}

@ -28,19 +28,16 @@ import com.google.common.annotations.VisibleForTesting;
public class NodeWhitelistController {
private final List<Peer> nodesWhitelist = new ArrayList<>();
private boolean nodeWhitelistSet = false;
public NodeWhitelistController(final PermissioningConfiguration configuration) {
if (configuration.isNodeWhitelistSet() && configuration.getNodeWhitelist() != null) {
if (configuration.isNodeWhitelistEnabled() && configuration.getNodeWhitelist() != null) {
for (URI uri : configuration.getNodeWhitelist()) {
nodesWhitelist.add(DefaultPeer.fromURI(uri));
}
nodeWhitelistSet = true;
}
}
public boolean addNode(final Peer node) {
nodeWhitelistSet = true;
return nodesWhitelist.add(node);
}
@ -102,17 +99,13 @@ public class NodeWhitelistController {
}
public boolean isPermitted(final Peer node) {
return (!nodeWhitelistSet || (nodeWhitelistSet && nodesWhitelist.contains(node)));
return (nodesWhitelist.contains(node));
}
public List<Peer> getNodesWhitelist() {
return nodesWhitelist;
}
public boolean nodeWhitelistSet() {
return nodeWhitelistSet;
}
public static class NodesWhitelistResult {
private final WhitelistOperationResult result;
private final Optional<String> message;
@ -136,8 +129,4 @@ public class NodeWhitelistController {
return message;
}
}
public boolean contains(final Peer node) {
return (!nodeWhitelistSet || (nodesWhitelist.contains(node)));
}
}

@ -46,6 +46,7 @@ import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.net.InetAddress;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
@ -84,7 +85,7 @@ public final class NettyP2PNetworkTest {
() -> false,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()));
Optional.empty());
final P2PNetwork connector =
new NettyP2PNetwork(
vertx,
@ -97,7 +98,7 @@ public final class NettyP2PNetworkTest {
() -> false,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
final int listenPort = listener.getLocalPeerInfo().getPort();
listener.run();
@ -138,7 +139,7 @@ public final class NettyP2PNetworkTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()));
Optional.empty());
final P2PNetwork connector =
new NettyP2PNetwork(
vertx,
@ -151,7 +152,7 @@ public final class NettyP2PNetworkTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
final int listenPort = listener.getLocalPeerInfo().getPort();
listener.run();
connector.run();
@ -207,7 +208,7 @@ public final class NettyP2PNetworkTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()));
Optional.empty());
final P2PNetwork connector1 =
new NettyP2PNetwork(
vertx,
@ -220,7 +221,7 @@ public final class NettyP2PNetworkTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()));
Optional.empty());
final P2PNetwork connector2 =
new NettyP2PNetwork(
vertx,
@ -233,7 +234,7 @@ public final class NettyP2PNetworkTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
final int listenPort = listener.getLocalPeerInfo().getPort();
// Setup listener and first connection
@ -288,7 +289,7 @@ public final class NettyP2PNetworkTest {
() -> false,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()));
Optional.empty());
final P2PNetwork connector =
new NettyP2PNetwork(
vertx,
@ -301,7 +302,7 @@ public final class NettyP2PNetworkTest {
() -> false,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
final int listenPort = listener.getLocalPeerInfo().getPort();
listener.run();
connector.run();
@ -343,7 +344,7 @@ public final class NettyP2PNetworkTest {
() -> false,
localBlacklist,
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()));
Optional.empty());
final P2PNetwork remoteNetwork =
new NettyP2PNetwork(
vertx,
@ -356,7 +357,7 @@ public final class NettyP2PNetworkTest {
() -> false,
remoteBlacklist,
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
final int localListenPort = localNetwork.getLocalPeerInfo().getPort();
final int remoteListenPort = remoteNetwork.getLocalPeerInfo().getPort();
final Peer localPeer =
@ -409,10 +410,12 @@ public final class NettyP2PNetworkTest {
final BytesValue localId = localKp.getPublicKey().getEncodedBytes();
final PeerBlacklist localBlacklist = new PeerBlacklist();
final PeerBlacklist remoteBlacklist = new PeerBlacklist();
final PermissioningConfiguration config = PermissioningConfiguration.createDefault();
final NodeWhitelistController localWhitelist = new NodeWhitelistController(config);
final Optional<PermissioningConfiguration> config =
Optional.ofNullable(PermissioningConfiguration.createDefault());
final Optional<NodeWhitelistController> localWhitelistController =
Optional.of(new NodeWhitelistController(config.get()));
// turn on whitelisting by adding a different node NOT remote node
localWhitelist.addNode(mockPeer());
localWhitelistController.ifPresent(nwc -> nwc.addNode(mockPeer()));
final SubProtocol subprotocol = subProtocol();
final Capability cap = Capability.create(subprotocol.getName(), 63);
@ -428,7 +431,7 @@ public final class NettyP2PNetworkTest {
() -> false,
localBlacklist,
new NoOpMetricsSystem(),
localWhitelist);
localWhitelistController);
final P2PNetwork remoteNetwork =
new NettyP2PNetwork(
vertx,
@ -441,7 +444,7 @@ public final class NettyP2PNetworkTest {
() -> false,
remoteBlacklist,
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
final int localListenPort = localNetwork.getLocalPeerInfo().getPort();
final Peer localPeer =
new DefaultPeer(
@ -636,7 +639,7 @@ public final class NettyP2PNetworkTest {
() -> false,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()));
Optional.empty());
}
private Peer mockPeer() {

@ -25,12 +25,11 @@ import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration;
import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryServiceException;
import tech.pegasys.pantheon.ethereum.p2p.netty.NettyP2PNetwork;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
import tech.pegasys.pantheon.ethereum.p2p.permissioning.NodeWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.NetworkUtility;
import java.io.IOException;
import java.util.Optional;
import io.vertx.core.Vertx;
import org.assertj.core.api.Assertions;
@ -58,7 +57,7 @@ public class NetworkingServiceLifecycleTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
service.run();
final int port = service.getDiscoverySocketAddress().getPort();
@ -84,7 +83,7 @@ public class NetworkingServiceLifecycleTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
Assertions.fail("Expected Exception");
}
}
@ -104,7 +103,7 @@ public class NetworkingServiceLifecycleTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
Assertions.fail("Expected Exception");
}
}
@ -124,7 +123,7 @@ public class NetworkingServiceLifecycleTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
Assertions.fail("Expected Exception");
}
}
@ -140,7 +139,7 @@ public class NetworkingServiceLifecycleTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
Assertions.fail("Expected Exception");
}
}
@ -157,7 +156,7 @@ public class NetworkingServiceLifecycleTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
service.run();
service.stop();
service.run();
@ -176,7 +175,7 @@ public class NetworkingServiceLifecycleTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()));
Optional.empty());
final NettyP2PNetwork service2 =
new NettyP2PNetwork(
vertx,
@ -186,7 +185,7 @@ public class NetworkingServiceLifecycleTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
service1.run();
service1.stop();
service2.run();
@ -206,7 +205,7 @@ public class NetworkingServiceLifecycleTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
service1.run();
final NetworkingConfiguration config = configWithRandomPorts();
config.getDiscovery().setBindPort(service1.getDiscoverySocketAddress().getPort());
@ -219,7 +218,7 @@ public class NetworkingServiceLifecycleTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
try {
service2.run();
} catch (final Exception e) {
@ -249,7 +248,7 @@ public class NetworkingServiceLifecycleTest {
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()))) {
Optional.empty())) {
assertTrue(agent.getDiscoveryPeers().isEmpty());
assertEquals(0, agent.getPeers().size());
}

@ -21,7 +21,6 @@ import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PacketType;
import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PingPacketData;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
import tech.pegasys.pantheon.ethereum.p2p.permissioning.NodeWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.util.Arrays;
@ -29,6 +28,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -168,8 +168,7 @@ public class PeerDiscoveryTestHelper {
private final AtomicInteger nextAvailablePort;
private PeerBlacklist blacklist = new PeerBlacklist();
private NodeWhitelistController whitelist =
new NodeWhitelistController(PermissioningConfiguration.createDefault());
private Optional<NodeWhitelistController> whitelist = Optional.empty();
private List<DiscoveryPeer> bootstrapPeers = Collections.emptyList();
private boolean active = true;
@ -190,7 +189,7 @@ public class PeerDiscoveryTestHelper {
return this;
}
public AgentBuilder whiteList(final NodeWhitelistController whitelist) {
public AgentBuilder whiteList(final Optional<NodeWhitelistController> whitelist) {
this.whitelist = whitelist;
return this;
}

@ -26,12 +26,11 @@ import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PeerDiscoveryContro
import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PeerTable;
import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PingPacketData;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
import tech.pegasys.pantheon.ethereum.p2p.permissioning.NodeWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.util.Subscribers;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
@ -62,7 +61,7 @@ public class PeerDiscoveryTimestampsTest {
TimeUnit.HOURS.toMillis(1),
() -> true,
new PeerBlacklist(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()),
Optional.empty(),
new Subscribers<>());
controller.start();

@ -26,6 +26,7 @@ import java.util.Arrays;
import java.util.Deque;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
public class MockPeerDiscoveryAgent extends PeerDiscoveryAgent {
@ -38,7 +39,7 @@ public class MockPeerDiscoveryAgent extends PeerDiscoveryAgent {
final DiscoveryConfiguration config,
final PeerRequirement peerRequirement,
final PeerBlacklist peerBlacklist,
final NodeWhitelistController nodeWhitelistController,
final Optional<NodeWhitelistController> nodeWhitelistController,
final Map<BytesValue, MockPeerDiscoveryAgent> agentNetwork) {
super(keyPair, config, peerRequirement, peerBlacklist, nodeWhitelistController);
this.agentNetwork = agentNetwork;

@ -588,8 +588,7 @@ public class PeerDiscoveryControllerTest {
}
@Test
public void shouldNotBondWithBlacklistedPeer()
throws InterruptedException, ExecutionException, TimeoutException {
public void shouldNotBondWithBlacklistedPeer() {
final List<DiscoveryPeer> peers = createPeersInLastBucket(localPeer, 3);
final DiscoveryPeer discoPeer = peers.get(0);
final DiscoveryPeer otherPeer = peers.get(1);
@ -885,8 +884,7 @@ public class PeerDiscoveryControllerTest {
}
@Test
public void shouldNotBondWithNonWhitelistedPeer()
throws InterruptedException, ExecutionException, TimeoutException {
public void shouldNotBondWithNonWhitelistedPeer() {
final List<DiscoveryPeer> peers = createPeersInLastBucket(localPeer, 3);
final DiscoveryPeer discoPeer = peers.get(0);
final DiscoveryPeer otherPeer = peers.get(1);
@ -905,7 +903,7 @@ public class PeerDiscoveryControllerTest {
getControllerBuilder()
.peers(discoPeer)
.blacklist(blacklist)
.whitelist(nodeWhitelistController)
.whitelist(Optional.of(nodeWhitelistController))
.outboundMessageHandler(outboundMessageHandler)
.build();
@ -963,7 +961,8 @@ public class PeerDiscoveryControllerTest {
// don't add disco peer to whitelist
PermissioningConfiguration config = PermissioningConfiguration.createDefault();
config.setNodeWhitelist(new ArrayList<>());
NodeWhitelistController nodeWhitelistController = new NodeWhitelistController(config);
Optional<NodeWhitelistController> nodeWhitelistController =
Optional.of(new NodeWhitelistController(config));
controller =
getControllerBuilder()
@ -1039,8 +1038,7 @@ public class PeerDiscoveryControllerTest {
static class ControllerBuilder {
private Collection<DiscoveryPeer> discoPeers = Collections.emptyList();
private PeerBlacklist blacklist = new PeerBlacklist();
private NodeWhitelistController whitelist =
new NodeWhitelistController(PermissioningConfiguration.createDefault());
private Optional<NodeWhitelistController> whitelist = Optional.empty();
private MockTimerUtil timerUtil = new MockTimerUtil();
private KeyPair keypair;
private DiscoveryPeer localPeer;
@ -1067,7 +1065,7 @@ public class PeerDiscoveryControllerTest {
return this;
}
ControllerBuilder whitelist(final NodeWhitelistController whitelist) {
ControllerBuilder whitelist(final Optional<NodeWhitelistController> whitelist) {
this.whitelist = whitelist;
return this;
}

@ -25,8 +25,6 @@ import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.p2p.discovery.DiscoveryPeer;
import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryTestHelper;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
import tech.pegasys.pantheon.ethereum.p2p.permissioning.NodeWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.util.Subscribers;
import tech.pegasys.pantheon.util.bytes.BytesValue;
@ -64,7 +62,7 @@ public class PeerDiscoveryTableRefreshTest {
0,
() -> true,
new PeerBlacklist(),
new NodeWhitelistController(PermissioningConfiguration.createDefault()),
Optional.empty(),
new Subscribers<>()));
controller.start();

@ -22,11 +22,9 @@ public class AccountWhitelistController {
private static final int ACCOUNT_BYTES_SIZE = 20;
private final List<String> accountWhitelist = new ArrayList<>();
private boolean isAccountWhitelistSet = false;
public AccountWhitelistController(final PermissioningConfiguration configuration) {
if (configuration != null && configuration.isAccountWhitelistSet()) {
this.isAccountWhitelistSet = configuration.isAccountWhitelistSet();
if (configuration != null && configuration.isAccountWhitelistEnabled()) {
if (!configuration.getAccountWhitelist().isEmpty()) {
addAccounts(configuration.getAccountWhitelist());
}
@ -44,7 +42,6 @@ public class AccountWhitelistController {
return WhitelistOperationResult.ERROR_EXISTING_ENTRY;
}
this.isAccountWhitelistSet = true;
this.accountWhitelist.addAll(accounts);
return WhitelistOperationResult.SUCCESS;
}
@ -84,11 +81,7 @@ public class AccountWhitelistController {
}
public boolean contains(final String account) {
return (!isAccountWhitelistSet || accountWhitelist.contains(account));
}
public boolean isAccountWhiteListSet() {
return isAccountWhitelistSet;
return (accountWhitelist.contains(account));
}
public List<String> getAccountWhitelist() {

@ -20,8 +20,8 @@ import java.util.List;
public class PermissioningConfiguration {
private List<URI> nodeWhitelist;
private List<String> accountWhitelist;
private boolean nodeWhitelistSet;
private boolean accountWhitelistSet;
private boolean nodeWhitelistEnabled;
private boolean accountWhitelistEnabled;
private String configurationFilePath;
public List<URI> getNodeWhitelist() {
@ -38,12 +38,12 @@ public class PermissioningConfiguration {
public void setNodeWhitelist(final Collection<URI> nodeWhitelist) {
if (nodeWhitelist != null) {
this.nodeWhitelist.addAll(nodeWhitelist);
this.nodeWhitelistSet = true;
this.nodeWhitelistEnabled = true;
}
}
public boolean isNodeWhitelistSet() {
return nodeWhitelistSet;
public boolean isNodeWhitelistEnabled() {
return nodeWhitelistEnabled;
}
public List<String> getAccountWhitelist() {
@ -53,12 +53,12 @@ public class PermissioningConfiguration {
public void setAccountWhitelist(final Collection<String> accountWhitelist) {
if (accountWhitelist != null) {
this.accountWhitelist.addAll(accountWhitelist);
this.accountWhitelistSet = true;
this.accountWhitelistEnabled = true;
}
}
public boolean isAccountWhitelistSet() {
return accountWhitelistSet;
public boolean isAccountWhitelistEnabled() {
return accountWhitelistEnabled;
}
public String getConfigurationFilePath() {

@ -35,34 +35,9 @@ public class AccountWhitelistControllerTest {
controller = new AccountWhitelistController(permissioningConfig);
}
@Test
public void newInstanceWithNullPermConfigShouldHaveAccountWhitelistNotSet() {
controller = new AccountWhitelistController(null);
assertThat(controller.isAccountWhiteListSet()).isFalse();
}
@Test
public void whenAccountWhitelistIsNotSetContainsShouldReturnTrue() {
when(permissioningConfig.isAccountWhitelistSet()).thenReturn(false);
controller = new AccountWhitelistController(permissioningConfig);
assertThat(controller.contains("0xfe3b557e8fb62b89f4916b721be55ceb828dbd73")).isTrue();
}
@Test
public void whenPermConfigHasAccountsShouldSetAccountsWhitelist() {
when(permissioningConfig.isAccountWhitelistSet()).thenReturn(true);
when(permissioningConfig.getAccountWhitelist())
.thenReturn(Arrays.asList("0xfe3b557e8fb62b89f4916b721be55ceb828dbd73"));
controller = new AccountWhitelistController(permissioningConfig);
assertThat(controller.isAccountWhiteListSet()).isTrue();
}
@Test
public void whenPermConfigHasAccountsShouldAddAllAccountsToWhitelist() {
when(permissioningConfig.isAccountWhitelistSet()).thenReturn(true);
when(permissioningConfig.isAccountWhitelistEnabled()).thenReturn(true);
when(permissioningConfig.getAccountWhitelist())
.thenReturn(Arrays.asList("0xfe3b557e8fb62b89f4916b721be55ceb828dbd73"));
controller = new AccountWhitelistController(permissioningConfig);
@ -73,7 +48,7 @@ public class AccountWhitelistControllerTest {
@Test
public void whenPermConfigContainsEmptyListOfAccountsContainsShouldReturnFalse() {
when(permissioningConfig.isAccountWhitelistSet()).thenReturn(true);
when(permissioningConfig.isAccountWhitelistEnabled()).thenReturn(true);
when(permissioningConfig.getAccountWhitelist()).thenReturn(new ArrayList<>());
controller = new AccountWhitelistController(permissioningConfig);

@ -31,9 +31,9 @@ public class PermissioningConfigurationTest {
public void defaultConfiguration() {
final PermissioningConfiguration configuration = PermissioningConfiguration.createDefault();
assertThat(configuration.getNodeWhitelist()).isEmpty();
assertThat(configuration.isNodeWhitelistSet()).isFalse();
assertThat(configuration.isNodeWhitelistEnabled()).isFalse();
assertThat(configuration.getAccountWhitelist()).isEmpty();
assertThat(configuration.isAccountWhitelistSet()).isFalse();
assertThat(configuration.isAccountWhitelistEnabled()).isFalse();
}
@Test
@ -41,7 +41,7 @@ public class PermissioningConfigurationTest {
final PermissioningConfiguration configuration = PermissioningConfiguration.createDefault();
configuration.setNodeWhitelist(Arrays.asList(nodes));
assertThat(configuration.getNodeWhitelist()).containsExactlyInAnyOrder(nodes);
assertThat(configuration.isNodeWhitelistSet()).isTrue();
assertThat(configuration.isNodeWhitelistEnabled()).isTrue();
}
@Test
@ -49,7 +49,7 @@ public class PermissioningConfigurationTest {
final PermissioningConfiguration configuration = PermissioningConfiguration.createDefault();
configuration.setNodeWhitelist(null);
assertThat(configuration.getNodeWhitelist()).isEmpty();
assertThat(configuration.isNodeWhitelistSet()).isFalse();
assertThat(configuration.isNodeWhitelistEnabled()).isFalse();
}
@Test
@ -58,7 +58,7 @@ public class PermissioningConfigurationTest {
final PermissioningConfiguration configuration = PermissioningConfiguration.createDefault();
configuration.setAccountWhitelist(Arrays.asList(accounts));
assertThat(configuration.getAccountWhitelist()).containsExactlyInAnyOrder(accounts);
assertThat(configuration.isAccountWhitelistSet()).isTrue();
assertThat(configuration.isAccountWhitelistEnabled()).isTrue();
}
@Test
@ -66,6 +66,6 @@ public class PermissioningConfigurationTest {
final PermissioningConfiguration configuration = PermissioningConfiguration.createDefault();
configuration.setAccountWhitelist(null);
assertThat(configuration.getAccountWhitelist()).isEmpty();
assertThat(configuration.isAccountWhitelistSet()).isFalse();
assertThat(configuration.isAccountWhitelistEnabled()).isFalse();
}
}

@ -88,7 +88,7 @@ public class RunnerBuilder {
private Collection<String> bannedNodeIds;
private MetricsConfiguration metricsConfiguration;
private MetricsSystem metricsSystem;
private PermissioningConfiguration permissioningConfiguration;
private Optional<PermissioningConfiguration> permissioningConfiguration = Optional.empty();
public RunnerBuilder vertx(final Vertx vertx) {
this.vertx = vertx;
@ -142,7 +142,7 @@ public class RunnerBuilder {
public RunnerBuilder permissioningConfiguration(
final PermissioningConfiguration permissioningConfiguration) {
this.permissioningConfiguration = permissioningConfiguration;
this.permissioningConfiguration = Optional.of(permissioningConfiguration);
return this;
}
@ -214,8 +214,10 @@ public class RunnerBuilder {
new PeerBlacklist(
bannedNodeIds.stream().map(BytesValue::fromHexString).collect(Collectors.toSet()));
final NodeWhitelistController nodeWhitelistController =
new NodeWhitelistController(permissioningConfiguration);
final Optional<NodeWhitelistController> nodeWhitelistController =
permissioningConfiguration
.filter(PermissioningConfiguration::isNodeWhitelistEnabled)
.map(NodeWhitelistController::new);
final Synchronizer synchronizer = pantheonController.getSynchronizer();
@ -241,11 +243,16 @@ public class RunnerBuilder {
final TransactionPool transactionPool = pantheonController.getTransactionPool();
final MiningCoordinator miningCoordinator = pantheonController.getMiningCoordinator();
final AccountWhitelistController accountWhitelistController =
new AccountWhitelistController(permissioningConfiguration);
if (permissioningConfiguration.isAccountWhitelistSet()) {
transactionPool.setAccountWhitelist(accountWhitelistController);
}
final Optional<AccountWhitelistController> accountWhitelistController =
permissioningConfiguration
.filter(PermissioningConfiguration::isAccountWhitelistEnabled)
.map(
configuration -> {
AccountWhitelistController whitelistController =
new AccountWhitelistController(configuration);
transactionPool.setAccountWhitelist(whitelistController);
return whitelistController;
});
final PrivacyParameters privacyParameters = pantheonController.getPrivacyParameters();
final PrivateTransactionHandler privateTransactionHandler =
@ -351,7 +358,7 @@ public class RunnerBuilder {
final Set<Capability> supportedCapabilities,
final Collection<RpcApi> jsonRpcApis,
final FilterManager filterManager,
final AccountWhitelistController accountWhitelistController,
final Optional<AccountWhitelistController> accountWhitelistController,
final PrivateTransactionHandler privateTransactionHandler) {
final Map<String, JsonRpcMethod> methods =
new JsonRpcMethodsFactory()

@ -583,8 +583,10 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
}
final EthNetworkConfig ethNetworkConfig = updateNetworkConfig(getNetwork());
final PermissioningConfiguration permissioningConfiguration = permissioningConfiguration();
ensureAllBootnodesAreInWhitelist(ethNetworkConfig, permissioningConfiguration);
final Optional<PermissioningConfiguration> permissioningConfiguration =
permissioningConfiguration();
permissioningConfiguration.ifPresent(
p -> ensureAllBootnodesAreInWhitelist(ethNetworkConfig, p));
synchronize(
buildController(),
@ -732,16 +734,16 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
return metricsConfiguration;
}
private PermissioningConfiguration permissioningConfiguration() {
private Optional<PermissioningConfiguration> permissioningConfiguration() {
if (!permissionsAccountsEnabled && !permissionsNodesEnabled) {
return PermissioningConfiguration.createDefault();
return Optional.empty();
}
final PermissioningConfiguration permissioningConfiguration =
PermissioningConfigurationBuilder.permissioningConfigurationFromToml(
getPermissionsConfigPath(), permissionsNodesEnabled, permissionsAccountsEnabled);
return permissioningConfiguration;
return Optional.of(permissioningConfiguration);
}
private PrivacyParameters orionConfiguration() throws IOException {
@ -786,10 +788,12 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
final JsonRpcConfiguration jsonRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
final MetricsConfiguration metricsConfiguration,
final PermissioningConfiguration permissioningConfiguration) {
final Optional<PermissioningConfiguration> permissioningConfiguration) {
checkNotNull(runnerBuilder);
permissioningConfiguration.ifPresent(runnerBuilder::permissioningConfiguration);
final Runner runner =
runnerBuilder
.vertx(Vertx.vertx())
@ -806,7 +810,6 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
.bannedNodeIds(bannedNodeIds)
.metricsSystem(metricsSystem)
.metricsConfiguration(metricsConfiguration)
.permissioningConfiguration(permissioningConfiguration)
.build();
addShutdownHook(runner);

@ -33,7 +33,7 @@ public class PermissioningConfigurationValidator {
final List<Peer> bootnodes =
DiscoveryConfiguration.getBootstrapPeersFromGenericCollection(
ethNetworkConfig.getBootNodes());
if (permissioningConfiguration.isNodeWhitelistSet() && bootnodes != null) {
if (permissioningConfiguration.isNodeWhitelistEnabled() && bootnodes != null) {
bootnodesNotInWhitelist =
bootnodes
.stream()

@ -57,10 +57,10 @@ public class PermissioningConfigurationBuilderTest {
PermissioningConfigurationBuilder.permissioningConfiguration(
toml.toAbsolutePath().toString(), true, true);
assertThat(permissioningConfiguration.isAccountWhitelistSet()).isTrue();
assertThat(permissioningConfiguration.isAccountWhitelistEnabled()).isTrue();
assertThat(permissioningConfiguration.getAccountWhitelist())
.containsExactly("0x0000000000000000000000000000000000000009");
assertThat(permissioningConfiguration.isNodeWhitelistSet()).isTrue();
assertThat(permissioningConfiguration.isNodeWhitelistEnabled()).isTrue();
assertThat(permissioningConfiguration.getNodeWhitelist())
.containsExactly(URI.create(uri), URI.create(uri2));
}
@ -78,8 +78,8 @@ public class PermissioningConfigurationBuilderTest {
PermissioningConfigurationBuilder.permissioningConfiguration(
toml.toAbsolutePath().toString(), true, false);
assertThat(permissioningConfiguration.isAccountWhitelistSet()).isFalse();
assertThat(permissioningConfiguration.isNodeWhitelistSet()).isTrue();
assertThat(permissioningConfiguration.isAccountWhitelistEnabled()).isFalse();
assertThat(permissioningConfiguration.isNodeWhitelistEnabled()).isTrue();
assertThat(permissioningConfiguration.getNodeWhitelist()).containsExactly(URI.create(uri));
}
@ -94,8 +94,8 @@ public class PermissioningConfigurationBuilderTest {
PermissioningConfigurationBuilder.permissioningConfiguration(
toml.toAbsolutePath().toString(), false, true);
assertThat(permissioningConfiguration.isNodeWhitelistSet()).isFalse();
assertThat(permissioningConfiguration.isAccountWhitelistSet()).isTrue();
assertThat(permissioningConfiguration.isNodeWhitelistEnabled()).isFalse();
assertThat(permissioningConfiguration.isAccountWhitelistEnabled()).isTrue();
assertThat(permissioningConfiguration.getAccountWhitelist())
.containsExactly("0x0000000000000000000000000000000000000009");
}
@ -127,9 +127,9 @@ public class PermissioningConfigurationBuilderTest {
PermissioningConfigurationBuilder.permissioningConfiguration(
toml.toAbsolutePath().toString(), true, true);
assertThat(permissioningConfiguration.isNodeWhitelistSet()).isTrue();
assertThat(permissioningConfiguration.isNodeWhitelistEnabled()).isTrue();
assertThat(permissioningConfiguration.getNodeWhitelist()).isEmpty();
assertThat(permissioningConfiguration.isAccountWhitelistSet()).isTrue();
assertThat(permissioningConfiguration.isAccountWhitelistEnabled()).isTrue();
assertThat(permissioningConfiguration.getAccountWhitelist()).isEmpty();
}
@ -144,9 +144,9 @@ public class PermissioningConfigurationBuilderTest {
PermissioningConfigurationBuilder.permissioningConfiguration(
toml.toAbsolutePath().toString(), true, true);
assertThat(permissioningConfiguration.isNodeWhitelistSet()).isTrue();
assertThat(permissioningConfiguration.isNodeWhitelistEnabled()).isTrue();
assertThat(permissioningConfiguration.getNodeWhitelist()).isEmpty();
assertThat(permissioningConfiguration.isAccountWhitelistSet()).isTrue();
assertThat(permissioningConfiguration.isAccountWhitelistEnabled()).isTrue();
assertThat(permissioningConfiguration.getAccountWhitelist()).isEmpty();
}
@ -163,9 +163,9 @@ public class PermissioningConfigurationBuilderTest {
assertThat(permissioningConfiguration.getConfigurationFilePath()).isEqualTo(toml.toString());
assertThat(permissioningConfiguration.isNodeWhitelistSet()).isTrue();
assertThat(permissioningConfiguration.isNodeWhitelistEnabled()).isTrue();
assertThat(permissioningConfiguration.getNodeWhitelist()).isEmpty();
assertThat(permissioningConfiguration.isAccountWhitelistSet()).isTrue();
assertThat(permissioningConfiguration.isAccountWhitelistEnabled()).isTrue();
assertThat(permissioningConfiguration.getAccountWhitelist()).isEmpty();
}
}

@ -81,7 +81,9 @@ public abstract class CommandTestAbstract {
@Captor ArgumentCaptor<JsonRpcConfiguration> jsonRpcConfigArgumentCaptor;
@Captor ArgumentCaptor<WebSocketConfiguration> wsRpcConfigArgumentCaptor;
@Captor ArgumentCaptor<MetricsConfiguration> metricsConfigArgumentCaptor;
@Captor ArgumentCaptor<PermissioningConfiguration> permissioningConfigurationArgumentCaptor;
@Captor ArgumentCaptor<Collection<URI>> uriListArgumentCaptor;
@Rule public final TemporaryFolder temp = new TemporaryFolder();
@ -118,7 +120,6 @@ public abstract class CommandTestAbstract {
when(mockRunnerBuilder.p2pEnabled(anyBoolean())).thenReturn(mockRunnerBuilder);
when(mockRunnerBuilder.jsonRpcConfiguration(any())).thenReturn(mockRunnerBuilder);
when(mockRunnerBuilder.webSocketConfiguration(any())).thenReturn(mockRunnerBuilder);
when(mockRunnerBuilder.permissioningConfiguration(any())).thenReturn(mockRunnerBuilder);
when(mockRunnerBuilder.dataDir(any())).thenReturn(mockRunnerBuilder);
when(mockRunnerBuilder.bannedNodeIds(any())).thenReturn(mockRunnerBuilder);
when(mockRunnerBuilder.metricsSystem(any())).thenReturn(mockRunnerBuilder);

Loading…
Cancel
Save