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

Feature/0.9.0 rebased #360

Closed
wants to merge 2 commits into from
Closed

Conversation

kubaplas
Copy link
Contributor

@kubaplas kubaplas commented Feb 16, 2024

Summary by CodeRabbit

  • New Features

    • Introduced benchmarking workflows for gas costs, including setup, evaluation, and reporting.
    • Added test coverage workflow for pull requests with detailed coverage reports.
    • Expanded the .gitignore to exclude benchmark reports.
    • Implemented detailed instructions and tools for benchmarking wasm files using cargo-odra.
    • Enhanced gas reporting with new data structures and reporting mechanisms across various components.
  • Documentation

    • Provided comprehensive documentation on benchmarking setup and execution.
  • Chores

    • Updated justfile with commands for benchmarking and evaluating benchmarks.
  • Refactor

    • Modified gas reporting functionality to return structured GasReport objects instead of direct printing, improving integration and analysis capabilities.

Copy link
Contributor

coderabbitai bot commented Feb 16, 2024

Walkthrough

The project has seen an extensive update focusing on benchmarking, gas cost evaluation, and improved test coverage workflows. Notably, it introduces benchmarking capabilities, enhances gas reporting, and streamlines GitHub Actions workflows for testing, benchmark evaluation, and coverage reporting. It also adjusts serialization attributes for better compatibility across architectures and includes various new tools and configurations for efficient development and testing.

Changes

Files Summary
.codecov.yml Added entries to ignore specific directories in codecov configuration.
.github/workflows/... Introduced workflows for benchmarking, coverage calculation, and benchmark evaluation.
.gitignore Ignored benchmark/gas_report.json.
benchmark/... Added benchmarking tools, configurations, and documentation.
core/src/... (address.rs, call_def.rs, gas_report.rs, host.rs, lib.rs) Enhanced gas reporting and added conditional serialization/deserialization attributes.
justfile, odra-.../..., odra/src/lib.rs Updated with benchmarking commands, gas reporting methods, and expanded public API.

"In a burrow, deep and wide,
A rabbit worked with joy and pride.
🐾🌟
Codes and tests, all day long,
Making sure nothing went wrong.
With each commit, a leap, a bound,
In the world of code, magic found."
🚀🐇✨

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@kubaplas kubaplas closed this Feb 16, 2024
@kubaplas kubaplas deleted the feature/0.9.0-rebased branch February 16, 2024 08:46
Copy link
Contributor

@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.

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1c9f63d and a751ca8.
Files ignored due to path filters (5)
  • Cargo.toml is excluded by: !**/*.toml
  • benchmark/Cargo.toml is excluded by: !**/*.toml
  • benchmark/Odra.toml is excluded by: !**/*.toml
  • core/Cargo.toml is excluded by: !**/*.toml
  • odra-casper/livenet-env/Cargo.toml is excluded by: !**/*.toml
Files selected for processing (27)
  • .codecov.yml (1 hunks)
  • .github/workflows/benchmark.yml (1 hunks)
  • .github/workflows/coverage.yml (1 hunks)
  • .github/workflows/evaluate-benchmark.yml (1 hunks)
  • .github/workflows/test.yml (1 hunks)
  • .gitignore (1 hunks)
  • benchmark/.cargo/config.toml (1 hunks)
  • benchmark/README.md (1 hunks)
  • benchmark/bin/benchmark.rs (1 hunks)
  • benchmark/bin/build_contract.rs (1 hunks)
  • benchmark/bin/build_schema.rs (1 hunks)
  • benchmark/bin/evaluate_benchmark.rs (1 hunks)
  • benchmark/build.rs (1 hunks)
  • benchmark/rust-toolchain (1 hunks)
  • benchmark/src/benchmark.rs (1 hunks)
  • benchmark/src/lib.rs (1 hunks)
  • core/src/address.rs (1 hunks)
  • core/src/call_def.rs (1 hunks)
  • core/src/gas_report.rs (1 hunks)
  • core/src/host.rs (6 hunks)
  • core/src/lib.rs (2 hunks)
  • justfile (3 hunks)
  • odra-casper/livenet-env/src/livenet_host.rs (2 hunks)
  • odra-casper/test-vm/src/casper_host.rs (2 hunks)
  • odra-casper/test-vm/src/vm/casper_vm.rs (7 hunks)
  • odra-vm/src/odra_vm_host.rs (2 hunks)
  • odra/src/lib.rs (1 hunks)
Files skipped from review due to trivial changes (3)
  • .codecov.yml
  • .gitignore
  • benchmark/rust-toolchain
Additional comments: 30
benchmark/.cargo/config.toml (1)
  • 1-2: The configuration change to specify the target-dir as "../target" is a good practice for organizing build artifacts in Rust projects. This helps in keeping the project directory clean by centralizing the build outputs. Ensure that the relative path is correctly set based on the project's directory structure.
benchmark/bin/build_contract.rs (1)
  • 1-4: The use of #![no_std] and #![no_main] attributes indicates that this script is intended for a no-std environment, likely targeting a WebAssembly (WASM) build for smart contracts. The allowance of unused_imports and clippy::single_component_path_imports lints is understandable in this context, though it's generally good practice to minimize the use of allow attributes. Ensure that the benchmark module is correctly defined and available in the project.
benchmark/src/lib.rs (1)
  • 1-5: The introduction of the benchmark module within the benchmark library is a key addition for the benchmarking framework. The conditional attributes #![cfg_attr(not(test), no_std)] and #![cfg_attr(not(test), no_main)] are correctly used to ensure no-std compatibility outside of test environments. This setup is essential for creating a benchmarking environment that closely mirrors the target execution environment, such as a blockchain platform. Ensure that the benchmark module is properly implemented with the necessary benchmarking functionalities.
benchmark/build.rs (1)
  • 1-8: The build script dynamically configures the Rust compiler based on the ODRA_MODULE environment variable, which is a flexible approach to handle different modules during the build process. This script ensures that any changes to the ODRA_MODULE environment variable trigger a rebuild, which is crucial for maintaining consistency in the build artifacts. Ensure that the ODRA_MODULE environment variable is properly documented and set before building the project.
benchmark/README.md (1)
  • 1-31: The README file provides clear and concise instructions on how to use the benchmarking tools, including commands for building and testing wasm files. The recommendation to install cargo-odra first is helpful for setting up the necessary environment. The inclusion of specific commands for different backends (e.g., casper) is valuable for users targeting various blockchain platforms. Ensure that all commands and instructions are up-to-date and accurately reflect the current capabilities of the benchmarking framework.
benchmark/bin/build_schema.rs (1)
  • 1-23: The script for generating a schema file based on the ODRA_MODULE environment variable is a useful tool for creating documented contract interfaces. The use of conditional compilation to exclude this functionality for wasm32 targets is appropriate. The script ensures the existence of a resources directory before attempting to create the schema file, which is a good practice. However, it's crucial to handle potential errors gracefully and provide meaningful error messages to the user. Ensure that the ODRA_MODULE environment variable is well-documented and that the schema generation process is clearly explained to users.
.github/workflows/test.yml (1)
  • 1-41: The GitHub Actions workflow for running tests is well-structured and includes all necessary steps for setting up the environment, caching build artifacts, and executing tests. The choice of buildjet-8vcpu-ubuntu-2204 as the runner provides a balance between performance and cost. The caching strategy for the target directory is a good practice to speed up subsequent builds. Ensure that all paths and commands used in the workflow are accurate and that the workflow is triggered under the correct conditions (e.g., pull requests and pushes to specific branches).
.github/workflows/coverage.yml (1)
  • 1-38: The GitHub Actions workflow for calculating test coverage is comprehensive and follows best practices for CI/CD pipelines. The inclusion of codecov/codecov-action for uploading the coverage report is an excellent choice for integrating with Codecov, a widely used tool for tracking code coverage over time. The workflow's steps for environment setup, caching, and executing coverage tests are well-defined. Ensure that the files parameter in the codecov/codecov-action step correctly points to the location of the coverage reports generated by the tests.
core/src/lib.rs (1)
  • 18-24: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [21-46]

The addition of the gas_report module to the public API is a significant enhancement for the library, enabling users to access gas reporting functionality. This change is crucial for analyzing contract execution costs and optimizing smart contract performance. The use of pub use gas_report::*; effectively exposes the functionalities of the gas_report module. Ensure that the gas_report module is well-documented and that examples of its usage are provided to help users integrate gas reporting into their workflows.

.github/workflows/benchmark.yml (1)
  • 1-40: The GitHub Actions workflow for running benchmarks is well-designed and includes all necessary steps for executing benchmarks and uploading the results. The dynamic naming of the benchmark results file based on the branch name (${{ env.BENCHMARK_FILENAME }}) is a clever approach to organizing benchmark artifacts. This workflow is essential for continuously monitoring the gas costs of smart contracts and identifying performance regressions. Ensure that the path parameter in the actions/upload-artifact step correctly points to the location of the generated gas_report.json file.
odra/src/lib.rs (1)
  • 44-45: The addition of DeployReport and GasReport types to the public API in odra/src/lib.rs significantly enhances the library's functionality related to contract deployment and gas reporting. These types provide users with detailed insights into the gas costs associated with deploying and executing smart contracts, which is crucial for optimizing contract performance and managing costs. Ensure that these types are well-documented and that examples of their usage are provided to help users leverage the new functionalities.
benchmark/bin/benchmark.rs (1)
  • 1-51: The script for running benchmarks and generating a gas report in benchmark/bin/benchmark.rs is comprehensive and covers various benchmarking scenarios, including variable manipulation, struct handling, and event emission. The conversion of the gas report to JSON and dumping it into a file is a crucial step for analyzing and sharing benchmark results. Ensure that the benchmark scenarios accurately reflect the intended use cases and that the generated gas report provides meaningful insights into the performance of the smart contracts being tested.
core/src/gas_report.rs (1)
  • 1-65: The core/src/gas_report.rs file introduces the GasReport and DeployReport types, which are essential for representing gas usage and deploy details. The implementation of the Display trait for DeployReport provides a human-readable representation of deploy reports, enhancing the usability of gas reports. The inclusion of tests to verify the Display implementation is a good practice for ensuring the correctness of the code. Ensure that the GasReport and DeployReport types are well-documented and that their usage is clearly explained to users.
.github/workflows/evaluate-benchmark.yml (1)
  • 1-63: The GitHub Actions workflow for evaluating benchmarks in .github/workflows/evaluate-benchmark.yml is well-designed and includes all necessary steps for setting up the environment, downloading base benchmark reports, and evaluating benchmark differences. The conditional creation of a comment and uploading of a full report artifact based on the evaluation results are excellent features for providing feedback on benchmark performance changes. Ensure that the just evaluate-benchmark command accurately compares the current benchmark results with the base benchmark and that the evaluation criteria are clearly defined and documented.
benchmark/src/benchmark.rs (1)
  • 1-93: The benchmark/src/benchmark.rs file defines the Benchmark contract, which is designed to benchmark various functionalities of the Odra framework. The contract demonstrates a wide range of operations, including variable manipulation, struct handling, and submodule interaction, providing a comprehensive benchmarking suite. The definition of StructVariable and SomeEvent types supports the benchmarking scenarios and event emission testing. Ensure that the Benchmark contract and its associated types are well-documented and that the benchmarking scenarios accurately reflect real-world use cases for smart contracts.
odra-vm/src/odra_vm_host.rs (1)
  • 103-115: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [11-112]

The update to the OdraVmHost struct in odra-vm/src/odra_vm_host.rs to include a new method gas_report returning GasReport is a significant enhancement to the functionality related to gas reporting. This change allows for more detailed analysis of contract execution costs, which is crucial for optimizing smart contract performance. The comment indicating that there is no gas to report in the OdraVM context is informative, but ensure that the method's implementation aligns with the intended behavior and that any future changes to the OdraVM's gas model are reflected in this method.

odra-casper/test-vm/src/casper_host.rs (1)
  • 109-116: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-113]

The changes in odra-casper/test-vm/src/casper_host.rs to add GasReport to the import statements and modify the print_gas_report function to return a GasReport enhance the functionality related to gas reporting in the Casper test virtual machine. This update allows for a more structured and detailed analysis of gas usage, which is essential for optimizing smart contract performance on the Casper platform. Ensure that the gas_report method is correctly implemented and that it provides meaningful insights into gas usage for contract executions.

core/src/call_def.rs (1)
  • 6-9: The conditional serialization and deserialization attributes for non-WASM target architectures are correctly applied to the CallDef struct. This ensures that serialization capabilities are available in environments that require them, while excluding them from WASM targets to optimize performance and binary size.
justfile (3)
  • 20-20: The addition of formatting commands for the benchmark directory ensures consistent code quality and style, aligning with the project's emphasis on benchmarking.
  • 29-30: The inclusion of linting and checking commands for the benchmark directory is a positive step towards maintaining high code standards within this critical area of the project.
  • 112-116: The new benchmark and evaluate-benchmark targets in the justfile provide clear and accessible ways to run and evaluate benchmarks, supporting the project's performance optimization efforts.
benchmark/bin/evaluate_benchmark.rs (1)
  • 1-214: The evaluate_benchmark.rs script is well-implemented, providing a comprehensive tool for evaluating benchmarks by comparing current and base gas reports. It correctly handles errors, generates detailed reports on changes and errors, and writes the results to files for easy access. This tool is a valuable addition to the project's benchmarking capabilities.
core/src/address.rs (1)
  • 12-15: The conditional serialization and deserialization attributes for non-WASM target architectures are correctly applied to the Address enum. This ensures that serialization capabilities are available in environments that require them, while excluding them from WASM targets to optimize performance and binary size.
odra-casper/test-vm/src/vm/casper_vm.rs (5)
  • 13-13: The addition of DeployReport and GasReport imports from odra_core is crucial for the new gas reporting functionality. This change aligns with the PR objectives to enhance gas reporting mechanisms.
  • 46-46: The replacement of the gas_cost vector with gas_report of type GasReport in the CasperVm struct is a significant change. It's essential to ensure that all instances where gas_cost was previously used are now correctly utilizing gas_report. This change should improve the granularity and utility of gas reporting within the VM.
  • 191-195: The update to gas cost reporting in the call_contract method, where gas_report.push(DeployReport::ContractCall {...}) is used, is a key part of enhancing the gas reporting mechanism. It's important to verify that the gas, contract_address, and call_def fields are correctly populated and that this new reporting format provides the intended insights into gas usage for contract calls.
  • 276-277: The modification of the gas_report method to return a reference to GasReport is a straightforward change that aligns with the new gas reporting structure. This method will be useful for external callers to access the gas report without modifying it.
  • 419-422: The update to gas cost reporting in the deploy_contract method, where gas_report.push(DeployReport::WasmDeploy {...}) is used, is another critical part of the new gas reporting mechanism. It's important to ensure that the gas and file_name fields are correctly populated and that this reporting format provides the intended insights into gas usage for contract deployments.
core/src/host.rs (2)
  • 166-167: The introduction of the gas_report method in the HostContext trait is a significant change. It's crucial to ensure that all implementations of this trait are updated accordingly to return a GasReport object. This change enhances the modularity and usability of gas reporting by allowing the gas report to be programmatically accessed and manipulated, rather than just printed to the console.
  • 291-292: The assignment of last_call_gas_cost from backend.last_call_gas_cost() right before creating a new CallResult object is a logical step. However, it's important to ensure that the last_call_gas_cost accurately reflects the gas cost of the last contract call, especially in concurrent or complex contract execution scenarios where gas costs might be updated frequently.

Comment on lines +314 to +315
pub fn gas_report(&self) -> GasReport {
self.backend.borrow().gas_report().clone()
Copy link
Contributor

Choose a reason for hiding this comment

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

The gas_report method in HostEnv directly calls self.backend.borrow().gas_report().clone(), which is a straightforward way to access the gas report from the host environment. Cloning the GasReport object ensures that the original report in the backend remains unchanged. However, consider if cloning is always necessary, as it could impact performance in scenarios with large gas reports. If the GasReport is immutable or if the report is only read, directly returning a reference might be more efficient.

Comment on lines +588 to +595
ctx.expect_gas_report().returning(GasReport::new).times(1);
ctx.expect_set_gas().returning(|_| ()).times(1);

let env = HostEnv::new(Rc::new(RefCell::new(ctx)));

assert_eq!(env.caller(), Address::Account(AccountHash::new([2; 32])));
// should call the `HostContext`
env.print_gas_report();
env.gas_report();
Copy link
Contributor

Choose a reason for hiding this comment

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

The test test_host_env demonstrates the expected behavior of the gas_report and set_gas methods in a controlled environment. It's good practice to include such tests to verify the functionality of new or modified methods. However, ensure comprehensive test coverage, including edge cases and failure scenarios, to fully validate the behavior of these methods under various conditions.

Would you like me to help generate additional test cases covering edge scenarios for the gas_report and set_gas methods?

@@ -401,7 +394,7 @@ impl CasperVm {
error: None,
attached_value: U512::zero(),
gas_used: BTreeMap::new(),
gas_cost: Vec::new(),
gas_report: Vec::new(),
Copy link
Contributor

Choose a reason for hiding this comment

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

The initialization of gas_report with Vec::new() in the new_instance method of the CasperVm struct seems to be incorrect based on the context of the changes. Given that gas_report is now of type GasReport and not a Vec, this line should likely initialize gas_report with GasReport::new() or an equivalent constructor, assuming GasReport is not directly a Vec type. This might be a critical oversight that could lead to compilation errors or runtime issues.

- gas_report: Vec::new(),
+ gas_report: GasReport::new(), // Assuming GasReport has a new() constructor or similar initialization method.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
gas_report: Vec::new(),
gas_report: GasReport::new(), // Assuming GasReport has a new() constructor or similar initialization method.

Comment on lines +156 to +158
fn gas_report(&self) -> GasReport {
println!("Gas report is unavailable for livenet");
todo!()
Copy link
Contributor

Choose a reason for hiding this comment

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

The new gas_report method in LivenetHost currently uses todo!(), indicating unfinished work. It's crucial to complete the implementation of this method or provide a clear plan for its completion to avoid runtime panics and ensure the PR meets its objectives regarding enhanced gas reporting capabilities.

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