Skip to content

refactor(config): extract CLIParameter and restructure Args init flow#6569

Open
vividctrlalt wants to merge 9 commits intotronprotocol:developfrom
vividctrlalt:refactor/parameter-init
Open

refactor(config): extract CLIParameter and restructure Args init flow#6569
vividctrlalt wants to merge 9 commits intotronprotocol:developfrom
vividctrlalt:refactor/parameter-init

Conversation

@vividctrlalt
Copy link
Contributor

@vividctrlalt vividctrlalt commented Mar 4, 2026

Summary

  • Extract CLI @Parameter annotations from CommonParameter into a new CLIParameter class, separating CLI parsing from runtime config state
  • Restructure Args.setParam() into a clear 4-step flow: parse CLI → applyConfigParamsapplyCLIParamsinitLocalWitnesses
  • Refactor WitnessInitializer into three static methods (initFromCLIPrivateKey, initFromCFGPrivateKey, initFromKeystore), with routing logic moved to Args.initLocalWitnesses
  • Remove password, privateKey, witnessAddress from CommonParameter — sensitive credentials are now passed directly as method parameters and never stored in global state
  • Fixes CLI flags silently overridden by config file for 13 parameters #6567

Test plan

  • ./gradlew :framework:test --tests "org.tron.core.config.args.*" — all parameter tests pass
  • ./gradlew :framework:test — full framework tests pass

vividcoder added 3 commits March 3, 2026 18:07
Extract all @parameter annotations from CommonParameter into a new
CLIParameter class, removing JCommander dependency from common module.
Refactor Args.setParam() into a four-step flow: parse CLI, apply
config, apply CLI overrides via isAssigned(), init witness. Simplify
clearParam() from ~160 lines to CommonParameter.reset().
- Restructure Args.setParam into 4-step flow: parse CLI, apply config,
  apply CLI overrides, init witnesses
- Rename setParam(Config) to applyConfigParams, setCLIParameter to
  applyCLIParams for clarity
- Extract WitnessInitializer into 3 static methods (initFromCLIPrivateKey,
  initFromCFGPrivateKey, initFromKeystore) with routing in Args
- Remove password/privateKey/witnessAddress/help/version/configFilePath
  from CommonParameter — pass as method params instead of global state
- Move JDK version check from Args to FullNode entry point
- Extract Configuration.getByFileName for single-param config loading
PARAMETER.maxHttpConnectNumber = cmd.maxHttpConnectNumber;
}
if (assigned.containsKey("--storage-db-directory")) {
PARAMETER.storageDbDirectory = cmd.storageDbDirectory;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In applyCLIParams(), 7 storage-related parameters are written only to intermediate fields on PARAMETER, not to the PARAMETER.storage object that is actually used at runtime. The approach in applyConfigParams() is correct (writing via PARAMETER.storage.setXxx()), and applyCLIParams() should be consistent with it.

Current code in applyCLIParams:

PARAMETER.storageDbDirectory = cmd.storageDbDirectory;

Should be changed to write directly to PARAMETER.storage, consistent with applyConfigParams:

PARAMETER.storage.setDbDirectory(cmd.storageDbDirectory);

Please check the relevant parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this!

The existing tests did not cover the scenario where CLI storage parameters override config file values, which is why this bug went undetected after the refactor. Two test cases have been added to cover both the CLI-overrides-config and config-defaults-without-CLI scenarios.

Fixed in c4cb0e1. Please continue reviewing, thank you!

vividcoder added 4 commits March 5, 2026 21:57
applyCLIParams() wrote 7 storage-related values to intermediate fields
on CommonParameter instead of the Storage object that is actually used
at runtime. Since applyConfigParams() runs first, these CLI values were
silently ignored.

- Remove 7 intermediate fields from CommonParameter
- Simplify applyConfigParams() to read directly from config
- Fix applyCLIParams() to write directly to PARAMETER.storage
- Add tests for CLI-overrides-config and config-defaults scenarios
The test failed on ARM64 because Storage.getDbEngineFromConfig()
silently overrode the user's config to ROCKSDB, which is unreasonable
as it hides incompatible configuration from the user.

Replace the silent override with an explicit validateConfig() check
in Args that fails fast with IllegalArgumentException when LevelDB
is configured on ARM64. This makes the incompatibility visible
instead of silently swallowed.
…erride

The validateConfig() approach caused 1273 test failures on ARM64 because
most tests use config files with db.engine="LEVELDB" and setParam() was
throwing IllegalArgumentException before any test logic could run.

Restore the original silent override in Storage.getDbEngineFromConfig()
which automatically switches to ROCKSDB on ARM64. Update the
testConfigStorageDefaults test to be architecture-aware.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI flags silently overridden by config file for 13 parameters

2 participants