Add geyser blockV2 (#36)

This commit is contained in:
Kirill Fomichev 2023-01-31 12:48:02 -03:00
parent 3828153d28
commit f370f0e23e
No known key found for this signature in database
GPG Key ID: 6AA0144D5E0C0C0A
5 changed files with 239 additions and 112 deletions

179
Cargo.lock generated
View File

@ -2475,8 +2475,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-account-decoder" name = "solana-account-decoder"
version = "1.14.13" version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2#c9db2ceb898985869fe565044e324e950fdbb535"
checksum = "b04c1316932017ae5f947e83d77cc0356c4a395130a480cdc17ffb0570a0c115"
dependencies = [ dependencies = [
"Inflector", "Inflector",
"base64 0.13.1", "base64 0.13.1",
@ -2500,8 +2499,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-address-lookup-table-program" name = "solana-address-lookup-table-program"
version = "1.14.13" version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2#c9db2ceb898985869fe565044e324e950fdbb535"
checksum = "5be490ed850c99286a4e4ba169ce20695336fe666c56bd823bfd8db689d23a58"
dependencies = [ dependencies = [
"bincode", "bincode",
"bytemuck", "bytemuck",
@ -2510,9 +2508,9 @@ dependencies = [
"num-traits", "num-traits",
"rustc_version", "rustc_version",
"serde", "serde",
"solana-frozen-abi", "solana-frozen-abi 1.14.13 (git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2)",
"solana-frozen-abi-macro", "solana-frozen-abi-macro 1.14.13 (git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2)",
"solana-program", "solana-program 1.14.13 (git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2)",
"solana-program-runtime", "solana-program-runtime",
"solana-sdk", "solana-sdk",
"thiserror", "thiserror",
@ -2521,8 +2519,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-config-program" name = "solana-config-program"
version = "1.14.13" version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2#c9db2ceb898985869fe565044e324e950fdbb535"
checksum = "fb275d80a482134f0f0c5439b0c40ba3f04bef70dbc46c0e47f6107f6ae482a8"
dependencies = [ dependencies = [
"bincode", "bincode",
"chrono", "chrono",
@ -2561,7 +2558,40 @@ dependencies = [
"serde_derive", "serde_derive",
"serde_json", "serde_json",
"sha2 0.10.6", "sha2 0.10.6",
"solana-frozen-abi-macro", "solana-frozen-abi-macro 1.14.13 (registry+https://github.com/rust-lang/crates.io-index)",
"subtle",
"thiserror",
]
[[package]]
name = "solana-frozen-abi"
version = "1.14.13"
source = "git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2#c9db2ceb898985869fe565044e324e950fdbb535"
dependencies = [
"ahash",
"blake3",
"block-buffer 0.9.0",
"bs58",
"bv",
"byteorder",
"cc",
"either",
"generic-array",
"getrandom 0.1.16",
"hashbrown 0.12.3",
"im",
"lazy_static",
"log",
"memmap2",
"once_cell",
"rand_core 0.6.4",
"rustc_version",
"serde",
"serde_bytes",
"serde_derive",
"serde_json",
"sha2 0.10.6",
"solana-frozen-abi-macro 1.14.13 (git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2)",
"subtle", "subtle",
"thiserror", "thiserror",
] ]
@ -2578,9 +2608,20 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "solana-frozen-abi-macro"
version = "1.14.13"
source = "git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2#c9db2ceb898985869fe565044e324e950fdbb535"
dependencies = [
"proc-macro2",
"quote",
"rustc_version",
"syn",
]
[[package]] [[package]]
name = "solana-geyser-grpc" name = "solana-geyser-grpc"
version = "0.4.1+solana.1.14.13" version = "0.5.0+solana.1.14.13"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",
@ -2610,8 +2651,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-geyser-plugin-interface" name = "solana-geyser-plugin-interface"
version = "1.14.13" version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2#c9db2ceb898985869fe565044e324e950fdbb535"
checksum = "99f7216b62034ddaa04ea7fae38738d6bd1de2927ca3bdb42fafcd471c9c6751"
dependencies = [ dependencies = [
"log", "log",
"solana-sdk", "solana-sdk",
@ -2622,8 +2662,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-logger" name = "solana-logger"
version = "1.14.13" version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2#c9db2ceb898985869fe565044e324e950fdbb535"
checksum = "447d16a70a1b5383736ef44801050c0e1affd022303b22ed899352f958c2de4b"
dependencies = [ dependencies = [
"env_logger", "env_logger",
"lazy_static", "lazy_static",
@ -2633,8 +2672,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-measure" name = "solana-measure"
version = "1.14.13" version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2#c9db2ceb898985869fe565044e324e950fdbb535"
checksum = "2400d2534a19f7605c5059060edea0499600a223f1a1f6a4b172666c04946a77"
dependencies = [ dependencies = [
"log", "log",
"solana-sdk", "solana-sdk",
@ -2643,8 +2681,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-metrics" name = "solana-metrics"
version = "1.14.13" version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2#c9db2ceb898985869fe565044e324e950fdbb535"
checksum = "68aaa3d683945dc3b6ca38923ef952ca1f96a27b61f898a1ddf9f4cd79f2df92"
dependencies = [ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"gethostname", "gethostname",
@ -2694,9 +2731,57 @@ dependencies = [
"serde_json", "serde_json",
"sha2 0.10.6", "sha2 0.10.6",
"sha3 0.10.6", "sha3 0.10.6",
"solana-frozen-abi", "solana-frozen-abi 1.14.13 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-frozen-abi-macro", "solana-frozen-abi-macro 1.14.13 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-sdk-macro", "solana-sdk-macro 1.14.13 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror",
"tiny-bip39",
"wasm-bindgen",
"zeroize",
]
[[package]]
name = "solana-program"
version = "1.14.13"
source = "git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2#c9db2ceb898985869fe565044e324e950fdbb535"
dependencies = [
"base64 0.13.1",
"bincode",
"bitflags",
"blake3",
"borsh",
"borsh-derive",
"bs58",
"bv",
"bytemuck",
"cc",
"console_error_panic_hook",
"console_log",
"curve25519-dalek",
"getrandom 0.2.8",
"itertools",
"js-sys",
"lazy_static",
"libc",
"libsecp256k1",
"log",
"memoffset 0.6.5",
"num-derive",
"num-traits",
"parking_lot",
"rand 0.7.3",
"rand_chacha 0.2.2",
"rustc_version",
"rustversion",
"serde",
"serde_bytes",
"serde_derive",
"serde_json",
"sha2 0.10.6",
"sha3 0.10.6",
"solana-frozen-abi 1.14.13 (git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2)",
"solana-frozen-abi-macro 1.14.13 (git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2)",
"solana-sdk-macro 1.14.13 (git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2)",
"thiserror", "thiserror",
"tiny-bip39", "tiny-bip39",
"wasm-bindgen", "wasm-bindgen",
@ -2706,8 +2791,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-program-runtime" name = "solana-program-runtime"
version = "1.14.13" version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2#c9db2ceb898985869fe565044e324e950fdbb535"
checksum = "b4d12047608bac77fca000e18f7a2df3c7fa90656d7c7d387b1cd7faf18b238c"
dependencies = [ dependencies = [
"base64 0.13.1", "base64 0.13.1",
"bincode", "bincode",
@ -2722,8 +2806,8 @@ dependencies = [
"rand 0.7.3", "rand 0.7.3",
"rustc_version", "rustc_version",
"serde", "serde",
"solana-frozen-abi", "solana-frozen-abi 1.14.13 (git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2)",
"solana-frozen-abi-macro", "solana-frozen-abi-macro 1.14.13 (git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2)",
"solana-measure", "solana-measure",
"solana-metrics", "solana-metrics",
"solana-sdk", "solana-sdk",
@ -2733,8 +2817,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-sdk" name = "solana-sdk"
version = "1.14.13" version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2#c9db2ceb898985869fe565044e324e950fdbb535"
checksum = "390e7481c56dda2ceab2652beeda30a533e9667b34861a2eb4eec92fa1d826d7"
dependencies = [ dependencies = [
"assert_matches", "assert_matches",
"base64 0.13.1", "base64 0.13.1",
@ -2771,11 +2854,11 @@ dependencies = [
"serde_json", "serde_json",
"sha2 0.10.6", "sha2 0.10.6",
"sha3 0.10.6", "sha3 0.10.6",
"solana-frozen-abi", "solana-frozen-abi 1.14.13 (git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2)",
"solana-frozen-abi-macro", "solana-frozen-abi-macro 1.14.13 (git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2)",
"solana-logger", "solana-logger",
"solana-program", "solana-program 1.14.13 (git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2)",
"solana-sdk-macro", "solana-sdk-macro 1.14.13 (git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2)",
"thiserror", "thiserror",
"uriparse", "uriparse",
"wasm-bindgen", "wasm-bindgen",
@ -2794,11 +2877,22 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "solana-sdk-macro"
version = "1.14.13"
source = "git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2#c9db2ceb898985869fe565044e324e950fdbb535"
dependencies = [
"bs58",
"proc-macro2",
"quote",
"rustversion",
"syn",
]
[[package]] [[package]]
name = "solana-transaction-status" name = "solana-transaction-status"
version = "1.14.13" version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2#c9db2ceb898985869fe565044e324e950fdbb535"
checksum = "3c5bbdaed99403e4a17763bee60c1e0e3418524503c72b514ebff62efbcc9d33"
dependencies = [ dependencies = [
"Inflector", "Inflector",
"base64 0.13.1", "base64 0.13.1",
@ -2826,8 +2920,7 @@ dependencies = [
[[package]] [[package]]
name = "solana-vote-program" name = "solana-vote-program"
version = "1.14.13" version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2#c9db2ceb898985869fe565044e324e950fdbb535"
checksum = "81ab9ff8928282cb42871a370435dd4713f700854801afb476cf63066f1337db"
dependencies = [ dependencies = [
"bincode", "bincode",
"log", "log",
@ -2836,8 +2929,8 @@ dependencies = [
"rustc_version", "rustc_version",
"serde", "serde",
"serde_derive", "serde_derive",
"solana-frozen-abi", "solana-frozen-abi 1.14.13 (git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2)",
"solana-frozen-abi-macro", "solana-frozen-abi-macro 1.14.13 (git+https://github.com/fanatid/solana.git?tag=v1.14.13-geyser-block-v2)",
"solana-metrics", "solana-metrics",
"solana-program-runtime", "solana-program-runtime",
"solana-sdk", "solana-sdk",
@ -2868,7 +2961,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"sha3 0.9.1", "sha3 0.9.1",
"solana-program", "solana-program 1.14.13 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-sdk", "solana-sdk",
"subtle", "subtle",
"thiserror", "thiserror",
@ -2891,7 +2984,7 @@ dependencies = [
"borsh", "borsh",
"num-derive", "num-derive",
"num-traits", "num-traits",
"solana-program", "solana-program 1.14.13 (registry+https://github.com/rust-lang/crates.io-index)",
"spl-token", "spl-token",
"spl-token-2022", "spl-token-2022",
"thiserror", "thiserror",
@ -2903,7 +2996,7 @@ version = "3.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd0dc6f70db6bacea7ff25870b016a65ba1d1b6013536f08e4fd79a8f9005325" checksum = "bd0dc6f70db6bacea7ff25870b016a65ba1d1b6013536f08e4fd79a8f9005325"
dependencies = [ dependencies = [
"solana-program", "solana-program 1.14.13 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -2917,7 +3010,7 @@ dependencies = [
"num-derive", "num-derive",
"num-traits", "num-traits",
"num_enum", "num_enum",
"solana-program", "solana-program 1.14.13 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror", "thiserror",
] ]
@ -2932,7 +3025,7 @@ dependencies = [
"num-derive", "num-derive",
"num-traits", "num-traits",
"num_enum", "num_enum",
"solana-program", "solana-program 1.14.13 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-zk-token-sdk", "solana-zk-token-sdk",
"spl-memo", "spl-memo",
"spl-token", "spl-token",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "solana-geyser-grpc" name = "solana-geyser-grpc"
version = "0.4.1+solana.1.14.13" version = "0.5.0+solana.1.14.13"
authors = ["Triton One"] authors = ["Triton One"]
edition = "2021" edition = "2021"
@ -35,6 +35,12 @@ protobuf-src = "1.1.0"
tonic-build = "0.8.2" tonic-build = "0.8.2"
vergen = "=7.2.1" vergen = "=7.2.1"
[patch.crates-io]
solana-geyser-plugin-interface = { git = "https://github.com/fanatid/solana.git", tag = "v1.14.13-geyser-block-v2" }
solana-logger = { git = "https://github.com/fanatid/solana.git", tag = "v1.14.13-geyser-block-v2" }
solana-sdk = { git = "https://github.com/fanatid/solana.git", tag = "v1.14.13-geyser-block-v2" }
solana-transaction-status = { git = "https://github.com/fanatid/solana.git", tag = "v1.14.13-geyser-block-v2" }
[profile.release] [profile.release]
debug = true debug = true
lto = true lto = true

View File

@ -96,6 +96,8 @@ message SubscribeUpdateBlock {
solana.storage.ConfirmedBlock.UnixTimestamp block_time = 4; solana.storage.ConfirmedBlock.UnixTimestamp block_time = 4;
solana.storage.ConfirmedBlock.BlockHeight block_height = 5; solana.storage.ConfirmedBlock.BlockHeight block_height = 5;
repeated SubscribeUpdateTransactionInfo transactions = 6; repeated SubscribeUpdateTransactionInfo transactions = 6;
uint64 parent_slot = 7;
string parent_blockhash = 8;
} }
message SubscribeUpdateBlockMeta { message SubscribeUpdateBlockMeta {
@ -104,6 +106,9 @@ message SubscribeUpdateBlockMeta {
solana.storage.ConfirmedBlock.Rewards rewards = 3; solana.storage.ConfirmedBlock.Rewards rewards = 3;
solana.storage.ConfirmedBlock.UnixTimestamp block_time = 4; solana.storage.ConfirmedBlock.UnixTimestamp block_time = 4;
solana.storage.ConfirmedBlock.BlockHeight block_height = 5; solana.storage.ConfirmedBlock.BlockHeight block_height = 5;
uint64 parent_slot = 6;
string parent_blockhash = 7;
uint64 executed_transaction_count = 8;
} }
message SubscribeUpdatePing {} message SubscribeUpdatePing {}

View File

@ -14,8 +14,7 @@ use {
}, },
log::*, log::*,
solana_geyser_plugin_interface::geyser_plugin_interface::{ solana_geyser_plugin_interface::geyser_plugin_interface::{
ReplicaAccountInfoVersions, ReplicaBlockInfoVersions, ReplicaTransactionInfoVersions, ReplicaAccountInfoV2, ReplicaBlockInfoV2, ReplicaTransactionInfoV2, SlotStatus,
SlotStatus,
}, },
solana_sdk::{ solana_sdk::{
clock::UnixTimestamp, pubkey::Pubkey, signature::Signature, clock::UnixTimestamp, pubkey::Pubkey, signature::Signature,
@ -58,23 +57,18 @@ pub struct MessageAccount {
pub is_startup: bool, pub is_startup: bool,
} }
impl<'a> From<(ReplicaAccountInfoVersions<'a>, u64, bool)> for MessageAccount { impl<'a> From<(&'a ReplicaAccountInfoV2<'a>, u64, bool)> for MessageAccount {
fn from((account, slot, is_startup): (ReplicaAccountInfoVersions<'a>, u64, bool)) -> Self { fn from((account, slot, is_startup): (&'a ReplicaAccountInfoV2<'a>, u64, bool)) -> Self {
Self { Self {
account: match account { account: MessageAccountInfo {
ReplicaAccountInfoVersions::V0_0_1(_info) => { pubkey: Pubkey::new(account.pubkey),
unreachable!("ReplicaAccountInfoVersions::V0_0_1 is not supported") lamports: account.lamports,
} owner: Pubkey::new(account.owner),
ReplicaAccountInfoVersions::V0_0_2(info) => MessageAccountInfo { executable: account.executable,
pubkey: Pubkey::new(info.pubkey), rent_epoch: account.rent_epoch,
lamports: info.lamports, data: account.data.into(),
owner: Pubkey::new(info.owner), write_version: account.write_version,
executable: info.executable, txn_signature: account.txn_signature.cloned(),
rent_epoch: info.rent_epoch,
data: info.data.into(),
write_version: info.write_version,
txn_signature: info.txn_signature.cloned(),
},
}, },
slot, slot,
is_startup, is_startup,
@ -130,20 +124,15 @@ pub struct MessageTransaction {
pub slot: u64, pub slot: u64,
} }
impl<'a> From<(ReplicaTransactionInfoVersions<'a>, u64)> for MessageTransaction { impl<'a> From<(&'a ReplicaTransactionInfoV2<'a>, u64)> for MessageTransaction {
fn from((transaction, slot): (ReplicaTransactionInfoVersions<'a>, u64)) -> Self { fn from((transaction, slot): (&'a ReplicaTransactionInfoV2<'a>, u64)) -> Self {
Self { Self {
transaction: match transaction { transaction: MessageTransactionInfo {
ReplicaTransactionInfoVersions::V0_0_1(_info) => { signature: *transaction.signature,
unreachable!("ReplicaAccountInfoVersions::V0_0_1 is not supported") is_vote: transaction.is_vote,
} transaction: transaction.transaction.clone(),
ReplicaTransactionInfoVersions::V0_0_2(info) => MessageTransactionInfo { meta: transaction.transaction_status_meta.clone(),
signature: *info.signature, index: transaction.index,
is_vote: info.is_vote,
transaction: info.transaction.clone(),
meta: info.transaction_status_meta.clone(),
index: info.index,
},
}, },
slot, slot,
} }
@ -152,7 +141,9 @@ impl<'a> From<(ReplicaTransactionInfoVersions<'a>, u64)> for MessageTransaction
#[derive(Debug)] #[derive(Debug)]
pub struct MessageBlock { pub struct MessageBlock {
pub parent_slot: u64,
pub slot: u64, pub slot: u64,
pub parent_blockhash: String,
pub blockhash: String, pub blockhash: String,
pub rewards: Vec<Reward>, pub rewards: Vec<Reward>,
pub block_time: Option<UnixTimestamp>, pub block_time: Option<UnixTimestamp>,
@ -160,50 +151,46 @@ pub struct MessageBlock {
pub transactions: Vec<MessageTransactionInfo>, pub transactions: Vec<MessageTransactionInfo>,
} }
impl<'a> impl<'a> From<(&'a ReplicaBlockInfoV2<'a>, Vec<MessageTransactionInfo>)> for MessageBlock {
From<(
&'a ReplicaBlockInfoVersions<'a>,
Vec<MessageTransactionInfo>,
)> for MessageBlock
{
fn from( fn from(
(blockinfo, transactions): ( (blockinfo, transactions): (&'a ReplicaBlockInfoV2<'a>, Vec<MessageTransactionInfo>),
&'a ReplicaBlockInfoVersions<'a>,
Vec<MessageTransactionInfo>,
),
) -> Self { ) -> Self {
match blockinfo { Self {
ReplicaBlockInfoVersions::V0_0_1(info) => Self { parent_slot: blockinfo.parent_slot,
slot: info.slot, slot: blockinfo.slot,
blockhash: info.blockhash.to_string(), blockhash: blockinfo.blockhash.to_string(),
rewards: info.rewards.into(), parent_blockhash: blockinfo.parent_blockhash.to_string(),
block_time: info.block_time, rewards: blockinfo.rewards.into(),
block_height: info.block_height, block_time: blockinfo.block_time,
transactions, block_height: blockinfo.block_height,
}, transactions,
} }
} }
} }
#[derive(Debug)] #[derive(Debug)]
pub struct MessageBlockMeta { pub struct MessageBlockMeta {
pub parent_slot: u64,
pub slot: u64, pub slot: u64,
pub parent_blockhash: String,
pub blockhash: String, pub blockhash: String,
pub rewards: Vec<Reward>, pub rewards: Vec<Reward>,
pub block_time: Option<UnixTimestamp>, pub block_time: Option<UnixTimestamp>,
pub block_height: Option<u64>, pub block_height: Option<u64>,
pub executed_transaction_count: u64,
} }
impl<'a> From<&'a ReplicaBlockInfoVersions<'a>> for MessageBlockMeta { impl<'a> From<&'a ReplicaBlockInfoV2<'a>> for MessageBlockMeta {
fn from(blockinfo: &'a ReplicaBlockInfoVersions<'a>) -> Self { fn from(blockinfo: &'a ReplicaBlockInfoV2<'a>) -> Self {
match blockinfo { Self {
ReplicaBlockInfoVersions::V0_0_1(info) => Self { parent_slot: blockinfo.parent_slot,
slot: info.slot, slot: blockinfo.slot,
blockhash: info.blockhash.to_string(), parent_blockhash: blockinfo.parent_blockhash.to_string(),
rewards: info.rewards.into(), blockhash: blockinfo.blockhash.to_string(),
block_time: info.block_time, rewards: blockinfo.rewards.into(),
block_height: info.block_height, block_time: blockinfo.block_time,
}, block_height: blockinfo.block_height,
executed_transaction_count: blockinfo.executed_transaction_count,
} }
} }
} }
@ -250,6 +237,8 @@ impl From<&Message> for UpdateOneof {
block_time: message.block_time.map(|v| v.into()), block_time: message.block_time.map(|v| v.into()),
block_height: message.block_height.map(|v| v.into()), block_height: message.block_height.map(|v| v.into()),
transactions: message.transactions.iter().map(Into::into).collect(), transactions: message.transactions.iter().map(Into::into).collect(),
parent_slot: message.parent_slot,
parent_blockhash: message.parent_blockhash.clone(),
}), }),
Message::BlockMeta(message) => UpdateOneof::BlockMeta(SubscribeUpdateBlockMeta { Message::BlockMeta(message) => UpdateOneof::BlockMeta(SubscribeUpdateBlockMeta {
slot: message.slot, slot: message.slot,
@ -257,6 +246,9 @@ impl From<&Message> for UpdateOneof {
rewards: Some(message.rewards.as_slice().into()), rewards: Some(message.rewards.as_slice().into()),
block_time: message.block_time.map(|v| v.into()), block_time: message.block_time.map(|v| v.into()),
block_height: message.block_height.map(|v| v.into()), block_height: message.block_height.map(|v| v.into()),
parent_slot: message.parent_slot,
parent_blockhash: message.parent_blockhash.clone(),
executed_transaction_count: message.executed_transaction_count,
}), }),
} }
} }

View File

@ -103,6 +103,13 @@ impl GeyserPlugin for Plugin {
is_startup: bool, is_startup: bool,
) -> PluginResult<()> { ) -> PluginResult<()> {
self.with_inner(|inner| { self.with_inner(|inner| {
let account = match account {
ReplicaAccountInfoVersions::V0_0_1(_info) => {
unreachable!("ReplicaAccountInfoVersions::V0_0_1 is not supported")
}
ReplicaAccountInfoVersions::V0_0_2(info) => info,
};
let message = Message::Account((account, slot, is_startup).into()); let message = Message::Account((account, slot, is_startup).into());
let _ = inner.grpc_channel.send(message); let _ = inner.grpc_channel.send(message);
Ok(()) Ok(())
@ -137,6 +144,13 @@ impl GeyserPlugin for Plugin {
slot: u64, slot: u64,
) -> PluginResult<()> { ) -> PluginResult<()> {
self.with_inner(|inner| { self.with_inner(|inner| {
let transaction = match transaction {
ReplicaTransactionInfoVersions::V0_0_1(_info) => {
unreachable!("ReplicaAccountInfoVersions::V0_0_1 is not supported")
}
ReplicaTransactionInfoVersions::V0_0_2(info) => info,
};
let msg_tx: MessageTransaction = (transaction, slot).into(); let msg_tx: MessageTransaction = (transaction, slot).into();
match &mut inner.transactions { match &mut inner.transactions {
Some((current_slot, transactions)) if *current_slot == slot => { Some((current_slot, transactions)) if *current_slot == slot => {
@ -168,21 +182,38 @@ impl GeyserPlugin for Plugin {
blockinfo: ReplicaBlockInfoVersions<'_>, blockinfo: ReplicaBlockInfoVersions<'_>,
) -> PluginResult<()> { ) -> PluginResult<()> {
self.with_inner(|inner| { self.with_inner(|inner| {
let ReplicaBlockInfoVersions::V0_0_1(block) = &blockinfo; let blockinfo = match blockinfo {
ReplicaBlockInfoVersions::V0_0_1(_info) => {
unreachable!("ReplicaBlockInfoVersions::V0_0_1 is not supported")
}
ReplicaBlockInfoVersions::V0_0_2(info) => info,
};
let transactions = match inner.transactions.take() { let transactions = match inner.transactions.take() {
Some((slot, transactions)) if slot == block.slot => Ok(transactions), Some((slot, _transactions)) if slot != blockinfo.slot => Err(format!(
Some((slot, _)) => Err(format!( "invalid transactions for block {}, expected block {}",
"invalid transactions for block {}, found {}", blockinfo.slot, slot
block.slot, slot
)), )),
None => Err(format!("no transactions for block {}", block.slot)), Some((_slot, transactions))
if transactions.len() != blockinfo.executed_transaction_count as usize =>
{
Err(format!(
"invalid count of transactions for block {}, collected {}, expected {}",
blockinfo.slot,
transactions.len(),
blockinfo.executed_transaction_count
))
}
Some((_slot, transactions)) => Ok(transactions),
None if blockinfo.executed_transaction_count == 0 => Ok(vec![]),
None => Err(format!("no transactions for block {}", blockinfo.slot)),
}; };
match transactions { match transactions {
Ok(transactions) => { Ok(transactions) => {
let message = Message::Block((&blockinfo, transactions).into()); let message = Message::Block((blockinfo, transactions).into());
let _ = inner.grpc_channel.send(message); let _ = inner.grpc_channel.send(message);
let message = Message::BlockMeta((&blockinfo).into()); let message = Message::BlockMeta((blockinfo).into());
let _ = inner.grpc_channel.send(message); let _ = inner.grpc_channel.send(message);
Ok(()) Ok(())
} }