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

[PRIV-41] Refactor PrivacyParameters config to use builder pattern #1226

Merged
merged 5 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion acceptance-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
testImplementation project(':consensus:clique')
testImplementation project(':consensus:ibft')
testImplementation project(':crypto')
testImplementation project(':enclave')
testImplementation project(':ethereum:eth')
testImplementation project(':ethereum:core')
testImplementation project(':ethereum:blockcreation')
Expand All @@ -28,9 +29,9 @@ dependencies {
testImplementation project(':ethereum:rlp')
testImplementation project(':metrics')
testImplementation project(':pantheon')
testImplementation project(':services:kvstore')
testImplementation project(':testutil')
testImplementation project(':util')
testImplementation project(':enclave')
testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')

testImplementation 'com.google.guava:guava'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void startNode(final PantheonNode node) {
if (node.getPrivacyParameters().isEnabled()) {
params.add("--privacy-enabled");
params.add("--privacy-url");
params.add(node.getPrivacyParameters().getUrl());
params.add(node.getPrivacyParameters().getEnclaveUri().toString());
params.add("--privacy-public-key-file");
params.add(node.getPrivacyParameters().getEnclavePublicKeyFile().getAbsolutePath());
params.add("--privacy-precompiled-address");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -34,6 +36,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import com.google.common.io.Files;
import io.vertx.core.Vertx;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -57,6 +60,7 @@ public void startNode(final PantheonNode node) {
.setBootNodes(node.getConfiguration().bootnodes());
node.getConfiguration().getGenesisConfig().ifPresent(networkConfigBuilder::setGenesisConfig);
final EthNetworkConfig ethNetworkConfig = networkConfigBuilder.build();
final Path tempDir = Files.createTempDir().toPath();

final PantheonController<?> pantheonController;
try {
Expand All @@ -71,6 +75,7 @@ public void startNode(final PantheonNode node) {
.nodePrivateKeyFile(KeyPairUtil.getDefaultKeyFile(node.homeDirectory()))
.metricsSystem(noOpMetricsSystem)
.maxPendingTransactions(PendingTransactions.MAX_PENDING_TRANSACTIONS)
.rocksDbConfiguration(new RocksDbConfiguration.Builder().databaseDir(tempDir).build())
.build();
} catch (final IOException e) {
throw new RuntimeException("Error building PantheonController", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class PantheonFactoryConfigurationBuilder {
private String name;
private MiningParameters miningParameters =
new MiningParametersTestBuilder().enabled(false).build();
private PrivacyParameters privacyParameters = PrivacyParameters.noPrivacy();
private PrivacyParameters privacyParameters = PrivacyParameters.DEFAULT;
private JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault();
private WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault();
private MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,11 @@ public String build(final TransactionType type) {
}

static PrivacyParameters getPrivacyParams(final OrionTestHarness testHarness) throws IOException {
final PrivacyParameters privacyParameters = new PrivacyParameters();
privacyParameters.setEnabled(true);
privacyParameters.setUrl(testHarness.clientUrl());
privacyParameters.setPrivacyAddress(Address.PRIVACY);
privacyParameters.setEnclavePublicKeyUsingFile(
testHarness.getConfig().publicKeys().get(0).toFile());
privacyParameters.enablePrivateDB(privacy.newFolder().toPath());
return privacyParameters;
return new PrivacyParameters.Builder()
.setEnabled(true)
.setEnclaveUrl(testHarness.clientUrl())
.setEnclavePublicKeyUsingFile(testHarness.getConfig().publicKeys().get(0).toFile())
.setDataDir(privacy.newFolder().toPath())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public static ProtocolSchedule<CliqueContext> create(
.createProtocolSchedule();
}

public static ProtocolSchedule<CliqueContext> create(
final GenesisConfigOptions config, final KeyPair nodeKeys) {
return create(config, nodeKeys, PrivacyParameters.DEFAULT);
}

private static ProtocolSpecBuilder<CliqueContext> applyCliqueSpecificModifications(
final EpochManager epochManager,
final long secondsBetweenBlocks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.config.GenesisConfigOptions;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec;
Expand All @@ -42,7 +41,7 @@ public void protocolSpecsAreCreatedAtBlockDefinedInJson() {

final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions();
final ProtocolSchedule<CliqueContext> protocolSchedule =
CliqueProtocolSchedule.create(config, NODE_KEYS, PrivacyParameters.noPrivacy());
CliqueProtocolSchedule.create(config, NODE_KEYS);

final ProtocolSpec<CliqueContext> homesteadSpec = protocolSchedule.getByBlockNumber(1);
final ProtocolSpec<CliqueContext> tangerineWhistleSpec = protocolSchedule.getByBlockNumber(2);
Expand All @@ -57,10 +56,7 @@ public void protocolSpecsAreCreatedAtBlockDefinedInJson() {
@Test
public void parametersAlignWithMainnetWithAdjustments() {
final ProtocolSpec<CliqueContext> homestead =
CliqueProtocolSchedule.create(
GenesisConfigFile.DEFAULT.getConfigOptions(),
NODE_KEYS,
PrivacyParameters.noPrivacy())
CliqueProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions(), NODE_KEYS)
.getByBlockNumber(0);

assertThat(homestead.getName()).isEqualTo("Frontier");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import tech.pegasys.pantheon.ethereum.core.BlockBody;
import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.core.Util;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
Expand Down Expand Up @@ -76,9 +75,7 @@ public class CliqueBlockCreatorTest {
public void setup() {
protocolSchedule =
CliqueProtocolSchedule.create(
GenesisConfigFile.DEFAULT.getConfigOptions(),
proposerKeyPair,
PrivacyParameters.noPrivacy());
GenesisConfigFile.DEFAULT.getConfigOptions(), proposerKeyPair);

final Address otherAddress = Util.publicKeyToAddress(otherKeyPair.getPublicKey());
validatorList.add(otherAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture;
import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.core.Util;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.metrics.MetricsSystem;
Expand Down Expand Up @@ -90,8 +89,7 @@ public void extraDataCreatedOnEpochBlocksContainsValidators() {
new CliqueMinerExecutor(
cliqueProtocolContext,
Executors.newSingleThreadExecutor(),
CliqueProtocolSchedule.create(
GENESIS_CONFIG_OPTIONS, proposerKeyPair, PrivacyParameters.noPrivacy()),
CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerKeyPair),
new PendingTransactions(1, TestClock.fixed(), metricsSystem),
proposerKeyPair,
new MiningParameters(AddressHelpers.ofValue(1), Wei.ZERO, wrappedVanityData, false),
Expand Down Expand Up @@ -121,8 +119,7 @@ public void extraDataForNonEpochBlocksDoesNotContainValidaors() {
new CliqueMinerExecutor(
cliqueProtocolContext,
Executors.newSingleThreadExecutor(),
CliqueProtocolSchedule.create(
GENESIS_CONFIG_OPTIONS, proposerKeyPair, PrivacyParameters.noPrivacy()),
CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerKeyPair),
new PendingTransactions(1, TestClock.fixed(), metricsSystem),
proposerKeyPair,
new MiningParameters(AddressHelpers.ofValue(1), Wei.ZERO, wrappedVanityData, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.core.Util;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
Expand Down Expand Up @@ -262,7 +261,7 @@ private static ControllerAndState createControllerAndFinalState(
genesisConfigOptions.byzantiumBlock(0);

final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(genesisConfigOptions, PrivacyParameters.noPrivacy());
IbftProtocolSchedule.create(genesisConfigOptions);

/////////////////////////////////////////////////////////////////////////////////////
// From here down is BASICALLY taken from IbftPantheonController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public static ProtocolSchedule<IbftContext> create(
.createProtocolSchedule();
}

public static ProtocolSchedule<IbftContext> create(final GenesisConfigOptions config) {
return create(config, PrivacyParameters.DEFAULT);
}

private static ProtocolSpecBuilder<IbftContext> applyIbftChanges(
final long secondsBetweenBlocks, final ProtocolSpecBuilder<Void> builder) {
return builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.BlockHeaderValidator;
import tech.pegasys.pantheon.ethereum.mainnet.HeaderValidationMode;
Expand Down Expand Up @@ -75,8 +74,7 @@ public void createdBlockPassesValidationRulesAndHasAppropriateHashAndMixHash() {
final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(
GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}")
.getConfigOptions(),
PrivacyParameters.noPrivacy());
.getConfigOptions());
final ProtocolContext<IbftContext> protContext =
new ProtocolContext<>(
blockchain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public static ProtocolSchedule<IbftContext> create(
.createProtocolSchedule();
}

public static ProtocolSchedule<IbftContext> create(final GenesisConfigOptions config) {
return create(config, PrivacyParameters.DEFAULT);
}

private static ProtocolSpecBuilder<IbftContext> applyIbftChanges(
final long secondsBetweenBlocks, final ProtocolSpecBuilder<Void> builder) {
return builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture;
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.BlockHeaderValidator;
import tech.pegasys.pantheon.ethereum.mainnet.HeaderValidationMode;
Expand Down Expand Up @@ -81,8 +80,7 @@ public void headerProducedPassesValidationRules() {
final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(
GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}")
.getConfigOptions(),
PrivacyParameters.noPrivacy());
.getConfigOptions());
final ProtocolContext<IbftContext> protContext =
new ProtocolContext<>(
blockchain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import tech.pegasys.pantheon.enclave.types.SendResponse;

import java.io.IOException;
import java.net.URI;
import java.util.List;

import com.google.common.collect.Lists;
Expand Down Expand Up @@ -81,7 +82,7 @@ public void testSendAndReceive() throws IOException {

@Test(expected = IOException.class)
public void whenUpCheckFailsThrows() throws IOException {
Enclave broken = new Enclave("http:");
Enclave broken = new Enclave(URI.create("http://null"));

broken.upCheck();
}
Expand Down
14 changes: 8 additions & 6 deletions enclave/src/main/java/tech/pegasys/pantheon/enclave/Enclave.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tech.pegasys.pantheon.enclave.types.SendResponse;

import java.io.IOException;
import java.net.URI;

import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.MediaType;
Expand All @@ -34,16 +35,17 @@ public class Enclave {
private static final MediaType JSON = MediaType.parse("application/json");
private static final MediaType ORION = MediaType.get("application/vnd.orion.v1+json");

private final String url;
private final URI enclaveUri;
private final OkHttpClient client;

public Enclave(final String enclaveUrl) {
this.url = enclaveUrl;
public Enclave(final URI enclaveUri) {
this.enclaveUri = enclaveUri;
this.client = new OkHttpClient();
}

public Boolean upCheck() throws IOException {
Request request = new Request.Builder().url(url + "/upcheck").get().build();
String url = enclaveUri.resolve("/upcheck").toString();
Request request = new Request.Builder().url(url).get().build();

try (Response response = client.newCall(request).execute()) {
return response.isSuccessful();
Expand All @@ -55,7 +57,6 @@ public Boolean upCheck() throws IOException {

public SendResponse send(final SendRequest content) throws IOException {
Request request = buildPostRequest(JSON, content, "/send");

return executePost(request, SendResponse.class);
}

Expand All @@ -67,7 +68,8 @@ public ReceiveResponse receive(final ReceiveRequest content) throws IOException
private Request buildPostRequest(
final MediaType mediaType, final Object content, final String endpoint) throws IOException {
RequestBody body = RequestBody.create(mediaType, objectMapper.writeValueAsString(content));
return new Request.Builder().url(url + endpoint).post(body).build();
String url = enclaveUri.resolve(endpoint).toString();
return new Request.Builder().url(url).post(body).build();
}

private <T> T executePost(final Request request, final Class<T> responseType) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.core.LogSeries;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.core.ProcessableBlockHeader;
import tech.pegasys.pantheon.ethereum.core.Transaction;
import tech.pegasys.pantheon.ethereum.core.TransactionReceipt;
Expand Down Expand Up @@ -68,8 +67,7 @@ public class BlockTransactionSelectorTest {
@Test
public void emptyPendingTransactionsResultsInEmptyVettingResult() {
final ProtocolSchedule<Void> protocolSchedule =
FixedDifficultyProtocolSchedule.create(
GenesisConfigFile.development().getConfigOptions(), PrivacyParameters.noPrivacy());
FixedDifficultyProtocolSchedule.create(GenesisConfigFile.development().getConfigOptions());
final Blockchain blockchain = new TestBlockchain();
final TransactionProcessor transactionProcessor =
protocolSchedule.getByBlockNumber(0).getTransactionProcessor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class EthHashBlockCreatorTest {
GenesisConfigFile.DEFAULT.getConfigOptions(),
42,
Function.identity(),
PrivacyParameters.noPrivacy())
PrivacyParameters.DEFAULT)
.createProtocolSchedule())
.build();

Expand Down
Loading