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

Backport tip distributor scripts updates from master #318

Merged
merged 5 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
388 changes: 227 additions & 161 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jito-programs
4 changes: 2 additions & 2 deletions tip-distributor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description = "Collection of binaries used to distribute MEV rewards to delegato

[dependencies]
anchor-lang = { path = "../anchor/lang" }
clap = { version = "3", features = ["derive", "env"] }
clap = { version = "3.1.18", features = ["derive", "env"] }
env_logger = "0.9.0"
futures = "0.3.21"
im = "15.1.0"
Expand All @@ -20,8 +20,8 @@ solana-client = { path = "../client", version = "=1.14.21" }
solana-genesis-utils = { path = "../genesis-utils", version = "=1.14.21" }
solana-ledger = { path = "../ledger", version = "=1.14.21" }
solana-merkle-tree = { path = "../merkle-tree", version = "=1.14.21" }
solana-metrics = { path = "../metrics", version = "=1.14.21" }
solana-program = { path = "../sdk/program", version = "=1.14.21" }
solana-rpc = { path = "../rpc", version = "=1.14.21" }
solana-runtime = { path = "../runtime", version = "=1.14.21" }
solana-sdk = { path = "../sdk", version = "=1.14.21" }
solana-stake-program = { path = "../programs/stake", version = "=1.14.21" }
Expand Down
7 changes: 6 additions & 1 deletion tip-distributor/src/bin/merkle-root-generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ struct Args {
#[clap(long, env)]
stake_meta_coll_path: PathBuf,

/// RPC to send transactions through. Used to validate what's being claimed is equal to TDA balance minus rent.
#[clap(long, env)]
rpc_url: String,

/// Path to JSON file to get populated with tree node data.
#[clap(long, env)]
out_path: PathBuf,
Expand All @@ -24,6 +28,7 @@ fn main() {
info!("Starting merkle-root-generator workflow...");

let args: Args = Args::parse();
generate_merkle_root(&args.stake_meta_coll_path, &args.out_path).expect("merkle tree produced");
generate_merkle_root(&args.stake_meta_coll_path, &args.out_path, &args.rpc_url)
.expect("merkle tree produced");
info!("saved merkle roots to {:?}", args.stake_meta_coll_path);
}
7 changes: 5 additions & 2 deletions tip-distributor/src/bin/reclaim-rent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ struct Args {
#[clap(long, env)]
keypair_path: PathBuf,

/// High timeout b/c of get_program_accounts call
#[clap(long, env, default_value_t = 180)]
rpc_timeout_secs: u64,

/// Specifies whether to reclaim rent on behalf of validators from respective TDAs.
#[clap(long, env)]
should_reclaim_tdas: bool,
Expand All @@ -44,8 +48,7 @@ fn main() {
if let Err(e) = runtime.block_on(reclaim_rent(
RpcClient::new_with_timeout_and_commitment(
args.rpc_url,
// High timeout b/c of get_program_accounts call
Duration::from_secs(60),
Duration::from_secs(args.rpc_timeout_secs),
CommitmentConfig::confirmed(),
),
args.tip_distribution_program_id,
Expand Down
42 changes: 21 additions & 21 deletions tip-distributor/src/claim_mev_workflow.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use {
crate::{read_json_from_file, send_transactions_with_retry, GeneratedMerkleTreeCollection},
crate::{
read_json_from_file, sign_and_send_transactions_with_retries, GeneratedMerkleTreeCollection,
},
anchor_lang::{AccountDeserialize, InstructionData, ToAccountMetas},
log::{debug, info, warn},
solana_client::{nonblocking::rpc_client::RpcClient, rpc_request::RpcError},
solana_client::{client_error, nonblocking::rpc_client::RpcClient, rpc_request::RpcError},
solana_program::{
fee_calculator::DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE, native_token::LAMPORTS_PER_SOL,
stake::state::StakeState, system_program,
Expand Down Expand Up @@ -35,8 +37,7 @@ pub fn claim_mev_tips(
tip_distribution_program_id: &Pubkey,
keypair_path: &PathBuf,
) -> Result<(), ClaimMevError> {
// roughly how long before blockhash expires
const MAX_RETRY_DURATION: Duration = Duration::from_secs(60);
const MAX_RETRY_DURATION: Duration = Duration::from_secs(600);

let merkle_trees: GeneratedMerkleTreeCollection =
read_json_from_file(merkle_root_path).expect("read GeneratedMerkleTreeCollection");
Expand All @@ -46,18 +47,17 @@ pub fn claim_mev_tips(
Pubkey::find_program_address(&[Config::SEED], tip_distribution_program_id).0;

let rpc_client =
RpcClient::new_with_commitment(rpc_url.to_string(), CommitmentConfig::confirmed());
RpcClient::new_with_commitment(rpc_url.to_string(), CommitmentConfig::finalized());

let runtime = Builder::new_multi_thread()
.worker_threads(16)
.enable_all()
.build()
.unwrap();

let mut transactions = Vec::new();
let mut instructions = Vec::new();

runtime.block_on(async move {
let blockhash = rpc_client.get_latest_blockhash().await.expect("read blockhash");
let start_balance = rpc_client.get_balance(&keypair.pubkey()).await.expect("failed to get balance");
// heuristic to make sure we have enough funds to cover the rent costs if epoch has many validators
{
Expand Down Expand Up @@ -99,7 +99,7 @@ pub fn claim_mev_tips(
continue;
}
// expected to not find ClaimStatus account, don't skip
Err(solana_client::client_error::ClientError { kind: solana_client::client_error::ClientErrorKind::RpcError(RpcError::ForUser(err)), .. }) if err.starts_with("AccountNotFound") => {}
Err(client_error::ClientError { kind: client_error::ClientErrorKind::RpcError(RpcError::ForUser(err)), .. }) if err.starts_with("AccountNotFound") => {}
Err(err) => panic!("Unexpected RPC Error: {}", err),
}

Expand All @@ -112,7 +112,7 @@ pub fn claim_mev_tips(
below_min_rent_count = below_min_rent_count.checked_add(1).unwrap();
continue;
}
let ix = Instruction {
instructions.push(Instruction {
program_id: *tip_distribution_program_id,
data: tip_distribution::instruction::Claim {
proof: node.proof.unwrap(),
Expand All @@ -127,23 +127,23 @@ pub fn claim_mev_tips(
payer: keypair.pubkey(),
system_program: system_program::id(),
}.to_account_metas(None),
};
let transaction = Transaction::new_signed_with_payer(
&[ix],
Some(&keypair.pubkey()),
&[&keypair],
blockhash,
);
info!("claiming for pubkey: {}, tx: {:?}", node.claimant, transaction);
transactions.push(transaction);
});
}
}

let transactions = instructions.into_iter().map(|ix|{
Transaction::new_with_payer(
&[ix],
Some(&keypair.pubkey()),
)
}).collect::<Vec<_>>();

info!("Sending {} tip claim transactions. {} tried sending zero lamports, {} would be below minimum rent",
&transactions.len(), zero_lamports_count, below_min_rent_count);
let num_failed_txs = send_transactions_with_retry(&rpc_client, &transactions, MAX_RETRY_DURATION).await;
if num_failed_txs != 0 {
panic!("failed to send {num_failed_txs} transactions");

let failed_transactions = sign_and_send_transactions_with_retries(&keypair, &rpc_client, transactions, MAX_RETRY_DURATION).await;
if !failed_transactions.is_empty() {
panic!("failed to send {} transactions", failed_transactions.len());
}
});

Expand Down
Loading