From abe8737b35317cd21814fc0d7e8d56aebc7c10a7 Mon Sep 17 00:00:00 2001 From: Koen Rijpstra Date: Wed, 10 Apr 2024 15:19:23 +0200 Subject: [PATCH] Improve Rebroadcast Logic --- src/main.rs | 2 +- src/send_and_confirm.rs | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index ce2723ec..fc0200ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -192,7 +192,7 @@ async fn main() { // Initialize miner. let cluster = args.rpc.unwrap_or(cli_config.json_rpc_url); let default_keypair = args.keypair.unwrap_or(cli_config.keypair_path); - let rpc_client = RpcClient::new_with_commitment(cluster, CommitmentConfig::finalized()); + let rpc_client = RpcClient::new_with_commitment(cluster, CommitmentConfig::confirmed()); let miner = Arc::new(Miner::new( Arc::new(rpc_client), diff --git a/src/send_and_confirm.rs b/src/send_and_confirm.rs index 087ef9e3..6d32eee6 100644 --- a/src/send_and_confirm.rs +++ b/src/send_and_confirm.rs @@ -20,11 +20,11 @@ use crate::Miner; const RPC_RETRIES: usize = 0; const SIMULATION_RETRIES: usize = 4; -const GATEWAY_RETRIES: usize = 4; -const CONFIRM_RETRIES: usize = 4; +const GATEWAY_RETRIES: usize = 150; +const CONFIRM_RETRIES: usize = 1; -const CONFIRM_DELAY: u64 = 5000; -const GATEWAY_DELAY: u64 = 2000; +const CONFIRM_DELAY: u64 = 0; +const GATEWAY_DELAY: u64 = 300; impl Miner { pub async fn send_and_confirm( @@ -47,16 +47,16 @@ impl Miner { } // Build tx - let (hash, slot) = client + let (_hash, slot) = client .get_latest_blockhash_with_commitment(self.rpc_client.commitment()) .await .unwrap(); let send_cfg = RpcSendTransactionConfig { - skip_preflight: false, - preflight_commitment: Some(CommitmentLevel::Finalized), + skip_preflight: true, + preflight_commitment: Some(CommitmentLevel::Confirmed), encoding: Some(UiTransactionEncoding::Base64), max_retries: Some(RPC_RETRIES), - min_context_slot: Some(slot), + min_context_slot: None, }; let mut tx = Transaction::new_with_payer(ixs, Some(&signer.pubkey())); @@ -113,6 +113,12 @@ impl Miner { } } + // Update hash before sending transactions + let (hash, _slot) = client + .get_latest_blockhash_with_commitment(self.rpc_client.commitment()) + .await + .unwrap(); + // Submit tx tx.sign(&[&signer], hash); // let mut sigs = vec![];