diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManager.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManager.java index 443988aba2..2fb4aeed7a 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManager.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManager.java @@ -243,29 +243,22 @@ public void handleNewConnection(final PeerConnection connection) { LOG.debug("Sending status message to {}.", peer); peer.send(status); peer.registerStatusSent(); - dispatchLocalTransaction(peer); - } catch (final PeerNotConnected peerNotConnected) { - // Nothing to do. + } catch (final PeerNotConnected ignored) { } } private void dispatchLocalTransaction(final EthPeer peer) { if (transactionPool == null) { - - System.out.println("999"); - return; } - - System.out.println("888"); - - LOG.debug("Dispatching local transactions to {}.", peer); - try{ + try { + LOG.debug("Dispatching local transactions to {}.", peer); Iterable localTransactions = transactionPool.getLocalTransactions(); peer.send(TransactionsMessage.create(localTransactions)); peerTransactionTracker.markTransactionsAsSeen(peer, transactionPool.getLocalTransactions()); - } catch (PeerNotConnected ignored){} + } catch (final PeerNotConnected ignored) { + } } @Override diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java index 867b418a3e..b3d5bcc679 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java @@ -1083,29 +1083,22 @@ public void transactionMessagesGoToTheCorrectExecutor() { } } + @SuppressWarnings("unchecked") @Test public void shouldSendLocalTransactionsToNewlyConnectedPeers() { SECP256K1.KeyPair KEY_PAIR1 = SECP256K1.KeyPair.generate(); - MetricsSystem metricsSystem = new NoOpMetricsSystem(); - - @SuppressWarnings("unchecked") ProtocolSchedule protocolSchedule = mock(ProtocolSchedule.class); - - @SuppressWarnings("unchecked") ProtocolSpec protocolSpec = mock(ProtocolSpec.class); - TransactionValidator transactionValidator = mock(TransactionValidator.class); - MutableBlockchain blockchain; - Transaction transaction1 = createTransaction(1, KEY_PAIR1); - ExecutionContextTestFixture executionContext = ExecutionContextTestFixture.create(); - blockchain = executionContext.getBlockchain(); + MutableBlockchain blockchain = executionContext.getBlockchain(); ProtocolContext protocolContext = executionContext.getProtocolContext(); when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(protocolSpec); when(protocolSpec.getTransactionValidator()).thenReturn(transactionValidator); - /* * */ + Transaction transaction1 = createTransaction(1, KEY_PAIR1); + Transaction transaction2 = createTransaction(2, KEY_PAIR1); String protocolName = "eth"; EthPeers ethPeers = new EthPeers(protocolName); @@ -1114,10 +1107,10 @@ public void shouldSendLocalTransactionsToNewlyConnectedPeers() { EthContext ethContext = new EthContext(protocolName, ethPeers, ethMessages, ethScheduler); PeerTransactionTracker peerTransactionTracker = new PeerTransactionTracker(); - TransactionsMessageSender transactionsMessageSender = new TransactionsMessageSender(peerTransactionTracker); - - PendingTransactions pendingTransactions = new PendingTransactions(200, TestClock.fixed(), metricsSystem); - + TransactionsMessageSender transactionsMessageSender = + new TransactionsMessageSender(peerTransactionTracker); + PendingTransactions pendingTransactions = + new PendingTransactions(200, TestClock.fixed(), metricsSystem); SyncState syncState = mock(SyncState.class); when(syncState.isInSync(anyLong())).thenReturn(true); @@ -1131,18 +1124,21 @@ public void shouldSendLocalTransactionsToNewlyConnectedPeers() { pendingTransactions, syncState); - blockchain.observeBlockAdded(transactionPool); - when(transactionValidator.validate(any(Transaction.class))).thenReturn(valid()); when(transactionValidator.validateForSender( eq(transaction1), nullable(Account.class), eq(true))) .thenReturn(valid()); + when(transactionValidator.validateForSender( + eq(transaction2), nullable(Account.class), eq(true))) + .thenReturn(valid()); assertThat(transactionPool.addLocalTransaction(transaction1)).isEqualTo(valid()); + transactionPool.addRemoteTransactions(Collections.singletonList(transaction2)); - assertTransactionPending(transaction1, transactionPool.getPendingTransactions()); - - /* * */ + assertThat(transactionPool.getPendingTransactions().getTransactionByHash(transaction1.hash())) + .contains(transaction1); + assertThat(transactionPool.getPendingTransactions().getTransactionByHash(transaction2.hash())) + .contains(transaction2); Set caps = new HashSet<>(Collections.singletonList(EthProtocol.ETH63)); PeerSendHandler onSend = @@ -1150,11 +1146,8 @@ public void shouldSendLocalTransactionsToNewlyConnectedPeers() { if (message.getCode() == EthPV62.STATUS) { return; } - BytesValue localTransactionData = TransactionsMessage.create(Collections.singletonList(transaction1)).getData(); - - System.out.println(TransactionsMessage.create(Collections.singletonList(transaction1)).getData()); - System.out.println(message.getData()); - + BytesValue localTransactionData = + TransactionsMessage.create(Collections.singletonList(transaction1)).getData(); assertThat(message.getData()).isEqualTo(localTransactionData); }; @@ -1167,18 +1160,13 @@ public void shouldSendLocalTransactionsToNewlyConnectedPeers() { 1, true, EthereumWireProtocolConfiguration.defaultConfig(), - transactionPool, - peerTransactionTracker, - ethScheduler); + transactionPool, + peerTransactionTracker, + ethScheduler); ethProtocolManager.handleNewConnection(peer); } - private void assertTransactionPending( - final Transaction t, final PendingTransactions transactions) { - assertThat(transactions.getTransactionByHash(t.hash())).contains(t); - } - private Transaction createTransaction( final int transactionNumber, final SECP256K1.KeyPair keyPair) { return new TransactionTestFixture()