From 1937f1251d87c5e11ed0cf62025b51dcb5364145 Mon Sep 17 00:00:00 2001 From: mbaxter Date: Wed, 25 Sep 2019 15:29:18 -0400 Subject: [PATCH] Clean up BesuConfiguration construction (#51) Signed-off-by: Meredith Baxter --- .../besu/tests/acceptance/dsl/privacy/PrivacyNode.java | 10 +++++++--- .../java/org/hyperledger/besu/cli/BesuCommand.java | 2 +- .../besu/services/BesuConfigurationImpl.java | 6 +----- .../test/java/org/hyperledger/besu/PrivacyTest.java | 7 ++++--- .../src/test/java/org/hyperledger/besu/RunnerTest.java | 8 ++++---- .../sync/worldstate/WorldStateDownloaderBenchmark.java | 6 +++--- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivacyNode.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivacyNode.java index d3b2af22c9..f01865ffe7 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivacyNode.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivacyNode.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.tests.acceptance.dsl.privacy; +import static org.hyperledger.besu.controller.BesuController.DATABASE_PATH; + import org.hyperledger.besu.controller.KeyPairUtil; import org.hyperledger.besu.enclave.Enclave; import org.hyperledger.besu.enclave.EnclaveException; @@ -146,13 +148,14 @@ public class PrivacyNode implements AutoCloseable { try { final Path dataDir = Files.createTempDirectory("acctest-privacy"); + final Path dbDir = dataDir.resolve(DATABASE_PATH); privacyParameters = new PrivacyParameters.Builder() .setEnabled(true) .setEnclaveUrl(orion.clientUrl()) .setEnclavePublicKeyUsingFile(orion.getConfig().publicKeys().get(0).toFile()) - .setStorageProvider(createKeyValueStorageProvider(dataDir)) + .setStorageProvider(createKeyValueStorageProvider(dataDir, dbDir)) .setPrivateKeyPath(KeyPairUtil.getDefaultKeyFile(besu.homeDirectory()).toPath()) .build(); } catch (IOException e) { @@ -206,7 +209,8 @@ public class PrivacyNode implements AutoCloseable { return besu.getConfiguration(); } - private StorageProvider createKeyValueStorageProvider(final Path dbLocation) { + private StorageProvider createKeyValueStorageProvider( + final Path dataLocation, final Path dbLocation) { return new KeyValueStorageProviderBuilder() .withStorageFactory( new RocksDBKeyValuePrivacyStorageFactory( @@ -217,7 +221,7 @@ public class PrivacyNode implements AutoCloseable { BACKGROUND_THREAD_COUNT, CACHE_CAPACITY), Arrays.asList(KeyValueSegmentIdentifier.values()))) - .withCommonConfiguration(new BesuConfigurationImpl(dbLocation)) + .withCommonConfiguration(new BesuConfigurationImpl(dataLocation, dbLocation)) .withMetricsSystem(new NoOpMetricsSystem()) .build(); } diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 00fcfcc9f9..ae661f6fa5 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -773,7 +773,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { if (pluginCommonConfiguration == null) { final Path dataDir = dataDir(); pluginCommonConfiguration = - new BesuConfigurationImpl(dataDir.resolve(DATABASE_PATH), dataDir); + new BesuConfigurationImpl(dataDir, dataDir.resolve(DATABASE_PATH)); besuPluginContext.addService(BesuConfiguration.class, pluginCommonConfiguration); } } diff --git a/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java b/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java index d64ff96d95..5c3d5cd5d1 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java @@ -23,11 +23,7 @@ public class BesuConfigurationImpl implements BesuConfiguration { private final Path storagePath; private final Path dataPath; - public BesuConfigurationImpl(final Path storagePath) { - this(storagePath, storagePath); - } - - public BesuConfigurationImpl(final Path storagePath, final Path dataPath) { + public BesuConfigurationImpl(final Path dataPath, final Path storagePath) { this.storagePath = storagePath; this.dataPath = dataPath; } diff --git a/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java b/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java index 2eea7c57f7..c3eb5b42fd 100644 --- a/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java +++ b/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java @@ -59,11 +59,12 @@ public class PrivacyTest { @Test public void privacyPrecompiled() throws IOException { final Path dataDir = folder.newFolder().toPath(); + final Path dbDir = dataDir.resolve("database"); final PrivacyParameters privacyParameters = new PrivacyParameters.Builder() .setPrivacyAddress(ADDRESS) .setEnabled(true) - .setStorageProvider(createKeyValueStorageProvider(dataDir)) + .setStorageProvider(createKeyValueStorageProvider(dataDir, dbDir)) .build(); final BesuController besuController = new BesuController.Builder() @@ -92,7 +93,7 @@ public class PrivacyTest { assertThat(precompiledContract.getName()).isEqualTo("Privacy"); } - private StorageProvider createKeyValueStorageProvider(final Path dbAhead) { + private StorageProvider createKeyValueStorageProvider(final Path dataDir, final Path dbDir) { return new KeyValueStorageProviderBuilder() .withStorageFactory( new RocksDBKeyValuePrivacyStorageFactory( @@ -103,7 +104,7 @@ public class PrivacyTest { BACKGROUND_THREAD_COUNT, CACHE_CAPACITY), Arrays.asList(KeyValueSegmentIdentifier.values()))) - .withCommonConfiguration(new BesuConfigurationImpl(dbAhead)) + .withCommonConfiguration(new BesuConfigurationImpl(dataDir, dbDir)) .withMetricsSystem(new NoOpMetricsSystem()) .build(); } diff --git a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java index 01f0dc4a66..6348ac07bf 100644 --- a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java +++ b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java @@ -148,7 +148,7 @@ public final class RunnerTest { .privacyParameters(PrivacyParameters.DEFAULT) .clock(TestClock.fixed()) .transactionPoolConfiguration(TransactionPoolConfiguration.builder().build()) - .storageProvider(createKeyValueStorageProvider(dbAhead)) + .storageProvider(createKeyValueStorageProvider(dataDirAhead, dbAhead)) .build()) { setupState(blockCount, controller.getProtocolSchedule(), controller.getProtocolContext()); } @@ -167,7 +167,7 @@ public final class RunnerTest { .privacyParameters(PrivacyParameters.DEFAULT) .clock(TestClock.fixed()) .transactionPoolConfiguration(TransactionPoolConfiguration.builder().build()) - .storageProvider(createKeyValueStorageProvider(dbAhead)) + .storageProvider(createKeyValueStorageProvider(dataDirAhead, dbAhead)) .build(); final String listenHost = InetAddress.getLoopbackAddress().getHostAddress(); final JsonRpcConfiguration aheadJsonRpcConfiguration = jsonRpcConfiguration(); @@ -355,7 +355,7 @@ public final class RunnerTest { return GenesisConfigFile.fromConfig(jsonNode); } - private StorageProvider createKeyValueStorageProvider(final Path dbAhead) { + private StorageProvider createKeyValueStorageProvider(final Path dataDir, final Path dbDir) { return new KeyValueStorageProviderBuilder() .withStorageFactory( new RocksDBKeyValueStorageFactory( @@ -366,7 +366,7 @@ public final class RunnerTest { BACKGROUND_THREAD_COUNT, CACHE_CAPACITY), Arrays.asList(KeyValueSegmentIdentifier.values()))) - .withCommonConfiguration(new BesuConfigurationImpl(dbAhead)) + .withCommonConfiguration(new BesuConfigurationImpl(dataDir, dbDir)) .withMetricsSystem(new NoOpMetricsSystem()) .build(); } diff --git a/ethereum/eth/src/jmh/java/org/hyperledger/besu/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java b/ethereum/eth/src/jmh/java/org/hyperledger/besu/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java index 896dfa45c5..c720ed5311 100644 --- a/ethereum/eth/src/jmh/java/org/hyperledger/besu/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java +++ b/ethereum/eth/src/jmh/java/org/hyperledger/besu/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java @@ -100,7 +100,7 @@ public class WorldStateDownloaderBenchmark { final EthContext ethContext = ethProtocolManager.ethContext(); final StorageProvider storageProvider = - createKeyValueStorageProvider(tempDir.resolve("database")); + createKeyValueStorageProvider(tempDir, tempDir.resolve("database")); worldStateStorage = storageProvider.createWorldStateStorage(); pendingRequests = @@ -158,7 +158,7 @@ public class WorldStateDownloaderBenchmark { return rootData; } - private StorageProvider createKeyValueStorageProvider(final Path dbAhead) { + private StorageProvider createKeyValueStorageProvider(final Path dataDir, final Path dbDir) { return new KeyValueStorageProviderBuilder() .withStorageFactory( new RocksDBKeyValueStorageFactory( @@ -169,7 +169,7 @@ public class WorldStateDownloaderBenchmark { DEFAULT_BACKGROUND_THREAD_COUNT, DEFAULT_CACHE_CAPACITY), Arrays.asList(KeyValueSegmentIdentifier.values()))) - .withCommonConfiguration(new BesuConfigurationImpl(dbAhead)) + .withCommonConfiguration(new BesuConfigurationImpl(dataDir, dbDir)) .withMetricsSystem(new NoOpMetricsSystem()) .build(); }