Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport 428 runtime-plugin #458

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -85,6 +85,7 @@ members = [
"rpc-client-nonce-utils",
"rpc-test",
"runtime",
"runtime-plugin",
"runtime/store-tool",
"sdk",
"sdk/cargo-build-bpf",
Expand Down Expand Up @@ -363,6 +364,7 @@ solana-rpc-client = { path = "rpc-client", version = "=1.17.4", default-features
solana-rpc-client-api = { path = "rpc-client-api", version = "=1.17.4" }
solana-rpc-client-nonce-utils = { path = "rpc-client-nonce-utils", version = "=1.17.4" }
solana-runtime = { path = "runtime", version = "=1.17.4" }
solana-runtime-plugin = { path = "runtime-plugin", version = "=1.17.4" }
solana-sdk = { path = "sdk", version = "=1.17.4" }
solana-sdk-macro = { path = "sdk/macro", version = "=1.17.4" }
solana-send-transaction-service = { path = "send-transaction-service", version = "=1.17.4" }
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 @@ -504,6 +508,10 @@ impl Validator {
tpu_connection_pool_size: usize,
tpu_enable_udp: bool,
admin_rpc_service_post_init: Arc<RwLock<Option<AdminRpcRequestMetadataPostInit>>>,
runtime_plugin_configs_and_request_rx: Option<(
Vec<PathBuf>,
Receiver<RuntimePluginManagerRpcRequest>,
)>,
) -> Result<Self, String> {
let id = identity_keypair.pubkey();
assert_eq!(&id, node.info.pubkey());
Expand Down Expand Up @@ -888,6 +896,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(),
)
.map_err(|e| format!("Failed to start runtime plugin service: {e:?}"))?;
}

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 @@ -2483,6 +2502,7 @@ mod tests {
DEFAULT_TPU_CONNECTION_POOL_SIZE,
DEFAULT_TPU_ENABLE_UDP,
Arc::new(RwLock::new(None)),
None,
)
.expect("assume successful validator start");
assert_eq!(
Expand Down Expand Up @@ -2560,14 +2580,15 @@ 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, // rpc_to_plugin_manager_receiver
Arc::new(RwLock::new(ValidatorStartProgress::default())),
SocketAddrSpace::Unspecified,
DEFAULT_TPU_USE_QUIC,
DEFAULT_TPU_CONNECTION_POOL_SIZE,
DEFAULT_TPU_ENABLE_UDP,
Arc::new(RwLock::new(None)),
None,
)
.expect("assume successful validator start")
})
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 @@ -295,6 +295,7 @@ impl LocalCluster {
DEFAULT_TPU_CONNECTION_POOL_SIZE,
DEFAULT_TPU_ENABLE_UDP,
Arc::new(RwLock::new(None)),
None,
)
.expect("assume successful validator start");

Expand Down Expand Up @@ -510,6 +511,7 @@ impl LocalCluster {
DEFAULT_TPU_CONNECTION_POOL_SIZE,
DEFAULT_TPU_ENABLE_UDP,
Arc::new(RwLock::new(None)),
None,
)
.expect("assume successful validator start");

Expand Down Expand Up @@ -907,6 +909,7 @@ impl Cluster for LocalCluster {
DEFAULT_TPU_CONNECTION_POOL_SIZE,
DEFAULT_TPU_ENABLE_UDP,
Arc::new(RwLock::new(None)),
None,
)
.expect("assume successful validator start");
cluster_validator_info.validator = Some(restarted_node);
Expand Down
20 changes: 20 additions & 0 deletions programs/sbf/Cargo.lock

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

23 changes: 23 additions & 0 deletions runtime-plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "solana-runtime-plugin"
publish = false
version = { workspace = true }
segfaultdoc marked this conversation as resolved.
Show resolved Hide resolved
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[dependencies]
crossbeam-channel = { workspace = true }
json5 = { workspace = true }
jsonrpc-core = { workspace = true }
jsonrpc-core-client = { workspace = true, features = ["ipc"] }
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