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

✨[API-2348] Make Contracts Upgradeable #81

Merged
merged 14 commits into from
Jan 4, 2024

Conversation

NotJeremyLiu
Copy link
Member

@NotJeremyLiu NotJeremyLiu commented Jan 3, 2024

This PR

Makes the contracts upgradable by:

  1. Adding an ADMIN_ADDRESS field in the deploy script configs
  2. Changing the deploy script to include an admin address when instantiating contracts
  3. Adding the cw2 contract version setting into the instantiate functions of the contracts, which is required to migrate contracts.
  4. Adding placeholder migrate functions in all the contracts (upon migration, we edit this function in the newly created contract)

Notes

  • Switched workspace versioning to 0.3.0, which will be the version start of our now upgradable contracts (we now care about versions/names since required to migrate)
  • Lint/small refactor fixes in the python script were also made

Summary by CodeRabbit

  • New Features

    • Implemented contract migration capabilities across various modules.
    • Introduced contract version tracking for improved lifecycle management.
  • Refactor

    • Updated deployment scripts for enhanced control flow and error handling.
  • Documentation

    • Standardized the use of contract constants for naming and versioning.

Copy link

coderabbitai bot commented Jan 3, 2024

Walkthrough

The changes across the contracts involve introducing upgradeability to the CosmWasm contracts. This is achieved by adding a migrate function and setting contract version constants during instantiation. These modifications ensure that contracts can be updated to handle failures without requiring governance proposals, addressing a critical need for operational resilience.

Changes

File Path Change Summary
.../ibc/ibc-hooks/src/contract.rs
.../ibc/neutron-transfer/src/contract.rs
.../swap/astroport/src/contract.rs
.../swap/lido-satellite/src/contract.rs
.../swap/osmosis-poolmanager/src/contract.rs
.../entry-point/src/contract.rs
Added migrate function and CONTRACT_NAME, CONTRACT_VERSION constants; set contract version during instantiation.
packages/skip/src/entry_point.rs
packages/skip/src/ibc.rs
packages/skip/src/swap.rs
Introduced MigrateMsg struct for migration parameters.
scripts/deploy.py Modified control flow, error messages, contract and wallet address creation, transaction sealing, and contract instantiation.

Assessment against linked issues

Objective Addressed Explanation
Make CosmWasm Contracts Upgradeable (API-2348) The addition of migrate functions across multiple contracts fulfills the requirement for upgradeability.

Poem

In the blockchain's burrow, deep and wide,
A rabbit worked with code as its guide.
Upgradeable contracts, now in the flow,
A hop, skip, and a jump; they're ready to go! 🚀🐰

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 with CodeRabbit Bot (@coderabbitai)

  • You can directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • You can tag CodeRabbit on specific lines of code or entire files in the PR by tagging @coderabbitai in a comment. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • You can tag @coderabbitai in a PR comment and ask questions about the PR and the codebase. 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.
    • @coderabbitai read the files in the src/scheduler package and generate 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.

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.

@NotJeremyLiu NotJeremyLiu changed the title Make Contracts Upgradeable ✨ Make Contracts Upgradeable Jan 3, 2024
@NotJeremyLiu NotJeremyLiu changed the title ✨ Make Contracts Upgradeable ✨[API-2348] Make Contracts Upgradeable Jan 3, 2024
@NotJeremyLiu NotJeremyLiu marked this pull request as ready for review January 3, 2024 23:19
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.

Review Status

Actionable comments generated: 10

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ec75ccc and 3b110d7.
Files ignored due to filter (12)
  • Cargo.lock
  • Cargo.toml
  • contracts/adapters/ibc/ibc-hooks/Cargo.toml
  • contracts/adapters/ibc/neutron-transfer/Cargo.toml
  • contracts/adapters/swap/astroport/Cargo.toml
  • contracts/adapters/swap/lido-satellite/Cargo.toml
  • contracts/adapters/swap/osmosis-poolmanager/Cargo.toml
  • contracts/entry-point/Cargo.toml
  • schema/skip-api-entry-point.json
  • scripts/configs/neutron.toml
  • scripts/configs/osmosis.toml
  • scripts/configs/terra.toml
Files selected for processing (10)
  • contracts/adapters/ibc/ibc-hooks/src/contract.rs (1 hunks)
  • contracts/adapters/ibc/neutron-transfer/src/contract.rs (1 hunks)
  • contracts/adapters/swap/astroport/src/contract.rs (1 hunks)
  • contracts/adapters/swap/lido-satellite/src/contract.rs (1 hunks)
  • contracts/adapters/swap/osmosis-poolmanager/src/contract.rs (2 hunks)
  • contracts/entry-point/src/contract.rs (1 hunks)
  • packages/skip/src/entry_point.rs (1 hunks)
  • packages/skip/src/ibc.rs (1 hunks)
  • packages/skip/src/swap.rs (1 hunks)
  • scripts/deploy.py (14 hunks)
Additional comments: 15
contracts/entry-point/src/contract.rs (2)
  • 31-32: Using environment variables to set CONTRACT_NAME and CONTRACT_VERSION is a standard practice and is correctly implemented here.

  • 42-42: The invocation of set_contract_version within the instantiate function is correct and necessary for contract versioning.

contracts/adapters/swap/lido-satellite/src/contract.rs (2)
  • 37-38: Using environment variables to set CONTRACT_NAME and CONTRACT_VERSION is a standard practice and is correctly implemented here.

  • 48-48: The invocation of set_contract_version within the instantiate function is correct and necessary for contract versioning.

contracts/adapters/ibc/neutron-transfer/src/contract.rs (1)
  • 34-47: Setting the contract version using CONTRACT_NAME and CONTRACT_VERSION derived from environment variables is a good practice for maintaining contract versioning. This change is well-implemented.
contracts/adapters/ibc/ibc-hooks/src/contract.rs (1)
  • 38-51: Setting the contract version using CONTRACT_NAME and CONTRACT_VERSION derived from environment variables is a good practice for maintaining contract versioning. This change is well-implemented.
contracts/adapters/swap/osmosis-poolmanager/src/contract.rs (1)
  • 39-52: Setting the contract version using CONTRACT_NAME and CONTRACT_VERSION derived from environment variables is a good practice for maintaining contract versioning. This change is well-implemented.
scripts/deploy.py (7)
  • 4-18: The removal of imports such as b64decode, create_cosmwasm_execute_msg, and Coin suggests refactoring or removal of functionality that used these imports. Ensure that the removal of these imports does not affect any other parts of the script that may rely on them.

  • 40-42: Improved error message for missing configuration is a good practice for clarity and debugging.

  • 68-70: The addition of an explicit exception for unspecified network configuration (mainnet or testnet) enhances the robustness of the script.

  • 86-87: The addition of ADMIN_ADDRESS in the script is crucial for managing contract migrations and aligns with the PR's objective to make contracts upgradeable.

  • 295-311: The instantiate_contract function correctly sets the admin field to the ADMIN_ADDRESS, aligning with the upgradability feature.

  • 323-350: The instantiate2_contract function has been introduced, which includes a salt parameter for deterministic contract creation. Ensure that the use of salt and fix_msg parameters are well-documented and tested, as they are critical for the deterministic creation of contracts.

  • 382-388: The broadcast_tx function now includes a delay and a GET request to check the transaction status, which is a good practice to ensure the transaction was processed before proceeding.

contracts/adapters/swap/astroport/src/contract.rs (1)
  • 41-54: The contract's instantiation now includes setting the contract version using set_contract_version, which is a necessary step for enabling contract migrations.

packages/skip/src/swap.rs Show resolved Hide resolved
packages/skip/src/entry_point.rs Show resolved Hide resolved
contracts/entry-point/src/contract.rs Show resolved Hide resolved
packages/skip/src/ibc.rs Show resolved Hide resolved
scripts/deploy.py Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3b110d7 and 508c73c.
Files selected for processing (1)
  • scripts/deploy.py (14 hunks)
Files skipped from review as they are similar to previous changes (1)
  • scripts/deploy.py


#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult<Response> {
unimplemented!()
Copy link
Member

Choose a reason for hiding this comment

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

Does this not block the upgrade by panicking? Don't you want to just return successfully here?

Copy link
Member Author

@NotJeremyLiu NotJeremyLiu Jan 4, 2024

Choose a reason for hiding this comment

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

Migrations work using the migration code of the new contract you are migrating to, not of the deployed contract. So when we instantiate all the contracts currently in the repo, they will all deploy without ever calling their migrate functions. But then if we want to upgrade a contract in the future, we will do so by implementing that contract's migrate function, store that code on chain, and then submit the MigrateMsg

Copy link
Member Author

Choose a reason for hiding this comment

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

tldr: we only implement the migrate function when we are doing a migration/upgrade, but can keep them unimplemented on normal deploys.

@NotJeremyLiu NotJeremyLiu merged commit 947104e into main Jan 4, 2024
5 checks passed
@NotJeremyLiu NotJeremyLiu deleted the jl/make-contract-upgradeable branch January 4, 2024 18:20
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.

None yet

3 participants