|
1 | 1 | package org.tron.core.config.args; |
2 | 2 |
|
3 | 3 | import static org.tron.core.config.Parameter.ChainConstant.MAX_ACTIVE_WITNESS_NUM; |
| 4 | +import static org.tron.core.exception.TronError.ErrCode.PARAMETER_INIT; |
4 | 5 |
|
5 | 6 | import com.typesafe.config.Config; |
6 | 7 | import com.typesafe.config.ConfigBeanFactory; |
7 | 8 | import com.typesafe.config.ConfigFactory; |
| 9 | +import com.typesafe.config.ConfigValueFactory; |
8 | 10 | import java.util.ArrayList; |
9 | 11 | import java.util.List; |
10 | 12 | import lombok.Getter; |
11 | 13 | import lombok.Setter; |
12 | 14 | import lombok.extern.slf4j.Slf4j; |
| 15 | +import org.tron.core.exception.TronError; |
13 | 16 |
|
14 | 17 | // Node configuration bean for the "node" section of config.conf. |
15 | 18 | // ConfigBeanFactory auto-binds all fields including sub-beans, dot-notation keys, |
@@ -198,6 +201,7 @@ public static class HttpConfig { |
198 | 201 | private int fullNodePort = 8090; |
199 | 202 | private boolean solidityEnable = true; |
200 | 203 | private int solidityPort = 8091; |
| 204 | + private long maxMessageSize = 4194304; |
201 | 205 | // PBFT fields — handled manually (same naming issue as CommitteeConfig) |
202 | 206 | // Default must match CommonParameter.pBFTHttpEnable = true |
203 | 207 | @Getter(lombok.AccessLevel.NONE) |
@@ -303,6 +307,7 @@ public void setHttpPBFTPort(int v) { |
303 | 307 | private int maxBlockRange = 5000; |
304 | 308 | private int maxSubTopics = 1000; |
305 | 309 | private int maxBlockFilterNum = 50000; |
| 310 | + private long maxMessageSize = 4194304; |
306 | 311 | } |
307 | 312 |
|
308 | 313 | @Getter |
@@ -360,7 +365,11 @@ public static class DnsConfig { |
360 | 365 | * since ConfigBeanFactory expects typed bean lists, not string lists. |
361 | 366 | */ |
362 | 367 | public static NodeConfig fromConfig(Config config) { |
363 | | - Config section = config.getConfig("node"); |
| 368 | + // Normalize human-readable size values (e.g. "4m") to numeric bytes so |
| 369 | + // ConfigBeanFactory's primitive int/long binding succeeds; same step |
| 370 | + // enforces non-negative and <= Integer.MAX_VALUE before bean creation |
| 371 | + // so failures point at the user-facing config path. |
| 372 | + Config section = normalizeMaxMessageSizes(config).getConfig("node"); |
364 | 373 |
|
365 | 374 | // Auto-bind all fields and sub-beans. ConfigBeanFactory fails fast with a |
366 | 375 | // descriptive path on any `= null` value — external configs that use the |
@@ -500,4 +509,34 @@ private static String getString(Config config, String path, String defaultValue) |
500 | 509 | return config.hasPath(path) ? config.getString(path) : defaultValue; |
501 | 510 | } |
502 | 511 |
|
| 512 | + // Pre-normalize size paths so ConfigBeanFactory's primitive int/long binding succeeds |
| 513 | + // for human-readable values like "4m" / "128MB". For each maxMessageSize key, parse |
| 514 | + // via getMemorySize, validate non-negative and <= Integer.MAX_VALUE, and write the |
| 515 | + // numeric byte value back into the Config tree. Validation errors propagate before |
| 516 | + // bean creation so the failure points at the user-facing config path. |
| 517 | + private static Config normalizeMaxMessageSizes(Config config) { |
| 518 | + String[] paths = { |
| 519 | + "node.rpc.maxMessageSize", |
| 520 | + "node.http.maxMessageSize", |
| 521 | + "node.jsonrpc.maxMessageSize" |
| 522 | + }; |
| 523 | + Config result = config; |
| 524 | + for (String path : paths) { |
| 525 | + if (config.hasPath(path)) { |
| 526 | + long bytes = parseMaxMessageSize(config, path); |
| 527 | + result = result.withValue(path, ConfigValueFactory.fromAnyRef(bytes)); |
| 528 | + } |
| 529 | + } |
| 530 | + return result; |
| 531 | + } |
| 532 | + |
| 533 | + private static long parseMaxMessageSize(Config config, String key) { |
| 534 | + long value = config.getMemorySize(key).toBytes(); |
| 535 | + if (value < 0 || value > Integer.MAX_VALUE) { |
| 536 | + throw new TronError(key + " must be non-negative and <= " |
| 537 | + + Integer.MAX_VALUE + ", got: " + value, PARAMETER_INIT); |
| 538 | + } |
| 539 | + return value; |
| 540 | + } |
| 541 | + |
503 | 542 | } |
0 commit comments