From d36f8ba027f5388d2779a1d7479bdf1cd3a61742 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Thu, 6 Feb 2025 11:03:41 -0500 Subject: [PATCH] proto: add enum `SlotStatus` (#529) --- CHANGELOG.md | 12 ++ Cargo.lock | 8 +- Cargo.toml | 12 +- examples/rust/Cargo.toml | 2 +- examples/typescript/package-lock.json | 6 +- examples/typescript/package.json | 2 +- .../package-lock.json | 4 +- yellowstone-grpc-client-nodejs/package.json | 2 +- .../solana-encoding-wasm/Cargo.lock | 2 +- .../solana-encoding-wasm/Cargo.toml | 2 +- yellowstone-grpc-client/Cargo.toml | 2 +- yellowstone-grpc-geyser/Cargo.toml | 2 +- yellowstone-grpc-geyser/src/grpc.rs | 50 ++++---- yellowstone-grpc-geyser/src/metrics.rs | 10 +- yellowstone-grpc-proto/Cargo.toml | 2 +- yellowstone-grpc-proto/proto/geyser.proto | 16 ++- .../src/plugin/filter/filter.rs | 11 +- .../src/plugin/filter/message.rs | 36 +++--- yellowstone-grpc-proto/src/plugin/message.rs | 118 ++++++++++++------ 19 files changed, 181 insertions(+), 118 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee40f5bf..6664ae02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,18 @@ The minor version will be incremented upon a breaking change and the patch versi ### Breaking +## 2025-02-06 + +- @triton-one/yellowstone-grpc@3.0.0 +- yellowstone-grpc-client-simple-5.0.0 +- yellowstone-grpc-client-5.0.0 +- yellowstone-grpc-geyser-5.0.0 +- yellowstone-grpc-proto-5.0.0 + +### Breaking + +- proto: add enum `SlotStatus` ([#529](https://github.com/rpcpool/yellowstone-grpc/pull/529)) + ## 2025-02-05 - yellowstone-grpc-client-simple-4.4.1 diff --git a/Cargo.lock b/Cargo.lock index fd693a76..bd563df1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5960,7 +5960,7 @@ checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" [[package]] name = "yellowstone-grpc-client" -version = "4.2.1" +version = "5.0.0" dependencies = [ "bytes", "futures", @@ -5973,7 +5973,7 @@ dependencies = [ [[package]] name = "yellowstone-grpc-client-simple" -version = "4.4.1" +version = "5.0.0" dependencies = [ "anyhow", "backoff", @@ -5998,7 +5998,7 @@ dependencies = [ [[package]] name = "yellowstone-grpc-geyser" -version = "4.3.1" +version = "5.0.0" dependencies = [ "affinity", "agave-geyser-plugin-interface", @@ -6038,7 +6038,7 @@ dependencies = [ [[package]] name = "yellowstone-grpc-proto" -version = "4.2.1" +version = "5.0.0" dependencies = [ "agave-geyser-plugin-interface", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 2a988d60..080f24ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [workspace] resolver = "2" members = [ - "examples/rust", # 4.4.1 - "yellowstone-grpc-client", # 4.2.1 - "yellowstone-grpc-geyser", # 4.3.1 - "yellowstone-grpc-proto", # 4.2.1 + "examples/rust", # 5.0.0 + "yellowstone-grpc-client", # 5.0.0 + "yellowstone-grpc-geyser", # 5.0.0 + "yellowstone-grpc-proto", # 5.0.0 ] exclude = [ "yellowstone-grpc-client-nodejs/solana-encoding-wasm", # 3.0.0 @@ -69,8 +69,8 @@ tonic = "0.12.1" tonic-build = "0.12.1" tonic-health = "0.12.1" vergen = "9.0.0" -yellowstone-grpc-client = { path = "yellowstone-grpc-client", version = "4.2.1" } -yellowstone-grpc-proto = { path = "yellowstone-grpc-proto", version = "4.2.1", default-features = false } +yellowstone-grpc-client = { path = "yellowstone-grpc-client", version = "5.0.0" } +yellowstone-grpc-proto = { path = "yellowstone-grpc-proto", version = "5.0.0", default-features = false } [workspace.lints.clippy] clone_on_ref_ptr = "deny" diff --git a/examples/rust/Cargo.toml b/examples/rust/Cargo.toml index a0430be5..ab732285 100644 --- a/examples/rust/Cargo.toml +++ b/examples/rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yellowstone-grpc-client-simple" -version = "4.4.1" +version = "5.0.0" authors = { workspace = true } edition = { workspace = true } homepage = { workspace = true } diff --git a/examples/typescript/package-lock.json b/examples/typescript/package-lock.json index c0e12994..4b3a6076 100644 --- a/examples/typescript/package-lock.json +++ b/examples/typescript/package-lock.json @@ -1,12 +1,12 @@ { "name": "yellowstone-grpc-client-example-ts", - "version": "2.1.0", + "version": "3.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "yellowstone-grpc-client-example-ts", - "version": "2.1.0", + "version": "3.0.0", "license": "Apache-2.0", "dependencies": { "@triton-one/yellowstone-grpc": "file:../../yellowstone-grpc-client-nodejs", @@ -19,7 +19,7 @@ }, "../../yellowstone-grpc-client-nodejs": { "name": "@triton-one/yellowstone-grpc", - "version": "2.1.0", + "version": "3.0.0", "license": "Apache-2.0", "dependencies": { "@grpc/grpc-js": "^1.8.0" diff --git a/examples/typescript/package.json b/examples/typescript/package.json index ad0f2be4..9e5be0ab 100644 --- a/examples/typescript/package.json +++ b/examples/typescript/package.json @@ -1,6 +1,6 @@ { "name": "yellowstone-grpc-client-example-ts", - "version": "2.1.0", + "version": "3.0.0", "license": "Apache-2.0", "author": "Triton One", "main": "dist/client.js", diff --git a/yellowstone-grpc-client-nodejs/package-lock.json b/yellowstone-grpc-client-nodejs/package-lock.json index b99bd70d..bf173bad 100644 --- a/yellowstone-grpc-client-nodejs/package-lock.json +++ b/yellowstone-grpc-client-nodejs/package-lock.json @@ -1,12 +1,12 @@ { "name": "@triton-one/yellowstone-grpc", - "version": "2.1.0", + "version": "3.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@triton-one/yellowstone-grpc", - "version": "2.1.0", + "version": "3.0.0", "license": "Apache-2.0", "dependencies": { "@grpc/grpc-js": "^1.8.0" diff --git a/yellowstone-grpc-client-nodejs/package.json b/yellowstone-grpc-client-nodejs/package.json index 09513ad0..2a39be8e 100644 --- a/yellowstone-grpc-client-nodejs/package.json +++ b/yellowstone-grpc-client-nodejs/package.json @@ -1,6 +1,6 @@ { "name": "@triton-one/yellowstone-grpc", - "version": "2.1.0", + "version": "3.0.0", "license": "Apache-2.0", "author": "Triton One", "description": "Yellowstone gRPC Geyser Node.js Client", diff --git a/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.lock b/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.lock index b4a0109e..18a8f2d6 100644 --- a/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.lock +++ b/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.lock @@ -3259,7 +3259,7 @@ dependencies = [ [[package]] name = "yellowstone-grpc-proto" -version = "4.2.1" +version = "5.0.0" dependencies = [ "anyhow", "bincode", diff --git a/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.toml b/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.toml index 9f287bef..f4c438bc 100644 --- a/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.toml +++ b/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.toml @@ -16,7 +16,7 @@ crate-type = ["cdylib"] serde_json = "1.0.86" solana-transaction-status = "~2.1.1" wasm-bindgen = "0.2.95" -yellowstone-grpc-proto = { path = "../../yellowstone-grpc-proto", version = "4.1.1", default-features = false, features = ["convert"] } +yellowstone-grpc-proto = { path = "../../yellowstone-grpc-proto", version = "5.0.0", default-features = false, features = ["convert"] } [workspace.lints.clippy] clone_on_ref_ptr = "deny" diff --git a/yellowstone-grpc-client/Cargo.toml b/yellowstone-grpc-client/Cargo.toml index 09fe03cf..dc670ae7 100644 --- a/yellowstone-grpc-client/Cargo.toml +++ b/yellowstone-grpc-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yellowstone-grpc-client" -version = "4.2.1" +version = "5.0.0" authors = { workspace = true } edition = { workspace = true } description = "Yellowstone gRPC Geyser Simple Client" diff --git a/yellowstone-grpc-geyser/Cargo.toml b/yellowstone-grpc-geyser/Cargo.toml index 775e4d7a..0c703487 100644 --- a/yellowstone-grpc-geyser/Cargo.toml +++ b/yellowstone-grpc-geyser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yellowstone-grpc-geyser" -version = "4.3.1" +version = "5.0.0" authors = { workspace = true } edition = { workspace = true } description = "Yellowstone gRPC Geyser Plugin" diff --git a/yellowstone-grpc-geyser/src/grpc.rs b/yellowstone-grpc-geyser/src/grpc.rs index 14595960..92ddb069 100644 --- a/yellowstone-grpc-geyser/src/grpc.rs +++ b/yellowstone-grpc-geyser/src/grpc.rs @@ -46,7 +46,7 @@ use { }, message::{ CommitmentLevel, Message, MessageBlock, MessageBlockMeta, MessageEntry, - MessageSlot, MessageTransactionInfo, + MessageSlot, MessageTransactionInfo, SlotStatus, }, proto::geyser_server::{Geyser, GeyserServer}, }, @@ -107,13 +107,13 @@ impl BlockMetaStorage { match message { Message::Slot(msg) => { match msg.status { - CommitmentLevel::Processed => { + SlotStatus::Processed => { storage.processed.replace(msg.slot); } - CommitmentLevel::Confirmed => { + SlotStatus::Confirmed => { storage.confirmed.replace(msg.slot); } - CommitmentLevel::Finalized => { + SlotStatus::Finalized => { storage.finalized.replace(msg.slot); } _ => {} @@ -130,20 +130,20 @@ impl BlockMetaStorage { .or_insert_with(|| BlockhashStatus::new(msg.slot)); match msg.status { - CommitmentLevel::Processed => { + SlotStatus::Processed => { entry.processed = true; } - CommitmentLevel::Confirmed => { + SlotStatus::Confirmed => { entry.confirmed = true; } - CommitmentLevel::Finalized => { + SlotStatus::Finalized => { entry.finalized = true; } _ => {} } } - if msg.status == CommitmentLevel::Finalized { + if msg.status == SlotStatus::Finalized { if let Some(keep_slot) = msg.slot.checked_sub(KEEP_SLOTS) { storage.blocks.retain(|slot, _block| *slot >= keep_slot); } @@ -202,7 +202,6 @@ impl BlockMetaStorage { CommitmentLevel::Processed => storage.processed, CommitmentLevel::Confirmed => storage.confirmed, CommitmentLevel::Finalized => storage.finalized, - _ => return Err(Status::internal("unreachable")), }; match slot.and_then(|slot| storage.blocks.get(&slot)) { @@ -231,7 +230,6 @@ impl BlockMetaStorage { CommitmentLevel::Processed => storage.processed, CommitmentLevel::Confirmed => storage.confirmed, CommitmentLevel::Finalized => storage.finalized, - _ => return Err(Status::internal("unreachable")), } .ok_or_else(|| Status::internal("startup"))?; @@ -239,12 +237,10 @@ impl BlockMetaStorage { .blockhashes .get(blockhash) .map(|status| match commitment { - CommitmentLevel::Processed => Ok(status.processed), - CommitmentLevel::Confirmed => Ok(status.confirmed), - CommitmentLevel::Finalized => Ok(status.finalized), - _ => Err(Status::internal("unreachable")), + CommitmentLevel::Processed => status.processed, + CommitmentLevel::Confirmed => status.confirmed, + CommitmentLevel::Finalized => status.finalized, }) - .transpose()? .unwrap_or(false); Ok(Response::new(IsBlockhashValidResponse { valid, slot })) @@ -548,10 +544,10 @@ impl GrpcService { match &message { // On startup we can receive multiple Confirmed/Finalized slots without BlockMeta message // With saved first Processed slot we can ignore errors caused by startup process - Message::Slot(msg) if processed_first_slot.is_none() && msg.status == CommitmentLevel::Processed => { + Message::Slot(msg) if processed_first_slot.is_none() && msg.status == SlotStatus::Processed => { processed_first_slot = Some(msg.slot); } - Message::Slot(msg) if msg.status == CommitmentLevel::Finalized => { + Message::Slot(msg) if msg.status == SlotStatus::Finalized => { // keep extra 10 slots + slots for replay if let Some(msg_slot) = msg.slot.checked_sub(10 + replay_stored_slots) { loop { @@ -600,13 +596,13 @@ impl GrpcService { let slot_messages = messages.entry(message.get_slot()).or_default(); if let Message::Slot(msg) = &message { match msg.status { - CommitmentLevel::Processed => { + SlotStatus::Processed => { slot_messages.parent_slot = msg.parent; }, - CommitmentLevel::Confirmed => { + SlotStatus::Confirmed => { slot_messages.confirmed = true; }, - CommitmentLevel::Finalized => { + SlotStatus::Finalized => { slot_messages.finalized = true; }, _ => {} @@ -685,12 +681,12 @@ impl GrpcService { .and_then(|entry| entry.parent_slot) .map(|parent| (parent, messages.get_mut(&parent))) { - if (status == CommitmentLevel::Confirmed && !entry.confirmed) || - (status == CommitmentLevel::Finalized && !entry.finalized) + if (status == SlotStatus::Confirmed && !entry.confirmed) || + (status == SlotStatus::Finalized && !entry.finalized) { - if status == CommitmentLevel::Confirmed { + if status == SlotStatus::Confirmed { entry.confirmed = true; - } else if status == CommitmentLevel::Finalized { + } else if status == SlotStatus::Finalized { entry.finalized = true; } @@ -711,10 +707,10 @@ impl GrpcService { for message in messages_vec.into_iter().rev() { if let Message::Slot(slot) = &message.1 { let (mut confirmed_messages, mut finalized_messages) = match slot.status { - CommitmentLevel::Processed | CommitmentLevel::FirstShredReceived | CommitmentLevel::Completed | CommitmentLevel::CreatedBank | CommitmentLevel::Dead => { + SlotStatus::Processed | SlotStatus::FirstShredReceived | SlotStatus::Completed | SlotStatus::CreatedBank | SlotStatus::Dead => { (Vec::with_capacity(1), Vec::with_capacity(1)) } - CommitmentLevel::Confirmed => { + SlotStatus::Confirmed => { if let Some(slot_messages) = messages.get_mut(&slot.slot) { if !slot_messages.sealed { slot_messages.confirmed_at = Some(slot_messages.messages.len()); @@ -727,7 +723,7 @@ impl GrpcService { .unwrap_or_default(); (vec, Vec::with_capacity(1)) } - CommitmentLevel::Finalized => { + SlotStatus::Finalized => { if let Some(slot_messages) = messages.get_mut(&slot.slot) { if !slot_messages.sealed { slot_messages.finalized_at = Some(slot_messages.messages.len()); diff --git a/yellowstone-grpc-geyser/src/metrics.rs b/yellowstone-grpc-geyser/src/metrics.rs index c0c8be33..0c959ecd 100644 --- a/yellowstone-grpc-geyser/src/metrics.rs +++ b/yellowstone-grpc-geyser/src/metrics.rs @@ -1,6 +1,6 @@ use { crate::{config::ConfigPrometheus, version::VERSION as VERSION_INFO}, - agave_geyser_plugin_interface::geyser_plugin_interface::SlotStatus, + agave_geyser_plugin_interface::geyser_plugin_interface::SlotStatus as GeyserSlosStatus, http_body_util::{combinators::BoxBody, BodyExt, Empty as BodyEmpty, Full as BodyFull}, hyper::{ body::{Bytes, Incoming as BodyIncoming}, @@ -24,7 +24,7 @@ use { sync::{mpsc, oneshot, Notify}, task::JoinHandle, }, - yellowstone_grpc_proto::plugin::{filter::Filter, message::CommitmentLevel}, + yellowstone_grpc_proto::plugin::{filter::Filter, message::SlotStatus}, }; lazy_static::lazy_static! { @@ -314,13 +314,13 @@ fn not_found_handler() -> http::Result>> { .body(BodyEmpty::new().boxed()) } -pub fn update_slot_status(status: &SlotStatus, slot: u64) { +pub fn update_slot_status(status: &GeyserSlosStatus, slot: u64) { SLOT_STATUS .with_label_values(&[status.as_str()]) .set(slot as i64); } -pub fn update_slot_plugin_status(status: CommitmentLevel, slot: u64) { +pub fn update_slot_plugin_status(status: SlotStatus, slot: u64) { SLOT_STATUS_PLUGIN .with_label_values(&[status.as_str()]) .set(slot as i64); @@ -365,7 +365,7 @@ pub fn update_subscriptions(endpoint: &str, old: Option<&Filter>, new: Option<&F } } -pub fn missed_status_message_inc(status: CommitmentLevel) { +pub fn missed_status_message_inc(status: SlotStatus) { MISSED_STATUS_MESSAGE .with_label_values(&[status.as_str()]) .inc() diff --git a/yellowstone-grpc-proto/Cargo.toml b/yellowstone-grpc-proto/Cargo.toml index fb580b68..80c261ea 100644 --- a/yellowstone-grpc-proto/Cargo.toml +++ b/yellowstone-grpc-proto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yellowstone-grpc-proto" -version = "4.2.1" +version = "5.0.0" authors = { workspace = true } edition = { workspace = true } description = "Yellowstone gRPC Geyser Protobuf Definitions" diff --git a/yellowstone-grpc-proto/proto/geyser.proto b/yellowstone-grpc-proto/proto/geyser.proto index 89a6c730..175a646d 100644 --- a/yellowstone-grpc-proto/proto/geyser.proto +++ b/yellowstone-grpc-proto/proto/geyser.proto @@ -21,10 +21,16 @@ enum CommitmentLevel { PROCESSED = 0; CONFIRMED = 1; FINALIZED = 2; - FIRST_SHRED_RECEIVED = 3; - COMPLETED = 4; - CREATED_BANK = 5; - DEAD = 6; +} + +enum SlotStatus { + SLOT_PROCESSED = 0; + SLOT_CONFIRMED = 1; + SLOT_FINALIZED = 2; + SLOT_FIRST_SHRED_RECEIVED = 3; + SLOT_COMPLETED = 4; + SLOT_CREATED_BANK = 5; + SLOT_DEAD = 6; } message SubscribeRequest { @@ -145,7 +151,7 @@ message SubscribeUpdateAccountInfo { message SubscribeUpdateSlot { uint64 slot = 1; optional uint64 parent = 2; - CommitmentLevel status = 3; + SlotStatus status = 3; optional string dead_error = 4; } diff --git a/yellowstone-grpc-proto/src/plugin/filter/filter.rs b/yellowstone-grpc-proto/src/plugin/filter/filter.rs index 8e70e164..763ebfba 100644 --- a/yellowstone-grpc-proto/src/plugin/filter/filter.rs +++ b/yellowstone-grpc-proto/src/plugin/filter/filter.rs @@ -26,7 +26,7 @@ use { }, message::{ CommitmentLevel, Message, MessageAccount, MessageBlock, MessageBlockMeta, - MessageEntry, MessageSlot, MessageTransaction, + MessageEntry, MessageSlot, MessageTransaction, SlotStatus, }, }, }, @@ -637,13 +637,14 @@ impl FilterSlots { .filters .iter() .filter_map(|(name, inner)| { - if (!inner.filter_by_commitment || commitment == Some(message.status)) + if (!inner.filter_by_commitment + || commitment + .map(|commitment| commitment == message.status) + .unwrap_or(false)) && (inner.interslot_updates || matches!( message.status, - CommitmentLevel::Processed - | CommitmentLevel::Confirmed - | CommitmentLevel::Finalized + SlotStatus::Processed | SlotStatus::Confirmed | SlotStatus::Finalized )) { Some(name.clone()) diff --git a/yellowstone-grpc-proto/src/plugin/filter/message.rs b/yellowstone-grpc-proto/src/plugin/filter/message.rs index 3cf76f0d..2ce44689 100644 --- a/yellowstone-grpc-proto/src/plugin/filter/message.rs +++ b/yellowstone-grpc-proto/src/plugin/filter/message.rs @@ -1,10 +1,10 @@ use { crate::{ geyser::{ - subscribe_update::UpdateOneof, CommitmentLevel as CommitmentLevelProto, - SubscribeUpdate, SubscribeUpdateAccount, SubscribeUpdateAccountInfo, - SubscribeUpdateBlock, SubscribeUpdateEntry, SubscribeUpdatePing, SubscribeUpdatePong, - SubscribeUpdateSlot, SubscribeUpdateTransaction, SubscribeUpdateTransactionInfo, + subscribe_update::UpdateOneof, SlotStatus as SlotStatusProto, SubscribeUpdate, + SubscribeUpdateAccount, SubscribeUpdateAccountInfo, SubscribeUpdateBlock, + SubscribeUpdateEntry, SubscribeUpdatePing, SubscribeUpdatePong, SubscribeUpdateSlot, + SubscribeUpdateTransaction, SubscribeUpdateTransactionInfo, SubscribeUpdateTransactionStatus, }, plugin::{ @@ -565,14 +565,14 @@ impl DerefMut for FilteredUpdateSlot { impl prost::Message for FilteredUpdateSlot { fn encode_raw(&self, buf: &mut impl BufMut) { - let status = CommitmentLevelProto::from(self.status) as i32; + let status = SlotStatusProto::from(self.status) as i32; if self.slot != 0u64 { ::prost::encoding::uint64::encode(1u32, &self.slot, buf); } if let ::core::option::Option::Some(ref value) = self.parent { ::prost::encoding::uint64::encode(2u32, value, buf); } - if status != CommitmentLevelProto::default() as i32 { + if status != SlotStatusProto::default() as i32 { ::prost::encoding::int32::encode(3u32, &status, buf); } if let Some(error) = &self.dead_error { @@ -581,7 +581,7 @@ impl prost::Message for FilteredUpdateSlot { } fn encoded_len(&self) -> usize { - let status = CommitmentLevelProto::from(self.status) as i32; + let status = SlotStatusProto::from(self.status) as i32; (if self.slot != 0u64 { ::prost::encoding::uint64::encoded_len(1u32, &self.slot) @@ -589,7 +589,7 @@ impl prost::Message for FilteredUpdateSlot { 0 }) + self.parent.as_ref().map_or(0, |value| { ::prost::encoding::uint64::encoded_len(2u32, value) - }) + if status != CommitmentLevelProto::default() as i32 { + }) + if status != SlotStatusProto::default() as i32 { ::prost::encoding::int32::encoded_len(3u32, &status) } else { 0 @@ -986,8 +986,8 @@ pub mod tests { plugin::{ filter::{name::FilterName, FilterAccountsDataSlice}, message::{ - CommitmentLevel, MessageAccount, MessageAccountInfo, MessageBlockMeta, - MessageEntry, MessageSlot, MessageTransaction, MessageTransactionInfo, + MessageAccount, MessageAccountInfo, MessageBlockMeta, MessageEntry, + MessageSlot, MessageTransaction, MessageTransactionInfo, SlotStatus, }, }, }, @@ -1265,13 +1265,13 @@ pub mod tests { for slot in [0, 42] { for parent in [None, Some(0), Some(42)] { for status in [ - CommitmentLevel::Processed, - CommitmentLevel::Confirmed, - CommitmentLevel::Finalized, - CommitmentLevel::FirstShredReceived, - CommitmentLevel::Completed, - CommitmentLevel::CreatedBank, - CommitmentLevel::Dead, + SlotStatus::Processed, + SlotStatus::Confirmed, + SlotStatus::Finalized, + SlotStatus::FirstShredReceived, + SlotStatus::Completed, + SlotStatus::CreatedBank, + SlotStatus::Dead, ] { encode_decode_cmp( &["123"], @@ -1289,7 +1289,7 @@ pub mod tests { FilteredUpdateOneof::slot(MessageSlot { slot, parent, - status: CommitmentLevel::Dead, + status: SlotStatus::Dead, dead_error: Some("123".to_owned()), created_at: Timestamp::from(SystemTime::now()), }), diff --git a/yellowstone-grpc-proto/src/plugin/message.rs b/yellowstone-grpc-proto/src/plugin/message.rs index 8ad2e5b9..c528d72e 100644 --- a/yellowstone-grpc-proto/src/plugin/message.rs +++ b/yellowstone-grpc-proto/src/plugin/message.rs @@ -3,15 +3,15 @@ use { convert_to, geyser::{ subscribe_update::UpdateOneof, CommitmentLevel as CommitmentLevelProto, - SubscribeUpdateAccount, SubscribeUpdateAccountInfo, SubscribeUpdateBlock, - SubscribeUpdateBlockMeta, SubscribeUpdateEntry, SubscribeUpdateSlot, - SubscribeUpdateTransaction, SubscribeUpdateTransactionInfo, + SlotStatus as SlotStatusProto, SubscribeUpdateAccount, SubscribeUpdateAccountInfo, + SubscribeUpdateBlock, SubscribeUpdateBlockMeta, SubscribeUpdateEntry, + SubscribeUpdateSlot, SubscribeUpdateTransaction, SubscribeUpdateTransactionInfo, }, solana::storage::confirmed_block, }, agave_geyser_plugin_interface::geyser_plugin_interface::{ ReplicaAccountInfoV3, ReplicaBlockInfoV4, ReplicaEntryInfoV2, ReplicaTransactionInfoV2, - SlotStatus, + SlotStatus as GeyserSlotStatus, }, prost_types::Timestamp, solana_sdk::{ @@ -35,24 +35,6 @@ pub enum CommitmentLevel { Processed, Confirmed, Finalized, - FirstShredReceived, - Completed, - CreatedBank, - Dead, -} - -impl From<&SlotStatus> for CommitmentLevel { - fn from(status: &SlotStatus) -> Self { - match status { - SlotStatus::Processed => Self::Processed, - SlotStatus::Confirmed => Self::Confirmed, - SlotStatus::Rooted => Self::Finalized, - SlotStatus::FirstShredReceived => Self::FirstShredReceived, - SlotStatus::Completed => Self::Completed, - SlotStatus::CreatedBank => Self::CreatedBank, - SlotStatus::Dead(_error) => Self::Dead, - } - } } impl From for CommitmentLevelProto { @@ -61,10 +43,6 @@ impl From for CommitmentLevelProto { CommitmentLevel::Processed => Self::Processed, CommitmentLevel::Confirmed => Self::Confirmed, CommitmentLevel::Finalized => Self::Finalized, - CommitmentLevel::FirstShredReceived => Self::FirstShredReceived, - CommitmentLevel::Completed => Self::Completed, - CommitmentLevel::CreatedBank => Self::CreatedBank, - CommitmentLevel::Dead => Self::Dead, } } } @@ -75,15 +53,85 @@ impl From for CommitmentLevel { CommitmentLevelProto::Processed => Self::Processed, CommitmentLevelProto::Confirmed => Self::Confirmed, CommitmentLevelProto::Finalized => Self::Finalized, - CommitmentLevelProto::FirstShredReceived => Self::FirstShredReceived, - CommitmentLevelProto::Completed => Self::Completed, - CommitmentLevelProto::CreatedBank => Self::CreatedBank, - CommitmentLevelProto::Dead => Self::Dead, } } } impl CommitmentLevel { + pub const fn as_str(&self) -> &'static str { + match self { + Self::Processed => "processed", + Self::Confirmed => "confirmed", + Self::Finalized => "finalized", + } + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +pub enum SlotStatus { + Processed, + Confirmed, + Finalized, + FirstShredReceived, + Completed, + CreatedBank, + Dead, +} + +impl From<&GeyserSlotStatus> for SlotStatus { + fn from(status: &GeyserSlotStatus) -> Self { + match status { + GeyserSlotStatus::Processed => Self::Processed, + GeyserSlotStatus::Confirmed => Self::Confirmed, + GeyserSlotStatus::Rooted => Self::Finalized, + GeyserSlotStatus::FirstShredReceived => Self::FirstShredReceived, + GeyserSlotStatus::Completed => Self::Completed, + GeyserSlotStatus::CreatedBank => Self::CreatedBank, + GeyserSlotStatus::Dead(_error) => Self::Dead, + } + } +} + +impl From for SlotStatus { + fn from(status: SlotStatusProto) -> Self { + match status { + SlotStatusProto::SlotProcessed => Self::Processed, + SlotStatusProto::SlotConfirmed => Self::Confirmed, + SlotStatusProto::SlotFinalized => Self::Finalized, + SlotStatusProto::SlotFirstShredReceived => Self::FirstShredReceived, + SlotStatusProto::SlotCompleted => Self::Completed, + SlotStatusProto::SlotCreatedBank => Self::CreatedBank, + SlotStatusProto::SlotDead => Self::Dead, + } + } +} + +impl From for SlotStatusProto { + fn from(status: SlotStatus) -> Self { + match status { + SlotStatus::Processed => Self::SlotProcessed, + SlotStatus::Confirmed => Self::SlotConfirmed, + SlotStatus::Finalized => Self::SlotFinalized, + SlotStatus::FirstShredReceived => Self::SlotFirstShredReceived, + SlotStatus::Completed => Self::SlotCompleted, + SlotStatus::CreatedBank => Self::SlotCreatedBank, + SlotStatus::Dead => Self::SlotDead, + } + } +} + +impl PartialEq for CommitmentLevel { + fn eq(&self, other: &SlotStatus) -> bool { + match self { + Self::Processed if *other == SlotStatus::Processed => true, + Self::Confirmed if *other == SlotStatus::Confirmed => true, + Self::Finalized if *other == SlotStatus::Finalized => true, + _ => false, + } + } +} + +impl SlotStatus { pub const fn as_str(&self) -> &'static str { match self { Self::Processed => "processed", @@ -101,18 +149,18 @@ impl CommitmentLevel { pub struct MessageSlot { pub slot: Slot, pub parent: Option, - pub status: CommitmentLevel, + pub status: SlotStatus, pub dead_error: Option, pub created_at: Timestamp, } impl MessageSlot { - pub fn from_geyser(slot: Slot, parent: Option, status: &SlotStatus) -> Self { + pub fn from_geyser(slot: Slot, parent: Option, status: &GeyserSlotStatus) -> Self { Self { slot, parent, status: status.into(), - dead_error: if let SlotStatus::Dead(error) = status { + dead_error: if let GeyserSlotStatus::Dead(error) = status { Some(error.clone()) } else { None @@ -128,8 +176,8 @@ impl MessageSlot { Ok(Self { slot: msg.slot, parent: msg.parent, - status: CommitmentLevelProto::try_from(msg.status) - .map_err(|_| "failed to parse commitment level")? + status: SlotStatusProto::try_from(msg.status) + .map_err(|_| "failed to parse slot status")? .into(), dead_error: msg.dead_error.clone(), created_at,