From 0f533466b921d39017224d6e40822713278378d3 Mon Sep 17 00:00:00 2001 From: Vadim <31490938+n00m4d@users.noreply.github.com> Date: Thu, 7 Nov 2024 14:32:34 +0100 Subject: [PATCH] MTG-888 Fix snapshot etl (#84) --- plerkle/src/geyser_plugin_nft.rs | 33 ++++++++++++++++++- .../src/bin/solana-snapshot-etl/main.rs | 2 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/plerkle/src/geyser_plugin_nft.rs b/plerkle/src/geyser_plugin_nft.rs index a8796af..7b99a92 100644 --- a/plerkle/src/geyser_plugin_nft.rs +++ b/plerkle/src/geyser_plugin_nft.rs @@ -98,6 +98,7 @@ pub(crate) struct Plerkle<'a> { account_event_cache: Arc)>>>, transaction_event_cache: Arc)>>>, conf_level: Option, + snapshot_parsing: bool, } trait PlerklePrivateMethods { @@ -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, } } @@ -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"); @@ -784,3 +803,15 @@ pub unsafe extern "C" fn _create_plugin() -> *mut dyn GeyserPlugin { let plugin: Box = 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 = Box::new(plugin); + Box::into_raw(plugin) +} diff --git a/plerkle_snapshot/src/bin/solana-snapshot-etl/main.rs b/plerkle_snapshot/src/bin/solana-snapshot-etl/main.rs index d7c2317..1b1c7c5 100644 --- a/plerkle_snapshot/src/bin/solana-snapshot-etl/main.rs +++ b/plerkle_snapshot/src/bin/solana-snapshot-etl/main.rs @@ -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 = lib.get(b"_create_plugin")?; + let constructor: Symbol = lib.get(b"_create_etl_plugin")?; // Unsafe call down to library. let plugin_raw = constructor(); let mut plugin = Box::from_raw(plugin_raw);