Skip to content

Commit

Permalink
geyser: add TokenAccountState to accounts filter (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Jun 29, 2023
1 parent e1ea5cf commit 6db9c9d
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 15 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ The minor version will be incremented upon a breaking change and the patch versi

## 2023-06-29

- @triton-one/yellowstone-grpc:0.1.3
- yellowstone-grpc-client-1.5.0+solana.1.14.18
- yellowstone-grpc-client-1.5.0+solana.1.16.1
- yellowstone-grpc-geyser-1.1.0+solana.1.14.18
- yellowstone-grpc-geyser-1.1.0+solana.1.16.1
- yellowstone-grpc-proto-1.5.0+solana.1.14.18
- yellowstone-grpc-proto-1.5.0+solana.1.16.1

### Features

- geyser: support TokenAccountState in accounts filter ([#154](https://github.com/rpcpool/yellowstone-grpc/pull/154)).

## 2023-06-29

- @triton-one/yellowstone-grpc:0.1.2
- yellowstone-grpc-client-1.4.0+solana.1.14.18
- yellowstone-grpc-client-1.4.0+solana.1.16.1
Expand Down
9 changes: 5 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.4.0+solana.1.14.18
"yellowstone-grpc-client", # 1.4.0+solana.1.14.18
"yellowstone-grpc-geyser", # 1.0.0+solana.1.14.18
"yellowstone-grpc-proto", # 1.4.0+solana.1.14.18
"examples/rust", # 1.5.0+solana.1.14.18
"yellowstone-grpc-client", # 1.5.0+solana.1.14.18
"yellowstone-grpc-geyser", # 1.1.0+solana.1.14.18
"yellowstone-grpc-proto", # 1.5.0+solana.1.14.18
]

[patch.crates-io]
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.4.0+solana.1.14.18"
version = "1.5.0+solana.1.14.18"
authors = ["Triton One"]
edition = "2021"
publish = false
Expand Down
9 changes: 9 additions & 0 deletions examples/rust/src/bin/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ struct ActionSubscribe {
#[clap(long)]
accounts_datasize: Option<u64>,

/// Filter valid token accounts
#[clap(long)]
accounts_token_account_state: bool,

/// Receive only part of updated data account, format: `offset,size`
#[clap(long)]
accounts_data_slice: Vec<String>,
Expand Down Expand Up @@ -198,6 +202,11 @@ impl Action {
filter: Some(AccountsFilterDataOneof::Datasize(datasize)),
});
}
if args.accounts_token_account_state {
filters.push(SubscribeRequestFilterAccountsFilter {
filter: Some(AccountsFilterDataOneof::TokenAccountState(true)),
});
}

accounts.insert(
"client".to_owned(),
Expand Down
11 changes: 11 additions & 0 deletions examples/typescript/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ async function subscribeCommand(client, args) {
}
}

if (args.accounts.tokenaccountstate) {
filters.push({
tokenAccountState: args.accounts.tokenaccountstate,
});
}

if (args.accounts.datasize) {
filters.push({ datasize: args.accounts.datasize });
}
Expand Down Expand Up @@ -238,6 +244,11 @@ function parseCommandLineArgs() {
describe: "filter by data size",
type: "number",
},
"accounts-tokenaccountstate": {
default: false,
describe: "filter valid token accounts",
type: "boolean",
},
"accounts-dataslice": {
default: [],
describe:
Expand Down
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.1.2",
"version": "0.1.3",
"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.4.0+solana.1.14.18"
version = "1.5.0+solana.1.14.18"
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.4.0+solana.1.14.18" }
yellowstone-grpc-proto = { path = "../yellowstone-grpc-proto", version = "1.5.0+solana.1.14.18" }

[dev-dependencies]
tokio = { version = "1.21.2", features = ["macros"] }
3 changes: 2 additions & 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.0.0+solana.1.14.18"
version = "1.1.0+solana.1.14.18"
authors = ["Triton One"]
edition = "2021"
description = "Yellowstone gRPC Geyser Plugin"
Expand Down Expand Up @@ -29,6 +29,7 @@ solana-geyser-plugin-interface = "=1.14.18"
solana-logger = "=1.14.18"
solana-sdk = "=1.14.18"
solana-transaction-status = "=1.14.18"
spl-token-2022 = "0.6.1"
tokio = { version = "1.21.2", features = ["rt-multi-thread", "macros", "time"] }
tokio-stream = "0.1.11"
tonic = { version = "0.9.2", features = ["gzip", "tls", "tls-roots"] }
Expand Down
11 changes: 10 additions & 1 deletion yellowstone-grpc-geyser/src/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use {
},
base64::{engine::general_purpose::STANDARD as base64_engine, Engine},
solana_sdk::{pubkey::Pubkey, signature::Signature},
spl_token_2022::{generic_token_account::GenericTokenAccount, state::Account as TokenAccount},
std::{
collections::{HashMap, HashSet},
iter::FromIterator,
Expand Down Expand Up @@ -176,6 +177,7 @@ impl FilterAccounts {
struct FilterAccountsData {
memcmp: Vec<(usize, Vec<u8>)>,
datasize: Option<usize>,
token_account_state: bool,
}

impl FilterAccountsData {
Expand Down Expand Up @@ -219,6 +221,10 @@ impl FilterAccountsData {
"datasize used more than once",
);
}
Some(AccountsFilterDataOneof::TokenAccountState(value)) => {
anyhow::ensure!(value, "token_account_state only allowed to be true");
this.token_account_state = true;
}
None => {
anyhow::bail!("filter should be defined");
}
Expand All @@ -228,13 +234,16 @@ impl FilterAccountsData {
}

fn is_empty(&self) -> bool {
self.memcmp.is_empty() && self.datasize.is_none()
self.memcmp.is_empty() && self.datasize.is_none() && !self.token_account_state
}

fn is_match(&self, data: &[u8]) -> bool {
if matches!(self.datasize, Some(datasize) if data.len() != datasize) {
return false;
}
if self.token_account_state && !TokenAccount::valid_account_data(data) {
return false;
}
for (offset, bytes) in self.memcmp.iter() {
if data.len() < *offset + bytes.len() {
return false;
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.4.0+solana.1.16.1"
version = "1.5.0+solana.1.14.18"
authors = ["Triton One"]
edition = "2021"
description = "Yellowstone gRPC Geyser Protobuf Definitions"
Expand Down
1 change: 1 addition & 0 deletions yellowstone-grpc-proto/proto/geyser.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ message SubscribeRequestFilterAccountsFilter {
oneof filter {
SubscribeRequestFilterAccountsFilterMemcmp memcmp = 1;
uint64 datasize = 2;
bool token_account_state = 3;
}
}

Expand Down

0 comments on commit 6db9c9d

Please sign in to comment.