Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/hyperledger/besu
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonybuckle committed Mar 3, 2020
2 parents 27d870b + b9e0b3b commit af1e76a
Show file tree
Hide file tree
Showing 32 changed files with 893 additions and 419 deletions.
1 change: 1 addition & 0 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
| Mark Terry | mark-terry | m.terry |
| Meredith Baxter | mbaxter | mbaxter |
| Nicolas Massart | NicolasMassart | NicolasMassart |
| Stefan Pingel | pinges | pinges |
| Trent Mohay | rain-on | trent.mohay |
| Rai Sur | RatanRSur | ratanraisur |
| Rob Dawson | rojotek | RobDawson |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
public class PrivacyAcceptanceTestBase {
@ClassRule public static final TemporaryFolder privacy = new TemporaryFolder();

protected static final long POW_CHAIN_ID = 2018;

protected final PrivacyTransactions privacyTransactions;
protected final PrivateContractVerifier privateContractVerifier;
protected final PrivateTransactionVerifier privateTransactionVerifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
*/
package org.hyperledger.besu.tests.acceptance.dsl.privacy.transaction;

import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyNode;
import org.hyperledger.besu.tests.acceptance.dsl.privacy.condition.PrivGetTransactionReceiptTransaction;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivGetCodeTransaction;

import java.util.List;

Expand All @@ -39,4 +41,9 @@ public PrivDistributeTransactionTransaction privDistributeTransaction(
final String signedPrivateTransaction) {
return new PrivDistributeTransactionTransaction(signedPrivateTransaction);
}

public PrivGetCodeTransaction privGetCode(
final String privacyGroupId, final Address contractAddress, final String blockParameter) {
return new PrivGetCodeTransaction(privacyGroupId, contractAddress, blockParameter);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy;

import static org.assertj.core.api.Assertions.assertThat;

import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction;

import java.io.IOException;

import org.apache.tuweni.bytes.Bytes;

public class PrivGetCodeTransaction implements Transaction<Bytes> {

private final String privacyGroupId;
private final Address contractAddress;
private final String blockParameter;

public PrivGetCodeTransaction(
final String privacyGroupId, final Address contractAddress, final String blockParameter) {
this.privacyGroupId = privacyGroupId;
this.contractAddress = contractAddress;
this.blockParameter = blockParameter;
}

@Override
public Bytes execute(final NodeRequests node) {
try {
final PrivacyRequestFactory.GetCodeResponse response =
node.privacy()
.privGetCode(privacyGroupId, contractAddress.toHexString(), blockParameter)
.send();
assertThat(response).as("check response is not null").isNotNull();
assertThat(response.getResult()).as("check code in response isn't null").isNotNull();
return Bytes.fromHexString(response.getResult());
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static class SendRawTransactionResponse extends Response<Hash> {}
public static class GetTransactionReceiptResponse extends Response<PrivateTransactionReceipt> {}

public static class GetTransactionCountResponse extends Response<Integer> {

final Integer count;

@JsonCreator
Expand All @@ -63,6 +64,8 @@ public Integer getCount() {
}
}

public static class GetCodeResponse extends Response<String> {}

public Request<?, PrivDistributeTransactionResponse> privDistributeTransaction(
final String signedPrivateTransaction) {
return new Request<>(
Expand Down Expand Up @@ -167,4 +170,13 @@ public Request<?, GetTransactionCountResponse> privGetEeaTransactionCount(final
web3jService,
GetTransactionCountResponse.class);
}

public Request<?, GetCodeResponse> privGetCode(
final String privacyGroupId, final String contractAddress, final String blockParameter) {
return new Request<>(
"priv_getCode",
List.of(privacyGroupId, contractAddress, blockParameter),
web3jService,
GetCodeResponse.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.tests.web3j.privacy;

import static org.assertj.core.api.Assertions.assertThat;

import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyAcceptanceTestBase;
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyNode;
import org.hyperledger.besu.tests.web3j.generated.EventEmitter;

import org.apache.tuweni.bytes.Bytes;
import org.junit.Before;
import org.junit.Test;
import org.web3j.protocol.besu.response.privacy.PrivacyGroup;
import org.web3j.utils.Base64String;

public class PrivGetCodeAcceptanceTest extends PrivacyAcceptanceTestBase {

private PrivacyNode alice;

@Before
public void setUp() throws Exception {
alice =
privacyBesu.createPrivateTransactionEnabledMinerNode(
"alice", privacyAccountResolver.resolve(0));
privacyCluster.start(alice);
}

@Test
public void privGetCodeReturnsDeployedContractBytecode() {
final String privacyGroupId = createPrivacyGroup();
final EventEmitter eventEmitterContract = deployPrivateContract(privacyGroupId);

final Bytes deployedContractCode =
alice.execute(
privacyTransactions.privGetCode(
privacyGroupId,
Address.fromHexString(eventEmitterContract.getContractAddress()),
"latest"));

assertThat(eventEmitterContract.getContractBinary())
.contains(deployedContractCode.toUnprefixedHexString());
}

private EventEmitter deployPrivateContract(final String privacyGroupId) {
final EventEmitter eventEmitter =
alice.execute(
privateContractTransactions.createSmartContractWithPrivacyGroupId(
EventEmitter.class,
alice.getTransactionSigningKey(),
POW_CHAIN_ID,
alice.getEnclaveKey(),
privacyGroupId));

privateContractVerifier
.validPrivateContractDeployed(
eventEmitter.getContractAddress(), alice.getAddress().toString())
.verify(eventEmitter);
return eventEmitter;
}

private String createPrivacyGroup() {
final String privacyGroupId =
alice.execute(
privacyTransactions.createPrivacyGroup("myGroupName", "my group description", alice));

assertThat(privacyGroupId).isNotNull();

final PrivacyGroup expected =
new PrivacyGroup(
privacyGroupId,
PrivacyGroup.Type.PANTHEON,
"myGroupName",
"my group description",
Base64String.wrapList(alice.getEnclaveKey()));

alice.verify(privateTransactionVerifier.validPrivacyGroupCreated(expected));

return privacyGroupId;
}
}
35 changes: 26 additions & 9 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.hyperledger.besu.cli.options.EthProtocolOptions;
import org.hyperledger.besu.cli.options.MetricsCLIOptions;
import org.hyperledger.besu.cli.options.NetworkingOptions;
import org.hyperledger.besu.cli.options.PrunerOptions;
import org.hyperledger.besu.cli.options.SynchronizerOptions;
import org.hyperledger.besu.cli.options.TransactionPoolOptions;
import org.hyperledger.besu.cli.presynctasks.PreSynchronizationTaskRunner;
Expand Down Expand Up @@ -95,6 +94,7 @@
import org.hyperledger.besu.ethereum.privacy.storage.keyvalue.PrivacyKeyValueStorageProviderBuilder;
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProvider;
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder;
import org.hyperledger.besu.ethereum.worldstate.PrunerConfiguration;
import org.hyperledger.besu.metrics.BesuMetricCategory;
import org.hyperledger.besu.metrics.MetricCategoryRegistryImpl;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
Expand Down Expand Up @@ -194,7 +194,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
final EthProtocolOptions ethProtocolOptions = EthProtocolOptions.create();
final MetricsCLIOptions metricsCLIOptions = MetricsCLIOptions.create();
final TransactionPoolOptions transactionPoolOptions = TransactionPoolOptions.create();
final PrunerOptions prunerOptions = PrunerOptions.create();
private final RunnerBuilder runnerBuilder;
private final BesuController.Builder controllerBuilderFactory;
private final BesuPluginContextImpl besuPluginContext;
Expand Down Expand Up @@ -629,9 +628,8 @@ void setBannedNodeIds(final List<String> values) {
@Option(
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 = LogManager.getRootLogger().getLevel();
description = "Logging verbosity levels: OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL")
private final Level logLevel = null;

@Option(
names = {"--miner-enabled"},
Expand Down Expand Up @@ -816,6 +814,25 @@ void setBannedNodeIds(final List<String> values) {
private final Map<String, String> genesisConfigOverrides =
new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

@Option(
names = {"--pruning-blocks-retained"},
defaultValue = "1024",
paramLabel = "<INTEGER>",
description =
"Minimum number of recent blocks for which to keep entire world state (default: ${DEFAULT-VALUE})",
arity = "1")
private final Integer pruningBlocksRetained = PrunerConfiguration.DEFAULT_PRUNING_BLOCKS_RETAINED;

@Option(
names = {"--pruning-block-confirmations"},
defaultValue = "10",
paramLabel = "<INTEGER>",
description =
"Minimum number of confirmations on a block before marking begins (default: ${DEFAULT-VALUE})",
arity = "1")
private final Integer pruningBlockConfirmations =
PrunerConfiguration.DEFAULT_PRUNING_BLOCK_CONFIRMATIONS;

private EthNetworkConfig ethNetworkConfig;
private JsonRpcConfiguration jsonRpcConfiguration;
private GraphQLConfiguration graphQLConfiguration;
Expand Down Expand Up @@ -894,7 +911,6 @@ public void run() {
try {
configureLogging(true);
logger.info("Starting Besu version: {}", BesuInfo.nodeName(identityString));

// Need to create vertx after cmdline has been parsed, such that metricSystem is configurable
vertx = createVertx(createVertxOptions(metricsSystem.get()));

Expand Down Expand Up @@ -979,7 +995,6 @@ private BesuCommand handleUnstableOptions() {
.put("P2P Network", networkingOptions)
.put("Synchronizer", synchronizerOptions)
.put("TransactionPool", transactionPoolOptions)
.put("Pruner", prunerOptions)
.build();

UnstableOptionsSubCommand.createUnstableOptions(commandLine, unstableOptions);
Expand Down Expand Up @@ -1212,7 +1227,8 @@ public BesuControllerBuilder<?> getControllerBuilder() {
.isRevertReasonEnabled(isRevertReasonEnabled)
.storageProvider(keyStorageProvider(keyValueStorageName))
.isPruningEnabled(isPruningEnabled())
.pruningConfiguration(prunerOptions.toDomainObject())
.pruningConfiguration(
new PrunerConfiguration(pruningBlockConfirmations, pruningBlocksRetained))
.genesisConfigOverrides(genesisConfigOverrides)
.targetGasLimit(targetGasLimit == null ? Optional.empty() : Optional.of(targetGasLimit))
.requiredBlocks(requiredBlocks);
Expand Down Expand Up @@ -2022,7 +2038,8 @@ public BesuExceptionHandler exceptionHandler() {
return new BesuExceptionHandler(this::getLogLevel);
}

private Level getLogLevel() {
@VisibleForTesting
Level getLogLevel() {
return logLevel;
}
}

This file was deleted.

Loading

0 comments on commit af1e76a

Please sign in to comment.