From 8b4b993e739064a41a2ccdfb3ec20c9b3aed58fe Mon Sep 17 00:00:00 2001 From: Lucas Saldanha Date: Thu, 13 Jun 2019 09:47:11 +1200 Subject: [PATCH] Removing account filter (#1556) Signed-off-by: Adrian Sutton --- .../pantheon/ethereum/core/AccountFilter.java | 18 ------------ .../eth/transactions/TransactionPool.java | 18 ------------ .../eth/transactions/TransactionPoolTest.java | 29 ------------------- 3 files changed, 65 deletions(-) delete mode 100644 ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/AccountFilter.java 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 deleted file mode 100644 index 7a6d93758d..0000000000 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/AccountFilter.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java index 5d665ecf9a..eca80ebdd2 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java @@ -22,7 +22,6 @@ import tech.pegasys.pantheon.ethereum.chain.BlockAddedObserver; import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Account; -import tech.pegasys.pantheon.ethereum.core.AccountFilter; import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.eth.manager.EthContext; @@ -41,7 +40,6 @@ import tech.pegasys.pantheon.metrics.MetricsSystem; import java.util.Collection; import java.util.HashSet; import java.util.List; -import java.util.Optional; import java.util.Set; import org.apache.logging.log4j.Logger; @@ -65,7 +63,6 @@ public class TransactionPool implements BlockAddedObserver { private final TransactionBatchAddedListener transactionBatchAddedListener; private final SyncState syncState; private final LabelledMetric duplicateTransactionCounter; - private Optional accountFilter = Optional.empty(); private final PeerTransactionTracker peerTransactionTracker; public TransactionPool( @@ -186,13 +183,6 @@ public class TransactionPool implements BlockAddedObserver { return basicValidationResult; } - final String sender = transaction.getSender().toString(); - if (accountIsNotPermitted(sender)) { - return ValidationResult.invalid( - TransactionInvalidReason.TX_SENDER_NOT_AUTHORIZED, - String.format("Sender %s is not on the Account Whitelist", sender)); - } - final BlockHeader chainHeadBlockHeader = getChainHeadBlockHeader(); if (transaction.getGasLimit() > chainHeadBlockHeader.getGasLimit()) { return ValidationResult.invalid( @@ -217,10 +207,6 @@ public class TransactionPool implements BlockAddedObserver { .orElseGet(() -> ValidationResult.invalid(CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE)); } - private boolean accountIsNotPermitted(final String account) { - return accountFilter.map(c -> !c.permitted(account)).orElse(false); - } - private BlockHeader getChainHeadBlockHeader() { final MutableBlockchain blockchain = protocolContext.getBlockchain(); return blockchain.getBlockHeader(blockchain.getChainHeadHash()).get(); @@ -230,8 +216,4 @@ public class TransactionPool implements BlockAddedObserver { void onTransactionsAdded(Iterable transactions); } - - public void setAccountFilter(final AccountFilter accountFilter) { - this.accountFilter = Optional.of(accountFilter); - } } diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPoolTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPoolTest.java index 8fb054c20b..e2fbeba493 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPoolTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPoolTest.java @@ -30,14 +30,12 @@ import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator.TransactionInvalidReason.EXCEEDS_BLOCK_GAS_LIMIT; import static tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator.TransactionInvalidReason.NONCE_TOO_LOW; -import static tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator.TransactionInvalidReason.TX_SENDER_NOT_AUTHORIZED; import static tech.pegasys.pantheon.ethereum.mainnet.ValidationResult.valid; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Account; -import tech.pegasys.pantheon.ethereum.core.AccountFilter; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockHeader; @@ -103,7 +101,6 @@ public class TransactionPoolTest { private final ProtocolContext protocolContext = executionContext.getProtocolContext(); private TransactionPool transactionPool; private long genesisBlockGasLimit; - private final AccountFilter accountFilter = mock(AccountFilter.class); private SyncState syncState; private EthContext ethContext; private PeerTransactionTracker peerTransactionTracker; @@ -442,32 +439,6 @@ public class TransactionPoolTest { verifyZeroInteractions(batchAddedListener); } - @Test - public void shouldAllowWhitelistedTransactionWhenWhitelistEnabled() { - transactionPool.setAccountFilter(accountFilter); - givenTransactionIsValid(transaction1); - - when(accountFilter.permitted(transaction1.getSender().toString())).thenReturn(true); - - assertThat(transactionPool.addLocalTransaction(transaction1)).isEqualTo(valid()); - - assertTransactionPending(transaction1); - } - - @Test - public void shouldRejectNonWhitelistedTransactionWhenWhitelistEnabled() { - transactionPool.setAccountFilter(accountFilter); - givenTransactionIsValid(transaction1); - - when(accountFilter.permitted(transaction1.getSender().toString())).thenReturn(false); - - assertThat(transactionPool.addLocalTransaction(transaction1)) - .isEqualTo(ValidationResult.invalid(TX_SENDER_NOT_AUTHORIZED)); - - assertTransactionNotPending(transaction1); - verifyZeroInteractions(batchAddedListener); - } - @Test public void shouldAllowTransactionWhenAccountWhitelistControllerIsNotPresent() { givenTransactionIsValid(transaction1);