Skip to content

Commit 3bb7eee

Browse files
committed
Revert "Deprecate TTFB, RESP_TIMEOUT, introduce MAX_CONCURRENT_REQUESTS (Consensys#8839)"
This reverts commit d633566.
1 parent 5f28824 commit 3bb7eee

File tree

13 files changed

+205
-124
lines changed

13 files changed

+205
-124
lines changed

ethereum/spec/src/main/java/tech/pegasys/teku/spec/constants/NetworkConstants.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,4 @@ public class NetworkConstants {
2020
public static final int DEFAULT_SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY = 128;
2121

2222
public static final int NODE_ID_BITS = 256;
23-
24-
// https://github.com/ethereum/consensus-specs/pull/3767
25-
public static final int MAX_CONCURRENT_REQUESTS = 2;
2623
}

infrastructure/async/src/main/java/tech/pegasys/teku/infrastructure/async/ThrottlingTaskQueue.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ public class ThrottlingTaskQueue {
2828

2929
private int inflightTaskCount = 0;
3030

31-
public static ThrottlingTaskQueue create(final int maximumConcurrentTasks) {
32-
return new ThrottlingTaskQueue(maximumConcurrentTasks);
33-
}
34-
3531
public static ThrottlingTaskQueue create(
3632
final int maximumConcurrentTasks,
3733
final MetricsSystem metricsSystem,

networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/peers/Eth2PeerManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import tech.pegasys.teku.networking.p2p.peer.Peer;
4242
import tech.pegasys.teku.networking.p2p.peer.PeerConnectedSubscriber;
4343
import tech.pegasys.teku.spec.Spec;
44+
import tech.pegasys.teku.spec.config.SpecConfig;
4445
import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage;
4546
import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessageSchema;
4647
import tech.pegasys.teku.spec.datastructures.state.Checkpoint;
@@ -50,8 +51,6 @@
5051
public class Eth2PeerManager implements PeerLookup, PeerHandler {
5152
private static final Logger LOG = LogManager.getLogger();
5253

53-
private static final Duration STATUS_RECEIVED_TIMEOUT = Duration.ofSeconds(10);
54-
5554
private final AsyncRunner asyncRunner;
5655
private final RecentChainData recentChainData;
5756
private final Eth2PeerFactory eth2PeerFactory;
@@ -67,6 +66,7 @@ public class Eth2PeerManager implements PeerLookup, PeerHandler {
6766
private final int eth2RpcOutstandingPingThreshold;
6867

6968
private final Duration eth2StatusUpdateInterval;
69+
private final SpecConfig specConfig;
7070

7171
Eth2PeerManager(
7272
final Spec spec,
@@ -99,6 +99,7 @@ public class Eth2PeerManager implements PeerLookup, PeerHandler {
9999
this.eth2RpcPingInterval = eth2RpcPingInterval;
100100
this.eth2RpcOutstandingPingThreshold = eth2RpcOutstandingPingThreshold;
101101
this.eth2StatusUpdateInterval = eth2StatusUpdateInterval;
102+
this.specConfig = spec.getGenesisSpecConfig();
102103
}
103104

104105
public static Eth2PeerManager create(
@@ -236,7 +237,7 @@ private void ensureStatusReceived(final Eth2Peer peer) {
236237
.ifExceptionGetsHereRaiseABug();
237238
}
238239
},
239-
STATUS_RECEIVED_TIMEOUT)
240+
Duration.ofSeconds(specConfig.getRespTimeout()))
240241
.finish(
241242
() -> {},
242243
error -> {

networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/BeaconChainMethods.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ public static BeaconChainMethods create(
115115
final MetadataMessagesFactory metadataMessagesFactory,
116116
final RpcEncoding rpcEncoding) {
117117
return new BeaconChainMethods(
118-
createStatus(asyncRunner, statusMessageFactory, peerLookup, rpcEncoding),
119-
createGoodBye(asyncRunner, metricsSystem, peerLookup, rpcEncoding),
118+
createStatus(spec, asyncRunner, statusMessageFactory, peerLookup, rpcEncoding),
119+
createGoodBye(spec, asyncRunner, metricsSystem, peerLookup, rpcEncoding),
120120
createBeaconBlocksByRoot(
121121
spec, metricsSystem, asyncRunner, recentChainData, peerLookup, rpcEncoding),
122122
createBeaconBlocksByRange(
@@ -144,10 +144,11 @@ public static BeaconChainMethods create(
144144
rpcEncoding,
145145
recentChainData),
146146
createMetadata(spec, asyncRunner, metadataMessagesFactory, peerLookup, rpcEncoding),
147-
createPing(asyncRunner, metadataMessagesFactory, peerLookup, rpcEncoding));
147+
createPing(spec, asyncRunner, metadataMessagesFactory, peerLookup, rpcEncoding));
148148
}
149149

150150
private static Eth2RpcMethod<StatusMessage, StatusMessage> createStatus(
151+
final Spec spec,
151152
final AsyncRunner asyncRunner,
152153
final StatusMessageFactory statusMessageFactory,
153154
final PeerLookup peerLookup,
@@ -164,10 +165,12 @@ private static Eth2RpcMethod<StatusMessage, StatusMessage> createStatus(
164165
true,
165166
contextCodec,
166167
statusHandler,
167-
peerLookup);
168+
peerLookup,
169+
spec.getNetworkingConfig());
168170
}
169171

170172
private static Eth2RpcMethod<GoodbyeMessage, GoodbyeMessage> createGoodBye(
173+
final Spec spec,
171174
final AsyncRunner asyncRunner,
172175
final MetricsSystem metricsSystem,
173176
final PeerLookup peerLookup,
@@ -184,7 +187,8 @@ private static Eth2RpcMethod<GoodbyeMessage, GoodbyeMessage> createGoodBye(
184187
false,
185188
contextCodec,
186189
goodbyeHandler,
187-
peerLookup);
190+
peerLookup,
191+
spec.getNetworkingConfig());
188192
}
189193

190194
private static Eth2RpcMethod<BeaconBlocksByRootRequestMessage, SignedBeaconBlock>
@@ -217,7 +221,8 @@ private static Eth2RpcMethod<GoodbyeMessage, GoodbyeMessage> createGoodBye(
217221
expectResponseToRequest,
218222
forkDigestContextCodec,
219223
beaconBlocksByRootHandler,
220-
peerLookup);
224+
peerLookup,
225+
spec.getNetworkingConfig());
221226

222227
return VersionedEth2RpcMethod.create(
223228
rpcEncoding, requestType, expectResponseToRequest, List.of(v2Method));
@@ -254,7 +259,8 @@ private static Eth2RpcMethod<GoodbyeMessage, GoodbyeMessage> createGoodBye(
254259
expectResponseToRequest,
255260
forkDigestContextCodec,
256261
beaconBlocksByRangeHandler,
257-
peerLookup);
262+
peerLookup,
263+
spec.getNetworkingConfig());
258264

259265
return VersionedEth2RpcMethod.create(
260266
rpcEncoding, requestType, expectResponseToRequest, List.of(v2Method));
@@ -293,7 +299,8 @@ private static Eth2RpcMethod<GoodbyeMessage, GoodbyeMessage> createGoodBye(
293299
true,
294300
forkDigestContextCodec,
295301
blobSidecarsByRootHandler,
296-
peerLookup));
302+
peerLookup,
303+
spec.getNetworkingConfig()));
297304
}
298305

299306
private static Optional<Eth2RpcMethod<BlobSidecarsByRangeRequestMessage, BlobSidecar>>
@@ -329,7 +336,8 @@ private static Eth2RpcMethod<GoodbyeMessage, GoodbyeMessage> createGoodBye(
329336
true,
330337
forkDigestContextCodec,
331338
blobSidecarsByRangeHandler,
332-
peerLookup));
339+
peerLookup,
340+
spec.getNetworkingConfig()));
333341
}
334342

335343
private static Eth2RpcMethod<EmptyMessage, MetadataMessage> createMetadata(
@@ -361,7 +369,8 @@ private static Eth2RpcMethod<EmptyMessage, MetadataMessage> createMetadata(
361369
expectResponse,
362370
phase0ContextCodec,
363371
messageHandler,
364-
peerLookup);
372+
peerLookup,
373+
spec.getNetworkingConfig());
365374

366375
if (spec.isMilestoneSupported(SpecMilestone.ALTAIR)) {
367376
final SszSchema<MetadataMessage> altairMetadataSchema =
@@ -383,7 +392,8 @@ private static Eth2RpcMethod<EmptyMessage, MetadataMessage> createMetadata(
383392
expectResponse,
384393
altairContextCodec,
385394
messageHandler,
386-
peerLookup);
395+
peerLookup,
396+
spec.getNetworkingConfig());
387397
return VersionedEth2RpcMethod.create(
388398
rpcEncoding, requestType, expectResponse, List.of(v2Method, v1Method));
389399
} else {
@@ -392,6 +402,7 @@ private static Eth2RpcMethod<EmptyMessage, MetadataMessage> createMetadata(
392402
}
393403

394404
private static Eth2RpcMethod<PingMessage, PingMessage> createPing(
405+
final Spec spec,
395406
final AsyncRunner asyncRunner,
396407
final MetadataMessagesFactory metadataMessagesFactory,
397408
final PeerLookup peerLookup,
@@ -408,7 +419,8 @@ private static Eth2RpcMethod<PingMessage, PingMessage> createPing(
408419
true,
409420
contextCodec,
410421
statusHandler,
411-
peerLookup);
422+
peerLookup,
423+
spec.getNetworkingConfig());
412424
}
413425

414426
public Collection<RpcMethod<?, ?, ?>> all() {

networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/rpc/core/Eth2IncomingRequestHandler.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
import tech.pegasys.teku.networking.p2p.rpc.RpcRequestHandler;
2929
import tech.pegasys.teku.networking.p2p.rpc.RpcStream;
3030
import tech.pegasys.teku.networking.p2p.rpc.StreamClosedException;
31+
import tech.pegasys.teku.spec.config.NetworkingSpecConfig;
3132
import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.RpcRequest;
3233

3334
public class Eth2IncomingRequestHandler<
3435
TRequest extends RpcRequest & SszData, TResponse extends SszData>
3536
implements RpcRequestHandler {
3637
private static final Logger LOG = LogManager.getLogger();
37-
private static final Duration RECEIVE_INCOMING_REQUEST_TIMEOUT = Duration.ofSeconds(10);
3838

3939
private final PeerLookup peerLookup;
4040
private final LocalMessageHandler<TRequest, TResponse> localMessageHandler;
@@ -45,20 +45,23 @@ public class Eth2IncomingRequestHandler<
4545
private final String protocolId;
4646
private final AsyncRunner asyncRunner;
4747
private final AtomicBoolean requestHandled = new AtomicBoolean(false);
48+
private final Duration respTimeout;
4849

4950
public Eth2IncomingRequestHandler(
5051
final String protocolId,
5152
final RpcResponseEncoder<TResponse, ?> responseEncoder,
5253
final RpcRequestDecoder<TRequest> requestDecoder,
5354
final AsyncRunner asyncRunner,
5455
final PeerLookup peerLookup,
55-
final LocalMessageHandler<TRequest, TResponse> localMessageHandler) {
56+
final LocalMessageHandler<TRequest, TResponse> localMessageHandler,
57+
final NetworkingSpecConfig networkingConfig) {
5658
this.protocolId = protocolId;
5759
this.asyncRunner = asyncRunner;
5860
this.peerLookup = peerLookup;
5961
this.localMessageHandler = localMessageHandler;
6062
this.responseEncoder = responseEncoder;
6163
this.requestDecoder = requestDecoder;
64+
this.respTimeout = Duration.ofSeconds(networkingConfig.getRespTimeout());
6265
}
6366

6467
@Override
@@ -118,14 +121,15 @@ private void handleRequest(
118121
}
119122

120123
private void ensureRequestReceivedWithinTimeLimit(final RpcStream stream) {
124+
final Duration timeout = respTimeout;
121125
asyncRunner
122-
.getDelayedFuture(RECEIVE_INCOMING_REQUEST_TIMEOUT)
126+
.getDelayedFuture(timeout)
123127
.thenAccept(
124128
(__) -> {
125129
if (!requestHandled.get()) {
126130
LOG.debug(
127131
"Failed to receive incoming request data within {} sec for protocol {}. Close stream.",
128-
RECEIVE_INCOMING_REQUEST_TIMEOUT.toSeconds(),
132+
timeout.toSeconds(),
129133
protocolId);
130134
stream.closeAbruptly().ifExceptionGetsHereRaiseABug();
131135
}

0 commit comments

Comments
 (0)