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

[JIT-504] Add low balance check in uploading merkle roots #209

Merged
merged 5 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
16 changes: 10 additions & 6 deletions bench-batch-simulate-bundle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -232,7 +236,7 @@ fn spawn_slots_subscribe_thread(
node_name: String,
exit: Arc<AtomicBool>,
) -> 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();
Expand All @@ -243,7 +247,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();
}
}
})
Expand All @@ -270,7 +274,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;
(
Expand Down
12 changes: 12 additions & 0 deletions tip-distributor/src/merkle_root_upload_workflow.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -68,6 +70,16 @@ 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 initial_balance = rpc_client.get_balance(&keypair.pubkey()).await.expect("failed to get balance");
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.",
desired_balance, &keypair.pubkey(), initial_balance, sol_to_deposit)
}
}
let mut trees_needing_update: Vec<GeneratedMerkleTree> = vec![];
for tree in trees {
let account = rpc_client
Expand Down
12 changes: 7 additions & 5 deletions tip-distributor/src/stake_meta_generator_workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,13 @@ pub fn generate_stake_meta_collection(
) -> Result<StakeMetaCollection, StakeMetaGeneratorError> {
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();
Expand Down