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

refactor: executor #829

Merged
merged 2 commits into from
May 13, 2024
Merged

refactor: executor #829

merged 2 commits into from
May 13, 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 13, 2024 18:57
Copy link

PR Review 🔍

⏱️ Estimated effort to review [1-5]

3, because the PR involves significant refactoring across multiple files and modules, including changes in transaction execution handling and storage mechanisms. The changes are complex and require a thorough understanding of the existing system architecture and the implications of the modifications on transaction processing and state management.

🧪 Relevant tests

No

⚡ Possible issues

Possible Bug: The refactoring in src/eth/block_miner.rs changes how transactions are processed and executed. Specifically, the removal of TransactionKind and restructuring to use LocalTransactionExecution and ExternalTransactionExecution might introduce bugs if not all properties and behaviors of the original implementation are preserved or correctly adapted.

Performance Concern: The changes in transaction execution handling could potentially affect performance, especially if the new structures and methods introduce inefficiencies in how transactions are processed or state is managed.

🔒 Security concerns

No

Code feedback:
relevant filesrc/eth/block_miner.rs
suggestion      

Consider adding error handling for the push_execution method to ensure that errors during the transaction execution pushing are caught and handled appropriately. This is important to maintain the robustness of the block mining process. [important]

relevant lineblock.push_execution(tx.input, tx.result);

relevant filesrc/eth/executor.rs
suggestion      

It might be beneficial to refactor the repeated pattern of transaction reexecution in the Executor to a separate method to reduce code duplication and improve maintainability. This pattern appears multiple times in the Executor implementation. [important]

relevant lineParallelExecutionRoute::Serial(tx, receipt) => self.reexecute_external_tx(tx, receipt, block).await.map_err(|(_, _, e)| e)?,

relevant filesrc/eth/primitives/transaction_execution.rs
suggestion      

Ensure that the new enum TransactionExecution and its variants are fully compatible with all use cases in the system, particularly with respect to serialization and deserialization processes that might be impacted by the structural changes from using TransactionKind to the new format. [medium]

relevant linepub enum TransactionExecution {

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

Optimize the storage update process by potentially introducing batch updates or other mechanisms to reduce the overhead of updating accounts one by one in the loop. This could improve the performance of the storage system, especially under high load. [medium]

relevant linelet changes = execution.changes.values();

Copy link

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Score
Enhancement
Add a default case to handle unexpected transaction types

The current implementation assumes that all transactions in txs are of type
TransactionExecution::Local or TransactionExecution::External. Consider adding a default
case in the match statement to handle potential future additions to the
TransactionExecution enum gracefully.

src/eth/block_miner.rs [221-227]

 match tx {
     TransactionExecution::Local(tx) => {
         local_txs.push(tx);
     }
     TransactionExecution::External(tx) => {
         external_txs.push(tx);
     }
+    _ => {
+        // Handle unexpected transaction type
+        tracing::warn!("Encountered an unexpected transaction type");
+    }
 }
 
Suggestion importance[1-10]: 7

Why: This is a valid suggestion for enhancing robustness by handling unexpected cases in the match statement. Adding a default case can prevent future errors if new transaction types are added.

7
Add detailed logging for conflicts in transaction execution saving

Consider adding detailed logging for each conflict detected. This would help in debugging
and understanding the specific reasons for conflicts during transaction execution saving.

src/eth/storage/inmemory/inmemory_temporary.rs [139-140]

 if let Some(conflicts) = state.check_conflicts(execution) {
+    tracing::error!("Conflicts detected: {:?}", conflicts);
     return Err(StorageError::Conflict(conflicts)).context("execution conflicts with current state");
 }
 
Suggestion importance[1-10]: 5

Why: Adding detailed logging for conflicts is a good practice for debugging and operational transparency. However, this is a relatively minor enhancement as it primarily aids in debugging rather than altering functionality or performance.

5
Maintainability
Simplify error handling for failed receipts in transaction reexecution

The error handling for receipt.is_failure() could be improved by directly returning the
error instead of wrapping it in a tuple. This change would simplify the error handling
flow and make the function more readable.

src/eth/executor.rs [169-182]

 if receipt.is_failure() {
-    let sender = match self.storage.read_account(&receipt.from.into(), &StoragePointInTime::Present).await {
-        Ok(sender) => sender,
-        Err(e) => return Err((tx, receipt, e)),
-    };
-    let execution = match EvmExecution::from_failed_external_transaction(sender, receipt, block) {
-        Ok(execution) => execution,
-        Err(e) => return Err((tx, receipt, e)),
-    };
+    let sender = self.storage.read_account(&receipt.from.into(), &StoragePointInTime::Present).await?;
+    let execution = EvmExecution::from_failed_external_transaction(sender, receipt, block)?;
     let evm_result = EvmExecutionResult {
         execution,
         metrics: ExecutionMetrics::default(),
     };
     return Ok(ExternalTransactionExecution::new(tx.clone(), receipt.clone(), evm_result));
 }
 
Suggestion importance[1-10]: 6

Why: The suggestion to simplify error handling by directly returning errors instead of wrapping them in a tuple is valid and improves readability. However, the existing code's approach might be intentional for debugging or other purposes, so the improvement is moderate.

6

@dinhani-cw dinhani-cw enabled auto-merge (squash) May 13, 2024 19:14
@dinhani-cw dinhani-cw merged commit 76a6268 into main May 13, 2024
25 checks passed
@dinhani-cw dinhani-cw deleted the refactor branch May 13, 2024 19:14
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.

1 participant