diff --git a/accounts-db/src/accounts_db/geyser_plugin_utils.rs b/accounts-db/src/accounts_db/geyser_plugin_utils.rs index 8cddf857f1681e..5841b3e7599785 100644 --- a/accounts-db/src/accounts_db/geyser_plugin_utils.rs +++ b/accounts-db/src/accounts_db/geyser_plugin_utils.rs @@ -39,20 +39,21 @@ impl AccountsDb { /// in the reverse order of the slots so that an account is only streamed once. At a slot, if the accounts is updated /// multiple times only the last write (with highest write_version) is notified. pub fn notify_account_restore_from_snapshot(&self) { - if self.accounts_update_notifier.is_none() { + let Some(accounts_update_notifier) = &self.accounts_update_notifier else { 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); + } } - let accounts_update_notifier = self.accounts_update_notifier.as_ref().unwrap(); accounts_update_notifier.notify_end_of_restore_from_snapshot(); notify_stats.report(); } @@ -196,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..ddb81ceb8098a1 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_snapshot_notifications_enabled(); let transaction_notifications_enabled = plugin_manager.transaction_notifications_enabled() || geyser_plugin_always_enabled; let entry_notifications_enabled = @@ -98,8 +100,10 @@ impl GeyserPluginService { let accounts_update_notifier: Option = if account_data_notifications_enabled { - let accounts_update_notifier = - AccountsUpdateNotifierImpl::new(plugin_manager.clone()); + let accounts_update_notifier = AccountsUpdateNotifierImpl::new( + plugin_manager.clone(), + account_data_snapshot_notifications_enabled, + ); Some(Arc::new(accounts_update_notifier)) } else { None