forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor slot status notification to decouple from accounts notificat…
…ions (solana-labs#21308) Problem Slot status can be used of in other scenarios in addition to account information such as transactions, blocks. The current implementation is too tightly coupled. Summary of Changes Decouple the slot status notification from accounts notification. Created a new slot status notification module.
- Loading branch information
1 parent
9eb0c01
commit 89c45a5
Showing
12 changed files
with
171 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod accounts_update_notifier; | ||
pub mod accountsdb_plugin_manager; | ||
pub mod accountsdb_plugin_service; | ||
pub mod slot_status_notifier; | ||
pub mod slot_status_observer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use { | ||
crate::accountsdb_plugin_manager::AccountsDbPluginManager, | ||
log::*, | ||
solana_accountsdb_plugin_interface::accountsdb_plugin_interface::SlotStatus, | ||
solana_measure::measure::Measure, | ||
solana_metrics::*, | ||
solana_sdk::clock::Slot, | ||
std::sync::{Arc, RwLock}, | ||
}; | ||
|
||
pub trait SlotStatusNotifierInterface { | ||
/// Notified when a slot is optimistically confirmed | ||
fn notify_slot_confirmed(&self, slot: Slot, parent: Option<Slot>); | ||
|
||
/// Notified when a slot is marked frozen. | ||
fn notify_slot_processed(&self, slot: Slot, parent: Option<Slot>); | ||
|
||
/// Notified when a slot is rooted. | ||
fn notify_slot_rooted(&self, slot: Slot, parent: Option<Slot>); | ||
} | ||
|
||
pub type SlotStatusNotifier = Arc<RwLock<dyn SlotStatusNotifierInterface + Sync + Send>>; | ||
|
||
pub struct SlotStatusNotifierImpl { | ||
plugin_manager: Arc<RwLock<AccountsDbPluginManager>>, | ||
} | ||
|
||
impl SlotStatusNotifierInterface for SlotStatusNotifierImpl { | ||
fn notify_slot_confirmed(&self, slot: Slot, parent: Option<Slot>) { | ||
self.notify_slot_status(slot, parent, SlotStatus::Confirmed); | ||
} | ||
|
||
fn notify_slot_processed(&self, slot: Slot, parent: Option<Slot>) { | ||
self.notify_slot_status(slot, parent, SlotStatus::Processed); | ||
} | ||
|
||
fn notify_slot_rooted(&self, slot: Slot, parent: Option<Slot>) { | ||
self.notify_slot_status(slot, parent, SlotStatus::Rooted); | ||
} | ||
} | ||
|
||
impl SlotStatusNotifierImpl { | ||
pub fn new(plugin_manager: Arc<RwLock<AccountsDbPluginManager>>) -> Self { | ||
Self { plugin_manager } | ||
} | ||
|
||
pub fn notify_slot_status(&self, slot: Slot, parent: Option<Slot>, slot_status: SlotStatus) { | ||
let mut plugin_manager = self.plugin_manager.write().unwrap(); | ||
if plugin_manager.plugins.is_empty() { | ||
return; | ||
} | ||
|
||
for plugin in plugin_manager.plugins.iter_mut() { | ||
let mut measure = Measure::start("accountsdb-plugin-update-slot"); | ||
match plugin.update_slot_status(slot, parent, slot_status.clone()) { | ||
Err(err) => { | ||
error!( | ||
"Failed to update slot status at slot {}, error: {} to plugin {}", | ||
slot, | ||
err, | ||
plugin.name() | ||
) | ||
} | ||
Ok(_) => { | ||
trace!( | ||
"Successfully updated slot status at slot {} to plugin {}", | ||
slot, | ||
plugin.name() | ||
); | ||
} | ||
} | ||
measure.stop(); | ||
inc_new_counter_debug!( | ||
"accountsdb-plugin-update-slot-us", | ||
measure.as_us() as usize, | ||
1000, | ||
1000 | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.