Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[PIE-1224] Different request limits for different request types #1224

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public Istanbul64ProtocolManager(
final int syncWorkers,
final int txWorkers,
final int computationWorkers,
final MetricsSystem metricsSystem) {
final MetricsSystem metricsSystem,
final int maxGetBlockHeaders,
final int maxGetBlockBodies,
final int maxGetReceipts,
final int maxGetNodeData) {
super(
blockchain,
worldStateArchive,
Expand All @@ -42,7 +46,11 @@ public Istanbul64ProtocolManager(
syncWorkers,
txWorkers,
computationWorkers,
metricsSystem);
metricsSystem,
maxGetBlockHeaders,
maxGetBlockBodies,
maxGetReceipts,
maxGetNodeData);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.apache.logging.log4j.Logger;

public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
static final int DEFAULT_REQUEST_LIMIT = 200;
private static final Logger LOG = LogManager.getLogger();
private static final List<Capability> FAST_SYNC_CAPS =
Collections.singletonList(EthProtocol.ETH63);
Expand All @@ -70,8 +69,11 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
final WorldStateArchive worldStateArchive,
final int networkId,
final boolean fastSyncEnabled,
final int requestLimit,
final EthScheduler scheduler) {
final EthScheduler scheduler,
final int maxGetBlockHeaders,
final int maxGetBlockBodies,
final int maxGetReceipts,
final int maxGetNodeData) {
this.networkId = networkId;
this.scheduler = scheduler;
this.blockchain = blockchain;
Expand All @@ -87,26 +89,14 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
this.blockBroadcaster = new BlockBroadcaster(ethContext);

// Set up request handlers
new EthServer(blockchain, worldStateArchive, ethMessages, requestLimit);
}

EthProtocolManager(
final Blockchain blockchain,
final WorldStateArchive worldStateArchive,
final int networkId,
final boolean fastSyncEnabled,
final int syncWorkers,
final int txWorkers,
final int computationWorkers,
final int requestLimit,
final MetricsSystem metricsSystem) {
this(
new EthServer(
blockchain,
worldStateArchive,
networkId,
fastSyncEnabled,
requestLimit,
new EthScheduler(syncWorkers, txWorkers, computationWorkers, metricsSystem));
ethMessages,
maxGetBlockHeaders,
maxGetBlockBodies,
maxGetReceipts,
maxGetNodeData);
}

public EthProtocolManager(
Expand All @@ -117,17 +107,21 @@ public EthProtocolManager(
final int syncWorkers,
final int txWorkers,
final int computationWorkers,
final MetricsSystem metricsSystem) {
final MetricsSystem metricsSystem,
final int maxGetBlockHeaders,
final int maxGetBlockBodies,
final int maxGetReceipts,
final int maxGetNodeData) {
this(
blockchain,
worldStateArchive,
networkId,
fastSyncEnabled,
syncWorkers,
txWorkers,
computationWorkers,
DEFAULT_REQUEST_LIMIT,
metricsSystem);
new EthScheduler(syncWorkers, txWorkers, computationWorkers, metricsSystem),
maxGetBlockHeaders,
maxGetBlockBodies,
maxGetReceipts,
maxGetNodeData);
}

public EthContext ethContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,30 @@
class EthServer {
private static final Logger LOG = LogManager.getLogger();

static final int DEFAULT_REQUEST_LIMIT = 200;
AbdelStark marked this conversation as resolved.
Show resolved Hide resolved
private final Blockchain blockchain;
private final WorldStateArchive worldStateArchive;
private final EthMessages ethMessages;
private final int requestLimit;
private final int maxGetBlockHeaders;
private final int maxGetBlockBodies;
private final int maxGetReceipts;
private final int maxGetNodeData;

EthServer(
AbdelStark marked this conversation as resolved.
Show resolved Hide resolved
final Blockchain blockchain,
final WorldStateArchive worldStateArchive,
final EthMessages ethMessages,
final int requestLimit) {
final int maxGetBlockHeaders,
final int maxGetBlockBodies,
final int maxGetReceipts,
final int maxGetNodeData) {
this.blockchain = blockchain;
this.worldStateArchive = worldStateArchive;
this.ethMessages = ethMessages;
this.requestLimit = requestLimit;
this.maxGetBlockHeaders = maxGetBlockHeaders;
this.maxGetBlockBodies = maxGetBlockBodies;
this.maxGetReceipts = maxGetReceipts;
this.maxGetNodeData = maxGetNodeData;
this.setupListeners();
}

Expand All @@ -75,7 +85,7 @@ private void handleGetBlockHeaders(final EthMessage message) {
LOG.trace("Responding to GET_BLOCK_HEADERS request");
try {
final MessageData response =
constructGetHeadersResponse(blockchain, message.getData(), requestLimit);
constructGetHeadersResponse(blockchain, message.getData(), maxGetBlockHeaders);
message.getPeer().send(response);
} catch (final RLPException e) {
message.getPeer().disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
Expand All @@ -88,7 +98,7 @@ private void handleGetBlockBodies(final EthMessage message) {
LOG.trace("Responding to GET_BLOCK_BODIES request");
try {
final MessageData response =
constructGetBodiesResponse(blockchain, message.getData(), requestLimit);
constructGetBodiesResponse(blockchain, message.getData(), maxGetBlockBodies);
message.getPeer().send(response);
} catch (final RLPException e) {
message.getPeer().disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
Expand All @@ -101,7 +111,7 @@ private void handleGetReceipts(final EthMessage message) {
LOG.trace("Responding to GET_RECEIPTS request");
try {
final MessageData response =
constructGetReceiptsResponse(blockchain, message.getData(), requestLimit);
constructGetReceiptsResponse(blockchain, message.getData(), maxGetReceipts);
message.getPeer().send(response);
} catch (final RLPException e) {
message.getPeer().disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
Expand All @@ -114,7 +124,7 @@ private void handleGetNodeData(final EthMessage message) {
LOG.trace("Responding to GET_NODE_DATA request");
try {
final MessageData response =
constructGetNodeDataResponse(worldStateArchive, message.getData(), requestLimit);
constructGetNodeDataResponse(worldStateArchive, message.getData(), maxGetNodeData);
message.getPeer().send(response);
} catch (final RLPException e) {
message.getPeer().disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public class SynchronizerConfiguration {
private static final int DEFAULT_WORLD_STATE_MAX_REQUESTS_WITHOUT_PROGRESS = 1000;
private static final long DEFAULT_WORLD_STATE_MIN_MILLIS_BEFORE_STALLING =
TimeUnit.MINUTES.toMillis(5);
private static final int DEFAULT_MAX_GET_BLOCK_HEADERS = 192;
private static final int DEFAULT_MAX_GET_BLOCK_BODIES = 128;
private static final int DEFAULT_MAX_GET_RECEIPTS = 256;
private static final int DEFAULT_MAX_GET_NODE_DATA = 384;
AbdelStark marked this conversation as resolved.
Show resolved Hide resolved

// Fast sync config
private final int fastSyncPivotDistance;
Expand Down Expand Up @@ -65,6 +69,12 @@ public class SynchronizerConfiguration {
private final int maxTrailingPeers;
private final long worldStateMinMillisBeforeStalling;

// Ethereum Wire Protocol config
private final int maxGetBlockHeaders;
private final int maxGetBlockBodies;
private final int maxGetReceipts;
private final int maxGetNodeData;

private SynchronizerConfiguration(
final int fastSyncPivotDistance,
final float fastSyncFullValidationRate,
Expand All @@ -85,7 +95,11 @@ private SynchronizerConfiguration(
final int downloaderParallelism,
final int transactionsParallelism,
final int computationParallelism,
final int maxTrailingPeers) {
final int maxTrailingPeers,
final int maxGetBlockHeaders,
final int maxGetBlockBodies,
final int maxGetReceipts,
final int maxGetNodeData) {
this.fastSyncPivotDistance = fastSyncPivotDistance;
this.fastSyncFullValidationRate = fastSyncFullValidationRate;
this.fastSyncMinimumPeerCount = fastSyncMinimumPeerCount;
Expand All @@ -106,6 +120,10 @@ private SynchronizerConfiguration(
this.transactionsParallelism = transactionsParallelism;
this.computationParallelism = computationParallelism;
this.maxTrailingPeers = maxTrailingPeers;
this.maxGetBlockHeaders = maxGetBlockHeaders;
this.maxGetBlockBodies = maxGetBlockBodies;
this.maxGetReceipts = maxGetReceipts;
this.maxGetNodeData = maxGetNodeData;
}

public static Builder builder() {
Expand Down Expand Up @@ -216,6 +234,22 @@ public int getMaxTrailingPeers() {
return maxTrailingPeers;
}

public int getMaxGetBlockHeaders() {
return maxGetBlockHeaders;
}

public int getMaxGetBlockBodies() {
return maxGetBlockBodies;
}

public int getMaxGetReceipts() {
return maxGetReceipts;
}

public int getMaxGetNodeData() {
return maxGetNodeData;
}

public static class Builder {
private SyncMode syncMode = SyncMode.FULL;
private int fastSyncMinimumPeerCount = DEFAULT_FAST_SYNC_MINIMUM_PEERS;
Expand Down Expand Up @@ -374,6 +408,11 @@ public void parseBlockPropagationRange(final String arg) {
"Minimum time in ms without progress before considering a world state download as stalled (default: ${DEFAULT-VALUE})")
private long worldStateMinMillisBeforeStalling = DEFAULT_WORLD_STATE_MIN_MILLIS_BEFORE_STALLING;

private int maxGetBlockHeaders = DEFAULT_MAX_GET_BLOCK_HEADERS;
private int maxGetBlockBodies = DEFAULT_MAX_GET_BLOCK_BODIES;
private int maxGetReceipts = DEFAULT_MAX_GET_RECEIPTS;
private int maxGetNodeData = DEFAULT_MAX_GET_NODE_DATA;

public Builder fastSyncPivotDistance(final int distance) {
fastSyncPivotDistance = distance;
return this;
Expand Down Expand Up @@ -480,6 +519,26 @@ public Builder maxTrailingPeers(final int maxTailingPeers) {
return this;
}

public Builder maxGetBlockHeaders(final int maxGetBlockHeaders) {
this.maxGetBlockHeaders = maxGetBlockHeaders;
return this;
}

public Builder maxGetBlockBodies(final int maxGetBlockBodies) {
this.maxGetBlockBodies = maxGetBlockBodies;
return this;
}

public Builder maxGetReceipts(final int maxGetReceipts) {
this.maxGetReceipts = maxGetReceipts;
return this;
}

public Builder maxGetNodeData(final int maxGetNodeData) {
this.maxGetNodeData = maxGetNodeData;
return this;
}

public SynchronizerConfiguration build() {
return new SynchronizerConfiguration(
fastSyncPivotDistance,
Expand All @@ -501,7 +560,11 @@ public SynchronizerConfiguration build() {
downloaderParallelism,
transactionsParallelism,
computationParallelism,
maxTrailingPeers);
maxTrailingPeers,
maxGetBlockHeaders,
maxGetBlockBodies,
maxGetReceipts,
maxGetNodeData);
}
}
}
Loading