You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Logging and Monitoring: The PR includes error and warning logs which are good for monitoring the system's behavior in case of failures or delays. However, it's not clear if these logs are sufficient for all new branches of execution introduced. It would be beneficial to ensure that all error states and exceptional conditions are logged.
Timeout Handling: The use of tokio::time::timeout is appropriate for handling potential delays in the receipt of transactions. However, the hardcoded timeout duration (30 seconds) might not be suitable for all environments or conditions. Consider making this configurable.
Retry Logic: The changes in retry logic (*this.retries_remaining <= 0) are sensible, ensuring that the transaction does not endlessly retry. However, it's crucial to ensure that this logic correctly matches the intended behavior, especially in edge cases where retries might decrement in unexpected ways.
Add error handling for None case in substrate_receipt comparison
Consider handling the case where substrate_receipt.compare(&stratus_receipt) might return an error due to substrate_receipt being None, which is not currently handled.
-if let Err(compare_error) = substrate_receipt.compare(&stratus_receipt) {- let err_string = compare_error.to_string();- let error = log_and_err!("transaction mismatch!").context(err_string.clone());- self.save_mismatch(stratus_receipt, substrate_receipt, &err_string).await;- return error.map_err(RelayError::Mismatch);+if let Some(receipt) = substrate_receipt {+ if let Err(compare_error) = receipt.compare(&stratus_receipt) {+ let err_string = compare_error.to_string();+ let error = log_and_err!("transaction mismatch!").context(err_string.clone());+ self.save_mismatch(stratus_receipt, receipt, &err_string).await;+ return error.map_err(RelayError::Mismatch);+ } else {+ return Ok(());+ }
} else {
- return Ok(());+ tracing::error!(?tx_hash, "substrate_receipt is None, cannot compare.");+ return Err(RelayError::InvalidData(anyhow!("substrate_receipt is None")));
}
Suggestion importance[1-10]: 9
Why: This suggestion addresses a potential bug where substrate_receipt could be None, which is not currently handled. Adding this error handling improves the robustness of the code.
9
Maintainability
Replace hardcoded timeout duration with a configurable constant
Replace the hardcoded timeout duration with a configurable value or constant to improve flexibility and maintainability.
Why: Using a configurable constant for the timeout duration improves maintainability and flexibility, allowing for easier adjustments in the future without modifying the code directly.
8
Refactor nested match statements into separate functions for clarity
Refactor the nested match statements to reduce complexity and improve code readability.
match receipt {
- Ok(Some(substrate_receipt)) => {- if let Err(compare_error) = substrate_receipt.compare(&stratus_receipt) {- let err_string = compare_error.to_string();- let error = log_and_err!("transaction mismatch!").context(err_string.clone());- self.save_mismatch(stratus_receipt, substrate_receipt, &err_string).await;- return error.map_err(RelayError::Mismatch);- } else {- return Ok(());- }- }- Ok(None) => {- if start.elapsed().as_secs() <= 30 {- tracing::warn!(?tx_hash, "no receipt returned by substrate, retrying...");- } else {- tracing::error!(?tx_hash, "no receipt returned by substrate for more than 30 seconds, retrying block");- return Err(RelayError::CompareTimeout(anyhow!("no receipt returned by substrate for more than 30 seconds")));- }- }+ Ok(Some(receipt)) => process_receipt(receipt, &stratus_receipt, &tx_hash),+ Ok(None) => handle_no_receipt(&start, &tx_hash),
Err(error) => {
tracing::error!(?tx_hash, ?error, "failed to fetch substrate receipt, retrying...");
}
}
+// Define `process_receipt` and `handle_no_receipt` elsewhere in your module+
Suggestion importance[1-10]: 7
Why: Refactoring nested match statements into separate functions can improve code readability and maintainability, although it is not critical for functionality.
7
Best practice
Improve variable naming for better code clarity
Use a more descriptive variable name than this to improve code readability and maintainability.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.