Skip to content
Merged
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 @@ -119,15 +119,9 @@ public class CommonParameter {
public boolean nodeEffectiveCheckEnable;
@Getter
@Setter
public int nodeConnectionTimeout = 2000; // from clearParam(), consistent with mainnet.conf
@Getter
@Setter
public int fetchBlockTimeout;
@Getter
@Setter
public int nodeChannelReadTimeout;
@Getter
@Setter
public int maxConnections = 30; // from clearParam(), consistent with mainnet.conf
@Getter
@Setter
Expand Down Expand Up @@ -297,13 +291,6 @@ public class CommonParameter {
@Setter
public long forbidTransferToContract;

// -- Netty --
@Getter
@Setter
public int tcpNettyWorkThreadNum;
@Getter
@Setter
public int udpNettyWorkThreadNum;
@Getter
@Setter
public String trustNodeAddr; // clearParam: ""
Expand Down
59 changes: 21 additions & 38 deletions common/src/main/java/org/tron/core/config/args/NodeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import com.typesafe.config.Config;
import com.typesafe.config.ConfigBeanFactory;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigValueFactory;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -49,6 +48,9 @@ public class NodeConfig {

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

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

public boolean isDiscoveryEnable() { return discovery.isEnable(); }
public boolean isDiscoveryPersist() { return discovery.isPersist(); }
public String getDiscoveryExternalIp() { return discovery.getExternal().getIp(); }
public String getDiscoveryExternalIp() { return externalIP; }
public String getShutdownBlockTime() { return shutdownBlockTime; }
public long getShutdownBlockHeight() { return shutdownBlockHeight; }
public long getShutdownBlockCount() { return shutdownBlockCount; }
Expand All @@ -76,13 +78,10 @@ public class NodeConfig {
private boolean enableIpv6 = false;
private boolean effectiveCheckEnable = false;
private int maxFastForwardNum = 4;
private int tcpNettyWorkThreadNum = 0;
private int udpNettyWorkThreadNum = 1;
private ValidContractProtoConfig validContractProto = new ValidContractProtoConfig();
private int shieldedTransInPendingMaxCounts = 10;
private long blockCacheTimeout = 60;
private long receiveTcpMinDataLength = 2048;
private ChannelConfig channel = new ChannelConfig();
private int maxTransactionPendingSize = 2000;
private long pendingTransactionTimeout = 60000;
private int maxTrxCacheSize = 50_000;
Expand All @@ -91,6 +90,8 @@ public class NodeConfig {
private boolean unsolidifiedBlockCheck = false;
private int maxUnsolidifiedBlocks = 54;
private String zenTokenId = "000000";
@Getter(lombok.AccessLevel.NONE)
@Setter(lombok.AccessLevel.NONE)
private boolean allowShieldedTransactionApi = false;
private double activeConnectFactor = 0.1;
private double connectFactor = 0.6;
Expand All @@ -100,17 +101,15 @@ public class NodeConfig {

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

// Convenience getters for backward compatibility with applyNodeConfig
public int getListenPort() { return listen.getPort(); }
public int getConnectionTimeout() { return connection.getTimeout(); }
public int getFetchBlockTimeout() { return fetchBlock.getTimeout(); }
public int getSolidityThreads() { return solidity.getThreads(); }
public int getChannelReadTimeout() { return channel.getRead().getTimeout(); }
public int getValidContractProtoThreads() { return validContractProto.getThreads(); }
public boolean isAllowShieldedTransactionApi() { return allowShieldedTransactionApi; }

// ---- List fields (manually read) ----
private List<String> active = new ArrayList<>();
Expand Down Expand Up @@ -139,13 +138,6 @@ public class NodeConfig {
public static class DiscoveryConfig {
private boolean enable = false;
private boolean persist = false;
private ExternalConfig external = new ExternalConfig();

@Getter
@Setter
public static class ExternalConfig {
private String ip = "";
}
}

@Getter
Expand All @@ -154,12 +146,6 @@ public static class ListenConfig {
private int port = 18888;
}

@Getter
@Setter
public static class ConnectionConfig {
private int timeout = 2;
}

@Getter
@Setter
public static class FetchBlockConfig {
Expand All @@ -172,18 +158,6 @@ public static class SolidityConfig {
private int threads = 0; // 0 = auto (availableProcessors)
}

@Getter
@Setter
public static class ChannelConfig {
private ReadConfig read = new ReadConfig();

@Getter
@Setter
public static class ReadConfig {
private int timeout = 0;
}
}

@Getter
@Setter
public static class ValidContractProtoConfig {
Expand Down Expand Up @@ -362,7 +336,7 @@ public static class DnsConfig {
/**
* Create NodeConfig from the "node" section of the application config.
*
* <p>Dot-notation keys (listen.port, connection.timeout, fetchBlock.timeout,
* <p>Dot-notation keys (listen.port, fetchBlock.timeout,
* solidity.threads) become nested HOCON objects and cannot be auto-bound to flat
* Java fields. They are read manually after ConfigBeanFactory binding.
*
Expand Down Expand Up @@ -403,14 +377,23 @@ public static NodeConfig fromConfig(Config config) {
nc.maxConnectionsWithSameIp = section.getInt("maxActiveNodesWithSameIp");
}

nc.externalIP = getString(section, "discovery.external.ip", "");
Comment thread
317787106 marked this conversation as resolved.
if ("null".equalsIgnoreCase(nc.externalIP)) {
nc.externalIP = "";
}

// Legacy key fallback: node.fullNodeAllowShieldedTransaction -> allowShieldedTransactionApi.
// reference.conf does not ship the legacy key, so hasPath here reliably means the user
// set it in their config. When present, it overrides the modern key.
if (section.hasPath("fullNodeAllowShieldedTransaction")) {
nc.allowShieldedTransactionApi = section.getBoolean("fullNodeAllowShieldedTransaction");
if (section.hasPath("allowShieldedTransactionApi")) {
nc.allowShieldedTransactionApi =
section.getBoolean("allowShieldedTransactionApi");
} else if (section.hasPath("fullNodeAllowShieldedTransaction")) {
// for compatibility with previous configuration
nc.allowShieldedTransactionApi =
section.getBoolean("fullNodeAllowShieldedTransaction");
logger.warn("Configuring [node.fullNodeAllowShieldedTransaction] will be deprecated. "
+ "Please use [node.allowShieldedTransactionApi] instead.");
}

// node.shutdown.* — PascalCase keys (BlockTime, BlockHeight), cannot auto-bind
nc.shutdownBlockTime = config.hasPath("node.shutdown.BlockTime")
? config.getString("node.shutdown.BlockTime") : "";
Expand Down
6 changes: 1 addition & 5 deletions common/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ node {
walletExtensionApi = false

listen.port = 18888
connection.timeout = 2
fetchBlock.timeout = 500

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

# Whether to enable shielded transaction API
allowShieldedTransactionApi = false
# allowShieldedTransactionApi = false

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

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

p2p {
Expand Down
80 changes: 71 additions & 9 deletions common/src/test/java/org/tron/core/config/args/NodeConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public void testDefaults() {
Config empty = withRef();
NodeConfig nc = NodeConfig.fromConfig(empty);
assertEquals(18888, nc.getListenPort());
assertEquals(2, nc.getConnectionTimeout());
assertEquals(500, nc.getFetchBlockTimeout());
assertEquals(30, nc.getMaxConnections());
assertEquals(8, nc.getMinConnections());
Expand All @@ -32,7 +31,6 @@ public void testDefaults() {
// reference.conf matches code default: discovery disabled when not configured
assertFalse(nc.isDiscoveryEnable());
assertFalse(nc.isDiscoveryPersist());
assertEquals(0, nc.getChannelReadTimeout());
}

@Test
Expand All @@ -42,7 +40,6 @@ public void testDotNotationFields() {
+ " fetchBlock { timeout = 300 }, solidity { threads = 4 } }");
NodeConfig nc = NodeConfig.fromConfig(config);
assertEquals(19999, nc.getListenPort());
assertEquals(5, nc.getConnectionTimeout());
assertEquals(300, nc.getFetchBlockTimeout());
assertEquals(4, nc.getSolidityThreads());
}
Expand Down Expand Up @@ -298,22 +295,87 @@ public void testShieldedApiModernKeyRespected() {

@Test
public void testShieldedApiLegacyKeyRespected() {
// Regression guard: reference.conf ships `allowShieldedTransactionApi = false`, which
// used to make the legacy-key fallback dead code. A user who only set the legacy key
// must still have their value honored.
NodeConfig nc = NodeConfig.fromConfig(
withRef("node.fullNodeAllowShieldedTransaction = true"));
assertTrue(nc.isAllowShieldedTransactionApi());
nc = NodeConfig.fromConfig(
withRef("node.fullNodeAllowShieldedTransaction = false"));
assertFalse(nc.isAllowShieldedTransactionApi());
nc = NodeConfig.fromConfig(
withRef("node.allowShieldedTransactionApi = true"));
assertTrue(nc.isAllowShieldedTransactionApi());
nc = NodeConfig.fromConfig(
withRef("node.allowShieldedTransactionApi = false"));
assertFalse(nc.isAllowShieldedTransactionApi());
nc = NodeConfig.fromConfig(
withRef(""));
assertFalse(nc.isAllowShieldedTransactionApi());
}

@Test
public void testShieldedApiLegacyKeyTakesPriorityOverModern() {
// Consistent with maxActiveNodesWithSameIp: legacy key presence wins over modern.
public void testShieldedApiModernKeyTakesPriorityOverLegacy() {
// When both keys are set, the modern key wins; the legacy key is only used as fallback
// when modern is absent.
NodeConfig nc = NodeConfig.fromConfig(
withRef("node {\n"
+ " allowShieldedTransactionApi = false\n"
+ " allowShieldedTransactionApi = true\n"
+ " fullNodeAllowShieldedTransaction = true\n"
+ "}"));
assertTrue(nc.isAllowShieldedTransactionApi());
nc = NodeConfig.fromConfig(
withRef("node {\n"
+ " allowShieldedTransactionApi = true\n"
+ " fullNodeAllowShieldedTransaction = false\n"
+ "}"));
assertTrue(nc.isAllowShieldedTransactionApi());
nc = NodeConfig.fromConfig(
withRef("node {\n"
+ " allowShieldedTransactionApi = false\n"
+ " fullNodeAllowShieldedTransaction = true\n"
+ "}"));
assertFalse(nc.isAllowShieldedTransactionApi());
nc = NodeConfig.fromConfig(
withRef("node {\n"
+ " allowShieldedTransactionApi = false\n"
+ " fullNodeAllowShieldedTransaction = false\n"
+ "}"));
assertFalse(nc.isAllowShieldedTransactionApi());
}

// ----- discovery.external.ip: null / "null" sentinel handling -----

@Test
public void testExternalIpAbsentDefaultsToEmpty() {
NodeConfig nc = NodeConfig.fromConfig(withRef());
assertEquals("", nc.getDiscoveryExternalIp());
}

@Test
public void testExternalIpHoconNullTreatedAsEmpty() {
// HOCON `null` makes hasPath() return false; getString falls back to "".
NodeConfig nc = NodeConfig.fromConfig(
withRef("node.discovery.external.ip = null"));
assertEquals("", nc.getDiscoveryExternalIp());
}

@Test
public void testExternalIpStringNullSentinelConvertedToEmpty() {
// String literal "null" (case-insensitive) is an explicit sentinel that must map to "".
NodeConfig nc = NodeConfig.fromConfig(
withRef("node.discovery.external.ip = \"null\""));
assertEquals("", nc.getDiscoveryExternalIp());

nc = NodeConfig.fromConfig(
withRef("node.discovery.external.ip = \"NULL\""));
assertEquals("", nc.getDiscoveryExternalIp());
}

@Test
public void testExternalIpValidValuePreserved() {
NodeConfig nc = NodeConfig.fromConfig(
withRef("node.discovery.external.ip = \"1.2.3.4\""));
assertEquals("1.2.3.4", nc.getDiscoveryExternalIp());
}


}
6 changes: 1 addition & 5 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ private static void applyBlockConfig(BlockConfig block) {
* which are applied here after copying the bean value.
*
* @param nc the NodeConfig bean populated from config.conf "node" section
* node.discovery / node.channel.read.timeout (dot-notation paths
* node.discovery / (dot-notation paths
* not part of the NodeConfig bean)
*/
@SuppressWarnings("checkstyle:MethodLength")
Expand Down Expand Up @@ -578,7 +578,6 @@ private static void applyNodeConfig(NodeConfig nc) {

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

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

PARAMETER.maxHttpConnectNumber = nc.getMaxHttpConnectNumber();
PARAMETER.netMaxTrxPerSecond = nc.getNetMaxTrxPerSecond();
PARAMETER.tcpNettyWorkThreadNum = nc.getTcpNettyWorkThreadNum();
PARAMETER.udpNettyWorkThreadNum = nc.getUdpNettyWorkThreadNum();

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

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

Expand Down
2 changes: 0 additions & 2 deletions framework/src/main/resources/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ node {

listen.port = 18888

connection.timeout = 2

fetchBlock.timeout = 200
# syncFetchBatchNum = 2000

Expand Down
8 changes: 0 additions & 8 deletions framework/src/test/java/org/tron/common/ParameterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,8 @@ public void testCommonParameter() {
assertFalse(parameter.isNodeDiscoveryPersist());
parameter.setNodeEffectiveCheckEnable(false);
assertFalse(parameter.isNodeEffectiveCheckEnable());
parameter.setNodeConnectionTimeout(500);
assertEquals(500, parameter.getNodeConnectionTimeout());
parameter.setFetchBlockTimeout(500);
assertEquals(500, parameter.getFetchBlockTimeout());
parameter.setNodeChannelReadTimeout(500);
assertEquals(500, parameter.getNodeChannelReadTimeout());
parameter.setMaxConnections(500);
assertEquals(500, parameter.getMaxConnections());
parameter.setMinConnections(500);
Expand Down Expand Up @@ -170,10 +166,6 @@ public void testCommonParameter() {
assertEquals(1, parameter.getAllowTvmSolidity059());
parameter.setForbidTransferToContract(1);
assertEquals(1, parameter.getForbidTransferToContract());
parameter.setTcpNettyWorkThreadNum(5);
assertEquals(5, parameter.getTcpNettyWorkThreadNum());
parameter.setUdpNettyWorkThreadNum(5);
assertEquals(5, parameter.getUdpNettyWorkThreadNum());
parameter.setTrustNodeAddr("address");
assertEquals("address", parameter.getTrustNodeAddr());
parameter.setWalletExtensionApi(false);
Expand Down
Loading
Loading