Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
50496d5
feat(http): add Jetty SizeLimitHandler to enforce request body size l…
bladehan1 Mar 19, 2026
736f2ed
feat(http) : wait for HttpService startup future in SizeLimitHandlerTest
bladehan1 Mar 19, 2026
b2ade66
feat(http): add independent maxMessageSize for HTTP and JSON-RPC
bladehan1 Mar 23, 2026
c41d30e
opt(checkstyle): optimize checkstyle
bladehan1 Apr 1, 2026
321e26a
change(config): update default size
bladehan1 Apr 2, 2026
e6b11a3
test(framework): align ArgsTest with 4M defaults
bladehan1 Apr 2, 2026
674e547
test(http): doc for default value
bladehan1 Apr 3, 2026
3048750
fix(api): use httpMaxMessageSize in checkBodySize instead of gRPC limit
bladehan1 Apr 9, 2026
5e35c4c
test(http): add chunked transfer and zero-limit tests for SizeLimitHa…
bladehan1 Apr 10, 2026
aa34bfc
refactor(config): use getMemorySize() for size limit configs
bladehan1 Apr 10, 2026
c64d3b2
fix(config): allow zero value for maxMessageSize parameters
bladehan1 Apr 10, 2026
5e3eed0
test(http): verify checkBodySize consistency with SizeLimitHandler
bladehan1 Apr 10, 2026
de76e5f
fix(config): correct comment from "positive" to "non-negative"
bladehan1 Apr 10, 2026
5ebac52
fix(http): add safe default for maxRequestSize and fix misleading var…
bladehan1 Apr 14, 2026
6f0a0f0
test(config): add maxMessageSize parsing and zero-value documentation
bladehan1 Apr 14, 2026
64ad6df
test(http): add real JSON-RPC integration test and clean up SizeLimit…
bladehan1 Apr 15, 2026
7df020e
refactor(http): replace reflection with @VisibleForTesting accessor a…
bladehan1 Apr 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ public class CommonParameter {
public int maxMessageSize;
@Getter
@Setter
public long httpMaxMessageSize;
@Getter
@Setter
public long jsonRpcMaxMessageSize;
@Getter
@Setter
public int maxHeaderListSize;
@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@

package org.tron.common.application;

import com.google.common.annotations.VisibleForTesting;
import java.util.concurrent.CompletableFuture;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jetty.server.ConnectionLimit;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.SizeLimitHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.tron.core.config.args.Args;

Expand All @@ -29,6 +31,18 @@ public abstract class HttpService extends AbstractService {

protected String contextPath;

protected long maxRequestSize = 4 * 1024 * 1024; // 4MB
Comment thread
waynercheung marked this conversation as resolved.

@VisibleForTesting
public long getMaxRequestSize() {
return this.maxRequestSize;
}

@VisibleForTesting
public void setMaxRequestSize(long maxRequestSize) {
this.maxRequestSize = maxRequestSize;
}

@Override
public void innerStart() throws Exception {
if (this.apiServer != null) {
Expand Down Expand Up @@ -63,7 +77,9 @@ protected void initServer() {
protected ServletContextHandler initContextHandler() {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath(this.contextPath);
this.apiServer.setHandler(context);
SizeLimitHandler sizeLimitHandler = new SizeLimitHandler(this.maxRequestSize, -1);
Comment thread
bladehan1 marked this conversation as resolved.
Comment thread
bladehan1 marked this conversation as resolved.
Comment thread
bladehan1 marked this conversation as resolved.
sizeLimitHandler.setHandler(context);
this.apiServer.setHandler(sizeLimitHandler);
return context;
}

Expand Down
26 changes: 24 additions & 2 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,30 @@ public static void applyConfigParams(
? config.getLong(ConfigKey.NODE_RPC_MAX_CONNECTION_AGE_IN_MILLIS)
: Long.MAX_VALUE;

PARAMETER.maxMessageSize = config.hasPath(ConfigKey.NODE_RPC_MAX_MESSAGE_SIZE)
? config.getInt(ConfigKey.NODE_RPC_MAX_MESSAGE_SIZE) : GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE;
long rpcMaxMessageSize = config.hasPath(ConfigKey.NODE_RPC_MAX_MESSAGE_SIZE)
Comment thread
bladehan1 marked this conversation as resolved.
? config.getMemorySize(ConfigKey.NODE_RPC_MAX_MESSAGE_SIZE).toBytes()
: GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE;
if (rpcMaxMessageSize < 0 || rpcMaxMessageSize > Integer.MAX_VALUE) {
throw new TronError("node.rpc.maxMessageSize must be non-negative and <= "
+ Integer.MAX_VALUE + ", got: " + rpcMaxMessageSize, PARAMETER_INIT);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 if (PARAMETER.httpMaxMessageSize <= 0) {                                 
       throw new TronError("node.http.maxMessageSize must be > 0, got: "
           + PARAMETER.httpMaxMessageSize, PARAMETER_INIT);                   
}   

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think we should change this to <= 0 in this PR. The current implementation, config docs, and tests all explicitly treat 0 as a valid value meaning “reject all non-empty request bodies”, not as an invalid configuration.
Changing that now would be a behavior change rather than a local validation cleanup, and would require updating the documented semantics and the related tests as well.

PARAMETER.maxMessageSize = (int) rpcMaxMessageSize;

long defaultMaxMessageSize = GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE;
PARAMETER.httpMaxMessageSize = config.hasPath(ConfigKey.NODE_HTTP_MAX_MESSAGE_SIZE)
? config.getMemorySize(ConfigKey.NODE_HTTP_MAX_MESSAGE_SIZE).toBytes()
: defaultMaxMessageSize;
if (PARAMETER.httpMaxMessageSize < 0) {
throw new TronError("node.http.maxMessageSize must be non-negative, got: "
+ PARAMETER.httpMaxMessageSize, PARAMETER_INIT);
}
PARAMETER.jsonRpcMaxMessageSize = config.hasPath(ConfigKey.NODE_JSONRPC_MAX_MESSAGE_SIZE)
? config.getMemorySize(ConfigKey.NODE_JSONRPC_MAX_MESSAGE_SIZE).toBytes()
: defaultMaxMessageSize;
if (PARAMETER.jsonRpcMaxMessageSize < 0) {
throw new TronError("node.jsonrpc.maxMessageSize must be non-negative, got: "
+ PARAMETER.jsonRpcMaxMessageSize, PARAMETER_INIT);
}

PARAMETER.maxHeaderListSize = config.hasPath(ConfigKey.NODE_RPC_MAX_HEADER_LIST_SIZE)
? config.getInt(ConfigKey.NODE_RPC_MAX_HEADER_LIST_SIZE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private ConfigKey() {
public static final String NODE_HTTP_SOLIDITY_ENABLE = "node.http.solidityEnable";
public static final String NODE_HTTP_PBFT_ENABLE = "node.http.PBFTEnable";
public static final String NODE_HTTP_PBFT_PORT = "node.http.PBFTPort";
public static final String NODE_HTTP_MAX_MESSAGE_SIZE = "node.http.maxMessageSize";

// node - jsonrpc
public static final String NODE_JSONRPC_HTTP_FULLNODE_ENABLE =
Expand All @@ -150,6 +151,7 @@ private ConfigKey() {
public static final String NODE_JSONRPC_MAX_SUB_TOPICS = "node.jsonrpc.maxSubTopics";
public static final String NODE_JSONRPC_MAX_BLOCK_FILTER_NUM =
"node.jsonrpc.maxBlockFilterNum";
public static final String NODE_JSONRPC_MAX_MESSAGE_SIZE = "node.jsonrpc.maxMessageSize";

// node - dns
public static final String NODE_DNS_TREE_URLS = "node.dns.treeUrls";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ public FullNodeHttpApiService() {
port = Args.getInstance().getFullNodeHttpPort();
enable = isFullNode() && Args.getInstance().isFullNodeHttpEnable();
contextPath = "/";
maxRequestSize = Args.getInstance().getHttpMaxMessageSize();
}

@Override
Expand Down
6 changes: 4 additions & 2 deletions framework/src/main/java/org/tron/core/services/http/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,12 @@ public static Transaction packTransaction(String strTransaction, boolean selfTyp
}
}

@Deprecated
Comment thread
bladehan1 marked this conversation as resolved.
public static void checkBodySize(String body) throws Exception {
CommonParameter parameter = Args.getInstance();
if (body.getBytes().length > parameter.getMaxMessageSize()) {
throw new Exception("body size is too big, the limit is " + parameter.getMaxMessageSize());
if (body.getBytes().length > parameter.getHttpMaxMessageSize()) {
Comment thread
waynercheung marked this conversation as resolved.
throw new Exception("body size is too big, the limit is "
+ parameter.getHttpMaxMessageSize());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public SolidityNodeHttpApiService() {
port = Args.getInstance().getSolidityHttpPort();
enable = !isFullNode() && Args.getInstance().isSolidityNodeHttpEnable();
contextPath = "/";
maxRequestSize = Args.getInstance().getHttpMaxMessageSize();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public JsonRpcServiceOnPBFT() {
port = Args.getInstance().getJsonRpcHttpPBFTPort();
enable = isFullNode() && Args.getInstance().isJsonRpcHttpPBFTNodeEnable();
contextPath = "/";
maxRequestSize = Args.getInstance().getJsonRpcMaxMessageSize();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public JsonRpcServiceOnSolidity() {
port = Args.getInstance().getJsonRpcHttpSolidityPort();
enable = isFullNode() && Args.getInstance().isJsonRpcHttpSolidityNodeEnable();
contextPath = "/";
maxRequestSize = Args.getInstance().getJsonRpcMaxMessageSize();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public HttpApiOnPBFTService() {
port = Args.getInstance().getPBFTHttpPort();
enable = isFullNode() && Args.getInstance().isPBFTHttpEnable();
contextPath = "/walletpbft";
maxRequestSize = Args.getInstance().getHttpMaxMessageSize();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public HttpApiOnSolidityService() {
port = Args.getInstance().getSolidityHttpPort();
enable = isFullNode() && Args.getInstance().isSolidityNodeHttpEnable();
contextPath = "/";
maxRequestSize = Args.getInstance().getHttpMaxMessageSize();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public FullNodeJsonRpcHttpService() {
port = Args.getInstance().getJsonRpcHttpFullNodePort();
enable = isFullNode() && Args.getInstance().isJsonRpcHttpFullNodeEnable();
contextPath = "/";
maxRequestSize = Args.getInstance().getJsonRpcMaxMessageSize();
}

@Override
Expand Down
16 changes: 14 additions & 2 deletions framework/src/main/resources/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ node {
solidityPort = 8091
PBFTEnable = true
PBFTPort = 8092

# The maximum request body size for HTTP API, default 4M (4194304 bytes).
Comment thread
bladehan1 marked this conversation as resolved.
# Supports human-readable sizes: 4m, 4MB, 4194304. Must be non-negative.
# Setting to 0 rejects all non-empty request bodies (not "unlimited").
# maxMessageSize = 4m
}

rpc {
Expand All @@ -248,8 +253,10 @@ node {
# Connection lasting longer than which will be gracefully terminated
# maxConnectionAgeInMillis =

# The maximum message size allowed to be received on the server, default 4MB
# maxMessageSize =
# The maximum message size allowed to be received on the server, default 4M (4194304 bytes).
# Supports human-readable sizes: 4m, 4MB, 4194304. Must be non-negative.
# Setting to 0 rejects all non-empty request bodies (not "unlimited").
# maxMessageSize = 4m

# The maximum size of header list allowed to be received, default 8192
# maxHeaderListSize =
Expand Down Expand Up @@ -357,6 +364,11 @@ node {
# openHistoryQueryWhenLiteFN = false

jsonrpc {
# The maximum request body size for JSON-RPC API, default 4M (4194304 bytes).
# Supports human-readable sizes: 4m, 4MB, 4194304. Must be non-negative.
# Setting to 0 rejects all non-empty request bodies (not "unlimited").
# maxMessageSize = 4m

# Note: Before release_4.8.1, if you turn on jsonrpc and run it for a while and then turn it off,
# you will not be able to get the data from eth_getLogs for that period of time. Default: false
# httpFullNodeEnable = false
Expand Down
Loading
Loading