fix(config): deprecate CLI params and add guardrails#6580
fix(config): deprecate CLI params and add guardrails#6580vividctrlalt wants to merge 3 commits intotronprotocol:developfrom
Conversation
…rotocol#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
| // isAssigned(). An empty-check is used instead — this is safe because the default | ||
| // is an empty list, so non-empty means the user explicitly passed values on CLI. | ||
| if (!cmd.seedNodes.isEmpty()) { | ||
| logger.warn("Positional seed-node arguments are deprecated. " |
There was a problem hiding this comment.
Since seedNodes is deprecated, the corresponding help info should also be removed, such as: helpStr.append(String.format("%nUsage: java -jar %s [options] [seedNode ...]%n", programName));
There was a problem hiding this comment.
Thanks for the feedback! Since seedNodes is deprecated but not yet removed, users may still want to use it, so I kept the Usage line but added a deprecation note right below it. Also noticed that --es and --solidity in the help output are deprecated too (marked in this PR), so I added (deprecated) hints to all deprecated options in the help text. See 84027da.
Mark deprecated options with "(deprecated)" in help text and add a note below the Usage line that positional seedNode args are deprecated.
| }) | ||
| .forEach(pd -> logger.warn( | ||
| "CLI option '{}' is deprecated and will be removed in a future release. " | ||
| + "Please use the corresponding config-file option instead.", |
There was a problem hiding this comment.
Consider enriching the warning message with the specific config-file key mapping so users know exactly how to migrate.
And if we implement this, it's necessary to add a static map like this:
private static final Map<String, String> DEPRECATED_CLI_TO_CONFIG = Map.ofEntries(
Map.entry("--storage-db-directory", "storage.db.directory"),
Map.entry("--storage-db-engine", "storage.db.engine"),
Map.entry("--storage-db-synchronous", "storage.db.synchronous"),
// add remaining params...
);And change this log like this:
.forEach(pd -> {
String cliOption = pd.getLongestName();
String configKey = DEPRECATED_CLI_TO_CONFIG.get(cliOption);
String suggestion = configKey != null
? String.format(" Please use config key '%s' instead.", configKey)
: " Please use the corresponding config-file option instead.";
logger.warn("CLI option '{}' is deprecated and will be removed in a future release.{}",
cliOption, suggestion);
});There was a problem hiding this comment.
Good suggestion! Added a DEPRECATED_CLI_TO_CONFIG map that provides specific config-key hints in deprecation warnings.
For params with a config equivalent:
CLI option '--storage-db-engine' is deprecated and will be removed in a future release. Please use config key 'storage.db.engine' instead.
For params without a config equivalent (--solidity, --p2p-disable):
CLI option '--solidity' is deprecated and will be removed in a future release.
This also addresses @3for's concern about misleading messages. See 5b0e37b.
| } | ||
| if (assigned.contains("--max-energy-limit-for-constant")) { | ||
| PARAMETER.maxEnergyLimitForConstant = cmd.maxEnergyLimitForConstant; | ||
| PARAMETER.maxEnergyLimitForConstant = max(3_000_000L, |
There was a problem hiding this comment.
I noticed that 3_000_000L is already defined as ENERGY_LIMIT_IN_CONSTANT_TX in Constant.java:
// In common/src/main/java/org/tron/core/Constant.java
public static final long ENERGY_LIMIT_IN_CONSTANT_TX = 3_000_000L;Would it make sense to reuse this constant here instead of the inline literal?
There was a problem hiding this comment.
Good catch! Replaced both occurrences of 3_000_000L with ENERGY_LIMIT_IN_CONSTANT_TX from Constant.java. See 5b0e37b.
| }) | ||
| .forEach(pd -> logger.warn( | ||
| "CLI option '{}' is deprecated and will be removed in a future release. " | ||
| + "Please use the corresponding config-file option instead.", |
There was a problem hiding this comment.
Some deprecated CLI parameters (e.g., --solidity, --p2p-disable, --es, --fast-forward) have no equivalent "config-file option" in .conf, making the message “Please use the corresponding config-file option instead” misleading.
There was a problem hiding this comment.
Valid point. Params like --solidity and --p2p-disable have no config-file equivalent — they are runtime mode switches being phased out entirely. The warning now omits the "use config-file option" suggestion for these params and simply states they will be removed. See 5b0e37b.
- Add DEPRECATED_CLI_TO_CONFIG map for CLI-to-config key lookup - Show specific config key in warning for params that have equivalents - Use generic "will be removed" message for params without config equiv (--solidity, --p2p-disable) - Replace magic literal 3_000_000L with ENERGY_LIMIT_IN_CONSTANT_TX Addresses review feedback from warku123 and 3for on tronprotocol#6580.
- Add DEPRECATED_CLI_TO_CONFIG map for CLI-to-config key lookup - Show specific config key in warning for params that have equivalents - Use generic "will be removed" message for params without config equiv (--solidity, --p2p-disable) - Replace magic literal 3_000_000L with ENERGY_LIMIT_IN_CONSTANT_TX Addresses review feedback from warku123 and 3for on tronprotocol#6580.
731abdb to
5b0e37b
Compare
Summary
Follow-up to #6569 review feedback:
@DeprecatedinCLIParameterand logging runtime warnings via reflection when usedmax(3_000_000L, ...)guardrail for--max-energy-limit-for-constantCLI path, consistent with config-file validation (addresses @waynercheung's review in refactor(config): extract CLIParameter and restructure Args init flow #6569)seedNodespositional parameter behavior with comment explaining whyisEmpty()is used instead ofisAssigned(), plus deprecation warningRetained CLI params (11)
-c,-d,--log-config,-h,-v,-w,-p,--witness-address,--password,--keystore-factory,--debugDeprecated CLI params (23)
All storage, VM, network/thread, and misc runtime parameters — these should be configured via config file.
Test plan
./gradlew compileJava— all modules compile successfully./gradlew :framework:test --tests "org.tron.core.config.args.*"— parameter tests pass./gradlew :framework:test— full framework tests passRelated