This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
geyser: allow custom name in config file #33550
Merged
lijunwangs
merged 7 commits into
solana-labs:master
from
fanatid:geyser-multiple-plugins
Dec 5, 2023
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
979ea2a
wrap dyn GeyserPlugin
fanatid b46199b
allow custom name from config
fanatid 69281f8
use String instead of &str
fanatid f5bb21a
rename libname to name
fanatid ccb6061
Merge branch 'master' into geyser-multiple-plugins
fanatid ecdaff6
Merge remote-tracking branch 'upstream/master' into geyser-multiple-p…
fanatid d9932ea
fix setup_logger_for_plugin
fanatid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,48 @@ use { | |
libloading::Library, | ||
log::*, | ||
solana_geyser_plugin_interface::geyser_plugin_interface::GeyserPlugin, | ||
std::path::Path, | ||
std::{ | ||
ops::{Deref, DerefMut}, | ||
path::Path, | ||
}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub struct LoadedGeyserPlugin { | ||
name: String, | ||
plugin: Box<dyn GeyserPlugin>, | ||
} | ||
|
||
impl LoadedGeyserPlugin { | ||
pub fn new(plugin: Box<dyn GeyserPlugin>, name: Option<String>) -> Self { | ||
Self { | ||
name: name.unwrap_or_else(|| plugin.name().to_owned()), | ||
plugin, | ||
} | ||
} | ||
|
||
pub fn name(&self) -> &str { | ||
&self.name | ||
} | ||
} | ||
|
||
impl Deref for LoadedGeyserPlugin { | ||
type Target = Box<dyn GeyserPlugin>; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.plugin | ||
} | ||
} | ||
|
||
impl DerefMut for LoadedGeyserPlugin { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.plugin | ||
} | ||
} | ||
|
||
#[derive(Default, Debug)] | ||
pub struct GeyserPluginManager { | ||
pub plugins: Vec<Box<dyn GeyserPlugin>>, | ||
pub plugins: Vec<LoadedGeyserPlugin>, | ||
libs: Vec<Library>, | ||
} | ||
|
||
|
@@ -264,7 +300,7 @@ pub enum GeyserPluginManagerError { | |
#[cfg(not(test))] | ||
pub(crate) fn load_plugin_from_config( | ||
geyser_plugin_config_file: &Path, | ||
) -> Result<(Box<dyn GeyserPlugin>, Library, &str), GeyserPluginManagerError> { | ||
) -> Result<(LoadedGeyserPlugin, Library, &str), GeyserPluginManagerError> { | ||
use std::{fs::File, io::Read, path::PathBuf}; | ||
type PluginConstructor = unsafe fn() -> *mut dyn GeyserPlugin; | ||
use libloading::Symbol; | ||
|
@@ -307,6 +343,8 @@ pub(crate) fn load_plugin_from_config( | |
libpath = config_dir.join(libpath); | ||
} | ||
|
||
let libname = result["libname"].as_str().map(|s| s.to_owned()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should make it optional now. If it is set in the config file, use it, otherwise old behavior to keep it backward compatible. I would like to still call it "name" instead of libname, we do not care about the libname. The lib path has the libname anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lijunwangs ping :) |
||
|
||
let config_file = geyser_plugin_config_file | ||
.as_os_str() | ||
.to_str() | ||
|
@@ -321,7 +359,7 @@ pub(crate) fn load_plugin_from_config( | |
let plugin_raw = constructor(); | ||
(Box::from_raw(plugin_raw), lib) | ||
}; | ||
Ok((plugin, lib, config_file)) | ||
Ok((LoadedGeyserPlugin::new(plugin, libname), lib, config_file)) | ||
} | ||
|
||
#[cfg(test)] | ||
|
@@ -337,7 +375,7 @@ const TESTPLUGIN2_CONFIG: &str = "TESTPLUGIN2_CONFIG"; | |
#[cfg(test)] | ||
pub(crate) fn load_plugin_from_config( | ||
geyser_plugin_config_file: &Path, | ||
) -> Result<(Box<dyn GeyserPlugin>, Library, &str), GeyserPluginManagerError> { | ||
) -> Result<(LoadedGeyserPlugin, Library, &str), GeyserPluginManagerError> { | ||
if geyser_plugin_config_file.ends_with(TESTPLUGIN_CONFIG) { | ||
Ok(tests::dummy_plugin_and_library( | ||
tests::TestPlugin, | ||
|
@@ -359,7 +397,7 @@ pub(crate) fn load_plugin_from_config( | |
mod tests { | ||
use { | ||
crate::geyser_plugin_manager::{ | ||
GeyserPluginManager, TESTPLUGIN2_CONFIG, TESTPLUGIN_CONFIG, | ||
GeyserPluginManager, LoadedGeyserPlugin, TESTPLUGIN2_CONFIG, TESTPLUGIN_CONFIG, | ||
}, | ||
libloading::Library, | ||
solana_geyser_plugin_interface::geyser_plugin_interface::GeyserPlugin, | ||
|
@@ -369,9 +407,9 @@ mod tests { | |
pub(super) fn dummy_plugin_and_library<P: GeyserPlugin>( | ||
plugin: P, | ||
config_path: &'static str, | ||
) -> (Box<dyn GeyserPlugin>, Library, &'static str) { | ||
) -> (LoadedGeyserPlugin, Library, &'static str) { | ||
( | ||
Box::new(plugin), | ||
LoadedGeyserPlugin::new(Box::new(plugin), None), | ||
Library::from(libloading::os::unix::Library::this()), | ||
config_path, | ||
) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe libname? I do not see how this utilized to solve the problem. We intentionally request the plugin has different names so that load/unload can work reliably. Why cannot you give different names to different plugins?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because for a new name you need to re-compile the whole plugin with hardcoded name in the code 🙂
solana/geyser-plugin-interface/src/geyser_plugin_interface.rs
Line 290 in 666ce9b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this problem can be solved by the plugin itself without the framework's involvement. The &static reference makes it a little tricky but not insurmountable. Here is some sample code to the effect:
This way, you don't have to hard code the plugin name in the code and load it from the config file yourself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha, nice workaround
I think
name()
happens beforeload()
socall_once
should be moved in this casewhile this code probably would work I still think that supporting
libname
through config would be nicefor plugins users, it should be much easier to add one line to config instead of patching the plugin with the proposed code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, confirmed
on_load
is called aftername
, so we can not take the name from the config file in the pluginsolana/geyser-plugin-manager/src/geyser_plugin_manager.rs
Lines 95 to 113 in 64b3613