Skip to content

Commit 8dc3443

Browse files
committed
fix(event): reject incompatible event-plugin versions below 2.0.0
Pre-2.0.0 event-plugin builds still link against com.alibaba.fastjson, which was removed from java-tron in #6701. When such a plugin is loaded, the NoClassDefFoundError surfaces inside the plugin's own worker thread and is swallowed by its catch(Throwable) handler. The node keeps running while silently dropping every trigger, leaving operators with no signal that the event subscription is broken. Enforce a minimum Plugin-Version at startup in EventPluginLoader.startPlugin using pf4j's VersionManager (semver). When the descriptor version is below 2.0.0, log a clear upgrade hint and return false; the existing call chain in Manager.startEventSubscribing wraps that into TronError(EVENT_SUBSCRIBE_INIT) and aborts node startup instead of silently degrading. Add a unit test covering accept/reject boundaries and empty/null versions.
1 parent 0a26d23 commit 8dc3443

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

framework/src/main/java/org/tron/common/logsfilter/EventPluginLoader.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.beust.jcommander.internal.Sets;
44
import com.fasterxml.jackson.core.JsonProcessingException;
55
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import com.google.common.base.Strings;
67
import java.io.File;
78
import java.util.HashSet;
89
import java.util.List;
@@ -14,8 +15,10 @@
1415
import org.bouncycastle.util.encoders.Hex;
1516
import org.pf4j.CompoundPluginDescriptorFinder;
1617
import org.pf4j.DefaultPluginManager;
18+
import org.pf4j.DefaultVersionManager;
1719
import org.pf4j.ManifestPluginDescriptorFinder;
1820
import org.pf4j.PluginManager;
21+
import org.pf4j.VersionManager;
1922
import org.springframework.util.StringUtils;
2023
import org.tron.common.logsfilter.nativequeue.NativeMessageQueue;
2124
import org.tron.common.logsfilter.trigger.BlockLogTrigger;
@@ -29,6 +32,15 @@
2932
@Slf4j
3033
public class EventPluginLoader {
3134

35+
/**
36+
* Minimum event-plugin Plugin-Version compatible with this node. Bumped to 2.0.0 to
37+
* reject pre-fastjson-removal builds whose worker threads would fail with
38+
* NoClassDefFoundError on com.alibaba.fastjson at runtime.
39+
*/
40+
static final String MIN_PLUGIN_VERSION = "2.0.0";
41+
42+
private static final VersionManager VERSION_MANAGER = new DefaultVersionManager();
43+
3244
private static EventPluginLoader instance;
3345

3446
private long MAX_PENDING_SIZE = 50000;
@@ -457,6 +469,14 @@ protected CompoundPluginDescriptorFinder createPluginDescriptorFinder() {
457469
return false;
458470
}
459471

472+
String pluginVersion = pluginManager.getPlugin(pluginId).getDescriptor().getVersion();
473+
if (!isPluginVersionSupported(pluginVersion)) {
474+
logger.error(
475+
"event-plugin '{}' version {} is older than required {}, please upgrade event-plugin",
476+
pluginId, pluginVersion, MIN_PLUGIN_VERSION);
477+
return false;
478+
}
479+
460480
pluginManager.startPlugins();
461481

462482
eventListeners = pluginManager.getExtensions(IPluginEventListener.class);
@@ -471,6 +491,13 @@ protected CompoundPluginDescriptorFinder createPluginDescriptorFinder() {
471491
return true;
472492
}
473493

494+
static boolean isPluginVersionSupported(String pluginVersion) {
495+
if (Strings.isNullOrEmpty(pluginVersion)) {
496+
return false;
497+
}
498+
return VERSION_MANAGER.compareVersions(pluginVersion, MIN_PLUGIN_VERSION) >= 0;
499+
}
500+
474501
public void stopPlugin() {
475502
if (Objects.nonNull(pluginManager)) {
476503
pluginManager.stopPlugins();

framework/src/test/java/org/tron/common/logsfilter/EventLoaderTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ public void launchNativeQueue() {
4848
EventPluginLoader.getInstance().stopPlugin();
4949
}
5050

51+
@Test
52+
public void testIsPluginVersionSupported() {
53+
assertEquals("2.0.0", EventPluginLoader.MIN_PLUGIN_VERSION);
54+
// last release before fastjson removal — must be rejected
55+
assertFalse(EventPluginLoader.isPluginVersionSupported("1.0.0"));
56+
assertFalse(EventPluginLoader.isPluginVersionSupported("1.9.9"));
57+
// 2.0.0 onward — must be accepted
58+
assertTrue(EventPluginLoader.isPluginVersionSupported("2.0.0"));
59+
assertTrue(EventPluginLoader.isPluginVersionSupported("2.1.5"));
60+
assertTrue(EventPluginLoader.isPluginVersionSupported("10.0.0"));
61+
// empty/null version — reject
62+
assertFalse(EventPluginLoader.isPluginVersionSupported(""));
63+
assertFalse(EventPluginLoader.isPluginVersionSupported(null));
64+
}
65+
5166
@Test
5267
public void testBlockLogTrigger() {
5368
BlockLogTrigger blt = new BlockLogTrigger();

0 commit comments

Comments
 (0)