Removing account filter (#1556)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Lucas Saldanha 6 years ago committed by GitHub
parent 791a9cb639
commit 8b4b993e73
  1. 18
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/AccountFilter.java
  2. 18
      ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java
  3. 29
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPoolTest.java

@ -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);
}

@ -22,7 +22,6 @@ import tech.pegasys.pantheon.ethereum.chain.BlockAddedObserver;
import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.chain.Blockchain;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.Account; 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.BlockHeader;
import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.Transaction;
import tech.pegasys.pantheon.ethereum.eth.manager.EthContext; 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.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -65,7 +63,6 @@ public class TransactionPool implements BlockAddedObserver {
private final TransactionBatchAddedListener transactionBatchAddedListener; private final TransactionBatchAddedListener transactionBatchAddedListener;
private final SyncState syncState; private final SyncState syncState;
private final LabelledMetric<Counter> duplicateTransactionCounter; private final LabelledMetric<Counter> duplicateTransactionCounter;
private Optional<AccountFilter> accountFilter = Optional.empty();
private final PeerTransactionTracker peerTransactionTracker; private final PeerTransactionTracker peerTransactionTracker;
public TransactionPool( public TransactionPool(
@ -186,13 +183,6 @@ public class TransactionPool implements BlockAddedObserver {
return basicValidationResult; 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(); final BlockHeader chainHeadBlockHeader = getChainHeadBlockHeader();
if (transaction.getGasLimit() > chainHeadBlockHeader.getGasLimit()) { if (transaction.getGasLimit() > chainHeadBlockHeader.getGasLimit()) {
return ValidationResult.invalid( return ValidationResult.invalid(
@ -217,10 +207,6 @@ public class TransactionPool implements BlockAddedObserver {
.orElseGet(() -> ValidationResult.invalid(CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE)); .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() { private BlockHeader getChainHeadBlockHeader() {
final MutableBlockchain blockchain = protocolContext.getBlockchain(); final MutableBlockchain blockchain = protocolContext.getBlockchain();
return blockchain.getBlockHeader(blockchain.getChainHeadHash()).get(); return blockchain.getBlockHeader(blockchain.getChainHeadHash()).get();
@ -230,8 +216,4 @@ public class TransactionPool implements BlockAddedObserver {
void onTransactionsAdded(Iterable<Transaction> transactions); void onTransactionsAdded(Iterable<Transaction> transactions);
} }
public void setAccountFilter(final AccountFilter accountFilter) {
this.accountFilter = Optional.of(accountFilter);
}
} }

@ -30,14 +30,12 @@ import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when; 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.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.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 static tech.pegasys.pantheon.ethereum.mainnet.ValidationResult.valid;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.Account; 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.Block;
import tech.pegasys.pantheon.ethereum.core.BlockBody; import tech.pegasys.pantheon.ethereum.core.BlockBody;
import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.BlockHeader;
@ -103,7 +101,6 @@ public class TransactionPoolTest {
private final ProtocolContext<Void> protocolContext = executionContext.getProtocolContext(); private final ProtocolContext<Void> protocolContext = executionContext.getProtocolContext();
private TransactionPool transactionPool; private TransactionPool transactionPool;
private long genesisBlockGasLimit; private long genesisBlockGasLimit;
private final AccountFilter accountFilter = mock(AccountFilter.class);
private SyncState syncState; private SyncState syncState;
private EthContext ethContext; private EthContext ethContext;
private PeerTransactionTracker peerTransactionTracker; private PeerTransactionTracker peerTransactionTracker;
@ -442,32 +439,6 @@ public class TransactionPoolTest {
verifyZeroInteractions(batchAddedListener); 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 @Test
public void shouldAllowTransactionWhenAccountWhitelistControllerIsNotPresent() { public void shouldAllowTransactionWhenAccountWhitelistControllerIsNotPresent() {
givenTransactionIsValid(transaction1); givenTransactionIsValid(transaction1);

Loading…
Cancel
Save