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

use peer reputation to compare current peers #7616

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Additions and Improvements
- Remove privacy test classes support [#7569](https://github.com/hyperledger/besu/pull/7569)
- Use peer reputation (then chain height) to compare current peers

### Bug fixes
- Fix for `debug_traceCall` to handle transactions without specified gas price. [#7510](https://github.com/hyperledger/besu/pull/7510)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public EthPeers(
this.clock = clock;
this.permissioningProviders = permissioningProviders;
this.maxMessageSize = maxMessageSize;
this.bestPeerComparator = HEAVIEST_CHAIN;
this.bestPeerComparator = MOST_USEFUL_PEER;
this.localNodeId = localNodeId;
this.peerUpperBound = peerUpperBound;
this.maxRemotelyInitiatedConnections = maxRemotelyInitiatedConnections;
Expand Down Expand Up @@ -369,7 +369,7 @@ public Optional<EthPeer> bestPeerMatchingCriteria(final Predicate<EthPeer> match
}

public void setBestPeerComparator(final Comparator<EthPeer> comparator) {
LOG.info("Updating the default best peer comparator");
LOG.info("Updating the default best peer comparator to {}", comparator);
bestPeerComparator = comparator;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public void comparesPeersWithHeightAndTd() {
assertThat(EthPeers.HEAVIEST_CHAIN.compare(peerA, peerA)).isEqualTo(0);
assertThat(EthPeers.HEAVIEST_CHAIN.compare(peerB, peerB)).isEqualTo(0);

ethProtocolManager.ethContext().getEthPeers().setBestPeerComparator(EthPeers.HEAVIEST_CHAIN);
assertThat(ethProtocolManager.ethContext().getEthPeers().bestPeer()).contains(peerB);
assertThat(ethProtocolManager.ethContext().getEthPeers().bestPeerWithHeightEstimate())
.contains(peerB);
Expand Down Expand Up @@ -113,6 +114,7 @@ public void comparesPeersWithTdAndNoHeight() {
assertThat(EthPeers.HEAVIEST_CHAIN.compare(peerA, peerA)).isEqualTo(0);
assertThat(EthPeers.HEAVIEST_CHAIN.compare(peerB, peerB)).isEqualTo(0);

ethProtocolManager.ethContext().getEthPeers().setBestPeerComparator(EthPeers.HEAVIEST_CHAIN);
assertThat(ethProtocolManager.ethContext().getEthPeers().bestPeer()).contains(peerA);
assertThat(ethProtocolManager.ethContext().getEthPeers().bestPeerWithHeightEstimate())
.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ protected void setup(final DataStorageFormat dataStorageFormat) {
blockchainUtil.getTransactionPool(),
EthProtocolConfiguration.defaultConfig());
syncConfig = SynchronizerConfiguration.builder().blockPropagationRange(-3, 5).build();
syncState = new SyncState(blockchain, ethProtocolManager.ethContext().getEthPeers());

// for tests use simple peer comparator
final EthPeers ethPeers = ethProtocolManager.ethContext().getEthPeers();
ethPeers.setBestPeerComparator(EthPeers.HEAVIEST_CHAIN);

syncState = new SyncState(blockchain, ethPeers);

blockBroadcaster = mock(BlockBroadcaster.class);
blockPropagationManager =
new BlockPropagationManager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockDataGenerator;
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.plugin.services.BesuEvents;

import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -176,6 +177,8 @@ public void shouldAwokeWhenConditionReachedAndReady() throws Exception {
when(context.getSyncState().subscribeTTDReached(any())).thenReturn(88L);
when(context.getSyncState().subscribeCompletionReached(any())).thenReturn(99L);
when(context.getEthContext().getEthPeers().peerCount()).thenReturn(1);
when(context.getEthContext().getEthPeers().getBestPeerComparator())
.thenReturn(EthPeers.HEAVIEST_CHAIN);

final CompletableFuture<Void> voidCompletableFuture = algorithm.waitForReady();
Thread.sleep(50);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ public void setUp(final DataStorageFormat storageFormat) {
blockchainSetupUtil.getTransactionPool(),
EthProtocolConfiguration.defaultConfig());
ethContext = ethProtocolManager.ethContext();

ethPeers = ethContext.getEthPeers();
// for tests use the heaviest chain comparator
ethPeers.setBestPeerComparator(EthPeers.HEAVIEST_CHAIN);

syncState = new SyncState(blockchain, ethPeers);
metricsSystem = new NoOpMetricsSystem();
fastSyncActions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
Expand Down Expand Up @@ -104,6 +105,8 @@ public void setupTest(final DataStorageFormat storageFormat) {
localBlockchainSetup.getTransactionPool(),
EthProtocolConfiguration.defaultConfig());
ethContext = ethProtocolManager.ethContext();
// for tests use the heaviest chain comparator
ethContext.getEthPeers().setBestPeerComparator(EthPeers.HEAVIEST_CHAIN);
syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers());
}

Expand Down
Loading