Skip to content

Commit

Permalink
block on txn confirmation
Browse files Browse the repository at this point in the history
mobile packet verifier is not handling many burn txns, we can block on confirming before attempting to process the next txn.

Txn tracking by signature and block-height will come in a later update.
  • Loading branch information
michaeldjeffrey committed Dec 4, 2024
1 parent 2db933d commit 8b059ec
Showing 1 changed file with 49 additions and 55 deletions.
104 changes: 49 additions & 55 deletions mobile_packet_verifier/src/burner.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{future::Future, time::Duration};
use std::time::Duration;

use file_store::file_sink::FileSinkClient;
use helium_crypto::PublicKeyBinary;
Expand Down Expand Up @@ -76,79 +76,73 @@ where
max_attempts = self.failed_retry_attempts
);

tokio::spawn(
self.transaction_confirmation_check(
pool, err, txn, payer, total_dcs, sessions,
)
.instrument(span),
);
// block on confirmation
self.transaction_confirmation_check(pool, err, txn, payer, total_dcs, sessions)
.instrument(span)
.await;
}
}
}

Ok(())
}

fn transaction_confirmation_check(
async fn transaction_confirmation_check(
&self,
pool: &Pool<Postgres>,
err: S::Error,
txn: S::Transaction,
payer: PublicKeyBinary,
total_dcs: u64,
sessions: Vec<pending_burns::DataTransferSession>,
) -> impl Future<Output = ()> {
let pool = pool.clone();
let solana = self.solana.clone();
let valid_sessions = self.valid_sessions.clone();
let retry_attempts = self.failed_retry_attempts;
let check_interval = self.failed_check_interval;

async move {
tracing::warn!(?err, "starting txn confirmation check");
// We don't know if the txn actually made it, maybe it did

let signature = txn.get_signature();
for check_idx in 0..retry_attempts {
tokio::time::sleep(check_interval).await;
match solana.confirm_transaction(signature).await {
Ok(true) => {
tracing::debug!("txn confirmed on chain");
let txn_success = handle_transaction_success(
&pool,
payer,
total_dcs,
sessions,
&valid_sessions,
)
.await;
if let Err(err) = txn_success {
tracing::error!(?err, "txn succeeded, something else failed");
}

return;
}
Ok(false) => {
tracing::info!(check_idx, "txn not confirmed, yet...");
continue;
}
Err(err) => {
tracing::error!(?err, check_idx, "failed to confirm txn");
continue;
) {
tracing::warn!(?err, "starting txn confirmation check");
// We don't know if the txn actually made it, maybe it did

let signature = txn.get_signature();

let mut attempt = 0;
while attempt <= self.failed_retry_attempts {
tokio::time::sleep(self.failed_check_interval).await;
match self.solana.confirm_transaction(signature).await {
Ok(true) => {
tracing::debug!("txn confirmed on chain");
let txn_success = handle_transaction_success(
&pool,
payer,
total_dcs,
sessions,
&self.valid_sessions,
)
.await;
if let Err(err) = txn_success {
tracing::error!(?err, "txn succeeded, something else failed");
}

return;
}
Ok(false) => {
tracing::info!(attempt, "txn not confirmed, yet...");
attempt += 1;
continue;
}
Err(err) => {
// Client errors do not count against retry attempts
tracing::error!(?err, attempt, "failed to confirm txn");
continue;
}
}
}

tracing::warn!("failed to confirm txn");
tracing::warn!("failed to confirm txn");

// We have failed to burn data credits:
metrics::counter!(
"burned",
"payer" => payer.to_string(),
"success" => "false"
)
.increment(total_dcs);
}
// We have failed to burn data credits:
metrics::counter!(
"burned",
"payer" => payer.to_string(),
"success" => "false"
)
.increment(total_dcs);
}
}

Expand Down

0 comments on commit 8b059ec

Please sign in to comment.