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

[PAN-2601] Refactorings and additions to add Account based Smart Contract permissioning #1430

Merged
merged 6 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.perm.SmartContractNodePermissioningTransactions;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.perm.NodeSmartContractNodePermissioningTransactions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NodeSmartContractNodePerm... Node Node node?!


public class SmartContractNodePermissioningConditions {
public class NodeSmartContractNodePermissioningConditions {

private final SmartContractNodePermissioningTransactions transactions;
private final NodeSmartContractNodePermissioningTransactions transactions;

public SmartContractNodePermissioningConditions(
final SmartContractNodePermissioningTransactions transactions) {
public NodeSmartContractNodePermissioningConditions(
final NodeSmartContractNodePermissioningTransactions transactions) {
this.transactions = transactions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ public void startNode(final PantheonNode node) {
if (permissioningConfiguration.isSmartContractNodeWhitelistEnabled()) {
params.add("--permissions-nodes-contract-enabled");
}
if (permissioningConfiguration.getSmartContractAddress() != null) {
if (permissioningConfiguration.getNodeSmartContractAddress() != null) {
params.add("--permissions-nodes-contract-address");
params.add(permissioningConfiguration.getSmartContractAddress().toString());
params.add(permissioningConfiguration.getNodeSmartContractAddress().toString());
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private SmartContractPermissioningConfiguration smartContractPermissioningConfig
SmartContractPermissioningConfiguration config =
SmartContractPermissioningConfiguration.createDefault();
if (permissioningSmartContractAddress != null) {
config.setSmartContractAddress(Address.fromHexString(permissioningSmartContractAddress));
config.setNodeSmartContractAddress(Address.fromHexString(permissioningSmartContractAddress));
config.setSmartContractNodeWhitelistEnabled(true);
}
return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;

public class SmartContractNodePermissioningTransactions {
public class NodeSmartContractNodePermissioningTransactions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much node, just NodeSmartContractPermissioningTransactions sounds fine

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


private final Accounts accounts;

public SmartContractNodePermissioningTransactions(final Accounts accounts) {
public NodeSmartContractNodePermissioningTransactions(final Accounts accounts) {
this.accounts = accounts;
}

public Transaction<Hash> allowNode(final String contractAddress, final Node node) {
return new SmartContractPermissioningAllowNodeTransaction(
return new NodeSmartContractPermissioningAllowNodeTransaction(
accounts.getPrimaryBenefactor(), Address.fromHexString(contractAddress), node);
}

public Transaction<Hash> forbidNode(final String contractAddress, final Node node) {
return new SmartContractPermissioningForbidNodeTransaction(
return new NodeSmartContractPermissioningForbidNodeTransaction(
accounts.getPrimaryBenefactor(), Address.fromHexString(contractAddress), node);
}

public Transaction<Boolean> isNodeAllowed(final String contractAddress, final Node node) {
return new SmartContractPermissioningNodeIsAllowedTransaction(
return new NodeSmartContractPermissioningNodeIsAllowedTransaction(
Address.fromHexString(contractAddress), node);
}

public Transaction<Boolean> isConnectionAllowed(
final String contractAddress, final Node source, final Node target) {
return new SmartContractPermissioningConnectionIsAllowedTransaction(
return new NodeSmartContractPermissioningConnectionIsAllowedTransaction(
Address.fromHexString(contractAddress), source, target);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.permissioning.SmartContractPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeSmartContractPermissioningController;
import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.RunnableNode;
Expand All @@ -32,7 +32,7 @@
import org.web3j.crypto.RawTransaction;
import org.web3j.crypto.TransactionEncoder;

public class SmartContractPermissioningAllowNodeTransaction implements Transaction<Hash> {
public class NodeSmartContractPermissioningAllowNodeTransaction implements Transaction<Hash> {

private static final BytesValue ADD_ENODE_SIGNATURE =
tech.pegasys.pantheon.crypto.Hash.keccak256(
Expand All @@ -43,7 +43,7 @@ public class SmartContractPermissioningAllowNodeTransaction implements Transacti
private final Address contractAddress;
private final Node node;

public SmartContractPermissioningAllowNodeTransaction(
public NodeSmartContractPermissioningAllowNodeTransaction(
final Account sender, final Address contractAddress, final Node node) {
this.sender = sender;
this.contractAddress = contractAddress;
Expand All @@ -65,7 +65,7 @@ public Hash execute(final JsonRequestFactories node) {
private String signedTransactionData() {
final String enodeURL = ((RunnableNode) node).enodeUrl().toASCIIString();
final BytesValue payload =
SmartContractPermissioningController.createPayload(
NodeSmartContractPermissioningController.createPayload(
ADD_ENODE_SIGNATURE, EnodeURL.fromString(enodeURL));

RawTransaction transaction =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.perm;

import static java.nio.charset.StandardCharsets.UTF_8;
import static tech.pegasys.pantheon.ethereum.permissioning.SmartContractPermissioningController.checkTransactionResult;
import static tech.pegasys.pantheon.ethereum.permissioning.NodeSmartContractPermissioningController.checkTransactionResult;

import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.permissioning.SmartContractPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeSmartContractPermissioningController;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.RunnableNode;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories;
Expand All @@ -28,7 +28,7 @@

import org.web3j.protocol.core.DefaultBlockParameterName;

public class SmartContractPermissioningConnectionIsAllowedTransaction
public class NodeSmartContractPermissioningConnectionIsAllowedTransaction
implements Transaction<Boolean> {

private static final BytesValue IS_CONNECTION_ALLOWED_SIGNATURE =
Expand All @@ -42,7 +42,7 @@ public class SmartContractPermissioningConnectionIsAllowedTransaction
private final Node source;
private final Node target;

public SmartContractPermissioningConnectionIsAllowedTransaction(
public NodeSmartContractPermissioningConnectionIsAllowedTransaction(
final Address contractAddress, final Node source, final Node target) {
this.contractAddress = contractAddress;
this.source = source;
Expand All @@ -64,7 +64,7 @@ private org.web3j.protocol.core.methods.request.Transaction payload() {
final String sourceEnodeURL = ((RunnableNode) source).enodeUrl().toASCIIString();
final String targetEnodeURL = ((RunnableNode) target).enodeUrl().toASCIIString();
final BytesValue payload =
SmartContractPermissioningController.createPayload(
NodeSmartContractPermissioningController.createPayload(
IS_CONNECTION_ALLOWED_SIGNATURE,
EnodeURL.fromString(sourceEnodeURL),
EnodeURL.fromString(targetEnodeURL));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.permissioning.SmartContractPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeSmartContractPermissioningController;
import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.RunnableNode;
Expand All @@ -32,7 +32,7 @@
import org.web3j.crypto.RawTransaction;
import org.web3j.crypto.TransactionEncoder;

public class SmartContractPermissioningForbidNodeTransaction implements Transaction<Hash> {
public class NodeSmartContractPermissioningForbidNodeTransaction implements Transaction<Hash> {

private static final BytesValue REMOVE_ENODE_SIGNATURE =
tech.pegasys.pantheon.crypto.Hash.keccak256(
Expand All @@ -43,7 +43,7 @@ public class SmartContractPermissioningForbidNodeTransaction implements Transact
private final Address contractAddress;
private final Node node;

public SmartContractPermissioningForbidNodeTransaction(
public NodeSmartContractPermissioningForbidNodeTransaction(
final Account sender, final Address contractAddress, final Node node) {
this.sender = sender;
this.contractAddress = contractAddress;
Expand All @@ -65,7 +65,7 @@ public Hash execute(final JsonRequestFactories node) {
private String signedTransactionData() {
final String enodeURL = ((RunnableNode) node).enodeUrl().toASCIIString();
final BytesValue payload =
SmartContractPermissioningController.createPayload(
NodeSmartContractPermissioningController.createPayload(
REMOVE_ENODE_SIGNATURE, EnodeURL.fromString(enodeURL));

RawTransaction transaction =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;

import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.permissioning.SmartContractPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeSmartContractPermissioningController;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.RunnableNode;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories;
Expand All @@ -27,7 +27,8 @@

import org.web3j.protocol.core.DefaultBlockParameterName;

public class SmartContractPermissioningNodeIsAllowedTransaction implements Transaction<Boolean> {
public class NodeSmartContractPermissioningNodeIsAllowedTransaction
implements Transaction<Boolean> {

private static final BytesValue IS_NODE_ALLOWED_SIGNATURE =
tech.pegasys.pantheon.crypto.Hash.keccak256(
Expand All @@ -37,7 +38,7 @@ public class SmartContractPermissioningNodeIsAllowedTransaction implements Trans
private final Address contractAddress;
private final Node node;

public SmartContractPermissioningNodeIsAllowedTransaction(
public NodeSmartContractPermissioningNodeIsAllowedTransaction(
final Address contractAddress, final Node node) {
this.contractAddress = contractAddress;
this.node = node;
Expand Down Expand Up @@ -83,7 +84,7 @@ static Boolean checkTransactionResult(final BytesValue result) {
private org.web3j.protocol.core.methods.request.Transaction payload() {
final String sourceEnodeURL = ((RunnableNode) node).enodeUrl().toASCIIString();
final BytesValue payload =
SmartContractPermissioningController.createPayload(
NodeSmartContractPermissioningController.createPayload(
IS_NODE_ALLOWED_SIGNATURE, EnodeURL.fromString(sourceEnodeURL));

return org.web3j.protocol.core.methods.request.Transaction.createFunctionCallTransaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.junit.Before;
import org.junit.Test;

public class SmartContractNodePermissioningAcceptanceTest
extends SmartContractNodePermissioningAcceptanceTestBase {
public class NodeNodeSmartContractNodePermissioningAcceptanceTest
extends NodeSmartContractNodePermissioningAcceptanceTestBase {

private Node bootnode;
private Node permissionedNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,32 @@
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.perm.SmartContractNodePermissioningConditions;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.perm.NodeSmartContractNodePermissioningConditions;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.Cluster;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.ClusterConfiguration;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.ClusterConfigurationBuilder;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.perm.SmartContractNodePermissioningTransactions;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.perm.NodeSmartContractNodePermissioningTransactions;

import java.io.IOException;

class SmartContractNodePermissioningAcceptanceTestBase extends AcceptanceTestBase {
class NodeSmartContractNodePermissioningAcceptanceTestBase extends AcceptanceTestBase {

private final SmartContractNodePermissioningTransactions smartContractNodePermissioning;
private final SmartContractNodePermissioningConditions smartContractNodePermissioningConditions;
private final NodeSmartContractNodePermissioningTransactions smartContractNodePermissioning;
private final NodeSmartContractNodePermissioningConditions
nodeSmartContractNodePermissioningConditions;

private static final String CONTRACT_ADDRESS = "0x0000000000000000000000000000000000009999";
private static final String GENESIS_FILE = "/permissioning/simple_permissioning_genesis.json";

protected final Cluster permissionedCluster;

protected SmartContractNodePermissioningAcceptanceTestBase() {
protected NodeSmartContractNodePermissioningAcceptanceTestBase() {
super();
smartContractNodePermissioning = new SmartContractNodePermissioningTransactions(accounts);
smartContractNodePermissioningConditions =
new SmartContractNodePermissioningConditions(smartContractNodePermissioning);
smartContractNodePermissioning = new NodeSmartContractNodePermissioningTransactions(accounts);
nodeSmartContractNodePermissioningConditions =
new NodeSmartContractNodePermissioningConditions(smartContractNodePermissioning);
this.permissionedCluster = permissionedCluster();
}

Expand Down Expand Up @@ -84,24 +85,24 @@ protected Transaction<Hash> allowNode(final Node node) {
}

protected Condition nodeIsAllowed(final Node node) {
return smartContractNodePermissioningConditions.nodeIsAllowed(CONTRACT_ADDRESS, node);
return nodeSmartContractNodePermissioningConditions.nodeIsAllowed(CONTRACT_ADDRESS, node);
}

protected Transaction<Hash> forbidNode(final Node node) {
return smartContractNodePermissioning.forbidNode(CONTRACT_ADDRESS, node);
}

protected Condition nodeIsForbidden(final Node node) {
return smartContractNodePermissioningConditions.nodeIsForbidden(CONTRACT_ADDRESS, node);
return nodeSmartContractNodePermissioningConditions.nodeIsForbidden(CONTRACT_ADDRESS, node);
}

protected Condition connectionIsAllowed(final Node source, final Node target) {
return smartContractNodePermissioningConditions.connectionIsAllowed(
return nodeSmartContractNodePermissioningConditions.connectionIsAllowed(
CONTRACT_ADDRESS, source, target);
}

protected Condition connectionIsForbidden(final Node source, final Node target) {
return smartContractNodePermissioningConditions.connectionIsForbidden(
return nodeSmartContractNodePermissioningConditions.connectionIsForbidden(
CONTRACT_ADDRESS, source, target);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public NodePermissioningController create(
SmartContractPermissioningConfiguration smartContractPermissioningConfiguration =
permissioningConfiguration.getSmartContractConfig().get();
if (smartContractPermissioningConfiguration.isSmartContractNodeWhitelistEnabled()) {
SmartContractPermissioningController smartContractProvider =
new SmartContractPermissioningController(
smartContractPermissioningConfiguration.getSmartContractAddress(),
NodeSmartContractPermissioningController smartContractProvider =
new NodeSmartContractPermissioningController(
smartContractPermissioningConfiguration.getNodeSmartContractAddress(),
transactionSimulator);
providers.add(smartContractProvider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Controller that can read from a smart contract that exposes the permissioning call
* connectionAllowed(bytes32,bytes32,bytes16,uint16,bytes32,bytes32,bytes16,uint16)
*/
public class SmartContractPermissioningController implements NodePermissioningProvider {
public class NodeSmartContractPermissioningController implements NodePermissioningProvider {
private final Address contractAddress;
private final TransactionSimulator transactionSimulator;

Expand Down Expand Up @@ -61,7 +61,7 @@ private static BytesValue hashSignature(final String signature) {
* @param contractAddress The address at which the permissioning smart contract resides
* @param transactionSimulator A transaction simulator with attached blockchain and world state
*/
public SmartContractPermissioningController(
public NodeSmartContractPermissioningController(
final Address contractAddress, final TransactionSimulator transactionSimulator) {
this.contractAddress = contractAddress;
this.transactionSimulator = transactionSimulator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class PermissioningConfigurationBuilder {
public static SmartContractPermissioningConfiguration smartContractPermissioningConfiguration(
final Address address, final boolean smartContractPermissionedNodeEnabled) {
SmartContractPermissioningConfiguration config = new SmartContractPermissioningConfiguration();
config.setSmartContractAddress(address);
config.setNodeSmartContractAddress(address);
config.setSmartContractNodeWhitelistEnabled(smartContractPermissionedNodeEnabled);
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

public class SmartContractPermissioningConfiguration {
private boolean smartContractNodeWhitelistEnabled;
private Address smartContractAddress;
private Address nodeSmartContractAddress;

private boolean smartContractAccountWhitelistEnabled;
private Address accountSmartContractAddress;

public static SmartContractPermissioningConfiguration createDefault() {
return new SmartContractPermissioningConfiguration();
Expand All @@ -31,11 +34,28 @@ public void setSmartContractNodeWhitelistEnabled(
this.smartContractNodeWhitelistEnabled = smartContractNodeWhitelistEnabled;
}

public Address getSmartContractAddress() {
return smartContractAddress;
public Address getNodeSmartContractAddress() {
return nodeSmartContractAddress;
}

public void setNodeSmartContractAddress(final Address nodeSmartContractAddress) {
this.nodeSmartContractAddress = nodeSmartContractAddress;
}

public boolean isSmartContractAccountWhitelistEnabled() {
return smartContractAccountWhitelistEnabled;
}

public void setSmartContractAccountWhitelistEnabled(
final boolean smartContractAccountWhitelistEnabled) {
this.smartContractAccountWhitelistEnabled = smartContractAccountWhitelistEnabled;
}

public Address getAccountSmartContractAddress() {
return accountSmartContractAddress;
}

public void setSmartContractAddress(final Address smartContractAddress) {
this.smartContractAddress = smartContractAddress;
public void setAccountSmartContractAddress(final Address accountSmartContractAddress) {
this.accountSmartContractAddress = accountSmartContractAddress;
}
}
Loading