Skip to content

Commit ef3f792

Browse files
authored
fix(config): deprecate CLI params and add guardrails (#6580)
1 parent 84362f1 commit ef3f792

File tree

6 files changed

+142
-5
lines changed

6 files changed

+142
-5
lines changed

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

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static org.tron.core.Constant.DEFAULT_PROPOSAL_EXPIRE_TIME;
88
import static org.tron.core.Constant.DYNAMIC_ENERGY_INCREASE_FACTOR_RANGE;
99
import static org.tron.core.Constant.DYNAMIC_ENERGY_MAX_FACTOR_RANGE;
10+
import static org.tron.core.Constant.ENERGY_LIMIT_IN_CONSTANT_TX;
1011
import static org.tron.core.Constant.MAX_PROPOSAL_EXPIRE_TIME;
1112
import static org.tron.core.Constant.MIN_PROPOSAL_EXPIRE_TIME;
1213
import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCE_TIMEOUT_PERCENT;
@@ -83,6 +84,40 @@
8384
@Component
8485
public class Args extends CommonParameter {
8586

87+
/**
88+
* Maps deprecated CLI option names to their config-file equivalents.
89+
* Options not in this map have no config equivalent and are being removed entirely.
90+
*/
91+
private static final Map<String, String> DEPRECATED_CLI_TO_CONFIG;
92+
93+
static {
94+
Map<String, String> m = new HashMap<>();
95+
m.put("--storage-db-directory", "storage.db.directory");
96+
m.put("--storage-db-engine", "storage.db.engine");
97+
m.put("--storage-db-synchronous", "storage.db.sync");
98+
m.put("--storage-index-directory", "storage.index.directory");
99+
m.put("--storage-index-switch", "storage.index.switch");
100+
m.put("--storage-transactionHistory-switch", "storage.transHistory.switch");
101+
m.put("--contract-parse-enable", "event.subscribe.contractParse");
102+
m.put("--support-constant", "vm.supportConstant");
103+
m.put("--max-energy-limit-for-constant", "vm.maxEnergyLimitForConstant");
104+
m.put("--lru-cache-size", "vm.lruCacheSize");
105+
m.put("--min-time-ratio", "vm.minTimeRatio");
106+
m.put("--max-time-ratio", "vm.maxTimeRatio");
107+
m.put("--save-internaltx", "vm.saveInternalTx");
108+
m.put("--save-featured-internaltx", "vm.saveFeaturedInternalTx");
109+
m.put("--save-cancel-all-unfreeze-v2-details", "vm.saveCancelAllUnfreezeV2Details");
110+
m.put("--long-running-time", "vm.longRunningTime");
111+
m.put("--max-connect-number", "node.maxHttpConnectNumber");
112+
m.put("--rpc-thread", "node.rpc.thread");
113+
m.put("--solidity-thread", "node.solidity.threads");
114+
m.put("--validate-sign-thread", "node.validateSignThreadNum");
115+
m.put("--trust-node", "node.trustNode");
116+
m.put("--history-balance-lookup", "storage.balance.history.lookup");
117+
m.put("--es", "event.subscribe.enable");
118+
DEPRECATED_CLI_TO_CONFIG = Collections.unmodifiableMap(m);
119+
}
120+
86121
@Getter
87122
private static String configFilePath = "";
88123

@@ -169,7 +204,7 @@ public static void applyConfigParams(
169204

170205
if (config.hasPath(ConfigKey.VM_MAX_ENERGY_LIMIT_FOR_CONSTANT)) {
171206
long configLimit = config.getLong(ConfigKey.VM_MAX_ENERGY_LIMIT_FOR_CONSTANT);
172-
PARAMETER.maxEnergyLimitForConstant = max(3_000_000L, configLimit, true);
207+
PARAMETER.maxEnergyLimitForConstant = max(ENERGY_LIMIT_IN_CONSTANT_TX, configLimit, true);
173208
}
174209

175210
if (config.hasPath(ConfigKey.VM_LRU_CACHE_SIZE)) {
@@ -678,6 +713,9 @@ public static void applyConfigParams(
678713
PARAMETER.eventFilter =
679714
config.hasPath(ConfigKey.EVENT_SUBSCRIBE_FILTER) ? getEventFilter(config) : null;
680715

716+
PARAMETER.eventSubscribe = config.hasPath(ConfigKey.EVENT_SUBSCRIBE_ENABLE)
717+
&& config.getBoolean(ConfigKey.EVENT_SUBSCRIBE_ENABLE);
718+
681719
if (config.hasPath(ConfigKey.ALLOW_SHIELDED_TRANSACTION_API)) {
682720
PARAMETER.allowShieldedTransactionApi =
683721
config.getBoolean(ConfigKey.ALLOW_SHIELDED_TRANSACTION_API);
@@ -1012,6 +1050,28 @@ private static void applyCLIParams(CLIParameter cmd, JCommander jc) {
10121050
.map(ParameterDescription::getLongestName)
10131051
.collect(Collectors.toSet());
10141052

1053+
jc.getParameters().stream()
1054+
.filter(ParameterDescription::isAssigned)
1055+
.filter(pd -> {
1056+
try {
1057+
return CLIParameter.class.getDeclaredField(pd.getParameterized().getName())
1058+
.isAnnotationPresent(Deprecated.class);
1059+
} catch (NoSuchFieldException e) {
1060+
return false;
1061+
}
1062+
})
1063+
.forEach(pd -> {
1064+
String cliOption = pd.getLongestName();
1065+
String configKey = DEPRECATED_CLI_TO_CONFIG.get(cliOption);
1066+
if (configKey != null) {
1067+
logger.warn("CLI option '{}' is deprecated and will be removed in a future release."
1068+
+ " Please use config key '{}' instead.", cliOption, configKey);
1069+
} else {
1070+
logger.warn("CLI option '{}' is deprecated and will be removed in a future release.",
1071+
cliOption);
1072+
}
1073+
});
1074+
10151075
if (assigned.contains("--output-directory")) {
10161076
PARAMETER.outputDirectory = cmd.outputDirectory;
10171077
}
@@ -1022,7 +1082,8 @@ private static void applyCLIParams(CLIParameter cmd, JCommander jc) {
10221082
PARAMETER.supportConstant = cmd.supportConstant;
10231083
}
10241084
if (assigned.contains("--max-energy-limit-for-constant")) {
1025-
PARAMETER.maxEnergyLimitForConstant = cmd.maxEnergyLimitForConstant;
1085+
PARAMETER.maxEnergyLimitForConstant = max(ENERGY_LIMIT_IN_CONSTANT_TX,
1086+
cmd.maxEnergyLimitForConstant, true);
10261087
}
10271088
if (assigned.contains("--lru-cache-size")) {
10281089
PARAMETER.lruCacheSize = cmd.lruCacheSize;
@@ -1105,7 +1166,12 @@ private static void applyCLIParams(CLIParameter cmd, JCommander jc) {
11051166
if (assigned.contains("--log-config")) {
11061167
PARAMETER.logbackPath = cmd.logbackPath;
11071168
}
1169+
// seedNodes is a JCommander positional (main) parameter, which does not support
1170+
// isAssigned(). An empty-check is used instead — this is safe because the default
1171+
// is an empty list, so non-empty means the user explicitly passed values on CLI.
11081172
if (!cmd.seedNodes.isEmpty()) {
1173+
logger.warn("Positional seed-node arguments are deprecated. "
1174+
+ "Please use seed.node.ip.list in the config file instead.");
11091175
List<InetSocketAddress> seeds = new ArrayList<>();
11101176
for (String s : cmd.seedNodes) {
11111177
seeds.add(NetUtil.parseInetSocketAddress(s));
@@ -1691,6 +1757,9 @@ public static void printHelp(JCommander jCommander) {
16911757
jCommander.getProgramName();
16921758
helpStr.append(String.format("%nUsage: java -jar %s [options] [seedNode <seedNode> ...]%n",
16931759
programName));
1760+
helpStr.append(String.format(
1761+
"%nNote: Positional seedNode arguments are deprecated."
1762+
+ " Use seed.node.ip.list in the config file instead.%n"));
16941763
helpStr.append(String.format("%nVERSION: %n%s-%s%n", Version.getVersion(),
16951764
getCommitIdAbbrev()));
16961765

@@ -1712,9 +1781,21 @@ public static void printHelp(JCommander jCommander) {
17121781
logger.warn("Miss option:{}", option);
17131782
continue;
17141783
}
1784+
boolean isDeprecated;
1785+
try {
1786+
isDeprecated = CLIParameter.class.getDeclaredField(
1787+
parameterDescription.getParameterized().getName())
1788+
.isAnnotationPresent(Deprecated.class);
1789+
} catch (NoSuchFieldException e) {
1790+
isDeprecated = false;
1791+
}
1792+
String desc = upperFirst(parameterDescription.getDescription());
1793+
if (isDeprecated) {
1794+
desc += " (deprecated)";
1795+
}
17151796
String tmpOptionDesc = String.format("%s\t\t\t%s%n",
17161797
Strings.padEnd(parameterDescription.getNames(), optionMaxLength, ' '),
1717-
upperFirst(parameterDescription.getDescription()));
1798+
desc);
17181799
helpStr.append(tmpOptionDesc);
17191800
}
17201801
}

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
* Fields here have NO default values — defaults live in CommonParameter.
1111
* JCommander only populates fields that are explicitly passed on the
1212
* command line.
13+
*
14+
* <p>Parameters marked {@code @Deprecated} are scheduled for removal.
15+
* Use the corresponding config-file options instead.</p>
1316
*/
1417
@NoArgsConstructor
1518
public class CLIParameter {
@@ -50,57 +53,70 @@ public class CLIParameter {
5053
@Parameter(names = {"--keystore-factory"}, description = "running KeystoreFactory")
5154
public boolean keystoreFactory;
5255

56+
@Deprecated
5357
@Parameter(names = {"--fast-forward"})
5458
public boolean fastForward;
5559

60+
@Deprecated
5661
@Parameter(names = {"--es"}, description = "Start event subscribe server")
5762
public boolean eventSubscribe;
5863

5964
@Parameter(names = {"--p2p-disable"}, description = "Switch for p2p module initialization. "
6065
+ "(default: false)", arity = 1)
6166
public boolean p2pDisable;
6267

68+
@Deprecated
6369
@Parameter(description = "--seed-nodes")
6470
public List<String> seedNodes = new ArrayList<>();
6571

66-
// -- Storage parameters --
72+
// -- Storage parameters (deprecated, use config file instead) --
6773

74+
@Deprecated
6875
@Parameter(names = {"--storage-db-directory"}, description = "Storage db directory")
6976
public String storageDbDirectory;
7077

78+
@Deprecated
7179
@Parameter(names = {"--storage-db-engine"},
7280
description = "Storage db engine.(leveldb or rocksdb)")
7381
public String storageDbEngine;
7482

83+
@Deprecated
7584
@Parameter(names = {"--storage-db-synchronous"},
7685
description = "Storage db is synchronous or not.(true or false)")
7786
public String storageDbSynchronous;
7887

88+
@Deprecated
7989
@Parameter(names = {"--storage-index-directory"}, description = "Storage index directory")
8090
public String storageIndexDirectory;
8191

92+
@Deprecated
8293
@Parameter(names = {"--storage-index-switch"},
8394
description = "Storage index switch.(on or off)")
8495
public String storageIndexSwitch;
8596

97+
@Deprecated
8698
@Parameter(names = {"--storage-transactionHistory-switch"},
8799
description = "Storage transaction history switch.(on or off)")
88100
public String storageTransactionHistorySwitch;
89101

102+
@Deprecated
90103
@Parameter(names = {"--contract-parse-enable"}, description = "Switch for contract parses in "
91104
+ "java-tron. (default: true)")
92105
public String contractParseEnable;
93106

94-
// -- Runtime parameters --
107+
// -- Runtime parameters (deprecated except --debug, use config file instead) --
95108

109+
@Deprecated
96110
@Parameter(names = {"--support-constant"}, description = "Support constant calling for TVM. "
97111
+ "(default: false)")
98112
public boolean supportConstant;
99113

114+
@Deprecated
100115
@Parameter(names = {"--max-energy-limit-for-constant"},
101116
description = "Max energy limit for constant calling. (default: 100,000,000)")
102117
public long maxEnergyLimitForConstant;
103118

119+
@Deprecated
104120
@Parameter(names = {"--lru-cache-size"}, description = "Max LRU size for caching bytecode and "
105121
+ "result of JUMPDEST analysis. (default: 500)")
106122
public int lruCacheSize;
@@ -109,48 +125,60 @@ public class CLIParameter {
109125
+ "will not check for timeout. (default: false)")
110126
public boolean debug;
111127

128+
@Deprecated
112129
@Parameter(names = {"--min-time-ratio"}, description = "Minimum CPU tolerance when executing "
113130
+ "timeout transactions while synchronizing blocks. (default: 0.0)")
114131
public double minTimeRatio;
115132

133+
@Deprecated
116134
@Parameter(names = {"--max-time-ratio"}, description = "Maximum CPU tolerance when executing "
117135
+ "non-timeout transactions while synchronizing blocks. (default: 5.0)")
118136
public double maxTimeRatio;
119137

138+
@Deprecated
120139
@Parameter(names = {"--save-internaltx"}, description = "Save internal transactions generated "
121140
+ "during TVM execution, such as create, call and suicide. (default: false)")
122141
public boolean saveInternalTx;
123142

143+
@Deprecated
124144
@Parameter(names = {"--save-featured-internaltx"}, description = "Save featured internal "
125145
+ "transactions generated during TVM execution, such as freeze, vote and so on. "
126146
+ "(default: false)")
127147
public boolean saveFeaturedInternalTx;
128148

149+
@Deprecated
129150
@Parameter(names = {"--save-cancel-all-unfreeze-v2-details"},
130151
description = "Record the details of the internal transactions generated by the "
131152
+ "CANCELALLUNFREEZEV2 opcode, such as bandwidth/energy/tronpower cancel amount. "
132153
+ "(default: false)")
133154
public boolean saveCancelAllUnfreezeV2Details;
134155

156+
@Deprecated
135157
@Parameter(names = {"--long-running-time"})
136158
public int longRunningTime;
137159

160+
@Deprecated
138161
@Parameter(names = {"--max-connect-number"}, description = "Http server max connect number "
139162
+ "(default:50)")
140163
public int maxHttpConnectNumber;
141164

165+
@Deprecated
142166
@Parameter(names = {"--rpc-thread"}, description = "Num of gRPC thread")
143167
public int rpcThreadNum;
144168

169+
@Deprecated
145170
@Parameter(names = {"--solidity-thread"}, description = "Num of solidity thread")
146171
public int solidityThreads;
147172

173+
@Deprecated
148174
@Parameter(names = {"--validate-sign-thread"}, description = "Num of validate thread")
149175
public int validateSignThreadNum;
150176

177+
@Deprecated
151178
@Parameter(names = {"--trust-node"}, description = "Trust node addr")
152179
public String trustNodeAddr;
153180

181+
@Deprecated
154182
@Parameter(names = {"--history-balance-lookup"})
155183
public boolean historyBalanceLookup;
156184
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ private ConfigKey() {
272272

273273
// event
274274
public static final String EVENT_SUBSCRIBE = "event.subscribe";
275+
public static final String EVENT_SUBSCRIBE_ENABLE = "event.subscribe.enable";
275276
public static final String EVENT_SUBSCRIBE_FILTER = "event.subscribe.filter";
276277
public static final String EVENT_SUBSCRIBE_VERSION = "event.subscribe.version";
277278
public static final String EVENT_SUBSCRIBE_START_SYNC_BLOCK_NUM =

framework/src/main/resources/config.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ committee = {
762762
}
763763

764764
event.subscribe = {
765+
enable = false // enable event subscribe, replaces deprecated CLI flag --es
765766
native = {
766767
useNativeQueue = true // if true, use native message queue, else use event plugin.
767768
bindport = 5555 // bind port

framework/src/test/java/org/tron/core/config/args/ArgsTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,28 @@ public void testCliOverridesStorageConfig() {
318318
Args.clearParam();
319319
}
320320

321+
/**
322+
* Verify that event.subscribe.enable = false from config is read correctly.
323+
*/
324+
@Test
325+
public void testEventSubscribeFromConfig() {
326+
Args.setParam(new String[] {}, TestConstants.TEST_CONF);
327+
Assert.assertFalse(Args.getInstance().isEventSubscribe());
328+
Args.clearParam();
329+
}
330+
331+
/**
332+
* Verify that CLI --es overrides event.subscribe.enable from config.
333+
* config-test.conf defines: event.subscribe.enable = false,
334+
* passing --es explicitly sets eventSubscribe = true, overriding config.
335+
*/
336+
@Test
337+
public void testCliEsOverridesConfig() {
338+
Args.setParam(new String[] {"--es"}, TestConstants.TEST_CONF);
339+
Assert.assertTrue(Args.getInstance().isEventSubscribe());
340+
Args.clearParam();
341+
}
342+
321343
/**
322344
* Verify that config file storage values are applied when no CLI override is present.
323345
*

framework/src/test/resources/config-test.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,4 +382,8 @@ rate.limiter.http = [
382382
]
383383

384384
node.dynamicConfig.enable = true
385+
386+
event.subscribe = {
387+
enable = false
388+
}
385389
node.dynamicConfig.checkInterval = 0

0 commit comments

Comments
 (0)