Skip to content
This repository was archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Merges #1736, #1762, #1778, #1777 to release-1.2 (#1791)
Browse files Browse the repository at this point in the history
* [PAN-2943] Renames various eea methods to priv methods, with associated docs (#1736)

* Renames various eea methods to priv methods, with associated docs

* Restructures packages

* Adds priv commandline switch

* Refactors eea_getTransactionCount and eea_getPrivateTransaction to priv

* Changes package structure and fixes TODO

* Remove whitespace

* Update docs with new method names

* [PAN-2972] Additional integration test for contract creation with privacyGroupId (#1762)

* Unit test for send raw transaction with privacy group

* Integration test works a bit better now, need to abstract to a separate subclass, fix verifyForParticipants logic bug

* Abstracts nodeCanDeployWithPrivacyGroupId to separate acceptance test

* Tidies up integration test

* Fix whitespace

* Fix inspection issues

* Restructure private transaction builder

* Fix default privateFrom behaviour

* Remove enclave public key from parameter (#1777)

* [PAN-2982] Modifies PrivGetPrivateTransaction to take public tx hash (#1778)

* Modifies PrivGetPrivateTransaction to take public tx hash

* Fix star imports
  • Loading branch information
josh-richardson authored and MadelineMurray committed Jul 30, 2019
1 parent ded93b1 commit ddbe840
Show file tree
Hide file tree
Showing 31 changed files with 354 additions and 140 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ Documentation updates include:

### Technical Improvements

- eea_getTransactionCount fails if account has not interacted with private state [\#1369](https://github.com/PegaSysEng/pantheon/pull/1369)
- priv_getTransactionCount fails if account has not interacted with private state [\#1369](https://github.com/PegaSysEng/pantheon/pull/1369)
- Updating Orion to 0.9.0 [\#1360](https://github.com/PegaSysEng/pantheon/pull/1360)
- Allow use of large chain IDs [\#1357](https://github.com/PegaSysEng/pantheon/pull/1357)
- Allow private contract invocations in multiple privacy groups [\#1340](https://github.com/PegaSysEng/pantheon/pull/1340)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public PantheonFactoryConfigurationBuilder jsonRpcEnabled() {
public PantheonFactoryConfigurationBuilder enablePrivateTransactions(
final PrivacyParameters privacyParameters) {
this.jsonRpcConfiguration.addRpcApi(RpcApis.EEA);
this.jsonRpcConfiguration.addRpcApi(RpcApis.PRIV);
this.privacyParameters = privacyParameters;
this.privacyParameters.setEnabled(true);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationProvider;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaGetTransactionCountTransaction;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv.PrivGetTransactionCountTransaction;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.bytes.BytesValues;

Expand Down Expand Up @@ -113,7 +113,7 @@ public void testOrionConnection(final PrivacyNode... otherNodes) {

public long nextNonce(final BytesValue privacyGroupId) {
return execute(
new EeaGetTransactionCountTransaction(
new PrivGetTransactionCountTransaction(
getAddress().toString(), BytesValues.asBase64String(privacyGroupId)))
.longValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/
package tech.pegasys.pantheon.tests.acceptance.dsl.privacy;

import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaGetTransactionCountTransaction;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaSendRawTransactionTransaction;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv.PrivGetTransactionCountTransaction;

public class PrivateTransactions {

Expand All @@ -29,8 +29,8 @@ public EeaSendRawTransactionTransaction createPrivateRawTransaction(
return new EeaSendRawTransactionTransaction(signedRawPrivateTransaction);
}

public EeaGetTransactionCountTransaction getTransactionCount(
public PrivGetTransactionCountTransaction getTransactionCount(
final String address, final String privacyGroupId) {
return new EeaGetTransactionCountTransaction(address, privacyGroupId);
return new PrivGetTransactionCountTransaction(address, privacyGroupId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ Request<?, PrivateTransactionReceiptResponse> eeaGetTransactionReceipt(final Str
PrivateTransactionReceiptResponse.class);
}

Request<?, EthGetTransactionCount> eeaGetTransactionCount(
public Request<?, EthGetTransactionCount> privGetTransactionCount(
final String accountAddress, final String privacyGroupId) {
return new Request<>(
"eea_getTransactionCount",
"priv_getTransactionCount",
Lists.newArrayList(accountAddress, privacyGroupId),
web3jService,
EthGetTransactionCount.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
*/
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea;

import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv.PrivGetTransactionCountTransaction;

public class EeaTransactions {

public EeaGetTransactionReceiptTransaction getTransactionReceipt(final String transactionHash) {
return new EeaGetTransactionReceiptTransaction(transactionHash);
}

public EeaGetTransactionCountTransaction getTransactionCount(
public PrivGetTransactionCountTransaction getTransactionCount(
final String address, final String privacyGroupId) {
return new EeaGetTransactionCountTransaction(address, privacyGroupId);
return new PrivGetTransactionCountTransaction(address, privacyGroupId);
}

public EeaGetTransactionReceiptTransaction getPrivateTransactionReceipt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class PrivateTransactionBuilder {

Expand Down Expand Up @@ -68,7 +69,8 @@ public static class Builder {
Address from;
Address to;
BytesValue privateFrom;
List<BytesValue> privateFor = new ArrayList<>();
Optional<BytesValue> privacyGroupId = Optional.empty();
Optional<List<BytesValue>> privateFor = Optional.of(new ArrayList<>());
SECP256K1.KeyPair keyPair;

public Builder nonce(final long nonce) {
Expand All @@ -91,8 +93,13 @@ public Builder privateFrom(final BytesValue privateFrom) {
return this;
}

public Builder privacyGroupId(final BytesValue privacyGroupId) {
this.privacyGroupId = Optional.of(privacyGroupId);
return this;
}

public Builder privateFor(final List<BytesValue> privateFor) {
this.privateFor = privateFor;
this.privateFor = Optional.of(privateFor);
return this;
}

Expand All @@ -116,22 +123,27 @@ public String build(final TransactionType type) {
default:
throw new IllegalStateException("Unexpected value: " + type);
}
return RLP.encode(
PrivateTransaction.builder()
.nonce(nonce)
.gasPrice(Wei.of(1000))
.gasLimit(63992)
.to(to)
.value(Wei.ZERO)
.payload(payload)
.sender(from)
.chainId(BigInteger.valueOf(2018))
.privateFrom(privateFrom)
.privateFor(privateFor)
.restriction(Restriction.RESTRICTED)
.signAndBuild(keyPair)
::writeTo)
.toString();

var builder =
PrivateTransaction.builder()
.nonce(nonce)
.gasPrice(Wei.of(1000))
.gasLimit(63992)
.to(to)
.value(Wei.ZERO)
.payload(payload)
.sender(from)
.chainId(BigInteger.valueOf(2018))
.privateFrom(privateFrom)
.restriction(Restriction.RESTRICTED);

if (privacyGroupId.isPresent()) {
builder = builder.privacyGroupId(privacyGroupId.get());
} else {
builder = builder.privateFor(privateFor.get());
}

return RLP.encode(builder.signAndBuild(keyPair)::writeTo).toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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.tests.acceptance.dsl.transaction.eea;
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv;

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

Expand All @@ -22,12 +22,12 @@

import org.web3j.protocol.core.methods.response.EthGetTransactionCount;

public class EeaGetTransactionCountTransaction implements Transaction<BigInteger> {
public class PrivGetTransactionCountTransaction implements Transaction<BigInteger> {

private final String accountAddress;
private String privacyGroupId;

public EeaGetTransactionCountTransaction(
public PrivGetTransactionCountTransaction(
final String accountAddress, final String privacyGroupId) {
this.accountAddress = accountAddress;
this.privacyGroupId = privacyGroupId;
Expand All @@ -37,7 +37,7 @@ public EeaGetTransactionCountTransaction(
public BigInteger execute(final NodeRequests node) {
try {
EthGetTransactionCount result =
node.eea().eeaGetTransactionCount(accountAddress, privacyGroupId).send();
node.eea().privGetTransactionCount(accountAddress, privacyGroupId).send();
assertThat(result).isNotNull();
return result.getTransactionCount();
} catch (final IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ public void deploy(final String contractName, final String sender, final String.
receivers);
}

public void deployWithPrivacyGroup(
final String contractName,
final String sender,
final String mPrivacyGroupId,
final String... groupMembers) {
deployWithPrivacyGroup(
contractName,
"Test",
nextNonce(sender, BytesValues.fromBase64(mPrivacyGroupId)),
sender,
mPrivacyGroupId,
groupMembers);
}

public void deploy(
final String contractName,
final EeaCondition forParticipants,
Expand Down Expand Up @@ -174,6 +188,40 @@ public void get(
verifyForNonParticipants(forNonParticipants, transactionHash, sender, receivers);
}

private void deployWithPrivacyGroup(
final String contractAddress,
final String contractName,
final long nonce,
final String sender,
final String privacyGroupId,
final String... groupMembers) {

final String deployContract =
privateTransactionBuilder
.nonce(nonce)
.from(privacyNet.getNode(sender).getAddress())
.to(null)
.privateFrom(
BytesValues.fromBase64(privacyNet.getEnclave(sender).getPublicKeys().get(0)))
.privacyGroupId(BytesValues.fromBase64(privacyGroupId))
.keyPair(privacyNet.getNode(sender).keyPair())
.build(PrivateTransactionBuilder.TransactionType.CREATE_CONTRACT);
final String transactionHash =
privacyNet
.getNode(sender)
.execute(privateTransactions.deployPrivateSmartContract(deployContract));

waitForTransactionToBeMined(transactionHash);

verifyForParticipants(
privateTransactionVerifier.validPrivateTransactionReceipt(),
transactionHash,
sender,
groupMembers);

contracts.put(contractName, contractAddress);
}

private void deploy(
final String contractAddress,
final String contractName,
Expand Down Expand Up @@ -247,7 +295,7 @@ private void verifyForParticipants(
final String[] toNodeNames) {
verifyForParticipant(condition, transactionHash, fromNodeName);
Arrays.stream(toNodeNames)
.forEach(node -> verifyForParticipant(condition, transactionHash, fromNodeName));
.forEach(node -> verifyForParticipant(condition, transactionHash, node));
}

private void verifyForParticipant(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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.tests.web3j.privacy;

import tech.pegasys.pantheon.enclave.Enclave;
import tech.pegasys.pantheon.enclave.types.CreatePrivacyGroupRequest;
import tech.pegasys.pantheon.enclave.types.PrivacyGroup;
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyAcceptanceTestBase;
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyNet;

import java.util.List;

import org.junit.Before;
import org.junit.Test;

public class PrivacyGroupIdAcceptanceTest extends PrivacyAcceptanceTestBase {
private static final String CONTRACT_NAME = "Event Emmiter";
private EventEmitterHarness eventEmitterHarness;
private PrivacyGroup privacyGroup;

@Before
public void setUp() throws Exception {
PrivacyNet privacyNet =
PrivacyNet.builder(privacy, privacyPantheon, cluster, false)
.addMinerNode("Alice")
.addMinerNode("Bob")
.addMinerNode("Charlie")
.build();

privacyNet.startPrivacyNet();

Enclave enclave =
new Enclave(privacyNet.getNode("Alice").getPrivacyParameters().getEnclaveUri());
String[] addresses =
privacyNet.getNodes().values().stream()
.map(privacyNode -> privacyNode.orion.getPublicKeys())
.flatMap(List::stream)
.toArray(String[]::new);
this.privacyGroup =
enclave.createPrivacyGroup(
new CreatePrivacyGroupRequest(
addresses,
privacyNet.getNode("Alice").orion.getPublicKeys().get(0),
"testName",
"testDesc"));

eventEmitterHarness =
new EventEmitterHarness(
privateTransactionBuilder,
privacyNet,
privateTransactions,
privateTransactionVerifier,
eea);
}

@Test
public void nodeCanDeployWithPrivacyGroupId() {
eventEmitterHarness.deployWithPrivacyGroup(
CONTRACT_NAME, "Alice", privacyGroup.getPrivacyGroupId(), "Alice", "Bob", "Charlie");
}
}
2 changes: 1 addition & 1 deletion docs/Deploying-Pantheon/High-Availability.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ are sent to multiple nodes, the [`eth_getTransactionCount`](../Reference/Pantheo
results can be incorrect.

!!! note
If using [private transactions](../Privacy/Explanation/Privacy-Overview.md), `eea_getTransactionCount` is used to obtain
If using [private transactions](../Privacy/Explanation/Privacy-Overview.md), `priv_getTransactionCount` is used to obtain
the account nonce and [`eea_sendRawTransaction`](../Reference/Pantheon-API-Methods.md#eea_sendrawtransaction)
to send private transactions.

Expand Down
4 changes: 2 additions & 2 deletions docs/Privacy/How-To/Creating-Sending-Private-Transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ to get the transaction receipt for the private transaction.

Use [`eth_getTransactionByHash`](../../Reference/Pantheon-API-Methods.md#eth_gettransactionbyhash) to
get the Privacy Marker Transaction with the transaction hash returned when submitting the private transaction.
Use [`eea_getPrivateTransacton`](../../Reference/Pantheon-API-Methods.md#eea_getprivatetransaction)
Use [`priv_getPrivateTransaction`](../../Reference/Pantheon-API-Methods.md#priv_getprivatetransaction)
to get the private transaction with the `input` value from the Privacy Marker Transaction.

Separate private states are maintained for each [privacy group](../Explanation/Privacy-Overview.md#privacy-groups) so
the account nonce for an account is specific to the privacy group. That is, the nonce for account A for
privacy group ABC is different to the account nonce for account A for privacy group AB. Use
[`eea_getTransactionCount`](../../Reference/Pantheon-API-Methods.md#eea_gettransactioncount) to get
[`priv_getTransactionCount`](../../Reference/Pantheon-API-Methods.md#priv_getTransactionCount) to get
the account nonce for an account for the specified privacy group.

!!! note
Expand Down
2 changes: 1 addition & 1 deletion docs/Reference/Pantheon-API-Objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Returned by [eth_getFilterChanges](Pantheon-API-Methods.md#eth_getfilterchanges)

## Private Transaction Object

Returned by [eea_getPrivateTransaction](Pantheon-API-Methods.md#eea_getprivatetransaction).
Returned by [priv_getPrivateTransaction](Pantheon-API-Methods.md#priv_getprivatetransaction).

| Key | Type | Value |
|----------------------|-:-:-------------------------------|---------------------------------------------------------------------------------|
Expand Down
Loading

0 comments on commit ddbe840

Please sign in to comment.