Skip to content

Commit 5cdcebd

Browse files
committed
refactor(framework): extract parseMaxMessageSize helper
Dedupe three near-identical maxMessageSize parsing blocks in applyConfigParams() (rpc, http, jsonrpc) into a single private static helper. Helper returns long to match the wider-typed http/jsonrpc fields; the rpc assignment retains an explicit (int) cast at the call site to make the gRPC int32 hard constraint visible. Net effect: ~16 lines removed, error messages guaranteed consistent across the three protocols, and adding a future protocol limit becomes a one-liner instead of a copy-paste block. Also add a brief comment on CommonParameter.maxMessageSize clarifying that the legacy field name refers to the gRPC limit, alongside the explicit httpMaxMessageSize / jsonRpcMaxMessageSize siblings.
1 parent bb14edd commit 5cdcebd

2 files changed

Lines changed: 19 additions & 27 deletions

File tree

common/src/main/java/org/tron/common/parameter/CommonParameter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ public class CommonParameter {
211211
@Getter
212212
@Setter
213213
public long maxConnectionAgeInMillis;
214+
// Refers to RPC (gRPC) max message size; see httpMaxMessageSize / jsonRpcMaxMessageSize
215+
// below for the HTTP / JSON-RPC counterparts.
214216
@Getter
215217
@Setter
216218
public int maxMessageSize;

framework/src/main/java/org/tron/core/config/args/Args.java

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -523,34 +523,13 @@ public static void applyConfigParams(
523523
? config.getLong(ConfigKey.NODE_RPC_MAX_CONNECTION_AGE_IN_MILLIS)
524524
: Long.MAX_VALUE;
525525

526-
long rpcMaxMessageSize = config.hasPath(ConfigKey.NODE_RPC_MAX_MESSAGE_SIZE)
527-
? config.getMemorySize(ConfigKey.NODE_RPC_MAX_MESSAGE_SIZE).toBytes()
528-
: GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE;
529-
if (rpcMaxMessageSize < 0 || rpcMaxMessageSize > Integer.MAX_VALUE) {
530-
throw new TronError("node.rpc.maxMessageSize must be non-negative and <= "
531-
+ Integer.MAX_VALUE + ", got: " + rpcMaxMessageSize, PARAMETER_INIT);
532-
}
533-
PARAMETER.maxMessageSize = (int) rpcMaxMessageSize;
534-
535526
long defaultMaxMessageSize = GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE;
536-
PARAMETER.httpMaxMessageSize = config.hasPath(ConfigKey.NODE_HTTP_MAX_MESSAGE_SIZE)
537-
? config.getMemorySize(ConfigKey.NODE_HTTP_MAX_MESSAGE_SIZE).toBytes()
538-
: defaultMaxMessageSize;
539-
if (PARAMETER.httpMaxMessageSize < 0
540-
|| PARAMETER.httpMaxMessageSize > Integer.MAX_VALUE) {
541-
throw new TronError("node.http.maxMessageSize must be non-negative and <= "
542-
+ Integer.MAX_VALUE + ", got: "
543-
+ PARAMETER.httpMaxMessageSize, PARAMETER_INIT);
544-
}
545-
PARAMETER.jsonRpcMaxMessageSize = config.hasPath(ConfigKey.NODE_JSONRPC_MAX_MESSAGE_SIZE)
546-
? config.getMemorySize(ConfigKey.NODE_JSONRPC_MAX_MESSAGE_SIZE).toBytes()
547-
: defaultMaxMessageSize;
548-
if (PARAMETER.jsonRpcMaxMessageSize < 0
549-
|| PARAMETER.jsonRpcMaxMessageSize > Integer.MAX_VALUE) {
550-
throw new TronError("node.jsonrpc.maxMessageSize must be non-negative and <= "
551-
+ Integer.MAX_VALUE + ", got: "
552-
+ PARAMETER.jsonRpcMaxMessageSize, PARAMETER_INIT);
553-
}
527+
PARAMETER.maxMessageSize = (int) parseMaxMessageSize(
528+
config, ConfigKey.NODE_RPC_MAX_MESSAGE_SIZE, defaultMaxMessageSize);
529+
PARAMETER.httpMaxMessageSize = parseMaxMessageSize(
530+
config, ConfigKey.NODE_HTTP_MAX_MESSAGE_SIZE, defaultMaxMessageSize);
531+
PARAMETER.jsonRpcMaxMessageSize = parseMaxMessageSize(
532+
config, ConfigKey.NODE_JSONRPC_MAX_MESSAGE_SIZE, defaultMaxMessageSize);
554533

555534
PARAMETER.maxHeaderListSize = config.hasPath(ConfigKey.NODE_RPC_MAX_HEADER_LIST_SIZE)
556535
? config.getInt(ConfigKey.NODE_RPC_MAX_HEADER_LIST_SIZE)
@@ -1258,6 +1237,17 @@ public static void clearParam() {
12581237
localWitnesses = null;
12591238
}
12601239

1240+
private static long parseMaxMessageSize(Config config, String key, long defaultBytes) {
1241+
long value = config.hasPath(key)
1242+
? config.getMemorySize(key).toBytes()
1243+
: defaultBytes;
1244+
if (value < 0 || value > Integer.MAX_VALUE) {
1245+
throw new TronError(key + " must be non-negative and <= "
1246+
+ Integer.MAX_VALUE + ", got: " + value, PARAMETER_INIT);
1247+
}
1248+
return value;
1249+
}
1250+
12611251
private static long getProposalExpirationTime(final Config config) {
12621252
if (config.hasPath(ConfigKey.COMMITTEE_PROPOSAL_EXPIRE_TIME)) {
12631253
throw new TronError("It is not allowed to configure committee.proposalExpireTime in "

0 commit comments

Comments
 (0)