Skip to content

Commit 8a76db8

Browse files
committed
fix(config): align reference.conf defaults with develop runtime fallbacks
Address review feedback from 317787106 (2026-04-16) and lxcmyf (2026-04-17) covering silent default-value drift introduced by the new reference.conf. Verified each drift against develop Args.initRocksDbSettings / applyConfigParams runtime fallbacks. reference.conf: - storage.dbSettings.compactThreads: 32 -> 0 (0 = auto: max(availableProcessors, 1)) - storage.dbSettings.blocksize: 64 -> 16 - storage.dbSettings.level0FileNumCompactionTrigger: 4 -> 2 - storage.dbSettings.targetFileSizeBase: 256 -> 64 - node.trustNode: "127.0.0.1:50051" -> "" (Args bridge converts empty -> null) - node.maxActiveNodesWithSameIp: line removed. Shipping the legacy alias in reference.conf caused HOCON merges to always mask user-supplied maxConnectionsWithSameIp via the alias-fallback branch. - node.validContractProto.threads: 2 -> 0 (0 = auto: availableProcessors) StorageConfig.java: - DbSettingsConfig field defaults mirror reference.conf - DbSettingsConfig.postProcess() expands compactThreads == 0 to max(availableProcessors, 1), matching develop Args.java:1609-1611 NodeConfig.java: - ValidContractProtoConfig.threads default: 2 -> 0 - postProcess() expands validContractProto.threads == 0 to availableProcessors(), matching develop Args.java:743-746 - Removed unused field maxActiveNodesWithSameIp. The alias read at fromConfig() uses section.hasPath() directly, and removing the bean field lets ConfigBeanFactory stop requiring a reference.conf default for it (which is what caused the alias pollution to begin with). Tests: - StorageConfigTest.testDbSettingsDefaults asserts the new fallbacks - StorageConfigTest: testCompactThreadsAutoExpand / testCompactThreadsExplicitPreserved - NodeConfigTest: testValidContractProtoThreadsDefaultAutoExpands / testValidContractProtoThreadsExplicitPreserved - NodeConfigTest: testTrustNodeNotDefaultedByReferenceConf - NodeConfigTest: testMaxConnectionsWithSameIpNotOverriddenByReferenceConfAlias - NodeConfigTest: testMaxActiveNodesWithSameIpLegacyAliasStillWorks - NodeConfigTest: testLegacyAliasTakesPriorityOverModernKey (matches develop Args.java:392-399)
1 parent 1292373 commit 8a76db8

5 files changed

Lines changed: 118 additions & 20 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ public class NodeConfig {
8989
private double activeConnectFactor = 0.1;
9090
private double connectFactor = 0.6;
9191
private double disconnectNumberFactor = 0.4;
92-
private int maxActiveNodesWithSameIp = 2;
92+
// Legacy alias `maxActiveNodesWithSameIp` has no bean field: we only peek at it via
93+
// section.hasPath() below. Keeping it field-less means reference.conf doesn't have to
94+
// ship a default that would otherwise mask the modern `maxConnectionsWithSameIp` key.
9395

9496
// ---- Sub-beans matching config's dot-notation nested structure ----
9597
private ListenConfig listen = new ListenConfig();
@@ -180,7 +182,7 @@ public static class ReadConfig {
180182
@Getter
181183
@Setter
182184
public static class ValidContractProtoConfig {
183-
private int threads = 2;
185+
private int threads = 0; // 0 = auto (availableProcessors)
184186
}
185187

186188
@Getter
@@ -428,6 +430,11 @@ private void postProcess() {
428430
solidity.threads = Runtime.getRuntime().availableProcessors();
429431
}
430432

433+
// validContractProto.threads: 0 = auto-detect (matches develop Args.java:743-746)
434+
if (validContractProto.threads == 0) {
435+
validContractProto.threads = Runtime.getRuntime().availableProcessors();
436+
}
437+
431438
// syncFetchBatchNum: clamp to [100, 2000]
432439
if (syncFetchBatchNum > 2000) {
433440
syncFetchBatchNum = 2000;

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,21 @@ public void setSwitch(String v) {
111111
@Setter
112112
public static class DbSettingsConfig {
113113
private int levelNumber = 7;
114-
private int compactThreads = 32;
115-
private int blocksize = 64;
114+
private int compactThreads = 0; // 0 = auto: max(availableProcessors, 1)
115+
private int blocksize = 16;
116116
private long maxBytesForLevelBase = 256;
117117
private double maxBytesForLevelMultiplier = 10;
118-
private int level0FileNumCompactionTrigger = 4;
119-
private long targetFileSizeBase = 256;
118+
private int level0FileNumCompactionTrigger = 2;
119+
private long targetFileSizeBase = 64;
120120
private int targetFileSizeMultiplier = 1;
121121
private int maxOpenFiles = 5000;
122+
123+
// Expand 0 → auto-detected processor count. Mirrors develop Args.java:1609-1611.
124+
void postProcess() {
125+
if (compactThreads == 0) {
126+
compactThreads = Math.max(Runtime.getRuntime().availableProcessors(), 1);
127+
}
128+
}
122129
}
123130

124131
@Getter
@@ -190,6 +197,8 @@ public static StorageConfig fromConfig(Config config) {
190197
sc.defaultDbOption = readDbOption(section, "default");
191198
sc.defaultMDbOption = readDbOption(section, "defaultM");
192199
sc.defaultLDbOption = readDbOption(section, "defaultL");
200+
201+
sc.dbSettings.postProcess();
193202
return sc;
194203
}
195204

common/src/main/resources/reference.conf

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ storage {
9595
# Strongly recommend NOT modifying unless you know every item's meaning clearly.
9696
dbSettings = {
9797
levelNumber = 7
98-
compactThreads = 32
99-
blocksize = 64 // n * KB
98+
compactThreads = 0 // 0 = auto: max(availableProcessors, 1)
99+
blocksize = 16 // n * KB
100100
maxBytesForLevelBase = 256 // n * MB
101101
maxBytesForLevelMultiplier = 10
102-
level0FileNumCompactionTrigger = 4
103-
targetFileSizeBase = 256 // n * MB
102+
level0FileNumCompactionTrigger = 2
103+
targetFileSizeBase = 64 // n * MB
104104
targetFileSizeMultiplier = 1
105105
maxOpenFiles = 5000
106106
}
@@ -188,9 +188,10 @@ node.metrics = {
188188
}
189189

190190
node {
191-
# Trust node for solidity node
192-
# trustNode = "ip:port"
193-
trustNode = "127.0.0.1:50051"
191+
# Trust node for solidity node (example: "127.0.0.1:50051").
192+
# Empty string here = "not configured"; Args.java bridge converts "" → null so the
193+
# runtime behavior matches develop (trustNodeAddr is null unless user sets the key).
194+
trustNode = ""
194195

195196
# Expose extension api to public or not
196197
walletExtensionApi = false
@@ -235,7 +236,9 @@ node {
235236
activeConnectFactor = 0.1
236237
connectFactor = 0.6
237238
disconnectNumberFactor = 0.4
238-
maxActiveNodesWithSameIp = 2
239+
# Legacy alias `maxActiveNodesWithSameIp` is still accepted from user config
240+
# (see NodeConfig alias-fallback) but is intentionally NOT defaulted here —
241+
# shipping it in reference.conf would always mask the modern `maxConnectionsWithSameIp`.
239242
channel.read.timeout = 0
240243
metricsEnable = false
241244

@@ -357,8 +360,8 @@ node {
357360
zenTokenId = "000000"
358361
shieldedTransInPendingMaxCounts = 10
359362

360-
# Contract proto validation thread pool
361-
validContractProto.threads = 2
363+
# Contract proto validation thread pool (0 = auto: availableProcessors)
364+
validContractProto.threads = 0
362365

363366
dns {
364367
treeUrls = [

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,61 @@ public void testMaxFastForwardNumBoundaryValues() {
225225
assertEquals(4, NodeConfig.fromConfig(
226226
withRef("node { maxFastForwardNum = 4 }")).getMaxFastForwardNum());
227227
}
228+
229+
// ----- validContractProto.threads: 0 = auto (availableProcessors) -----
230+
231+
@Test
232+
public void testValidContractProtoThreadsDefaultAutoExpands() {
233+
// Default in reference.conf is 0; postProcess must expand to availableProcessors.
234+
// Matches develop Args.java:743-746 runtime fallback.
235+
NodeConfig nc = NodeConfig.fromConfig(withRef());
236+
assertEquals(Runtime.getRuntime().availableProcessors(),
237+
nc.getValidContractProtoThreads());
238+
}
239+
240+
@Test
241+
public void testValidContractProtoThreadsExplicitPreserved() {
242+
NodeConfig nc = NodeConfig.fromConfig(
243+
withRef("node { validContractProto { threads = 3 } }"));
244+
assertEquals(3, nc.getValidContractProtoThreads());
245+
}
246+
247+
// ----- trustNode: empty reference.conf default means trustNode stays unset -----
248+
249+
@Test
250+
public void testTrustNodeNotDefaultedByReferenceConf() {
251+
// reference.conf intentionally omits `node.trustNode` so that empty configs
252+
// preserve develop's behavior (trustNodeAddr stays null in the Args bridge).
253+
NodeConfig nc = NodeConfig.fromConfig(withRef());
254+
assertTrue(nc.getTrustNode() == null || nc.getTrustNode().isEmpty());
255+
}
256+
257+
// ----- maxConnectionsWithSameIp alias: reference.conf must not poison merge -----
258+
259+
@Test
260+
public void testMaxConnectionsWithSameIpNotOverriddenByReferenceConfAlias() {
261+
// reference.conf must NOT ship `maxActiveNodesWithSameIp`, otherwise the alias-
262+
// fallback branch would silently clobber the user's modern key. Regression guard
263+
// for review #2 (317787106, 2026-04-16).
264+
NodeConfig nc = NodeConfig.fromConfig(
265+
withRef("node { maxConnectionsWithSameIp = 10 }"));
266+
assertEquals(10, nc.getMaxConnectionsWithSameIp());
267+
}
268+
269+
@Test
270+
public void testMaxActiveNodesWithSameIpLegacyAliasStillWorks() {
271+
// Back-compat: users who still write the legacy key in their config.conf
272+
// must get their value routed to maxConnectionsWithSameIp.
273+
NodeConfig nc = NodeConfig.fromConfig(
274+
withRef("node { maxActiveNodesWithSameIp = 5 }"));
275+
assertEquals(5, nc.getMaxConnectionsWithSameIp());
276+
}
277+
278+
@Test
279+
public void testLegacyAliasTakesPriorityOverModernKey() {
280+
// Matches develop Args.java:392-399: if the legacy key is present, it wins.
281+
NodeConfig nc = NodeConfig.fromConfig(
282+
withRef("node { maxActiveNodesWithSameIp = 5, maxConnectionsWithSameIp = 10 }"));
283+
assertEquals(5, nc.getMaxConnectionsWithSameIp());
284+
}
228285
}

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,42 @@ public void testCheckpointDefaults() {
5959

6060
@Test
6161
public void testDbSettingsDefaults() {
62+
// These defaults must match develop's Args.initRocksDbSettings() fallbacks so that
63+
// nodes with minimal configs retain the same RocksDB tuning. See
64+
// docs/plans/2026-04-21-001-fix-reference-conf-default-drift.md.
6265
Config empty = withRef();
6366
StorageConfig sc = StorageConfig.fromConfig(empty);
6467
StorageConfig.DbSettingsConfig ds = sc.getDbSettings();
6568
assertEquals(7, ds.getLevelNumber());
66-
assertEquals(32, ds.getCompactThreads());
67-
assertEquals(64, ds.getBlocksize());
69+
// compactThreads default is 0 in reference.conf, auto-expanded by postProcess()
70+
assertEquals(Math.max(Runtime.getRuntime().availableProcessors(), 1),
71+
ds.getCompactThreads());
72+
assertEquals(16, ds.getBlocksize());
6873
assertEquals(256, ds.getMaxBytesForLevelBase());
6974
assertEquals(10, ds.getMaxBytesForLevelMultiplier(), 0.01);
70-
assertEquals(4, ds.getLevel0FileNumCompactionTrigger());
71-
assertEquals(256, ds.getTargetFileSizeBase());
75+
assertEquals(2, ds.getLevel0FileNumCompactionTrigger());
76+
assertEquals(64, ds.getTargetFileSizeBase());
7277
assertEquals(1, ds.getTargetFileSizeMultiplier());
7378
assertEquals(5000, ds.getMaxOpenFiles());
7479
}
7580

81+
@Test
82+
public void testCompactThreadsAutoExpand() {
83+
// compactThreads = 0 must be auto-expanded to availableProcessors (min 1)
84+
Config config = withRef("storage { dbSettings { compactThreads = 0 } }");
85+
StorageConfig sc = StorageConfig.fromConfig(config);
86+
assertEquals(Math.max(Runtime.getRuntime().availableProcessors(), 1),
87+
sc.getDbSettings().getCompactThreads());
88+
}
89+
90+
@Test
91+
public void testCompactThreadsExplicitPreserved() {
92+
// Non-zero compactThreads must be passed through untouched
93+
Config config = withRef("storage { dbSettings { compactThreads = 7 } }");
94+
StorageConfig sc = StorageConfig.fromConfig(config);
95+
assertEquals(7, sc.getDbSettings().getCompactThreads());
96+
}
97+
7698
@Test
7799
public void testBalanceHistoryLookup() {
78100
Config config = withRef(

0 commit comments

Comments
 (0)