From 33979e330882aa27636932537283641623a21dc7 Mon Sep 17 00:00:00 2001 From: Evan B Date: Tue, 9 Apr 2024 12:29:59 -0400 Subject: [PATCH] Restructure CLI for external keepers running (#29) --- keepers/validator-keeper/src/main.rs | 51 ++++++++++++++++++---------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/keepers/validator-keeper/src/main.rs b/keepers/validator-keeper/src/main.rs index c7bf2758..8a1e6195 100644 --- a/keepers/validator-keeper/src/main.rs +++ b/keepers/validator-keeper/src/main.rs @@ -41,15 +41,15 @@ struct Args { /// Gossip entrypoint in the form of URL:PORT #[arg(short, long, env)] - gossip_entrypoint: String, + gossip_entrypoint: Option, /// Path to keypair used to pay for account creation and execute transactions #[arg(short, long, env, default_value = "~/.config/solana/id.json")] keypair: PathBuf, - /// Path to keypair used specifically for submitting stake upload transactions + /// Path to keypair used specifically for submitting permissioned transactions #[arg(short, long, env)] - stake_upload_keypair: Option, + oracle_authority_keypair: Option, /// Validator history program ID (Pubkey as base58 string) #[arg(short, long, env)] @@ -487,8 +487,6 @@ async fn main() { Duration::from_secs(60), )); let keypair = Arc::new(read_keypair_file(args.keypair).expect("Failed reading keypair file")); - let entrypoint = solana_net_utils::parse_host_port(&args.gossip_entrypoint) - .expect("Failed to parse host and port from gossip entrypoint"); info!("Starting validator history keeper..."); @@ -512,18 +510,6 @@ async fn main() { args.interval, )); - if let Some(stake_upload_keypair) = args.stake_upload_keypair { - let stake_upload_keypair = Arc::new( - read_keypair_file(stake_upload_keypair).expect("Failed reading stake keypair file"), - ); - tokio::spawn(stake_upload_loop( - Arc::clone(&client), - Arc::clone(&stake_upload_keypair), - args.program_id, - args.interval, - )); - } - tokio::spawn(mev_commission_loop( client.clone(), keypair.clone(), @@ -539,5 +525,34 @@ async fn main() { args.tip_distribution_program_id, args.interval, )); - gossip_upload_loop(client, keypair, args.program_id, entrypoint, args.interval).await; + + if let Some(oracle_authority_keypair) = args.oracle_authority_keypair { + let oracle_authority_keypair = Arc::new( + read_keypair_file(oracle_authority_keypair).expect("Failed reading stake keypair file"), + ); + tokio::spawn(stake_upload_loop( + Arc::clone(&client), + Arc::clone(&oracle_authority_keypair), + args.program_id, + args.interval, + )); + + if let Some(gossip_entrypoint) = args.gossip_entrypoint { + let entrypoint = solana_net_utils::parse_host_port(&gossip_entrypoint) + .expect("Failed to parse host and port from gossip entrypoint"); + // Cannot be sent to thread because there's a Box inside + gossip_upload_loop( + client.clone(), + oracle_authority_keypair, + args.program_id, + entrypoint, + args.interval, + ) + .await; + } + } + // Need final infinite loop to keep all threads alive + loop { + sleep(Duration::from_secs(60)).await; + } }