Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/upstream/master' into PAN-3023
Browse files Browse the repository at this point in the history
# Conflicts:
#	besu/src/test/java/org/hyperledger/besu/RunnerTest.java
  • Loading branch information
cfelde committed Sep 26, 2019
2 parents e0012e7 + 50c0764 commit c04fbcb
Show file tree
Hide file tree
Showing 36 changed files with 752 additions and 230 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Build Status](https://jenkins.pegasys.tech/job/Besu/job/master/badge/icon)](https://jenkins.pegasys.tech/job/Besu/job/master/)
[![Documentation Status](https://readthedocs.org/projects/hyperledger-besu/badge/?version=latest)](https://besu.hyperledger.org/en/latest/?badge=latest)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/PegasysEng/besu/blob/master/LICENSE)
[ ![Download](https://api.bintray.com/packages/hyperledger/besu-repo/besu/images/download.svg) ](https://bintray.com/hyperledger/besu-repo/besu/_latestVersion)
[ ![Download](https://api.bintray.com/packages/hyperledger-org/besu-repo/besu/images/download.svg) ](https://bintray.com/hyperledger-org/besu-repo/besu/_latestVersion)
[![RocketChat chat](https://open.rocket.chat/images/join-chat.svg)](https://chat.hyperledger.org/channel/besu)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public void startNode(final BesuNode node) {
}

final StorageServiceImpl storageService = new StorageServiceImpl();
final BesuConfiguration commonPluginConfiguration =
new BesuConfigurationImpl(Files.createTempDir().toPath());
final Path path = Files.createTempDir().toPath();
final BesuConfiguration commonPluginConfiguration = new BesuConfigurationImpl(path, path);
final BesuPluginContextImpl besuPluginContext =
besuPluginContextMap.computeIfAbsent(
node, n -> buildPluginContext(node, storageService, commonPluginConfiguration));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -146,13 +148,14 @@ public void start(final BesuNodeRunner runner) {

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) {
Expand Down Expand Up @@ -206,7 +209,8 @@ public NodeConfiguration getConfiguration() {
return besu.getConfiguration();
}

private StorageProvider createKeyValueStorageProvider(final Path dbLocation) {
private StorageProvider createKeyValueStorageProvider(
final Path dataLocation, final Path dbLocation) {
return new KeyValueStorageProviderBuilder()
.withStorageFactory(
new RocksDBKeyValuePrivacyStorageFactory(
Expand All @@ -217,7 +221,7 @@ private StorageProvider createKeyValueStorageProvider(final Path dbLocation) {
BACKGROUND_THREAD_COUNT,
CACHE_CAPACITY),
Arrays.asList(KeyValueSegmentIdentifier.values())))
.withCommonConfiguration(new BesuConfigurationImpl(dbLocation))
.withCommonConfiguration(new BesuConfigurationImpl(dataLocation, dbLocation))
.withMetricsSystem(new NoOpMetricsSystem())
.build();
}
Expand Down
10 changes: 6 additions & 4 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ void setBannedNodeIds(final List<String> values) {
names = {"--logging", "-l"},
paramLabel = "<LOG VERBOSITY LEVEL>",
description =
"Logging verbosity levels: OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL (default: ${DEFAULT-VALUE})")
private final Level logLevel = Level.INFO;
"Logging verbosity levels: OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL (default: INFO)")
private final Level logLevel = null;

@Option(
names = {"--miner-enabled"},
Expand Down Expand Up @@ -777,7 +777,9 @@ public void run() {

private void addConfigurationService() {
if (pluginCommonConfiguration == null) {
pluginCommonConfiguration = new BesuConfigurationImpl(dataDir().resolve(DATABASE_PATH));
final Path dataDir = dataDir();
pluginCommonConfiguration =
new BesuConfigurationImpl(dataDir, dataDir.resolve(DATABASE_PATH));
besuPluginContext.addService(BesuConfiguration.class, pluginCommonConfiguration);
}
}
Expand Down Expand Up @@ -936,7 +938,7 @@ protected void validateP2PInterface(final String p2pInterface) {
if (!NetworkUtility.isNetworkInterfaceAvailable(p2pInterface)) {
throw new ParameterException(commandLine, failMessage);
}
} catch (UnknownHostException | SocketException e) {
} catch (final UnknownHostException | SocketException e) {
throw new ParameterException(commandLine, failMessage, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class RetestethSubCommand implements Runnable {
paramLabel = "<LOG VERBOSITY LEVEL>",
description =
"Logging verbosity levels: OFF, FATAL, WARN, INFO, DEBUG, TRACE, ALL (default: INFO)")
private final Level logLevel = Level.INFO;
private final Level logLevel = null;

@SuppressWarnings("FieldMayBeFinal") // Because PicoCLI requires Strings to not be final.
@Option(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public BesuController<C> build() {
checkNotNull(metricsSystem, "Missing metrics system");
checkNotNull(privacyParameters, "Missing privacy parameters");
checkNotNull(dataDirectory, "Missing data directory"); // Why do we need this?
checkNotNull(clock, "Mising clock");
checkNotNull(clock, "Missing clock");
checkNotNull(transactionPoolConfiguration, "Missing transaction pool configuration");
checkNotNull(nodeKeys, "Missing node keys");
checkNotNull(storageProvider, "Must supply a storage provider");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@
public class BesuConfigurationImpl implements BesuConfiguration {

private final Path storagePath;
private final Path dataPath;

public BesuConfigurationImpl(final Path storagePath) {
public BesuConfigurationImpl(final Path dataPath, final Path storagePath) {
this.storagePath = storagePath;
this.dataPath = dataPath;
}

@Override
public Path getStoragePath() {
return storagePath;
}

@Override
public Path getDataPath() {
return dataPath;
}
}
7 changes: 4 additions & 3 deletions besu/src/test/java/org/hyperledger/besu/PrivacyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,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()
Expand Down Expand Up @@ -94,7 +95,7 @@ public void privacyPrecompiled() throws IOException {
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(
Expand All @@ -105,7 +106,7 @@ private StorageProvider createKeyValueStorageProvider(final Path dbAhead) {
BACKGROUND_THREAD_COUNT,
CACHE_CAPACITY),
Arrays.asList(KeyValueSegmentIdentifier.values())))
.withCommonConfiguration(new BesuConfigurationImpl(dbAhead))
.withCommonConfiguration(new BesuConfigurationImpl(dataDir, dbDir))
.withMetricsSystem(new NoOpMetricsSystem())
.build();
}
Expand Down
8 changes: 4 additions & 4 deletions besu/src/test/java/org/hyperledger/besu/RunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi
.privacyParameters(PrivacyParameters.DEFAULT)
.clock(TestClock.fixed())
.transactionPoolConfiguration(TransactionPoolConfiguration.builder().build())
.storageProvider(createKeyValueStorageProvider(dbAhead))
.storageProvider(createKeyValueStorageProvider(dataDirAhead, dbAhead))
.targetGasLimit(GasLimitCalculator.DEFAULT)
.build()) {
setupState(blockCount, controller.getProtocolSchedule(), controller.getProtocolContext());
Expand All @@ -169,7 +169,7 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi
.privacyParameters(PrivacyParameters.DEFAULT)
.clock(TestClock.fixed())
.transactionPoolConfiguration(TransactionPoolConfiguration.builder().build())
.storageProvider(createKeyValueStorageProvider(dbAhead))
.storageProvider(createKeyValueStorageProvider(dataDirAhead, dbAhead))
.targetGasLimit(GasLimitCalculator.DEFAULT)
.build();
final String listenHost = InetAddress.getLoopbackAddress().getHostAddress();
Expand Down Expand Up @@ -359,7 +359,7 @@ private GenesisConfigFile getFastSyncGenesis() {
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(
Expand All @@ -370,7 +370,7 @@ private StorageProvider createKeyValueStorageProvider(final Path dbAhead) {
BACKGROUND_THREAD_COUNT,
CACHE_CAPACITY),
Arrays.asList(KeyValueSegmentIdentifier.values())))
.withCommonConfiguration(new BesuConfigurationImpl(dbAhead))
.withCommonConfiguration(new BesuConfigurationImpl(dataDir, dbDir))
.withMetricsSystem(new NoOpMetricsSystem())
.build();
}
Expand Down
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ allprojects {
}

// Below this line are currently only license header tasks
format 'groovy', {
target '**/src/*/grovy/**/*.groovy'
}
format 'groovy', { target '**/src/*/grovy/**/*.groovy' }

// Currently disabled due to referencetest issues
// format 'bash', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Optional;
import java.util.stream.Stream;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Streams;
import com.google.common.io.Resources;
Expand Down Expand Up @@ -72,23 +71,7 @@ public static GenesisConfigFile development() {
}

public static GenesisConfigFile fromConfig(final String jsonString) {
try {
final ObjectNode rootNode = JsonUtil.objectNodeFromString(jsonString, false);
return fromConfig(rootNode);
} catch (final RuntimeException re) {
if (re.getCause() instanceof JsonParseException) {
// we had a runtime exception cause by a jsom parse exception.
// try again with comments enabled
final ObjectNode rootNode = JsonUtil.objectNodeFromString(jsonString, true);
// if we get here comments is what broke things, warn and move on.
LOG.warn(
"The provided genesis file contains comments. "
+ "In a future release of Besu this will not be supported.");
return fromConfig(rootNode);
} else {
throw re;
}
}
return fromConfig(JsonUtil.objectNodeFromString(jsonString, false));
}

public static GenesisConfigFile fromConfig(final ObjectNode config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import com.fasterxml.jackson.core.JsonParseException;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.Test;

Expand Down Expand Up @@ -208,14 +209,13 @@ public void shouldGetLargeChainId() {
}

@Test
public void acceptComments() {
// this test will change in the future to reject comments.
final GenesisConfigFile config =
GenesisConfigFile.fromConfig(
"{\"config\": { \"chainId\": 2017 }\n/* C comment }*/\n//C++ comment }\n}");

assertThat(config.getConfigOptions().getChainId()).contains(new BigInteger("2017"));
// Unfortunately there is no good (non-flakey) way to assert logs.
public void mustNotAcceptComments() {
assertThatThrownBy(
() ->
GenesisConfigFile.fromConfig(
"{\"config\": { \"chainId\": 2017 }\n/* C comment }*/\n//C++ comment }\n}"))
.hasCauseInstanceOf(JsonParseException.class)
.hasMessageContaining("Unexpected character ('/'");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ public static GraphQLError of(final TransactionInvalidReason transactionInvalidR
case UPFRONT_COST_EXCEEDS_BALANCE:
return TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE;
case NONCE_TOO_LOW:
case PRIVATE_NONCE_TOO_LOW:
return NONCE_TOO_LOW;
case INCORRECT_NONCE:
case INCORRECT_PRIVATE_NONCE:
return INCORRECT_NONCE;
case INTRINSIC_GAS_EXCEEDS_GAS_LIMIT:
return INTRINSIC_GAS_EXCEEDS_LIMIT;
Expand All @@ -87,10 +89,6 @@ public static GraphQLError of(final TransactionInvalidReason transactionInvalidR
// Private Transaction Invalid Reasons
case PRIVATE_TRANSACTION_FAILED:
return PRIVATE_TRANSACTION_FAILED;
case PRIVATE_NONCE_TOO_LOW:
return PRIVATE_NONCE_TOO_LOW;
case INCORRECT_PRIVATE_NONCE:
return INCORRECT_PRIVATE_NONCE;
case GAS_PRICE_TOO_LOW:
return GAS_PRICE_TOO_LOW;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public static JsonRpcError convertTransactionInvalidReason(
final TransactionInvalidReason reason) {
switch (reason) {
case NONCE_TOO_LOW:
case PRIVATE_NONCE_TOO_LOW:
return JsonRpcError.NONCE_TOO_LOW;
case INCORRECT_NONCE:
case INCORRECT_PRIVATE_NONCE:
return JsonRpcError.INCORRECT_NONCE;
case INVALID_SIGNATURE:
return JsonRpcError.INVALID_TRANSACTION_SIGNATURE;
Expand All @@ -39,10 +41,6 @@ public static JsonRpcError convertTransactionInvalidReason(
// Private Transaction Invalid Reasons
case CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE:
return JsonRpcError.CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE;
case PRIVATE_NONCE_TOO_LOW:
return JsonRpcError.PRIVATE_NONCE_TOO_LOW;
case INCORRECT_PRIVATE_NONCE:
return JsonRpcError.INCORRECT_PRIVATE_NONCE;
case GAS_PRICE_TOO_LOW:
return JsonRpcError.GAS_PRICE_TOO_LOW;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.privacy.PrivateTransaction;
import org.hyperledger.besu.ethereum.privacy.PrivateTransactionHandler;
import org.hyperledger.besu.util.bytes.BytesValues;

public class PrivDistributeRawTransaction extends AbstractSendTransaction implements JsonRpcMethod {

Expand Down Expand Up @@ -72,6 +73,8 @@ public JsonRpcResponse response(final JsonRpcRequest request) {
request,
privateTransaction,
privacyGroupId,
() -> new JsonRpcSuccessResponse(request.getId(), privateTransaction.hash().toString()));
() ->
new JsonRpcSuccessResponse(
request.getId(), BytesValues.fromBase64(enclaveKey).toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ public enum JsonRpcError {

// Private transaction errors
ENCLAVE_ERROR(-50100, "Error communicating with enclave"),
PRIVATE_NONCE_TOO_LOW(-50100, "Private transaction nonce too low"),
INCORRECT_PRIVATE_NONCE(-50100, "Private transaction nonce is incorrect"),
UNIMPLEMENTED_PRIVATE_TRANSACTION_TYPE(-50100, "Unimplemented private transaction type"),
PRIVACY_NOT_ENABLED(-50100, "Privacy is not enabled to get the precompiled address"),
CREATE_PRIVACY_GROUP_ERROR(-50100, "Error creating privacy group"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.hyperledger.besu.ethereum.mainnet.ValidationResult;
import org.hyperledger.besu.ethereum.privacy.PrivateTransaction;
import org.hyperledger.besu.ethereum.privacy.PrivateTransactionHandler;
import org.hyperledger.besu.util.bytes.BytesValues;

import org.junit.Before;
import org.junit.Test;
Expand All @@ -47,7 +48,7 @@ public class PrivDistributeRawTransactionTest {
+ "200e885ff29e973e2576b6600181d1b0a2b5294e30d9be4a1981"
+ "ffb33a0b8c8a72657374726963746564";

final String MOCK_ORION_KEY = "";
final String MOCK_ORION_KEY = "93Ky7lXwFkMc7+ckoFgUMku5bpr9tz4zhmWmk9RlNng=";
private final String MOCK_PRIVACY_GROUP = "";

@Mock private TransactionPool transactionPool;
Expand Down Expand Up @@ -82,7 +83,7 @@ public void validTransactionHashReturnedAfterDistribute() throws Exception {

final JsonRpcResponse expectedResponse =
new JsonRpcSuccessResponse(
request.getId(), "0x34d3db0593e0dad50104cc575db154b6e1a57ff3fc0354b2df2f25c8f21aca66");
request.getId(), BytesValues.fromBase64(MOCK_ORION_KEY).toString());

final JsonRpcResponse actualResponse = method.response(request);

Expand Down
Loading

0 comments on commit c04fbcb

Please sign in to comment.