yellowstone-block-machine 0.9.0-rc2

State machine for reconstructing Solana blocks from Geyser events
Documentation
use solana_clock::Slot;

///
/// The lifecycle/commitment status of a slot, independent of any specific Geyser wire format.
///
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SlotStatusKind {
    FirstShredReceived,
    Completed,
    CreatedBank,
    Dead,
    Processed,
    Confirmed,
    Finalized,
    ///
    /// Any status not recognized by this crate. Keeps the abstraction forward-compatible with
    /// new statuses introduced by a Geyser wire format without requiring a breaking change here.
    ///
    Other,
}

///
/// A borrowed view over a slot lifecycle/commitment update.
///
#[derive(Debug, Clone, Copy)]
pub struct SlotUpdateView {
    pub slot: Slot,
    pub parent: Option<Slot>,
    pub status: SlotStatusKind,
    pub dead_error: bool,
}

///
/// A borrowed view over a block metadata (summary) update.
///
#[derive(Debug, Clone, Copy)]
pub struct BlockMetaView<'a> {
    pub slot: Slot,
    pub parent_slot: Slot,
    pub entries_count: u64,
    pub executed_transaction_count: u64,
    pub blockhash: &'a str,
}

///
/// A borrowed view over a block entry update.
///
#[derive(Debug, Clone, Copy)]
pub struct EntryView<'a> {
    pub slot: Slot,
    pub index: u64,
    pub starting_transaction_index: u64,
    pub executed_transaction_count: u64,
    pub hash: &'a [u8],
    ///
    /// The names of the subscription filters that matched this event. Used to distinguish
    /// entries received only because of the crate's internal reserved filter (and therefore not
    /// requested by the caller) from entries the caller explicitly subscribed to.
    ///
    pub filters: &'a [String],
}

///
/// A borrowed, wire-format-agnostic view over a single Geyser event.
///
/// This is the abstraction boundary that lets [`crate::wrapper::BlocksStateMachineWrapper`]
/// and [`crate::stream::BlockStream`] operate over any event source, not just a specific version
/// of `yellowstone_grpc_proto`.
///
#[derive(Debug, Clone, Copy)]
pub enum GeyserEventView<'a> {
    Slot(SlotUpdateView),
    BlockMeta(BlockMetaView<'a>),
    Entry(EntryView<'a>),
    Transaction { slot: Slot },
    Account { slot: Slot },
    TransactionStatus { slot: Slot },
    ///
    /// Any event kind not used by block reconstruction (or not recognized by this crate).
    ///
    Other,
}

///
/// Knows how to view a raw Geyser event (of type [`GeyserEventT`](GeyserEventViewer::GeyserEventT)),
/// abstracted away from any specific wire format.
///
/// The implementing type does not have to be the event type itself. This lets you bridge a Geyser
/// event type you don't own (e.g. `yellowstone_grpc_proto::geyser::SubscribeUpdate` from a version
/// pinned by another crate) by implementing this trait on a small local marker type instead —
/// satisfying Rust's orphan rules, since only the implementing type (not the associated type) needs
/// to be local to your crate.
///
pub trait GeyserEventViewer {
    ///
    /// The raw Geyser event type this viewer knows how to view.
    ///
    type GeyserEventT;

    fn view(event: &Self::GeyserEventT) -> GeyserEventView<'_>;
}