From 233e7f2354d8e77867ba9982fa05f9749fe3ed2f Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Fri, 10 Jan 2025 18:35:54 +0200 Subject: [PATCH] few changes --- .../multipeer/chains/SyncSourceFactory.java | 10 +--- .../eth2/Eth2P2PNetworkBuilder.java | 3 +- .../teku/networking/eth2/P2PConfig.java | 47 ++++++++++++++----- .../eth2/peers/Eth2PeerFactory.java | 16 +++---- .../eth2/peers/Eth2PeerManager.java | 6 ++- .../eth2/Eth2P2PNetworkFactory.java | 5 +- .../pegasys/teku/cli/options/P2POptions.java | 19 ++++++-- .../teku/cli/BeaconNodeCommandTest.java | 13 +++-- .../options/Eth2P2PNetworkOptionsTest.java | 14 ++++-- .../teku/cli/options/P2POptionsTest.java | 3 +- .../src/test/resources/P2POptions_config.yaml | 3 +- 11 files changed, 92 insertions(+), 47 deletions(-) diff --git a/beacon/sync/src/main/java/tech/pegasys/teku/beacon/sync/forward/multipeer/chains/SyncSourceFactory.java b/beacon/sync/src/main/java/tech/pegasys/teku/beacon/sync/forward/multipeer/chains/SyncSourceFactory.java index c9411b4f316..bc04b7fa451 100644 --- a/beacon/sync/src/main/java/tech/pegasys/teku/beacon/sync/forward/multipeer/chains/SyncSourceFactory.java +++ b/beacon/sync/src/main/java/tech/pegasys/teku/beacon/sync/forward/multipeer/chains/SyncSourceFactory.java @@ -52,14 +52,8 @@ public SyncSource getOrCreateSyncSource(final Eth2Peer peer, final Spec spec) { final Optional maybeMaxBlobSidecarsPerMinute = spec.getMaxBlobsPerBlockForHighestMilestone() .map( - maxBlobsPerBlock -> { - final int maxBlobSidecarsPerMinuteUpperBound = - ((this.maxBlocksPerMinute - batchSize) * maxBlobsPerBlock) - 1; - // 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, so - // choose the minimum of the two - return Math.min(maxBlobSidecarsPerMinute, maxBlobSidecarsPerMinuteUpperBound); - }); + maxBlobsPerBlock -> + this.maxBlobSidecarsPerMinute - (batchSize * maxBlobsPerBlock) - 1); return syncSourcesByPeer.computeIfAbsent( peer, source -> diff --git a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkBuilder.java b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkBuilder.java index bd470eb3ffb..9467a22d4a3 100644 --- a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkBuilder.java +++ b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkBuilder.java @@ -162,7 +162,8 @@ public Eth2P2PNetwork build() { eth2RpcOutstandingPingThreshold, eth2StatusUpdateInterval, timeProvider, - config.getPeerRateLimit(), + config.getPeerBlocksRateLimit(), + config.getPeerBlobSidecarsRateLimit(), config.getPeerRequestLimit(), spec, kzg, diff --git a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/P2PConfig.java b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/P2PConfig.java index c8010945433..93827f0e00f 100644 --- a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/P2PConfig.java +++ b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/P2PConfig.java @@ -31,7 +31,9 @@ public class P2PConfig { - public static final int DEFAULT_PEER_RATE_LIMIT = 500; + public static final int DEFAULT_PEER_BLOCKS_RATE_LIMIT = 500; + public static final int DEFAULT_PEER_BLOB_SIDECARS_RATE_LIMIT = 1500; + public static final int DEFAULT_PEER_REQUEST_LIMIT = 100; public static final boolean DEFAULT_PEER_ALL_TOPIC_FILTER_ENABLED = true; @@ -54,7 +56,8 @@ public class P2PConfig { private final GossipEncoding gossipEncoding; private final int targetSubnetSubscriberCount; private final boolean subscribeAllSubnetsEnabled; - private final int peerRateLimit; + private final int peerBlocksRateLimit; + private final int peerBlobSidecarsRateLimit; private final int peerRequestLimit; private final int batchVerifyMaxThreads; private final int batchVerifyQueueCapacity; @@ -71,7 +74,8 @@ private P2PConfig( final GossipEncoding gossipEncoding, final int targetSubnetSubscriberCount, final boolean subscribeAllSubnetsEnabled, - final int peerRateLimit, + final int peerBlocksRateLimit, + final int peerBlobSidecarsRateLimit, final int peerRequestLimit, final int batchVerifyMaxThreads, final int batchVerifyQueueCapacity, @@ -86,7 +90,8 @@ private P2PConfig( this.gossipEncoding = gossipEncoding; this.targetSubnetSubscriberCount = targetSubnetSubscriberCount; this.subscribeAllSubnetsEnabled = subscribeAllSubnetsEnabled; - this.peerRateLimit = peerRateLimit; + this.peerBlocksRateLimit = peerBlocksRateLimit; + this.peerBlobSidecarsRateLimit = peerBlobSidecarsRateLimit; this.peerRequestLimit = peerRequestLimit; this.batchVerifyMaxThreads = batchVerifyMaxThreads; this.batchVerifyQueueCapacity = batchVerifyQueueCapacity; @@ -129,8 +134,12 @@ public boolean isSubscribeAllSubnetsEnabled() { return subscribeAllSubnetsEnabled; } - public int getPeerRateLimit() { - return peerRateLimit; + public int getPeerBlocksRateLimit() { + return peerBlocksRateLimit; + } + + public int getPeerBlobSidecarsRateLimit() { + return peerBlobSidecarsRateLimit; } public int getPeerRequestLimit() { @@ -174,7 +183,8 @@ public static class Builder { private final GossipEncoding gossipEncoding = GossipEncoding.SSZ_SNAPPY; private Integer targetSubnetSubscriberCount = DEFAULT_P2P_TARGET_SUBNET_SUBSCRIBER_COUNT; private Boolean subscribeAllSubnetsEnabled = DEFAULT_SUBSCRIBE_ALL_SUBNETS_ENABLED; - private Integer peerRateLimit = DEFAULT_PEER_RATE_LIMIT; + private Integer peerBlocksRateLimit = DEFAULT_PEER_BLOCKS_RATE_LIMIT; + private Integer peerBlobSidecarsRateLimit = DEFAULT_PEER_BLOB_SIDECARS_RATE_LIMIT; private Integer peerRequestLimit = DEFAULT_PEER_REQUEST_LIMIT; private int batchVerifyMaxThreads = DEFAULT_BATCH_VERIFY_MAX_THREADS; private OptionalInt batchVerifyQueueCapacity = OptionalInt.empty(); @@ -225,7 +235,8 @@ public P2PConfig build() { gossipEncoding, targetSubnetSubscriberCount, subscribeAllSubnetsEnabled, - peerRateLimit, + peerBlocksRateLimit, + peerBlobSidecarsRateLimit, peerRequestLimit, batchVerifyMaxThreads, batchVerifyQueueCapacity.orElse(DEFAULT_BATCH_VERIFY_QUEUE_CAPACITY), @@ -277,13 +288,23 @@ public Builder subscribeAllSubnetsEnabled(final Boolean subscribeAllSubnetsEnabl return this; } - public Builder peerRateLimit(final Integer peerRateLimit) { - checkNotNull(peerRateLimit); - if (peerRateLimit < 0) { + public Builder peerBlocksRateLimit(final Integer peerBlocksRateLimit) { + checkNotNull(peerBlocksRateLimit); + if (peerBlocksRateLimit < 0) { + throw new InvalidConfigurationException( + String.format("Invalid peerBlocksRateLimit: %d", peerBlocksRateLimit)); + } + this.peerBlocksRateLimit = peerBlocksRateLimit; + return this; + } + + public Builder peerBlobSidecarsRateLimit(final Integer peerBlobSidecarsRateLimit) { + checkNotNull(peerBlobSidecarsRateLimit); + if (peerBlobSidecarsRateLimit < 0) { throw new InvalidConfigurationException( - String.format("Invalid peerRateLimit: %d", peerRateLimit)); + String.format("Invalid peerBlobSidecarsRateLimit: %d", peerBlobSidecarsRateLimit)); } - this.peerRateLimit = peerRateLimit; + this.peerBlobSidecarsRateLimit = peerBlobSidecarsRateLimit; return this; } diff --git a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerFactory.java b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerFactory.java index 2122c93ff19..95dc0962180 100644 --- a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerFactory.java +++ b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerFactory.java @@ -35,7 +35,8 @@ public class Eth2PeerFactory { private final CombinedChainDataClient chainDataClient; private final TimeProvider timeProvider; private final Optional requiredCheckpoint; - private final int peerRateLimit; + private final int peerBlocksRateLimit; + private final int peerBlobSidecarsRateLimit; private final int peerRequestLimit; private final KZG kzg; private final DiscoveryNodeIdExtractor discoveryNodeIdExtractor; @@ -48,7 +49,8 @@ public Eth2PeerFactory( final MetadataMessagesFactory metadataMessagesFactory, final TimeProvider timeProvider, final Optional requiredCheckpoint, - final int peerRateLimit, + final int peerBlocksRateLimit, + final int peerBlobSidecarsRateLimit, final int peerRequestLimit, final KZG kzg, final DiscoveryNodeIdExtractor discoveryNodeIdExtractor) { @@ -59,7 +61,8 @@ public Eth2PeerFactory( this.statusMessageFactory = statusMessageFactory; this.metadataMessagesFactory = metadataMessagesFactory; this.requiredCheckpoint = requiredCheckpoint; - this.peerRateLimit = peerRateLimit; + this.peerBlocksRateLimit = peerBlocksRateLimit; + this.peerBlobSidecarsRateLimit = peerBlobSidecarsRateLimit; this.peerRequestLimit = peerRequestLimit; this.kzg = kzg; this.discoveryNodeIdExtractor = discoveryNodeIdExtractor; @@ -74,11 +77,8 @@ public Eth2Peer create(final Peer peer, final BeaconChainMethods rpcMethods) { statusMessageFactory, metadataMessagesFactory, PeerChainValidator.create(spec, metricsSystem, chainDataClient, requiredCheckpoint), - RateTracker.create(peerRateLimit, TIME_OUT, timeProvider), - RateTracker.create( - peerRateLimit * spec.getMaxBlobsPerBlockForHighestMilestone().orElse(1), - TIME_OUT, - timeProvider), + RateTracker.create(peerBlocksRateLimit, TIME_OUT, timeProvider), + RateTracker.create(peerBlobSidecarsRateLimit, TIME_OUT, timeProvider), RateTracker.create(peerRequestLimit, TIME_OUT, timeProvider), kzg); } diff --git a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerManager.java b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerManager.java index 88e57f491a7..4ea63f4c17d 100644 --- a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerManager.java +++ b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerManager.java @@ -114,7 +114,8 @@ public static Eth2PeerManager create( final int eth2RpcOutstandingPingThreshold, final Duration eth2StatusUpdateInterval, final TimeProvider timeProvider, - final int peerRateLimit, + final int peerBlocksRateLimit, + final int peerBlobSidecarsRateLimit, final int peerRequestLimit, final Spec spec, final KZG kzg, @@ -140,7 +141,8 @@ public static Eth2PeerManager create( metadataMessagesFactory, timeProvider, requiredCheckpoint, - peerRateLimit, + peerBlocksRateLimit, + peerBlobSidecarsRateLimit, peerRequestLimit, kzg, discoveryNodeIdExtractor), diff --git a/networking/eth2/src/testFixtures/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkFactory.java b/networking/eth2/src/testFixtures/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkFactory.java index 104c074f441..e2d9ea4f4bd 100644 --- a/networking/eth2/src/testFixtures/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkFactory.java +++ b/networking/eth2/src/testFixtures/java/tech/pegasys/teku/networking/eth2/Eth2P2PNetworkFactory.java @@ -225,8 +225,9 @@ protected Eth2P2PNetwork buildNetwork(final P2PConfig config) { eth2RpcOutstandingPingThreshold, eth2StatusUpdateInterval, timeProvider, - 500, - 50, + P2PConfig.DEFAULT_PEER_BLOCKS_RATE_LIMIT, + P2PConfig.DEFAULT_PEER_BLOB_SIDECARS_RATE_LIMIT, + P2PConfig.DEFAULT_PEER_REQUEST_LIMIT, spec, KZG.NOOP, (__) -> Optional.empty()); diff --git a/teku/src/main/java/tech/pegasys/teku/cli/options/P2POptions.java b/teku/src/main/java/tech/pegasys/teku/cli/options/P2POptions.java index cc37a972e25..40fd299d68a 100644 --- a/teku/src/main/java/tech/pegasys/teku/cli/options/P2POptions.java +++ b/teku/src/main/java/tech/pegasys/teku/cli/options/P2POptions.java @@ -294,14 +294,22 @@ The network interface(s) on which the node listens for P2P communication. private boolean gossipScoringEnabled = P2PConfig.DEFAULT_GOSSIP_SCORING_ENABLED; @Option( - names = {"--Xpeer-rate-limit"}, + names = {"--Xpeer-blocks-rate-limit"}, paramLabel = "", description = - "The number of requested blocks/blobs per peer to allow per minute before disconnecting the peer.\n" - + "NOTE: the actual size for the allowed blobs per peer per minute will be `maxBlobsPerBlock` times the value of this parameter.", + "The number of requested blocks per peer to allow per minute before disconnecting the peer.", arity = "1", hidden = true) - private Integer peerRateLimit = P2PConfig.DEFAULT_PEER_RATE_LIMIT; + private Integer peerBlocksRateLimit = P2PConfig.DEFAULT_PEER_BLOCKS_RATE_LIMIT; + + @Option( + names = {"--Xpeer-blob-sidecars-rate-limit"}, + paramLabel = "", + description = + "The number of requested blobs per peer to allow per minute before disconnecting the peer.", + arity = "1", + hidden = true) + private Integer peerBlobSidecarsRateLimit = P2PConfig.DEFAULT_PEER_BLOB_SIDECARS_RATE_LIMIT; @Option( names = {"--Xp2p-gossip-blobs-after-block-enabled"}, @@ -430,7 +438,8 @@ public void configure(final TekuConfiguration.Builder builder) { .batchVerifyStrictThreadLimitEnabled(batchVerifyStrictThreadLimitEnabled) .targetSubnetSubscriberCount(p2pTargetSubnetSubscriberCount) .isGossipScoringEnabled(gossipScoringEnabled) - .peerRateLimit(peerRateLimit) + .peerBlocksRateLimit(peerBlocksRateLimit) + .peerBlobSidecarsRateLimit(peerBlobSidecarsRateLimit) .allTopicsFilterEnabled(allTopicsFilterEnabled) .peerRequestLimit(peerRequestLimit) .floodPublishMaxMessageSizeThreshold(floodPublishMaxMessageSizeThreshold) diff --git a/teku/src/test/java/tech/pegasys/teku/cli/BeaconNodeCommandTest.java b/teku/src/test/java/tech/pegasys/teku/cli/BeaconNodeCommandTest.java index f347901ab8e..3bf9eeb11cd 100644 --- a/teku/src/test/java/tech/pegasys/teku/cli/BeaconNodeCommandTest.java +++ b/teku/src/test/java/tech/pegasys/teku/cli/BeaconNodeCommandTest.java @@ -556,8 +556,10 @@ private String[] createCliArgs() { "127.0.0.1", "--Xrest-api-max-url-length", "65535", - "--Xpeer-rate-limit", + "--Xpeer-blocks-rate-limit", "500", + "--Xpeer-blob-sidecars-rate-limit", + "1500", "--Xpeer-request-limit", "50" }; @@ -582,7 +584,7 @@ private TekuConfiguration.Builder expectedDefaultConfigurationBuilder() { .dataStorageMode(MINIMAL)) .metrics(b -> b.metricsCategories(DEFAULT_METRICS_CATEGORIES)) .restApi(b -> b.eth1DepositContractAddress(networkConfig.getEth1DepositContractAddress())) - .p2p(p -> p.peerRateLimit(500).peerRequestLimit(50)) + .p2p(p -> p.peerBlocksRateLimit(500).peerBlobSidecarsRateLimit(1500).peerRequestLimit(100)) .discovery( d -> d.isDiscoveryEnabled(true) @@ -623,7 +625,12 @@ private TekuConfiguration.Builder expectedConfigurationBuilder() { .dataStorageCreateDbVersion(DatabaseVersion.DEFAULT_VERSION) .maxKnownNodeCacheSize(100_000)) .data(b -> b.dataBasePath(dataPath)) - .p2p(b -> b.targetSubnetSubscriberCount(2).peerRateLimit(500).peerRequestLimit(50)) + .p2p( + b -> + b.targetSubnetSubscriberCount(2) + .peerBlocksRateLimit(500) + .peerBlobSidecarsRateLimit(1500) + .peerRequestLimit(100)) .discovery( d -> d.isDiscoveryEnabled(false) diff --git a/teku/src/test/java/tech/pegasys/teku/cli/options/Eth2P2PNetworkOptionsTest.java b/teku/src/test/java/tech/pegasys/teku/cli/options/Eth2P2PNetworkOptionsTest.java index 2bec62ab205..1ab771eaa56 100644 --- a/teku/src/test/java/tech/pegasys/teku/cli/options/Eth2P2PNetworkOptionsTest.java +++ b/teku/src/test/java/tech/pegasys/teku/cli/options/Eth2P2PNetworkOptionsTest.java @@ -128,11 +128,19 @@ public void usingNetworkFromUrl() { } @Test - public void setPeerRateLimit() { + public void setPeerBlocksRateLimit() { TekuConfiguration tekuConfiguration = - getTekuConfigurationFromArguments("--Xpeer-rate-limit", "10"); + getTekuConfigurationFromArguments("--Xpeer-blocks-rate-limit", "10"); final P2PConfig config = tekuConfiguration.beaconChain().p2pConfig(); - assertThat(config.getPeerRateLimit()).isEqualTo(10); + assertThat(config.getPeerBlocksRateLimit()).isEqualTo(10); + } + + @Test + public void setPeerBlobSidecarsRateLimit() { + TekuConfiguration tekuConfiguration = + getTekuConfigurationFromArguments("--Xpeer-blob-sidecars-rate-limit", "10"); + final P2PConfig config = tekuConfiguration.beaconChain().p2pConfig(); + assertThat(config.getPeerBlobSidecarsRateLimit()).isEqualTo(10); } @Test diff --git a/teku/src/test/java/tech/pegasys/teku/cli/options/P2POptionsTest.java b/teku/src/test/java/tech/pegasys/teku/cli/options/P2POptionsTest.java index 61d8b161414..b5fe9b8d6d4 100644 --- a/teku/src/test/java/tech/pegasys/teku/cli/options/P2POptionsTest.java +++ b/teku/src/test/java/tech/pegasys/teku/cli/options/P2POptionsTest.java @@ -43,7 +43,8 @@ public void shouldReadFromConfigurationFile() { final P2PConfig p2pConfig = tekuConfig.p2p(); assertThat(p2pConfig.getTargetSubnetSubscriberCount()).isEqualTo(5); - assertThat(p2pConfig.getPeerRateLimit()).isEqualTo(100); + assertThat(p2pConfig.getPeerBlocksRateLimit()).isEqualTo(100); + assertThat(p2pConfig.getPeerBlobSidecarsRateLimit()).isEqualTo(300); assertThat(p2pConfig.getPeerRequestLimit()).isEqualTo(101); final DiscoveryConfig discoConfig = tekuConfig.discovery(); diff --git a/teku/src/test/resources/P2POptions_config.yaml b/teku/src/test/resources/P2POptions_config.yaml index b4647ccc03a..92287485330 100644 --- a/teku/src/test/resources/P2POptions_config.yaml +++ b/teku/src/test/resources/P2POptions_config.yaml @@ -11,7 +11,8 @@ p2p-peer-lower-bound: 70 p2p-peer-upper-bound: 85 Xp2p-target-subnet-subscriber-count: 5 Xp2p-minimum-randomly-selected-peer-count: 1 -Xpeer-rate-limit: 100 +Xpeer-blocks-rate-limit: 100 +Xpeer-blob-sidecars-rate-limit: 300 Xpeer-request-limit: 101 Xp2p-historical-sync-batch-size: 102 Xp2p-sync-batch-size: 103