Skip to content

Commit

Permalink
first pass at wiring up jito-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
segfaultdoc committed Oct 19, 2023
1 parent 326c848 commit 4eecee0
Show file tree
Hide file tree
Showing 15 changed files with 911 additions and 2 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ members = [
"geyser-plugin-manager",
"gossip",
"install",
"runtime-plugin",
"jito-protos",
"keygen",
"ledger",
Expand Down Expand Up @@ -346,6 +347,7 @@ solana-genesis-utils = { path = "genesis-utils", version = "=1.18.0" }
solana-geyser-plugin-interface = { path = "geyser-plugin-interface", version = "=1.18.0" }
solana-geyser-plugin-manager = { path = "geyser-plugin-manager", version = "=1.18.0" }
solana-gossip = { path = "gossip", version = "=1.18.0" }
solana-runtime-plugin = { path = "runtime-plugin", version = "=1.18.0" }
solana-loader-v4-program = { path = "programs/loader-v4", version = "=1.18.0" }
solana-ledger = { path = "ledger", version = "=1.18.0" }
solana-local-cluster = { path = "local-cluster", version = "=1.18.0" }
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ solana-rayon-threadlimit = { workspace = true }
solana-rpc = { workspace = true }
solana-rpc-client-api = { workspace = true }
solana-runtime = { workspace = true }
solana-runtime-plugin = { workspace = true }
solana-sdk = { workspace = true }
solana-send-transaction-service = { workspace = true }
solana-streamer = { workspace = true }
Expand Down
23 changes: 22 additions & 1 deletion core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ use {
self, clean_orphaned_account_snapshot_dirs, move_and_async_delete_path_contents,
},
},
solana_runtime_plugin::{
runtime_plugin_admin_rpc_service::RuntimePluginManagerRpcRequest,
runtime_plugin_service::RuntimePluginService,
},
solana_sdk::{
clock::Slot,
epoch_schedule::MAX_LEADER_SCHEDULE_EPOCH_OFFSET,
Expand Down Expand Up @@ -498,6 +502,10 @@ impl Validator {
cluster_entrypoints: Vec<ContactInfo>,
config: &ValidatorConfig,
should_check_duplicate_instance: bool,
runtime_plugin_configs_and_request_rx: Option<(
Vec<PathBuf>,
Receiver<RuntimePluginManagerRpcRequest>,
)>,
rpc_to_plugin_manager_receiver: Option<Receiver<GeyserPluginManagerRequest>>,
start_progress: Arc<RwLock<ValidatorStartProgress>>,
socket_addr_space: SocketAddrSpace,
Expand Down Expand Up @@ -889,6 +897,17 @@ impl Validator {
None,
));

if let Some((runtime_plugin_configs, request_rx)) = runtime_plugin_configs_and_request_rx {
RuntimePluginService::start(
&runtime_plugin_configs,
request_rx,
bank_forks.clone(),
block_commitment_cache.clone(),
exit.clone(),
)
.unwrap();
}

let max_slots = Arc::new(MaxSlots::default());
let (completed_data_sets_sender, completed_data_sets_receiver) =
bounded(MAX_COMPLETED_DATA_SETS_IN_CHANNEL);
Expand Down Expand Up @@ -2505,6 +2524,7 @@ mod tests {
vec![LegacyContactInfo::try_from(&leader_node.info).unwrap()],
&config,
true, // should_check_duplicate_instance
None,
None, // rpc_to_plugin_manager_receiver
start_progress.clone(),
SocketAddrSpace::Unspecified,
Expand Down Expand Up @@ -2589,7 +2609,8 @@ mod tests {
Arc::new(RwLock::new(vec![Arc::new(vote_account_keypair)])),
vec![LegacyContactInfo::try_from(&leader_node.info).unwrap()],
&config,
true, // should_check_duplicate_instance.
true, // should_check_duplicate_instance
None,
None, // rpc_to_plugin_manager_receiver
Arc::new(RwLock::new(ValidatorStartProgress::default())),
SocketAddrSpace::Unspecified,
Expand Down
3 changes: 3 additions & 0 deletions local-cluster/src/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ impl LocalCluster {
vec![],
&leader_config,
true, // should_check_duplicate_instance
None,
None, // rpc_to_plugin_manager_receiver
Arc::new(RwLock::new(ValidatorStartProgress::default())),
socket_addr_space,
Expand Down Expand Up @@ -503,6 +504,7 @@ impl LocalCluster {
vec![LegacyContactInfo::try_from(&self.entry_point_info).unwrap()],
&config,
true, // should_check_duplicate_instance
None,
None, // rpc_to_plugin_manager_receiver
Arc::new(RwLock::new(ValidatorStartProgress::default())),
socket_addr_space,
Expand Down Expand Up @@ -900,6 +902,7 @@ impl Cluster for LocalCluster {
.unwrap_or_default(),
&safe_clone_config(&cluster_validator_info.config),
true, // should_check_duplicate_instance
None,
None, // rpc_to_plugin_manager_receiver
Arc::new(RwLock::new(ValidatorStartProgress::default())),
socket_addr_space,
Expand Down
18 changes: 18 additions & 0 deletions runtime-plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "solana-runtime-plugin"
version = "1.18.0"
edition = "2021"

[dependencies]
crossbeam-channel = { workspace = true }
json5 = { workspace = true }
jsonrpc-core = { workspace = true }
jsonrpc-core-client = { workspace = true }
jsonrpc-derive = { workspace = true }
jsonrpc-ipc-server = { workspace = true }
jsonrpc-server-utils = { workspace = true }
libloading = { workspace = true }
log = { workspace = true }
solana-runtime = { workspace = true }
solana-sdk = { workspace = true }
thiserror = { workspace = true }
4 changes: 4 additions & 0 deletions runtime-plugin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod runtime_plugin;
pub mod runtime_plugin_admin_rpc_service;
pub mod runtime_plugin_manager;
pub mod runtime_plugin_service;
41 changes: 41 additions & 0 deletions runtime-plugin/src/runtime_plugin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use {
solana_runtime::{bank_forks::BankForks, commitment::BlockCommitmentCache},
std::{
any::Any,
error,
fmt::Debug,
io,
sync::{atomic::AtomicBool, Arc, RwLock},
},
thiserror::Error,
};

pub type Result<T> = std::result::Result<T, RuntimePluginError>;

/// Errors returned by plugin calls
#[derive(Error, Debug)]
pub enum RuntimePluginError {
/// Error opening the configuration file; for example, when the file
/// is not found or when the validator process has no permission to read it.
#[error("Error opening config file. Error detail: ({0}).")]
ConfigFileOpenError(#[from] io::Error),

/// Any custom error defined by the plugin.
#[error("Plugin-defined custom error. Error message: ({0})")]
Custom(Box<dyn error::Error + Send + Sync>),

#[error("Failed to load a runtime plugin")]
FailedToLoadPlugin(#[from] Box<dyn std::error::Error>),
}

pub struct PluginDependencies {
pub bank_forks: Arc<RwLock<BankForks>>,
pub block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
pub exit: Arc<AtomicBool>,
}

pub trait RuntimePlugin: Any + Debug + Send + Sync {
fn name(&self) -> &'static str;
fn on_load(&mut self, config_file: &str, dependencies: PluginDependencies) -> Result<()>;
fn on_unload(&mut self);
}
Loading

0 comments on commit 4eecee0

Please sign in to comment.