Skip to content

Commit 953651d

Browse files
committed
optimize external.ip
1 parent b70fccc commit 953651d

2 files changed

Lines changed: 57 additions & 25 deletions

File tree

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

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ public static CommitteeConfig fromConfig(Config config) {
8282
private static Config normalizeNonStandardKeys(Config section) {
8383
if (section.hasPath("allowPBFT")) {
8484
ConfigValue v = section.getValue("allowPBFT");
85-
section = section.withValue("allowPbft", v);
85+
section = section.withValue("allowPbft", v); // rename allowPBFT -> allowPbft
8686
}
8787
if (section.hasPath("pBFTExpireNum")) {
8888
ConfigValue v = section.getValue("pBFTExpireNum");
89-
section = section.withValue("pbftExpireNum", v);
89+
section = section.withValue("pbftExpireNum", v); // rename pBFTExpireNum -> pbftExpireNum
9090
}
9191
return section;
9292
}
@@ -101,35 +101,61 @@ private void postProcess() {
101101
}
102102

103103
// clamp allowDelegateOptimization to 0-1
104-
if (allowDelegateOptimization < 0) { allowDelegateOptimization = 0; }
105-
if (allowDelegateOptimization > 1) { allowDelegateOptimization = 1; }
104+
if (allowDelegateOptimization < 0) {
105+
allowDelegateOptimization = 0;
106+
}
107+
if (allowDelegateOptimization > 1) {
108+
allowDelegateOptimization = 1;
109+
}
106110

107111
// clamp allowDynamicEnergy to 0-1
108-
if (allowDynamicEnergy < 0) { allowDynamicEnergy = 0; }
109-
if (allowDynamicEnergy > 1) { allowDynamicEnergy = 1; }
112+
if (allowDynamicEnergy < 0) {
113+
allowDynamicEnergy = 0;
114+
}
115+
if (allowDynamicEnergy > 1) {
116+
allowDynamicEnergy = 1;
117+
}
110118

111119
// clamp dynamicEnergyThreshold to 0-100_000_000_000_000_000
112-
if (dynamicEnergyThreshold < 0) { dynamicEnergyThreshold = 0; }
120+
if (dynamicEnergyThreshold < 0) {
121+
dynamicEnergyThreshold = 0;
122+
}
113123
if (dynamicEnergyThreshold > 100_000_000_000_000_000L) {
114124
dynamicEnergyThreshold = 100_000_000_000_000_000L;
115125
}
116126

117127
// clamp dynamicEnergyIncreaseFactor to 0-10_000
118-
if (dynamicEnergyIncreaseFactor < 0) { dynamicEnergyIncreaseFactor = 0; }
119-
if (dynamicEnergyIncreaseFactor > 10_000L) { dynamicEnergyIncreaseFactor = 10_000L; }
128+
if (dynamicEnergyIncreaseFactor < 0) {
129+
dynamicEnergyIncreaseFactor = 0;
130+
}
131+
if (dynamicEnergyIncreaseFactor > 10_000L) {
132+
dynamicEnergyIncreaseFactor = 10_000L;
133+
}
120134

121135
// clamp dynamicEnergyMaxFactor to 0-100_000
122-
if (dynamicEnergyMaxFactor < 0) { dynamicEnergyMaxFactor = 0; }
123-
if (dynamicEnergyMaxFactor > 100_000L) { dynamicEnergyMaxFactor = 100_000L; }
136+
if (dynamicEnergyMaxFactor < 0) {
137+
dynamicEnergyMaxFactor = 0;
138+
}
139+
if (dynamicEnergyMaxFactor > 100_000L) {
140+
dynamicEnergyMaxFactor = 100_000L;
141+
}
124142

125143
// clamp allowNewReward to 0-1 (must run BEFORE the cross-field check below,
126144
// which depends on allowNewReward != 1)
127-
if (allowNewReward < 0) { allowNewReward = 0; }
128-
if (allowNewReward > 1) { allowNewReward = 1; }
145+
if (allowNewReward < 0) {
146+
allowNewReward = 0;
147+
}
148+
if (allowNewReward > 1) {
149+
allowNewReward = 1;
150+
}
129151

130152
// clamp memoFee to 0-1_000_000_000
131-
if (memoFee < 0) { memoFee = 0; }
132-
if (memoFee > 1_000_000_000L) { memoFee = 1_000_000_000L; }
153+
if (memoFee < 0) {
154+
memoFee = 0;
155+
}
156+
if (memoFee > 1_000_000_000L) {
157+
memoFee = 1_000_000_000L;
158+
}
133159

134160
// cross-field: allowOldRewardOpt requires at least one reward/vote flag
135161
if (allowOldRewardOpt == 1 && allowNewRewardAlgorithm != 1

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ public class NodeConfig {
4343

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

5047
// node.shutdown.* uses PascalCase nested keys (shutdown.BlockTime, etc.).
5148
// These are optional (not in reference.conf), so @Setter(NONE) prevents ConfigBeanFactory
@@ -66,7 +63,7 @@ public boolean isDiscoveryPersist() {
6663
}
6764

6865
public String getDiscoveryExternalIp() {
69-
return externalIP;
66+
return discovery.getExternal().getIp();
7067
}
7168

7269
private int inactiveThreshold = 600;
@@ -148,6 +145,14 @@ public static class DiscoveryConfig {
148145

149146
private boolean enable = false;
150147
private boolean persist = false;
148+
private ExternalConfig external = new ExternalConfig();
149+
150+
@Getter
151+
@Setter
152+
public static class ExternalConfig {
153+
154+
private String ip = "";
155+
}
151156
}
152157

153158
@Getter
@@ -314,11 +319,6 @@ public static NodeConfig fromConfig(Config config) {
314319
nc.maxConnectionsWithSameIp = section.getInt("maxActiveNodesWithSameIp");
315320
}
316321

317-
nc.externalIP = getString(section, "discovery.external.ip", "");
318-
if ("null".equalsIgnoreCase(nc.externalIP)) {
319-
nc.externalIP = "";
320-
}
321-
322322
// Legacy key fallback: node.fullNodeAllowShieldedTransaction -> allowShieldedTransactionApi.
323323
if (section.hasPath("allowShieldedTransactionApi")) {
324324
nc.allowShieldedTransactionApi =
@@ -449,13 +449,19 @@ private static String getString(Config config, String path, String defaultValue)
449449

450450
/**
451451
* "isOpenFullTcpDisconnect" config key has an "is" prefix that the JavaBean Introspector
452-
* strips from boolean getter names, so the derived property is "openFullTcpDisconnect"
452+
* strips from boolean getter names, so the derived property is "openFullTcpDisconnect".
453+
* "discovery.external.ip" may be HOCON null or the string "null"; both normalize to "".
453454
*/
454455
private static Config normalizeNonStandardKeys(Config section) {
455456
if (section.hasPath("isOpenFullTcpDisconnect")) {
456457
section = section.withValue("openFullTcpDisconnect",
457458
section.getValue("isOpenFullTcpDisconnect"));
458459
}
460+
String externalIpPath = "discovery.external.ip";
461+
if (section.getIsNull(externalIpPath)
462+
|| "null".equalsIgnoreCase(section.getString(externalIpPath))) {
463+
section = section.withValue(externalIpPath, ConfigValueFactory.fromAnyRef(""));
464+
}
459465
return section;
460466
}
461467

0 commit comments

Comments
 (0)