Skip to content

Commit

Permalink
feat: add new Plerkle creation function for etl
Browse files Browse the repository at this point in the history
  • Loading branch information
n00m4d committed Nov 7, 2024
1 parent 93aaacb commit 100dbc9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
35 changes: 33 additions & 2 deletions plerkle/src/geyser_plugin_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub(crate) struct Plerkle<'a> {
account_event_cache: Arc<DashMap<u64, DashMap<Pubkey, (u64, SerializedData<'a>)>>>,
transaction_event_cache: Arc<DashMap<u64, DashMap<Signature, (u64, SerializedData<'a>)>>>,
conf_level: Option<SlotStatus>,
snapshot_parsing: bool,
}

trait PlerklePrivateMethods {
Expand Down Expand Up @@ -195,6 +196,24 @@ impl<'a> Plerkle<'a> {
account_event_cache: Arc::new(DashMap::new()),
transaction_event_cache: Arc::new(DashMap::new()),
conf_level: None,
snapshot_parsing: false,
}
}

pub fn new_for_etl() -> Self {
init_logger();
Plerkle {
runtime: None,
accounts_selector: None,
transaction_selector: None,
sender: None,
started_at: None,
handle_startup: false,
slots_seen: Arc::new(Mutex::new(SlotStore::new())),
account_event_cache: Arc::new(DashMap::new()),
transaction_event_cache: Arc::new(DashMap::new()),
conf_level: None,
snapshot_parsing: true,
}
}

Expand Down Expand Up @@ -477,7 +496,7 @@ impl GeyserPlugin for Plerkle<'static> {
slot: u64,
is_startup: bool,
) -> solana_geyser_plugin_interface::geyser_plugin_interface::Result<()> {
if !self.handle_startup && is_startup {
if !self.snapshot_parsing && !self.handle_startup && is_startup {
return Ok(());
}
let rep: plerkle_serialization::solana_geyser_plugin_interface_shims::ReplicaAccountInfoV2;
Expand Down Expand Up @@ -554,7 +573,7 @@ impl GeyserPlugin for Plerkle<'static> {
let runtime = self.get_runtime()?;
let sender = self.get_sender_clone()?;

if is_startup {
if is_startup || self.snapshot_parsing {
Plerkle::send(sender, runtime, data)?;
} else {
let account_key = Pubkey::try_from(account.pubkey).expect("valid Pubkey");
Expand Down Expand Up @@ -784,3 +803,15 @@ pub unsafe extern "C" fn _create_plugin() -> *mut dyn GeyserPlugin {
let plugin: Box<dyn GeyserPlugin> = Box::new(plugin);
Box::into_raw(plugin)
}

#[no_mangle]
#[allow(improper_ctypes_definitions)]
/// # Safety
///
/// This function returns the GeyserPluginPostgres pointer as trait GeyserPlugin.
/// This binary has to be used for snapshot parsing.
pub unsafe extern "C" fn _create_etl_plugin() -> *mut dyn GeyserPlugin {
let plugin = Plerkle::new_for_etl();
let plugin: Box<dyn GeyserPlugin> = Box::new(plugin);
Box::into_raw(plugin)
}
2 changes: 1 addition & 1 deletion plerkle_snapshot/src/bin/solana-snapshot-etl/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ unsafe fn load_plugin_inner(
type PluginConstructor = unsafe fn() -> *mut dyn GeyserPlugin;
// Load library and leak, as we never want to unload it.
let lib = Box::leak(Box::new(Library::new(libpath)?));
let constructor: Symbol<PluginConstructor> = lib.get(b"_create_plugin")?;
let constructor: Symbol<PluginConstructor> = lib.get(b"_create_etl_plugin")?;
// Unsafe call down to library.
let plugin_raw = constructor();
let mut plugin = Box::from_raw(plugin_raw);
Expand Down

0 comments on commit 100dbc9

Please sign in to comment.