Skip to content

Commit 4036f03

Browse files
authored
fix(config): fix the issue where --es fails to start (#6757)
* fix(config): remove redundant JSON-RPC config fields and consolidate parameter binding Remove maxBlockFilterNum, maxAddressSize, and maxRequestTimeout from NodeConfig/CommonParameter since they were superseded by the jsonRpcMaxBatchSize/jsonRpcMaxResponseSize parameters. Consolidate the config binding path so all JSON-RPC size limits flow through a single reference.conf entry, and clean up stale test-config fixtures. * fix bug of NodeConfigTest * remove allowShieldedTransactionApi from reference.conf * add testcase of external.ip is null * change comment * fix the bug of --es and 7 failed testcases
1 parent 381d369 commit 4036f03

4 files changed

Lines changed: 57 additions & 18 deletions

File tree

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

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,19 @@ public static void setParam(final String[] args, final String confFileName) {
167167
? cmd.shellConfFileName : confFileName;
168168
Config config = Configuration.getByFileName(configFilePath);
169169

170-
// 2. Config overrides defaults
170+
// 2. Config overrides defaults (event config bean is read here but not yet applied)
171171
applyConfigParams(config);
172172

173-
// 3. CLI overrides Config (highest priority)
173+
// 3. CLI overrides Config (highest priority, including --es → eventSubscribe)
174174
applyCLIParams(cmd, jc);
175175

176-
// 4. Apply platform constraints (e.g. ARM64 forces RocksDB)
176+
// 4. Apply event config after CLI
177+
applyEventConfig(eventConfig);
178+
179+
// 5. Apply platform constraints (e.g. ARM64 forces RocksDB)
177180
applyPlatformConstraints();
178181

179-
// 5. Init witness (depends on CLI witness flag)
182+
// 6. Init witness (depends on CLI witness flag)
180183
initLocalWitnesses(config, cmd);
181184
}
182185

@@ -217,7 +220,7 @@ private static void applyStorageConfig(StorageConfig sc) {
217220
PARAMETER.storage.setIndexSwitch(
218221
org.apache.commons.lang3.StringUtils.isNotEmpty(indexSwitch) ? indexSwitch : "on");
219222
PARAMETER.storage.setTransactionHistorySwitch(sc.getTransHistory().getSwitch());
220-
// contractParse is set in applyEventConfig — it belongs to event.subscribe domain
223+
// contractParse is set in applyConfigParams alongside event config, not here
221224
PARAMETER.storage.setCheckpointVersion(sc.getCheckpoint().getVersion());
222225
PARAMETER.storage.setCheckpointSync(sc.getCheckpoint().isSync());
223226

@@ -343,21 +346,21 @@ private static void applyRateLimiterConfig(RateLimiterConfig rl) {
343346
PARAMETER.rateLimiterInitialization = initialization;
344347
}
345348

349+
/**
350+
* Package-private entry point only for tests
351+
*/
352+
static void applyEventConfig() {
353+
applyEventConfig(eventConfig);
354+
}
355+
346356
/**
347357
* Bridge EventConfig bean values to CommonParameter fields.
348358
* Converts EventConfig (raw bean) into EventPluginConfig and FilterQuery (business objects).
349359
*/
350360
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-
355-
// 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()) {
361+
// cmd parameter has higher priority
362+
PARAMETER.eventSubscribe = PARAMETER.eventSubscribe || ec.isEnable();
363+
if (!PARAMETER.eventSubscribe) {
361364
return;
362365
}
363366

@@ -770,9 +773,12 @@ public static void applyConfigParams(
770773

771774
// node.shutdown — handled in applyNodeConfig
772775

773-
// Event config: bind from config.conf "event.subscribe" section
776+
// Event config: read bean here; applyEventConfig() is called once in setParam()
777+
// after applyCLIParams() so that --es is already reflected in eventSubscribe.
774778
eventConfig = EventConfig.fromConfig(config);
775-
applyEventConfig(eventConfig);
779+
// contractParse is event-domain but must be set from config before CLI can
780+
// override it with --contract-parse-enable (which runs in applyCLIParams).
781+
PARAMETER.storage.setContractParseSwitch(eventConfig.isContractParse());
776782

777783
logConfig();
778784
}

framework/src/main/java/org/tron/core/net/peer/PeerConnection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ public class PeerConnection {
170170

171171
public void setChannel(Channel channel) {
172172
this.channel = channel;
173-
if (relayNodes.stream().anyMatch(n -> n.getAddress().equals(channel.getInetAddress()))) {
173+
if (relayNodes != null
174+
&& relayNodes.stream().anyMatch(n -> n.getAddress().equals(channel.getInetAddress()))) {
174175
this.isRelayPeer = true;
175176
}
176177
this.nodeStatistics = TronStatsManager.getNodeStatistics(channel.getInetAddress());

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,21 @@ public void testCliEsOverridesConfig() {
344344
Args.clearParam();
345345
}
346346

347+
/**
348+
* Regression: when --es is the sole source of event.subscribe.enable=true
349+
* (config has it disabled), eventPluginConfig must be built.
350+
* Previously applyEventConfig() ran before applyCLIParams() and returned
351+
* early (both flags false), leaving eventPluginConfig=null; Manager then
352+
* called EventPluginLoader.start(null) and threw "Failed to load eventPlugin."
353+
*/
354+
@Test
355+
public void testCliEsBuildsEventPluginConfig() {
356+
Args.setParam(new String[] {"--es"}, TestConstants.TEST_CONF);
357+
Assert.assertTrue(Args.getInstance().isEventSubscribe());
358+
Assert.assertNotNull(Args.getInstance().getEventPluginConfig());
359+
Args.clearParam();
360+
}
361+
347362
/**
348363
* Verify that config file storage values are applied when no CLI override is present.
349364
*
@@ -454,6 +469,7 @@ public void testEventConfigDisabledSkipsEpcAndFilter() {
454469
Config config = ConfigFactory.parseMap(override)
455470
.withFallback(ConfigFactory.defaultReference());
456471
Args.applyConfigParams(config);
472+
Args.applyEventConfig();
457473
Assert.assertNull(Args.getInstance().getEventPluginConfig());
458474
Assert.assertNull(Args.getInstance().getEventFilter());
459475
Args.clearParam();
@@ -467,6 +483,7 @@ public void testEventConfigEnabledBuildsEpcAndFilter() {
467483
Config config = ConfigFactory.parseMap(override)
468484
.withFallback(ConfigFactory.defaultReference());
469485
Args.applyConfigParams(config);
486+
Args.applyEventConfig();
470487
Assert.assertNotNull(Args.getInstance().getEventPluginConfig());
471488
Assert.assertNotNull(Args.getInstance().getEventFilter());
472489
Args.clearParam();
@@ -481,6 +498,7 @@ public void testEventConfigEnabledWithInvalidFromBlockLeavesFilterNull() {
481498
Config config = ConfigFactory.parseMap(override)
482499
.withFallback(ConfigFactory.defaultReference());
483500
Args.applyConfigParams(config);
501+
Args.applyEventConfig();
484502
// epc still built; filter rejected
485503
Assert.assertNotNull(Args.getInstance().getEventPluginConfig());
486504
Assert.assertNull(Args.getInstance().getEventFilter());

framework/src/test/java/org/tron/core/net/messagehandler/ChainInventoryMsgHandlerTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,32 @@
33
import java.util.ArrayList;
44
import java.util.LinkedList;
55
import java.util.List;
6+
import org.junit.AfterClass;
67
import org.junit.Assert;
8+
import org.junit.BeforeClass;
79
import org.junit.Test;
10+
import org.tron.common.TestConstants;
811
import org.tron.common.utils.Pair;
912
import org.tron.core.capsule.BlockCapsule.BlockId;
1013
import org.tron.core.config.Parameter.NetConstants;
14+
import org.tron.core.config.args.Args;
1115
import org.tron.core.exception.P2pException;
1216
import org.tron.core.net.message.keepalive.PingMessage;
1317
import org.tron.core.net.message.sync.ChainInventoryMessage;
1418
import org.tron.core.net.peer.PeerConnection;
1519

1620
public class ChainInventoryMsgHandlerTest {
1721

22+
@BeforeClass
23+
public static void init() {
24+
Args.setParam(new String[]{}, TestConstants.TEST_CONF);
25+
}
26+
27+
@AfterClass
28+
public static void destroy() {
29+
Args.clearParam();
30+
}
31+
1832
private ChainInventoryMsgHandler handler = new ChainInventoryMsgHandler();
1933
private PeerConnection peer = new PeerConnection();
2034
private ChainInventoryMessage msg = new ChainInventoryMessage(new ArrayList<>(), 0L);

0 commit comments

Comments
 (0)