-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
WalkthroughThe 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
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
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 ofunused_imports
andclippy::single_component_path_imports
lints is understandable in this context, though it's generally good practice to minimize the use ofallow
attributes. Ensure that thebenchmark
module is correctly defined and available in the project.benchmark/src/lib.rs (1)
- 1-5: The introduction of the
benchmark
module within thebenchmark
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 thebenchmark
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 theODRA_MODULE
environment variable trigger a rebuild, which is crucial for maintaining consistency in the build artifacts. Ensure that theODRA_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 aresources
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 theODRA_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 thetarget
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 thefiles
parameter in thecodecov/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 ofpub use gas_report::*;
effectively exposes the functionalities of thegas_report
module. Ensure that thegas_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 thepath
parameter in theactions/upload-artifact
step correctly points to the location of the generatedgas_report.json
file.odra/src/lib.rs (1)
- 44-45: The addition of
DeployReport
andGasReport
types to the public API inodra/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 theGasReport
andDeployReport
types, which are essential for representing gas usage and deploy details. The implementation of theDisplay
trait forDeployReport
provides a human-readable representation of deploy reports, enhancing the usability of gas reports. The inclusion of tests to verify theDisplay
implementation is a good practice for ensuring the correctness of the code. Ensure that theGasReport
andDeployReport
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 thejust 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 theBenchmark
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 ofStructVariable
andSomeEvent
types supports the benchmarking scenarios and event emission testing. Ensure that theBenchmark
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 inodra-vm/src/odra_vm_host.rs
to include a new methodgas_report
returningGasReport
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 addGasReport
to the import statements and modify theprint_gas_report
function to return aGasReport
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 thegas_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
andevaluate-benchmark
targets in thejustfile
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
andGasReport
imports fromodra_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 withgas_report
of typeGasReport
in theCasperVm
struct is a significant change. It's essential to ensure that all instances wheregas_cost
was previously used are now correctly utilizinggas_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, wheregas_report.push(DeployReport::ContractCall {...})
is used, is a key part of enhancing the gas reporting mechanism. It's important to verify that thegas
,contract_address
, andcall_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 toGasReport
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, wheregas_report.push(DeployReport::WasmDeploy {...})
is used, is another critical part of the new gas reporting mechanism. It's important to ensure that thegas
andfile_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 theHostContext
trait is a significant change. It's crucial to ensure that all implementations of this trait are updated accordingly to return aGasReport
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
frombackend.last_call_gas_cost()
right before creating a newCallResult
object is a logical step. However, it's important to ensure that thelast_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.
pub fn gas_report(&self) -> GasReport { | ||
self.backend.borrow().gas_report().clone() |
There was a problem hiding this comment.
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.
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(); |
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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.
gas_report: Vec::new(), | |
gas_report: GasReport::new(), // Assuming GasReport has a new() constructor or similar initialization method. |
fn gas_report(&self) -> GasReport { | ||
println!("Gas report is unavailable for livenet"); | ||
todo!() |
There was a problem hiding this comment.
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.
Summary by CodeRabbit
New Features
.gitignore
to exclude benchmark reports.cargo-odra
.Documentation
Chores
Refactor
GasReport
objects instead of direct printing, improving integration and analysis capabilities.