diff --git a/framework/src/main/java/org/tron/core/config/args/Args.java b/framework/src/main/java/org/tron/core/config/args/Args.java index 2d6660f9a6..482724127a 100644 --- a/framework/src/main/java/org/tron/core/config/args/Args.java +++ b/framework/src/main/java/org/tron/core/config/args/Args.java @@ -178,6 +178,14 @@ public static void setParam(final String[] args, final String confFileName) { // 5. Init witness (depends on CLI witness flag) initLocalWitnesses(config, cmd); + + // 6. Build event-subscribe derivatives (EventPluginConfig + FilterQuery) + // after CLI/platform overrides have settled the final eventSubscribe flag. + // Doing it here — instead of inside applyConfigParams — lets deprecated + // --es still produce a valid EventPluginConfig when the config file has + // event.subscribe.enable = false. + buildEventDerivatives(eventConfig); + logConfig(); } /** @@ -217,7 +225,7 @@ private static void applyStorageConfig(StorageConfig sc) { PARAMETER.storage.setIndexSwitch( org.apache.commons.lang3.StringUtils.isNotEmpty(indexSwitch) ? indexSwitch : "on"); PARAMETER.storage.setTransactionHistorySwitch(sc.getTransHistory().getSwitch()); - // contractParse is set in applyEventConfig — it belongs to event.subscribe domain + // contractParse is set in applyConfigParams from event.subscribe.contractParse PARAMETER.storage.setCheckpointVersion(sc.getCheckpoint().getVersion()); PARAMETER.storage.setCheckpointSync(sc.getCheckpoint().isSync()); @@ -344,20 +352,24 @@ private static void applyRateLimiterConfig(RateLimiterConfig rl) { } /** - * Bridge EventConfig bean values to CommonParameter fields. - * Converts EventConfig (raw bean) into EventPluginConfig and FilterQuery (business objects). + * Build event-subscribe derivative objects (EventPluginConfig + FilterQuery) + * from the raw EventConfig bean. Gated by the final PARAMETER.eventSubscribe + * value, which has already absorbed any CLI/platform overrides by the time + * this is called. + * + *

Atomic values (PARAMETER.eventSubscribe, contractParseSwitch) are bound + * earlier in applyConfigParams; they are not re-applied here so that any + * CLI overrides such as --contract-parse-enable survive.

*/ - private static void applyEventConfig(EventConfig ec) { - PARAMETER.eventSubscribe = ec.isEnable(); - // contractParse belongs to event.subscribe but Storage object holds it - PARAMETER.storage.setContractParseSwitch(ec.isContractParse()); - + @VisibleForTesting + static void buildEventDerivatives(EventConfig ec) { // PARAMETER.eventPluginConfig and PARAMETER.eventFilter are only consumed by - // Manager.startEventSubscribing(), which itself is gated by isEventSubscribe() - // (= ec.isEnable()) at Manager.java:564. When subscribe is disabled, building - // these objects has no observable effect — skip both early so PARAMETER stays - // consistent with the runtime intent. - if (!ec.isEnable()) { + // Manager.startEventSubscribing(), which itself is gated by isEventSubscribe(). + // When subscribe is disabled, these objects have no observable effect — null + // them out so PARAMETER stays consistent with runtime intent. + if (!PARAMETER.isEventSubscribe()) { + PARAMETER.eventPluginConfig = null; + PARAMETER.eventFilter = null; return; } @@ -706,6 +718,13 @@ private static void applyPlatformConstraints() { /** * Apply parameters from config file. + * + *

Binds atomic values only. Event-subscribe derivative objects + * (EventPluginConfig + FilterQuery) are NOT built here — {@link #setParam} + * builds them via {@link #buildEventDerivatives} after CLI overrides have + * settled. Tests that call this method directly and need EPC/FilterQuery + * populated must call {@code buildEventDerivatives(getEventConfig())} + * themselves.

*/ public static void applyConfigParams( final Config config) { @@ -770,11 +789,13 @@ public static void applyConfigParams( // node.shutdown — handled in applyNodeConfig - // Event config: bind from config.conf "event.subscribe" section + // Event config: bind atomic values from config.conf "event.subscribe". + // Derivative business objects (EventPluginConfig + FilterQuery) are built + // later in setParam, after CLI overrides have run. eventConfig = EventConfig.fromConfig(config); - applyEventConfig(eventConfig); - - logConfig(); + PARAMETER.eventSubscribe = eventConfig.isEnable(); + // contractParse belongs to event.subscribe but Storage object holds it. + PARAMETER.storage.setContractParseSwitch(eventConfig.isContractParse()); } /** @@ -1001,7 +1022,7 @@ public static List filterInetSocketAddress( // getInetAddress removed — use filterInetSocketAddress - // getEventPluginConfig removed — logic moved to applyEventConfig() + // getEventPluginConfig removed — logic moved to buildEventDerivatives() public static PublishConfig loadDnsPublishConfig(NodeConfig nodeConfig) { @@ -1109,8 +1130,8 @@ private static void logEmptyError(String arg) { throw new IllegalArgumentException(String.format("Check %s, must not be null or empty", arg)); } - // createTriggerConfig removed — logic moved to applyEventConfig() - // getEventFilter removed — logic moved to applyEventConfig() + // createTriggerConfig removed — logic moved to buildEventDerivatives() + // getEventFilter removed — logic moved to buildEventDerivatives() private static void externalIp(NodeConfig nodeConfig) { String externalIp = nodeConfig.getDiscoveryExternalIp(); @@ -1333,4 +1354,3 @@ private static Map getOptionGroup() { return optionGroupMap; } } - diff --git a/framework/src/test/java/org/tron/core/config/args/ArgsTest.java b/framework/src/test/java/org/tron/core/config/args/ArgsTest.java index 4b6b7ad0a7..e05b3480ca 100644 --- a/framework/src/test/java/org/tron/core/config/args/ArgsTest.java +++ b/framework/src/test/java/org/tron/core/config/args/ArgsTest.java @@ -335,12 +335,31 @@ public void testEventSubscribeFromConfig() { /** * Verify that CLI --es overrides event.subscribe.enable from config. * config-test.conf defines: event.subscribe.enable = false, - * passing --es explicitly sets eventSubscribe = true, overriding config. + * passing --es explicitly sets eventSubscribe = true and still builds + * EventPluginConfig for backward compatibility with old startup commands. */ @Test public void testCliEsOverridesConfig() { Args.setParam(new String[] {"--es"}, TestConstants.TEST_CONF); Assert.assertTrue(Args.getInstance().isEventSubscribe()); + Assert.assertNotNull(Args.getInstance().getEventPluginConfig()); + Assert.assertNotNull(Args.getInstance().getEventFilter()); + Args.clearParam(); + } + + /** + * Regression: --contract-parse-enable=false must survive the post-CLI + * derivative build that --es triggers. The bean default for contractParse + * is true, so a naive re-apply of the EventConfig bean would clobber the + * CLI override back to true. + */ + @Test + public void testCliContractParseDisableSurvivesEsDerivativeBuild() { + Args.setParam( + new String[] {"--es", "--contract-parse-enable", "false"}, + TestConstants.TEST_CONF); + Assert.assertTrue(Args.getInstance().isEventSubscribe()); + Assert.assertFalse(Args.getInstance().getStorage().isContractParseSwitch()); Args.clearParam(); } @@ -454,6 +473,7 @@ public void testEventConfigDisabledSkipsEpcAndFilter() { Config config = ConfigFactory.parseMap(override) .withFallback(ConfigFactory.defaultReference()); Args.applyConfigParams(config); + Args.buildEventDerivatives(Args.getEventConfig()); Assert.assertNull(Args.getInstance().getEventPluginConfig()); Assert.assertNull(Args.getInstance().getEventFilter()); Args.clearParam(); @@ -467,6 +487,7 @@ public void testEventConfigEnabledBuildsEpcAndFilter() { Config config = ConfigFactory.parseMap(override) .withFallback(ConfigFactory.defaultReference()); Args.applyConfigParams(config); + Args.buildEventDerivatives(Args.getEventConfig()); Assert.assertNotNull(Args.getInstance().getEventPluginConfig()); Assert.assertNotNull(Args.getInstance().getEventFilter()); Args.clearParam(); @@ -481,6 +502,7 @@ public void testEventConfigEnabledWithInvalidFromBlockLeavesFilterNull() { Config config = ConfigFactory.parseMap(override) .withFallback(ConfigFactory.defaultReference()); Args.applyConfigParams(config); + Args.buildEventDerivatives(Args.getEventConfig()); // epc still built; filter rejected Assert.assertNotNull(Args.getInstance().getEventPluginConfig()); Assert.assertNull(Args.getInstance().getEventFilter());