Skip to content

Commit

Permalink
grpc: add a metdata feed to indicate missing account, snapshot start …
Browse files Browse the repository at this point in the history
…and end
  • Loading branch information
farnyser committed May 6, 2024
1 parent 8e465c4 commit 9e7ebd1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions connector/examples/combined_example_consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ async fn main() -> anyhow::Result<()> {
&config,
&filter_config,
account_write_queue_sender,
None,
slot_queue_sender,
metrics_tx.clone(),
exit.clone(),
Expand Down
1 change: 1 addition & 0 deletions connector/examples/geyser_example_consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ async fn main() -> anyhow::Result<()> {
&config,
&filter_config,
account_write_queue_sender,
None,
slot_queue_sender,
metrics_tx.clone(),
exit.clone(),
Expand Down
28 changes: 26 additions & 2 deletions connector/src/grpc_plugin_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use crate::snapshot::{get_snapshot_gma, get_snapshot_gpa};
use crate::{
chain_data::SlotStatus,
metrics::{MetricType, Metrics},
AccountWrite, GrpcSourceConfig, SlotUpdate, SnapshotSourceConfig, SourceConfig, TlsConfig,
AccountWrite, FeedMetadata, GrpcSourceConfig, SlotUpdate, SnapshotSourceConfig, SourceConfig,
TlsConfig,
};
use crate::{EntityFilter, FilterConfig};

Expand Down Expand Up @@ -415,6 +416,7 @@ pub async fn process_events(
config: &SourceConfig,
filter_config: &FilterConfig,
account_write_queue_sender: async_channel::Sender<AccountWrite>,
metdata_write_queue_sender: Option<async_channel::Sender<FeedMetadata>>,
slot_queue_sender: async_channel::Sender<SlotUpdate>,
metrics_sender: Metrics,
exit: Arc<AtomicBool>,
Expand Down Expand Up @@ -504,6 +506,14 @@ pub async fn process_events(
let mut metric_snapshot_account_writes =
metrics_sender.register_u64("grpc_snapshot_account_writes".into(), MetricType::Counter);

let metadata_sender = |msg| {
if let Some(sender) = &metdata_write_queue_sender {
sender.send_blocking(msg)
} else {
Ok(())
}
};

loop {
if exit.load(Ordering::Relaxed) {
warn!("shutting down grpc_plugin_source...");
Expand Down Expand Up @@ -593,6 +603,10 @@ pub async fn process_events(
Message::Snapshot(update) => {
metric_snapshots.increment();
info!("processing snapshot...");
if let Err(e) = metadata_sender(FeedMetadata::SnapshotStart) {
warn!("failed to send feed matadata event: {}", e);
}

for account in update.accounts.iter() {
metric_snapshot_account_writes.increment();
metric_account_queue.set(account_write_queue_sender.len() as u64);
Expand All @@ -607,10 +621,20 @@ pub async fn process_events(
.await
.expect("send success");
}
(key, None) => warn!("account not found {}", key),
(key, None) => {
warn!("account not found {}", key);
let pubkey = Pubkey::from_str(key).unwrap();
if let Err(e) = metadata_sender(FeedMetadata::InvalidAccount(pubkey)) {
warn!("failed to send feed matadata event: {}", e);
}
}
}
}

info!("processing snapshot done");
if let Err(e) = metadata_sender(FeedMetadata::SnapshotEnd) {
warn!("failed to send feed matadata event: {}", e);
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions connector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ impl<T, E: std::fmt::Debug> AnyhowWrap for Result<T, E> {
}
}

pub enum FeedMetadata {
InvalidAccount(Pubkey),
SnapshotStart,
SnapshotEnd,
}

#[derive(Clone, PartialEq, Debug)]
pub struct AccountWrite {
pub pubkey: Pubkey,
Expand Down

0 comments on commit 9e7ebd1

Please sign in to comment.