Skip to content

Commit

Permalink
Remove MetricsSystem from PivotSelectorFromPeers
Browse files Browse the repository at this point in the history
Signed-off-by: Matilda Clerke <[email protected]>
  • Loading branch information
Matilda-Clerke committed Dec 17, 2024
1 parent e3919bc commit 4cdf752
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,6 @@ private PivotBlockSelector createPivotSelector(
ethContext,
syncConfig,
syncState,
metricsSystem,
protocolContext,
nodeKey,
blockchain.getChainHeadHeader());
Expand Down Expand Up @@ -954,7 +953,7 @@ private PivotBlockSelector createPivotSelector(
unsubscribeForkchoiceListener);
} else {
LOG.info("TTD difficulty is not present, creating initial sync phase for PoW");
return new PivotSelectorFromPeers(ethContext, syncConfig, syncState, metricsSystem);
return new PivotSelectorFromPeers(ethContext, syncConfig, syncState);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.hyperledger.besu.ethereum.eth.sync.fastsync.NoSyncRequiredException;
import org.hyperledger.besu.ethereum.eth.sync.fastsync.PivotSelectorFromPeers;
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;
import org.hyperledger.besu.plugin.services.MetricsSystem;

import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -56,7 +55,6 @@ public class BFTPivotSelectorFromPeers extends PivotSelectorFromPeers {
* @param ethContext the eth context
* @param syncConfig the sync config
* @param syncState the sync state
* @param metricsSystem the metrics
* @param protocolContext the protocol context
* @param nodeKey the node key
* @param blockHeader the block header
Expand All @@ -65,11 +63,10 @@ public BFTPivotSelectorFromPeers(
final EthContext ethContext,
final SynchronizerConfiguration syncConfig,
final SyncState syncState,
final MetricsSystem metricsSystem,
final ProtocolContext protocolContext,
final NodeKey nodeKey,
final BlockHeader blockHeader) {
super(ethContext, syncConfig, syncState, metricsSystem);
super(ethContext, syncConfig, syncState);
this.protocolContext = protocolContext;
this.blockHeader = blockHeader;
this.nodeKey = nodeKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState;
import org.hyperledger.besu.ethereum.eth.sync.fastsync.NoSyncRequiredException;
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;
import org.hyperledger.besu.plugin.services.MetricsSystem;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -55,7 +54,6 @@ public class QbftPivotSelectorTest {
@Mock private ProtocolContext protocolContext;
@Mock private BftContext bftContext;
@Mock private SyncState syncState;
@Mock private MetricsSystem metricsSystem;
@Mock private EthContext ethContext;
@Mock private EthPeers ethPeers;
@Mock private ValidatorProvider validatorProvider;
Expand All @@ -80,13 +78,7 @@ public void returnEmptySyncStateIfValidatorWithOtherValidatorsButNoPeers() {
when(validatorProvider.getValidatorsAtHead()).thenReturn(validatorList);
BFTPivotSelectorFromPeers pivotSelector =
new BFTPivotSelectorFromPeers(
ethContext,
syncConfig,
syncState,
metricsSystem,
protocolContext,
nodeKey,
blockHeader);
ethContext, syncConfig, syncState, protocolContext, nodeKey, blockHeader);
Optional<FastSyncState> pivotState = pivotSelector.selectNewPivotBlock();
assertThat(pivotState.isEmpty()).isTrue();
}
Expand All @@ -104,13 +96,7 @@ public void returnNoSyncRequiredIfOnlyValidatorAndNoPeers() {
when(validatorProvider.getValidatorsAtHead()).thenReturn(validatorList);
BFTPivotSelectorFromPeers pivotSelector =
new BFTPivotSelectorFromPeers(
ethContext,
syncConfig,
syncState,
metricsSystem,
protocolContext,
nodeKey,
blockHeader);
ethContext, syncConfig, syncState, protocolContext, nodeKey, blockHeader);

try {
Optional<FastSyncState> pivotState = pivotSelector.selectNewPivotBlock();
Expand All @@ -126,13 +112,7 @@ public void returnEmptySyncStateIfNonValidatorWithNoBestPeer() {
when(validatorProvider.nodeIsValidator(any())).thenReturn(false);
BFTPivotSelectorFromPeers pivotSelector =
new BFTPivotSelectorFromPeers(
ethContext,
syncConfig,
syncState,
metricsSystem,
protocolContext,
nodeKey,
blockHeader);
ethContext, syncConfig, syncState, protocolContext, nodeKey, blockHeader);

Optional<FastSyncState> pivotState = pivotSelector.selectNewPivotBlock();
assertThat(pivotState.isEmpty()).isTrue();
Expand All @@ -145,13 +125,7 @@ public void returnEmptySyncStateIfValidatorAndNotAtGenesisAndOtherValidators() {
when(blockHeader.getNumber()).thenReturn(10L);
BFTPivotSelectorFromPeers pivotSelector =
new BFTPivotSelectorFromPeers(
ethContext,
syncConfig,
syncState,
metricsSystem,
protocolContext,
nodeKey,
blockHeader);
ethContext, syncConfig, syncState, protocolContext, nodeKey, blockHeader);

Optional<FastSyncState> pivotState = pivotSelector.selectNewPivotBlock();
assertThat(pivotState.isEmpty()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.hyperledger.besu.ethereum.eth.sync.TrailingPeerLimiter;
import org.hyperledger.besu.ethereum.eth.sync.TrailingPeerRequirements;
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;
import org.hyperledger.besu.plugin.services.MetricsSystem;

import java.util.Optional;
import java.util.concurrent.CompletableFuture;
Expand All @@ -41,8 +40,7 @@ public class PivotSelectorFromPeers implements PivotBlockSelector {
public PivotSelectorFromPeers(
final EthContext ethContext,
final SynchronizerConfiguration syncConfig,
final SyncState syncState,
final MetricsSystem metricsSystem) {
final SyncState syncState) {
this.ethContext = ethContext;
this.syncConfig = syncConfig;
this.syncState = syncState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ public void setUp(
metricsSystem = new NoOpMetricsSystem();
fastSyncActions =
createFastSyncActions(
syncConfig,
new PivotSelectorFromPeers(ethContext, syncConfig, syncState, metricsSystem));
syncConfig, new PivotSelectorFromPeers(ethContext, syncConfig, syncState));
}

@ParameterizedTest
Expand Down Expand Up @@ -171,8 +170,7 @@ public void selectPivotBlockShouldSelectBlockPivotDistanceFromBestPeer(

fastSyncActions =
createFastSyncActions(
syncConfig,
new PivotSelectorFromPeers(ethContext, syncConfig, syncState, metricsSystem));
syncConfig, new PivotSelectorFromPeers(ethContext, syncConfig, syncState));

EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 5000);

Expand All @@ -189,8 +187,7 @@ public void selectPivotBlockShouldConsiderTotalDifficultyWhenSelectingBestPeer(
setUp(storageFormat, false, Optional.of(1));
fastSyncActions =
createFastSyncActions(
syncConfig,
new PivotSelectorFromPeers(ethContext, syncConfig, syncState, metricsSystem));
syncConfig, new PivotSelectorFromPeers(ethContext, syncConfig, syncState));

EthProtocolManagerTestUtil.createPeer(ethProtocolManager, Difficulty.of(1000), 5500);
EthProtocolManagerTestUtil.createPeer(ethProtocolManager, Difficulty.of(2000), 4000);
Expand All @@ -209,8 +206,7 @@ public void selectPivotBlockShouldWaitAndRetryUntilMinHeightEstimatesAreAvailabl
EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager);
fastSyncActions =
createFastSyncActions(
syncConfig,
new PivotSelectorFromPeers(ethContext, syncConfig, syncState, metricsSystem));
syncConfig, new PivotSelectorFromPeers(ethContext, syncConfig, syncState));

final CompletableFuture<FastSyncState> result =
fastSyncActions.selectPivotBlock(FastSyncState.EMPTY_SYNC_STATE);
Expand Down Expand Up @@ -283,8 +279,7 @@ private void selectPivotBlockUsesBestPeerMatchingRequiredCriteria(
final int peerCount = 4;
fastSyncActions =
createFastSyncActions(
syncConfig,
new PivotSelectorFromPeers(ethContext, syncConfig, syncState, metricsSystem));
syncConfig, new PivotSelectorFromPeers(ethContext, syncConfig, syncState));
final long minPivotHeight = syncConfig.getSyncPivotDistance() + 1L;
EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager);

Expand Down Expand Up @@ -332,8 +327,7 @@ public void selectPivotBlockShouldWaitAndRetryIfBestPeerChainIsShorterThanPivotD
setUp(storageFormat, false, Optional.of(1));
fastSyncActions =
createFastSyncActions(
syncConfig,
new PivotSelectorFromPeers(ethContext, syncConfig, syncState, metricsSystem));
syncConfig, new PivotSelectorFromPeers(ethContext, syncConfig, syncState));
final long pivotDistance = syncConfig.getSyncPivotDistance();

EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager);
Expand Down Expand Up @@ -394,8 +388,7 @@ public void downloadPivotBlockHeaderShouldRetrievePivotBlockHeader(
setUp(storageFormat, false, Optional.of(1));
fastSyncActions =
createFastSyncActions(
syncConfig,
new PivotSelectorFromPeers(ethContext, syncConfig, syncState, metricsSystem));
syncConfig, new PivotSelectorFromPeers(ethContext, syncConfig, syncState));

final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 1001);
final CompletableFuture<FastSyncState> result =
Expand Down

0 comments on commit 4cdf752

Please sign in to comment.