Skip to content

Commit 6db1143

Browse files
committed
fix(config): restore --es behavior when event.subscribe.enable=false
The previous flow built EventPluginConfig/FilterQuery only when the config bean had enable=true, so passing the deprecated --es CLI flag against a config with enable=false set eventSubscribe=true but left the plugin config null, causing "Failed to load eventPlugin" at startup. Split applyConfigParams into atomic-bind (eventSubscribe, contractParseSwitch) and buildEventDerivatives (EPC + FilterQuery). The derivative build now runs once at the end of setParam, after CLI overrides have settled, so --es produces a valid EPC and --contract-parse-enable is not clobbered.
1 parent 381d369 commit 6db1143

2 files changed

Lines changed: 64 additions & 22 deletions

File tree

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

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ public static void setParam(final String[] args, final String confFileName) {
178178

179179
// 5. Init witness (depends on CLI witness flag)
180180
initLocalWitnesses(config, cmd);
181+
182+
// 6. Build event-subscribe derivatives (EventPluginConfig + FilterQuery)
183+
// after CLI/platform overrides have settled the final eventSubscribe flag.
184+
// Doing it here — instead of inside applyConfigParams — lets deprecated
185+
// --es still produce a valid EventPluginConfig when the config file has
186+
// event.subscribe.enable = false.
187+
buildEventDerivatives(eventConfig);
188+
logConfig();
181189
}
182190

183191
/**
@@ -217,7 +225,7 @@ private static void applyStorageConfig(StorageConfig sc) {
217225
PARAMETER.storage.setIndexSwitch(
218226
org.apache.commons.lang3.StringUtils.isNotEmpty(indexSwitch) ? indexSwitch : "on");
219227
PARAMETER.storage.setTransactionHistorySwitch(sc.getTransHistory().getSwitch());
220-
// contractParse is set in applyEventConfig — it belongs to event.subscribe domain
228+
// contractParse is set in applyConfigParams from event.subscribe.contractParse
221229
PARAMETER.storage.setCheckpointVersion(sc.getCheckpoint().getVersion());
222230
PARAMETER.storage.setCheckpointSync(sc.getCheckpoint().isSync());
223231

@@ -344,20 +352,24 @@ private static void applyRateLimiterConfig(RateLimiterConfig rl) {
344352
}
345353

346354
/**
347-
* Bridge EventConfig bean values to CommonParameter fields.
348-
* Converts EventConfig (raw bean) into EventPluginConfig and FilterQuery (business objects).
355+
* Build event-subscribe derivative objects (EventPluginConfig + FilterQuery)
356+
* from the raw EventConfig bean. Gated by the final PARAMETER.eventSubscribe
357+
* value, which has already absorbed any CLI/platform overrides by the time
358+
* this is called.
359+
*
360+
* <p>Atomic values (PARAMETER.eventSubscribe, contractParseSwitch) are bound
361+
* earlier in applyConfigParams; they are not re-applied here so that any
362+
* CLI overrides such as --contract-parse-enable survive.</p>
349363
*/
350-
private static void applyEventConfig(EventConfig ec) {
351-
PARAMETER.eventSubscribe = ec.isEnable();
352-
// contractParse belongs to event.subscribe but Storage object holds it
353-
PARAMETER.storage.setContractParseSwitch(ec.isContractParse());
354-
364+
@VisibleForTesting
365+
static void buildEventDerivatives(EventConfig ec) {
355366
// PARAMETER.eventPluginConfig and PARAMETER.eventFilter are only consumed by
356-
// Manager.startEventSubscribing(), which itself is gated by isEventSubscribe()
357-
// (= ec.isEnable()) at Manager.java:564. When subscribe is disabled, building
358-
// these objects has no observable effect — skip both early so PARAMETER stays
359-
// consistent with the runtime intent.
360-
if (!ec.isEnable()) {
367+
// Manager.startEventSubscribing(), which itself is gated by isEventSubscribe().
368+
// When subscribe is disabled, these objects have no observable effect — null
369+
// them out so PARAMETER stays consistent with runtime intent.
370+
if (!PARAMETER.isEventSubscribe()) {
371+
PARAMETER.eventPluginConfig = null;
372+
PARAMETER.eventFilter = null;
361373
return;
362374
}
363375

@@ -706,6 +718,13 @@ private static void applyPlatformConstraints() {
706718

707719
/**
708720
* Apply parameters from config file.
721+
*
722+
* <p>Binds atomic values only. Event-subscribe derivative objects
723+
* (EventPluginConfig + FilterQuery) are NOT built here — {@link #setParam}
724+
* builds them via {@link #buildEventDerivatives} after CLI overrides have
725+
* settled. Tests that call this method directly and need EPC/FilterQuery
726+
* populated must call {@code buildEventDerivatives(getEventConfig())}
727+
* themselves.</p>
709728
*/
710729
public static void applyConfigParams(
711730
final Config config) {
@@ -770,11 +789,13 @@ public static void applyConfigParams(
770789

771790
// node.shutdown — handled in applyNodeConfig
772791

773-
// Event config: bind from config.conf "event.subscribe" section
792+
// Event config: bind atomic values from config.conf "event.subscribe".
793+
// Derivative business objects (EventPluginConfig + FilterQuery) are built
794+
// later in setParam, after CLI overrides have run.
774795
eventConfig = EventConfig.fromConfig(config);
775-
applyEventConfig(eventConfig);
776-
777-
logConfig();
796+
PARAMETER.eventSubscribe = eventConfig.isEnable();
797+
// contractParse belongs to event.subscribe but Storage object holds it.
798+
PARAMETER.storage.setContractParseSwitch(eventConfig.isContractParse());
778799
}
779800

780801
/**
@@ -1001,7 +1022,7 @@ public static List<InetSocketAddress> filterInetSocketAddress(
10011022

10021023
// getInetAddress removed — use filterInetSocketAddress
10031024

1004-
// getEventPluginConfig removed — logic moved to applyEventConfig()
1025+
// getEventPluginConfig removed — logic moved to buildEventDerivatives()
10051026

10061027

10071028
public static PublishConfig loadDnsPublishConfig(NodeConfig nodeConfig) {
@@ -1109,8 +1130,8 @@ private static void logEmptyError(String arg) {
11091130
throw new IllegalArgumentException(String.format("Check %s, must not be null or empty", arg));
11101131
}
11111132

1112-
// createTriggerConfig removed — logic moved to applyEventConfig()
1113-
// getEventFilter removed — logic moved to applyEventConfig()
1133+
// createTriggerConfig removed — logic moved to buildEventDerivatives()
1134+
// getEventFilter removed — logic moved to buildEventDerivatives()
11141135

11151136
private static void externalIp(NodeConfig nodeConfig) {
11161137
String externalIp = nodeConfig.getDiscoveryExternalIp();
@@ -1333,4 +1354,3 @@ private static Map<String, String[]> getOptionGroup() {
13331354
return optionGroupMap;
13341355
}
13351356
}
1336-

framework/src/test/java/org/tron/core/config/args/ArgsTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,31 @@ public void testEventSubscribeFromConfig() {
335335
/**
336336
* Verify that CLI --es overrides event.subscribe.enable from config.
337337
* config-test.conf defines: event.subscribe.enable = false,
338-
* passing --es explicitly sets eventSubscribe = true, overriding config.
338+
* passing --es explicitly sets eventSubscribe = true and still builds
339+
* EventPluginConfig for backward compatibility with old startup commands.
339340
*/
340341
@Test
341342
public void testCliEsOverridesConfig() {
342343
Args.setParam(new String[] {"--es"}, TestConstants.TEST_CONF);
343344
Assert.assertTrue(Args.getInstance().isEventSubscribe());
345+
Assert.assertNotNull(Args.getInstance().getEventPluginConfig());
346+
Assert.assertNotNull(Args.getInstance().getEventFilter());
347+
Args.clearParam();
348+
}
349+
350+
/**
351+
* Regression: --contract-parse-enable=false must survive the post-CLI
352+
* derivative build that --es triggers. The bean default for contractParse
353+
* is true, so a naive re-apply of the EventConfig bean would clobber the
354+
* CLI override back to true.
355+
*/
356+
@Test
357+
public void testCliContractParseDisableSurvivesEsDerivativeBuild() {
358+
Args.setParam(
359+
new String[] {"--es", "--contract-parse-enable", "false"},
360+
TestConstants.TEST_CONF);
361+
Assert.assertTrue(Args.getInstance().isEventSubscribe());
362+
Assert.assertFalse(Args.getInstance().getStorage().isContractParseSwitch());
344363
Args.clearParam();
345364
}
346365

@@ -454,6 +473,7 @@ public void testEventConfigDisabledSkipsEpcAndFilter() {
454473
Config config = ConfigFactory.parseMap(override)
455474
.withFallback(ConfigFactory.defaultReference());
456475
Args.applyConfigParams(config);
476+
Args.buildEventDerivatives(Args.getEventConfig());
457477
Assert.assertNull(Args.getInstance().getEventPluginConfig());
458478
Assert.assertNull(Args.getInstance().getEventFilter());
459479
Args.clearParam();
@@ -467,6 +487,7 @@ public void testEventConfigEnabledBuildsEpcAndFilter() {
467487
Config config = ConfigFactory.parseMap(override)
468488
.withFallback(ConfigFactory.defaultReference());
469489
Args.applyConfigParams(config);
490+
Args.buildEventDerivatives(Args.getEventConfig());
470491
Assert.assertNotNull(Args.getInstance().getEventPluginConfig());
471492
Assert.assertNotNull(Args.getInstance().getEventFilter());
472493
Args.clearParam();
@@ -481,6 +502,7 @@ public void testEventConfigEnabledWithInvalidFromBlockLeavesFilterNull() {
481502
Config config = ConfigFactory.parseMap(override)
482503
.withFallback(ConfigFactory.defaultReference());
483504
Args.applyConfigParams(config);
505+
Args.buildEventDerivatives(Args.getEventConfig());
484506
// epc still built; filter rejected
485507
Assert.assertNotNull(Args.getInstance().getEventPluginConfig());
486508
Assert.assertNull(Args.getInstance().getEventFilter());

0 commit comments

Comments
 (0)