Skip to content

Commit

Permalink
Added retry for gateway tx (#1765)
Browse files Browse the repository at this point in the history
* Added retry for gateway tx
  • Loading branch information
oxade authored and longbowlu committed May 12, 2022
1 parent 2641369 commit 14fb016
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion sui_core/src/gateway_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub type GatewayClient = Box<dyn GatewayAPI + Sync + Send>;
pub type GatewayTxSeqNumber = u64;

const MAX_TX_RANGE_SIZE: u64 = 4096;
/// Number of times to retry failed TX
const MAX_NUM_TX_RETRIES: usize = 5;

pub struct GatewayState<A> {
authorities: AuthorityAggregator<A>,
Expand Down Expand Up @@ -575,7 +577,20 @@ where
tx: Transaction,
) -> Result<TransactionResponse, anyhow::Error> {
let tx_kind = tx.data.kind.clone();
let (certificate, effects) = self.execute_transaction_impl(tx).await?;
let mut res = self.execute_transaction_impl(tx.clone()).await;

let mut remaining_retries = MAX_NUM_TX_RETRIES;
while res.is_err() {
if remaining_retries == 0 {
// Okay to do this since we checked that this is an error
return Err(res.unwrap_err());
}
remaining_retries -= 1;
res = self.execute_transaction_impl(tx.clone()).await;
}

// Okay to unwrap() since we checked that this is Ok
let (certificate, effects) = res.unwrap();

// Create custom response base on the request type
if let TransactionKind::Single(tx_kind) = tx_kind {
Expand Down

0 comments on commit 14fb016

Please sign in to comment.