Skip to content

Commit

Permalink
use proto structs inside message for filter
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Nov 20, 2024
1 parent 7d570a4 commit 55d0429
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- proto: add mod `plugin` with `FilterNames` cache ([#458](https://github.com/rpcpool/yellowstone-grpc/pull/458))
- proto: move enum Message from geyser crate ([#459](https://github.com/rpcpool/yellowstone-grpc/pull/459))
- proto: move `Filter` from geyser crate ([#466](https://github.com/rpcpool/yellowstone-grpc/pull/466))
- geyser: build encoded message from filtered message ([#467](https://github.com/rpcpool/yellowstone-grpc/pull/467))

### Breaking

Expand Down
35 changes: 13 additions & 22 deletions yellowstone-grpc-proto/src/plugin/filter/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use {
crate::{
geyser::{
subscribe_update::UpdateOneof, SubscribeUpdate, SubscribeUpdateAccount,
SubscribeUpdateAccountInfo, SubscribeUpdateBlock, SubscribeUpdateBlockMeta,
SubscribeUpdateEntry, SubscribeUpdatePing, SubscribeUpdatePong, SubscribeUpdateSlot,
SubscribeUpdateAccountInfo, SubscribeUpdateBlock, SubscribeUpdateEntry,
SubscribeUpdatePing, SubscribeUpdatePong, SubscribeUpdateSlot,
SubscribeUpdateTransaction, SubscribeUpdateTransactionInfo,
SubscribeUpdateTransactionStatus,
},
Expand Down Expand Up @@ -139,7 +139,7 @@ impl FilteredUpdate {
FilteredUpdateOneof::Block(msg) => UpdateOneof::Block(SubscribeUpdateBlock {
slot: msg.meta.slot,
blockhash: msg.meta.blockhash.clone(),
rewards: Some(msg.meta.rewards.clone()),
rewards: msg.meta.rewards.clone(),
block_time: msg.meta.block_time,
block_height: msg.meta.block_height,
parent_slot: msg.meta.parent_slot,
Expand Down Expand Up @@ -167,20 +167,7 @@ impl FilteredUpdate {
}),
FilteredUpdateOneof::Ping => UpdateOneof::Ping(SubscribeUpdatePing {}),
FilteredUpdateOneof::Pong(msg) => UpdateOneof::Pong(*msg),
FilteredUpdateOneof::BlockMeta(msg) => {
let msg = &msg.0;
UpdateOneof::BlockMeta(SubscribeUpdateBlockMeta {
slot: msg.slot,
blockhash: msg.blockhash.clone(),
rewards: Some(msg.rewards.clone()),
block_time: msg.block_time,
block_height: msg.block_height,
parent_slot: msg.parent_slot,
parent_blockhash: msg.parent_blockhash.clone(),
executed_transaction_count: msg.executed_transaction_count,
entries_count: msg.entries_count,
})
}
FilteredUpdateOneof::BlockMeta(msg) => UpdateOneof::BlockMeta(msg.0.as_ref().0.clone()),
FilteredUpdateOneof::Entry(msg) => {
UpdateOneof::Entry(Self::as_subscribe_update_entry(&msg.0))
}
Expand Down Expand Up @@ -306,7 +293,7 @@ pub mod tests {
super::{FilteredUpdate, FilteredUpdateBlock, FilteredUpdateFilters, FilteredUpdateOneof},
crate::{
convert_to,
geyser::SubscribeUpdate,
geyser::{SubscribeUpdate, SubscribeUpdateBlockMeta},
plugin::{
filter::{name::FilterName, FilterAccountsDataSlice},
message::{
Expand Down Expand Up @@ -502,19 +489,23 @@ pub mod tests {
let entries = create_entries();

let slot = block.parent_slot + 1;
let block_meta1 = MessageBlockMeta {
let block_meta1 = MessageBlockMeta(SubscribeUpdateBlockMeta {
parent_slot: block.parent_slot,
slot,
parent_blockhash: block.previous_blockhash,
blockhash: block.blockhash,
rewards: convert_to::create_rewards_obj(&block.rewards, block.num_partitions),
rewards: Some(convert_to::create_rewards_obj(
&block.rewards,
block.num_partitions,
)),
block_time: block.block_time.map(convert_to::create_timestamp),
block_height: block.block_height.map(convert_to::create_block_height),
executed_transaction_count: transactions.len() as u64,
entries_count: entries.len() as u64,
};
});
let mut block_meta2 = block_meta1.clone();
block_meta2.rewards.num_partitions = Some(convert_to::create_num_partitions(42));
block_meta2.rewards =
Some(convert_to::create_rewards_obj(&block.rewards, Some(42)));

let block_meta1 = Arc::new(block_meta1);
let block_meta2 = Arc::new(block_meta2);
Expand Down
9 changes: 9 additions & 0 deletions yellowstone-grpc-proto/src/plugin/filter/name.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
borrow::Borrow,
collections::HashSet,
ops::Deref,
sync::Arc,
time::{Duration, Instant},
};
Expand All @@ -23,6 +24,14 @@ impl AsRef<str> for FilterName {
}
}

impl Deref for FilterName {
type Target = str;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl Borrow<str> for FilterName {
#[inline]
fn borrow(&self) -> &str {
Expand Down
41 changes: 25 additions & 16 deletions yellowstone-grpc-proto/src/plugin/message.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
use {
crate::{
convert_to, geyser::CommitmentLevel as CommitmentLevelProto,
convert_to,
geyser::{CommitmentLevel as CommitmentLevelProto, SubscribeUpdateBlockMeta},
solana::storage::confirmed_block,
},
agave_geyser_plugin_interface::geyser_plugin_interface::{
ReplicaAccountInfoV3, ReplicaBlockInfoV4, ReplicaEntryInfoV2, ReplicaTransactionInfoV2,
SlotStatus,
},
solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey, signature::Signature},
std::{collections::HashSet, sync::Arc},
std::{
collections::HashSet,
ops::{Deref, DerefMut},
sync::Arc,
},
};

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -182,34 +187,38 @@ impl MessageEntry {
}

#[derive(Debug, Clone)]
pub struct MessageBlockMeta {
pub parent_slot: u64,
pub slot: u64,
pub parent_blockhash: String,
pub blockhash: String,
pub rewards: confirmed_block::Rewards,
pub block_time: Option<confirmed_block::UnixTimestamp>,
pub block_height: Option<confirmed_block::BlockHeight>,
pub executed_transaction_count: u64,
pub entries_count: u64,
pub struct MessageBlockMeta(pub SubscribeUpdateBlockMeta);

impl Deref for MessageBlockMeta {
type Target = SubscribeUpdateBlockMeta;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for MessageBlockMeta {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl MessageBlockMeta {
pub fn from_geyser(info: &ReplicaBlockInfoV4<'_>) -> Self {
Self {
Self(SubscribeUpdateBlockMeta {
parent_slot: info.parent_slot,
slot: info.slot,
parent_blockhash: info.parent_blockhash.to_string(),
blockhash: info.blockhash.to_string(),
rewards: convert_to::create_rewards_obj(
rewards: Some(convert_to::create_rewards_obj(
&info.rewards.rewards,
info.rewards.num_partitions,
),
)),
block_time: info.block_time.map(convert_to::create_timestamp),
block_height: info.block_height.map(convert_to::create_block_height),
executed_transaction_count: info.executed_transaction_count,
entries_count: info.entry_count,
}
})
}
}

Expand Down

0 comments on commit 55d0429

Please sign in to comment.