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

Added retry for gateway tx #1765

Merged
merged 2 commits into from
May 4, 2022
Merged
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
17 changes: 16 additions & 1 deletion sui_core/src/gateway_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would ideally want a compile-tile way to assert this is always non zero


pub struct GatewayState<A> {
authorities: AuthorityAggregator<A>,
Expand Down Expand Up @@ -573,7 +575,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