Add Geyser entry interfaces (#30872)

* Correct comment

* Use Slot alias

* Add entry interface elements to geyser

* Correct another comment

* Add entry_notifications_enabled method
This commit is contained in:
Tyera 2023-03-24 00:11:04 -06:00 committed by GitHub
parent 08f0fada7e
commit f07b7ac49b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 54 additions and 10 deletions

View File

@ -3,7 +3,11 @@
/// In addition, the dynamic library must export a "C" function _create_plugin which
/// creates the implementation of the plugin.
use {
solana_sdk::{clock::UnixTimestamp, signature::Signature, transaction::SanitizedTransaction},
solana_sdk::{
clock::{Slot, UnixTimestamp},
signature::Signature,
transaction::SanitizedTransaction,
},
solana_transaction_status::{Reward, TransactionStatusMeta},
std::{any::Any, error, io},
thiserror::Error,
@ -158,9 +162,31 @@ pub enum ReplicaTransactionInfoVersions<'a> {
V0_0_2(&'a ReplicaTransactionInfoV2<'a>),
}
#[derive(Clone, Debug)]
pub struct ReplicaEntryInfo<'a> {
/// The slot number of the block containing this Entry
pub slot: Slot,
/// The Entry's index in the block
pub index: usize,
/// The number of hashes since the previous Entry
pub num_hashes: u64,
/// The Entry's SHA-256 hash, generated from the previous Entry's hash with
/// `solana_entry::entry::next_hash()`
pub hash: &'a [u8],
/// The number of executed transactions in the Entry
pub executed_transaction_count: u64,
}
/// A wrapper to future-proof ReplicaEntryInfo handling. To make a change to the structure of
/// ReplicaEntryInfo, add an new enum variant wrapping a newer version, which will force plugin
/// implementations to handle the change.
pub enum ReplicaEntryInfoVersions<'a> {
V0_0_1(&'a ReplicaEntryInfo<'a>),
}
#[derive(Clone, Debug)]
pub struct ReplicaBlockInfo<'a> {
pub slot: u64,
pub slot: Slot,
pub blockhash: &'a str,
pub rewards: &'a [Reward],
pub block_time: Option<UnixTimestamp>,
@ -170,9 +196,9 @@ pub struct ReplicaBlockInfo<'a> {
/// Extending ReplicaBlockInfo by sending the transaction_entries_count.
#[derive(Clone, Debug)]
pub struct ReplicaBlockInfoV2<'a> {
pub parent_slot: u64,
pub parent_slot: Slot,
pub parent_blockhash: &'a str,
pub slot: u64,
pub slot: Slot,
pub blockhash: &'a str,
pub rewards: &'a [Reward],
pub block_time: Option<UnixTimestamp>,
@ -270,7 +296,7 @@ pub trait GeyserPlugin: Any + Send + Sync + std::fmt::Debug {
fn update_account(
&self,
account: ReplicaAccountInfoVersions,
slot: u64,
slot: Slot,
is_startup: bool,
) -> Result<()> {
Ok(())
@ -283,20 +309,31 @@ pub trait GeyserPlugin: Any + Send + Sync + std::fmt::Debug {
/// Called when a slot status is updated
#[allow(unused_variables)]
fn update_slot_status(&self, slot: u64, parent: Option<u64>, status: SlotStatus) -> Result<()> {
fn update_slot_status(
&self,
slot: Slot,
parent: Option<u64>,
status: SlotStatus,
) -> Result<()> {
Ok(())
}
/// Called when a transaction is updated at a slot.
/// Called when a transaction is processed in a slot.
#[allow(unused_variables)]
fn notify_transaction(
&self,
transaction: ReplicaTransactionInfoVersions,
slot: u64,
slot: Slot,
) -> Result<()> {
Ok(())
}
/// Called when an entry is executed.
#[allow(unused_variables)]
fn notify_entry(&self, entry: ReplicaEntryInfoVersions) -> Result<()> {
Ok(())
}
/// Called when block's metadata is updated.
#[allow(unused_variables)]
fn notify_block_metadata(&self, blockinfo: ReplicaBlockInfoVersions) -> Result<()> {
@ -311,9 +348,16 @@ pub trait GeyserPlugin: Any + Send + Sync + std::fmt::Debug {
}
/// Check if the plugin is interested in transaction data
/// Default is false -- if the plugin is not interested in
/// transaction data, please return false.
/// Default is false -- if the plugin is interested in
/// transaction data, please return true.
fn transaction_notifications_enabled(&self) -> bool {
false
}
/// Check if the plugin is interested in entry data
/// Default is false -- if the plugin is interested in
/// entry data, return true.
fn entry_notifications_enabled(&self) -> bool {
false
}
}