Skip to content

Commit

Permalink
Refactor values into plugin config
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Garfield committed Jun 1, 2022
1 parent 4d8ef60 commit fda809b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 3 additions & 1 deletion plugin/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"libpath": "../target/debug/libcronos_plugin.dylib",
"keypath": "./test-ledger/validator-keypair.json",
"rpc_url": "http://127.0.0.1:8899"
"rpc_url": "http://127.0.0.1:8899",
"slot_timeout_threshold": 150,
"worker_threads": 10
}
12 changes: 8 additions & 4 deletions plugin/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@ use {
};

/// Plugin config.
#[derive(Deserialize)]
pub struct Config {
#[derive(Clone, Debug, Deserialize)]
pub struct PluginConfig {
pub keypath: String,
pub rpc_url: String,
pub slot_timeout_threshold: u64,
pub worker_threads: usize,
}

impl Default for Config {
impl Default for PluginConfig {
fn default() -> Self {
Self {
keypath: "".to_string(),
rpc_url: "http://127.0.0.1:8899".to_string(),
slot_timeout_threshold: 150,
worker_threads: 10,
}
}
}

impl Config {
impl PluginConfig {
/// Read plugin from JSON file.
pub fn read_from<P: AsRef<Path>>(config_path: P) -> PluginResult<Self> {
let file = File::open(config_path)?;
Expand Down
11 changes: 6 additions & 5 deletions plugin/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
crate::{config::Config as PluginConfig, filter::CronosAccountUpdate},
crate::{config::PluginConfig, filter::CronosAccountUpdate},
cronos_sdk::{
scheduler::state::{Queue, Task},
Client,
Expand Down Expand Up @@ -44,12 +44,13 @@ impl GeyserPlugin for CronosPlugin {
solana_logger::setup_with_default("info");
let config = PluginConfig::read_from(config_file)?;
self.inner = Some(Arc::new(Inner {
config: config.clone(),
client: Client::new(config.keypath, config.rpc_url),
runtime: Builder::new_multi_thread()
.enable_all()
.thread_name("cronos-plugin")
.worker_threads(10) // TODO add to config
.max_blocking_threads(10) // TODO add to config
.worker_threads(config.worker_threads)
.max_blocking_threads(config.worker_threads)
.build()
.unwrap(),
actionable_queues: DashSet::new(),
Expand Down Expand Up @@ -140,6 +141,7 @@ impl GeyserPlugin for CronosPlugin {
#[derive(Debug)]
pub struct Inner {
pub client: Client,
pub config: PluginConfig,
pub runtime: Runtime,

// The set of queues that can be processed
Expand Down Expand Up @@ -373,8 +375,7 @@ impl Inner {
None => {
// If many slots have passed since the tx was sent, then assume failure
// and move the pubkey back into the set of actionable queues.
let timeout_threshold = 150;
if confirmed_slot > attempted_slot + timeout_threshold {
if confirmed_slot > attempted_slot + self.config.slot_timeout_threshold {
self.signatures.remove(&signature);
self.actionable_queues.insert(queue_pubkey);
}
Expand Down

0 comments on commit fda809b

Please sign in to comment.