Skip to content

Commit 4b5d37d

Browse files
authored
refactor(config): overhaul config docs, fix defaults, remove dead params (#6790)
1 parent 97bffb3 commit 4b5d37d

11 files changed

Lines changed: 752 additions & 750 deletions

File tree

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,6 @@ public class CommonParameter {
316316
public List<String> backupMembers;
317317
@Getter
318318
@Setter
319-
public long receiveTcpMinDataLength; // clearParam: 2048
320-
@Getter
321-
@Setter
322319
public boolean isOpenFullTcpDisconnect;
323320
@Getter
324321
@Setter

common/src/main/java/org/tron/core/config/args/NodeConfig.java

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// ConfigBeanFactory auto-binds all fields including sub-beans, dot-notation keys,
1818
// PBFT fields, and list fields. Only legacy key fallbacks and PascalCase shutdown
1919
// keys are read manually.
20+
// Always construct via {@link #fromConfig} — direct construction skips postProcess() clamping.
2021
@Slf4j
2122
@Getter
2223
@Setter
@@ -77,7 +78,6 @@ public String getDiscoveryExternalIp() {
7778
private ValidContractProtoConfig validContractProto = new ValidContractProtoConfig();
7879
private int shieldedTransInPendingMaxCounts = 10;
7980
private long blockCacheTimeout = 60;
80-
private long receiveTcpMinDataLength = 2048;
8181
private int maxTransactionPendingSize = 2000;
8282
private long pendingTransactionTimeout = 60000;
8383
private int maxTrxCacheSize = 50_000;
@@ -215,10 +215,10 @@ public static class RpcConfig {
215215
private int pBFTPort = 50071;
216216

217217
private int thread = 0;
218-
private int maxConcurrentCallsPerConnection = 2147483647;
218+
private int maxConcurrentCallsPerConnection = 0;
219219
private int flowControlWindow = 1048576;
220-
private long maxConnectionIdleInMillis = Long.MAX_VALUE;
221-
private long maxConnectionAgeInMillis = Long.MAX_VALUE;
220+
private long maxConnectionIdleInMillis = 0;
221+
private long maxConnectionAgeInMillis = 0;
222222
private int maxMessageSize = 4194304;
223223
private int maxHeaderListSize = 8192;
224224
private int maxRstStream = 0;
@@ -277,8 +277,8 @@ public static class DnsConfig {
277277
private String dnsPrivate = "";
278278
private List<String> knownUrls = new ArrayList<>();
279279
private List<String> staticNodes = new ArrayList<>();
280-
private int maxMergeSize = 0;
281-
private double changeThreshold = 0.0;
280+
private int maxMergeSize = 5;
281+
private double changeThreshold = 0.1;
282282
private String serverType = "";
283283
private String accessKeyId = "";
284284
private String accessKeySecret = "";
@@ -294,8 +294,7 @@ public static class DnsConfig {
294294
* since ConfigBeanFactory expects typed bean lists, not string lists.
295295
*/
296296
public static NodeConfig fromConfig(Config config) {
297-
Config section = normalizeNonStandardKeys(
298-
normalizeMaxMessageSizes(config).getConfig("node"));
297+
Config section = normalizeNonStandardKeys(config.getConfig("node"));
299298

300299
// Auto-bind all fields and sub-beans. ConfigBeanFactory fails fast with a
301300
// descriptive path on any `= null` value
@@ -304,20 +303,28 @@ public static NodeConfig fromConfig(Config config) {
304303
// --- Legacy key fallbacks (backward compatibility) ---
305304
// node.maxActiveNodes (old) -> maxConnections (new)
306305
if (section.hasPath("maxActiveNodes")) {
306+
logger.warn("Configuring [node.maxActiveNodes] is deprecated and will be removed in a future "
307+
+ "release. Please use [node.maxConnections] instead.");
307308
nc.maxConnections = section.getInt("maxActiveNodes");
308309
if (section.hasPath("connectFactor")) {
310+
logger.warn("Configuring [node.connectFactor] is deprecated and will be removed in a future "
311+
+ "release.");
309312
nc.minConnections = (int) (nc.maxConnections * section.getDouble("connectFactor"));
310313
}
311314
if (section.hasPath("activeConnectFactor")) {
315+
logger.warn("Configuring [node.activeConnectFactor] is deprecated and will be removed in a "
316+
+ "future release.");
312317
nc.minActiveConnections = (int) (nc.maxConnections
313318
* section.getDouble("activeConnectFactor"));
314319
}
315320
}
316321
if (section.hasPath("maxActiveNodesWithSameIp")) {
322+
logger.warn("Configuring [node.maxActiveNodesWithSameIp] is deprecated and will be removed "
323+
+ "in a future release. Please use [node.maxConnectionsWithSameIp] instead.");
317324
nc.maxConnectionsWithSameIp = section.getInt("maxActiveNodesWithSameIp");
318325
}
319326

320-
// Legacy key fallback: node.fullNodeAllowShieldedTransaction -> allowShieldedTransactionApi.
327+
// Legacy key fallback: node.allowShieldedTransactionApi wins fullNodeAllowShieldedTransaction
321328
if (section.hasPath("allowShieldedTransactionApi")) {
322329
nc.allowShieldedTransactionApi =
323330
section.getBoolean("allowShieldedTransactionApi");
@@ -351,6 +358,16 @@ private void postProcess() {
351358
rpc.thread = (Runtime.getRuntime().availableProcessors() + 1) / 2;
352359
}
353360

361+
if (rpc.maxConcurrentCallsPerConnection == 0) {
362+
rpc.maxConcurrentCallsPerConnection = Integer.MAX_VALUE;
363+
}
364+
if (rpc.maxConnectionIdleInMillis == 0) {
365+
rpc.maxConnectionIdleInMillis = Long.MAX_VALUE;
366+
}
367+
if (rpc.maxConnectionAgeInMillis == 0) {
368+
rpc.maxConnectionAgeInMillis = Long.MAX_VALUE;
369+
}
370+
354371
// validateSignThreadNum: 0 = auto-detect
355372
if (validateSignThreadNum == 0) {
356373
validateSignThreadNum = Runtime.getRuntime().availableProcessors();
@@ -374,6 +391,14 @@ private void postProcess() {
374391
syncFetchBatchNum = 100;
375392
}
376393

394+
// fetchBlock.timeout : clamp to [100, 1000]
395+
if (fetchBlock.timeout > 1000) {
396+
fetchBlock.timeout = 1000;
397+
}
398+
if (fetchBlock.timeout < 100) {
399+
fetchBlock.timeout = 100;
400+
}
401+
377402
// maxPendingBlockSize: clamp to [50, 2000]
378403
if (maxPendingBlockSize > 2000) {
379404
maxPendingBlockSize = 2000;
@@ -425,6 +450,20 @@ private void postProcess() {
425450
if (maxTrxCacheSize < 2000) {
426451
maxTrxCacheSize = 2000;
427452
}
453+
454+
// maxMessageSize: reject negative values
455+
if (rpc.maxMessageSize < 0) {
456+
throw new TronError("node.rpc.maxMessageSize must be non-negative, got: "
457+
+ rpc.maxMessageSize, PARAMETER_INIT);
458+
}
459+
if (http.maxMessageSize < 0) {
460+
throw new TronError("node.http.maxMessageSize must be non-negative, got: "
461+
+ http.maxMessageSize, PARAMETER_INIT);
462+
}
463+
if (jsonrpc.maxMessageSize < 0) {
464+
throw new TronError("node.jsonrpc.maxMessageSize must be non-negative, got: "
465+
+ jsonrpc.maxMessageSize, PARAMETER_INIT);
466+
}
428467
}
429468

430469
// ===========================================================================
@@ -465,36 +504,4 @@ private static Config normalizeNonStandardKeys(Config section) {
465504
return section;
466505
}
467506

468-
/**
469-
* Pre-normalize size paths so ConfigBeanFactory's primitive int/long binding succeeds
470-
* for human-readable values like "4m" / "128MB". For each maxMessageSize key, parse
471-
* via getMemorySize, validate non-negative and <= Integer.MAX_VALUE, and write the
472-
* numeric byte value back into the Config tree. Validation errors propagate before
473-
* bean creation so the failure points at the user-facing config path.
474-
*/
475-
private static Config normalizeMaxMessageSizes(Config config) {
476-
String[] paths = {
477-
"node.rpc.maxMessageSize",
478-
"node.http.maxMessageSize",
479-
"node.jsonrpc.maxMessageSize"
480-
};
481-
Config result = config;
482-
for (String path : paths) {
483-
if (config.hasPath(path)) {
484-
long bytes = parseMaxMessageSize(config, path);
485-
result = result.withValue(path, ConfigValueFactory.fromAnyRef(bytes));
486-
}
487-
}
488-
return result;
489-
}
490-
491-
private static long parseMaxMessageSize(Config config, String key) {
492-
long value = config.getMemorySize(key).toBytes();
493-
if (value < 0 || value > Integer.MAX_VALUE) {
494-
throw new TronError(key + " must be non-negative and <= "
495-
+ Integer.MAX_VALUE + ", got: " + value, PARAMETER_INIT);
496-
}
497-
return value;
498-
}
499-
500507
}

0 commit comments

Comments
 (0)