-
Notifications
You must be signed in to change notification settings - Fork 21
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
Tweak keeper for alerts #74
Changes from 8 commits
4bab837
4aea07c
460d02e
47f0c16
499b819
4fd0129
ce62f8f
cc7a4eb
a7d6dd9
970dcfb
b88b575
c0a792f
bfca1bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,31 +122,33 @@ pub fn _get_update_stake_pool_ixs( | |
.get(&validator_info.vote_account_address) | ||
.expect("Stake account not found"); | ||
|
||
let should_deactivate = if raw_vote_account.is_none() || raw_stake_account.is_none() { | ||
true | ||
} else { | ||
let stake_account = | ||
StakeStateV2::deserialize(&mut raw_stake_account.clone().unwrap().data.as_slice()) | ||
.expect("Could not deserialize stake account"); | ||
|
||
let vote_account = VoteState::deserialize(&raw_vote_account.clone().unwrap().data) | ||
.expect("Could not deserialize vote account"); | ||
|
||
let latest_epoch = vote_account.epoch_credits.iter().last().unwrap().0; | ||
|
||
match stake_account { | ||
StakeStateV2::Stake(_meta, stake, _stake_flags) => { | ||
if stake.delegation.deactivation_epoch != std::u64::MAX { | ||
let should_deactivate = match (raw_vote_account, raw_stake_account) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is much better! |
||
(None, Some(_)) => true, | ||
(Some(raw_vote_account), Some(raw_stake_account)) => { | ||
let stake_account = | ||
StakeStateV2::deserialize(&mut raw_stake_account.data.as_slice()) | ||
.expect("Could not deserialize stake account"); | ||
|
||
let vote_account = VoteState::deserialize(&raw_vote_account.data) | ||
.expect("Could not deserialize vote account"); | ||
|
||
let latest_epoch = vote_account.epoch_credits.iter().last().unwrap().0; | ||
|
||
match stake_account { | ||
StakeStateV2::Stake(_meta, stake, _stake_flags) => { | ||
if stake.delegation.deactivation_epoch != std::u64::MAX { | ||
false | ||
} else { | ||
latest_epoch <= epoch - 5 | ||
} | ||
} | ||
_ => { | ||
println!("🔶 Error: Stake account is not StakeStateV2::Stake"); | ||
false | ||
} else { | ||
latest_epoch <= epoch - 5 | ||
} | ||
} | ||
_ => { | ||
println!("🔶 Error: Stake account is not StakeStateV2::Stake"); | ||
false | ||
} | ||
} | ||
(_, None) => false, | ||
}; | ||
|
||
if should_deactivate { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ use std::vec; | |
use std::{collections::HashMap, sync::Arc, time::Duration}; | ||
|
||
use log::*; | ||
use solana_client::rpc_response::{Response, RpcSimulateTransactionResult, RpcVoteAccountInfo}; | ||
use solana_client::rpc_response::{ | ||
Response, RpcResult, RpcSimulateTransactionResult, RpcVoteAccountInfo, | ||
}; | ||
use solana_client::{client_error::ClientError, nonblocking::rpc_client::RpcClient}; | ||
use solana_metrics::datapoint_error; | ||
use solana_program::hash::Hash; | ||
|
@@ -17,6 +19,7 @@ use solana_sdk::{ | |
instruction::Instruction, packet::Packet, pubkey::Pubkey, signature::Keypair, | ||
signature::Signature, signer::Signer, transaction::Transaction, | ||
}; | ||
use solana_transaction_status::TransactionStatus; | ||
use tokio::task; | ||
use tokio::time::sleep; | ||
|
||
|
@@ -197,6 +200,19 @@ pub async fn get_vote_accounts_with_retry( | |
} | ||
} | ||
|
||
pub async fn get_signature_statuses_with_retry( | ||
client: &RpcClient, | ||
signatures: &[Signature], | ||
) -> RpcResult<Vec<Option<TransactionStatus>>> { | ||
for _ in 1..4 { | ||
if let Ok(result) = client.get_signature_statuses(signatures).await { | ||
return Ok(result); | ||
} | ||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; | ||
} | ||
client.get_signature_statuses(signatures).await | ||
} | ||
|
||
async fn find_ix_per_tx( | ||
client: &Arc<RpcClient>, | ||
instruction: &Instruction, | ||
|
@@ -264,14 +280,17 @@ async fn parallel_confirm_transactions( | |
let confirmation_futures: Vec<_> = signatures_to_confirm | ||
.chunks(SIG_STATUS_BATCH_SIZE) | ||
.map(|sig_batch| async move { | ||
match client.get_signature_statuses(sig_batch).await { | ||
match get_signature_statuses_with_retry(client, sig_batch).await { | ||
Ok(sig_batch_response) => sig_batch_response | ||
.value | ||
.iter() | ||
.enumerate() | ||
.map(|(i, sig_status)| (sig_batch[i], sig_status.clone())) | ||
.collect::<Vec<_>>(), | ||
Err(_) => vec![], | ||
Err(e) => { | ||
info!("Failed getting signature statuses: {}", e); | ||
vec![] | ||
} | ||
} | ||
}) | ||
.collect(); | ||
|
@@ -650,7 +669,7 @@ pub async fn submit_transactions( | |
.map(|t| t.as_slice()) | ||
.collect::<Vec<_>>(); | ||
|
||
match parallel_execute_transactions(client, &tx_slice, keypair, 100, 20).await { | ||
match parallel_execute_transactions(client, &tx_slice, keypair, 100, 30).await { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 100 and 30 should be args There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adding |
||
Ok(results) => { | ||
stats.successes = results.iter().filter(|&tx| tx.is_ok()).count() as u64; | ||
stats.errors = results.len() as u64 - stats.successes; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can specify this in the .env