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: improving temporary storage and block miner signatures #805

Merged
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 15:53
Copy link

github-actions bot commented May 8, 2024

PR Review 🔍

⏱️ Estimated effort to review [1-5]

3, because the PR involves multiple changes across various files related to storage and block mining, which requires a good understanding of the system's architecture and the specific modules affected.

🧪 Relevant tests

No

⚡ Possible issues

Possible Bug: The method remove_executions_before in InMemoryTemporaryStorage and RocksTemporaryStorage might incorrectly remove executions due to the expression ..index - 1. This could lead to off-by-one errors where an additional execution is removed.

🔒 Security concerns

No

Code feedback:
relevant filesrc/eth/storage/inmemory/inmemory_temporary.rs
suggestion      

Consider adjusting the range in remove_executions_before to correctly handle the boundary conditions. The current implementation ..index - 1 might lead to off-by-one errors. You should change it to ..index to ensure that all executions up to, but not including, the specified index are removed. [important]

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

relevant filesrc/eth/block_miner.rs
suggestion      

Refactor the error handling in mine_external and mine_mixed methods to ensure that errors from read_executions are properly handled. Currently, the method proceeds even if read_executions fails, which could lead to runtime panics or logic errors. Consider adding error propagation or handling logic. [important]

relevant linelet txs = self.storage.temp.read_executions().await?;

relevant filesrc/eth/storage/rocks/rocks_temporary.rs
suggestion      

Ensure consistency in error handling for save_execution in RocksTemporaryStorage. The method should propagate errors from the underlying temporary storage's save_execution method instead of swallowing them. This change will help maintain robustness and make error handling more predictable. [important]

relevant lineself.temp.save_execution(tx).await?;

relevant filesrc/eth/storage/stratus_storage.rs
suggestion      

Optimize the save_block_to_perm method by removing redundant metric calculations when the feature 'metrics' is disabled. This can be achieved by enclosing the metric-related variables within the #[cfg(feature = "metrics")] attribute to ensure they are only compiled and executed when the feature is enabled. [medium]

relevant linelet (start, label_size_by_tx, label_size_by_gas, gas_used) = (

Copy link

github-actions bot commented May 8, 2024

PR Code Suggestions ✨

CategorySuggestions                                                                                                                                                       
Enhancement
Improve the handling of transaction types using conditional pattern matching.

Replace the pattern matching with a filter and map combination to handle transactions of
type External more efficiently and cleanly.

src/eth/block_miner.rs [60]

-let TransactionKind::External(external_tx, external_receipt) = tx.kind else {
+if let TransactionKind::External(external_tx, external_receipt) = &tx.kind {
+    // process external_tx and external_receipt
+}
 
Add error handling to the execution saving process to ensure data integrity.

Implement error handling for the save_execution method to ensure that changes are only
committed if all updates are successful.

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

-state.tx_executions.push(tx);
+if let Err(e) = state.tx_executions.try_push(tx) {
+    return Err(anyhow::Error::new(e));
+}
 
Enhance error handling in the block saving process.

Refactor the save_block_to_perm method to handle errors more gracefully and provide more
detailed error messages.

src/eth/storage/stratus_storage.rs [338]

-let result = self.perm.save_block(block).await;
+let result = self.perm.save_block(block).await.map_err(|e| {
+    tracing::error!("Failed to save block: {}", e);
+    e
+})?;
 
Maintainability
Add logging for better traceability of execution saving.

Add logging to trace the operations within the save_execution and read_executions methods
to aid in debugging and monitoring.

src/eth/storage/rocks/rocks_temporary.rs [44]

+tracing::debug!("Saving execution: {:?}", tx);
 self.temp.save_execution(tx).await?;
 
Performance
Reduce memory usage by avoiding unnecessary cloning of data.

Replace the direct cloning of transaction and execution with a reference where possible to
avoid unnecessary data duplication.

src/eth/executor.rs [301]

-let block = miner.mine_with_one_transaction(transaction.clone(), execution.clone()).await?;
+let block = miner.mine_with_one_transaction(&transaction, &execution).await?;
 

@dinhani-cw dinhani-cw merged commit cd71a1a into main May 8, 2024
26 checks passed
@dinhani-cw dinhani-cw deleted the temp-storage branch May 8, 2024 16:03
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