From 312ddc22b768276f9849b0712a48372f9836c880 Mon Sep 17 00:00:00 2001 From: Antony Denyer Date: Fri, 5 Apr 2019 16:07:00 +0100 Subject: [PATCH 1/4] [PRIV-41] Use metrics system for private state db - Use PrivacyParametersBuilder to build PrivacyParameters - refactor PrivacyParameters to expose default options - refactor test builders to use PrivacyParameters.DEFAULT - Use URI in Enclave --- .../dsl/node/ProcessPantheonNodeRunner.java | 2 +- .../PantheonFactoryConfigurationBuilder.java | 2 +- .../privacy/PrivateAcceptanceTestBase.java | 15 ++- .../clique/CliqueProtocolSchedule.java | 5 + .../clique/CliqueProtocolScheduleTest.java | 8 +- .../blockcreation/CliqueBlockCreatorTest.java | 5 +- .../CliqueMinerExecutorTest.java | 7 +- .../ibft/support/TestContextBuilder.java | 3 +- .../consensus/ibft/IbftProtocolSchedule.java | 4 + .../blockcreation/IbftBlockCreatorTest.java | 4 +- .../ibftlegacy/IbftProtocolSchedule.java | 4 + .../blockcreation/IbftBlockCreatorTest.java | 4 +- .../pegasys/pantheon/enclave/EnclaveTest.java | 3 +- .../pegasys/pantheon/enclave/Enclave.java | 11 +- .../BlockTransactionSelectorTest.java | 4 +- .../EthHashBlockCreatorTest.java | 2 +- .../ethereum/core/PrivacyParameters.java | 117 ++++++++---------- .../core/PrivacyParametersBuilder.java | 110 ++++++++++++++++ .../FixedDifficultyProtocolSchedule.java | 4 + .../mainnet/MainnetProtocolSchedule.java | 14 ++- .../privacy/PrivacyPrecompiledContract.java | 2 +- .../privacy/PrivateTransactionHandler.java | 2 +- .../core/ExecutionContextTestFixture.java | 2 +- .../fixed/FixedProtocolScheduleTest.java | 2 +- .../mainnet/MainnetProtocolScheduleTest.java | 11 +- .../vm/ReferenceTestProtocolSchedules.java | 2 +- .../pantheon/ethereum/vm/VMReferenceTest.java | 2 +- ...stantinopleSStoreOperationGasCostTest.java | 4 +- .../eth/messages/BlockBodiesMessageTest.java | 4 +- .../eth/messages/BlockHeadersMessageTest.java | 3 +- .../eth/sync/ChainHeadTrackerTest.java | 4 +- .../ethereum/eth/transactions/TestNode.java | 4 +- .../ethereum/jsonrpc/BlockchainImporter.java | 4 +- .../jsonrpc/JsonRpcMethodsFactory.java | 2 +- .../JsonRpcHttpServiceHostWhitelistTest.java | 3 +- .../jsonrpc/JsonRpcHttpServiceLoginTest.java | 3 +- .../jsonrpc/JsonRpcHttpServiceTest.java | 3 +- .../pegasys/pantheon/cli/PantheonCommand.java | 16 +-- .../tech/pegasys/pantheon/PrivacyTest.java | 11 +- .../tech/pegasys/pantheon/RunnerTest.java | 6 +- .../pantheon/cli/PantheonCommandTest.java | 2 +- .../pantheon/util/BlockImporterTest.java | 4 +- .../orion/testutil/OrionTestHarness.java | 19 +-- 43 files changed, 264 insertions(+), 179 deletions(-) create mode 100644 ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParametersBuilder.java diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java index e2b07647af..a0ddc7f56e 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java @@ -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"); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonFactoryConfigurationBuilder.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonFactoryConfigurationBuilder.java index df5710f22c..691acc5fbb 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonFactoryConfigurationBuilder.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonFactoryConfigurationBuilder.java @@ -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(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateAcceptanceTestBase.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateAcceptanceTestBase.java index a4098a737a..3eb3a4bd2e 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateAcceptanceTestBase.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateAcceptanceTestBase.java @@ -17,6 +17,7 @@ import tech.pegasys.pantheon.crypto.SECP256K1; import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; +import tech.pegasys.pantheon.ethereum.core.PrivacyParametersBuilder; import tech.pegasys.pantheon.ethereum.privacy.PrivateTransaction; import tech.pegasys.pantheon.ethereum.rlp.RLP; import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; @@ -120,13 +121,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 PrivacyParametersBuilder() + .setEnabled(true) + .setEnclaveUrl(testHarness.clientUrl()) + .setEnclavePublicKeyUsingFile(testHarness.getConfig().publicKeys().get(0).toFile()) + .setDataDir(privacy.newFolder().toPath()) + .build(); } } diff --git a/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolSchedule.java b/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolSchedule.java index 56d0748ee4..eb96d72a1a 100644 --- a/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolSchedule.java +++ b/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolSchedule.java @@ -54,6 +54,11 @@ public static ProtocolSchedule create( .createProtocolSchedule(); } + public static ProtocolSchedule create( + final GenesisConfigOptions config, final KeyPair nodeKeys) { + return create(config, nodeKeys, PrivacyParameters.DEFAULT); + } + private static ProtocolSpecBuilder applyCliqueSpecificModifications( final EpochManager epochManager, final long secondsBetweenBlocks, diff --git a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolScheduleTest.java b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolScheduleTest.java index d230246f87..fcec092441 100644 --- a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolScheduleTest.java +++ b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolScheduleTest.java @@ -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; @@ -42,7 +41,7 @@ public void protocolSpecsAreCreatedAtBlockDefinedInJson() { final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions(); final ProtocolSchedule protocolSchedule = - CliqueProtocolSchedule.create(config, NODE_KEYS, PrivacyParameters.noPrivacy()); + CliqueProtocolSchedule.create(config, NODE_KEYS); final ProtocolSpec homesteadSpec = protocolSchedule.getByBlockNumber(1); final ProtocolSpec tangerineWhistleSpec = protocolSchedule.getByBlockNumber(2); @@ -57,10 +56,7 @@ public void protocolSpecsAreCreatedAtBlockDefinedInJson() { @Test public void parametersAlignWithMainnetWithAdjustments() { final ProtocolSpec homestead = - CliqueProtocolSchedule.create( - GenesisConfigFile.DEFAULT.getConfigOptions(), - NODE_KEYS, - PrivacyParameters.noPrivacy()) + CliqueProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions(), NODE_KEYS) .getByBlockNumber(0); assertThat(homestead.getName()).isEqualTo("Frontier"); diff --git a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java index 420cf37d36..cee8cec20b 100644 --- a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java +++ b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java @@ -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; @@ -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); diff --git a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueMinerExecutorTest.java b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueMinerExecutorTest.java index 6a09ada16c..c09f80a84c 100644 --- a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueMinerExecutorTest.java +++ b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueMinerExecutorTest.java @@ -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; @@ -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), @@ -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), diff --git a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextBuilder.java b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextBuilder.java index c6edaf368c..50498d2876 100644 --- a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextBuilder.java +++ b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextBuilder.java @@ -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; @@ -262,7 +261,7 @@ private static ControllerAndState createControllerAndFinalState( genesisConfigOptions.byzantiumBlock(0); final ProtocolSchedule protocolSchedule = - IbftProtocolSchedule.create(genesisConfigOptions, PrivacyParameters.noPrivacy()); + IbftProtocolSchedule.create(genesisConfigOptions); ///////////////////////////////////////////////////////////////////////////////////// // From here down is BASICALLY taken from IbftPantheonController diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftProtocolSchedule.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftProtocolSchedule.java index 4269e09a50..269f857a6e 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftProtocolSchedule.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftProtocolSchedule.java @@ -45,6 +45,10 @@ public static ProtocolSchedule create( .createProtocolSchedule(); } + public static ProtocolSchedule create(final GenesisConfigOptions config) { + return create(config, PrivacyParameters.DEFAULT); + } + private static ProtocolSpecBuilder applyIbftChanges( final long secondsBetweenBlocks, final ProtocolSpecBuilder builder) { return builder diff --git a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/blockcreation/IbftBlockCreatorTest.java b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/blockcreation/IbftBlockCreatorTest.java index 889fa2dbdf..1c09a88aca 100644 --- a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/blockcreation/IbftBlockCreatorTest.java +++ b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/blockcreation/IbftBlockCreatorTest.java @@ -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; @@ -75,8 +74,7 @@ public void createdBlockPassesValidationRulesAndHasAppropriateHashAndMixHash() { final ProtocolSchedule protocolSchedule = IbftProtocolSchedule.create( GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}") - .getConfigOptions(), - PrivacyParameters.noPrivacy()); + .getConfigOptions()); final ProtocolContext protContext = new ProtocolContext<>( blockchain, diff --git a/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/IbftProtocolSchedule.java b/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/IbftProtocolSchedule.java index e1cd8e92d5..ec7064d074 100644 --- a/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/IbftProtocolSchedule.java +++ b/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/IbftProtocolSchedule.java @@ -46,6 +46,10 @@ public static ProtocolSchedule create( .createProtocolSchedule(); } + public static ProtocolSchedule create(final GenesisConfigOptions config) { + return create(config, PrivacyParameters.DEFAULT); + } + private static ProtocolSpecBuilder applyIbftChanges( final long secondsBetweenBlocks, final ProtocolSpecBuilder builder) { return builder diff --git a/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java b/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java index 3f48518a51..d588e92e69 100644 --- a/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java +++ b/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java @@ -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; @@ -81,8 +80,7 @@ public void headerProducedPassesValidationRules() { final ProtocolSchedule protocolSchedule = IbftProtocolSchedule.create( GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}") - .getConfigOptions(), - PrivacyParameters.noPrivacy()); + .getConfigOptions()); final ProtocolContext protContext = new ProtocolContext<>( blockchain, diff --git a/enclave/src/integration-test/java/tech/pegasys/pantheon/enclave/EnclaveTest.java b/enclave/src/integration-test/java/tech/pegasys/pantheon/enclave/EnclaveTest.java index a219675951..c536e03f6a 100644 --- a/enclave/src/integration-test/java/tech/pegasys/pantheon/enclave/EnclaveTest.java +++ b/enclave/src/integration-test/java/tech/pegasys/pantheon/enclave/EnclaveTest.java @@ -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; @@ -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(); } diff --git a/enclave/src/main/java/tech/pegasys/pantheon/enclave/Enclave.java b/enclave/src/main/java/tech/pegasys/pantheon/enclave/Enclave.java index cc262ed7c2..c5d2e242dd 100644 --- a/enclave/src/main/java/tech/pegasys/pantheon/enclave/Enclave.java +++ b/enclave/src/main/java/tech/pegasys/pantheon/enclave/Enclave.java @@ -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; @@ -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 uri; private final OkHttpClient client; - public Enclave(final String enclaveUrl) { - this.url = enclaveUrl; + public Enclave(final URI enclaveUri) { + this.uri = enclaveUri; this.client = new OkHttpClient(); } public Boolean upCheck() throws IOException { - Request request = new Request.Builder().url(url + "/upcheck").get().build(); + String url = uri.resolve("/upcheck").toString(); + Request request = new Request.Builder().url(url).get().build(); try (Response response = client.newCall(request).execute()) { return response.isSuccessful(); @@ -67,6 +69,7 @@ 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)); + String url = uri.resolve(endpoint).toString(); return new Request.Builder().url(url + endpoint).post(body).build(); } diff --git a/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/BlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/BlockTransactionSelectorTest.java index 5df750241c..b7c6d247d6 100644 --- a/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/BlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/BlockTransactionSelectorTest.java @@ -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; @@ -68,8 +67,7 @@ public class BlockTransactionSelectorTest { @Test public void emptyPendingTransactionsResultsInEmptyVettingResult() { final ProtocolSchedule 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(); diff --git a/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashBlockCreatorTest.java index 4a53a940c0..7327e8f8ae 100644 --- a/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashBlockCreatorTest.java @@ -55,7 +55,7 @@ public class EthHashBlockCreatorTest { GenesisConfigFile.DEFAULT.getConfigOptions(), 42, Function.identity(), - PrivacyParameters.noPrivacy()) + PrivacyParameters.DEFAULT) .createProtocolSchedule()) .build(); diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParameters.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParameters.java index 648d26eca6..e9dbaebe23 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParameters.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParameters.java @@ -12,34 +12,22 @@ */ package tech.pegasys.pantheon.ethereum.core; -import static java.nio.charset.StandardCharsets.UTF_8; - import tech.pegasys.pantheon.crypto.SECP256K1; import tech.pegasys.pantheon.ethereum.privacy.PrivateStateStorage; import tech.pegasys.pantheon.ethereum.privacy.PrivateTransactionStorage; import tech.pegasys.pantheon.ethereum.storage.StorageProvider; -import tech.pegasys.pantheon.ethereum.storage.keyvalue.RocksDbStorageProvider; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; -import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; -import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; -import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; import java.io.File; -import java.io.IOException; import java.net.URI; -import java.nio.file.Path; - -import com.google.common.io.Files; public class PrivacyParameters { - private static final String ENCLAVE_URL = "http://localhost:8888"; - public static final URI DEFAULT_ENCLAVE_URL = URI.create(ENCLAVE_URL); - private final String PRIVATE_DATABASE_PATH = "private"; - private final String PRIVATE_STATE_DATABASE_PATH = "privateState"; + public static final URI DEFAULT_ENCLAVE_URL = URI.create("http://localhost:8888"); + public static final PrivacyParameters DEFAULT = new PrivacyParameters(); - private Integer privacyAddress; + private Integer privacyAddress = Address.PRIVACY; private boolean enabled; - private String url; + private URI enclaveUri; private String enclavePublicKey; private File enclavePublicKeyFile; private SECP256K1.KeyPair signingKeyPair; @@ -49,96 +37,89 @@ public class PrivacyParameters { private PrivateTransactionStorage privateTransactionStorage; private PrivateStateStorage privateStateStorage; - public String getEnclavePublicKey() { - return enclavePublicKey; + public Integer getPrivacyAddress() { + return privacyAddress; } - public File getEnclavePublicKeyFile() { - return enclavePublicKeyFile; + public void setPrivacyAddress(final Integer privacyAddress) { + this.privacyAddress = privacyAddress; } - public void setEnclavePublicKeyUsingFile(final File publicKeyFile) throws IOException { - this.enclavePublicKeyFile = publicKeyFile; - this.enclavePublicKey = Files.asCharSource(publicKeyFile, UTF_8).read(); + public Boolean isEnabled() { + return enabled; } - public void setSigningKeyPair(final SECP256K1.KeyPair signingKeyPair) { - this.signingKeyPair = signingKeyPair; + public void setEnabled(final boolean enabled) { + this.enabled = enabled; } - public SECP256K1.KeyPair getSigningKeyPair() { - return signingKeyPair; + public URI getEnclaveUri() { + return enclaveUri; } - public static PrivacyParameters noPrivacy() { - final PrivacyParameters config = new PrivacyParameters(); - config.setEnabled(false); - config.setUrl(ENCLAVE_URL); - config.setPrivacyAddress(Address.PRIVACY); - return config; + public void setEnclaveUri(final URI enclaveUri) { + this.enclaveUri = enclaveUri; } - @Override - public String toString() { - return "PrivacyParameters{" + "enabled=" + enabled + ", url='" + url + '\'' + '}'; + public String getEnclavePublicKey() { + return enclavePublicKey; } - public void setUrl(final String url) { - this.url = url; + public void setEnclavePublicKey(final String enclavePublicKey) { + this.enclavePublicKey = enclavePublicKey; } - public String getUrl() { - return this.url; + public File getEnclavePublicKeyFile() { + return enclavePublicKeyFile; } - public boolean isEnabled() { - return enabled; + public void setEnclavePublicKeyFile(final File enclavePublicKeyFile) { + this.enclavePublicKeyFile = enclavePublicKeyFile; } - public void setEnabled(final boolean enabled) { - this.enabled = enabled; + public SECP256K1.KeyPair getSigningKeyPair() { + return signingKeyPair; } - public Integer getPrivacyAddress() { - return privacyAddress; + public void setSigningKeyPair(final SECP256K1.KeyPair signingKeyPair) { + this.signingKeyPair = signingKeyPair; } - public void setPrivacyAddress(final Integer privacyAddress) { - this.privacyAddress = privacyAddress; + public WorldStateArchive getPrivateWorldStateArchive() { + return privateWorldStateArchive; } - public void enablePrivateDB(final Path path) throws IOException { - final Path privateDbPath = path.resolve(PRIVATE_DATABASE_PATH); - this.privateStorageProvider = - RocksDbStorageProvider.create( - new RocksDbConfiguration.Builder().databaseDir(privateDbPath).build(), - new NoOpMetricsSystem()); - final WorldStateStorage privateWorldStateStorage = - privateStorageProvider.createWorldStateStorage(); - this.privateWorldStateArchive = new WorldStateArchive(privateWorldStateStorage); + public void setPrivateWorldStateArchive(final WorldStateArchive privateWorldStateArchive) { + this.privateWorldStateArchive = privateWorldStateArchive; + } + + public StorageProvider getPrivateStorageProvider() { + return privateStorageProvider; + } - final Path privateStateDbPath = path.resolve(PRIVATE_STATE_DATABASE_PATH); - final StorageProvider privateStateStorageProvider = - RocksDbStorageProvider.create( - new RocksDbConfiguration.Builder().databaseDir(privateStateDbPath).build(), - new NoOpMetricsSystem()); - this.privateTransactionStorage = privateStateStorageProvider.createPrivateTransactionStorage(); - this.privateStateStorage = privateStateStorageProvider.createPrivateStateStorage(); + public void setPrivateStorageProvider(final StorageProvider privateStorageProvider) { + this.privateStorageProvider = privateStorageProvider; } public PrivateTransactionStorage getPrivateTransactionStorage() { return privateTransactionStorage; } + public void setPrivateTransactionStorage( + final PrivateTransactionStorage privateTransactionStorage) { + this.privateTransactionStorage = privateTransactionStorage; + } + public PrivateStateStorage getPrivateStateStorage() { return privateStateStorage; } - public WorldStateArchive getPrivateWorldStateArchive() { - return privateWorldStateArchive; + public void setPrivateStateStorage(final PrivateStateStorage privateStateStorage) { + this.privateStateStorage = privateStateStorage; } - public StorageProvider getPrivateStorageProvider() { - return this.privateStorageProvider; + @Override + public String toString() { + return "PrivacyParameters{" + "enabled=" + enabled + ", enclaveUri='" + enclaveUri + '\'' + '}'; } } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParametersBuilder.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParametersBuilder.java new file mode 100644 index 0000000000..8041cb87fd --- /dev/null +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParametersBuilder.java @@ -0,0 +1,110 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.ethereum.core; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import tech.pegasys.pantheon.ethereum.privacy.PrivateStateStorage; +import tech.pegasys.pantheon.ethereum.privacy.PrivateTransactionStorage; +import tech.pegasys.pantheon.ethereum.storage.StorageProvider; +import tech.pegasys.pantheon.ethereum.storage.keyvalue.RocksDbStorageProvider; +import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; +import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; +import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; +import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.nio.file.Path; + +import com.google.common.io.Files; + +public class PrivacyParametersBuilder { + private final String PRIVATE_DATABASE_PATH = "private"; + private final String PRIVATE_STATE_DATABASE_PATH = "privateState"; + + private boolean enabled; + private URI enclaveUrl; + private Integer privacyAddress; + private MetricsSystem metricsSystem = new NoOpMetricsSystem(); + private Path dataDir; + private File enclavePublicKeyFile; + private String enclavePublicKey; + + public PrivacyParametersBuilder setPrivacyAddress(final Integer privacyAddress) { + this.privacyAddress = privacyAddress; + return this; + } + + public PrivacyParametersBuilder setEnclaveUrl(final URI enclaveUrl) { + this.enclaveUrl = enclaveUrl; + return this; + } + + public PrivacyParametersBuilder setEnabled(final boolean enabled) { + this.enabled = enabled; + return this; + } + + public PrivacyParametersBuilder setMetricsSystem(final MetricsSystem metricsSystem) { + this.metricsSystem = metricsSystem; + return this; + } + + public PrivacyParametersBuilder setDataDir(final Path dataDir) { + this.dataDir = dataDir; + return this; + } + + public PrivacyParameters build() throws IOException { + PrivacyParameters config = new PrivacyParameters(); + if (enabled) { + Path privateDbPath = dataDir.resolve(PRIVATE_DATABASE_PATH); + StorageProvider privateStorageProvider = + RocksDbStorageProvider.create( + new RocksDbConfiguration.Builder().databaseDir(privateDbPath).build(), metricsSystem); + WorldStateStorage privateWorldStateStorage = privateStorageProvider.createWorldStateStorage(); + WorldStateArchive privateWorldStateArchive = new WorldStateArchive(privateWorldStateStorage); + + Path privateStateDbPath = dataDir.resolve(PRIVATE_STATE_DATABASE_PATH); + StorageProvider privateStateStorageProvider = + RocksDbStorageProvider.create( + new RocksDbConfiguration.Builder().databaseDir(privateStateDbPath).build(), + metricsSystem); + PrivateTransactionStorage privateTransactionStorage = + privateStateStorageProvider.createPrivateTransactionStorage(); + PrivateStateStorage privateStateStorage = + privateStateStorageProvider.createPrivateStateStorage(); + + config.setPrivateWorldStateArchive(privateWorldStateArchive); + config.setEnclavePublicKey(enclavePublicKey); + config.setEnclavePublicKeyFile(enclavePublicKeyFile); + config.setPrivateStorageProvider(privateStorageProvider); + config.setPrivateTransactionStorage(privateTransactionStorage); + config.setPrivateStateStorage(privateStateStorage); + } + config.setEnabled(enabled); + config.setEnclaveUri(enclaveUrl); + config.setPrivacyAddress(privacyAddress); + return config; + } + + public PrivacyParametersBuilder setEnclavePublicKeyUsingFile(final File publicKeyFile) + throws IOException { + this.enclavePublicKeyFile = publicKeyFile; + this.enclavePublicKey = Files.asCharSource(publicKeyFile, UTF_8).read(); + return this; + } +} diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java index 2307c04425..50ab59dc63 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java @@ -31,4 +31,8 @@ public static ProtocolSchedule create( privacyParameters) .createProtocolSchedule(); } + + public static ProtocolSchedule create(final GenesisConfigOptions config) { + return create(config, PrivacyParameters.DEFAULT); + } } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolSchedule.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolSchedule.java index b4f0132e51..7a4d1a9209 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolSchedule.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolSchedule.java @@ -26,8 +26,7 @@ public class MainnetProtocolSchedule { public static final int DEFAULT_CHAIN_ID = 1; public static ProtocolSchedule create() { - return fromConfig( - GenesisConfigFile.mainnet().getConfigOptions(), PrivacyParameters.noPrivacy()); + return fromConfig(GenesisConfigFile.mainnet().getConfigOptions(), PrivacyParameters.DEFAULT); } /** @@ -47,4 +46,15 @@ public static ProtocolSchedule fromConfig( config, DEFAULT_CHAIN_ID, Function.identity(), privacyParameters) .createProtocolSchedule(); } + + /** + * Create a Mainnet protocol schedule from a config object + * + * @param config {@link GenesisConfigOptions} containing the config options for the milestone + * starting points + * @return A configured mainnet protocol schedule + */ + public static ProtocolSchedule fromConfig(final GenesisConfigOptions config) { + return fromConfig(config, PrivacyParameters.DEFAULT); + } } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContract.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContract.java index e1b4363aff..b4f4eb86ac 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContract.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContract.java @@ -62,7 +62,7 @@ public PrivacyPrecompiledContract( this( gasCalculator, privacyParameters.getEnclavePublicKey(), - new Enclave(privacyParameters.getUrl()), + new Enclave(privacyParameters.getEnclaveUri()), privacyParameters.getPrivateWorldStateArchive(), privacyParameters.getPrivateTransactionStorage(), privacyParameters.getPrivateStateStorage()); diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionHandler.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionHandler.java index b3928fbb15..cb0a124f91 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionHandler.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionHandler.java @@ -42,7 +42,7 @@ public class PrivateTransactionHandler { public PrivateTransactionHandler(final PrivacyParameters privacyParameters) { this( - new Enclave(privacyParameters.getUrl()), + new Enclave(privacyParameters.getEnclaveUri()), Address.privacyPrecompiled(privacyParameters.getPrivacyAddress()), privacyParameters.getSigningKeyPair()); } diff --git a/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java b/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java index 64ff603c62..073e45fd02 100644 --- a/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java +++ b/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java @@ -113,7 +113,7 @@ public ExecutionContextTestFixture build() { new StubGenesisConfigOptions().constantinopleFixBlock(0), 42, Function.identity(), - PrivacyParameters.noPrivacy()) + new PrivacyParameters()) .createProtocolSchedule(); } if (keyValueStorage == null) { diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java index 927ca44ea5..82e27a3f27 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java @@ -29,7 +29,7 @@ public void reportedDifficultyForAllBlocksIsAFixedValue() { final ProtocolSchedule schedule = FixedDifficultyProtocolSchedule.create( - GenesisConfigFile.development().getConfigOptions(), PrivacyParameters.noPrivacy()); + GenesisConfigFile.development().getConfigOptions(), PrivacyParameters.DEFAULT); final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolScheduleTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolScheduleTest.java index 788109c1fc..72a41b416f 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolScheduleTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolScheduleTest.java @@ -50,8 +50,7 @@ public void shouldReturnDefaultProtocolSpecsWhenCustomNumbersAreNotUsed() { public void shouldOnlyUseFrontierWhenEmptyJsonConfigIsUsed() { final JsonObject json = new JsonObject("{}"); final ProtocolSchedule sched = - MainnetProtocolSchedule.fromConfig( - GenesisConfigFile.fromConfig(json).getConfigOptions(), PrivacyParameters.noPrivacy()); + MainnetProtocolSchedule.fromConfig(GenesisConfigFile.fromConfig(json).getConfigOptions()); Assertions.assertThat(sched.getByBlockNumber(1L).getName()).isEqualTo("Frontier"); Assertions.assertThat(sched.getByBlockNumber(Long.MAX_VALUE).getName()).isEqualTo("Frontier"); } @@ -62,8 +61,7 @@ public void createFromConfigWithSettings() { new JsonObject( "{\"config\": {\"homesteadBlock\": 2, \"daoForkBlock\": 3, \"eip150Block\": 14, \"eip158Block\": 15, \"byzantiumBlock\": 16, \"constantinopleBlock\": 18, \"constantinopleFixBlock\": 19, \"chainId\":1234}}"); final ProtocolSchedule sched = - MainnetProtocolSchedule.fromConfig( - GenesisConfigFile.fromConfig(json).getConfigOptions(), PrivacyParameters.noPrivacy()); + MainnetProtocolSchedule.fromConfig(GenesisConfigFile.fromConfig(json).getConfigOptions()); Assertions.assertThat(sched.getByBlockNumber(1).getName()).isEqualTo("Frontier"); Assertions.assertThat(sched.getByBlockNumber(2).getName()).isEqualTo("Homestead"); Assertions.assertThat(sched.getByBlockNumber(3).getName()).isEqualTo("DaoRecoveryInit"); @@ -87,8 +85,7 @@ public void outOfOrderForksFails() { .isThrownBy( () -> MainnetProtocolSchedule.fromConfig( - GenesisConfigFile.fromConfig(json).getConfigOptions(), - PrivacyParameters.noPrivacy())); + GenesisConfigFile.fromConfig(json).getConfigOptions())); } @Test @@ -99,7 +96,7 @@ public void shouldCreateRopstenConfig() throws Exception { Resources.toString( Resources.getResource("ropsten.json"), StandardCharsets.UTF_8)) .getConfigOptions(), - PrivacyParameters.noPrivacy()); + PrivacyParameters.DEFAULT); Assertions.assertThat(sched.getByBlockNumber(0).getName()).isEqualTo("TangerineWhistle"); Assertions.assertThat(sched.getByBlockNumber(1).getName()).isEqualTo("TangerineWhistle"); Assertions.assertThat(sched.getByBlockNumber(10).getName()).isEqualTo("SpuriousDragon"); diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/ReferenceTestProtocolSchedules.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/ReferenceTestProtocolSchedules.java index 185ed3924a..952cce7ff3 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/ReferenceTestProtocolSchedules.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/ReferenceTestProtocolSchedules.java @@ -65,7 +65,7 @@ public ProtocolSchedule getByName(final String name) { private static ProtocolSchedule createSchedule(final GenesisConfigOptions options) { return new ProtocolScheduleBuilder<>( - options, CHAIN_ID, Function.identity(), PrivacyParameters.noPrivacy()) + options, CHAIN_ID, Function.identity(), PrivacyParameters.DEFAULT) .createProtocolSchedule(); } } diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/VMReferenceTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/VMReferenceTest.java index 9cff8c278a..d2e093bb6b 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/VMReferenceTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/VMReferenceTest.java @@ -118,7 +118,7 @@ protected void runTest() { final ProtocolSpec protocolSpec = MainnetProtocolSpecs.frontierDefinition(OptionalInt.empty()) - .privacyParameters(PrivacyParameters.noPrivacy()) + .privacyParameters(PrivacyParameters.DEFAULT) .build(new MutableProtocolSchedule<>(CHAIN_ID)); final TestBlockchain blockchain = new TestBlockchain(execEnv.getBlockHeader().getNumber()); diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/operations/ConstantinopleSStoreOperationGasCostTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/operations/ConstantinopleSStoreOperationGasCostTest.java index f485854326..239ec05260 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/operations/ConstantinopleSStoreOperationGasCostTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/operations/ConstantinopleSStoreOperationGasCostTest.java @@ -16,7 +16,6 @@ import tech.pegasys.pantheon.config.StubGenesisConfigOptions; import tech.pegasys.pantheon.ethereum.core.Gas; -import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.core.TestCodeExecutor; import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; @@ -35,8 +34,7 @@ public class ConstantinopleSStoreOperationGasCostTest { private static final ProtocolSchedule protocolSchedule = - MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().constantinopleBlock(0), PrivacyParameters.noPrivacy()); + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().constantinopleBlock(0)); @Parameters(name = "Code: {0}, Original: {1}") public static Object[][] scenarios() { diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockBodiesMessageTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockBodiesMessageTest.java index 489b77601f..3f17fbe25a 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockBodiesMessageTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockBodiesMessageTest.java @@ -15,7 +15,6 @@ import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockHeader; -import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; @@ -67,8 +66,7 @@ public void blockBodiesRoundTrip() throws IOException { message .bodies( FixedDifficultyProtocolSchedule.create( - GenesisConfigFile.development().getConfigOptions(), - PrivacyParameters.noPrivacy())) + GenesisConfigFile.development().getConfigOptions())) .iterator(); for (int i = 0; i < 50; ++i) { Assertions.assertThat(readBodies.next()).isEqualTo(bodies.get(i)); diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockHeadersMessageTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockHeadersMessageTest.java index a7b68940e9..ef02021577 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockHeadersMessageTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockHeadersMessageTest.java @@ -14,7 +14,6 @@ import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.ethereum.core.BlockHeader; -import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.p2p.api.MessageData; @@ -59,7 +58,7 @@ public void blockHeadersRoundTrip() throws IOException { final List readHeaders = message.getHeaders( FixedDifficultyProtocolSchedule.create( - GenesisConfigFile.development().getConfigOptions(), PrivacyParameters.noPrivacy())); + GenesisConfigFile.development().getConfigOptions())); for (int i = 0; i < 50; ++i) { Assertions.assertThat(readHeaders.get(i)).isEqualTo(headers.get(i)); diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/ChainHeadTrackerTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/ChainHeadTrackerTest.java index 514e96d4f8..0176519ce7 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/ChainHeadTrackerTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/ChainHeadTrackerTest.java @@ -18,7 +18,6 @@ import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Hash; -import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import tech.pegasys.pantheon.ethereum.eth.manager.ChainState; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; @@ -45,8 +44,7 @@ public class ChainHeadTrackerTest { blockchain.getChainHead().getTotalDifficulty(), 0); private final ProtocolSchedule protocolSchedule = - FixedDifficultyProtocolSchedule.create( - GenesisConfigFile.development().getConfigOptions(), PrivacyParameters.noPrivacy()); + FixedDifficultyProtocolSchedule.create(GenesisConfigFile.development().getConfigOptions()); private final TrailingPeerLimiter trailingPeerLimiter = mock(TrailingPeerLimiter.class); private final ChainHeadTracker chainHeadTracker = diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java index 26170eef89..fa78c707bc 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java @@ -24,7 +24,6 @@ import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.BlockHashFunction; import tech.pegasys.pantheon.ethereum.core.PendingTransactions; -import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.TransactionPool; import tech.pegasys.pantheon.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; @@ -95,8 +94,7 @@ public TestNode( final GenesisConfigFile genesisConfigFile = GenesisConfigFile.development(); final ProtocolSchedule protocolSchedule = - FixedDifficultyProtocolSchedule.create( - GenesisConfigFile.development().getConfigOptions(), PrivacyParameters.noPrivacy()); + FixedDifficultyProtocolSchedule.create(GenesisConfigFile.development().getConfigOptions()); final GenesisState genesisState = GenesisState.fromConfig(genesisConfigFile, protocolSchedule); final BlockHashFunction blockHashFunction = diff --git a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/BlockchainImporter.java b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/BlockchainImporter.java index ed89ad36fd..6e316a62cb 100644 --- a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/BlockchainImporter.java +++ b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/BlockchainImporter.java @@ -16,7 +16,6 @@ import tech.pegasys.pantheon.ethereum.chain.GenesisState; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockHeader; -import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; @@ -41,8 +40,7 @@ public class BlockchainImporter { public BlockchainImporter(final URL blocksUrl, final String genesisJson) throws Exception { protocolSchedule = MainnetProtocolSchedule.fromConfig( - GenesisConfigFile.fromConfig(genesisJson).getConfigOptions(), - PrivacyParameters.noPrivacy()); + GenesisConfigFile.fromConfig(genesisJson).getConfigOptions()); blocks = new ArrayList<>(); try (final RawBlockIterator iterator = diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java index 4cfb0ee80d..5c0af059fa 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java @@ -291,7 +291,7 @@ blockchainQueries, new TransactionTracer(blockReplay), parameter), enabledMethods, new EeaGetTransactionReceipt( blockchainQueries, - new Enclave(privacyParameters.getUrl()), + new Enclave(privacyParameters.getEnclaveUri()), parameter, privacyParameters)); } diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java index 8a02955de4..64669ed917 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java @@ -93,8 +93,7 @@ public void initServerAndClient() throws Exception { blockchainQueries, synchronizer, MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), - PrivacyParameters.noPrivacy()), + new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)), mock(FilterManager.class), mock(TransactionPool.class), mock(EthHashMiningCoordinator.class), diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceLoginTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceLoginTest.java index 539ed7a1db..6f304d5865 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceLoginTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceLoginTest.java @@ -123,8 +123,7 @@ public static void initServerAndClient() throws Exception { peerDiscoveryMock, blockchainQueries, synchronizer, - MainnetProtocolSchedule.fromConfig( - genesisConfigOptions, PrivacyParameters.noPrivacy()), + MainnetProtocolSchedule.fromConfig(genesisConfigOptions), mock(FilterManager.class), mock(TransactionPool.class), mock(EthHashMiningCoordinator.class), diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java index a478e80125..d20a7776d3 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java @@ -121,8 +121,7 @@ public static void initServerAndClient() throws Exception { blockchainQueries, synchronizer, MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), - PrivacyParameters.noPrivacy()), + new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)), mock(FilterManager.class), mock(TransactionPool.class), mock(EthHashMiningCoordinator.class), diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 8ece5e0b8f..cacb988578 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -44,6 +44,7 @@ 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.PrivacyParametersBuilder; import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; @@ -938,20 +939,21 @@ private PrivacyParameters privacyParameters() throws IOException { !isPrivacyEnabled, asList("--privacy-url", "--privacy-public-key-file", "--privacy-precompiled-address")); - final PrivacyParameters privacyParameters = PrivacyParameters.noPrivacy(); + final PrivacyParametersBuilder privacyParametersBuilder = new PrivacyParametersBuilder(); if (isPrivacyEnabled) { - privacyParameters.setEnabled(true); - privacyParameters.setUrl(privacyUrl.toString()); + privacyParametersBuilder.setEnabled(true); + privacyParametersBuilder.setEnclaveUrl(privacyUrl); if (privacyPublicKeyFile() != null) { - privacyParameters.setEnclavePublicKeyUsingFile(privacyPublicKeyFile()); + privacyParametersBuilder.setEnclavePublicKeyUsingFile(privacyPublicKeyFile()); } else { throw new ParameterException( commandLine, "Please specify Enclave public key file path to enable privacy"); } - privacyParameters.setPrivacyAddress(privacyPrecompiledAddress); - privacyParameters.enablePrivateDB(dataDir()); + privacyParametersBuilder.setPrivacyAddress(privacyPrecompiledAddress); + privacyParametersBuilder.setMetricsSystem(metricsSystem.get()); + privacyParametersBuilder.setDataDir(dataDir()); } - return privacyParameters; + return privacyParametersBuilder.build(); } private SynchronizerConfiguration buildSyncConfig() { diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/PrivacyTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/PrivacyTest.java index 79b046b5bc..4b4ab1549e 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/PrivacyTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/PrivacyTest.java @@ -23,6 +23,7 @@ import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder; import tech.pegasys.pantheon.ethereum.core.PendingTransactions; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; +import tech.pegasys.pantheon.ethereum.core.PrivacyParametersBuilder; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import tech.pegasys.pantheon.ethereum.mainnet.PrecompiledContract; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; @@ -43,10 +44,12 @@ public class PrivacyTest { @Test public void privacyPrecompiled() throws IOException { final Path dataDir = folder.newFolder().toPath(); - PrivacyParameters privacyParameters = PrivacyParameters.noPrivacy(); - privacyParameters.setPrivacyAddress(ADDRESS); - privacyParameters.setEnabled(true); - privacyParameters.enablePrivateDB(dataDir); + PrivacyParameters privacyParameters = + new PrivacyParametersBuilder() + .setPrivacyAddress(ADDRESS) + .setEnabled(true) + .setDataDir(dataDir) + .build(); MainnetPantheonController mainnetPantheonController = (MainnetPantheonController) diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java index 9a364c68a2..8d17bc8867 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java @@ -110,7 +110,7 @@ private void syncFromGenesis(final SyncMode mode) throws Exception { new MiningParametersTestBuilder().enabled(false).build(), networkId, aheadDbNodeKeys, - PrivacyParameters.noPrivacy(), + PrivacyParameters.DEFAULT, dataDirAhead, noOpMetricsSystem, TestClock.fixed(), @@ -128,7 +128,7 @@ private void syncFromGenesis(final SyncMode mode) throws Exception { new MiningParametersTestBuilder().enabled(false).build(), networkId, aheadDbNodeKeys, - PrivacyParameters.noPrivacy(), + PrivacyParameters.DEFAULT, dataDirAhead, noOpMetricsSystem, TestClock.fixed(), @@ -184,7 +184,7 @@ private void syncFromGenesis(final SyncMode mode) throws Exception { new MiningParametersTestBuilder().enabled(false).build(), networkId, KeyPair.generate(), - PrivacyParameters.noPrivacy(), + PrivacyParameters.DEFAULT, dataDirBehind, noOpMetricsSystem, TestClock.fixed(), diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java index f41bf45ecc..2e132b01bc 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -2074,7 +2074,7 @@ public void mustUseEnclaveUriAndOptions() throws IOException { verify(mockControllerBuilder).build(); assertThat(enclaveArg.getValue().isEnabled()).isEqualTo(true); - assertThat(enclaveArg.getValue().getUrl()).isEqualTo(ENCLAVE_URI); + assertThat(enclaveArg.getValue().getEnclaveUri()).isEqualTo(URI.create(ENCLAVE_URI)); assertThat(enclaveArg.getValue().getEnclavePublicKey()).isEqualTo(ENCLAVE_PUBLIC_KEY); assertThat(commandOutput.toString()).isEmpty(); diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockImporterTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockImporterTest.java index a84551b09e..c12cc8c1ca 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockImporterTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockImporterTest.java @@ -59,7 +59,7 @@ public void blockImport() throws IOException { new MiningParametersTestBuilder().enabled(false).build(), KeyPair.generate(), new NoOpMetricsSystem(), - PrivacyParameters.noPrivacy(), + PrivacyParameters.DEFAULT, dataDir, TestClock.fixed(), PendingTransactions.MAX_PENDING_TRANSACTIONS); @@ -96,7 +96,7 @@ public void ibftImport() throws IOException { new MiningParametersTestBuilder().enabled(false).build(), KeyPair.generate(), new NoOpMetricsSystem(), - PrivacyParameters.noPrivacy(), + PrivacyParameters.DEFAULT, dataDir, TestClock.fixed(), PendingTransactions.MAX_PENDING_TRANSACTIONS); diff --git a/testutil/src/main/java/tech/pegasys/orion/testutil/OrionTestHarness.java b/testutil/src/main/java/tech/pegasys/orion/testutil/OrionTestHarness.java index 38cdccb20a..80f50c8665 100644 --- a/testutil/src/main/java/tech/pegasys/orion/testutil/OrionTestHarness.java +++ b/testutil/src/main/java/tech/pegasys/orion/testutil/OrionTestHarness.java @@ -15,6 +15,7 @@ import static com.google.common.io.Files.readLines; import java.io.IOException; +import java.net.URI; import java.nio.file.Path; import java.util.List; import java.util.stream.Collectors; @@ -51,12 +52,6 @@ public List getPublicKeys() { .collect(Collectors.toList()); } - public List getPrivateKeys() { - return config.privateKeys().stream() - .map(OrionTestHarness::readFile) - .collect(Collectors.toList()); - } - private static String readFile(final Path path) { try { return readLines(path.toFile(), Charsets.UTF_8).get(0); @@ -66,13 +61,11 @@ private static String readFile(final Path path) { } } - public String clientUrl() { - return new HttpUrl.Builder() - .scheme("http") - .host(HOST) - .port(orion.clientPort()) - .build() - .toString(); + public URI clientUrl() { + HttpUrl httpUrl = + new HttpUrl.Builder().scheme("http").host(HOST).port(orion.clientPort()).build(); + + return URI.create(httpUrl.toString()); } public String nodeUrl() { From a02e41fa75d1638aa12c04f1c1bef94cca328c0f Mon Sep 17 00:00:00 2001 From: Antony Denyer Date: Fri, 5 Apr 2019 18:44:49 +0100 Subject: [PATCH 2/4] Fix: enclave tests from bad merge --- .../java/tech/pegasys/pantheon/enclave/Enclave.java | 11 +++++------ .../ethereum/core/PrivacyParametersBuilder.java | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/enclave/src/main/java/tech/pegasys/pantheon/enclave/Enclave.java b/enclave/src/main/java/tech/pegasys/pantheon/enclave/Enclave.java index c5d2e242dd..faa987d35e 100644 --- a/enclave/src/main/java/tech/pegasys/pantheon/enclave/Enclave.java +++ b/enclave/src/main/java/tech/pegasys/pantheon/enclave/Enclave.java @@ -35,16 +35,16 @@ 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 URI uri; + private final URI enclaveUri; private final OkHttpClient client; public Enclave(final URI enclaveUri) { - this.uri = enclaveUri; + this.enclaveUri = enclaveUri; this.client = new OkHttpClient(); } public Boolean upCheck() throws IOException { - String url = uri.resolve("/upcheck").toString(); + String url = enclaveUri.resolve("/upcheck").toString(); Request request = new Request.Builder().url(url).get().build(); try (Response response = client.newCall(request).execute()) { @@ -57,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); } @@ -69,8 +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)); - String url = uri.resolve(endpoint).toString(); - 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 executePost(final Request request, final Class responseType) throws IOException { diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParametersBuilder.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParametersBuilder.java index 8041cb87fd..d185881edd 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParametersBuilder.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParametersBuilder.java @@ -37,7 +37,7 @@ public class PrivacyParametersBuilder { private boolean enabled; private URI enclaveUrl; - private Integer privacyAddress; + private Integer privacyAddress = Address.PRIVACY; private MetricsSystem metricsSystem = new NoOpMetricsSystem(); private Path dataDir; private File enclavePublicKeyFile; From ce8ad19fc4de2de8a35d929469fb15e9dbb34e28 Mon Sep 17 00:00:00 2001 From: Antony Denyer Date: Fri, 5 Apr 2019 18:52:38 +0100 Subject: [PATCH 3/4] Fix privacy acceptance tests after db configuration changes --- acceptance-tests/build.gradle | 3 ++- .../tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/acceptance-tests/build.gradle b/acceptance-tests/build.gradle index ea4cf91ec4..177381f15a 100644 --- a/acceptance-tests/build.gradle +++ b/acceptance-tests/build.gradle @@ -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') @@ -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' diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java index d67e6d68ef..b0d44825fd 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java @@ -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; @@ -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; @@ -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 { @@ -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); From d46cab6df264a7c01cb7f5dbac4f94d4a38f220c Mon Sep 17 00:00:00 2001 From: Antony Denyer Date: Tue, 9 Apr 2019 15:44:42 +0100 Subject: [PATCH 4/4] Switch to use nested class for PrivacyParametersBuilder --- .../privacy/PrivateAcceptanceTestBase.java | 3 +- .../ethereum/core/PrivacyParameters.java | 91 +++++++++++++++ .../core/PrivacyParametersBuilder.java | 110 ------------------ .../pegasys/pantheon/cli/PantheonCommand.java | 3 +- .../tech/pegasys/pantheon/PrivacyTest.java | 3 +- 5 files changed, 94 insertions(+), 116 deletions(-) delete mode 100644 ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParametersBuilder.java diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateAcceptanceTestBase.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateAcceptanceTestBase.java index 3eb3a4bd2e..d912b73baa 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateAcceptanceTestBase.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateAcceptanceTestBase.java @@ -17,7 +17,6 @@ import tech.pegasys.pantheon.crypto.SECP256K1; import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; -import tech.pegasys.pantheon.ethereum.core.PrivacyParametersBuilder; import tech.pegasys.pantheon.ethereum.privacy.PrivateTransaction; import tech.pegasys.pantheon.ethereum.rlp.RLP; import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; @@ -121,7 +120,7 @@ public String build(final TransactionType type) { } static PrivacyParameters getPrivacyParams(final OrionTestHarness testHarness) throws IOException { - return new PrivacyParametersBuilder() + return new PrivacyParameters.Builder() .setEnabled(true) .setEnclaveUrl(testHarness.clientUrl()) .setEnclavePublicKeyUsingFile(testHarness.getConfig().publicKeys().get(0).toFile()) diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParameters.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParameters.java index e9dbaebe23..0dd8d3b792 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParameters.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParameters.java @@ -12,14 +12,25 @@ */ package tech.pegasys.pantheon.ethereum.core; +import static java.nio.charset.StandardCharsets.UTF_8; + import tech.pegasys.pantheon.crypto.SECP256K1; import tech.pegasys.pantheon.ethereum.privacy.PrivateStateStorage; import tech.pegasys.pantheon.ethereum.privacy.PrivateTransactionStorage; import tech.pegasys.pantheon.ethereum.storage.StorageProvider; +import tech.pegasys.pantheon.ethereum.storage.keyvalue.RocksDbStorageProvider; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; +import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; +import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; +import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; import java.io.File; +import java.io.IOException; import java.net.URI; +import java.nio.file.Path; + +import com.google.common.io.Files; public class PrivacyParameters { public static final URI DEFAULT_ENCLAVE_URL = URI.create("http://localhost:8888"); @@ -122,4 +133,84 @@ public void setPrivateStateStorage(final PrivateStateStorage privateStateStorage public String toString() { return "PrivacyParameters{" + "enabled=" + enabled + ", enclaveUri='" + enclaveUri + '\'' + '}'; } + + public static class Builder { + private final String PRIVATE_DATABASE_PATH = "private"; + private final String PRIVATE_STATE_DATABASE_PATH = "privateState"; + + private boolean enabled; + private URI enclaveUrl; + private Integer privacyAddress = Address.PRIVACY; + private MetricsSystem metricsSystem = new NoOpMetricsSystem(); + private Path dataDir; + private File enclavePublicKeyFile; + private String enclavePublicKey; + + public Builder setPrivacyAddress(final Integer privacyAddress) { + this.privacyAddress = privacyAddress; + return this; + } + + public Builder setEnclaveUrl(final URI enclaveUrl) { + this.enclaveUrl = enclaveUrl; + return this; + } + + public Builder setEnabled(final boolean enabled) { + this.enabled = enabled; + return this; + } + + public Builder setMetricsSystem(final MetricsSystem metricsSystem) { + this.metricsSystem = metricsSystem; + return this; + } + + public Builder setDataDir(final Path dataDir) { + this.dataDir = dataDir; + return this; + } + + public PrivacyParameters build() throws IOException { + PrivacyParameters config = new PrivacyParameters(); + if (enabled) { + Path privateDbPath = dataDir.resolve(PRIVATE_DATABASE_PATH); + StorageProvider privateStorageProvider = + RocksDbStorageProvider.create( + new RocksDbConfiguration.Builder().databaseDir(privateDbPath).build(), + metricsSystem); + WorldStateStorage privateWorldStateStorage = + privateStorageProvider.createWorldStateStorage(); + WorldStateArchive privateWorldStateArchive = + new WorldStateArchive(privateWorldStateStorage); + + Path privateStateDbPath = dataDir.resolve(PRIVATE_STATE_DATABASE_PATH); + StorageProvider privateStateStorageProvider = + RocksDbStorageProvider.create( + new RocksDbConfiguration.Builder().databaseDir(privateStateDbPath).build(), + metricsSystem); + PrivateTransactionStorage privateTransactionStorage = + privateStateStorageProvider.createPrivateTransactionStorage(); + PrivateStateStorage privateStateStorage = + privateStateStorageProvider.createPrivateStateStorage(); + + config.setPrivateWorldStateArchive(privateWorldStateArchive); + config.setEnclavePublicKey(enclavePublicKey); + config.setEnclavePublicKeyFile(enclavePublicKeyFile); + config.setPrivateStorageProvider(privateStorageProvider); + config.setPrivateTransactionStorage(privateTransactionStorage); + config.setPrivateStateStorage(privateStateStorage); + } + config.setEnabled(enabled); + config.setEnclaveUri(enclaveUrl); + config.setPrivacyAddress(privacyAddress); + return config; + } + + public Builder setEnclavePublicKeyUsingFile(final File publicKeyFile) throws IOException { + this.enclavePublicKeyFile = publicKeyFile; + this.enclavePublicKey = Files.asCharSource(publicKeyFile, UTF_8).read(); + return this; + } + } } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParametersBuilder.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParametersBuilder.java deleted file mode 100644 index d185881edd..0000000000 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParametersBuilder.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2019 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.pantheon.ethereum.core; - -import static java.nio.charset.StandardCharsets.UTF_8; - -import tech.pegasys.pantheon.ethereum.privacy.PrivateStateStorage; -import tech.pegasys.pantheon.ethereum.privacy.PrivateTransactionStorage; -import tech.pegasys.pantheon.ethereum.storage.StorageProvider; -import tech.pegasys.pantheon.ethereum.storage.keyvalue.RocksDbStorageProvider; -import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; -import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; -import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; -import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.nio.file.Path; - -import com.google.common.io.Files; - -public class PrivacyParametersBuilder { - private final String PRIVATE_DATABASE_PATH = "private"; - private final String PRIVATE_STATE_DATABASE_PATH = "privateState"; - - private boolean enabled; - private URI enclaveUrl; - private Integer privacyAddress = Address.PRIVACY; - private MetricsSystem metricsSystem = new NoOpMetricsSystem(); - private Path dataDir; - private File enclavePublicKeyFile; - private String enclavePublicKey; - - public PrivacyParametersBuilder setPrivacyAddress(final Integer privacyAddress) { - this.privacyAddress = privacyAddress; - return this; - } - - public PrivacyParametersBuilder setEnclaveUrl(final URI enclaveUrl) { - this.enclaveUrl = enclaveUrl; - return this; - } - - public PrivacyParametersBuilder setEnabled(final boolean enabled) { - this.enabled = enabled; - return this; - } - - public PrivacyParametersBuilder setMetricsSystem(final MetricsSystem metricsSystem) { - this.metricsSystem = metricsSystem; - return this; - } - - public PrivacyParametersBuilder setDataDir(final Path dataDir) { - this.dataDir = dataDir; - return this; - } - - public PrivacyParameters build() throws IOException { - PrivacyParameters config = new PrivacyParameters(); - if (enabled) { - Path privateDbPath = dataDir.resolve(PRIVATE_DATABASE_PATH); - StorageProvider privateStorageProvider = - RocksDbStorageProvider.create( - new RocksDbConfiguration.Builder().databaseDir(privateDbPath).build(), metricsSystem); - WorldStateStorage privateWorldStateStorage = privateStorageProvider.createWorldStateStorage(); - WorldStateArchive privateWorldStateArchive = new WorldStateArchive(privateWorldStateStorage); - - Path privateStateDbPath = dataDir.resolve(PRIVATE_STATE_DATABASE_PATH); - StorageProvider privateStateStorageProvider = - RocksDbStorageProvider.create( - new RocksDbConfiguration.Builder().databaseDir(privateStateDbPath).build(), - metricsSystem); - PrivateTransactionStorage privateTransactionStorage = - privateStateStorageProvider.createPrivateTransactionStorage(); - PrivateStateStorage privateStateStorage = - privateStateStorageProvider.createPrivateStateStorage(); - - config.setPrivateWorldStateArchive(privateWorldStateArchive); - config.setEnclavePublicKey(enclavePublicKey); - config.setEnclavePublicKeyFile(enclavePublicKeyFile); - config.setPrivateStorageProvider(privateStorageProvider); - config.setPrivateTransactionStorage(privateTransactionStorage); - config.setPrivateStateStorage(privateStateStorage); - } - config.setEnabled(enabled); - config.setEnclaveUri(enclaveUrl); - config.setPrivacyAddress(privacyAddress); - return config; - } - - public PrivacyParametersBuilder setEnclavePublicKeyUsingFile(final File publicKeyFile) - throws IOException { - this.enclavePublicKeyFile = publicKeyFile; - this.enclavePublicKey = Files.asCharSource(publicKeyFile, UTF_8).read(); - return this; - } -} diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 8beb026f56..6da844fe5b 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -44,7 +44,6 @@ 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.PrivacyParametersBuilder; import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; @@ -939,7 +938,7 @@ private PrivacyParameters privacyParameters() throws IOException { !isPrivacyEnabled, asList("--privacy-url", "--privacy-public-key-file", "--privacy-precompiled-address")); - final PrivacyParametersBuilder privacyParametersBuilder = new PrivacyParametersBuilder(); + final PrivacyParameters.Builder privacyParametersBuilder = new PrivacyParameters.Builder(); if (isPrivacyEnabled) { privacyParametersBuilder.setEnabled(true); privacyParametersBuilder.setEnclaveUrl(privacyUrl); diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/PrivacyTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/PrivacyTest.java index 4b4ab1549e..2fd8f1ebf2 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/PrivacyTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/PrivacyTest.java @@ -23,7 +23,6 @@ import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder; import tech.pegasys.pantheon.ethereum.core.PendingTransactions; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; -import tech.pegasys.pantheon.ethereum.core.PrivacyParametersBuilder; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import tech.pegasys.pantheon.ethereum.mainnet.PrecompiledContract; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; @@ -45,7 +44,7 @@ public class PrivacyTest { public void privacyPrecompiled() throws IOException { final Path dataDir = folder.newFolder().toPath(); PrivacyParameters privacyParameters = - new PrivacyParametersBuilder() + new PrivacyParameters.Builder() .setPrivacyAddress(ADDRESS) .setEnabled(true) .setDataDir(dataDir)