Skip to content

Commit

Permalink
Add priority fees to submission (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebatsell authored Apr 9, 2024
1 parent a810470 commit 18984a3
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 23 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

29 changes: 23 additions & 6 deletions keepers/keeper-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use log::*;
use solana_client::rpc_response::RpcVoteAccountInfo;
use solana_client::{client_error::ClientError, nonblocking::rpc_client::RpcClient};
use solana_program::hash::Hash;
use solana_sdk::compute_budget::ComputeBudgetInstruction;
use solana_sdk::packet::PACKET_DATA_SIZE;
use solana_sdk::transaction::TransactionError;
use solana_sdk::{
Expand Down Expand Up @@ -308,7 +309,6 @@ pub async fn parallel_execute_transactions(
Err(e) => match e.get_transaction_error() {
Some(TransactionError::BlockhashNotFound) => {
is_blockhash_not_found = true;
break;
}
Some(TransactionError::AlreadyProcessed) => {
submitted_signatures.insert(tx.signatures[0], idx);
Expand Down Expand Up @@ -365,6 +365,7 @@ pub async fn parallel_execute_instructions(
signer: &Arc<Keypair>,
retry_count: u16,
confirmation_time: u64,
microlamports: u64,
) -> Result<Vec<Result<(), SendTransactionError>>, TransactionExecutionError> {
/*
Note: Assumes all instructions are equivalent in compute, equivalent in size, and can be executed in any order
Expand All @@ -383,8 +384,20 @@ pub async fn parallel_execute_instructions(

let instructions_per_tx = calculate_instructions_per_tx(client, instructions, signer)
.await
.map_err(|e| TransactionExecutionError::ClientError(e.to_string()))?;
let transactions: Vec<&[Instruction]> = instructions.chunks(instructions_per_tx).collect();
.map_err(|e| TransactionExecutionError::ClientError(e.to_string()))?
- 1;

let mut transactions: Vec<Vec<Instruction>> = instructions
.chunks(instructions_per_tx)
.map(|c| c.to_vec())
.collect();
for tx in transactions.iter_mut() {
tx.insert(
0,
ComputeBudgetInstruction::set_compute_unit_price(microlamports),
);
}
let transactions: Vec<&[Instruction]> = transactions.iter().map(|c| c.as_slice()).collect();

parallel_execute_transactions(
client,
Expand Down Expand Up @@ -441,7 +454,7 @@ pub async fn submit_transactions(
.map(|t| t.as_slice())
.collect::<Vec<_>>();

match parallel_execute_transactions(client, &tx_slice, keypair, 10, 30).await {
match parallel_execute_transactions(client, &tx_slice, keypair, 100, 20).await {
Ok(results) => {
stats.successes = results.iter().filter(|&tx| tx.is_ok()).count() as u64;
stats.errors = results.len() as u64 - stats.successes;
Expand All @@ -456,9 +469,12 @@ pub async fn submit_instructions(
client: &Arc<RpcClient>,
instructions: Vec<Instruction>,
keypair: &Arc<Keypair>,
microlamports: u64,
) -> Result<SubmitStats, TransactionExecutionError> {
let mut stats = SubmitStats::default();
match parallel_execute_instructions(client, &instructions, keypair, 10, 30).await {
match parallel_execute_instructions(client, &instructions, keypair, 100, 20, microlamports)
.await
{
Ok(results) => {
stats.successes = results.iter().filter(|&tx| tx.is_ok()).count() as u64;
stats.errors = results.len() as u64 - stats.successes;
Expand All @@ -474,9 +490,10 @@ pub async fn submit_create_and_update(
create_transactions: Vec<Vec<Instruction>>,
update_instructions: Vec<Instruction>,
keypair: &Arc<Keypair>,
microlamports: u64,
) -> Result<CreateUpdateStats, TransactionExecutionError> {
Ok(CreateUpdateStats {
creates: submit_transactions(client, create_transactions, keypair).await?,
updates: submit_instructions(client, update_instructions, keypair).await?,
updates: submit_instructions(client, update_instructions, keypair, microlamports).await?,
})
}
15 changes: 12 additions & 3 deletions keepers/validator-keeper/src/cluster_info.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use std::sync::Arc;

use anchor_lang::{InstructionData, ToAccountMetas};
use keeper_core::{submit_instructions, SubmitStats, TransactionExecutionError};
use keeper_core::{submit_transactions, SubmitStats, TransactionExecutionError};
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::{
compute_budget, instruction::Instruction, pubkey::Pubkey, signature::Keypair, signer::Signer,
};
use validator_history::state::ClusterHistory;

use crate::PRIORITY_FEE;

pub async fn update_cluster_info(
client: Arc<RpcClient>,
keypair: Arc<Keypair>,
Expand All @@ -16,6 +18,8 @@ pub async fn update_cluster_info(
let (cluster_history_account, _) =
Pubkey::find_program_address(&[ClusterHistory::SEED], program_id);

let priority_fee_ix =
compute_budget::ComputeBudgetInstruction::set_compute_unit_price(PRIORITY_FEE);
let heap_request_ix = compute_budget::ComputeBudgetInstruction::request_heap_frame(256 * 1024);
let compute_budget_ix =
compute_budget::ComputeBudgetInstruction::set_compute_unit_limit(1_400_000);
Expand All @@ -30,9 +34,14 @@ pub async fn update_cluster_info(
data: validator_history::instruction::CopyClusterInfo {}.data(),
};

submit_instructions(
submit_transactions(
&client,
vec![heap_request_ix, compute_budget_ix, update_instruction],
vec![vec![
priority_fee_ix,
heap_request_ix,
compute_budget_ix,
update_instruction,
]],
&keypair,
)
.await
Expand Down
2 changes: 2 additions & 0 deletions keepers/validator-keeper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub mod vote_account;

pub type Error = Box<dyn std::error::Error>;

pub const PRIORITY_FEE: u64 = 500_000;

#[derive(ThisError, Debug)]
pub enum KeeperError {
#[error(transparent)]
Expand Down
22 changes: 17 additions & 5 deletions keepers/validator-keeper/src/mev_commission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use solana_sdk::{signature::Keypair, signer::Signer};
use validator_history::constants::MIN_VOTE_EPOCHS;
use validator_history::{constants::MAX_ALLOC_BYTES, Config, ValidatorHistory};

use crate::KeeperError;
use crate::{KeeperError, PRIORITY_FEE};

#[derive(Clone)]
pub struct ValidatorMevCommissionEntry {
Expand Down Expand Up @@ -160,8 +160,14 @@ pub async fn update_mev_commission(
let (create_transactions, update_instructions) =
build_create_and_update_instructions(&client, &entries_to_update).await?;

match submit_create_and_update(&client, create_transactions, update_instructions, &keypair)
.await
match submit_create_and_update(
&client,
create_transactions,
update_instructions,
&keypair,
PRIORITY_FEE,
)
.await
{
Ok(submit_result) => {
if submit_result.creates.errors == 0 && submit_result.updates.errors == 0 {
Expand Down Expand Up @@ -222,8 +228,14 @@ pub async fn update_mev_earned(
let (create_transactions, update_instructions) =
build_create_and_update_instructions(client, &entries_to_update).await?;

let submit_result =
submit_create_and_update(client, create_transactions, update_instructions, keypair).await;
let submit_result = submit_create_and_update(
client,
create_transactions,
update_instructions,
keypair,
PRIORITY_FEE,
)
.await;
match submit_result {
Ok(submit_result) => {
if submit_result.creates.errors == 0 && submit_result.updates.errors == 0 {
Expand Down
16 changes: 11 additions & 5 deletions keepers/validator-keeper/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use validator_history::{
state::{Config, ValidatorHistory},
};

use crate::KeeperError;
use crate::{KeeperError, PRIORITY_FEE};

pub struct StakeHistoryEntry {
pub stake: u64,
Expand Down Expand Up @@ -218,9 +218,15 @@ pub async fn update_stake_history(
let (create_transactions, update_instructions) =
build_create_and_update_instructions(&client, &stake_history_entries).await?;

submit_create_and_update(&client, create_transactions, update_instructions, &keypair)
.await
.map_err(|e| e.into())
submit_create_and_update(
&client,
create_transactions,
update_instructions,
&keypair,
PRIORITY_FEE,
)
.await
.map_err(|e| e.into())
}

/*
Expand Down Expand Up @@ -311,7 +317,7 @@ pub async fn _recompute_superminority_and_rank(
.map(|entry| entry.update_instruction())
.collect::<Vec<_>>();

match submit_instructions(&client, update_instructions, &keypair).await {
match submit_instructions(&client, update_instructions, &keypair, PRIORITY_FEE).await {
Ok(_) => println!("completed epoch {}", epoch),
Err(e) => return Err(e.into()),
};
Expand Down
3 changes: 2 additions & 1 deletion keepers/validator-keeper/src/vote_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use validator_history::constants::{MAX_ALLOC_BYTES, MIN_VOTE_EPOCHS};
use validator_history::state::ValidatorHistory;
use validator_history::Config;

use crate::{get_validator_history_accounts_with_retry, KeeperError};
use crate::{get_validator_history_accounts_with_retry, KeeperError, PRIORITY_FEE};

pub struct CopyVoteAccountEntry {
pub vote_account: Pubkey,
Expand Down Expand Up @@ -162,6 +162,7 @@ pub async fn update_vote_accounts(
create_transactions,
update_instructions,
&keypair,
PRIORITY_FEE,
)
.await;

Expand Down

0 comments on commit 18984a3

Please sign in to comment.