Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support of peers that do not support eth/65 #724

Merged
merged 5 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make protocol version part of the function
Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>
  • Loading branch information
atoulme committed Apr 15, 2020
commit c6d9431495726b656f6ae49c292c28e0cb5cf907
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import static java.util.Collections.emptySet;

import org.hyperledger.besu.ethereum.core.Hash;
import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability;

import java.util.Collection;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.hyperledger.besu.ethereum.eth.transactions;

import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool.TransactionBatchAddedListener;

Expand All @@ -38,7 +39,7 @@ public void onTransactionsAdded(final Iterable<Transaction> transactions) {
ethContext
.getEthPeers()
.streamAvailablePeers()
.filter(transactionTracker::isPeerSupported)
.filter(peer -> transactionTracker.isPeerSupported(peer, EthProtocol.ETH65))
.forEach(
peer ->
transactions.forEach(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.hyperledger.besu.ethereum.core.Hash;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;
Expand Down Expand Up @@ -111,7 +112,7 @@ void handleConnect(final EthPeer peer) {
for (final Transaction transaction : localTransactions) {
peerTransactionTracker.addToPeerSendQueue(peer, transaction);
}
if (peerPendingTransactionTracker.isPeerSupported(peer)) {
if (peerPendingTransactionTracker.isPeerSupported(peer, EthProtocol.ETH65)) {
final Collection<Hash> hashes = getNewPooledHashes();
for (final Hash hash : hashes) {
peerPendingTransactionTracker.addToPeerSendQueue(peer, hash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.hyperledger.besu.ethereum.core.Hash;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
Expand Down Expand Up @@ -57,8 +58,8 @@ public void testSendEth65PeersOnly() {
EthPeers ethPeers = mock(EthPeers.class);
when(ethContext.getEthPeers()).thenReturn(ethPeers);
when(ethPeers.streamAvailablePeers()).thenReturn(Arrays.asList(peer1, peer2).stream());
when(peerPendingTransactionTracker.isPeerSupported(peer1)).thenReturn(true);
when(peerPendingTransactionTracker.isPeerSupported(peer2)).thenReturn(false);
when(peerPendingTransactionTracker.isPeerSupported(peer1, EthProtocol.ETH65)).thenReturn(true);
when(peerPendingTransactionTracker.isPeerSupported(peer2, EthProtocol.ETH65)).thenReturn(false);
sender.onTransactionsAdded(Collections.singleton(tx));
verify(peerPendingTransactionTracker, times(1)).addToPeerSendQueue(peer1, hash);
verify(peerPendingTransactionTracker, never()).addToPeerSendQueue(peer2, hash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.core.TransactionTestFixture;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
Expand Down Expand Up @@ -496,8 +497,9 @@ public void shouldNotNotifyBatchListenerIfNoTransactionsAreAdded() {
public void shouldNotNotifyPeerForPendingTransactionsIfItDoesntSupportEth65() {
EthPeer peer = mock(EthPeer.class);
EthPeer validPeer = mock(EthPeer.class);
when(peerPendingTransactionTracker.isPeerSupported(peer)).thenReturn(false);
when(peerPendingTransactionTracker.isPeerSupported(validPeer)).thenReturn(true);
when(peerPendingTransactionTracker.isPeerSupported(peer, EthProtocol.ETH65)).thenReturn(false);
when(peerPendingTransactionTracker.isPeerSupported(validPeer, EthProtocol.ETH65))
.thenReturn(true);
when(transactionValidator.validate(any())).thenReturn(valid());
transactionPool.addTransactionHash(transaction1.getHash());
transactionPool.handleConnect(peer);
Expand Down