Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
smatthewenglish committed Apr 16, 2019
1 parent 973fea8 commit 834a9a5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transaction> localTransactions = transactionPool.getLocalTransactions();
peer.send(TransactionsMessage.create(localTransactions));
peerTransactionTracker.markTransactionsAsSeen(peer, transactionPool.getLocalTransactions());
} catch (PeerNotConnected ignored){}
} catch (final PeerNotConnected ignored) {
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void> protocolSchedule = mock(ProtocolSchedule.class);

@SuppressWarnings("unchecked")
ProtocolSpec<Void> 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<Void> 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);
Expand All @@ -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);

Expand All @@ -1131,30 +1124,30 @@ 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<Capability> caps = new HashSet<>(Collections.singletonList(EthProtocol.ETH63));
PeerSendHandler onSend =
(cap, message, conn) -> {
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);
};

Expand All @@ -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()
Expand Down

0 comments on commit 834a9a5

Please sign in to comment.