Skip to content

Commit 2fb5da8

Browse files
committed
refactor(config): add reference.conf and remove bean DEFAULTS
Add common/src/main/resources/reference.conf as the standard Typesafe Config default file, providing fallback values for all configuration parameters. This eliminates hardcoded DEFAULTS maps from bean classes and centralizes default values in a single, maintainable file. - Create reference.conf with full default configuration matching existing code behavior (gRPC defaults, committee zeros, etc.) - Remove DEFAULTS from all bean classes (VmConfig, BlockConfig, etc.) - Add withFallback(defaultReference()) in Configuration.java - Convert dot-notation fields to sub-beans in NodeConfig - Add index.directory/switch to reference.conf (legacy, unused) - Add storage.backup section to reference.conf - Update all bean tests to use withRef() helper with defaultReference() - Fix ArgsTest to include defaultReference() fallback
1 parent e5e8401 commit 2fb5da8

23 files changed

Lines changed: 1082 additions & 370 deletions

common/src/main/java/org/tron/core/config/Configuration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public static com.typesafe.config.Config getByFileName(
4848

4949
private static void resolveConfigFile(String fileName, File confFile) {
5050
if (confFile.exists()) {
51-
config = ConfigFactory.parseFile(confFile);
51+
config = ConfigFactory.parseFile(confFile)
52+
.withFallback(ConfigFactory.defaultReference());
5253
} else if (Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName)
5354
!= null) {
5455
config = ConfigFactory.load(fileName);

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import com.typesafe.config.Config;
99
import com.typesafe.config.ConfigBeanFactory;
10-
import com.typesafe.config.ConfigFactory;
1110
import lombok.Getter;
1211
import lombok.Setter;
1312
import lombok.extern.slf4j.Slf4j;
@@ -26,12 +25,7 @@ public class BlockConfig {
2625
private long proposalExpireTime = DEFAULT_PROPOSAL_EXPIRE_TIME;
2726
private int checkFrozenTime = 1;
2827

29-
private static final Config DEFAULTS = ConfigFactory.parseString(
30-
"needSyncCheck = false\n"
31-
+ "maintenanceTimeInterval = 21600000\n"
32-
+ "proposalExpireTime = " + DEFAULT_PROPOSAL_EXPIRE_TIME + "\n"
33-
+ "checkFrozenTime = 1\n"
34-
);
28+
// Defaults come from reference.conf (loaded globally via Configuration.java)
3529

3630
/**
3731
* Create BlockConfig from the "block" section of the application config.
@@ -44,9 +38,7 @@ public static BlockConfig fromConfig(Config config) {
4438
+ "config.conf, please set the value in block.proposalExpireTime.", PARAMETER_INIT);
4539
}
4640

47-
Config blockSection = config.hasPath("block")
48-
? config.getConfig("block").withFallback(DEFAULTS)
49-
: DEFAULTS;
41+
Config blockSection = config.getConfig("block");
5042
BlockConfig blockConfig = ConfigBeanFactory.create(blockSection, BlockConfig.class);
5143
blockConfig.postProcess();
5244
return blockConfig;

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

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.typesafe.config.Config;
44
import com.typesafe.config.ConfigBeanFactory;
5-
import com.typesafe.config.ConfigFactory;
65
import lombok.Getter;
76
import lombok.Setter;
87
import lombok.extern.slf4j.Slf4j;
@@ -84,57 +83,7 @@ public class CommitteeConfig {
8483

8584
// proposalExpireTime is NOT a committee field — it's in block.* and handled by BlockConfig
8685

87-
private static final Config DEFAULTS;
88-
89-
static {
90-
StringBuilder sb = new StringBuilder();
91-
sb.append("allowCreationOfContracts = 0\n");
92-
sb.append("allowMultiSign = 0\n");
93-
sb.append("allowAdaptiveEnergy = 0\n");
94-
sb.append("allowDelegateResource = 0\n");
95-
sb.append("allowSameTokenName = 0\n");
96-
sb.append("allowTvmTransferTrc10 = 0\n");
97-
sb.append("allowTvmConstantinople = 0\n");
98-
sb.append("allowTvmSolidity059 = 0\n");
99-
sb.append("forbidTransferToContract = 0\n");
100-
sb.append("allowShieldedTRC20Transaction = 0\n");
101-
sb.append("allowMarketTransaction = 0\n");
102-
sb.append("allowTransactionFeePool = 0\n");
103-
sb.append("allowBlackHoleOptimization = 0\n");
104-
sb.append("allowNewResourceModel = 0\n");
105-
sb.append("allowTvmIstanbul = 0\n");
106-
sb.append("allowProtoFilterNum = 0\n");
107-
sb.append("allowAccountStateRoot = 0\n");
108-
sb.append("changedDelegation = 0\n");
109-
sb.append("allowPBFT = 0\n");
110-
sb.append("pBFTExpireNum = 20\n");
111-
sb.append("allowTvmFreeze = 0\n");
112-
sb.append("allowTvmVote = 0\n");
113-
sb.append("allowTvmLondon = 0\n");
114-
sb.append("allowTvmCompatibleEvm = 0\n");
115-
sb.append("allowHigherLimitForMaxCpuTimeOfOneTx = 0\n");
116-
sb.append("allowNewRewardAlgorithm = 0\n");
117-
sb.append("allowOptimizedReturnValueOfChainId = 0\n");
118-
sb.append("allowTvmShangHai = 0\n");
119-
sb.append("allowOldRewardOpt = 0\n");
120-
sb.append("allowEnergyAdjustment = 0\n");
121-
sb.append("allowStrictMath = 0\n");
122-
sb.append("consensusLogicOptimization = 0\n");
123-
sb.append("allowTvmCancun = 0\n");
124-
sb.append("allowTvmBlob = 0\n");
125-
sb.append("unfreezeDelayDays = 0\n");
126-
sb.append("allowReceiptsMerkleRoot = 0\n");
127-
sb.append("allowAccountAssetOptimization = 0\n");
128-
sb.append("allowAssetOptimization = 0\n");
129-
sb.append("allowNewReward = 0\n");
130-
sb.append("memoFee = 0\n");
131-
sb.append("allowDelegateOptimization = 0\n");
132-
sb.append("allowDynamicEnergy = 0\n");
133-
sb.append("dynamicEnergyThreshold = 0\n");
134-
sb.append("dynamicEnergyIncreaseFactor = 0\n");
135-
sb.append("dynamicEnergyMaxFactor = 0\n");
136-
DEFAULTS = ConfigFactory.parseString(sb.toString());
137-
}
86+
// Defaults come from reference.conf (loaded globally via Configuration.java)
13887

13988
/**
14089
* Create CommitteeConfig from the "committee" section of the application config.
@@ -144,9 +93,7 @@ public class CommitteeConfig {
14493
* are excluded from automatic binding and handled manually after.
14594
*/
14695
public static CommitteeConfig fromConfig(Config config) {
147-
Config section = config.hasPath("committee")
148-
? config.getConfig("committee").withFallback(DEFAULTS)
149-
: DEFAULTS;
96+
Config section = config.getConfig("committee");
15097

15198
// ConfigBeanFactory derives key names from setter methods. For setPBFTExpireNum()
15299
// it expects "PBFTExpireNum" (capital P), but config.conf uses "pBFTExpireNum".

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,7 @@ public static class FilterConfig {
6868
private List<String> contractTopic = new ArrayList<>();
6969
}
7070

71-
private static final Config DEFAULTS = ConfigFactory.parseString(
72-
"enable = false\n"
73-
+ "version = 0\n"
74-
+ "startSyncBlockNum = 0\n"
75-
+ "path = \"\"\n"
76-
+ "server = \"\"\n"
77-
+ "dbconfig = \"\"\n"
78-
+ "contractParse = true\n"
79-
+ "native { useNativeQueue = true, bindport = 5555, sendqueuelength = 1000 }\n"
80-
+ "topics = []\n"
81-
+ "topicDefaults { triggerName = \"\", enable = false, topic = \"\","
82-
+ " solidified = false, ethCompatible = false, redundancy = false }\n"
83-
+ "filter { fromblock = \"\", toblock = \"\","
84-
+ " contractAddress = [\"\"], contractTopic = [\"\"] }\n"
85-
);
71+
// Defaults come from reference.conf (loaded globally via Configuration.java)
8672

8773
/**
8874
* Create EventConfig from the "event.subscribe" section of the application config.
@@ -91,9 +77,7 @@ public static class FilterConfig {
9177
* "nativeQueue" but config key is "native". We handle this manually after binding.
9278
*/
9379
public static EventConfig fromConfig(Config config) {
94-
Config section = config.hasPath("event.subscribe")
95-
? config.getConfig("event.subscribe").withFallback(DEFAULTS)
96-
: DEFAULTS;
80+
Config section = config.getConfig("event.subscribe");
9781

9882
// "native" is a Java reserved word, "topics" has optional fields per item —
9983
// strip both before binding, read manually

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.typesafe.config.Config;
44
import com.typesafe.config.ConfigBeanFactory;
5-
import com.typesafe.config.ConfigFactory;
65
import java.util.ArrayList;
76
import java.util.List;
87
import lombok.Getter;
@@ -42,18 +41,10 @@ public static class WitnessConfig {
4241
private long voteCount = 0;
4342
}
4443

45-
private static final Config DEFAULTS = ConfigFactory.parseString(
46-
"timestamp = \"\"\n"
47-
+ "parentHash = \"\"\n"
48-
+ "assets = []\n"
49-
+ "witnesses = []\n"
50-
);
44+
// Defaults come from reference.conf (loaded globally via Configuration.java)
5145

5246
public static GenesisConfig fromConfig(Config config) {
53-
if (!config.hasPath("genesis.block")) {
54-
return new GenesisConfig();
55-
}
56-
Config section = config.getConfig("genesis.block").withFallback(DEFAULTS);
47+
Config section = config.getConfig("genesis.block");
5748
return ConfigBeanFactory.create(section, GenesisConfig.class);
5849
}
5950
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.typesafe.config.Config;
44
import com.typesafe.config.ConfigBeanFactory;
5-
import com.typesafe.config.ConfigFactory;
65
import lombok.Getter;
76
import lombok.Setter;
87
import lombok.extern.slf4j.Slf4j;
@@ -36,20 +35,13 @@ public static class InfluxDbConfig {
3635
private int metricsReportInterval = 10;
3736
}
3837

39-
private static final Config DEFAULTS = ConfigFactory.parseString(
40-
"storageEnable = false\n"
41-
+ "prometheus { enable = false, port = 9527 }\n"
42-
+ "influxdb { ip = \"\", port = 8086, database = metrics,"
43-
+ " metricsReportInterval = 10 }\n"
44-
);
38+
// Defaults come from reference.conf (loaded globally via Configuration.java)
4539

4640
/**
4741
* Create MetricsConfig from the "node.metrics" section of the application config.
4842
*/
4943
public static MetricsConfig fromConfig(Config config) {
50-
Config section = config.hasPath("node.metrics")
51-
? config.getConfig("node.metrics").withFallback(DEFAULTS)
52-
: DEFAULTS;
44+
Config section = config.getConfig("node.metrics");
5345
return ConfigBeanFactory.create(section, MetricsConfig.class);
5446
}
5547
}

0 commit comments

Comments
 (0)