From 1e453a32ffc46125b20a8150eba4f20b6819f975 Mon Sep 17 00:00:00 2001 From: Eric Semeniuc <3838856+esemeniuc@users.noreply.github.com> Date: Thu, 1 Dec 2022 12:11:03 -0800 Subject: [PATCH 1/5] clippy warnings --- bench-batch-simulate-bundle/src/main.rs | 6 +++--- tip-distributor/src/stake_meta_generator_workflow.rs | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bench-batch-simulate-bundle/src/main.rs b/bench-batch-simulate-bundle/src/main.rs index 56e8762ddb..7aed653ec2 100644 --- a/bench-batch-simulate-bundle/src/main.rs +++ b/bench-batch-simulate-bundle/src/main.rs @@ -232,7 +232,7 @@ fn spawn_slots_subscribe_thread( node_name: String, exit: Arc, ) -> JoinHandle<()> { - let mut slots_sub = PubsubClient::slot_subscribe(&*pubsub_addr).unwrap(); + let mut slots_sub = PubsubClient::slot_subscribe(&pubsub_addr).unwrap(); thread::spawn(move || loop { if exit.load(Ordering::Acquire) { let _ = slots_sub.0.shutdown(); @@ -243,7 +243,7 @@ fn spawn_slots_subscribe_thread( Ok(slot_info) => info!("[RPC={} slot={:?}]", node_name, slot_info.slot), Err(e) => { error!("error receiving on slots_sub channel: {}", e); - slots_sub = PubsubClient::slot_subscribe(&*pubsub_addr).unwrap(); + slots_sub = PubsubClient::slot_subscribe(&pubsub_addr).unwrap(); } } }) @@ -270,7 +270,7 @@ fn fetch_n_highest_cost_transactions( }; let block = rpc_client .get_block_with_config(slot, config) - .expect(&*format!("failed to fetch block at slot: {}", slot)); + .unwrap_or_else(|_| panic!("failed to fetch block at slot: {}", slot)); let parent_slot = block.parent_slot; ( diff --git a/tip-distributor/src/stake_meta_generator_workflow.rs b/tip-distributor/src/stake_meta_generator_workflow.rs index 1020b3f2e8..bcf6c31439 100644 --- a/tip-distributor/src/stake_meta_generator_workflow.rs +++ b/tip-distributor/src/stake_meta_generator_workflow.rs @@ -145,11 +145,13 @@ pub fn generate_stake_meta_collection( ) -> Result { assert!(bank.is_frozen()); - let epoch_vote_accounts = bank.epoch_vote_accounts(bank.epoch()).expect(&*format!( - "No epoch_vote_accounts found for slot {} at epoch {}", - bank.slot(), - bank.epoch() - )); + let epoch_vote_accounts = bank.epoch_vote_accounts(bank.epoch()).unwrap_or_else(|| { + panic!( + "No epoch_vote_accounts found for slot {} at epoch {}", + bank.slot(), + bank.epoch() + ) + }); let l_stakes = bank.stakes_cache.stakes(); let delegations = l_stakes.stake_delegations(); From cddd17626c32a73fc592f4ce498276b037026265 Mon Sep 17 00:00:00 2001 From: Eric Semeniuc <3838856+esemeniuc@users.noreply.github.com> Date: Thu, 1 Dec 2022 12:55:36 -0800 Subject: [PATCH 2/5] editor tweak --- bench-batch-simulate-bundle/src/main.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bench-batch-simulate-bundle/src/main.rs b/bench-batch-simulate-bundle/src/main.rs index 7aed653ec2..19151fb084 100644 --- a/bench-batch-simulate-bundle/src/main.rs +++ b/bench-batch-simulate-bundle/src/main.rs @@ -111,10 +111,14 @@ fn main() { let t_hdls = vec![ spawn_slots_subscribe_thread( args.simulation_ws_url, - "simulation-node".into(), + "simulation-node".to_string(), + exit.clone(), + ), + spawn_slots_subscribe_thread( + args.baseline_ws_url, + "baseline-node".to_string(), exit.clone(), ), - spawn_slots_subscribe_thread(args.baseline_ws_url, "baseline-node".into(), exit.clone()), ]; let rpc_client = RpcClient::new(args.baseline_rpc_url.clone()); @@ -204,7 +208,7 @@ fn spawn_highest_cost_bundle_scraper( bundle_size: usize, ) -> JoinHandle<()> { Builder::new() - .name("highest-cost-tx-scraper".into()) + .name("highest-cost-tx-scraper".to_string()) .spawn(move || loop { let (transactions, simulation_slot) = fetch_n_highest_cost_transactions(&rpc_client, bundle_size); From 73a5e9855a2406a8ed7a4b6aea94c3bde6272b21 Mon Sep 17 00:00:00 2001 From: Eric Semeniuc <3838856+esemeniuc@users.noreply.github.com> Date: Thu, 1 Dec 2022 13:20:12 -0800 Subject: [PATCH 3/5] add check --- tip-distributor/src/merkle_root_upload_workflow.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tip-distributor/src/merkle_root_upload_workflow.rs b/tip-distributor/src/merkle_root_upload_workflow.rs index 4925087fae..4ea7f63c67 100644 --- a/tip-distributor/src/merkle_root_upload_workflow.rs +++ b/tip-distributor/src/merkle_root_upload_workflow.rs @@ -1,3 +1,5 @@ +use solana_program::fee_calculator::DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE; +use solana_program::native_token::LAMPORTS_PER_SOL; use { crate::{ read_json_from_file, send_transactions_with_retry, GeneratedMerkleTree, @@ -68,6 +70,17 @@ pub fn upload_merkle_root( info!("num trees to upload: {:?}", trees.len()); + // heuristic to make sure we have enough funds to cover execution, assumes all trees need updating + { + let tree_count = trees.iter().count(); + let initial_balance = rpc_client.get_balance(&keypair.pubkey()).await.expect("failed to get balance"); + let desired_balance = tree_count as u64 * DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE; + if initial_balance < desired_balance { + let sol_to_deposit = (desired_balance - initial_balance + LAMPORTS_PER_SOL - 1) / LAMPORTS_PER_SOL; // rounds up to nearest sol + panic!("Expected to have at least {} lamports in {}, current balance is {} lamports, deposit {} SOL to continue.", + desired_balance, &keypair.pubkey(), initial_balance, sol_to_deposit) + } + } let mut trees_needing_update: Vec = vec![]; for tree in trees { let account = rpc_client From 0be64c95d33378697019a624f6cb276c519e41ac Mon Sep 17 00:00:00 2001 From: Eric Semeniuc <3838856+esemeniuc@users.noreply.github.com> Date: Thu, 1 Dec 2022 13:23:20 -0800 Subject: [PATCH 4/5] clippy --- tip-distributor/src/merkle_root_upload_workflow.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tip-distributor/src/merkle_root_upload_workflow.rs b/tip-distributor/src/merkle_root_upload_workflow.rs index 4ea7f63c67..26f993159d 100644 --- a/tip-distributor/src/merkle_root_upload_workflow.rs +++ b/tip-distributor/src/merkle_root_upload_workflow.rs @@ -72,9 +72,8 @@ pub fn upload_merkle_root( // heuristic to make sure we have enough funds to cover execution, assumes all trees need updating { - let tree_count = trees.iter().count(); let initial_balance = rpc_client.get_balance(&keypair.pubkey()).await.expect("failed to get balance"); - let desired_balance = tree_count as u64 * DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE; + let desired_balance = trees.len() as u64 * DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE; if initial_balance < desired_balance { let sol_to_deposit = (desired_balance - initial_balance + LAMPORTS_PER_SOL - 1) / LAMPORTS_PER_SOL; // rounds up to nearest sol panic!("Expected to have at least {} lamports in {}, current balance is {} lamports, deposit {} SOL to continue.", From dc225f63e956676dbe677b23ce5e648df4e6bfad Mon Sep 17 00:00:00 2001 From: Eric Semeniuc <3838856+esemeniuc@users.noreply.github.com> Date: Thu, 1 Dec 2022 14:11:55 -0800 Subject: [PATCH 5/5] address comments --- bench-batch-simulate-bundle/src/main.rs | 10 +++------- tip-distributor/src/claim_mev_workflow.rs | 5 ++--- tip-distributor/src/merkle_root_upload_workflow.rs | 5 +++-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/bench-batch-simulate-bundle/src/main.rs b/bench-batch-simulate-bundle/src/main.rs index 19151fb084..7aed653ec2 100644 --- a/bench-batch-simulate-bundle/src/main.rs +++ b/bench-batch-simulate-bundle/src/main.rs @@ -111,14 +111,10 @@ fn main() { let t_hdls = vec![ spawn_slots_subscribe_thread( args.simulation_ws_url, - "simulation-node".to_string(), - exit.clone(), - ), - spawn_slots_subscribe_thread( - args.baseline_ws_url, - "baseline-node".to_string(), + "simulation-node".into(), exit.clone(), ), + spawn_slots_subscribe_thread(args.baseline_ws_url, "baseline-node".into(), exit.clone()), ]; let rpc_client = RpcClient::new(args.baseline_rpc_url.clone()); @@ -208,7 +204,7 @@ fn spawn_highest_cost_bundle_scraper( bundle_size: usize, ) -> JoinHandle<()> { Builder::new() - .name("highest-cost-tx-scraper".to_string()) + .name("highest-cost-tx-scraper".into()) .spawn(move || loop { let (transactions, simulation_slot) = fetch_n_highest_cost_transactions(&rpc_client, bundle_size); diff --git a/tip-distributor/src/claim_mev_workflow.rs b/tip-distributor/src/claim_mev_workflow.rs index 96274948f4..72a7a6f3cc 100644 --- a/tip-distributor/src/claim_mev_workflow.rs +++ b/tip-distributor/src/claim_mev_workflow.rs @@ -1,12 +1,11 @@ -use solana_program::native_token::LAMPORTS_PER_SOL; use { crate::{read_json_from_file, send_transactions_with_retry, GeneratedMerkleTreeCollection}, anchor_lang::{AccountDeserialize, InstructionData, ToAccountMetas}, log::{debug, info, warn}, solana_client::{nonblocking::rpc_client::RpcClient, rpc_request::RpcError}, solana_program::{ - fee_calculator::DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE, stake::state::StakeState, - system_program, + fee_calculator::DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE, native_token::LAMPORTS_PER_SOL, + stake::state::StakeState, system_program, }, solana_rpc_client_api::client_error, solana_sdk::{ diff --git a/tip-distributor/src/merkle_root_upload_workflow.rs b/tip-distributor/src/merkle_root_upload_workflow.rs index 26f993159d..2ae7a36031 100644 --- a/tip-distributor/src/merkle_root_upload_workflow.rs +++ b/tip-distributor/src/merkle_root_upload_workflow.rs @@ -1,5 +1,3 @@ -use solana_program::fee_calculator::DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE; -use solana_program::native_token::LAMPORTS_PER_SOL; use { crate::{ read_json_from_file, send_transactions_with_retry, GeneratedMerkleTree, @@ -8,6 +6,9 @@ use { anchor_lang::AccountDeserialize, log::{error, info}, solana_client::nonblocking::rpc_client::RpcClient, + solana_program::{ + fee_calculator::DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE, native_token::LAMPORTS_PER_SOL, + }, solana_sdk::{ commitment_config::CommitmentConfig, pubkey::Pubkey,