Skip to content

Commit

Permalink
geyser: include entries to block message
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Aug 10, 2023
1 parent 1e2e3bb commit eea42f8
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 28 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ The minor version will be incremented upon a breaking change and the patch versi

### Breaking

## 2023-08-10

- @triton-one/yellowstone-grpc:0.2.1
- yellowstone-grpc-client-1.9.0+solana.1.16.1
- yellowstone-grpc-geyser-1.7.0+solana.1.16.1
- yellowstone-grpc-proto-1.9.0+solana.1.16.1

### Fix

geyser: include entries to block message ([#169](https://github.com/rpcpool/yellowstone-grpc/pull/169)).

## 2023-07-26

- yellowstone-grpc-geyser-1.6.1+solana.1.16.1
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[workspace]
members = [
"examples/rust", # 1.8.0+solana.1.16.1
"yellowstone-grpc-client", # 1.8.0+solana.1.16.1
"yellowstone-grpc-geyser", # 1.6.1+solana.1.16.1
"yellowstone-grpc-proto", # 1.8.0+solana.1.16.1
"examples/rust", # 1.9.0+solana.1.16.1
"yellowstone-grpc-client", # 1.9.0+solana.1.16.1
"yellowstone-grpc-geyser", # 1.7.0+solana.1.16.1
"yellowstone-grpc-proto", # 1.9.0+solana.1.16.1
]

[profile.release]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ If all fields are empty then all transactions are broadcasted. Otherwise fields
- `account_include` — filter transactions and accounts which use any of listed accounts
- `include_transactions` — include all transactions
- `include_accounts` — include all accounts updates
- `include_entries` — include all entries

Currently all blocks are broadcasted.

Expand Down
2 changes: 1 addition & 1 deletion examples/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yellowstone-grpc-client-simple"
version = "1.8.0+solana.1.16.1"
version = "1.9.0+solana.1.16.1"
authors = ["Triton One"]
edition = "2021"
publish = false
Expand Down
5 changes: 5 additions & 0 deletions examples/rust/src/bin/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ struct ActionSubscribe {
#[clap(long)]
blocks_include_accounts: Option<bool>,

/// Include entries to block message
#[clap(long)]
blocks_include_entries: Option<bool>,

/// Subscribe on block meta updates (without transactions)
#[clap(long)]
blocks_meta: bool,
Expand Down Expand Up @@ -266,6 +270,7 @@ impl Action {
account_include: args.blocks_account_include.clone(),
include_transactions: args.blocks_include_transactions,
include_accounts: args.blocks_include_accounts,
include_entries: args.blocks_include_entries,
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions examples/typescript/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ async function subscribeCommand(client, args) {
accountInclude: args.blocksAccountInclude,
includeTransactions: args.blocksIncludeTransactions,
includeAccounts: args.blocksIncludeAccounts,
includeEntries: args.blocksIncludeEntries,
};
}

Expand Down Expand Up @@ -328,6 +329,11 @@ function parseCommandLineArgs() {
description: "include accounts to block message",
type: "boolean",
},
"blocks-include-entries": {
default: false,
description: "include entries to block message",
type: "boolean",
},
"blocks-meta": {
default: false,
description: "subscribe on block meta updates (without transactions)",
Expand Down
4 changes: 2 additions & 2 deletions yellowstone-grpc-client-nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion yellowstone-grpc-client-nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@triton-one/yellowstone-grpc",
"version": "0.2.0",
"version": "0.2.1",
"license": "Apache-2.0",
"author": "Triton One",
"description": "Yellowstone gRPC Geyser Node.js Client",
Expand Down
4 changes: 2 additions & 2 deletions yellowstone-grpc-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yellowstone-grpc-client"
version = "1.8.0+solana.1.16.1"
version = "1.9.0+solana.1.16.1"
authors = ["Triton One"]
edition = "2021"
description = "Yellowstone gRPC Geyser Simple Client"
Expand All @@ -16,7 +16,7 @@ http = "0.2.8"
thiserror = "1.0"
tonic = { version = "0.9.2", features = ["gzip", "tls", "tls-roots"] }
tonic-health = "0.9.2"
yellowstone-grpc-proto = { path = "../yellowstone-grpc-proto", version = "1.8.0+solana.1.16.1" }
yellowstone-grpc-proto = { path = "../yellowstone-grpc-proto", version = "1.9.0+solana.1.16.1" }

[dev-dependencies]
tokio = { version = "1.21.2", features = ["macros"] }
2 changes: 1 addition & 1 deletion yellowstone-grpc-geyser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yellowstone-grpc-geyser"
version = "1.6.1+solana.1.16.1"
version = "1.7.0+solana.1.16.1"
authors = ["Triton One"]
edition = "2021"
description = "Yellowstone gRPC Geyser Plugin"
Expand Down
3 changes: 2 additions & 1 deletion yellowstone-grpc-geyser/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"account_include_any": false,
"account_include_reject": ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"],
"include_transactions": true,
"include_accounts" : false
"include_accounts" : false,
"include_entries" : false
},
"blocks_meta": {
"max": 1
Expand Down
2 changes: 2 additions & 0 deletions yellowstone-grpc-geyser/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ pub struct ConfigGrpcFiltersBlocks {
pub account_include_reject: HashSet<Pubkey>,
pub include_transactions: bool,
pub include_accounts: bool,
pub include_entries: bool,
}

impl Default for ConfigGrpcFiltersBlocks {
Expand All @@ -232,6 +233,7 @@ impl Default for ConfigGrpcFiltersBlocks {
account_include_reject: HashSet::new(),
include_transactions: true,
include_accounts: true,
include_entries: true,
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion yellowstone-grpc-geyser/src/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ pub struct FilterBlocksInner {
account_include: HashSet<Pubkey>,
include_transactions: Option<bool>,
include_accounts: Option<bool>,
include_entries: Option<bool>,
}

#[derive(Debug, Default, Clone)]
Expand Down Expand Up @@ -574,6 +575,10 @@ impl FilterBlocks {
matches!(filter.include_accounts, None | Some(false)) || limit.include_accounts,
"`include_accounts` is not allowed"
);
anyhow::ensure!(
matches!(filter.include_entries, None | Some(false)) || limit.include_accounts,
"`include_entries` is not allowed"
);

this.filters.insert(
name.clone(),
Expand All @@ -584,6 +589,7 @@ impl FilterBlocks {
)?,
include_transactions: filter.include_transactions,
include_accounts: filter.include_accounts,
include_entries: filter.include_entries,
},
);
}
Expand Down Expand Up @@ -637,9 +643,15 @@ impl FilterBlocks {
vec![]
};

let entries = if inner.include_entries == Some(true) {
message.entries.iter().collect::<Vec<_>>()
} else {
vec![]
};

(
vec![filter.clone()],
MessageRef::Block((message, transactions, accounts).into()),
MessageRef::Block((message, transactions, accounts, entries).into()),
)
})
.collect()
Expand Down
48 changes: 39 additions & 9 deletions yellowstone-grpc-geyser/src/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ impl From<&ReplicaEntryInfo<'_>> for MessageEntry {
}
}

impl MessageEntry {
fn to_proto(&self) -> SubscribeUpdateEntry {
SubscribeUpdateEntry {
slot: self.slot,
index: self.index as u64,
num_hashes: self.num_hashes,
hash: self.hash.clone(),
executed_transaction_count: self.executed_transaction_count,
}
}
}

#[derive(Debug, Clone)]
pub struct MessageBlock {
pub parent_slot: u64,
Expand All @@ -213,6 +225,8 @@ pub struct MessageBlock {
pub transactions: Vec<MessageTransactionInfo>,
pub updated_account_count: u64,
pub accounts: Vec<MessageAccountInfo>,
pub entries_count: u64,
pub entries: Vec<MessageEntry>,
}

impl From<(MessageBlockMeta, Vec<MessageTransactionInfo>)> for MessageBlock {
Expand All @@ -229,6 +243,8 @@ impl From<(MessageBlockMeta, Vec<MessageTransactionInfo>)> for MessageBlock {
transactions,
updated_account_count: 0,
accounts: Vec::new(),
entries_count: 0,
entries: Vec::new(),
}
}
}
Expand Down Expand Up @@ -308,20 +324,24 @@ pub struct MessageBlockRef<'a> {
pub transactions: Vec<&'a MessageTransactionInfo>,
pub updated_account_count: u64,
pub accounts: Vec<&'a MessageAccountInfo>,
pub entries_count: u64,
pub entries: Vec<&'a MessageEntry>,
}

impl<'a>
From<(
&'a MessageBlock,
Vec<&'a MessageTransactionInfo>,
Vec<&'a MessageAccountInfo>,
Vec<&'a MessageEntry>,
)> for MessageBlockRef<'a>
{
fn from(
(block, transactions, accounts): (
(block, transactions, accounts, entries): (
&'a MessageBlock,
Vec<&'a MessageTransactionInfo>,
Vec<&'a MessageAccountInfo>,
Vec<&'a MessageEntry>,
),
) -> Self {
Self {
Expand All @@ -336,6 +356,8 @@ impl<'a>
transactions,
updated_account_count: block.updated_account_count,
accounts,
entries_count: block.entries_count,
entries,
}
}
}
Expand Down Expand Up @@ -368,13 +390,7 @@ impl<'a> MessageRef<'a> {
transaction: Some(message.transaction.to_proto()),
slot: message.slot,
}),
Self::Entry(message) => UpdateOneof::Entry(SubscribeUpdateEntry {
slot: message.slot,
index: message.index as u64,
num_hashes: message.num_hashes,
hash: message.hash.clone(),
executed_transaction_count: message.executed_transaction_count,
}),
Self::Entry(message) => UpdateOneof::Entry(message.to_proto()),
Self::Block(message) => UpdateOneof::Block(SubscribeUpdateBlock {
slot: message.slot,
blockhash: message.blockhash.clone(),
Expand All @@ -397,6 +413,12 @@ impl<'a> MessageRef<'a> {
.iter()
.map(|acc| acc.to_proto(accounts_data_slice))
.collect(),
entries_count: message.entries_count,
entries: message
.entries
.iter()
.map(|entry| entry.to_proto())
.collect(),
}),
Self::BlockMeta(message) => UpdateOneof::BlockMeta(SubscribeUpdateBlockMeta {
slot: message.slot,
Expand Down Expand Up @@ -731,10 +753,18 @@ impl GrpcService {
accounts.push(account.account.clone());
}
}

block.updated_account_count = accounts.len() as u64;
block.accounts = accounts;

let mut entries = Vec::with_capacity(vec.len());
for item in vec {
if let Some(Message::Entry(entry)) = item {
entries.push(entry.clone());
}
}
block.entries_count = entries.len() as u64;
block.entries = entries;

*collected = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion yellowstone-grpc-proto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yellowstone-grpc-proto"
version = "1.8.0+solana.1.16.1"
version = "1.9.0+solana.1.16.1"
authors = ["Triton One"]
edition = "2021"
description = "Yellowstone gRPC Geyser Protobuf Definitions"
Expand Down
3 changes: 3 additions & 0 deletions yellowstone-grpc-proto/proto/geyser.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ message SubscribeRequestFilterBlocks {
repeated string account_include = 1;
optional bool include_transactions = 2;
optional bool include_accounts = 3;
optional bool include_entries = 4;
}

message SubscribeRequestFilterBlocksMeta {}
Expand Down Expand Up @@ -143,6 +144,8 @@ message SubscribeUpdateBlock {
repeated SubscribeUpdateTransactionInfo transactions = 6;
uint64 updated_account_count = 10;
repeated SubscribeUpdateAccountInfo accounts = 11;
uint64 entries_count = 12;
repeated SubscribeUpdateEntry entries = 13;
}

message SubscribeUpdateBlockMeta {
Expand Down

0 comments on commit eea42f8

Please sign in to comment.