Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into use-txpool-prefix-and-group
Browse files Browse the repository at this point in the history
  • Loading branch information
rojotek authored Mar 18, 2019
2 parents a8d54e7 + e2928a4 commit 5f60b09
Show file tree
Hide file tree
Showing 33 changed files with 408 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import tech.pegasys.pantheon.ethereum.core.Util;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition;
import tech.pegasys.pantheon.tests.acceptance.dsl.httptransaction.HttpRequestFactory;
Expand Down Expand Up @@ -83,7 +83,7 @@ public class PantheonNode implements NodeConfiguration, RunnableNode, AutoClosea
private final JsonRpcConfiguration jsonRpcConfiguration;
private final WebSocketConfiguration webSocketConfiguration;
private final MetricsConfiguration metricsConfiguration;
private final Optional<LocalPermissioningConfiguration> permissioningConfiguration;
private final Optional<PermissioningConfiguration> permissioningConfiguration;
private final GenesisConfigProvider genesisConfigProvider;
private final boolean devMode;
private final boolean discoveryEnabled;
Expand All @@ -103,7 +103,7 @@ public PantheonNode(
final JsonRpcConfiguration jsonRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
final MetricsConfiguration metricsConfiguration,
final Optional<LocalPermissioningConfiguration> permissioningConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
final boolean devMode,
final GenesisConfigProvider genesisConfigProvider,
final boolean p2pEnabled,
Expand Down Expand Up @@ -472,7 +472,7 @@ public boolean isDiscoveryEnabled() {
return discoveryEnabled;
}

Optional<LocalPermissioningConfiguration> getPermissioningConfiguration() {
Optional<PermissioningConfiguration> getPermissioningConfiguration() {
return permissioningConfiguration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -145,6 +146,7 @@ public void startNode(final PantheonNode node) {
}

node.getPermissioningConfiguration()
.flatMap(PermissioningConfiguration::getLocalConfig)
.ifPresent(
permissioningConfiguration -> {
if (permissioningConfiguration.isNodeWhitelistEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.GenesisConfigProvider;

Expand All @@ -30,7 +30,7 @@ class PantheonFactoryConfiguration {
private final JsonRpcConfiguration jsonRpcConfiguration;
private final WebSocketConfiguration webSocketConfiguration;
private final MetricsConfiguration metricsConfiguration;
private final Optional<LocalPermissioningConfiguration> permissioningConfiguration;
private final Optional<PermissioningConfiguration> permissioningConfiguration;
private final boolean devMode;
private final GenesisConfigProvider genesisConfigProvider;
private final boolean p2pEnabled;
Expand All @@ -44,7 +44,7 @@ class PantheonFactoryConfiguration {
final JsonRpcConfiguration jsonRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
final MetricsConfiguration metricsConfiguration,
final Optional<LocalPermissioningConfiguration> permissioningConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
final boolean devMode,
final GenesisConfigProvider genesisConfigProvider,
final boolean p2pEnabled,
Expand Down Expand Up @@ -88,7 +88,7 @@ public MetricsConfiguration getMetricsConfiguration() {
return metricsConfiguration;
}

public Optional<LocalPermissioningConfiguration> getPermissioningConfiguration() {
public Optional<PermissioningConfiguration> getPermissioningConfiguration() {
return permissioningConfiguration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.GenesisConfigProvider;

Expand All @@ -38,7 +38,7 @@ public class PantheonFactoryConfigurationBuilder {
private JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault();
private WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault();
private MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault();
private Optional<LocalPermissioningConfiguration> permissioningConfiguration = Optional.empty();
private Optional<PermissioningConfiguration> permissioningConfiguration = Optional.empty();
private boolean devMode = true;
private GenesisConfigProvider genesisConfigProvider = ignore -> Optional.empty();
private Boolean p2pEnabled = true;
Expand Down Expand Up @@ -137,7 +137,7 @@ public PantheonFactoryConfigurationBuilder webSocketAuthenticationEnabled()
}

public PantheonFactoryConfigurationBuilder setPermissioningConfiguration(
final LocalPermissioningConfiguration permissioningConfiguration) {
final PermissioningConfiguration permissioningConfiguration) {
this.permissioningConfiguration = Optional.of(permissioningConfiguration);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.WhitelistPersistor;
import tech.pegasys.pantheon.ethereum.permissioning.WhitelistPersistor.WHITELIST_TYPE;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.GenesisConfigProvider;
Expand Down Expand Up @@ -183,11 +184,15 @@ public PantheonNode createNodeWithWhitelistsEnabled(
final List<String> accountsWhitelist,
final String tempFilePath)
throws IOException {
final LocalPermissioningConfiguration permissioningConfiguration =
final LocalPermissioningConfiguration localPermissioningConfiguration =
LocalPermissioningConfiguration.createDefault();
permissioningConfiguration.setNodeWhitelist(nodesWhitelist);
permissioningConfiguration.setAccountWhitelist(accountsWhitelist);
permissioningConfiguration.setConfigurationFilePath(tempFilePath);
localPermissioningConfiguration.setNodeWhitelist(nodesWhitelist);
localPermissioningConfiguration.setAccountWhitelist(accountsWhitelist);
localPermissioningConfiguration.setConfigurationFilePath(tempFilePath);

final PermissioningConfiguration permissioningConfiguration =
new PermissioningConfiguration(
Optional.of(localPermissioningConfiguration), Optional.empty());

return create(
new PantheonFactoryConfigurationBuilder()
Expand All @@ -204,18 +209,22 @@ public PantheonNode createNodeWithNodesWhitelist(

public PantheonNode createNodeWithNodesWhitelist(
final String name, final List<URI> nodesWhitelist) throws IOException {
final LocalPermissioningConfiguration permissioningConfiguration =
final LocalPermissioningConfiguration localPermissioningConfiguration =
LocalPermissioningConfiguration.createDefault();
permissioningConfiguration.setNodeWhitelist(nodesWhitelist);
localPermissioningConfiguration.setNodeWhitelist(nodesWhitelist);

final List<String> whitelistAsStrings =
nodesWhitelist.parallelStream().map(URI::toString).collect(toList());
final File tempFile = createTempPermissioningConfigurationFile();
tempFile.deleteOnExit();
permissioningConfiguration.setConfigurationFilePath(tempFile.getPath());
localPermissioningConfiguration.setConfigurationFilePath(tempFile.getPath());
initPermissioningConfigurationFile(
WhitelistPersistor.WHITELIST_TYPE.NODES, whitelistAsStrings, tempFile.toPath());

final PermissioningConfiguration permissioningConfiguration =
new PermissioningConfiguration(
Optional.of(localPermissioningConfiguration), Optional.empty());

return create(
new PantheonFactoryConfigurationBuilder()
.setName(name)
Expand All @@ -241,18 +250,22 @@ private void initPermissioningConfigurationFile(

public PantheonNode createNodeWithAccountsWhitelist(
final String name, final List<String> accountsWhitelist) throws IOException {
final LocalPermissioningConfiguration permissioningConfiguration =
final LocalPermissioningConfiguration localPermissioningConfiguration =
LocalPermissioningConfiguration.createDefault();
permissioningConfiguration.setAccountWhitelist(accountsWhitelist);
permissioningConfiguration.setConfigurationFilePath(
localPermissioningConfiguration.setAccountWhitelist(accountsWhitelist);
localPermissioningConfiguration.setConfigurationFilePath(
createTempPermissioningConfigurationFile().getPath());

final File tempFile = createTempPermissioningConfigurationFile();
tempFile.deleteOnExit();
permissioningConfiguration.setConfigurationFilePath(tempFile.getPath());
localPermissioningConfiguration.setConfigurationFilePath(tempFile.getPath());
initPermissioningConfigurationFile(
WHITELIST_TYPE.ACCOUNTS, accountsWhitelist, tempFile.toPath());

final PermissioningConfiguration permissioningConfiguration =
new PermissioningConfiguration(
Optional.of(localPermissioningConfiguration), Optional.empty());

return create(
new PantheonFactoryConfigurationBuilder()
.setName(name)
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import net.ltgt.gradle.errorprone.CheckSeverity

plugins {
id 'com.diffplug.gradle.spotless' version '3.17.0'
id 'com.diffplug.gradle.spotless' version '3.19.0'
id 'com.jfrog.bintray' version '1.8.4'
id 'com.github.ben-manes.versions' version '0.20.0'
id 'com.github.ben-manes.versions' version '0.21.0'
id 'com.github.hierynomus.license' version '0.15.0'
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.7.RELEASE'
id 'me.champeau.gradle.jmh' version '0.4.8' apply false
id 'net.ltgt.errorprone' version '0.6.1'
id 'net.researchgate.release' version '2.7.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;

public class WorldStateDownloaderTest {

@Rule public Timeout globalTimeout = Timeout.seconds(60); // 1 minute max per test

private static final Hash EMPTY_TRIE_ROOT = Hash.wrap(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH);

private final BlockDataGenerator dataGen = new BlockDataGenerator(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public TestNode(
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Optional.empty()))
.metricsSystem(new NoOpMetricsSystem())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController;
import tech.pegasys.pantheon.util.NetworkUtility;
import tech.pegasys.pantheon.util.Subscribers;
import tech.pegasys.pantheon.util.bytes.BytesValue;
Expand Down Expand Up @@ -71,6 +72,7 @@ public abstract class PeerDiscoveryAgent implements DisconnectCallback {
private final PeerRequirement peerRequirement;
private final PeerBlacklist peerBlacklist;
private final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController;
private final Optional<NodePermissioningController> nodePermissioningController;
/* The peer controller, which takes care of the state machine of peers. */
protected Optional<PeerDiscoveryController> controller = Optional.empty();

Expand All @@ -93,7 +95,8 @@ public PeerDiscoveryAgent(
final DiscoveryConfiguration config,
final PeerRequirement peerRequirement,
final PeerBlacklist peerBlacklist,
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController) {
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController,
final Optional<NodePermissioningController> nodePermissioningController) {
checkArgument(keyPair != null, "keypair cannot be null");
checkArgument(config != null, "provided configuration cannot be null");

Expand All @@ -102,6 +105,7 @@ public PeerDiscoveryAgent(
this.peerRequirement = peerRequirement;
this.peerBlacklist = peerBlacklist;
this.nodeWhitelistController = nodeWhitelistController;
this.nodePermissioningController = nodePermissioningController;
this.bootstrapPeers =
config.getBootstrapPeers().stream().map(DiscoveryPeer::new).collect(Collectors.toList());

Expand Down Expand Up @@ -164,6 +168,7 @@ private PeerDiscoveryController createController() {
peerRequirement,
peerBlacklist,
nodeWhitelistController,
nodePermissioningController,
peerBondedObservers,
peerDroppedObservers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import tech.pegasys.pantheon.ethereum.p2p.peers.Endpoint;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController;
import tech.pegasys.pantheon.util.NetworkUtility;
import tech.pegasys.pantheon.util.Preconditions;

Expand Down Expand Up @@ -58,8 +59,15 @@ public VertxPeerDiscoveryAgent(
final DiscoveryConfiguration config,
final PeerRequirement peerRequirement,
final PeerBlacklist peerBlacklist,
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController) {
super(keyPair, config, peerRequirement, peerBlacklist, nodeWhitelistController);
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController,
final Optional<NodePermissioningController> nodePermissioningController) {
super(
keyPair,
config,
peerRequirement,
peerBlacklist,
nodeWhitelistController,
nodePermissioningController);
checkArgument(vertx != null, "vertx instance cannot be null");
this.vertx = vertx;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import tech.pegasys.pantheon.ethereum.permissioning.node.NodeWhitelistUpdatedEvent;
import tech.pegasys.pantheon.util.Subscribers;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.enode.EnodeURL;

import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -118,6 +119,7 @@ public class PeerDiscoveryController {
private final OutboundMessageHandler outboundMessageHandler;
private final PeerBlacklist peerBlacklist;
private final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController;
private final Optional<NodePermissioningController> nodePermissioningController;

private RetryDelayFunction retryDelayFunction = RetryDelayFunction.linear(1.5, 2000, 60000);

Expand All @@ -136,9 +138,6 @@ public class PeerDiscoveryController {

private RecursivePeerRefreshState recursivePeerRefreshState;

private final Optional<NodePermissioningController> nodePermissioningController =
Optional.empty();

public PeerDiscoveryController(
final KeyPair keypair,
final DiscoveryPeer localPeer,
Expand All @@ -151,6 +150,7 @@ public PeerDiscoveryController(
final PeerRequirement peerRequirement,
final PeerBlacklist peerBlacklist,
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController,
final Optional<NodePermissioningController> nodePermissioningController,
final Subscribers<Consumer<PeerBondedEvent>> peerBondedObservers,
final Subscribers<Consumer<PeerDroppedEvent>> peerDroppedObservers) {
this.timerUtil = timerUtil;
Expand All @@ -163,6 +163,7 @@ public PeerDiscoveryController(
this.peerRequirement = peerRequirement;
this.peerBlacklist = peerBlacklist;
this.nodeWhitelistController = nodeWhitelistController;
this.nodePermissioningController = nodePermissioningController;
this.outboundMessageHandler = outboundMessageHandler;
this.peerBondedObservers = peerBondedObservers;
this.peerDroppedObservers = peerDroppedObservers;
Expand All @@ -173,25 +174,23 @@ public void start() {
throw new IllegalStateException("The peer table had already been started");
}

bootstrapNodes.stream()
.filter(this::whitelistIfPresentIsNodePermitted)
.forEach(peerTable::tryAdd);
bootstrapNodes.stream().filter(p -> isPeerPermitted(localPeer, p)).forEach(peerTable::tryAdd);

recursivePeerRefreshState =
new RecursivePeerRefreshState(
peerBlacklist,
nodeWhitelistController,
nodePermissioningController,
this::bond,
this::findNodes,
timerUtil,
localPeer.getId(),
localPeer,
peerTable,
PEER_REFRESH_ROUND_TIMEOUT_IN_SECONDS,
100);

final List<DiscoveryPeer> initialDiscoveryPeers =
bootstrapNodes.stream()
.filter(this::whitelistIfPresentIsNodePermitted)
.filter(p -> isPeerPermitted(localPeer, p))
.collect(Collectors.toList());

if (nodePermissioningController.isPresent()) {
Expand Down Expand Up @@ -225,9 +224,13 @@ public CompletableFuture<?> stop() {
return CompletableFuture.completedFuture(null);
}

private boolean whitelistIfPresentIsNodePermitted(final DiscoveryPeer sender) {
return nodeWhitelistController
.map(nodeWhitelistController -> nodeWhitelistController.isPermitted(sender.getEnodeURI()))
private boolean isPeerPermitted(final Peer sourcePeer, final Peer destinationPeer) {
return nodePermissioningController
.map(
c ->
c.isPermitted(
new EnodeURL(sourcePeer.getEnodeURI()),
new EnodeURL(destinationPeer.getEnodeURI())))
.orElse(true);
}

Expand All @@ -250,7 +253,7 @@ public void onMessage(final Packet packet, final DiscoveryPeer sender) {
return;
}

if (!whitelistIfPresentIsNodePermitted(sender)) {
if (!isPeerPermitted(sender, localPeer)) {
LOG.trace("Dropping packet from peer not in the whitelist ({})", sender.getEnodeURI());
return;
}
Expand Down
Loading

0 comments on commit 5f60b09

Please sign in to comment.