Skip to content

Commit

Permalink
introduce fn account_data_snapshot_notifications_enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Dec 16, 2024
1 parent e73ff18 commit 3d5b2c5
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
12 changes: 7 additions & 5 deletions accounts-db/src/accounts_db/geyser_plugin_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ impl AccountsDb {
return;
};

let mut slots = self.storage.all_slots();
let mut notified_accounts: HashSet<Pubkey> = 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<Pubkey> = 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();
Expand Down
3 changes: 3 additions & 0 deletions accounts-db/src/accounts_update_notifier_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions geyser-plugin-interface/src/geyser_plugin_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 13 additions & 2 deletions geyser-plugin-manager/src/accounts_update_notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ use {
#[derive(Debug)]
pub(crate) struct AccountsUpdateNotifierImpl {
plugin_manager: Arc<RwLock<GeyserPluginManager>>,
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,
Expand Down Expand Up @@ -97,8 +102,14 @@ impl AccountsUpdateNotifierInterface for AccountsUpdateNotifierImpl {
}

impl AccountsUpdateNotifierImpl {
pub fn new(plugin_manager: Arc<RwLock<GeyserPluginManager>>) -> Self {
AccountsUpdateNotifierImpl { plugin_manager }
pub fn new(
plugin_manager: Arc<RwLock<GeyserPluginManager>>,
snapshot_notifications_enabled: bool,
) -> Self {
AccountsUpdateNotifierImpl {
plugin_manager,
snapshot_notifications_enabled,
}
}

fn accountinfo_from_shared_account_data<'a>(
Expand Down
10 changes: 10 additions & 0 deletions geyser-plugin-manager/src/geyser_plugin_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion geyser-plugin-manager/src/geyser_plugin_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -99,7 +101,7 @@ impl GeyserPluginService {
let accounts_update_notifier: Option<AccountsUpdateNotifier> =
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
Expand Down

0 comments on commit 3d5b2c5

Please sign in to comment.