Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.beust.jcommander.internal.Sets;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import java.io.File;
import java.util.HashSet;
import java.util.List;
Expand All @@ -14,8 +15,10 @@
import org.bouncycastle.util.encoders.Hex;
import org.pf4j.CompoundPluginDescriptorFinder;
import org.pf4j.DefaultPluginManager;
import org.pf4j.DefaultVersionManager;
import org.pf4j.ManifestPluginDescriptorFinder;
import org.pf4j.PluginManager;
import org.pf4j.VersionManager;
import org.springframework.util.StringUtils;
import org.tron.common.logsfilter.nativequeue.NativeMessageQueue;
import org.tron.common.logsfilter.trigger.BlockLogTrigger;
Expand All @@ -29,6 +32,16 @@
@Slf4j
public class EventPluginLoader {

/**
* Minimum event-plugin Plugin-Version compatible with this node. Bumped to 3.0.0 to
* reject pre-fastjson-removal builds whose worker threads would fail with
* NoClassDefFoundError on com.alibaba.fastjson at runtime. The previous event-plugin
* release is 2.2.0, so 3.0.0 is the first version that ships the Jackson replacement.
*/
static final String MIN_PLUGIN_VERSION = "3.0.0";

private static final VersionManager VERSION_MANAGER = new DefaultVersionManager();

private static EventPluginLoader instance;

private long MAX_PENDING_SIZE = 50000;
Expand Down Expand Up @@ -457,6 +470,10 @@ protected CompoundPluginDescriptorFinder createPluginDescriptorFinder() {
return false;
}

if (!isPluginVersionSupported(pluginManager, pluginId)) {
return false;
}

pluginManager.startPlugins();

eventListeners = pluginManager.getExtensions(IPluginEventListener.class);
Expand All @@ -471,6 +488,21 @@ protected CompoundPluginDescriptorFinder createPluginDescriptorFinder() {
return true;
}

static boolean isPluginVersionSupported(PluginManager pm, String pluginId) {
String pluginVersion = pm.getPlugin(pluginId).getDescriptor().getVersion();
if (Strings.isNullOrEmpty(pluginVersion)) {
return false;
}
boolean isSupported = VERSION_MANAGER.compareVersions(pluginVersion, MIN_PLUGIN_VERSION) >= 0;

if (!isSupported) {
logger.error(
"event-plugin '{}' version {} is older than required {}, please upgrade event-plugin",
pluginId, pluginVersion, MIN_PLUGIN_VERSION);
}
return isSupported;
}

public void stopPlugin() {
if (Objects.nonNull(pluginManager)) {
pluginManager.stopPlugins();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.pf4j.PluginDescriptor;
import org.pf4j.PluginManager;
import org.pf4j.PluginWrapper;
import org.tron.common.logsfilter.trigger.BlockLogTrigger;
import org.tron.common.logsfilter.trigger.TransactionLogTrigger;

Expand Down Expand Up @@ -48,6 +53,32 @@ public void launchNativeQueue() {
EventPluginLoader.getInstance().stopPlugin();
}

@Test
public void testIsPluginVersionSupported() {
assertEquals("3.0.0", EventPluginLoader.MIN_PLUGIN_VERSION);
// last releases before fastjson removal — must be rejected
assertFalse(checkVersion("1.0.0"));
assertFalse(checkVersion("2.2.0"));
assertFalse(checkVersion("2.9.9"));
// 3.0.0 onward — must be accepted
assertTrue(checkVersion("3.0.0"));
assertTrue(checkVersion("3.1.5"));
assertTrue(checkVersion("10.0.0"));
// empty/null version — reject
assertFalse(checkVersion(""));
assertFalse(checkVersion(null));
}

private static boolean checkVersion(String version) {
PluginManager pm = mock(PluginManager.class);
PluginWrapper wrapper = mock(PluginWrapper.class);
PluginDescriptor desc = mock(PluginDescriptor.class);
when(pm.getPlugin("test")).thenReturn(wrapper);
when(wrapper.getDescriptor()).thenReturn(desc);
when(desc.getVersion()).thenReturn(version);
return EventPluginLoader.isPluginVersionSupported(pm, "test");
}

@Test
public void testBlockLogTrigger() {
BlockLogTrigger blt = new BlockLogTrigger();
Expand Down
Loading