Skip to content

Commit

Permalink
[PIE-1224] Different request limits for different request types (Pega…
Browse files Browse the repository at this point in the history
…SysEng#1224)

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

- create `EthLimits` with max size of response according to geth (https://github.com/ethereum/go-ethereum/blob/master/eth/downloader/downloader.go)
- update `EthServer` to use those constants limits instead of the default one
- remove requestLimit from EthServer and EthProtocolManager constructor
fix PIE-1224

* eth wire protocol request limits

- add fields in `SynchronizerConfiguration` to configure per type request limit
- update `EthServer` constructor to add new fields
- update `EthProtocolManager` and subclasses to support new fields
- update unit tests accordingly

* Update SynchronizerConfiguration.java

* Update EthProtocolManagerTestUtil.java

* Update EthServerTest.java

* Update EthProtocolManagerTest.java

* Update EthServerTest.java

* fix after review discussion

- remove per type request limit configuration from `SynchronizerConfiguration`.
- add `EthServer` constructor without new fields that use default values.
- update unit tests accordingly
- update instanciation of different `PantheonController` accordingly

* Update EthServerTest.java

* fix review

- spotless
- fix clean up review comment

* spotlessApply
  • Loading branch information
AbdelStark authored and notlesh committed Apr 24, 2019
1 parent 62616be commit f174e74
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 51 deletions.
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,35 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
this.blockBroadcaster = new BlockBroadcaster(ethContext);

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

EthProtocolManager(
public 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(
blockchain,
worldStateArchive,
networkId,
fastSyncEnabled,
requestLimit,
new EthScheduler(syncWorkers, txWorkers, computationWorkers, metricsSystem));
new EthScheduler(syncWorkers, txWorkers, computationWorkers, metricsSystem),
EthServer.DEFAULT_MAX_GET_BLOCK_HEADERS,
EthServer.DEFAULT_MAX_GET_BLOCK_BODIES,
EthServer.DEFAULT_MAX_GET_RECEIPTS,
EthServer.DEFAULT_MAX_GET_NODE_DATA);
}

public EthProtocolManager(
Expand All @@ -117,17 +128,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,23 +47,51 @@
class EthServer {
private static final Logger LOG = LogManager.getLogger();

public static final int DEFAULT_MAX_GET_BLOCK_HEADERS = 192;
public static final int DEFAULT_MAX_GET_BLOCK_BODIES = 128;
public static final int DEFAULT_MAX_GET_RECEIPTS = 256;
public static final int DEFAULT_MAX_GET_NODE_DATA = 384;

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(
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();
}

EthServer(
final Blockchain blockchain,
final WorldStateArchive worldStateArchive,
final EthMessages ethMessages) {
this(
blockchain,
worldStateArchive,
ethMessages,
DEFAULT_MAX_GET_BLOCK_HEADERS,
DEFAULT_MAX_GET_BLOCK_BODIES,
DEFAULT_MAX_GET_RECEIPTS,
DEFAULT_MAX_GET_NODE_DATA);
}

private void setupListeners() {
ethMessages.subscribe(EthPV62.GET_BLOCK_HEADERS, this::handleGetBlockHeaders);
ethMessages.subscribe(EthPV62.GET_BLOCK_BODIES, this::handleGetBlockBodies);
Expand All @@ -75,7 +103,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 +116,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 +129,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 +142,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
Loading

0 comments on commit f174e74

Please sign in to comment.