Skip to content

refactor(config): replace ConfigKey with bean binding#13

Open
vividctrlalt wants to merge 16 commits intodevelopfrom
refactor/config-bean-binding
Open

refactor(config): replace ConfigKey with bean binding#13
vividctrlalt wants to merge 16 commits intodevelopfrom
refactor/config-bean-binding

Conversation

@vividctrlalt
Copy link
Copy Markdown
Owner

Summary

Replace manual config key constant lookup (ConfigKey.java + hasPath/getXxx) with ConfigBeanFactory.create() automatic bean binding across all config.conf domains.

  • 12 new bean classes (VmConfig, BlockConfig, CommitteeConfig, NodeConfig, MetricsConfig, EventConfig, GenesisConfig, RateLimiterConfig, StorageConfig, MiscConfig, LocalWitnessConfig, RateLimiterConfig)
  • ConfigKey.java deleted — config.conf is the single source of truth
  • All bridge methods read from beans only — no raw Config parameter passing
  • Storage.java string constants removed — reads from StorageConfig bean
  • 11 unit test classes for all bean classes
  • DynamicArgs migrated to use bean + filterInetSocketAddress

Key design decisions

  1. ConfigBeanFactory binds field names to config keys automatically — zero key string duplication
  2. PBFT naming workaround — 4 keys with consecutive uppercase excluded from auto-binding, read manually with documented reason
  3. Dot-notation fields (listen.port, connection.timeout) — create sub-beans or exclude + manual read
  4. Legacy key fallback (maxActiveNodes → maxConnections) — handled in bean's fromConfig()
  5. Dynamic key-value structures (cache.strategies, merkleRoot) — pass raw Config sub-tree from bean, documented why

Adding a new config parameter after this change

  1. Add one line in config.conf
  2. Add one field in the corresponding bean class

That's it. ConfigBeanFactory auto-binds.

Test plan

  • All 11 new bean unit tests pass
  • Full test suite passes (framework + plugins + common)
  • Verified defaults match CommonParameter field initializers
  • Code review: correctness + maintainability reviewers ran

ouy95917 and others added 9 commits February 25, 2026 15:45
# Conflicts:
#	common/src/main/java/org/tron/core/Constant.java
#	framework/src/main/java/org/tron/core/config/args/Args.java
1. Change ALLOW_TVM_OSAKA proposal id from 95 to 96
2. DynamicPropertiesStore.getAllowTvmOsaka() defaults to CommonParameter
3. ModExp returns Pair.of(false, EMPTY_BYTE_ARRAY) instead of throwing
   PrecompiledContractException when inputs exceed 1024 bytes, matching
   geth/besu behavior where only the CALL fails (not the whole tx)
4. Update test to verify return value instead of catching exception
docs: fix shieldedTransaction typos in comments
- baseLen == 1024 boundary value should succeed
- baseLen == 1025 just over limit should fail
- oversized expLen only should fail
- oversized modLen only should fail
- all limits exceeded with osaka disabled should succeed
Changes:
- Add a registration status check to prevent duplicate initialization during CI test runs.
- Throw TronError on actuator instantiation failures to improve error visibility and debugging.
- Narrow package scanning from "org.tron" to "org.tron.core.actuator" to reduce reflection overhead and speed up registration.
- Remove JVM args for CI test to avoid JDK8 G1 GC bugs and Evacuation Pause failures.
- Optimize console output to prevent test OOM for CI
- Adjust memory and parallelism settings
- Exclude dnsjava InetAddressResolverProvider
@github-actions
Copy link
Copy Markdown

❌ Math Usage Detection Results

Found forbidden usage of java.lang.Math in the following files:

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

Please review if this usage is intended.

Caution

Note: You should use org.tron.common.math.StrictMathWrapper.
If you need to use java.lang.Math, please provide a justification.

@vividctrlalt vividctrlalt changed the title refactor(config): replace ConfigKey constants with ConfigBeanFactory bean binding refactor(config): replace ConfigKey with bean binding Mar 31, 2026
@github-actions
Copy link
Copy Markdown

❌ Math Usage Detection Results

Found forbidden usage of java.lang.Math in the following files:

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

Please review if this usage is intended.

Caution

Note: You should use org.tron.common.math.StrictMathWrapper.
If you need to use java.lang.Math, please provide a justification.

…ation test

TronError extends Error, not Exception, so use Throwable to ensure
worker thread failures are properly captured.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vividctrlalt vividctrlalt force-pushed the refactor/config-bean-binding branch from 66f39a2 to 19cadf7 Compare April 1, 2026 07:05
lvs0075 and others added 6 commits April 1, 2026 15:25
…actuator_opt

feat(actuator): prevent duplicate registration and stabilize CI
Replace ~850 lines of manual if/hasPath/getXxx blocks in Args.applyConfigParams()
with ConfigBeanFactory.create() automatic binding. Each config.conf domain now maps
to a typed Java bean class (VmConfig, BlockConfig, CommitteeConfig, MetricsConfig,
NodeConfig, EventConfig, StorageConfig, etc.).

- Delete ConfigKey.java (~100 string constants), config.conf is sole source of truth
- Migrate Storage.java static getters to read from StorageConfig bean
- Add unit tests for all config bean classes
- Migrate DynamicArgs to use bean binding
Move all default values from scattered bean field initializers into
reference.conf, making it the single source of truth for config defaults.
Expose config beans as static singletons for convenient access.

- Add comprehensive reference.conf with defaults for all config domains
- Auto-bind discovery, PBFT, and list fields in NodeConfig
- Expose config beans as static singletons (NodeConfig.getInstance() etc.)
- Move postProcess logic into bean classes
- Fix test configs (external.ip=null -> empty string)
- Document manual-read keys with reasons in reference.conf
…Config

Move default/defaultM/defaultL LevelDB option reading into StorageConfig,
so Storage no longer touches Config directly.

- Add DbOptionOverride with nullable boxed types for partial overrides
- Fix cacheSize type from int to long to match LevelDB Options API
- Remove dead externalIp(Config) bridge method
- Remove setIfNeeded and Config field from Storage
- Replace null values (discovery.external.ip, trustNode) with empty
  string before ConfigBeanFactory binding for external config compat
  (system-test uses "external.ip = null" which ConfigBeanFactory cannot
  bind to String fields; recommend updating system-test to use "" instead)
- Fix floating point comparison with Double.compare (java:S1244)
- Extract duplicated string literals into constants/variables (java:S1192)
@vividctrlalt vividctrlalt force-pushed the refactor/config-bean-binding branch from eb841d0 to 4d8d9b9 Compare April 1, 2026 08:59
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.

5 participants