Skip to content

Commit f55e9cf

Browse files
committed
fix(config): deprecate CLI params and add safety guardrails for #6569 review follow-up
- Mark 23 config-file-replaceable CLI parameters as @deprecated in CLIParameter - Add runtime deprecation warning via reflection when deprecated CLI options are used - Add max(3_000_000L, ...) guardrail for --max-energy-limit-for-constant CLI path, consistent with config-file validation (addresses waynercheung's review feedback) - Document seedNodes positional parameter behavior and add deprecation warning - Retain 11 essential CLI params: -c, -d, --log-config, -h, -v, -w, -p, --witness-address, --password, --keystore-factory, --debug
1 parent 7e5bbbd commit f55e9cf

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,21 @@ private static void applyCLIParams(CLIParameter cmd, JCommander jc) {
998998
.map(ParameterDescription::getLongestName)
999999
.collect(Collectors.toSet());
10001000

1001+
jc.getParameters().stream()
1002+
.filter(ParameterDescription::isAssigned)
1003+
.filter(pd -> {
1004+
try {
1005+
return CLIParameter.class.getDeclaredField(pd.getParameterized().getName())
1006+
.isAnnotationPresent(Deprecated.class);
1007+
} catch (NoSuchFieldException e) {
1008+
return false;
1009+
}
1010+
})
1011+
.forEach(pd -> logger.warn(
1012+
"CLI option '{}' is deprecated and will be removed in a future release. "
1013+
+ "Please use the corresponding config-file option instead.",
1014+
pd.getLongestName()));
1015+
10011016
if (assigned.contains("--output-directory")) {
10021017
PARAMETER.outputDirectory = cmd.outputDirectory;
10031018
}
@@ -1008,7 +1023,8 @@ private static void applyCLIParams(CLIParameter cmd, JCommander jc) {
10081023
PARAMETER.supportConstant = cmd.supportConstant;
10091024
}
10101025
if (assigned.contains("--max-energy-limit-for-constant")) {
1011-
PARAMETER.maxEnergyLimitForConstant = cmd.maxEnergyLimitForConstant;
1026+
PARAMETER.maxEnergyLimitForConstant = max(3_000_000L,
1027+
cmd.maxEnergyLimitForConstant, true);
10121028
}
10131029
if (assigned.contains("--lru-cache-size")) {
10141030
PARAMETER.lruCacheSize = cmd.lruCacheSize;
@@ -1091,7 +1107,12 @@ private static void applyCLIParams(CLIParameter cmd, JCommander jc) {
10911107
if (assigned.contains("--log-config")) {
10921108
PARAMETER.logbackPath = cmd.logbackPath;
10931109
}
1110+
// seedNodes is a JCommander positional (main) parameter, which does not support
1111+
// isAssigned(). An empty-check is used instead — this is safe because the default
1112+
// is an empty list, so non-empty means the user explicitly passed values on CLI.
10941113
if (!cmd.seedNodes.isEmpty()) {
1114+
logger.warn("Positional seed-node arguments are deprecated. "
1115+
+ "Please use seed.node.ip.list in the config file instead.");
10951116
List<InetSocketAddress> seeds = new ArrayList<>();
10961117
for (String s : cmd.seedNodes) {
10971118
seeds.add(NetUtil.parseInetSocketAddress(s));

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

Lines changed: 32 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 {
@@ -44,63 +47,78 @@ public class CLIParameter {
4447
@Parameter(names = {"--password"}, description = "password")
4548
public String password;
4649

50+
@Deprecated
4751
@Parameter(names = {"--solidity"}, description = "running a solidity node for java tron")
4852
public boolean solidityNode;
4953

5054
@Parameter(names = {"--keystore-factory"}, description = "running KeystoreFactory")
5155
public boolean keystoreFactory;
5256

57+
@Deprecated
5358
@Parameter(names = {"--fast-forward"})
5459
public boolean fastForward;
5560

61+
@Deprecated
5662
@Parameter(names = {"--es"}, description = "Start event subscribe server")
5763
public boolean eventSubscribe;
5864

65+
@Deprecated
5966
@Parameter(names = {"--p2p-disable"}, description = "Switch for p2p module initialization. "
6067
+ "(default: false)", arity = 1)
6168
public boolean p2pDisable;
6269

70+
@Deprecated
6371
@Parameter(description = "--seed-nodes")
6472
public List<String> seedNodes = new ArrayList<>();
6573

66-
// -- Storage parameters --
74+
// -- Storage parameters (deprecated, use config file instead) --
6775

76+
@Deprecated
6877
@Parameter(names = {"--storage-db-directory"}, description = "Storage db directory")
6978
public String storageDbDirectory;
7079

80+
@Deprecated
7181
@Parameter(names = {"--storage-db-engine"},
7282
description = "Storage db engine.(leveldb or rocksdb)")
7383
public String storageDbEngine;
7484

85+
@Deprecated
7586
@Parameter(names = {"--storage-db-synchronous"},
7687
description = "Storage db is synchronous or not.(true or false)")
7788
public String storageDbSynchronous;
7889

90+
@Deprecated
7991
@Parameter(names = {"--storage-index-directory"}, description = "Storage index directory")
8092
public String storageIndexDirectory;
8193

94+
@Deprecated
8295
@Parameter(names = {"--storage-index-switch"},
8396
description = "Storage index switch.(on or off)")
8497
public String storageIndexSwitch;
8598

99+
@Deprecated
86100
@Parameter(names = {"--storage-transactionHistory-switch"},
87101
description = "Storage transaction history switch.(on or off)")
88102
public String storageTransactionHistorySwitch;
89103

104+
@Deprecated
90105
@Parameter(names = {"--contract-parse-enable"}, description = "Switch for contract parses in "
91106
+ "java-tron. (default: true)")
92107
public String contractParseEnable;
93108

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

111+
@Deprecated
96112
@Parameter(names = {"--support-constant"}, description = "Support constant calling for TVM. "
97113
+ "(default: false)")
98114
public boolean supportConstant;
99115

116+
@Deprecated
100117
@Parameter(names = {"--max-energy-limit-for-constant"},
101118
description = "Max energy limit for constant calling. (default: 100,000,000)")
102119
public long maxEnergyLimitForConstant;
103120

121+
@Deprecated
104122
@Parameter(names = {"--lru-cache-size"}, description = "Max LRU size for caching bytecode and "
105123
+ "result of JUMPDEST analysis. (default: 500)")
106124
public int lruCacheSize;
@@ -109,48 +127,60 @@ public class CLIParameter {
109127
+ "will not check for timeout. (default: false)")
110128
public boolean debug;
111129

130+
@Deprecated
112131
@Parameter(names = {"--min-time-ratio"}, description = "Minimum CPU tolerance when executing "
113132
+ "timeout transactions while synchronizing blocks. (default: 0.0)")
114133
public double minTimeRatio;
115134

135+
@Deprecated
116136
@Parameter(names = {"--max-time-ratio"}, description = "Maximum CPU tolerance when executing "
117137
+ "non-timeout transactions while synchronizing blocks. (default: 5.0)")
118138
public double maxTimeRatio;
119139

140+
@Deprecated
120141
@Parameter(names = {"--save-internaltx"}, description = "Save internal transactions generated "
121142
+ "during TVM execution, such as create, call and suicide. (default: false)")
122143
public boolean saveInternalTx;
123144

145+
@Deprecated
124146
@Parameter(names = {"--save-featured-internaltx"}, description = "Save featured internal "
125147
+ "transactions generated during TVM execution, such as freeze, vote and so on. "
126148
+ "(default: false)")
127149
public boolean saveFeaturedInternalTx;
128150

151+
@Deprecated
129152
@Parameter(names = {"--save-cancel-all-unfreeze-v2-details"},
130153
description = "Record the details of the internal transactions generated by the "
131154
+ "CANCELALLUNFREEZEV2 opcode, such as bandwidth/energy/tronpower cancel amount. "
132155
+ "(default: false)")
133156
public boolean saveCancelAllUnfreezeV2Details;
134157

158+
@Deprecated
135159
@Parameter(names = {"--long-running-time"})
136160
public int longRunningTime;
137161

162+
@Deprecated
138163
@Parameter(names = {"--max-connect-number"}, description = "Http server max connect number "
139164
+ "(default:50)")
140165
public int maxHttpConnectNumber;
141166

167+
@Deprecated
142168
@Parameter(names = {"--rpc-thread"}, description = "Num of gRPC thread")
143169
public int rpcThreadNum;
144170

171+
@Deprecated
145172
@Parameter(names = {"--solidity-thread"}, description = "Num of solidity thread")
146173
public int solidityThreads;
147174

175+
@Deprecated
148176
@Parameter(names = {"--validate-sign-thread"}, description = "Num of validate thread")
149177
public int validateSignThreadNum;
150178

179+
@Deprecated
151180
@Parameter(names = {"--trust-node"}, description = "Trust node addr")
152181
public String trustNodeAddr;
153182

183+
@Deprecated
154184
@Parameter(names = {"--history-balance-lookup"})
155185
public boolean historyBalanceLookup;
156186
}

0 commit comments

Comments
 (0)