Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -316,9 +316,6 @@ public class CommonParameter {
public List<String> backupMembers;
@Getter
@Setter
public long receiveTcpMinDataLength; // clearParam: 2048
@Getter
@Setter
public boolean isOpenFullTcpDisconnect;
@Getter
@Setter
Expand Down
89 changes: 48 additions & 41 deletions common/src/main/java/org/tron/core/config/args/NodeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// ConfigBeanFactory auto-binds all fields including sub-beans, dot-notation keys,
// PBFT fields, and list fields. Only legacy key fallbacks and PascalCase shutdown
// keys are read manually.
// Always construct via {@link #fromConfig} — direct construction skips postProcess() clamping.
@Slf4j
@Getter
@Setter
Expand Down Expand Up @@ -77,7 +78,6 @@ public String getDiscoveryExternalIp() {
private ValidContractProtoConfig validContractProto = new ValidContractProtoConfig();
private int shieldedTransInPendingMaxCounts = 10;
private long blockCacheTimeout = 60;
private long receiveTcpMinDataLength = 2048;
private int maxTransactionPendingSize = 2000;
private long pendingTransactionTimeout = 60000;
private int maxTrxCacheSize = 50_000;
Expand Down Expand Up @@ -217,10 +217,10 @@ public static class RpcConfig {
private int pBFTPort = 50071;

private int thread = 0;
private int maxConcurrentCallsPerConnection = 2147483647;
private int maxConcurrentCallsPerConnection = 0;
private int flowControlWindow = 1048576;
private long maxConnectionIdleInMillis = Long.MAX_VALUE;
private long maxConnectionAgeInMillis = Long.MAX_VALUE;
private long maxConnectionIdleInMillis = 0;
private long maxConnectionAgeInMillis = 0;
private int maxMessageSize = 4194304;
private int maxHeaderListSize = 8192;
private int maxRstStream = 0;
Expand Down Expand Up @@ -279,8 +279,8 @@ public static class DnsConfig {
private String dnsPrivate = "";
private List<String> knownUrls = new ArrayList<>();
private List<String> staticNodes = new ArrayList<>();
private int maxMergeSize = 0;
private double changeThreshold = 0.0;
private int maxMergeSize = 5;
private double changeThreshold = 0.1;
private String serverType = "";
private String accessKeyId = "";
private String accessKeySecret = "";
Expand All @@ -296,8 +296,7 @@ public static class DnsConfig {
* since ConfigBeanFactory expects typed bean lists, not string lists.
*/
public static NodeConfig fromConfig(Config config) {
Config section = normalizeNonStandardKeys(
normalizeMaxMessageSizes(config).getConfig("node"));
Config section = normalizeNonStandardKeys(config.getConfig("node"));

// Auto-bind all fields and sub-beans. ConfigBeanFactory fails fast with a
// descriptive path on any `= null` value
Expand All @@ -306,20 +305,28 @@ public static NodeConfig fromConfig(Config config) {
// --- Legacy key fallbacks (backward compatibility) ---
// node.maxActiveNodes (old) -> maxConnections (new)
if (section.hasPath("maxActiveNodes")) {
logger.warn("Configuring [node.maxActiveNodes] is deprecated and will be removed in a future "
+ "release. Please use [node.maxConnections] instead.");
nc.maxConnections = section.getInt("maxActiveNodes");
if (section.hasPath("connectFactor")) {
logger.warn("Configuring [node.connectFactor] is deprecated and will be removed in a future "
+ "release.");
nc.minConnections = (int) (nc.maxConnections * section.getDouble("connectFactor"));
}
if (section.hasPath("activeConnectFactor")) {
logger.warn("Configuring [node.activeConnectFactor] is deprecated and will be removed in a "
+ "future release.");
nc.minActiveConnections = (int) (nc.maxConnections
* section.getDouble("activeConnectFactor"));
}
}
if (section.hasPath("maxActiveNodesWithSameIp")) {
logger.warn("Configuring [node.maxActiveNodesWithSameIp] is deprecated and will be removed "
+ "in a future release. Please use [node.maxConnectionsWithSameIp] instead.");
nc.maxConnectionsWithSameIp = section.getInt("maxActiveNodesWithSameIp");
}

// Legacy key fallback: node.fullNodeAllowShieldedTransaction -> allowShieldedTransactionApi.
// Legacy key fallback: node.allowShieldedTransactionApi wins fullNodeAllowShieldedTransaction
if (section.hasPath("allowShieldedTransactionApi")) {
nc.allowShieldedTransactionApi =
section.getBoolean("allowShieldedTransactionApi");
Expand Down Expand Up @@ -353,6 +360,16 @@ private void postProcess() {
rpc.thread = (Runtime.getRuntime().availableProcessors() + 1) / 2;
}

if (rpc.maxConcurrentCallsPerConnection == 0) {
rpc.maxConcurrentCallsPerConnection = Integer.MAX_VALUE;
}
if (rpc.maxConnectionIdleInMillis == 0) {
rpc.maxConnectionIdleInMillis = Long.MAX_VALUE;
}
if (rpc.maxConnectionAgeInMillis == 0) {
rpc.maxConnectionAgeInMillis = Long.MAX_VALUE;
}

// validateSignThreadNum: 0 = auto-detect
if (validateSignThreadNum == 0) {
validateSignThreadNum = Runtime.getRuntime().availableProcessors();
Expand All @@ -376,6 +393,14 @@ private void postProcess() {
syncFetchBatchNum = 100;
}

// fetchBlock.timeout : clamp to [100, 1000]
Comment thread
317787106 marked this conversation as resolved.
if (fetchBlock.timeout > 1000) {
fetchBlock.timeout = 1000;
}
if (fetchBlock.timeout < 100) {
fetchBlock.timeout = 100;
}

// maxPendingBlockSize: clamp to [50, 2000]
if (maxPendingBlockSize > 2000) {
maxPendingBlockSize = 2000;
Expand Down Expand Up @@ -427,6 +452,20 @@ private void postProcess() {
if (maxTrxCacheSize < 2000) {
maxTrxCacheSize = 2000;
}

// maxMessageSize: reject negative values
if (rpc.maxMessageSize < 0) {
throw new TronError("node.rpc.maxMessageSize must be non-negative, got: "
+ rpc.maxMessageSize, PARAMETER_INIT);
}
if (http.maxMessageSize < 0) {
throw new TronError("node.http.maxMessageSize must be non-negative, got: "
+ http.maxMessageSize, PARAMETER_INIT);
}
if (jsonrpc.maxMessageSize < 0) {
throw new TronError("node.jsonrpc.maxMessageSize must be non-negative, got: "
+ jsonrpc.maxMessageSize, PARAMETER_INIT);
}
}

// ===========================================================================
Expand Down Expand Up @@ -467,36 +506,4 @@ private static Config normalizeNonStandardKeys(Config section) {
return section;
}

/**
* Pre-normalize size paths so ConfigBeanFactory's primitive int/long binding succeeds
* for human-readable values like "4m" / "128MB". For each maxMessageSize key, parse
* via getMemorySize, validate non-negative and <= Integer.MAX_VALUE, and write the
* numeric byte value back into the Config tree. Validation errors propagate before
* bean creation so the failure points at the user-facing config path.
*/
private static Config normalizeMaxMessageSizes(Config config) {
String[] paths = {
"node.rpc.maxMessageSize",
"node.http.maxMessageSize",
"node.jsonrpc.maxMessageSize"
};
Config result = config;
for (String path : paths) {
if (config.hasPath(path)) {
long bytes = parseMaxMessageSize(config, path);
result = result.withValue(path, ConfigValueFactory.fromAnyRef(bytes));
}
}
return result;
}

private static long parseMaxMessageSize(Config config, String key) {
long value = config.getMemorySize(key).toBytes();
if (value < 0 || value > Integer.MAX_VALUE) {
throw new TronError(key + " must be non-negative and <= "
+ Integer.MAX_VALUE + ", got: " + value, PARAMETER_INIT);
}
return value;
}

}
Loading
Loading