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

Nc 1942 Add account whitelisting and refactor into permissioning package #460

Merged
merged 40 commits into from
Dec 20, 2018

Conversation

Shinabyss
Copy link
Contributor

PR description

Create account whitelisting serving as the groundwork for role based permissioning system for transactions

Include:

  • "--accounts-whitelisting" config on startup
  • logic to reject transaction on validation when using account whitelist is active
  • Unit testing
  • refactor account whitelisting from p2p to permissioning package

Fixed Issue(s)

…NC-1942

# Conflicts:
#	pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java
#	pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java
 Resolved
…NC-1942

# Conflicts:
#	consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftControllerTest.java
#	docs/Getting-Started/ExplorerBlockDetails.png
#	docs/Getting-Started/ExplorerSearch.png
#	docs/Getting-Started/ExplorerSummary.png
#	ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfiguration.java
#	ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfigurationTest.java
#	pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java
#	pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java
…NC-1942

# Conflicts:
#	consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftControllerTest.java
#	docs/Getting-Started/ExplorerBlockDetails.png
#	docs/Getting-Started/ExplorerSearch.png
#	docs/Getting-Started/ExplorerSummary.png
#	ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfiguration.java
#	ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfigurationTest.java
#	pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java
#	pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java
…NC-1942

# Conflicts:
#	consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftControllerTest.java
#	docs/Getting-Started/ExplorerBlockDetails.png
#	docs/Getting-Started/ExplorerSearch.png
#	docs/Getting-Started/ExplorerSummary.png
#	ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfiguration.java
#	ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfigurationTest.java
#	pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java
#	pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java
@Shinabyss Shinabyss self-assigned this Dec 19, 2018
@Shinabyss Shinabyss requested a review from macfarla December 19, 2018 06:19
@Shinabyss Shinabyss changed the title Nc 1942 Nc 1942 Add account whitelisting and refactor into permissioning package Dec 19, 2018
@@ -131,6 +134,16 @@ public PendingTransactions getPendingTransactions() {
return basicValidationResult;
}

if (accountWhitelistController.isPresent()
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to have this whole logic inside a private method with a meaningful name like checkIfAccountIsWhitelisted or something similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actioned

AccountWhitelistController accountWhitelistController =
new AccountWhitelistController(permissioningConfiguration);

transactionPool.setAccountWhitelist(accountWhitelistController);
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to call the setter if the account whitelist property hasn't been set. Why don't we check it here?

if (permissioningConfiguration.isAccountWhitelistSet()) {
  transactionPool.setAccountWhitelist(accountWhitelistController);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actioned

@@ -404,13 +404,24 @@ private void setRefreshDelay(final Long refreshDelay) {
names = {"--nodes-whitelist"},
paramLabel = "<enode://id@host:port>",
description =
"Comma separated enode URLs for permissioned networks. Not intended to be used with mainnet or public testnets.",
"Comma separated enode URLs for permissioned networks. You may specify an empty list.",
Copy link
Contributor

Choose a reason for hiding this comment

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

You've reverted a text change here - can you change it back?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actioned

description =
"Comma separated hexString of account public key "
+ "for permissioned/role-based transaction. You may specify an empty list.",
split = ",",
Copy link
Contributor

Choose a reason for hiding this comment

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

s/transaction/transactions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actioned

split = ",",
arity = "0..*",
converter = EnodeToURIPropertyConverter.class
)
private final Collection<URI> nodesWhitelist = null;

@Option(
names = {"--accounts-whitelist"},
paramLabel = "<hexString of account public key>",
Copy link
Contributor

Choose a reason for hiding this comment

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

s/key/keys

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actioned

@@ -131,6 +134,13 @@ public PendingTransactions getPendingTransactions() {
return basicValidationResult;
}

String sender = transaction.getSender().toString();
if (!checkIfAccountIsWhitelisted(sender)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that I read this, I think the if statement will be better as something like:

if (!accountIsWhitelisted(sender)) {

What do you think?

Copy link
Contributor

@lucassaldanha lucassaldanha Dec 20, 2018

Choose a reason for hiding this comment

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

Or maybe even accountIsNotWhitelisted(sender)) so we don't need to negate the expression... idk

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actioned

Copy link
Contributor

@lucassaldanha lucassaldanha left a comment

Choose a reason for hiding this comment

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

It is looking good now. I've added another comment re readability and Sally has got some comments herself that I believe it would be good to implement.

@Shinabyss Shinabyss merged commit 6b60370 into PegaSysEng:master Dec 20, 2018
@Shinabyss Shinabyss deleted the NC-1942 branch December 20, 2018 08:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants