Skip to content

Commit

Permalink
Improve wait_for_transaction_acceptance (#2177)
Browse files Browse the repository at this point in the history
* Don't error with NotFound for the first attempts in wait_for_transaction_acceptance as the node may not have fully processed the tx at this point

* Don't error on NotFound as nodes may haven't processed/got the tx yet
  • Loading branch information
Thoralf-M authored Mar 14, 2024
1 parent 9c36a7c commit 05cf681
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions sdk/src/client/api/wait_for_tx_acceptance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ impl Client {
.unwrap_or(DEFAULT_WAIT_FOR_TX_ACCEPTANCE_INTERVAL);

for _ in 0..max_attempts.unwrap_or(DEFAULT_WAIT_FOR_TX_ACCEPTANCE_MAX_ATTEMPTS) {
let transaction_metadata = self.get_transaction_metadata(transaction_id).await?;

match transaction_metadata.transaction_state {
TransactionState::Accepted | TransactionState::Committed | TransactionState::Finalized => {
return Ok(());
match self.get_transaction_metadata(transaction_id).await {
Ok(transaction_metadata) => {
match transaction_metadata.transaction_state {
TransactionState::Accepted | TransactionState::Committed | TransactionState::Finalized => {
return Ok(());
}
TransactionState::Failed => {
return Err(ClientError::TransactionAcceptance(transaction_id.to_string()));
}
TransactionState::Pending => {} // Just need to wait longer
};
}
TransactionState::Failed => return Err(ClientError::TransactionAcceptance(transaction_id.to_string())),
TransactionState::Pending => {} // Just need to wait longer
Err(ClientError::Node(crate::client::node_api::error::Error::NotFound(_))) => {}
Err(e) => return Err(e),
};

#[cfg(target_family = "wasm")]
Expand Down

0 comments on commit 05cf681

Please sign in to comment.