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: miner read all values from storage #808

Merged
merged 3 commits into from
May 8, 2024
Merged

feat: miner read all values from storage #808

merged 3 commits 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 17:32
@dinhani-cw dinhani-cw enabled auto-merge (squash) May 8, 2024 17:33
Copy link

github-actions bot commented May 8, 2024

PR Review 🔍

⏱️ Estimated effort to review [1-5]

3, because the PR involves significant changes across multiple files, including logic changes in mining and execution functions, and the introduction of new helper functions. Understanding the impact of these changes on the system's behavior requires a good grasp of the existing architecture and the intended functionality of the modifications.

🧪 Relevant tests

No

⚡ Possible issues

Possible Bug: The removal of the block parameter in mine_external() and mine_mixed() methods in BlockMiner class might lead to issues if the external block data is not properly managed or is missing in the storage, as these methods now rely entirely on the storage to provide the necessary block data.

Logic Error: The new partitioning logic in partition_transactions() might introduce errors if the transaction kinds are not correctly identified and separated, leading to incorrect mining behavior.

🔒 Security concerns

No

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

Consider adding error handling for the case where block_number() does not return a valid block number in mine_external_transactions(). This could prevent potential runtime errors or inconsistencies if the block number is missing or invalid. [important]

relevant lineif tx.block_number() != block_number {

relevant filesrc/eth/block_miner.rs
suggestion      

It might be beneficial to implement logging for successful mining operations or critical steps within the mining functions to aid in debugging and monitoring the mining process. [medium]

relevant lineblock_from_external(external_block, mined_txs)

relevant filesrc/eth/block_miner.rs
suggestion      

To enhance code clarity and maintainability, consider refactoring the mine_external() and mine_mixed() methods to separate the concerns of data retrieval, transaction partitioning, and block construction into distinct methods or structs. [medium]

relevant linepub async fn mine_external(&self) -> anyhow::Result {

relevant filesrc/eth/block_miner.rs
suggestion      

Ensure that the new helper functions like read_external_block_and_executions() are covered by unit tests to verify their behavior, especially their interaction with the storage system and error handling. [important]

relevant lineasync fn read_external_block_and_executions(storage: &StratusStorage) -> anyhow::Result<(ExternalBlock, Vec)> {

Copy link

github-actions bot commented May 8, 2024

PR Code Suggestions ✨

CategorySuggestions                                                                                                                                                       
Bug
Replace the not function with the ! operator for proper negation in Rust.

Replace the not function with the ! operator for negating the condition in Rust.

src/eth/block_miner.rs [60-62]

-if not(local_txs.is_empty()) {
+if !local_txs.is_empty() {
     return log_and_err!("cannot mine external block because one of the transactions is not an external transaction");
 }
 
Add error handling to prevent potential runtime panic.

Add error handling for the case when block_from_external returns an error, to prevent
unwrapping on an Err value which could cause a panic.

src/eth/block_miner.rs [65-66]

 let mined_txs = mine_external_transactions(external_block.number(), external_txs)?;
-block_from_external(external_block, mined_txs)
+block_from_external(external_block, mined_txs)?
 
Correct the logic to properly handle successful transaction executions.

Ensure that the is_success() method is correctly checked against the expected condition by
negating the current check.

src/eth/block_miner.rs [81-83]

-if execution.is_success() {
-    return log_and_err!("cannot mine mixed block because one of the local execution is not a failure");
+if !execution.is_success() {
+    block.push_execution(tx, execution);
 }
 
Enhancement
Simplify error handling using pattern matching and error propagation.

Use pattern matching to simplify the error handling in read_external_block_and_executions.

src/eth/block_miner.rs [206-210]

-let block = match storage.temp.read_external_block().await {
-    Ok(Some(block)) => block,
-    Ok(None) => return log_and_err!("no active external block being re-executed"),
-    Err(e) => return Err(e),
-};
+let block = storage.temp.read_external_block().await?
+    .ok_or_else(|| anyhow::anyhow!("no active external block being re-executed"))?;
 
Improve error messages to include specific transaction details.

Use a more descriptive error message in mine_external_transactions to include which
transaction caused the issue.

src/eth/block_miner.rs [239-241]

 if tx.block_number() != block_number {
-    return log_and_err!("cannot mine external block because one of the transactions does not belong to the external block");
+    return log_and_err!(format!("cannot mine external block because transaction {} does not belong to the external block", tx.hash()));
 }
 

@dinhani-cw dinhani-cw merged commit da19374 into main May 8, 2024
25 checks passed
@dinhani-cw dinhani-cw deleted the miner-block branch May 8, 2024 17:46
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