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

rm VMAdapter #4191

Merged
merged 1 commit into from
Sep 5, 2024
Merged

rm VMAdapter #4191

merged 1 commit into from
Sep 5, 2024

Conversation

nkysg
Copy link
Collaborator

@nkysg nkysg commented Sep 3, 2024

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Other information

Summary by CodeRabbit

  • New Features

    • Enhanced transaction processing with the introduction of a new PreprocessedTransaction enum for better type safety.
    • Added functions for improved error handling and transaction execution within the StarcoinVM.
  • Bug Fixes

    • Streamlined error management and transaction output generation, improving overall reliability.
  • Refactor

    • Simplified import structures and removed unnecessary dependencies, leading to improved maintainability.
  • Documentation

    • Updated public entity declarations to reflect new structures and functionalities.

Copy link

coderabbitai bot commented Sep 3, 2024

Walkthrough

The changes involve modifications to the vm_wrapper.rs, starcoin_vm.rs, and vm_adapter/mod.rs files within the VM runtime. Key alterations include the removal of the VMAdapter import, restructuring of error handling and transaction execution logic in StarcoinVM, and the introduction of a new enum PreprocessedTransaction in vm_adapter. These updates streamline dependencies and enhance the clarity of transaction processing.

Changes

Files Change Summary
vm/vm-runtime/src/parallel_executor/vm_wrapper.rs, vm/vm-runtime/src/starcoin_vm.rs, vm/vm-runtime/src/vm_adapter/mod.rs Removal of VMAdapter import in vm_wrapper.rs; restructuring of error handling and transaction execution in starcoin_vm.rs; introduction of PreprocessedTransaction enum and preprocess_transaction function in vm_adapter/mod.rs.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant StarcoinVM
    participant TransactionProcessor

    User->>StarcoinVM: Submit Transaction
    StarcoinVM->>TransactionProcessor: Process Transaction
    TransactionProcessor-->>StarcoinVM: Return Result
    StarcoinVM-->>User: Send Transaction Output
Loading

🐰 In the meadow, I hop with glee,
🐇 Changes abound, so fresh and free!
🥕 With clearer paths and fewer ties,
🌼 The code now dances, oh how it flies!
🐇 So let us cheer, with a joyful heart,
🎉 For brighter days, this is just the start!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 12e17fb and 8d4cea0.

Files selected for processing (3)
  • vm/vm-runtime/src/parallel_executor/vm_wrapper.rs (1 hunks)
  • vm/vm-runtime/src/starcoin_vm.rs (6 hunks)
  • vm/vm-runtime/src/vm_adapter/mod.rs (1 hunks)
Files skipped from review due to trivial changes (1)
  • vm/vm-runtime/src/parallel_executor/vm_wrapper.rs
Additional comments not posted (8)
vm/vm-runtime/src/vm_adapter/mod.rs (4)

6-8: LGTM!

The changes to the public use declarations are approved. Directly importing specific types from starcoin_vm_types instead of the entire adapter_common module suggests a more focused approach to managing dependencies.


10-14: LGTM!

The new enum PreprocessedTransaction is a great addition. It enhances type safety and clarity of the transaction processing logic by clearly encapsulating different transaction types.


16-26: LGTM!

The new function preprocess_transaction is a valuable addition. It improves the handling of different transaction types and streamlines the processing logic by clearly delineating how each transaction is treated.


Line range hint 1-26: Overall, the changes in this file are excellent!

The modifications reflect a more structured approach to transaction management within the module, enhancing both clarity and functionality. The removal of the adapter_common module from the public use declarations, the introduction of the PreprocessedTransaction enum, and the addition of the preprocess_transaction function all contribute to a cleaner and more focused design.

Great work on improving the transaction processing logic!

vm/vm-runtime/src/starcoin_vm.rs (4)

81-91: LGTM!

The code changes are approved.


93-102: LGTM!

The code changes are approved.


1491-1513: LGTM!

The code changes are approved.


1515-1526: LGTM!

The code changes are approved.

let sender = txn.sender().to_string();
let (vm_status, output) = self.execute_user_transaction(data_cache, *txn.clone());
// XXX FIXME YSG
// let gas_unit_price = transaction.gas_unit_price(); think about gas_used OutOfGas
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address the TODO comment.

The TODO comment indicates that the gas_used logic needs to be fixed to handle OutOfGas scenarios.

Do you want me to open a GitHub issue to track this task? I can also help brainstorm potential solutions if needed.


pub(crate) fn should_restart_execution(output: &TransactionOutput) -> bool {
// XXX FIXME YSG if GasSchedule.move UpgradeEvent
for event in output.events() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address the TODO comment.

The TODO comment indicates that the logic to determine if execution should be restarted needs to be fixed to handle GasSchedule changes.

Do you want me to open a GitHub issue to track this task? I can also help brainstorm potential solutions if needed.

Ok(match txn {
PreprocessedTransaction::UserTransaction(txn) => {
let sender = txn.sender().to_string();
let (vm_status, output) = self.execute_user_transaction(data_cache, *txn.clone());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address the TODO comment.

The TODO comment indicates that the sender string logic needs to be fixed.

Do you want me to open a GitHub issue to track this task? I can also help brainstorm potential solutions if needed.

}
PreprocessedTransaction::BlockMetadata(block_meta) => {
let (vm_status, output) =
match self.process_block_metadata(data_cache, block_meta.clone()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address the TODO comment.

The TODO comment indicates that the match logic needs to be fixed.

Do you want me to open a GitHub issue to track this task? I can also help brainstorm potential solutions if needed.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (2)
vm/vm-runtime/src/starcoin_vm.rs (2)

1491-1513: Overall structure looks good, but address the TODO comments.

The overall structure of the function, with matching on the transaction type and executing accordingly, looks good.

However, please address the following TODO comments:

  • Review the gas unit price logic to handle OutOfGas scenarios.
  • Fix the sender string logic.

1515-1526: Overall logic looks good, but address the TODO comment.

The overall logic of the function, with checking for specific events and their creator address to determine if execution should be restarted, looks good.

However, please address the following TODO comment:

  • Review and fix the logic for checking the GasSchedule and UpgradeEvent.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8d4cea0 and 9b757f7.

Files selected for processing (3)
  • vm/vm-runtime/src/parallel_executor/vm_wrapper.rs (1 hunks)
  • vm/vm-runtime/src/starcoin_vm.rs (6 hunks)
  • vm/vm-runtime/src/vm_adapter/mod.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • vm/vm-runtime/src/parallel_executor/vm_wrapper.rs
Additional comments not posted (5)
vm/vm-runtime/src/vm_adapter/mod.rs (3)

5-6: LGTM!

The changes to the public use declarations are approved. Removing the adapter_common module and directly importing specific types from starcoin_vm_types suggests a more focused approach to handling transaction types.


10-14: LGTM!

The new enum PreprocessedTransaction is approved. It enhances the type safety and clarity of the transaction processing logic by encapsulating the UserTransaction and BlockMetadata variants.


16-26: LGTM!

The new function preprocess_transaction is approved. It improves the handling of different transaction types and streamlines the processing logic by clearly delineating how each transaction is treated.

vm/vm-runtime/src/starcoin_vm.rs (2)

81-91: LGTM!

The code changes are approved.


93-102: LGTM!

The code changes are approved.

Copy link

github-actions bot commented Sep 4, 2024

Benchmark for d5c3c19

Click to view benchmark
Test Base PR %
accumulator_append 768.8±74.56µs 747.7±49.56µs -2.74%
block_apply/block_apply_10 367.5±4.44ms 367.6±2.85ms +0.03%
block_apply/block_apply_1000 39.1±1.07s 38.9±0.83s -0.51%
get_with_proof/db_store 46.1±3.16µs 46.8±3.20µs +1.52%
get_with_proof/mem_store 36.7±1.25µs 36.7±1.02µs 0.00%
put_and_commit/db_store/1 116.6±13.66µs 118.5±9.80µs +1.63%
put_and_commit/db_store/10 1084.1±108.90µs 1059.4±56.37µs -2.28%
put_and_commit/db_store/100 9.7±0.45ms 10.3±1.00ms +6.19%
put_and_commit/db_store/5 538.5±28.50µs 580.2±63.90µs +7.74%
put_and_commit/db_store/50 5.0±0.18ms 5.0±0.27ms 0.00%
put_and_commit/mem_store/1 72.8±7.27µs 72.1±6.52µs -0.96%
put_and_commit/mem_store/10 680.7±50.88µs 682.9±55.62µs +0.32%
put_and_commit/mem_store/100 6.6±0.66ms 6.6±0.31ms 0.00%
put_and_commit/mem_store/5 348.1±31.37µs 340.7±28.13µs -2.13%
put_and_commit/mem_store/50 3.3±0.27ms 3.3±0.14ms 0.00%
query_block/query_block_in(10)_times(100) 9.0±0.28ms 8.8±0.32ms -2.22%
query_block/query_block_in(10)_times(1000) 91.4±10.65ms 89.2±4.14ms -2.41%
query_block/query_block_in(10)_times(10000) 873.4±41.70ms 888.4±25.88ms +1.72%
query_block/query_block_in(1000)_times(100) 1712.9±28.81µs 1728.7±43.42µs +0.92%
query_block/query_block_in(1000)_times(1000) 17.8±0.83ms 17.0±0.57ms -4.49%
query_block/query_block_in(1000)_times(10000) 170.1±2.40ms 168.6±1.36ms -0.88%
storage_transaction 1108.6±454.72µs 1095.7±418.92µs -1.16%
vm/transaction_execution/1 422.4±27.17ms 402.2±3.13ms -4.78%
vm/transaction_execution/10 134.9±7.40ms 126.1±2.40ms -6.52%
vm/transaction_execution/20 125.5±9.37ms 119.8±4.47ms -4.54%
vm/transaction_execution/5 159.5±4.03ms 164.8±7.92ms +3.32%
vm/transaction_execution/50 140.1±8.38ms 134.0±1.97ms -4.35%

@nkysg nkysg merged commit 85564ab into dag-master Sep 5, 2024
4 of 5 checks passed
@nkysg nkysg deleted the remove_adapter branch September 5, 2024 00:21
@nkysg nkysg restored the remove_adapter branch September 5, 2024 00:21
@nkysg nkysg deleted the remove_adapter branch September 5, 2024 00:21
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