Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Jan 10, 2025
1 parent 7a63cfe commit d63e446
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SyncConfig {
public static final int DEFAULT_HISTORICAL_SYNC_BATCH_SIZE = 50;
public static final int DEFAULT_FORWARD_SYNC_MAX_PENDING_BATCHES = 5;
public static final int DEFAULT_FORWARD_SYNC_MAX_BLOCKS_PER_MINUTE = 500;
public static final int DEFAULT_FORWARD_SYNC_MAX_BLOB_SIDECARS_PER_MINUTE = 1250;
public static final int DEFAULT_FORWARD_SYNC_MAX_BLOB_SIDECARS_PER_MINUTE = 1500;

private final boolean isEnabled;
private final boolean isMultiPeerSyncEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ eventThread, blobSidecarManager, new PeerScoringConflictResolutionStrategy()),
eventThread,
p2pNetwork,
new SyncSourceFactory(
asyncRunner, timeProvider, maxBlocksPerMinute, maxBlobSidecarsPerMinute),
asyncRunner, timeProvider, batchSize, maxBlocksPerMinute, maxBlobSidecarsPerMinute),
finalizedTargetChains,
nonfinalizedTargetChains);
peerChainTracker.subscribeToTargetChainUpdates(syncController::onTargetChainsUpdated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.beacon.sync.forward.multipeer.chains;

import com.google.common.base.Preconditions;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
Expand All @@ -21,12 +22,12 @@
import tech.pegasys.teku.networking.eth2.peers.Eth2Peer;
import tech.pegasys.teku.networking.eth2.peers.SyncSource;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecMilestone;

public class SyncSourceFactory {

private final AsyncRunner asyncRunner;
private final TimeProvider timeProvider;
private final int batchSize;
private final int maxBlocksPerMinute;
private final int maxBlobSidecarsPerMinute;

Expand All @@ -35,15 +36,42 @@ public class SyncSourceFactory {
public SyncSourceFactory(
final AsyncRunner asyncRunner,
final TimeProvider timeProvider,
final int batchSize,
final int maxBlocksPerMinute,
final int maxBlobSidecarsPerMinute) {
this.asyncRunner = asyncRunner;
this.timeProvider = timeProvider;
this.batchSize = batchSize;
this.maxBlocksPerMinute = maxBlocksPerMinute;
this.maxBlobSidecarsPerMinute = maxBlobSidecarsPerMinute;
}

public SyncSource getOrCreateSyncSource(final Eth2Peer peer, final Spec spec) {
// Limit request rates for blocks/blobs to just a little under what we'd accept (see
// Eth2PeerFactory)
final int maxBlocksPerMinute = this.maxBlocksPerMinute - batchSize - 1;

Check notice

Code scanning / CodeQL

Possible confusion of local and field Note

Potentially confusing name: method
getOrCreateSyncSource
also refers to field
maxBlocksPerMinute
(as this.maxBlocksPerMinute).
Preconditions.checkState(
maxBlocksPerMinute > 0,
"maxBlocksPerMinute should be a positive number but was %s",
maxBlocksPerMinute);
final Optional<Integer> maybeMaxBlobSidecarsPerMinute =
spec.getMaxBlobsPerBlockForHighestMilestone()
.map(
maxBlobsPerBlock -> {
final int maximumAcceptedBlobsPerMinute =
this.maxBlocksPerMinute * maxBlobsPerBlock;
// The default configured value for requesting is less than what we'd accept to
// avoid requesting a very large number of blobs in a short amount of time
final int maxBlobSidecarsPerMinute =
Math.min(
this.maxBlobSidecarsPerMinute,
maximumAcceptedBlobsPerMinute - (batchSize * maxBlobsPerBlock) - 1);
Preconditions.checkState(
maxBlobSidecarsPerMinute > 0,
"maxBlobSidecarsPerMinute should be a positive number but was %s",
maxBlobSidecarsPerMinute);
return maxBlobSidecarsPerMinute;
});
return syncSourcesByPeer.computeIfAbsent(
peer,
source ->
Expand All @@ -52,9 +80,7 @@ public SyncSource getOrCreateSyncSource(final Eth2Peer peer, final Spec spec) {
timeProvider,
source,
maxBlocksPerMinute,
spec.isMilestoneSupported(SpecMilestone.DENEB)
? Optional.of(maxBlobSidecarsPerMinute)
: Optional.empty()));
maybeMaxBlobSidecarsPerMinute));
}

public void onPeerDisconnected(final Eth2Peer peer) {
Expand Down

0 comments on commit d63e446

Please sign in to comment.