Skip to content

Commit

Permalink
geyser: add flag geyser-plugin-snapshot-disabled (#4103)
Browse files Browse the repository at this point in the history
* geyser: add flag `geyser-plugin-snapshot-disabled`

* early exit

* revert cli flag

* introduce fn account_data_snapshot_notifications_enabled

* Update geyser-plugin-manager/src/geyser_plugin_service.rs

Co-authored-by: Lijun Wang <[email protected]>

---------

Co-authored-by: Lijun Wang <[email protected]>
  • Loading branch information
fanatid and lijunwangs authored Dec 19, 2024
1 parent 4bb6c4a commit 22c8951
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 12 deletions.
21 changes: 13 additions & 8 deletions accounts-db/src/accounts_db/geyser_plugin_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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);
}
}

let accounts_update_notifier = self.accounts_update_notifier.as_ref().unwrap();
accounts_update_notifier.notify_end_of_restore_from_snapshot();
notify_stats.report();
}
Expand Down Expand Up @@ -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,
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
8 changes: 6 additions & 2 deletions 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_snapshot_notifications_enabled();
let transaction_notifications_enabled =
plugin_manager.transaction_notifications_enabled() || geyser_plugin_always_enabled;
let entry_notifications_enabled =
Expand All @@ -98,8 +100,10 @@ impl GeyserPluginService {

let accounts_update_notifier: Option<AccountsUpdateNotifier> =
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
Expand Down

0 comments on commit 22c8951

Please sign in to comment.