Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 41 additions & 21 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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.
*
* <p>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.</p>
*/
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;
}

Expand Down Expand Up @@ -706,6 +718,13 @@ private static void applyPlatformConstraints() {

/**
* Apply parameters from config file.
*
* <p>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.</p>
*/
public static void applyConfigParams(
final Config config) {
Expand Down Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -1001,7 +1022,7 @@ public static List<InetSocketAddress> filterInetSocketAddress(

// getInetAddress removed — use filterInetSocketAddress

// getEventPluginConfig removed — logic moved to applyEventConfig()
// getEventPluginConfig removed — logic moved to buildEventDerivatives()


public static PublishConfig loadDnsPublishConfig(NodeConfig nodeConfig) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1333,4 +1354,3 @@ private static Map<String, String[]> getOptionGroup() {
return optionGroupMap;
}
}

24 changes: 23 additions & 1 deletion framework/src/test/java/org/tron/core/config/args/ArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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());
Expand Down
Loading