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

backports #520: add priority fees to mev claim #525

Merged
merged 2 commits into from
Dec 27, 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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tip-distributor/src/bin/claim-mev-tips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ struct Args {
/// Specifies whether to reclaim rent on behalf of validators from respective TDAs.
#[arg(long, env)]
should_reclaim_tdas: bool,

/// The price to pay per compute unit aka "Priority Fee".
#[arg(long, env, default_value_t = 1)]
micro_lamports_per_compute_unit: u64,
}

#[tokio::main]
Expand Down Expand Up @@ -90,6 +94,7 @@ async fn main() -> Result<(), ClaimMevError> {
keypair.clone(),
args.max_loop_retries,
max_loop_duration,
args.micro_lamports_per_compute_unit,
)
.await
{
Expand Down Expand Up @@ -133,6 +138,7 @@ async fn main() -> Result<(), ClaimMevError> {
args.max_loop_retries,
max_loop_duration,
args.should_reclaim_tdas,
args.micro_lamports_per_compute_unit,
)
.await
{
Expand Down
10 changes: 9 additions & 1 deletion tip-distributor/src/claim_mev_workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use {
solana_sdk::{
account::Account,
commitment_config::CommitmentConfig,
compute_budget::ComputeBudgetInstruction,
instruction::Instruction,
pubkey::Pubkey,
signature::{Keypair, Signer},
Expand Down Expand Up @@ -78,6 +79,7 @@ pub async fn claim_mev_tips(
keypair: Arc<Keypair>,
max_loop_retries: u64,
max_loop_duration: Duration,
micro_lamports_per_compute_unit: u64,
) -> Result<(), ClaimMevError> {
let payer_pubkey = keypair.pubkey();
let blockhash_rpc_client = Arc::new(RpcClient::new_with_commitment(
Expand Down Expand Up @@ -204,6 +206,7 @@ pub async fn claim_mev_tips(
&tdas,
&claimants,
&claim_statuses,
micro_lamports_per_compute_unit,
)?;
datapoint_info!(
"claim_mev_workflow-prepare_transactions",
Expand Down Expand Up @@ -308,6 +311,7 @@ fn build_transactions(
tdas: &HashMap<Pubkey, TipDistributionAccount>,
claimants: &HashMap<Pubkey, (u64 /* lamports */, usize /* allocated bytes */)>,
claim_statuses: &HashMap<Pubkey, Option<Account>>,
micro_lamports_per_compute_unit: u64,
) -> Result<
(
usize, /* skipped_merkle_root_count */
Expand Down Expand Up @@ -397,7 +401,11 @@ fn build_transactions(

let transactions = instructions
.into_iter()
.map(|ix| Transaction::new_with_payer(&[ix], Some(payer_pubkey)))
.map(|claim_ix| {
let priority_fee_ix =
ComputeBudgetInstruction::set_compute_unit_price(micro_lamports_per_compute_unit);
Transaction::new_with_payer(&[priority_fee_ix, claim_ix], Some(payer_pubkey))
})
.collect::<Vec<_>>();
Ok((
skipped_merkle_root_count,
Expand Down
12 changes: 11 additions & 1 deletion tip-distributor/src/reclaim_rent_workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use {
solana_program::pubkey::Pubkey,
solana_sdk::{
commitment_config::CommitmentConfig,
compute_budget::ComputeBudgetInstruction,
signature::{Keypair, Signer},
transaction::Transaction,
},
Expand All @@ -42,6 +43,7 @@ pub async fn reclaim_rent(
max_loop_duration: Duration,
// Optionally reclaim TipDistributionAccount rents on behalf of validators.
should_reclaim_tdas: bool,
micro_lamports_per_compute_unit: u64,
) -> Result<(), ClaimMevError> {
let blockhash_rpc_client = Arc::new(RpcClient::new_with_timeout_and_commitment(
rpc_url.clone(),
Expand All @@ -67,6 +69,7 @@ pub async fn reclaim_rent(
&tip_distribution_program_id,
&signer_pubkey,
should_reclaim_tdas,
micro_lamports_per_compute_unit,
)
.await?;
datapoint_info!(
Expand Down Expand Up @@ -138,6 +141,7 @@ async fn build_transactions(
tip_distribution_program_id: &Pubkey,
signer_pubkey: &Pubkey,
should_reclaim_tdas: bool,
micro_lamports_per_compute_unit: u64,
) -> Result<(Vec<Transaction>, Duration, Duration), ClaimMevError> {
info!("Fetching program accounts");
let (accounts, get_pa_elapsed) = measure!(
Expand Down Expand Up @@ -197,7 +201,13 @@ async fn build_transactions(
})
.collect::<Vec<_>>()
.chunks(4)
.map(|instructions| Transaction::new_with_payer(instructions, Some(signer_pubkey)))
.map(|close_claim_status_instructions| {
let mut instructions = vec![ComputeBudgetInstruction::set_compute_unit_price(
micro_lamports_per_compute_unit,
)];
instructions.extend(close_claim_status_instructions.to_vec());
Transaction::new_with_payer(&instructions, Some(signer_pubkey))
})
.collect::<Vec<_>>();

info!(
Expand Down
Loading