Skip to content

Commit 67fc14e

Browse files
authored
refactor(config): extract ConfigKey and remove testnet config (#6565)
1 parent 13b68ea commit 67fc14e

54 files changed

Lines changed: 1093 additions & 1047 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public class CommonParameter {
3232
@Parameter(names = {"-c", "--config"}, description = "Config file (default:config.conf)")
3333
public String shellConfFileName = "";
3434
@Getter
35+
@Setter
36+
public String configFilePath = "";
37+
@Getter
3538
@Parameter(names = {"-d", "--output-directory"},
3639
description = "Data directory for the databases (default:output-directory)")
3740
public String outputDirectory = "output-directory";

common/src/main/java/org/tron/core/Constant.java

Lines changed: 22 additions & 380 deletions
Large diffs are not rendered by default.

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

Lines changed: 456 additions & 456 deletions
Large diffs are not rendered by default.

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

Lines changed: 329 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.tron.core.config.args;
22

3-
import static org.apache.commons.lang3.StringUtils.isNoneBlank;
4-
53
import com.typesafe.config.Config;
64
import java.io.File;
75
import java.net.InetAddress;
@@ -15,7 +13,6 @@
1513
import org.springframework.stereotype.Component;
1614
import org.tron.common.es.ExecutorServiceManager;
1715
import org.tron.common.parameter.CommonParameter;
18-
import org.tron.core.Constant;
1916
import org.tron.core.config.Configuration;
2017
import org.tron.core.net.TronNetService;
2118

@@ -25,6 +22,7 @@
2522
public class DynamicArgs {
2623
private final CommonParameter parameter = Args.getInstance();
2724

25+
private File configFile;
2826
private long lastModified = 0;
2927

3028
private ScheduledExecutorService reloadExecutor;
@@ -36,11 +34,12 @@ public void init() {
3634
reloadExecutor = ExecutorServiceManager.newSingleThreadScheduledExecutor(esName);
3735
logger.info("Start the dynamic loading configuration service");
3836
long checkInterval = parameter.getDynamicConfigCheckInterval();
39-
File config = getConfigFile();
40-
if (config == null) {
37+
configFile = new File(parameter.getConfigFilePath());
38+
if (!configFile.exists()) {
39+
logger.warn("Configuration path is required! No such file {}", configFile);
4140
return;
4241
}
43-
lastModified = config.lastModified();
42+
lastModified = configFile.lastModified();
4443
reloadExecutor.scheduleWithFixedDelay(() -> {
4544
try {
4645
run();
@@ -52,36 +51,16 @@ public void init() {
5251
}
5352

5453
public void run() {
55-
File config = getConfigFile();
56-
if (config != null) {
57-
long lastModifiedTime = config.lastModified();
58-
if (lastModifiedTime > lastModified) {
59-
reload();
60-
lastModified = lastModifiedTime;
61-
}
62-
}
63-
}
64-
65-
private File getConfigFile() {
66-
String confFilePath;
67-
if (isNoneBlank(parameter.getShellConfFileName())) {
68-
confFilePath = parameter.getShellConfFileName();
69-
} else {
70-
confFilePath = Constant.NET_CONF;
71-
}
72-
73-
File confFile = new File(confFilePath);
74-
if (!confFile.exists()) {
75-
logger.warn("Configuration path is required! No such file {}", confFile);
76-
return null;
54+
long lastModifiedTime = configFile.lastModified();
55+
if (lastModifiedTime > lastModified) {
56+
reload();
57+
lastModified = lastModifiedTime;
7758
}
78-
return confFile;
7959
}
8060

8161
public void reload() {
8262
logger.debug("Reloading ... ");
83-
Config config = Configuration.getByFileName(parameter.getShellConfFileName(),
84-
Constant.NET_CONF);
63+
Config config = Configuration.getByFileName(parameter.getConfigFilePath(), null);
8564

8665
updateActiveNodes(config);
8766

@@ -90,7 +69,7 @@ public void reload() {
9069

9170
private void updateActiveNodes(Config config) {
9271
List<InetSocketAddress> newActiveNodes =
93-
Args.getInetSocketAddress(config, Constant.NODE_ACTIVE, true);
72+
Args.getInetSocketAddress(config, ConfigKey.NODE_ACTIVE, true);
9473
parameter.setActiveNodes(newActiveNodes);
9574
List<InetSocketAddress> activeNodes = TronNetService.getP2pConfig().getActiveNodes();
9675
activeNodes.clear();
@@ -100,7 +79,7 @@ private void updateActiveNodes(Config config) {
10079
}
10180

10281
private void updateTrustNodes(Config config) {
103-
List<InetAddress> newPassiveNodes = Args.getInetAddress(config, Constant.NODE_PASSIVE);
82+
List<InetAddress> newPassiveNodes = Args.getInetAddress(config, ConfigKey.NODE_PASSIVE);
10483
parameter.setPassiveNodes(newPassiveNodes);
10584
List<InetAddress> trustNodes = TronNetService.getP2pConfig().getTrustNodes();
10685
trustNodes.clear();

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.tron.common.utils.ByteArray;
1212
import org.tron.common.utils.Commons;
1313
import org.tron.common.utils.LocalWitnesses;
14-
import org.tron.core.Constant;
1514
import org.tron.core.exception.CipherException;
1615
import org.tron.core.exception.TronError;
1716
import org.tron.keystore.Credentials;
@@ -70,12 +69,12 @@ private boolean tryInitFromCommandLine() {
7069
}
7170

7271
private boolean tryInitFromConfig() {
73-
if (!config.hasPath(Constant.LOCAL_WITNESS) || config.getStringList(Constant.LOCAL_WITNESS)
72+
if (!config.hasPath(ConfigKey.LOCAL_WITNESS) || config.getStringList(ConfigKey.LOCAL_WITNESS)
7473
.isEmpty()) {
7574
return false;
7675
}
7776

78-
List<String> localWitness = config.getStringList(Constant.LOCAL_WITNESS);
77+
List<String> localWitness = config.getStringList(ConfigKey.LOCAL_WITNESS);
7978
this.localWitnesses.setPrivateKeys(localWitness);
8079
logger.debug("Got privateKey from config.conf");
8180
byte[] witnessAddress = getWitnessAddress();
@@ -85,12 +84,12 @@ private boolean tryInitFromConfig() {
8584
}
8685

8786
private void tryInitFromKeystore() {
88-
if (!config.hasPath(Constant.LOCAL_WITNESS_KEYSTORE)
89-
|| config.getStringList(Constant.LOCAL_WITNESS_KEYSTORE).isEmpty()) {
87+
if (!config.hasPath(ConfigKey.LOCAL_WITNESS_KEYSTORE)
88+
|| config.getStringList(ConfigKey.LOCAL_WITNESS_KEYSTORE).isEmpty()) {
9089
return;
9190
}
9291

93-
List<String> localWitness = config.getStringList(Constant.LOCAL_WITNESS_KEYSTORE);
92+
List<String> localWitness = config.getStringList(ConfigKey.LOCAL_WITNESS_KEYSTORE);
9493
if (localWitness.size() > 1) {
9594
logger.warn(
9695
"Multiple keystores detected. Only the first keystore will be used as witness, all "
@@ -127,7 +126,7 @@ private void tryInitFromKeystore() {
127126
}
128127

129128
private byte[] getWitnessAddress() {
130-
if (!config.hasPath(Constant.LOCAL_WITNESS_ACCOUNT_ADDRESS)) {
129+
if (!config.hasPath(ConfigKey.LOCAL_WITNESS_ACCOUNT_ADDRESS)) {
131130
return null;
132131
}
133132

@@ -137,7 +136,7 @@ private byte[] getWitnessAddress() {
137136
TronError.ErrCode.WITNESS_INIT);
138137
}
139138
byte[] witnessAddress = Commons
140-
.decodeFromBase58Check(config.getString(Constant.LOCAL_WITNESS_ACCOUNT_ADDRESS));
139+
.decodeFromBase58Check(config.getString(ConfigKey.LOCAL_WITNESS_ACCOUNT_ADDRESS));
141140
if (witnessAddress != null) {
142141
logger.debug("Got localWitnessAccountAddress from config.conf");
143142
} else {

framework/src/main/java/org/tron/program/FullNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.tron.common.log.LogService;
1010
import org.tron.common.parameter.CommonParameter;
1111
import org.tron.common.prometheus.Metrics;
12-
import org.tron.core.Constant;
1312
import org.tron.core.config.DefaultConfig;
1413
import org.tron.core.config.args.Args;
1514

@@ -21,7 +20,7 @@ public class FullNode {
2120
*/
2221
public static void main(String[] args) {
2322
ExitManager.initExceptionHandler();
24-
Args.setParam(args, Constant.NET_CONF);
23+
Args.setParam(args, "config.conf");
2524
CommonParameter parameter = Args.getInstance();
2625

2726
LogService.load(parameter.getLogbackPath());

framework/src/main/resources/config-backup.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
net {
2-
type = mainnet
3-
# type = testnet
2+
# type is deprecated and has no effect.
3+
# type = mainnet
44
}
55

66
storage {

framework/src/main/resources/config-beta.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
net {
2+
# type is deprecated and has no effect.
23
# type = mainnet
3-
type = testnet
44
}
55

66
storage {

framework/src/main/resources/config-localtest.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
net {
2-
type = mainnet
3-
# type = testnet
2+
# type is deprecated and has no effect.
3+
# type = mainnet
44
}
55

66
storage {

0 commit comments

Comments
 (0)