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

Improve Rebroadcast Logic #62

Merged
merged 1 commit into from
Apr 10, 2024
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
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