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: vip challenge #76

Closed
wants to merge 19 commits into from
Closed

feat: vip challenge #76

wants to merge 19 commits into from

Conversation

djm07073
Copy link
Contributor

@djm07073 djm07073 commented Jun 26, 2024

  • execute_challenge: execute a challenge regarding the reward result, only be executed by governance.
  • Added a challenge period to prevent users and operators from claiming rewards during the challenge period.
  • Governance can update the challenge period.

Summary by CodeRabbit

  • New Features

    • Added support for challenge-related structures and functionality in the VIP module.
    • Introduced new constants and default periods for challenges.
    • Added events and view functions for swap simulations and spot price calculations in the StableSwap module.
  • Bug Fixes

    • Corrected typos in comments and assertion statements for various modules to improve readability and consistency.
  • Refactor

    • Simplified logic for initializing variables in the BuiltPackage implementation.
    • Improved formatting and alignment of code blocks in multiple modules for better readability.
  • Dependencies

    • Updated clru dependency version in Cargo.toml.
  • Chores

    • Adjusted movefmt command in Makefile for more specific file pattern formatting.
    • Updated Rust toolchain setup in .github/workflows/lint.yml.
  • Tests

    • Adjusted memory allocation values for VM instance initialization in test files.

@djm07073 djm07073 requested a review from a team as a code owner June 26, 2024 08:18
Copy link

coderabbitai bot commented Jun 26, 2024

Walkthrough

Recent changes encompass updates across multiple modules and repositories, focusing on API enhancements, refactoring, and bug fixes. Notable updates include modifications to vip.move for challenge functionalities, vip_weight_vote.move for testing constants, and structural updates on assertion formatting in several Move files. There were also improvements in Rust code readability and efficiency, such as caching logic, and minor corrections in headers and config files.

Changes

File(s) Change Summary
precompile/modules/.../vip.move, precompile/modules/.../vip_weight_vote.move Added constants, structs, and functions for challenge management and testing-related constants.
.github/workflows/lint.yml, Cargo.toml, Makefile Improved configurations for toolchains and dependencies, including more specific patterns and version updates.
api/bindings_compiler.h, libcompiler/bindings_compiler.h, api/bindings.h Corrected comments in #endif directives.
crates/compiler/src/built_package.rs Simplified initialization logic using unwrap_or_default.
crates/e2e-move-tests/src/tests/args.rs Updated usage of std::u64::MAX to u64::MAX.
crates/vm/src/move_vm.rs Enforced minimum cache capacities for modules and scripts in MoveVM::new().
lib_test.go Adjusted memory initialization parameters for VM instances.
precompile/modules/.../account.move Refactored and improved formatting of assert statements across various account-related functions.
precompile/modules/.../coin.move, precompile/modules/.../managed_coin.move Reformatted assert statements and function parameters for better readability.
precompile/modules/initia_stdlib/sources/stableswap.move Introduced new events and simulation functions, along with swap fee calculations.
precompile/modules/initia_stdlib/sources/staking.move Minor comment update for clarity.

Poem

In code's vast garden, changes bloom anew,
Constants and structs in vip.move grew,
Refactoring lines, assertions align,
Cache and constraints keep modules in line.
Move fast, debug wise, for the system to rise,
A rabbit's delight in development skies. 🐇✨

Tip

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


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

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.
  • 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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cbbcc55 and 2d3481d.

Files ignored due to path filters (2)
  • api/libcompiler.dylib is excluded by !**/*.dylib
  • api/libmovevm.dylib is excluded by !**/*.dylib
Files selected for processing (1)
  • precompile/modules/initia_stdlib/sources/vip/vip.move (54 hunks)
Additional comments not posted (7)
precompile/modules/initia_stdlib/sources/vip/vip.move (7)

54-56: Constants for Error Codes

The constants EINVALID_CLAIMABLE_PERIOD, EINVALID_CHALLENGE_PERIOD, and EINVALID_CHALLENGE_STAGE are well-named, following the naming convention for error codes in the module. They provide clear indications of their purpose.


71-71: Default Challenge Period Defined

The constant DEFAULT_CHALLENGE_PERIOD is set to 10080, which corresponds to 7 days (assuming the unit is minutes). This is a typical duration for a challenge or review period in governance systems. The comment is clear and helpful.


Line range hint 74-103: Review of ModuleStore Struct

The ModuleStore struct centralizes important configuration and state information. It includes fields for stages, vesting periods, ratios, and tables for data storage. The use of table::Table for challenges and stage_data suggests an efficient lookup and storage mechanism for potentially large datasets. The struct is comprehensive and seems well-structured for its intended use in managing VIP operations.


104-106: Agent Data Struct Review

The AgentData struct holds an agent address and an api_uri, which are essential for operations that involve external data interactions. The inclusion of the api_uri is particularly notable as it allows dynamic interaction endpoints, which can be crucial for decentralized applications.


144-153: Executed Challenge Data Structure

The ExecutedChallenge struct is well-designed to encapsulate all necessary details about a challenge, including identifiers, descriptive fields (title, summary), and execution metadata (api_uri, new_agent, merkle_root, execution_time). This struct will be critical for tracking and auditing challenge executions.


928-1008: Function execute_challenge Review

This function handles the execution of a challenge, ensuring that only authorized entities can trigger it (check_chain_permission). It performs several checks, such as stage progression and challenge timing, before updating the system state. The function is complex but appears to be well-structured with clear error handling and state management. However, detailed unit tests would be crucial to ensure its robustness and security.


238-248: Event ExecuteChallengeEvent Review

The ExecuteChallengeEvent is comprehensive, including all relevant details about the executed challenge. This is crucial for transparency and auditability in the system. The event captures both identifiers and descriptive information, ensuring that external systems or interfaces can effectively utilize this data.

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2d3481d and 90cb0bc.

Files selected for processing (1)
  • precompile/modules/initia_stdlib/sources/vip/vip.move (55 hunks)
Additional comments not posted (3)
precompile/modules/initia_stdlib/sources/vip/vip.move (3)

54-56: Constants for Error Codes and Default Values

The addition of error codes for claimable period, challenge period, and challenge stage is appropriate to handle specific error scenarios. The DEFAULT_CHALLENGE_PERIOD is set to 10080, which corresponds to 7 days (in minutes), aligning with the typical weekly cycle used in many systems. This is a sensible default for a challenge period.

Also applies to: 71-71


Line range hint 74-102: Struct Modifications and Additions

  1. ModuleStore: The addition of challenge_period and challenges table supports the new challenge functionality. It's crucial to ensure that these fields are appropriately utilized in the logic to manage challenges and periods effectively.
  2. AgentData: This new struct with agent and api_uri fields seems to be designed for managing agent-specific data, which is a good practice for separating concerns.
  3. Snapshot: Addition of create_time and upsert_time helps in tracking the lifecycle of snapshots, which is beneficial for audit and tracking purposes.
  4. ExecutedChallenge: This new struct captures detailed information about executed challenges, which is essential for maintaining a transparent and traceable system for challenge management.

Overall, the struct modifications and additions seem well-thought-out and align with the objectives of enhancing the challenge mechanism.

Also applies to: 104-106, 121-123, 144-153


928-1008: Function execute_challenge Review

This function is central to the new challenge mechanism. It checks permissions, validates stages, and handles the creation and updating of challenge-related data. A few points to consider:

  • The permission check using check_chain_user_permission ensures that only authorized users can execute challenges, which is crucial for security.
  • The assertion that the current stage must be greater than the challenge stage (module_store.stage > challenge_stage) is a good safeguard to prevent retrospective challenges which could disrupt the system state.
  • The use of make_challenge_table_key for creating a unique key for each challenge ensures that challenges are stored uniquely and can be retrieved efficiently.
  • Updating the agentData and snapshot upon successful challenge execution is a critical operation and seems to be handled correctly.

This function is well-implemented with appropriate checks and balances. It is a good example of solid smart contract function design.

@@ -337,7 +391,7 @@ module initia_std::vip {
fun check_agent_permission(agent: &signer) acquires ModuleStore {
let module_store = borrow_global<ModuleStore>(@initia_std);
assert!(
signer::address_of(agent) == module_store.agent,
signer::address_of(agent) == module_store.agentData.agent,
Copy link

Choose a reason for hiding this comment

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

Check Agent Permission

The function check_agent_permission uses a direct comparison of the agent's address with the stored address in ModuleStore. This is a straightforward and effective way to ensure that the action is being performed by the authorized agent. However, consider adding more detailed error messages or logging to provide clearer feedback in case of unauthorized access attempts.

- error::permission_denied(EUNAUTHORIZED)
+ error::permission_denied(EUNAUTHORIZED, "Unauthorized access attempt by non-agent")

Committable suggestion was skipped due to low confidence.

@djm07073 djm07073 force-pushed the feat/vip-challenge branch from 06bf04e to b0d5c07 Compare June 26, 2024 09:45
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 90cb0bc and b0d5c07.

Files selected for processing (1)
  • precompile/modules/initia_stdlib/sources/vip/vip.move (55 hunks)
Additional comments not posted (3)
precompile/modules/initia_stdlib/sources/vip/vip.move (3)

54-56: Constants Review: Error Codes and Default Settings

The constants EINVALID_CLAIMABLE_PERIOD, EINVALID_CHALLENGE_PERIOD, and EINVALID_CHALLENGE_STAGE are well-named, clearly indicating their purpose related to error handling in challenge periods. The DEFAULT_CHALLENGE_PERIOD is set to 10080, which presumably represents minutes in a week, aligning with the typical duration for a challenge period. Ensure these constants are used consistently across the codebase.

Also applies to: 71-71


Line range hint 74-102: Structs Review: Modifications and Additions

  1. ModuleStore has been significantly modified to include challenge_period and a new table for challenges. This aligns with the new functionality to handle challenges.
  2. AgentData is a new struct that includes agent and api_uri, which seems to be used for identifying and interacting with external agents.
  3. ExecutedChallenge is another new struct that captures details about executed challenges, including metadata like title and summary, which enhances traceability and auditability of challenges.

Ensure that the new fields in these structs are properly initialized wherever these structs are instantiated or modified.

Also applies to: 104-106, 121-123, 144-153


238-248: Event Review: ExecuteChallengeEvent

The ExecuteChallengeEvent logs key data points related to the execution of a challenge, including bridge_id, stage, title, summary, api_uri, new_agent, merkle_root, and execution_time. This comprehensive data capture is excellent for auditability and tracking. Ensure that this event is emitted at the correct places in the logic flow to accurately reflect the operations performed.
[APROVED]

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 and nitpick comments (1)
precompile/modules/initia_stdlib/sources/vip/weight_vote.move (1)

Line range hint 1258-1268: Use of hardcoded test data in functional code.

The function init_test uses hardcoded test data (DEFAULT_VIP_L2_CONTRACT_FOR_TEST) directly within its body. This is generally not recommended as it reduces the flexibility and reusability of the test function. Consider parameterizing this data or retrieving it from a configuration file or environment variable to enhance the test's adaptability and maintainability.

- string::utf8(DEFAULT_VIP_L2_CONTRACT_FOR_TEST),
+ string::utf8(test_contract_data),

And modify the function signature to:

- fun init_test(chain: &signer): coin::MintCapability {
+ fun init_test(chain: &signer, test_contract_data: vector<u8>): coin::MintCapability {
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b0d5c07 and 240a3ed.

Files selected for processing (2)
  • precompile/modules/initia_stdlib/sources/vip/vip.move (77 hunks)
  • precompile/modules/initia_stdlib/sources/vip/weight_vote.move (3 hunks)
Files not summarized due to errors (1)
  • precompile/modules/initia_stdlib/sources/vip/vip.move: Error: Message exceeds token limit
Additional comments not posted (7)
precompile/modules/initia_stdlib/sources/vip/weight_vote.move (1)

1226-1227: Add documentation for the constant.

The constant DEFAULT_VIP_L2_CONTRACT_FOR_TEST is added for testing purposes, but there is no accompanying documentation to explain its purpose or usage context. This can make maintenance difficult, especially for new developers or external contributors.

precompile/modules/initia_stdlib/sources/vip/vip.move (6)

54-56: New Error Constants Defined Appropriately

The newly added error constants (EINVALID_CLAIMABLE_PERIOD, EINVALID_CHALLENGE_PERIOD, EINVALID_CHALLENGE_STAGE) are well-defined and seem to cover specific scenarios related to challenge periods and stages. Ensure these constants are used appropriately in error handling throughout the module.


71-71: Default Challenge Period Set

The constant DEFAULT_CHALLENGE_PERIOD is set to 10080, which corresponds to 7 days (in minutes). This aligns with typical governance challenge periods, providing a reasonable default value.


Line range hint 80-106: Struct ModuleStore and AgentData Enhancements

The addition of challenge_period and agentData to the ModuleStore struct is crucial for the new challenge functionalities. The AgentData struct, which includes agent and api_uri, is well-defined. Ensure the api_uri is validated where it is used to prevent any potential security issues from malformed URLs.


101-101: New Table for Challenges

The introduction of a challenges table to store ExecutedChallenge instances is a key part of managing challenge data. The struct AgentData is appropriately designed to handle agent-specific data, which is critical for operations that require permissions.

Also applies to: 104-106


145-154: Struct ExecutedChallenge Adequately Defined

The ExecutedChallenge struct captures all necessary details about a challenge, such as bridge_id, stage, title, summary, api_uri, new_agent, merkle_root, and execution_time. This comprehensive data collection is essential for tracking and auditing challenges.


1614-1621: Function to Update Challenge Period

The update_challenge_period function allows governance to update the challenge period. It correctly checks chain permissions before proceeding with the update. This function is vital for adaptability in governance processes.

ALPAC-4 and others added 11 commits June 28, 2024 17:19
* feat: minitswap in house arb

* update precompile

* update dependency

* fix test

* enforce minium cache capacity

* fix clippy

* fix clippy

* feat: add ibc_op_init_metadata on arb batch response

* fix: fix `get_fully_recovered_pool_amounts` and use pool size

* add some break condition

* update binary

---------

Co-authored-by: beer-1 <147697694+beer-1@users.noreply.github.com>
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 240a3ed and 3aefa83.

Files ignored due to path filters (6)
  • api/libcompiler.aarch64.so is excluded by !**/*.so
  • api/libcompiler.dylib is excluded by !**/*.dylib
  • api/libcompiler.x86_64.so is excluded by !**/*.so
  • api/libmovevm.aarch64.so is excluded by !**/*.so
  • api/libmovevm.dylib is excluded by !**/*.dylib
  • api/libmovevm.x86_64.so is excluded by !**/*.so
Files selected for processing (17)
  • .github/workflows/lint.yml (1 hunks)
  • Cargo.toml (1 hunks)
  • Makefile (1 hunks)
  • api/bindings_compiler.h (1 hunks)
  • crates/compiler/src/built_package.rs (1 hunks)
  • crates/e2e-move-tests/src/tests/args.rs (2 hunks)
  • crates/vm/src/move_vm.rs (1 hunks)
  • lib_test.go (1 hunks)
  • libcompiler/bindings_compiler.h (1 hunks)
  • precompile/modules/initia_stdlib/sources/account.move (7 hunks)
  • precompile/modules/initia_stdlib/sources/coin.move (2 hunks)
  • precompile/modules/initia_stdlib/sources/managed_coin.move (2 hunks)
  • precompile/modules/initia_stdlib/sources/stableswap.move (12 hunks)
  • precompile/modules/initia_stdlib/sources/staking.move (1 hunks)
  • precompile/modules/minitia_stdlib/sources/account.move (7 hunks)
  • precompile/modules/minitia_stdlib/sources/coin.move (2 hunks)
  • precompile/modules/minitia_stdlib/sources/managed_coin.move (2 hunks)
Files skipped from review due to trivial changes (12)
  • .github/workflows/lint.yml
  • Cargo.toml
  • Makefile
  • api/bindings_compiler.h
  • crates/compiler/src/built_package.rs
  • crates/e2e-move-tests/src/tests/args.rs
  • libcompiler/bindings_compiler.h
  • precompile/modules/initia_stdlib/sources/account.move
  • precompile/modules/initia_stdlib/sources/coin.move
  • precompile/modules/initia_stdlib/sources/managed_coin.move
  • precompile/modules/initia_stdlib/sources/staking.move
  • precompile/modules/minitia_stdlib/sources/managed_coin.move
Additional context used
golangci-lint
lib_test.go

17-17: could not import github.com/initia-labs/movevm/api (-: # github.com/initia-labs/movevm/api
api/callbacks.go:7:10: fatal error: bindings.h: No such file or directory
7 | #include "bindings.h"
| ^~~~~~~~~~~~
compilation terminated.)

(typecheck)

Additional comments not posted (18)
precompile/modules/minitia_stdlib/sources/coin.move (2)

61-64: LGTM!

The formatting changes improve readability without altering the logic.


79-82: LGTM!

The formatting changes improve readability without altering the logic.

precompile/modules/minitia_stdlib/sources/account.move (8)

35-38: LGTM!

The formatting changes improve readability without altering the logic.


46-58: LGTM!

The formatting changes improve readability without altering the logic.


Line range hint 70-89: LGTM!

The formatting changes improve readability without altering the logic.


117-120: LGTM!

The formatting changes improve readability without altering the logic.


128-131: LGTM!

The formatting changes improve readability without altering the logic.


139-142: LGTM!

The formatting changes improve readability without altering the logic.


150-153: LGTM!

The formatting changes improve readability without altering the logic.


161-164: LGTM!

The formatting changes improve readability without altering the logic.

lib_test.go (1)

58-58: Verify the appropriateness of the new memory allocation values.

The memory allocation for the VM has been increased significantly. Ensure that the new values are appropriate for the expected workload.

crates/vm/src/move_vm.rs (2)

88-88: LGTM!

The change enforces a default cache capacity for modules and scripts, ensuring that the MoveVM is initialized with a minimum cache size.


93-101: LGTM!

The change ensures that the cache capacities for modules and scripts are not below the specified threshold, providing a safeguard against insufficient cache sizes.

precompile/modules/initia_stdlib/sources/stableswap.move (5)

75-85: LGTM!

The addition of UpdateSwapFeeEvent and UpdateAnnEvent allows tracking updates to swap fees and ANN values, enhancing the observability and auditability of changes to these parameters.


174-191: LGTM!

The addition of get_swap_simulation_given_out provides a way to simulate swaps based on the desired output amount, which can be useful for users who want to determine the required input amount to obtain a specific output.


268-294: LGTM!

The addition of spot_price provides a way to determine the current price of a pool based on a fixed swap amount, which can be useful for price discovery and analysis.


Line range hint 1036-1107: LGTM!

The modifications to swap_simulation ensure that the swap simulation accurately reflects the impact of fees and adjusts the offer amount accordingly, improving the accuracy of the simulation results.


Line range hint 1174-1238: LGTM!

The inclusion of the swap operation in the end_to_end test ensures that the swap functionality is tested in a comprehensive manner, covering the entire pool lifecycle.

@djm07073 djm07073 closed this Jul 3, 2024
@djm07073 djm07073 deleted the feat/vip-challenge branch July 3, 2024 09:38
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3aefa83 and c38f333.

Files selected for processing (1)
  • api/bindings.h (1 hunks)
Files skipped from review due to trivial changes (1)
  • api/bindings.h

@djm07073 djm07073 restored the feat/vip-challenge branch July 3, 2024 09:39
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