diff --git a/ethereum/core/build.gradle b/ethereum/core/build.gradle index 4f524c29ff..de6349b11e 100644 --- a/ethereum/core/build.gradle +++ b/ethereum/core/build.gradle @@ -31,7 +31,6 @@ dependencies { implementation project(':enclave') implementation project(':ethereum:rlp') implementation project(':ethereum:trie') - implementation project(':ethereum:permissioning') implementation project(':metrics') implementation project(':services:kvstore') diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/AccountFilter.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/AccountFilter.java new file mode 100644 index 0000000000..7a6d93758d --- /dev/null +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/AccountFilter.java @@ -0,0 +1,18 @@ +/* + * 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.ethereum.core; + +@FunctionalInterface +public interface AccountFilter { + boolean permitted(String account); +} diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/TransactionPool.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/TransactionPool.java index e0882c2940..ec8d994564 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/TransactionPool.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/TransactionPool.java @@ -25,7 +25,6 @@ import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator; import tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator.TransactionInvalidReason; import tech.pegasys.pantheon.ethereum.mainnet.ValidationResult; -import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController; import java.util.ArrayList; import java.util.Collection; @@ -50,7 +49,7 @@ public class TransactionPool implements BlockAddedObserver { private final ProtocolSchedule protocolSchedule; private final ProtocolContext protocolContext; private final TransactionBatchAddedListener transactionBatchAddedListener; - private Optional accountWhitelistController = Optional.empty(); + private Optional accountFilter = Optional.empty(); public TransactionPool( final PendingTransactions pendingTransactions, @@ -136,7 +135,7 @@ public class TransactionPool implements BlockAddedObserver { } final String sender = transaction.getSender().toString(); - if (accountIsNotWhitelisted(sender)) { + if (accountIsNotPermitted(sender)) { return ValidationResult.invalid( TransactionInvalidReason.TX_SENDER_NOT_AUTHORIZED, String.format("Sender %s is not on the Account Whitelist", sender)); @@ -166,8 +165,8 @@ public class TransactionPool implements BlockAddedObserver { .orElseGet(() -> ValidationResult.invalid(CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE)); } - private boolean accountIsNotWhitelisted(final String account) { - return accountWhitelistController.map(c -> !c.contains(account)).orElse(false); + private boolean accountIsNotPermitted(final String account) { + return accountFilter.map(c -> !c.permitted(account)).orElse(false); } private BlockHeader getChainHeadBlockHeader() { @@ -180,7 +179,7 @@ public class TransactionPool implements BlockAddedObserver { void onTransactionsAdded(Iterable transactions); } - public void setAccountWhitelist(AccountWhitelistController accountWhitelist) { - accountWhitelistController = Optional.of(accountWhitelist); + public void setAccountFilter(final AccountFilter accountFilter) { + this.accountFilter = Optional.of(accountFilter); } } diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/core/TransactionPoolTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/core/TransactionPoolTest.java index 7467e67242..094ac1e395 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/core/TransactionPoolTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/core/TransactionPoolTest.java @@ -41,7 +41,6 @@ import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec; import tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator; import tech.pegasys.pantheon.ethereum.mainnet.ValidationResult; -import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController; import tech.pegasys.pantheon.util.uint.UInt256; import java.util.List; @@ -72,8 +71,7 @@ public class TransactionPoolTest { private final Transaction transaction2 = createTransaction(2); private TransactionPool transactionPool; private long genesisBlockGasLimit; - private final AccountWhitelistController accountWhitelistController = - mock(AccountWhitelistController.class); + private final AccountFilter accountFilter = mock(AccountFilter.class); @Before public void setUp() { @@ -361,10 +359,10 @@ public class TransactionPoolTest { @Test public void shouldAllowWhitelistedTransactionWhenWhitelistEnabled() { - transactionPool.setAccountWhitelist(accountWhitelistController); + transactionPool.setAccountFilter(accountFilter); givenTransactionIsValid(transaction1); - when(accountWhitelistController.contains(transaction1.getSender().toString())).thenReturn(true); + when(accountFilter.permitted(transaction1.getSender().toString())).thenReturn(true); assertThat(transactionPool.addLocalTransaction(transaction1)).isEqualTo(valid()); @@ -373,11 +371,10 @@ public class TransactionPoolTest { @Test public void shouldRejectNonWhitelistedTransactionWhenWhitelistEnabled() { - transactionPool.setAccountWhitelist(accountWhitelistController); + transactionPool.setAccountFilter(accountFilter); givenTransactionIsValid(transaction1); - when(accountWhitelistController.contains(transaction1.getSender().toString())) - .thenReturn(false); + when(accountFilter.permitted(transaction1.getSender().toString())).thenReturn(false); assertThat(transactionPool.addLocalTransaction(transaction1)) .isEqualTo(ValidationResult.invalid(TX_SENDER_NOT_AUTHORIZED)); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java index 09225eeac1..e2710b1c44 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java @@ -255,7 +255,7 @@ public class RunnerBuilder { configuration -> { final AccountWhitelistController whitelistController = new AccountWhitelistController(configuration); - transactionPool.setAccountWhitelist(whitelistController); + transactionPool.setAccountFilter(whitelistController::contains); return whitelistController; });