Clean up BesuConfiguration construction (#51)

Signed-off-by: Meredith Baxter <meredith.baxter@consensys.net>
pull/53/head
mbaxter 5 years ago committed by GitHub
parent 78ecf33237
commit 1937f1251d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivacyNode.java
  2. 2
      besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
  3. 6
      besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java
  4. 7
      besu/src/test/java/org/hyperledger/besu/PrivacyTest.java
  5. 8
      besu/src/test/java/org/hyperledger/besu/RunnerTest.java
  6. 6
      ethereum/eth/src/jmh/java/org/hyperledger/besu/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java

@ -14,6 +14,8 @@
*/ */
package org.hyperledger.besu.tests.acceptance.dsl.privacy; 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.controller.KeyPairUtil;
import org.hyperledger.besu.enclave.Enclave; import org.hyperledger.besu.enclave.Enclave;
import org.hyperledger.besu.enclave.EnclaveException; import org.hyperledger.besu.enclave.EnclaveException;
@ -146,13 +148,14 @@ public class PrivacyNode implements AutoCloseable {
try { try {
final Path dataDir = Files.createTempDirectory("acctest-privacy"); final Path dataDir = Files.createTempDirectory("acctest-privacy");
final Path dbDir = dataDir.resolve(DATABASE_PATH);
privacyParameters = privacyParameters =
new PrivacyParameters.Builder() new PrivacyParameters.Builder()
.setEnabled(true) .setEnabled(true)
.setEnclaveUrl(orion.clientUrl()) .setEnclaveUrl(orion.clientUrl())
.setEnclavePublicKeyUsingFile(orion.getConfig().publicKeys().get(0).toFile()) .setEnclavePublicKeyUsingFile(orion.getConfig().publicKeys().get(0).toFile())
.setStorageProvider(createKeyValueStorageProvider(dataDir)) .setStorageProvider(createKeyValueStorageProvider(dataDir, dbDir))
.setPrivateKeyPath(KeyPairUtil.getDefaultKeyFile(besu.homeDirectory()).toPath()) .setPrivateKeyPath(KeyPairUtil.getDefaultKeyFile(besu.homeDirectory()).toPath())
.build(); .build();
} catch (IOException e) { } catch (IOException e) {
@ -206,7 +209,8 @@ public class PrivacyNode implements AutoCloseable {
return besu.getConfiguration(); return besu.getConfiguration();
} }
private StorageProvider createKeyValueStorageProvider(final Path dbLocation) { private StorageProvider createKeyValueStorageProvider(
final Path dataLocation, final Path dbLocation) {
return new KeyValueStorageProviderBuilder() return new KeyValueStorageProviderBuilder()
.withStorageFactory( .withStorageFactory(
new RocksDBKeyValuePrivacyStorageFactory( new RocksDBKeyValuePrivacyStorageFactory(
@ -217,7 +221,7 @@ public class PrivacyNode implements AutoCloseable {
BACKGROUND_THREAD_COUNT, BACKGROUND_THREAD_COUNT,
CACHE_CAPACITY), CACHE_CAPACITY),
Arrays.asList(KeyValueSegmentIdentifier.values()))) Arrays.asList(KeyValueSegmentIdentifier.values())))
.withCommonConfiguration(new BesuConfigurationImpl(dbLocation)) .withCommonConfiguration(new BesuConfigurationImpl(dataLocation, dbLocation))
.withMetricsSystem(new NoOpMetricsSystem()) .withMetricsSystem(new NoOpMetricsSystem())
.build(); .build();
} }

@ -773,7 +773,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
if (pluginCommonConfiguration == null) { if (pluginCommonConfiguration == null) {
final Path dataDir = dataDir(); final Path dataDir = dataDir();
pluginCommonConfiguration = pluginCommonConfiguration =
new BesuConfigurationImpl(dataDir.resolve(DATABASE_PATH), dataDir); new BesuConfigurationImpl(dataDir, dataDir.resolve(DATABASE_PATH));
besuPluginContext.addService(BesuConfiguration.class, pluginCommonConfiguration); besuPluginContext.addService(BesuConfiguration.class, pluginCommonConfiguration);
} }
} }

@ -23,11 +23,7 @@ public class BesuConfigurationImpl implements BesuConfiguration {
private final Path storagePath; private final Path storagePath;
private final Path dataPath; private final Path dataPath;
public BesuConfigurationImpl(final Path storagePath) { public BesuConfigurationImpl(final Path dataPath, final Path storagePath) {
this(storagePath, storagePath);
}
public BesuConfigurationImpl(final Path storagePath, final Path dataPath) {
this.storagePath = storagePath; this.storagePath = storagePath;
this.dataPath = dataPath; this.dataPath = dataPath;
} }

@ -59,11 +59,12 @@ public class PrivacyTest {
@Test @Test
public void privacyPrecompiled() throws IOException { public void privacyPrecompiled() throws IOException {
final Path dataDir = folder.newFolder().toPath(); final Path dataDir = folder.newFolder().toPath();
final Path dbDir = dataDir.resolve("database");
final PrivacyParameters privacyParameters = final PrivacyParameters privacyParameters =
new PrivacyParameters.Builder() new PrivacyParameters.Builder()
.setPrivacyAddress(ADDRESS) .setPrivacyAddress(ADDRESS)
.setEnabled(true) .setEnabled(true)
.setStorageProvider(createKeyValueStorageProvider(dataDir)) .setStorageProvider(createKeyValueStorageProvider(dataDir, dbDir))
.build(); .build();
final BesuController<?> besuController = final BesuController<?> besuController =
new BesuController.Builder() new BesuController.Builder()
@ -92,7 +93,7 @@ public class PrivacyTest {
assertThat(precompiledContract.getName()).isEqualTo("Privacy"); assertThat(precompiledContract.getName()).isEqualTo("Privacy");
} }
private StorageProvider createKeyValueStorageProvider(final Path dbAhead) { private StorageProvider createKeyValueStorageProvider(final Path dataDir, final Path dbDir) {
return new KeyValueStorageProviderBuilder() return new KeyValueStorageProviderBuilder()
.withStorageFactory( .withStorageFactory(
new RocksDBKeyValuePrivacyStorageFactory( new RocksDBKeyValuePrivacyStorageFactory(
@ -103,7 +104,7 @@ public class PrivacyTest {
BACKGROUND_THREAD_COUNT, BACKGROUND_THREAD_COUNT,
CACHE_CAPACITY), CACHE_CAPACITY),
Arrays.asList(KeyValueSegmentIdentifier.values()))) Arrays.asList(KeyValueSegmentIdentifier.values())))
.withCommonConfiguration(new BesuConfigurationImpl(dbAhead)) .withCommonConfiguration(new BesuConfigurationImpl(dataDir, dbDir))
.withMetricsSystem(new NoOpMetricsSystem()) .withMetricsSystem(new NoOpMetricsSystem())
.build(); .build();
} }

@ -148,7 +148,7 @@ public final class RunnerTest {
.privacyParameters(PrivacyParameters.DEFAULT) .privacyParameters(PrivacyParameters.DEFAULT)
.clock(TestClock.fixed()) .clock(TestClock.fixed())
.transactionPoolConfiguration(TransactionPoolConfiguration.builder().build()) .transactionPoolConfiguration(TransactionPoolConfiguration.builder().build())
.storageProvider(createKeyValueStorageProvider(dbAhead)) .storageProvider(createKeyValueStorageProvider(dataDirAhead, dbAhead))
.build()) { .build()) {
setupState(blockCount, controller.getProtocolSchedule(), controller.getProtocolContext()); setupState(blockCount, controller.getProtocolSchedule(), controller.getProtocolContext());
} }
@ -167,7 +167,7 @@ public final class RunnerTest {
.privacyParameters(PrivacyParameters.DEFAULT) .privacyParameters(PrivacyParameters.DEFAULT)
.clock(TestClock.fixed()) .clock(TestClock.fixed())
.transactionPoolConfiguration(TransactionPoolConfiguration.builder().build()) .transactionPoolConfiguration(TransactionPoolConfiguration.builder().build())
.storageProvider(createKeyValueStorageProvider(dbAhead)) .storageProvider(createKeyValueStorageProvider(dataDirAhead, dbAhead))
.build(); .build();
final String listenHost = InetAddress.getLoopbackAddress().getHostAddress(); final String listenHost = InetAddress.getLoopbackAddress().getHostAddress();
final JsonRpcConfiguration aheadJsonRpcConfiguration = jsonRpcConfiguration(); final JsonRpcConfiguration aheadJsonRpcConfiguration = jsonRpcConfiguration();
@ -355,7 +355,7 @@ public final class RunnerTest {
return GenesisConfigFile.fromConfig(jsonNode); return GenesisConfigFile.fromConfig(jsonNode);
} }
private StorageProvider createKeyValueStorageProvider(final Path dbAhead) { private StorageProvider createKeyValueStorageProvider(final Path dataDir, final Path dbDir) {
return new KeyValueStorageProviderBuilder() return new KeyValueStorageProviderBuilder()
.withStorageFactory( .withStorageFactory(
new RocksDBKeyValueStorageFactory( new RocksDBKeyValueStorageFactory(
@ -366,7 +366,7 @@ public final class RunnerTest {
BACKGROUND_THREAD_COUNT, BACKGROUND_THREAD_COUNT,
CACHE_CAPACITY), CACHE_CAPACITY),
Arrays.asList(KeyValueSegmentIdentifier.values()))) Arrays.asList(KeyValueSegmentIdentifier.values())))
.withCommonConfiguration(new BesuConfigurationImpl(dbAhead)) .withCommonConfiguration(new BesuConfigurationImpl(dataDir, dbDir))
.withMetricsSystem(new NoOpMetricsSystem()) .withMetricsSystem(new NoOpMetricsSystem())
.build(); .build();
} }

@ -100,7 +100,7 @@ public class WorldStateDownloaderBenchmark {
final EthContext ethContext = ethProtocolManager.ethContext(); final EthContext ethContext = ethProtocolManager.ethContext();
final StorageProvider storageProvider = final StorageProvider storageProvider =
createKeyValueStorageProvider(tempDir.resolve("database")); createKeyValueStorageProvider(tempDir, tempDir.resolve("database"));
worldStateStorage = storageProvider.createWorldStateStorage(); worldStateStorage = storageProvider.createWorldStateStorage();
pendingRequests = pendingRequests =
@ -158,7 +158,7 @@ public class WorldStateDownloaderBenchmark {
return rootData; return rootData;
} }
private StorageProvider createKeyValueStorageProvider(final Path dbAhead) { private StorageProvider createKeyValueStorageProvider(final Path dataDir, final Path dbDir) {
return new KeyValueStorageProviderBuilder() return new KeyValueStorageProviderBuilder()
.withStorageFactory( .withStorageFactory(
new RocksDBKeyValueStorageFactory( new RocksDBKeyValueStorageFactory(
@ -169,7 +169,7 @@ public class WorldStateDownloaderBenchmark {
DEFAULT_BACKGROUND_THREAD_COUNT, DEFAULT_BACKGROUND_THREAD_COUNT,
DEFAULT_CACHE_CAPACITY), DEFAULT_CACHE_CAPACITY),
Arrays.asList(KeyValueSegmentIdentifier.values()))) Arrays.asList(KeyValueSegmentIdentifier.values())))
.withCommonConfiguration(new BesuConfigurationImpl(dbAhead)) .withCommonConfiguration(new BesuConfigurationImpl(dataDir, dbDir))
.withMetricsSystem(new NoOpMetricsSystem()) .withMetricsSystem(new NoOpMetricsSystem())
.build(); .build();
} }

Loading…
Cancel
Save