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

feat: error logs and importer-offline fix #807

Merged
merged 1 commit into from
May 8, 2024
Merged

feat: error logs and importer-offline fix #807

merged 1 commit into from
May 8, 2024

Conversation

dinhani-cw
Copy link
Contributor

No description provided.

@dinhani-cw dinhani-cw requested a review from a team as a code owner May 8, 2024 16:32
Copy link

github-actions bot commented May 8, 2024

PR Review 🔍

⏱️ Estimated effort to review [1-5]

3, because the PR involves multiple files and changes in both Rust and Solidity, affecting error handling, logging, and data structures. The changes are moderate in complexity, involving asynchronous programming and error management which require careful review to ensure correctness and efficiency.

🧪 Relevant tests

No

⚡ Possible issues

Possible Bug: The error handling in src/bin/importer_offline.rs and src/bin/importer_online.rs might suppress the propagation of errors after logging, which can lead to the continuation of execution when it should actually stop.

Thread Safety: The modifications in src/eth/storage/inmemory/inmemory_temporary.rs involve asynchronous access to shared state, which could lead to race conditions if not handled properly.

🔒 Security concerns

No

Code feedback:
relevant filesrc/bin/importer_offline.rs
suggestion      

Consider rethrowing the error after logging in importer_offline.rs to ensure that the error state does not get suppressed unintentionally. This can be done by adding return Err(e); after the logging statement. [important]

relevant linetracing::error!(reason = ?e, "storage-loader failed");

relevant filesrc/bin/importer_online.rs
suggestion      

Similar to the offline importer, ensure that errors are not suppressed after logging in the online importer. This can be achieved by returning the error after logging. [important]

relevant linetracing::error!(reason = ?e, "importer-online failed");

relevant filesrc/eth/storage/inmemory/inmemory_temporary.rs
suggestion      

Add error handling for potential failures in the drain method within remove_executions_before. This could involve logging the error or rethrowing it to handle it upstream. [medium]

relevant linelet _ = state.tx_executions.drain(..index - 1);

relevant filesrc/eth/primitives/transaction_execution.rs
suggestion      

Ensure that the hash method in TransactionExecution handles all possible cases or errors that might arise from hashing, especially if the transaction data is incomplete or corrupted. [medium]

relevant linepub fn hash(&self) -> Hash {

@dinhani-cw dinhani-cw enabled auto-merge (squash) May 8, 2024 16:34
Copy link

github-actions bot commented May 8, 2024

PR Code Suggestions ✨

CategorySuggestions                                                                                                                                                       
Bug
Handle potential errors from thread joining to avoid silent failures.

Consider handling the potential error from the join method on the thread handle
importer_join. If the thread panics, the error will be silently ignored, which might lead
to unexpected behavior.

src/bin/importer_offline.rs [126]

-let _ = importer_join.join();
+if let Err(e) = importer_join.join() {
+    tracing::error!("Failed to join importer thread: {:?}", e);
+}
 
Add a check to prevent underflow and improve the clarity of debug logs.

The debug statement in remove_executions_before logs index - 1, which might be confusing
if index is 0, leading to an underflow. Consider adding a check to ensure index is greater
than 0 before subtracting.

src/eth/storage/inmemory/inmemory_temporary.rs [123]

-tracing::debug!(tx_executions_len = %state.tx_executions.len(), index = %index, "removing executions");
+if index > 0 {
+    tracing::debug!(tx_executions_len = %state.tx_executions.len(), index = %index - 1, "removing executions");
+} else {
+    tracing::warn!("Attempted to remove executions with non-positive index: {}", index);
+}
 
Enhancement
Correct the spelling of the variable to improve readability.

The variable config.paralellism seems to be a typo. Consider renaming it to
config.parallelism to improve code readability and maintain consistency.

src/bin/importer_offline.rs [96]

-config.paralellism,
+config.parallelism,
 
Enhance logging to include successful completions for better traceability.

The result of run_importer_online is being logged only on error. It might be beneficial to
also log successful completion or other statuses for better traceability and debugging.

src/bin/importer_online.rs [39]

 let result = run_importer_online(executor, miner, storage, chain).await;
+match &result {
+    Ok(_) => tracing::info!("Importer online completed successfully"),
+    Err(e) => tracing::error!(reason = ?e, "importer-online failed"),
+}
 
Possible issue
Ensure consistent method availability in enum variants to prevent runtime panics.

The method hash in TransactionExecution might panic if the TransactionKind::Local
variant's tx does not have a hash method. Ensure that all variants used in this match have
a consistent interface for fetching a hash.

src/eth/primitives/transaction_execution.rs [34-38]

 pub fn hash(&self) -> Hash {
     match self.kind {
-        TransactionKind::Local(ref tx) => tx.hash,
+        TransactionKind::Local(ref tx) => tx.hash(),
         TransactionKind::External(ref tx, _) => tx.hash(),
     }
 }
 

@dinhani-cw dinhani-cw merged commit 6a82ac4 into main May 8, 2024
26 checks passed
@dinhani-cw dinhani-cw deleted the error-logs branch May 8, 2024 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants