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 committed May 4, 2022
1 parent 5b6a3b1 commit b644b87
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

1 comment on commit b644b87

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Bench results

�[0m�[0m�[1m�[32m Finished�[0m release [optimized] target(s) in 0.38s
�[0m�[0m�[1m�[32m Running�[0m target/release/bench microbench throughput
�[2m2022-05-04T02:03:26.746616Z�[0m �[32m INFO�[0m �[2msui::benchmark�[0m�[2m:�[0m benchmark : Benchmark { committee_size: 1, send_timeout_us: 400000000, recv_timeout_us: 400000000, buffer_size: 65000, tcp_connections: 0, db_cpus: 1, use_native: false, batch_size: 2000, running_mode: SingleValidatorThread, working_dir: None, bench_type: MicroBenchmark { host: "127.0.0.1", port: 9555, type_: Throughput { num_transactions: 100000 } } }
�[2m2022-05-04T02:03:26.747552Z�[0m �[32m INFO�[0m �[2msui::benchmark::validator_preparer�[0m�[2m:�[0m authority address hex: 355B3D08C5CE4AFCDA085839E207C67E56FA2654
�[2m2022-05-04T02:03:26.747711Z�[0m �[32m INFO�[0m �[2msui::benchmark::validator_preparer�[0m�[2m:�[0m Open database on path: "/tmp/DB_2CB62BFB544B66138E14FD592BE58BCE07AF63B5"
�[2m2022-05-04T02:03:27.998698Z�[0m �[32m INFO�[0m �[2msui::benchmark::validator_preparer�[0m�[2m:�[0m Spawning a validator thread...
�[2m2022-05-04T02:03:27.999530Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m Listening to TCP traffic on 127.0.0.1:9555
Throughout: 33126.57930966859 tps

Please sign in to comment.