From 7acf15c30444d635eb2f29d2f46c53863d8a9615 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Mon, 16 Dec 2024 16:42:42 -0500 Subject: [PATCH] introduce fn account_data_snapshot_notifications_enabled --- .../src/accounts_db/geyser_plugin_utils.rs | 16 +++++++++++----- .../src/accounts_update_notifier_interface.rs | 3 +++ .../src/geyser_plugin_interface.rs | 8 ++++++++ .../src/accounts_update_notifier.rs | 15 +++++++++++++-- .../src/geyser_plugin_manager.rs | 10 ++++++++++ .../src/geyser_plugin_service.rs | 4 +++- 6 files changed, 48 insertions(+), 8 deletions(-) diff --git a/accounts-db/src/accounts_db/geyser_plugin_utils.rs b/accounts-db/src/accounts_db/geyser_plugin_utils.rs index 96b6e9c1245a2b..5841b3e7599785 100644 --- a/accounts-db/src/accounts_db/geyser_plugin_utils.rs +++ b/accounts-db/src/accounts_db/geyser_plugin_utils.rs @@ -43,13 +43,15 @@ impl AccountsDb { return; }; - let mut slots = self.storage.all_slots(); - let mut notified_accounts: HashSet = HashSet::default(); let mut notify_stats = GeyserPluginNotifyAtSnapshotRestoreStats::default(); + if accounts_update_notifier.snapshot_notifications_enabled() { + let mut slots = self.storage.all_slots(); + let mut notified_accounts: HashSet = HashSet::default(); - slots.sort_by(|a, b| b.cmp(a)); - for slot in slots { - self.notify_accounts_in_slot(slot, &mut notified_accounts, &mut notify_stats); + slots.sort_by(|a, b| b.cmp(a)); + for slot in slots { + self.notify_accounts_in_slot(slot, &mut notified_accounts, &mut notify_stats); + } } accounts_update_notifier.notify_end_of_restore_from_snapshot(); @@ -195,6 +197,10 @@ pub mod tests { } impl AccountsUpdateNotifierInterface for GeyserTestPlugin { + fn snapshot_notifications_enabled(&self) -> bool { + true + } + /// Notified when an account is updated at runtime, due to transaction activities fn notify_account_update( &self, diff --git a/accounts-db/src/accounts_update_notifier_interface.rs b/accounts-db/src/accounts_update_notifier_interface.rs index ec86fce8cd6898..165c98f9fcaa39 100644 --- a/accounts-db/src/accounts_update_notifier_interface.rs +++ b/accounts-db/src/accounts_update_notifier_interface.rs @@ -7,6 +7,9 @@ use { }; pub trait AccountsUpdateNotifierInterface: std::fmt::Debug { + /// Enable account notifications from snapshot + fn snapshot_notifications_enabled(&self) -> bool; + /// Notified when an account is updated at runtime, due to transaction activities fn notify_account_update( &self, diff --git a/geyser-plugin-interface/src/geyser_plugin_interface.rs b/geyser-plugin-interface/src/geyser_plugin_interface.rs index 0cfff715a7d82b..c79513c0a1adf5 100644 --- a/geyser-plugin-interface/src/geyser_plugin_interface.rs +++ b/geyser-plugin-interface/src/geyser_plugin_interface.rs @@ -457,6 +457,14 @@ pub trait GeyserPlugin: Any + Send + Sync + std::fmt::Debug { true } + /// Check if the plugin is interested in account data from snapshot + /// Default is true -- if the plugin is not interested in + /// account data snapshot, please return false because startup would be + /// improved significantly. + fn account_data_snapshot_notifications_enabled(&self) -> bool { + true + } + /// Check if the plugin is interested in transaction data /// Default is false -- if the plugin is interested in /// transaction data, please return true. diff --git a/geyser-plugin-manager/src/accounts_update_notifier.rs b/geyser-plugin-manager/src/accounts_update_notifier.rs index 60df441a7e3cef..98e43987df5fea 100644 --- a/geyser-plugin-manager/src/accounts_update_notifier.rs +++ b/geyser-plugin-manager/src/accounts_update_notifier.rs @@ -22,9 +22,14 @@ use { #[derive(Debug)] pub(crate) struct AccountsUpdateNotifierImpl { plugin_manager: Arc>, + snapshot_notifications_enabled: bool, } impl AccountsUpdateNotifierInterface for AccountsUpdateNotifierImpl { + fn snapshot_notifications_enabled(&self) -> bool { + self.snapshot_notifications_enabled + } + fn notify_account_update( &self, slot: Slot, @@ -97,8 +102,14 @@ impl AccountsUpdateNotifierInterface for AccountsUpdateNotifierImpl { } impl AccountsUpdateNotifierImpl { - pub fn new(plugin_manager: Arc>) -> Self { - AccountsUpdateNotifierImpl { plugin_manager } + pub fn new( + plugin_manager: Arc>, + snapshot_notifications_enabled: bool, + ) -> Self { + AccountsUpdateNotifierImpl { + plugin_manager, + snapshot_notifications_enabled, + } } fn accountinfo_from_shared_account_data<'a>( diff --git a/geyser-plugin-manager/src/geyser_plugin_manager.rs b/geyser-plugin-manager/src/geyser_plugin_manager.rs index beaa799109b5d7..1e4fb7dbba0aef 100644 --- a/geyser-plugin-manager/src/geyser_plugin_manager.rs +++ b/geyser-plugin-manager/src/geyser_plugin_manager.rs @@ -85,6 +85,16 @@ impl GeyserPluginManager { false } + /// Check if there is any plugin interested in account data from snapshot + pub fn account_data_snapshot_notifications_enabled(&self) -> bool { + for plugin in &self.plugins { + if plugin.account_data_snapshot_notifications_enabled() { + return true; + } + } + false + } + /// Check if there is any plugin interested in transaction data pub fn transaction_notifications_enabled(&self) -> bool { for plugin in &self.plugins { diff --git a/geyser-plugin-manager/src/geyser_plugin_service.rs b/geyser-plugin-manager/src/geyser_plugin_service.rs index f624fc66c90c3e..6eabea37ed61a9 100644 --- a/geyser-plugin-manager/src/geyser_plugin_service.rs +++ b/geyser-plugin-manager/src/geyser_plugin_service.rs @@ -90,6 +90,8 @@ impl GeyserPluginService { let account_data_notifications_enabled = plugin_manager.account_data_notifications_enabled() || geyser_plugin_always_enabled; + let account_data_snapshot_notifications_enabled = + plugin_manager.account_data_notifications_enabled(); let transaction_notifications_enabled = plugin_manager.transaction_notifications_enabled() || geyser_plugin_always_enabled; let entry_notifications_enabled = @@ -99,7 +101,7 @@ impl GeyserPluginService { let accounts_update_notifier: Option = if account_data_notifications_enabled { let accounts_update_notifier = - AccountsUpdateNotifierImpl::new(plugin_manager.clone()); + AccountsUpdateNotifierImpl::new(plugin_manager.clone(), account_data_snapshot_notifications_enabled); Some(Arc::new(accounts_update_notifier)) } else { None