From 526eef9988ee7902cc00bcae347361bca91f3ddb Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Sat, 7 Dec 2024 09:34:04 -0500 Subject: [PATCH 1/5] geyser: add flag `geyser-plugin-snapshot-disabled` --- .../src/accounts_db/geyser_plugin_utils.rs | 34 +++++++++++-------- .../src/accounts_update_notifier_interface.rs | 3 ++ core/src/validator.rs | 3 ++ .../src/accounts_update_notifier.rs | 12 +++++-- .../src/geyser_plugin_service.rs | 9 +++-- ledger-tool/src/ledger_utils.rs | 2 +- local-cluster/src/validator_configs.rs | 1 + validator/src/cli.rs | 7 ++++ validator/src/main.rs | 1 + 9 files changed, 53 insertions(+), 19 deletions(-) diff --git a/accounts-db/src/accounts_db/geyser_plugin_utils.rs b/accounts-db/src/accounts_db/geyser_plugin_utils.rs index 8cddf857f1681e..341cd3dd82486d 100644 --- a/accounts-db/src/accounts_db/geyser_plugin_utils.rs +++ b/accounts-db/src/accounts_db/geyser_plugin_utils.rs @@ -39,22 +39,23 @@ 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() { - return; - } - - let mut slots = self.storage.all_slots(); - let mut notified_accounts: HashSet = HashSet::default(); - let mut notify_stats = GeyserPluginNotifyAtSnapshotRestoreStats::default(); + if let Some(accounts_update_notifier) = &self.accounts_update_notifier { + if accounts_update_notifier.notify_snapshot_disabled() { + accounts_update_notifier.notify_end_of_restore_from_snapshot(); + } else { + let mut slots = self.storage.all_slots(); + let mut notified_accounts: HashSet = HashSet::default(); + let mut notify_stats = GeyserPluginNotifyAtSnapshotRestoreStats::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(); + notify_stats.report(); + } } - - let accounts_update_notifier = self.accounts_update_notifier.as_ref().unwrap(); - accounts_update_notifier.notify_end_of_restore_from_snapshot(); - notify_stats.report(); } pub fn notify_account_at_accounts_update( @@ -196,6 +197,11 @@ pub mod tests { } impl AccountsUpdateNotifierInterface for GeyserTestPlugin { + /// Disable account notifications from snapshot + fn notify_snapshot_disabled(&self) -> bool { + false + } + /// 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..de2fe9989b035b 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 { + /// Disable account notifications from snapshot + fn notify_snapshot_disabled(&self) -> bool; + /// Notified when an account is updated at runtime, due to transaction activities fn notify_account_update( &self, diff --git a/core/src/validator.rs b/core/src/validator.rs index c3318ee070f2bc..dc74dd226c201b 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -227,6 +227,7 @@ pub struct ValidatorConfig { /// Specifies which plugins to start up with pub on_start_geyser_plugin_config_files: Option>, pub geyser_plugin_always_enabled: bool, + pub geyser_plugin_snapshot_disabled: bool, pub rpc_addrs: Option<(SocketAddr, SocketAddr)>, // (JsonRpc, JsonRpcPubSub) pub pubsub_config: PubSubConfig, pub snapshot_config: SnapshotConfig, @@ -303,6 +304,7 @@ impl Default for ValidatorConfig { rpc_config: JsonRpcConfig::default(), on_start_geyser_plugin_config_files: None, geyser_plugin_always_enabled: false, + geyser_plugin_snapshot_disabled: false, rpc_addrs: None, pubsub_config: PubSubConfig::default(), snapshot_config: SnapshotConfig::new_load_only(), @@ -602,6 +604,7 @@ impl Validator { GeyserPluginService::new_with_receiver( confirmed_bank_receiver, config.geyser_plugin_always_enabled, + config.geyser_plugin_snapshot_disabled, geyser_plugin_config_files.as_ref(), rpc_to_plugin_manager_receiver_and_exit, ) diff --git a/geyser-plugin-manager/src/accounts_update_notifier.rs b/geyser-plugin-manager/src/accounts_update_notifier.rs index 60df441a7e3cef..6f7a58b1499fab 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_disabled: bool, } impl AccountsUpdateNotifierInterface for AccountsUpdateNotifierImpl { + fn notify_snapshot_disabled(&self) -> bool { + self.snapshot_disabled + } + fn notify_account_update( &self, slot: Slot, @@ -97,8 +102,11 @@ impl AccountsUpdateNotifierInterface for AccountsUpdateNotifierImpl { } impl AccountsUpdateNotifierImpl { - pub fn new(plugin_manager: Arc>) -> Self { - AccountsUpdateNotifierImpl { plugin_manager } + pub fn new(plugin_manager: Arc>, snapshot_disabled: bool) -> Self { + AccountsUpdateNotifierImpl { + plugin_manager, + snapshot_disabled, + } } fn accountinfo_from_shared_account_data<'a>( diff --git a/geyser-plugin-manager/src/geyser_plugin_service.rs b/geyser-plugin-manager/src/geyser_plugin_service.rs index f624fc66c90c3e..4a2959364cc232 100644 --- a/geyser-plugin-manager/src/geyser_plugin_service.rs +++ b/geyser-plugin-manager/src/geyser_plugin_service.rs @@ -59,11 +59,13 @@ impl GeyserPluginService { pub fn new( confirmed_bank_receiver: Receiver, geyser_plugin_always_enabled: bool, + geyser_plugin_snapshot_disabled: bool, geyser_plugin_config_files: &[PathBuf], ) -> Result { Self::new_with_receiver( confirmed_bank_receiver, geyser_plugin_always_enabled, + geyser_plugin_snapshot_disabled, geyser_plugin_config_files, None, ) @@ -72,6 +74,7 @@ impl GeyserPluginService { pub fn new_with_receiver( confirmed_bank_receiver: Receiver, geyser_plugin_always_enabled: bool, + geyser_plugin_snapshot_disabled: bool, geyser_plugin_config_files: &[PathBuf], rpc_to_plugin_manager_receiver_and_exit: Option<( Receiver, @@ -98,8 +101,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(), + geyser_plugin_snapshot_disabled, + ); Some(Arc::new(accounts_update_notifier)) } else { None diff --git a/ledger-tool/src/ledger_utils.rs b/ledger-tool/src/ledger_utils.rs index 58c2a54f725055..78bbb5f3efaf43 100644 --- a/ledger-tool/src/ledger_utils.rs +++ b/ledger-tool/src/ledger_utils.rs @@ -275,7 +275,7 @@ pub fn load_and_process_ledger( let (confirmed_bank_sender, confirmed_bank_receiver) = unbounded(); drop(confirmed_bank_sender); let geyser_service = - GeyserPluginService::new(confirmed_bank_receiver, false, &geyser_config_files) + GeyserPluginService::new(confirmed_bank_receiver, false, false, &geyser_config_files) .map_err(LoadAndProcessLedgerError::GeyserServiceSetup)?; ( geyser_service.get_accounts_update_notifier(), diff --git a/local-cluster/src/validator_configs.rs b/local-cluster/src/validator_configs.rs index e90475aad2a06f..ddf4cfb3e18778 100644 --- a/local-cluster/src/validator_configs.rs +++ b/local-cluster/src/validator_configs.rs @@ -16,6 +16,7 @@ pub fn safe_clone_config(config: &ValidatorConfig) -> ValidatorConfig { rpc_config: config.rpc_config.clone(), on_start_geyser_plugin_config_files: config.on_start_geyser_plugin_config_files.clone(), geyser_plugin_always_enabled: config.geyser_plugin_always_enabled, + geyser_plugin_snapshot_disabled: config.geyser_plugin_snapshot_disabled, rpc_addrs: config.rpc_addrs, pubsub_config: config.pubsub_config.clone(), snapshot_config: config.snapshot_config.clone(), diff --git a/validator/src/cli.rs b/validator/src/cli.rs index aed7a3bffc1d9f..bdc95b2efc0272 100644 --- a/validator/src/cli.rs +++ b/validator/src/cli.rs @@ -1201,6 +1201,13 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> { .takes_value(false) .help("Еnable Geyser interface even if no Geyser configs are specified."), ) + .arg( + Arg::with_name("geyser_plugin_snapshot_disabled") + .long("geyser-plugin-snapshot-disabled") + .value_name("BOOLEAN") + .takes_value(false) + .help("Disable on startup account notifications from snapshot."), + ) .arg( Arg::with_name("snapshot_archive_format") .long("snapshot-archive-format") diff --git a/validator/src/main.rs b/validator/src/main.rs index a7de615b3be9ac..33e133243d23ec 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -1504,6 +1504,7 @@ pub fn main() { }, on_start_geyser_plugin_config_files, geyser_plugin_always_enabled: matches.is_present("geyser_plugin_always_enabled"), + geyser_plugin_snapshot_disabled: matches.is_present("geyser_plugin_snapshot_disabled"), rpc_addrs: value_t!(matches, "rpc_port", u16).ok().map(|rpc_port| { ( SocketAddr::new(rpc_bind_address, rpc_port), From 251612bb42bf20a15eac1f1c5aeb1f39a09e7131 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Mon, 16 Dec 2024 09:17:28 -0500 Subject: [PATCH 2/5] early exit --- .../src/accounts_db/geyser_plugin_utils.rs | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/accounts-db/src/accounts_db/geyser_plugin_utils.rs b/accounts-db/src/accounts_db/geyser_plugin_utils.rs index 341cd3dd82486d..8dbba07aa3ca44 100644 --- a/accounts-db/src/accounts_db/geyser_plugin_utils.rs +++ b/accounts-db/src/accounts_db/geyser_plugin_utils.rs @@ -39,22 +39,24 @@ 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 let Some(accounts_update_notifier) = &self.accounts_update_notifier { - if accounts_update_notifier.notify_snapshot_disabled() { - accounts_update_notifier.notify_end_of_restore_from_snapshot(); - } else { - let mut slots = self.storage.all_slots(); - let mut notified_accounts: HashSet = HashSet::default(); - let mut notify_stats = GeyserPluginNotifyAtSnapshotRestoreStats::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); - } - - accounts_update_notifier.notify_end_of_restore_from_snapshot(); - notify_stats.report(); + let Some(accounts_update_notifier) = &self.accounts_update_notifier else { + return; + }; + + if accounts_update_notifier.notify_snapshot_disabled() { + accounts_update_notifier.notify_end_of_restore_from_snapshot(); + } else { + let mut slots = self.storage.all_slots(); + let mut notified_accounts: HashSet = HashSet::default(); + let mut notify_stats = GeyserPluginNotifyAtSnapshotRestoreStats::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); } + + accounts_update_notifier.notify_end_of_restore_from_snapshot(); + notify_stats.report(); } } From e73ff18745333911d55b854f78742fa9c7cac944 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Mon, 16 Dec 2024 16:29:26 -0500 Subject: [PATCH 3/5] revert cli flag --- .../src/accounts_db/geyser_plugin_utils.rs | 27 +++++++------------ .../src/accounts_update_notifier_interface.rs | 3 --- core/src/validator.rs | 3 --- .../src/accounts_update_notifier.rs | 12 ++------- .../src/geyser_plugin_service.rs | 9 ++----- ledger-tool/src/ledger_utils.rs | 2 +- local-cluster/src/validator_configs.rs | 1 - validator/src/cli.rs | 7 ----- validator/src/main.rs | 1 - 9 files changed, 14 insertions(+), 51 deletions(-) diff --git a/accounts-db/src/accounts_db/geyser_plugin_utils.rs b/accounts-db/src/accounts_db/geyser_plugin_utils.rs index 8dbba07aa3ca44..96b6e9c1245a2b 100644 --- a/accounts-db/src/accounts_db/geyser_plugin_utils.rs +++ b/accounts-db/src/accounts_db/geyser_plugin_utils.rs @@ -43,21 +43,17 @@ impl AccountsDb { return; }; - if accounts_update_notifier.notify_snapshot_disabled() { - accounts_update_notifier.notify_end_of_restore_from_snapshot(); - } else { - let mut slots = self.storage.all_slots(); - let mut notified_accounts: HashSet = HashSet::default(); - let mut notify_stats = GeyserPluginNotifyAtSnapshotRestoreStats::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); - } + let mut slots = self.storage.all_slots(); + let mut notified_accounts: HashSet = HashSet::default(); + let mut notify_stats = GeyserPluginNotifyAtSnapshotRestoreStats::default(); - accounts_update_notifier.notify_end_of_restore_from_snapshot(); - notify_stats.report(); + 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(); + notify_stats.report(); } pub fn notify_account_at_accounts_update( @@ -199,11 +195,6 @@ pub mod tests { } impl AccountsUpdateNotifierInterface for GeyserTestPlugin { - /// Disable account notifications from snapshot - fn notify_snapshot_disabled(&self) -> bool { - false - } - /// 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 de2fe9989b035b..ec86fce8cd6898 100644 --- a/accounts-db/src/accounts_update_notifier_interface.rs +++ b/accounts-db/src/accounts_update_notifier_interface.rs @@ -7,9 +7,6 @@ use { }; pub trait AccountsUpdateNotifierInterface: std::fmt::Debug { - /// Disable account notifications from snapshot - fn notify_snapshot_disabled(&self) -> bool; - /// Notified when an account is updated at runtime, due to transaction activities fn notify_account_update( &self, diff --git a/core/src/validator.rs b/core/src/validator.rs index dc74dd226c201b..c3318ee070f2bc 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -227,7 +227,6 @@ pub struct ValidatorConfig { /// Specifies which plugins to start up with pub on_start_geyser_plugin_config_files: Option>, pub geyser_plugin_always_enabled: bool, - pub geyser_plugin_snapshot_disabled: bool, pub rpc_addrs: Option<(SocketAddr, SocketAddr)>, // (JsonRpc, JsonRpcPubSub) pub pubsub_config: PubSubConfig, pub snapshot_config: SnapshotConfig, @@ -304,7 +303,6 @@ impl Default for ValidatorConfig { rpc_config: JsonRpcConfig::default(), on_start_geyser_plugin_config_files: None, geyser_plugin_always_enabled: false, - geyser_plugin_snapshot_disabled: false, rpc_addrs: None, pubsub_config: PubSubConfig::default(), snapshot_config: SnapshotConfig::new_load_only(), @@ -604,7 +602,6 @@ impl Validator { GeyserPluginService::new_with_receiver( confirmed_bank_receiver, config.geyser_plugin_always_enabled, - config.geyser_plugin_snapshot_disabled, geyser_plugin_config_files.as_ref(), rpc_to_plugin_manager_receiver_and_exit, ) diff --git a/geyser-plugin-manager/src/accounts_update_notifier.rs b/geyser-plugin-manager/src/accounts_update_notifier.rs index 6f7a58b1499fab..60df441a7e3cef 100644 --- a/geyser-plugin-manager/src/accounts_update_notifier.rs +++ b/geyser-plugin-manager/src/accounts_update_notifier.rs @@ -22,14 +22,9 @@ use { #[derive(Debug)] pub(crate) struct AccountsUpdateNotifierImpl { plugin_manager: Arc>, - snapshot_disabled: bool, } impl AccountsUpdateNotifierInterface for AccountsUpdateNotifierImpl { - fn notify_snapshot_disabled(&self) -> bool { - self.snapshot_disabled - } - fn notify_account_update( &self, slot: Slot, @@ -102,11 +97,8 @@ impl AccountsUpdateNotifierInterface for AccountsUpdateNotifierImpl { } impl AccountsUpdateNotifierImpl { - pub fn new(plugin_manager: Arc>, snapshot_disabled: bool) -> Self { - AccountsUpdateNotifierImpl { - plugin_manager, - snapshot_disabled, - } + pub fn new(plugin_manager: Arc>) -> Self { + AccountsUpdateNotifierImpl { plugin_manager } } fn accountinfo_from_shared_account_data<'a>( diff --git a/geyser-plugin-manager/src/geyser_plugin_service.rs b/geyser-plugin-manager/src/geyser_plugin_service.rs index 4a2959364cc232..f624fc66c90c3e 100644 --- a/geyser-plugin-manager/src/geyser_plugin_service.rs +++ b/geyser-plugin-manager/src/geyser_plugin_service.rs @@ -59,13 +59,11 @@ impl GeyserPluginService { pub fn new( confirmed_bank_receiver: Receiver, geyser_plugin_always_enabled: bool, - geyser_plugin_snapshot_disabled: bool, geyser_plugin_config_files: &[PathBuf], ) -> Result { Self::new_with_receiver( confirmed_bank_receiver, geyser_plugin_always_enabled, - geyser_plugin_snapshot_disabled, geyser_plugin_config_files, None, ) @@ -74,7 +72,6 @@ impl GeyserPluginService { pub fn new_with_receiver( confirmed_bank_receiver: Receiver, geyser_plugin_always_enabled: bool, - geyser_plugin_snapshot_disabled: bool, geyser_plugin_config_files: &[PathBuf], rpc_to_plugin_manager_receiver_and_exit: Option<( Receiver, @@ -101,10 +98,8 @@ impl GeyserPluginService { let accounts_update_notifier: Option = if account_data_notifications_enabled { - let accounts_update_notifier = AccountsUpdateNotifierImpl::new( - plugin_manager.clone(), - geyser_plugin_snapshot_disabled, - ); + let accounts_update_notifier = + AccountsUpdateNotifierImpl::new(plugin_manager.clone()); Some(Arc::new(accounts_update_notifier)) } else { None diff --git a/ledger-tool/src/ledger_utils.rs b/ledger-tool/src/ledger_utils.rs index 78bbb5f3efaf43..58c2a54f725055 100644 --- a/ledger-tool/src/ledger_utils.rs +++ b/ledger-tool/src/ledger_utils.rs @@ -275,7 +275,7 @@ pub fn load_and_process_ledger( let (confirmed_bank_sender, confirmed_bank_receiver) = unbounded(); drop(confirmed_bank_sender); let geyser_service = - GeyserPluginService::new(confirmed_bank_receiver, false, false, &geyser_config_files) + GeyserPluginService::new(confirmed_bank_receiver, false, &geyser_config_files) .map_err(LoadAndProcessLedgerError::GeyserServiceSetup)?; ( geyser_service.get_accounts_update_notifier(), diff --git a/local-cluster/src/validator_configs.rs b/local-cluster/src/validator_configs.rs index ddf4cfb3e18778..e90475aad2a06f 100644 --- a/local-cluster/src/validator_configs.rs +++ b/local-cluster/src/validator_configs.rs @@ -16,7 +16,6 @@ pub fn safe_clone_config(config: &ValidatorConfig) -> ValidatorConfig { rpc_config: config.rpc_config.clone(), on_start_geyser_plugin_config_files: config.on_start_geyser_plugin_config_files.clone(), geyser_plugin_always_enabled: config.geyser_plugin_always_enabled, - geyser_plugin_snapshot_disabled: config.geyser_plugin_snapshot_disabled, rpc_addrs: config.rpc_addrs, pubsub_config: config.pubsub_config.clone(), snapshot_config: config.snapshot_config.clone(), diff --git a/validator/src/cli.rs b/validator/src/cli.rs index bdc95b2efc0272..aed7a3bffc1d9f 100644 --- a/validator/src/cli.rs +++ b/validator/src/cli.rs @@ -1201,13 +1201,6 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> { .takes_value(false) .help("Еnable Geyser interface even if no Geyser configs are specified."), ) - .arg( - Arg::with_name("geyser_plugin_snapshot_disabled") - .long("geyser-plugin-snapshot-disabled") - .value_name("BOOLEAN") - .takes_value(false) - .help("Disable on startup account notifications from snapshot."), - ) .arg( Arg::with_name("snapshot_archive_format") .long("snapshot-archive-format") diff --git a/validator/src/main.rs b/validator/src/main.rs index 33e133243d23ec..a7de615b3be9ac 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -1504,7 +1504,6 @@ pub fn main() { }, on_start_geyser_plugin_config_files, geyser_plugin_always_enabled: matches.is_present("geyser_plugin_always_enabled"), - geyser_plugin_snapshot_disabled: matches.is_present("geyser_plugin_snapshot_disabled"), rpc_addrs: value_t!(matches, "rpc_port", u16).ok().map(|rpc_port| { ( SocketAddr::new(rpc_bind_address, rpc_port), From b7801eef055138cb2ca44eaf20b8258da286eaed Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Mon, 16 Dec 2024 16:42:42 -0500 Subject: [PATCH 4/5] 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 | 8 ++++++-- 6 files changed, 51 insertions(+), 9 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..eded5ee097e3ea 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 = @@ -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 From e56827e156286f551f853d593f6f8ee9b2c0f24f Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Wed, 18 Dec 2024 19:03:31 -0500 Subject: [PATCH 5/5] Update geyser-plugin-manager/src/geyser_plugin_service.rs Co-authored-by: Lijun Wang <83639177+lijunwangs@users.noreply.github.com> --- geyser-plugin-manager/src/geyser_plugin_service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geyser-plugin-manager/src/geyser_plugin_service.rs b/geyser-plugin-manager/src/geyser_plugin_service.rs index eded5ee097e3ea..ddb81ceb8098a1 100644 --- a/geyser-plugin-manager/src/geyser_plugin_service.rs +++ b/geyser-plugin-manager/src/geyser_plugin_service.rs @@ -91,7 +91,7 @@ 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(); + plugin_manager.account_data_snapshot_notifications_enabled(); let transaction_notifications_enabled = plugin_manager.transaction_notifications_enabled() || geyser_plugin_always_enabled; let entry_notifications_enabled =