fetch local transactions in isolation (#1259)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
S. Matthew English 6 years ago committed by GitHub
parent c416f419bf
commit 5d9b4b9583
  1. 12
      ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactions.java
  2. 4
      ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java
  3. 16
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactionsTest.java
  4. 16
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPoolTest.java

@ -92,6 +92,18 @@ public class PendingTransactions {
"operation");
}
List<Transaction> getLocalTransactions() {
synchronized (pendingTransactions) {
List<Transaction> localTransactions = new ArrayList<>();
for (Map.Entry<Hash, TransactionInfo> transaction : pendingTransactions.entrySet()) {
if (transaction.getValue().isReceivedFromLocalSource()) {
localTransactions.add(transaction.getValue().getTransaction());
}
}
return localTransactions;
}
}
public boolean addRemoteTransaction(final Transaction transaction) {
final TransactionInfo transactionInfo =
new TransactionInfo(transaction, false, clock.instant());

@ -66,6 +66,10 @@ public class TransactionPool implements BlockAddedObserver {
this.transactionBatchAddedListener = transactionBatchAddedListener;
}
public List<Transaction> getLocalTransactions() {
return pendingTransactions.getLocalTransactions();
}
public ValidationResult<TransactionInvalidReason> addLocalTransaction(
final Transaction transaction) {
final ValidationResult<TransactionInvalidReason> validationResult =

@ -54,6 +54,22 @@ public class PendingTransactionsTest {
private static final Address SENDER1 = Util.publicKeyToAddress(KEYS1.getPublicKey());
private static final Address SENDER2 = Util.publicKeyToAddress(KEYS2.getPublicKey());
@Test
public void shouldReturnExclusivelyLocalTransactionsWhenAppropriate() {
final Transaction localTransaction0 = createTransaction(0);
transactions.addLocalTransaction(localTransaction0);
assertThat(transactions.size()).isEqualTo(1);
transactions.addRemoteTransaction(transaction1);
assertThat(transactions.size()).isEqualTo(2);
transactions.addRemoteTransaction(transaction2);
assertThat(transactions.size()).isEqualTo(3);
List<Transaction> localTransactions = transactions.getLocalTransactions();
assertThat(localTransactions.size()).isEqualTo(1);
}
@Test
public void shouldAddATransaction() {
transactions.addRemoteTransaction(transaction1);

@ -103,6 +103,22 @@ public class TransactionPoolTest {
blockchain.observeBlockAdded(transactionPool);
}
@Test
public void shouldReturnExclusivelyLocalTransactionsWhenAppropriate() {
final Transaction localTransaction0 = createTransaction(0);
transactions.addLocalTransaction(localTransaction0);
assertThat(transactions.size()).isEqualTo(1);
transactions.addRemoteTransaction(transaction1);
assertThat(transactions.size()).isEqualTo(2);
transactions.addRemoteTransaction(transaction2);
assertThat(transactions.size()).isEqualTo(3);
List<Transaction> localTransactions = transactions.getLocalTransactions();
assertThat(localTransactions.size()).isEqualTo(1);
}
@Test
public void shouldRemoveTransactionsFromPendingListWhenIncludedInBlockOnChain() {
transactions.addRemoteTransaction(transaction1);

Loading…
Cancel
Save