Skip to content

Commit

Permalink
Merge pull request regolith-labs#62 from KoenRijpstra/koen
Browse files Browse the repository at this point in the history
Improve Rebroadcast Logic
  • Loading branch information
HardhatChad authored Apr 10, 2024
2 parents 778a667 + abe8737 commit 524bb8c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
22 changes: 14 additions & 8 deletions src/send_and_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()));

Expand Down Expand Up @@ -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![];
Expand Down

0 comments on commit 524bb8c

Please sign in to comment.