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: simplify temporary storage #838

Merged
merged 1 commit into from
May 14, 2024
Merged

refactor: simplify temporary storage #838

merged 1 commit into from
May 14, 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 14, 2024 14:15
Copy link

PR Review 🔍

⏱️ Estimated effort to review [1-5]

4, because the PR involves multiple changes across several files, including refactoring and feature removals which require careful consideration of impacts on existing functionality and dependencies. The changes are spread across core components like mining logic and storage handling, which are critical and complex parts of the system.

🧪 Relevant tests

No

⚡ Possible issues

Possible Bug: The removal of RocksTemporaryStorage without a clear replacement or migration path could lead to issues if other parts of the system still depend on this functionality.

Possible Bug: The new method mine_external_mixed in BlockMiner assumes that the block exists (let Some(external_block) = block.external_block else { ... }), which might not always be the case, potentially leading to runtime errors if not handled properly.

🔒 Security concerns

No

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

Consider adding error handling for the case when block.external_block is None in the mine_external method to prevent potential runtime panics. [important]

relevant linelet Some(external_block) = block.external_block else {

relevant filesrc/eth/block_miner.rs
suggestion      

Refactor the repeated logic in mine_external and mine_external_mixed methods to a common function to improve code maintainability and reduce duplication. [important]

relevant linelet mined_txs = mine_external_transactions(block.number, external_txs)?;

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

Ensure that the new block number is correctly incremented in finish_block method to maintain the integrity of block sequencing. [important]

relevant linestates.head.block = Some(PendingBlock::new(finished_block.number.next()));

relevant filesrc/bin/importer_online.rs
suggestion      

Verify that the new method mine_external_mixed is correctly handling all edge cases, especially around transaction types and block commitments, to ensure system stability. [important]

relevant linelet mined_block = miner.mine_external_mixed().await?;

Copy link

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Score
Maintainability
Refactor require_active_block and require_active_block_mut to reduce code redundancy

The require_active_block_mut and require_active_block methods duplicate some logic.
Consider refactoring these methods to reduce redundancy and improve maintainability.

src/eth/storage/inmemory/inmemory_temporary.rs [77-89]

-fn require_active_block(&mut self) -> anyhow::Result<&PendingBlock> {
+fn require_active_block<T>(&mut self) -> anyhow::Result<&T> where T: Borrow<PendingBlock> + BorrowMut<PendingBlock> {
     match &self.block {
-        Some(block) => Ok(block),
-        None => log_and_err!("no pending block being mined"),
-    }
-}
-fn require_active_block_mut(&mut self) -> anyhow::Result<&mut PendingBlock> {
-    match &mut self.block {
-        Some(block) => Ok(block),
+        Some(block) => Ok(block.borrow()),
         None => log_and_err!("no pending block being mined"),
     }
 }
 
Suggestion importance[1-10]: 8

Why: The suggestion to refactor require_active_block and require_active_block_mut is beneficial for maintainability by reducing code redundancy and simplifying future modifications.

8
Possible issue
Add error handling for the mine_external_transactions function to enhance robustness

Consider handling the case where mine_external_transactions might fail due to network or
other errors. Currently, the function assumes success and proceeds to create a block from
external transactions. Adding error handling here would make the function more robust.

src/eth/block_miner.rs [59]

-let mined_txs = mine_external_transactions(block.number, external_txs)?;
+let mined_txs = mine_external_transactions(block.number, external_txs)
+    .map_err(|e| log_and_err!("failed to mine external transactions: {}", e))?;
 
Suggestion importance[1-10]: 7

Why: The suggestion correctly identifies a potential issue with error handling in the mine_external_transactions function, which is crucial for robustness, especially in network-related operations.

7
Enhancement
Implement filtering of local transactions to include only failed ones in mine_external_mixed

The current implementation of mine_external_mixed does not differentiate between
successful and failed local transactions as mentioned in the comment. It's important to
implement this differentiation to ensure that only failed local transactions are included.

src/eth/block_miner.rs [76-77]

 let mined_txs = mine_external_transactions(block.number, external_txs)?;
-let mut block = block_from_external(external_block, mined_txs)?;
+let failed_local_txs = filter_failed_local_transactions(local_txs);
+let mut block = block_from_external_and_local(external_block, mined_txs, failed_local_txs)?;
 
Suggestion importance[1-10]: 6

Why: The suggestion is valid as it addresses the need to differentiate between successful and failed local transactions in the mine_external_mixed method, aligning with the method's documentation and intent.

6

@dinhani-cw dinhani-cw merged commit fd0fc23 into main May 14, 2024
26 checks passed
@dinhani-cw dinhani-cw deleted the pending-block branch May 14, 2024 14:22
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