forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cluster info on geyser #46
Closed
godmodegalactus
wants to merge
1
commit into
anza-xyz:master
from
blockworks-foundation:add_cluster_info_on_geyser
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,152 @@ | ||
// Module responsible for notifying plugins of transactions | ||
use { | ||
crate::geyser_plugin_manager::GeyserPluginManager, | ||
agave_geyser_plugin_interface::geyser_plugin_interface::ReplicaClusterInfoNode, | ||
log::*, | ||
solana_client::connection_cache::Protocol, | ||
solana_gossip::{ | ||
cluster_info_notifier_interface::ClusterInfoNotifierInterface, | ||
legacy_contact_info::LegacyContactInfo, | ||
}, | ||
solana_measure::measure::Measure, | ||
solana_metrics::*, | ||
solana_sdk::pubkey::Pubkey, | ||
std::sync::{Arc, RwLock}, | ||
}; | ||
|
||
// This implementation of ClusterInfoNotifierImpl is passed to the rpc's TransactionStatusService | ||
// at the validator startup. TransactionStatusService invokes the notify_transaction method | ||
// for new transactions. The implementation in turn invokes the notify_transaction of each | ||
// plugin enabled with transaction notification managed by the GeyserPluginManager. | ||
#[derive(Debug)] | ||
pub(crate) struct ClusterInfoNotifierImpl { | ||
plugin_manager: Arc<RwLock<GeyserPluginManager>>, | ||
} | ||
|
||
impl ClusterInfoNotifierImpl { | ||
pub fn new(plugin_manager: Arc<RwLock<GeyserPluginManager>>) -> Self { | ||
ClusterInfoNotifierImpl { plugin_manager } | ||
} | ||
|
||
fn clusterinfo_from_legacy_contact_info( | ||
legacy_info: &LegacyContactInfo, | ||
) -> ReplicaClusterInfoNode { | ||
ReplicaClusterInfoNode { | ||
id: *legacy_info.pubkey(), | ||
// gossip address | ||
gossip: legacy_info.gossip().ok(), | ||
// address to connect to for replication | ||
tvu: legacy_info.tvu(Protocol::UDP).ok(), | ||
// TVU over QUIC protocol. | ||
tvu_quic: legacy_info.tvu(Protocol::QUIC).ok(), | ||
// repair service over QUIC protocol. | ||
serve_repair_quic: legacy_info.serve_repair(Protocol::QUIC).ok(), | ||
// transactions address | ||
tpu: legacy_info.tpu(Protocol::UDP).ok(), | ||
// address to forward unprocessed transactions to | ||
tpu_forwards: legacy_info.tpu_forwards(Protocol::UDP).ok(), | ||
// address to which to send bank state requests | ||
tpu_vote: legacy_info.tpu_vote().ok(), | ||
// address to which to send JSON-RPC requests | ||
rpc: legacy_info.rpc().ok(), | ||
// websocket for JSON-RPC push notifications | ||
rpc_pubsub: legacy_info.rpc_pubsub().ok(), | ||
// address to send repair requests to | ||
serve_repair: legacy_info.serve_repair(Protocol::UDP).ok(), | ||
// latest wallclock picked | ||
wallclock: legacy_info.wallclock(), | ||
// node shred version | ||
shred_version: legacy_info.shred_version(), | ||
} | ||
} | ||
} | ||
|
||
impl ClusterInfoNotifierInterface for ClusterInfoNotifierImpl { | ||
fn notify_clusterinfo_update(&self, contact_info: &LegacyContactInfo) { | ||
let cluster_info = | ||
ClusterInfoNotifierImpl::clusterinfo_from_legacy_contact_info(contact_info); | ||
let mut measure2 = Measure::start("geyser-plugin-notify_plugins_of_cluster_info_update"); | ||
let plugin_manager = self.plugin_manager.read().unwrap(); | ||
|
||
if plugin_manager.plugins.is_empty() { | ||
return; | ||
} | ||
for plugin in plugin_manager.plugins.iter() { | ||
let mut measure = Measure::start("geyser-plugin-update-cluster_info"); | ||
match plugin.update_cluster_info(&cluster_info) { | ||
Err(err) => { | ||
error!( | ||
"Failed to update cluster_info {}, error: {} to plugin {}", | ||
bs58::encode(cluster_info.id).into_string(), | ||
err, | ||
plugin.name() | ||
) | ||
} | ||
Ok(_) => { | ||
trace!( | ||
"Successfully updated cluster_info {} to plugin {}", | ||
bs58::encode(cluster_info.id).into_string(), | ||
plugin.name() | ||
); | ||
} | ||
} | ||
measure.stop(); | ||
inc_new_counter_debug!( | ||
"geyser-plugin-update-cluster_info-us", | ||
measure.as_us() as usize, | ||
100000, | ||
100000 | ||
); | ||
} | ||
measure2.stop(); | ||
inc_new_counter_debug!( | ||
"geyser-plugin-notify_plugins_of_cluster_info_update-us", | ||
measure2.as_us() as usize, | ||
100000, | ||
100000 | ||
); | ||
} | ||
|
||
fn notify_clusterinfo_remove(&self, pubkey: &Pubkey) { | ||
let mut measure2 = Measure::start("geyser-plugin-notify_plugins_of_cluster_info_update"); | ||
let plugin_manager = self.plugin_manager.read().unwrap(); | ||
|
||
if plugin_manager.plugins.is_empty() { | ||
return; | ||
} | ||
for plugin in plugin_manager.plugins.iter() { | ||
let mut measure = Measure::start("geyser-plugin-remove-cluster_info"); | ||
match plugin.notify_clusterinfo_remove(pubkey) { | ||
Err(err) => { | ||
error!( | ||
"Failed to remove cluster_info {}, error: {} to plugin {}", | ||
bs58::encode(pubkey).into_string(), | ||
err, | ||
plugin.name() | ||
) | ||
} | ||
Ok(_) => { | ||
trace!( | ||
"Successfully remove cluster_info {} to plugin {}", | ||
bs58::encode(pubkey).into_string(), | ||
plugin.name() | ||
); | ||
} | ||
} | ||
measure.stop(); | ||
inc_new_counter_debug!( | ||
"geyser-plugin-remove-cluster_info-us", | ||
measure.as_us() as usize, | ||
100000, | ||
100000 | ||
); | ||
} | ||
measure2.stop(); | ||
inc_new_counter_debug!( | ||
"geyser-plugin-notify_plugins_of_cluster_info_remove-us", | ||
measure2.as_us() as usize, | ||
100000, | ||
100000 | ||
); | ||
} | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens to this struct if we change gossip
ContactInfo
, e.g. add a new socket for a new protocol?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya so that is the goal of doing something with an FFI interface. See PR: #3434. We could modify that PR and choose to only expose a pointer to a ContactInfo struct, making it much easier to update
ContactInfo
in the future. More details here: #3434 (comment)