Skip to content

Commit

Permalink
upgrade to 2.0 (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
segfaultdoc authored Aug 20, 2024
1 parent b910bbe commit 9451dc3
Show file tree
Hide file tree
Showing 11 changed files with 474 additions and 569 deletions.
883 changes: 342 additions & 541 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ members = [
resolver = "2"

[workspace.package]
version = "1.18.1"
version = "2.0.5"
license = "Apache-2.0"
authors = ["Jito Foundation <[email protected]>"]
edition = "2021"
repository = "https://github.com/jito-foundation/geyser-grpc-plugin"
homepage = "https://jito.network/"

[workspace.dependencies]
agave-geyser-plugin-interface = "=2.0.5"
bincode = "1.3.3"
bs58 = "0.5.0"
clap = { version = "4.4.6", features = ["derive", "env"] }
crossbeam-channel = "0.5.8"
enum-iterator = "1.4.1"
futures-util = "0.3.28"
geyser-grpc-plugin-client = { path = "client", version = "=1.18.1" }
jito-geyser-protos = { path = "proto", version = "=1.18.1" }
geyser-grpc-plugin-client = { path = "client", version = "=2.0.5" }
jito-geyser-protos = { path = "proto", version = "=2.0.5" }
log = "0.4.17"
lru = "0.12.0"
once_cell = "1.17.1"
Expand All @@ -36,14 +37,13 @@ rand = "0.8"
serde = "1.0.160"
serde_derive = "1.0.160"
serde_json = "1.0.96"
solana-account-decoder = "=1.18.1"
solana-geyser-plugin-interface = "=1.18.1"
solana-logger = "=1.18.1"
solana-metrics = "=1.18.1"
solana-program = "=1.18.1"
solana-sdk = "=1.18.1"
solana-transaction-status = "=1.18.1"
solana-vote-program = "=1.18.1"
solana-account-decoder = "=2.0.5"
solana-logger = "=2.0.5"
solana-metrics = "=2.0.5"
solana-program = "=2.0.5"
solana-sdk = "=2.0.5"
solana-transaction-status = "=2.0.5"
solana-vote-program = "=2.0.5"
thiserror = "1.0.40"
tokio = { version = "1", features = ["rt-multi-thread"] }
tokio-stream = "0.1"
Expand Down
3 changes: 2 additions & 1 deletion proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ fn main() {
)
.compile(
&[
"proto/geyser.proto",
"proto/confirmed_block.proto",
"proto/entries.proto",
"proto/geyser.proto",
"proto/transaction_by_addr.proto",
],
&["proto"],
Expand Down
6 changes: 6 additions & 0 deletions proto/proto/confirmed_block.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ message ConfirmedBlock {
repeated Reward rewards = 5;
UnixTimestamp block_time = 6;
BlockHeight block_height = 7;
NumPartitions num_partitions = 8;
}

message ConfirmedTransaction {
Expand Down Expand Up @@ -130,6 +131,7 @@ message Reward {

message Rewards {
repeated Reward rewards = 1;
NumPartitions num_partitions = 2;
}

message UnixTimestamp {
Expand All @@ -139,3 +141,7 @@ message UnixTimestamp {
message BlockHeight {
uint64 block_height = 1;
}

message NumPartitions {
uint64 num_partitions = 1;
}
15 changes: 15 additions & 0 deletions proto/proto/entries.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";

package solana.storage.Entries;

message Entries {
repeated Entry entries = 1;
}

message Entry {
uint32 index = 1;
uint64 num_hashes = 2;
bytes hash = 3;
uint64 num_transactions = 4;
uint32 starting_transaction_index = 5;
}
1 change: 1 addition & 0 deletions proto/proto/transaction_by_addr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum TransactionErrorType {
RESANITIZATION_NEEDED = 34;
PROGRAM_EXECUTION_TEMPORARILY_RESTRICTED = 35;
UNBALANCED_TRANSACTION = 36;
PROGRAM_CACHE_HIT_MAX_LIMIT = 37;
}

message InstructionError {
Expand Down
72 changes: 64 additions & 8 deletions proto/src/convert.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//! Note: most of this copied from solana labs storage-proto files, with the addition of the module definitions below
use std::{
convert::{TryFrom, TryInto},
str::FromStr,
Expand All @@ -19,21 +18,28 @@ use solana_sdk::{
transaction_context::TransactionReturnData,
};
use solana_transaction_status::{
ConfirmedBlock, InnerInstruction, InnerInstructions, Reward, RewardType, TransactionByAddrInfo,
TransactionStatusMeta, TransactionTokenBalance, TransactionWithStatusMeta,
VersionedConfirmedBlock, VersionedTransactionWithStatusMeta,
ConfirmedBlock, EntrySummary, InnerInstruction, InnerInstructions, Reward, RewardType,
RewardsAndNumPartitions, TransactionByAddrInfo, TransactionStatusMeta, TransactionTokenBalance,
TransactionWithStatusMeta, VersionedConfirmedBlock, VersionedTransactionWithStatusMeta,
};

use crate::solana::{entries, tx_by_addr};
use crate::{solana::storage::confirmed_block, StoredExtendedRewards, StoredTransactionStatusMeta};

pub mod tx_by_addr {
tonic::include_proto!("solana.storage.transaction_by_addr");
}

impl From<Vec<Reward>> for confirmed_block::Rewards {
fn from(rewards: Vec<Reward>) -> Self {
Self {
rewards: rewards.into_iter().map(|r| r.into()).collect(),
num_partitions: None,
}
}
}

impl From<RewardsAndNumPartitions> for confirmed_block::Rewards {
fn from(input: RewardsAndNumPartitions) -> Self {
Self {
rewards: input.rewards.into_iter().map(|r| r.into()).collect(),
num_partitions: input.num_partitions.map(|n| n.into()),
}
}
}
Expand All @@ -44,6 +50,17 @@ impl From<confirmed_block::Rewards> for Vec<Reward> {
}
}

impl From<confirmed_block::Rewards> for (Vec<Reward>, Option<u64>) {
fn from(rewards: confirmed_block::Rewards) -> Self {
(
rewards.rewards.into_iter().map(|r| r.into()).collect(),
rewards
.num_partitions
.map(|confirmed_block::NumPartitions { num_partitions }| num_partitions),
)
}
}

impl From<StoredExtendedRewards> for confirmed_block::Rewards {
fn from(rewards: StoredExtendedRewards) -> Self {
Self {
Expand All @@ -54,6 +71,7 @@ impl From<StoredExtendedRewards> for confirmed_block::Rewards {
r.into()
})
.collect(),
num_partitions: None,
}
}
}
Expand Down Expand Up @@ -108,6 +126,12 @@ impl From<confirmed_block::Reward> for Reward {
}
}

impl From<u64> for confirmed_block::NumPartitions {
fn from(num_partitions: u64) -> Self {
Self { num_partitions }
}
}

impl From<VersionedConfirmedBlock> for confirmed_block::ConfirmedBlock {
fn from(confirmed_block: VersionedConfirmedBlock) -> Self {
let VersionedConfirmedBlock {
Expand All @@ -116,6 +140,7 @@ impl From<VersionedConfirmedBlock> for confirmed_block::ConfirmedBlock {
parent_slot,
transactions,
rewards,
num_partitions,
block_time,
block_height,
} = confirmed_block;
Expand All @@ -126,6 +151,7 @@ impl From<VersionedConfirmedBlock> for confirmed_block::ConfirmedBlock {
parent_slot,
transactions: transactions.into_iter().map(|tx| tx.into()).collect(),
rewards: rewards.into_iter().map(|r| r.into()).collect(),
num_partitions: num_partitions.map(Into::into),
block_time: block_time.map(|timestamp| confirmed_block::UnixTimestamp { timestamp }),
block_height: block_height
.map(|block_height| confirmed_block::BlockHeight { block_height }),
Expand All @@ -144,6 +170,7 @@ impl TryFrom<confirmed_block::ConfirmedBlock> for ConfirmedBlock {
parent_slot,
transactions,
rewards,
num_partitions,
block_time,
block_height,
} = confirmed_block;
Expand All @@ -157,6 +184,8 @@ impl TryFrom<confirmed_block::ConfirmedBlock> for ConfirmedBlock {
.map(|tx| tx.try_into())
.collect::<std::result::Result<Vec<_>, Self::Error>>()?,
rewards: rewards.into_iter().map(|r| r.into()).collect(),
num_partitions: num_partitions
.map(|confirmed_block::NumPartitions { num_partitions }| num_partitions),
block_time: block_time.map(|confirmed_block::UnixTimestamp { timestamp }| timestamp),
block_height: block_height
.map(|confirmed_block::BlockHeight { block_height }| block_height),
Expand Down Expand Up @@ -808,6 +837,7 @@ impl TryFrom<tx_by_addr::TransactionError> for TransactionError {
33 => TransactionError::InvalidLoadedAccountsDataSizeLimit,
34 => TransactionError::ResanitizationNeeded,
36 => TransactionError::UnbalancedTransaction,
37 => TransactionError::ProgramCacheHitMaxLimit,
_ => return Err("Invalid TransactionError"),
})
}
Expand Down Expand Up @@ -926,6 +956,9 @@ impl From<TransactionError> for tx_by_addr::TransactionError {
TransactionError::UnbalancedTransaction => {
tx_by_addr::TransactionErrorType::UnbalancedTransaction
}
TransactionError::ProgramCacheHitMaxLimit => {
tx_by_addr::TransactionErrorType::ProgramCacheHitMaxLimit
}
} as i32,
instruction_error: match transaction_error {
TransactionError::InstructionError(index, ref instruction_error) => {
Expand Down Expand Up @@ -1184,6 +1217,29 @@ impl TryFrom<tx_by_addr::TransactionByAddr> for Vec<TransactionByAddrInfo> {
}
}

impl From<(usize, EntrySummary)> for entries::Entry {
fn from((index, entry_summary): (usize, EntrySummary)) -> Self {
entries::Entry {
index: index as u32,
num_hashes: entry_summary.num_hashes,
hash: entry_summary.hash.as_ref().into(),
num_transactions: entry_summary.num_transactions,
starting_transaction_index: entry_summary.starting_transaction_index as u32,
}
}
}

impl From<entries::Entry> for EntrySummary {
fn from(entry: entries::Entry) -> Self {
EntrySummary {
num_hashes: entry.num_hashes,
hash: Hash::new(&entry.hash),
num_transactions: entry.num_transactions,
starting_transaction_index: entry.starting_transaction_index as usize,
}
}
}

#[cfg(test)]
mod test {
use enum_iterator::all;
Expand Down
7 changes: 6 additions & 1 deletion proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use solana_transaction_status::{

pub mod convert;

// NOTE: Jito Labs added
pub mod solana {
pub mod geyser {
tonic::include_proto!("solana.geyser");
Expand All @@ -26,6 +25,12 @@ pub mod solana {
tonic::include_proto!("solana.storage.confirmed_block");
}
}
pub mod tx_by_addr {
tonic::include_proto!("solana.storage.transaction_by_addr");
}
pub mod entries {
tonic::include_proto!("solana.storage.entries");
}
}

pub type StoredExtendedRewards = Vec<StoredExtendedReward>;
Expand Down
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = { workspace = true }
crate-type = ["cdylib", "rlib"]

[dependencies]
agave-geyser-plugin-interface = { workspace = true }
bs58 = { workspace = true }
crossbeam-channel = { workspace = true }
futures-util = { workspace = true }
Expand All @@ -20,7 +21,6 @@ prost-types = { workspace = true }
serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
solana-geyser-plugin-interface = { workspace = true }
solana-logger = { workspace = true }
solana-metrics = { workspace = true }
solana-program = { workspace = true }
Expand Down
28 changes: 24 additions & 4 deletions server/src/geyser_grpc_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ use std::{
time::SystemTime,
};

use agave_geyser_plugin_interface::geyser_plugin_interface::{
GeyserPlugin, GeyserPluginError, ReplicaAccountInfoVersions, ReplicaBlockInfoVersions,
ReplicaTransactionInfoVersions, Result as PluginResult, SlotStatus,
};
use bs58;
use crossbeam_channel::{bounded, Sender, TrySendError};
use jito_geyser_protos::solana::{
Expand All @@ -24,10 +28,6 @@ use jito_geyser_protos::solana::{
use log::*;
use serde_derive::Deserialize;
use serde_json;
use solana_geyser_plugin_interface::geyser_plugin_interface::{
GeyserPlugin, GeyserPluginError, ReplicaAccountInfoVersions, ReplicaBlockInfoVersions,
ReplicaTransactionInfoVersions, Result as PluginResult, SlotStatus,
};
use tokio::{runtime::Runtime, sync::oneshot};
use tonic::{
service::{interceptor::InterceptedService, Interceptor},
Expand Down Expand Up @@ -445,6 +445,26 @@ impl GeyserPlugin for GeyserGrpcPlugin {
entry_count: Some(block.entry_count),
}),
},
ReplicaBlockInfoVersions::V0_0_4(block) => TimestampedBlockUpdate {
ts: Some(prost_types::Timestamp::from(SystemTime::now())),
block_update: Some(BlockUpdate {
slot: block.slot,
blockhash: block.blockhash.to_string(),
rewards: block
.rewards
.rewards
.iter()
.map(|r| (*r).clone().into())
.collect(),
block_time: block.block_time.map(|t| prost_types::Timestamp {
seconds: t,
nanos: 0,
}),
block_height: block.block_height,
executed_transaction_count: Some(block.executed_transaction_count),
entry_count: Some(block.entry_count),
}),
},
};
match data.block_update_sender.try_send(block) {
Ok(_) => Ok(()),
Expand Down
4 changes: 2 additions & 2 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod server;
pub(crate) mod subscription_stream;

#[cfg(not(feature = "jito-solana"))]
extern crate solana_geyser_plugin_interface;
extern crate agave_geyser_plugin_interface;
#[cfg(not(feature = "jito-solana"))]
extern crate solana_logger;
#[cfg(not(feature = "jito-solana"))]
Expand All @@ -16,7 +16,7 @@ extern crate solana_sdk;
extern crate solana_vote_program;

#[cfg(feature = "jito-solana")]
extern crate jito_solana_geyser_plugin_interface as solana_geyser_plugin_interface;
extern crate jito_solana_geyser_plugin_interface as agave_geyser_plugin_interface;
#[cfg(feature = "jito-solana")]
extern crate jito_solana_logger as solana_logger;
#[cfg(feature = "jito-solana")]
Expand Down

0 comments on commit 9451dc3

Please sign in to comment.