Skip to content

Commit 381d369

Browse files
authored
fix(config): optimizes config binding for node (#6755)
1 parent 0a8289c commit 381d369

14 files changed

Lines changed: 94 additions & 97 deletions

File tree

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,9 @@ public class CommonParameter {
119119
public boolean nodeEffectiveCheckEnable;
120120
@Getter
121121
@Setter
122-
public int nodeConnectionTimeout = 2000; // from clearParam(), consistent with mainnet.conf
123-
@Getter
124-
@Setter
125122
public int fetchBlockTimeout;
126123
@Getter
127124
@Setter
128-
public int nodeChannelReadTimeout;
129-
@Getter
130-
@Setter
131125
public int maxConnections = 30; // from clearParam(), consistent with mainnet.conf
132126
@Getter
133127
@Setter
@@ -297,13 +291,6 @@ public class CommonParameter {
297291
@Setter
298292
public long forbidTransferToContract;
299293

300-
// -- Netty --
301-
@Getter
302-
@Setter
303-
public int tcpNettyWorkThreadNum;
304-
@Getter
305-
@Setter
306-
public int udpNettyWorkThreadNum;
307294
@Getter
308295
@Setter
309296
public String trustNodeAddr; // clearParam: ""

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

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import com.typesafe.config.Config;
77
import com.typesafe.config.ConfigBeanFactory;
8-
import com.typesafe.config.ConfigFactory;
98
import com.typesafe.config.ConfigValueFactory;
109
import java.util.ArrayList;
1110
import java.util.List;
@@ -49,6 +48,9 @@ public class NodeConfig {
4948

5049
// node.discovery.* — HOCON merges into node { discovery { ... } }, auto-bound
5150
private DiscoveryConfig discovery = new DiscoveryConfig();
51+
@Getter(lombok.AccessLevel.NONE)
52+
@Setter(lombok.AccessLevel.NONE)
53+
private String externalIP = "";
5254

5355
// node.shutdown.* uses PascalCase keys (BlockTime, BlockHeight, BlockCount)
5456
// that don't match JavaBean naming. Excluded, read manually.
@@ -64,7 +66,7 @@ public class NodeConfig {
6466

6567
public boolean isDiscoveryEnable() { return discovery.isEnable(); }
6668
public boolean isDiscoveryPersist() { return discovery.isPersist(); }
67-
public String getDiscoveryExternalIp() { return discovery.getExternal().getIp(); }
69+
public String getDiscoveryExternalIp() { return externalIP; }
6870
public String getShutdownBlockTime() { return shutdownBlockTime; }
6971
public long getShutdownBlockHeight() { return shutdownBlockHeight; }
7072
public long getShutdownBlockCount() { return shutdownBlockCount; }
@@ -76,13 +78,10 @@ public class NodeConfig {
7678
private boolean enableIpv6 = false;
7779
private boolean effectiveCheckEnable = false;
7880
private int maxFastForwardNum = 4;
79-
private int tcpNettyWorkThreadNum = 0;
80-
private int udpNettyWorkThreadNum = 1;
8181
private ValidContractProtoConfig validContractProto = new ValidContractProtoConfig();
8282
private int shieldedTransInPendingMaxCounts = 10;
8383
private long blockCacheTimeout = 60;
8484
private long receiveTcpMinDataLength = 2048;
85-
private ChannelConfig channel = new ChannelConfig();
8685
private int maxTransactionPendingSize = 2000;
8786
private long pendingTransactionTimeout = 60000;
8887
private int maxTrxCacheSize = 50_000;
@@ -91,6 +90,8 @@ public class NodeConfig {
9190
private boolean unsolidifiedBlockCheck = false;
9291
private int maxUnsolidifiedBlocks = 54;
9392
private String zenTokenId = "000000";
93+
@Getter(lombok.AccessLevel.NONE)
94+
@Setter(lombok.AccessLevel.NONE)
9495
private boolean allowShieldedTransactionApi = false;
9596
private double activeConnectFactor = 0.1;
9697
private double connectFactor = 0.6;
@@ -100,17 +101,15 @@ public class NodeConfig {
100101

101102
// ---- Sub-beans matching config's dot-notation nested structure ----
102103
private ListenConfig listen = new ListenConfig();
103-
private ConnectionConfig connection = new ConnectionConfig();
104104
private FetchBlockConfig fetchBlock = new FetchBlockConfig();
105105
private SolidityConfig solidity = new SolidityConfig();
106106

107107
// Convenience getters for backward compatibility with applyNodeConfig
108108
public int getListenPort() { return listen.getPort(); }
109-
public int getConnectionTimeout() { return connection.getTimeout(); }
110109
public int getFetchBlockTimeout() { return fetchBlock.getTimeout(); }
111110
public int getSolidityThreads() { return solidity.getThreads(); }
112-
public int getChannelReadTimeout() { return channel.getRead().getTimeout(); }
113111
public int getValidContractProtoThreads() { return validContractProto.getThreads(); }
112+
public boolean isAllowShieldedTransactionApi() { return allowShieldedTransactionApi; }
114113

115114
// ---- List fields (manually read) ----
116115
private List<String> active = new ArrayList<>();
@@ -139,13 +138,6 @@ public class NodeConfig {
139138
public static class DiscoveryConfig {
140139
private boolean enable = false;
141140
private boolean persist = false;
142-
private ExternalConfig external = new ExternalConfig();
143-
144-
@Getter
145-
@Setter
146-
public static class ExternalConfig {
147-
private String ip = "";
148-
}
149141
}
150142

151143
@Getter
@@ -154,12 +146,6 @@ public static class ListenConfig {
154146
private int port = 18888;
155147
}
156148

157-
@Getter
158-
@Setter
159-
public static class ConnectionConfig {
160-
private int timeout = 2;
161-
}
162-
163149
@Getter
164150
@Setter
165151
public static class FetchBlockConfig {
@@ -172,18 +158,6 @@ public static class SolidityConfig {
172158
private int threads = 0; // 0 = auto (availableProcessors)
173159
}
174160

175-
@Getter
176-
@Setter
177-
public static class ChannelConfig {
178-
private ReadConfig read = new ReadConfig();
179-
180-
@Getter
181-
@Setter
182-
public static class ReadConfig {
183-
private int timeout = 0;
184-
}
185-
}
186-
187161
@Getter
188162
@Setter
189163
public static class ValidContractProtoConfig {
@@ -362,7 +336,7 @@ public static class DnsConfig {
362336
/**
363337
* Create NodeConfig from the "node" section of the application config.
364338
*
365-
* <p>Dot-notation keys (listen.port, connection.timeout, fetchBlock.timeout,
339+
* <p>Dot-notation keys (listen.port, fetchBlock.timeout,
366340
* solidity.threads) become nested HOCON objects and cannot be auto-bound to flat
367341
* Java fields. They are read manually after ConfigBeanFactory binding.
368342
*
@@ -403,14 +377,23 @@ public static NodeConfig fromConfig(Config config) {
403377
nc.maxConnectionsWithSameIp = section.getInt("maxActiveNodesWithSameIp");
404378
}
405379

380+
nc.externalIP = getString(section, "discovery.external.ip", "");
381+
if ("null".equalsIgnoreCase(nc.externalIP)) {
382+
nc.externalIP = "";
383+
}
384+
406385
// Legacy key fallback: node.fullNodeAllowShieldedTransaction -> allowShieldedTransactionApi.
407-
// reference.conf does not ship the legacy key, so hasPath here reliably means the user
408-
// set it in their config. When present, it overrides the modern key.
409-
if (section.hasPath("fullNodeAllowShieldedTransaction")) {
410-
nc.allowShieldedTransactionApi = section.getBoolean("fullNodeAllowShieldedTransaction");
386+
if (section.hasPath("allowShieldedTransactionApi")) {
387+
nc.allowShieldedTransactionApi =
388+
section.getBoolean("allowShieldedTransactionApi");
389+
} else if (section.hasPath("fullNodeAllowShieldedTransaction")) {
390+
// for compatibility with previous configuration
391+
nc.allowShieldedTransactionApi =
392+
section.getBoolean("fullNodeAllowShieldedTransaction");
411393
logger.warn("Configuring [node.fullNodeAllowShieldedTransaction] will be deprecated. "
412394
+ "Please use [node.allowShieldedTransactionApi] instead.");
413395
}
396+
414397
// node.shutdown.* — PascalCase keys (BlockTime, BlockHeight), cannot auto-bind
415398
nc.shutdownBlockTime = config.hasPath("node.shutdown.BlockTime")
416399
? config.getString("node.shutdown.BlockTime") : "";

common/src/main/resources/reference.conf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ node {
174174
walletExtensionApi = false
175175

176176
listen.port = 18888
177-
connection.timeout = 2
178177
fetchBlock.timeout = 500
179178

180179
# Number of blocks to fetch in one batch during sync. Range: [100, 2000].
@@ -194,7 +193,7 @@ node {
194193
minParticipationRate = 0
195194

196195
# Whether to enable shielded transaction API
197-
allowShieldedTransactionApi = false
196+
# allowShieldedTransactionApi = false
198197

199198
# Whether to print config log at startup
200199
openPrintLog = true
@@ -211,15 +210,12 @@ node {
211210

212211
isOpenFullTcpDisconnect = false
213212
inactiveThreshold = 600 // seconds
214-
tcpNettyWorkThreadNum = 0
215-
udpNettyWorkThreadNum = 1
216213
maxFastForwardNum = 4
217214
activeConnectFactor = 0.1
218215
connectFactor = 0.6
219216
# Legacy alias `maxActiveNodesWithSameIp` is still accepted from user config
220217
# (see NodeConfig alias-fallback) but is intentionally NOT defaulted here —
221218
# shipping it in reference.conf would always mask the modern `maxConnectionsWithSameIp`.
222-
channel.read.timeout = 0
223219
metricsEnable = false
224220

225221
p2p {

common/src/test/java/org/tron/core/config/args/NodeConfigTest.java

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public void testDefaults() {
2323
Config empty = withRef();
2424
NodeConfig nc = NodeConfig.fromConfig(empty);
2525
assertEquals(18888, nc.getListenPort());
26-
assertEquals(2, nc.getConnectionTimeout());
2726
assertEquals(500, nc.getFetchBlockTimeout());
2827
assertEquals(30, nc.getMaxConnections());
2928
assertEquals(8, nc.getMinConnections());
@@ -32,7 +31,6 @@ public void testDefaults() {
3231
// reference.conf matches code default: discovery disabled when not configured
3332
assertFalse(nc.isDiscoveryEnable());
3433
assertFalse(nc.isDiscoveryPersist());
35-
assertEquals(0, nc.getChannelReadTimeout());
3634
}
3735

3836
@Test
@@ -42,7 +40,6 @@ public void testDotNotationFields() {
4240
+ " fetchBlock { timeout = 300 }, solidity { threads = 4 } }");
4341
NodeConfig nc = NodeConfig.fromConfig(config);
4442
assertEquals(19999, nc.getListenPort());
45-
assertEquals(5, nc.getConnectionTimeout());
4643
assertEquals(300, nc.getFetchBlockTimeout());
4744
assertEquals(4, nc.getSolidityThreads());
4845
}
@@ -298,22 +295,87 @@ public void testShieldedApiModernKeyRespected() {
298295

299296
@Test
300297
public void testShieldedApiLegacyKeyRespected() {
301-
// Regression guard: reference.conf ships `allowShieldedTransactionApi = false`, which
302-
// used to make the legacy-key fallback dead code. A user who only set the legacy key
303-
// must still have their value honored.
304298
NodeConfig nc = NodeConfig.fromConfig(
305299
withRef("node.fullNodeAllowShieldedTransaction = true"));
306300
assertTrue(nc.isAllowShieldedTransactionApi());
301+
nc = NodeConfig.fromConfig(
302+
withRef("node.fullNodeAllowShieldedTransaction = false"));
303+
assertFalse(nc.isAllowShieldedTransactionApi());
304+
nc = NodeConfig.fromConfig(
305+
withRef("node.allowShieldedTransactionApi = true"));
306+
assertTrue(nc.isAllowShieldedTransactionApi());
307+
nc = NodeConfig.fromConfig(
308+
withRef("node.allowShieldedTransactionApi = false"));
309+
assertFalse(nc.isAllowShieldedTransactionApi());
310+
nc = NodeConfig.fromConfig(
311+
withRef(""));
312+
assertFalse(nc.isAllowShieldedTransactionApi());
307313
}
308314

309315
@Test
310-
public void testShieldedApiLegacyKeyTakesPriorityOverModern() {
311-
// Consistent with maxActiveNodesWithSameIp: legacy key presence wins over modern.
316+
public void testShieldedApiModernKeyTakesPriorityOverLegacy() {
317+
// When both keys are set, the modern key wins; the legacy key is only used as fallback
318+
// when modern is absent.
312319
NodeConfig nc = NodeConfig.fromConfig(
313320
withRef("node {\n"
314-
+ " allowShieldedTransactionApi = false\n"
321+
+ " allowShieldedTransactionApi = true\n"
315322
+ " fullNodeAllowShieldedTransaction = true\n"
316323
+ "}"));
317324
assertTrue(nc.isAllowShieldedTransactionApi());
325+
nc = NodeConfig.fromConfig(
326+
withRef("node {\n"
327+
+ " allowShieldedTransactionApi = true\n"
328+
+ " fullNodeAllowShieldedTransaction = false\n"
329+
+ "}"));
330+
assertTrue(nc.isAllowShieldedTransactionApi());
331+
nc = NodeConfig.fromConfig(
332+
withRef("node {\n"
333+
+ " allowShieldedTransactionApi = false\n"
334+
+ " fullNodeAllowShieldedTransaction = true\n"
335+
+ "}"));
336+
assertFalse(nc.isAllowShieldedTransactionApi());
337+
nc = NodeConfig.fromConfig(
338+
withRef("node {\n"
339+
+ " allowShieldedTransactionApi = false\n"
340+
+ " fullNodeAllowShieldedTransaction = false\n"
341+
+ "}"));
342+
assertFalse(nc.isAllowShieldedTransactionApi());
343+
}
344+
345+
// ----- discovery.external.ip: null / "null" sentinel handling -----
346+
347+
@Test
348+
public void testExternalIpAbsentDefaultsToEmpty() {
349+
NodeConfig nc = NodeConfig.fromConfig(withRef());
350+
assertEquals("", nc.getDiscoveryExternalIp());
351+
}
352+
353+
@Test
354+
public void testExternalIpHoconNullTreatedAsEmpty() {
355+
// HOCON `null` makes hasPath() return false; getString falls back to "".
356+
NodeConfig nc = NodeConfig.fromConfig(
357+
withRef("node.discovery.external.ip = null"));
358+
assertEquals("", nc.getDiscoveryExternalIp());
318359
}
360+
361+
@Test
362+
public void testExternalIpStringNullSentinelConvertedToEmpty() {
363+
// String literal "null" (case-insensitive) is an explicit sentinel that must map to "".
364+
NodeConfig nc = NodeConfig.fromConfig(
365+
withRef("node.discovery.external.ip = \"null\""));
366+
assertEquals("", nc.getDiscoveryExternalIp());
367+
368+
nc = NodeConfig.fromConfig(
369+
withRef("node.discovery.external.ip = \"NULL\""));
370+
assertEquals("", nc.getDiscoveryExternalIp());
371+
}
372+
373+
@Test
374+
public void testExternalIpValidValuePreserved() {
375+
NodeConfig nc = NodeConfig.fromConfig(
376+
withRef("node.discovery.external.ip = \"1.2.3.4\""));
377+
assertEquals("1.2.3.4", nc.getDiscoveryExternalIp());
378+
}
379+
380+
319381
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ private static void applyBlockConfig(BlockConfig block) {
510510
* which are applied here after copying the bean value.
511511
*
512512
* @param nc the NodeConfig bean populated from config.conf "node" section
513-
* node.discovery / node.channel.read.timeout (dot-notation paths
513+
* node.discovery / (dot-notation paths
514514
* not part of the NodeConfig bean)
515515
*/
516516
@SuppressWarnings("checkstyle:MethodLength")
@@ -578,7 +578,6 @@ private static void applyNodeConfig(NodeConfig nc) {
578578

579579
// ---- Flat scalar fields ----
580580
PARAMETER.nodeEffectiveCheckEnable = nc.isEffectiveCheckEnable();
581-
PARAMETER.nodeConnectionTimeout = nc.getConnectionTimeout() * 1000;
582581

583582
// fetchBlock.timeout — range check [100, 1000], default 500
584583
int fetchTimeout = nc.getFetchBlockTimeout();
@@ -606,8 +605,6 @@ private static void applyNodeConfig(NodeConfig nc) {
606605

607606
PARAMETER.maxHttpConnectNumber = nc.getMaxHttpConnectNumber();
608607
PARAMETER.netMaxTrxPerSecond = nc.getNetMaxTrxPerSecond();
609-
PARAMETER.tcpNettyWorkThreadNum = nc.getTcpNettyWorkThreadNum();
610-
PARAMETER.udpNettyWorkThreadNum = nc.getUdpNettyWorkThreadNum();
611608

612609
if (StringUtils.isEmpty(PARAMETER.trustNodeAddr)) {
613610
String trustNode = nc.getTrustNode();
@@ -654,7 +651,6 @@ private static void applyNodeConfig(NodeConfig nc) {
654651
// discovery (dot-notation, read in NodeConfig.fromConfig)
655652
PARAMETER.nodeDiscoveryEnable = nc.isDiscoveryEnable();
656653
PARAMETER.nodeDiscoveryPersist = nc.isDiscoveryPersist();
657-
PARAMETER.nodeChannelReadTimeout = nc.getChannelReadTimeout();
658654

659655
// Legacy maxActiveNodes fallback handled in NodeConfig.fromConfig()
660656

framework/src/main/resources/config.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ node {
150150

151151
listen.port = 18888
152152

153-
connection.timeout = 2
154-
155153
fetchBlock.timeout = 200
156154
# syncFetchBatchNum = 2000
157155

framework/src/test/java/org/tron/common/ParameterTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,8 @@ public void testCommonParameter() {
7676
assertFalse(parameter.isNodeDiscoveryPersist());
7777
parameter.setNodeEffectiveCheckEnable(false);
7878
assertFalse(parameter.isNodeEffectiveCheckEnable());
79-
parameter.setNodeConnectionTimeout(500);
80-
assertEquals(500, parameter.getNodeConnectionTimeout());
8179
parameter.setFetchBlockTimeout(500);
8280
assertEquals(500, parameter.getFetchBlockTimeout());
83-
parameter.setNodeChannelReadTimeout(500);
84-
assertEquals(500, parameter.getNodeChannelReadTimeout());
8581
parameter.setMaxConnections(500);
8682
assertEquals(500, parameter.getMaxConnections());
8783
parameter.setMinConnections(500);
@@ -170,10 +166,6 @@ public void testCommonParameter() {
170166
assertEquals(1, parameter.getAllowTvmSolidity059());
171167
parameter.setForbidTransferToContract(1);
172168
assertEquals(1, parameter.getForbidTransferToContract());
173-
parameter.setTcpNettyWorkThreadNum(5);
174-
assertEquals(5, parameter.getTcpNettyWorkThreadNum());
175-
parameter.setUdpNettyWorkThreadNum(5);
176-
assertEquals(5, parameter.getUdpNettyWorkThreadNum());
177169
parameter.setTrustNodeAddr("address");
178170
assertEquals("address", parameter.getTrustNodeAddr());
179171
parameter.setWalletExtensionApi(false);

0 commit comments

Comments
 (0)