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

Integrate contract migration #160

Merged
merged 13 commits into from
Mar 18, 2024

Conversation

dzmitryhil
Copy link
Contributor

@dzmitryhil dzmitryhil commented Feb 20, 2024

Description

Integrate contract migration

  • Migrate the contract before the integration tests start
  • Add migration integration test
  • Add migration CLI and instructions

Reviewers checklist:

  • Try to write more meaningful comments with clear actions to be taken.
  • Nit-picking should be unblocking. Focus on core issues.

Authors checklist

  • Provide a concise and meaningful description
  • Review the code yourself first, before making the PR.
  • Annotate your PR in places that require explanation.
  • Think and try to split the PR to smaller PR if it is big.

This change is Reviewable

* Migrate contract before the integration tests start
* Add migration integration test
* Add migration CLI and instructions
@dzmitryhil dzmitryhil requested a review from a team as a code owner February 20, 2024 12:59
@dzmitryhil dzmitryhil requested review from miladz68, ysv and wojtek-coreum and removed request for a team February 20, 2024 12:59
@dzmitryhil dzmitryhil changed the base branch from master to migration February 20, 2024 12:59
Copy link
Contributor

@miladz68 miladz68 left a comment

Choose a reason for hiding this comment

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

Reviewed 23 of 25 files at r1, 2 of 2 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @wojtek-coreum and @ysv)

Copy link
Collaborator

@ysv ysv left a comment

Choose a reason for hiding this comment

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

Reviewed 23 of 25 files at r1, 2 of 2 files at r2, all commit messages.
Reviewable status: all files reviewed, 11 unresolved discussions (waiting on @dzmitryhil and @wojtek-coreum)


Makefile line 18 at r2 (raw file):

GOARCH?=
BINARY_NAME?=coreumbridge-xrpl-relayer
MAINNET_RELEASE_VERSION=v0.0.2

nit: do we necessary need it to be released to mainnet ?
I think better name here is smth like upgrade_from_version ?

Code quote:

MAINNET_RELEASE_VERSION

README.md line 227 at r2 (raw file):

#### Download new version of the contract

Download new version form the [Releases page](https://github.com/CoreumFoundation/coreumbridge-xrpl/releases) and store

nit: from the

Code quote:

form the

README.md line 251 at r2 (raw file):

Only owner(admin) is authorized to call that command.

I'm a bit confused
owner & admin are 2 different roles responsible for different things, aren't they ?

Code quote:

Only owner(admin)

.github/workflows/contract-ci.yml line 4 at r2 (raw file):

on:
  push:
    branches: [ master, migration ]

nit: will this be removed before master merge ?

Code quote:

migration

contract/src/migration.rs line 16 at r2 (raw file):

#[entry_point]
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {

by the way, is it possible to test migrations on rust side ? how is it usually done @keyleu ?

Sounds like reasonable task for rust because it should be possible to reproduce more complex and specific state on rust end and then try to run migration

I'm ok to keep go testing but in general it seems to be reasonable task for contract creator also.


integration-tests/contract.go line 18 at r2 (raw file):

// CompiledContractFilePath is bridge contract file path.
const (
	MainnetContractFilePath  = "../../build/coreumbridge_xrpl_v0.0.2.wasm"

nit: as I mentioned earlier I don't think mainnet is the best word here. Because mainnet is network but contract version is independent on it

Or we can just use version inside name like we do for cored in crust
something like: ContractFilePathV002

Code quote:

Mainnet

integration-tests/contract.go line 24 at r2 (raw file):

// DeployInstantiateAndMigrateContract deploys and instantiates the mainnet version of the contract and applies
// migration.
func DeployInstantiateAndMigrateContract(

nit: it is kinda bad practice when single func has multiple verbs. It was negligible when we had 2 but 3 is too much.

Maybe we should rename it ? My options: SetupContract or PrepareContract


integration-tests/contract.go line 65 at r2 (raw file):

// DeployAndInstantiateMainnetContract deploys and instantiates the mainnet version of the contract.
func DeployAndInstantiateMainnetContract(

I think ContractFilePath could become parameter and then we can use this func for any version of contract

Or config could also change ?


integration-tests/contract/cancel_pending_operation_test.go line 37 at r2 (raw file):

	})

	owner, contractClient := integrationtests.DeployInstantiateAndMigrateContract(

question: so now in each test instead of just instantiating latest contract version you setup old version then migrate to latest and only after this run integration tests ?

Code quote:

DeployInstantiateAndMigrateContract

relayer/cmd/cli/cli.go line 207 at r2 (raw file):

		contractByteCodePath string,
	) (*sdk.TxResponse, uint64, error)
	MigrateContract(

it is usually named migrate, not upgrade ?

Code quote:

MigrateContract

relayer/cmd/cli/cli.go line 1858 at r2 (raw file):

func MigrateContractCmd(bcp BridgeClientProvider) *cobra.Command {
	cmd := &cobra.Command{
		Use:   "migrate-contract [code-id]",

could you remind me what we decided to do if we migrate to new contract version but relayers still run old one ? Do we block them or allow to submit msgs normally ?

Copy link
Contributor Author

@dzmitryhil dzmitryhil left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 11 unresolved discussions (waiting on @keyleu and @wojtek-coreum)


contract/src/migration.rs line 16 at r2 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

by the way, is it possible to test migrations on rust side ? how is it usually done @keyleu ?

Sounds like reasonable task for rust because it should be possible to reproduce more complex and specific state on rust end and then try to run migration

I'm ok to keep go testing but in general it seems to be reasonable task for contract creator also.

Yes, it is possible with the test-tube. It works similarly to what we do with the znet.

Copy link
Collaborator

@keyleu keyleu left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 11 unresolved discussions (waiting on @dzmitryhil, @wojtek-coreum, and @ysv)


contract/src/migration.rs line 16 at r2 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

by the way, is it possible to test migrations on rust side ? how is it usually done @keyleu ?

Sounds like reasonable task for rust because it should be possible to reproduce more complex and specific state on rust end and then try to run migration

I'm ok to keep go testing but in general it seems to be reasonable task for contract creator also.

Yes, we can test migrations either using multi-test or test-tube like we are currently testing. But it's only done if there is actual migration of the state, if there is no migration logic there is nothing to test.

Copy link
Contributor Author

@dzmitryhil dzmitryhil left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @wojtek-coreum and @ysv)


Makefile line 18 at r2 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

nit: do we necessary need it to be released to mainnet ?
I think better name here is smth like upgrade_from_version ?

Update to RELEASE_VERSION


README.md line 227 at r2 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

nit: from the

Done


README.md line 251 at r2 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

I'm a bit confused
owner & admin are 2 different roles responsible for different things, aren't they ?

Owner - contract manager (logic)
Admin - who is able to redeploy


.github/workflows/contract-ci.yml line 4 at r2 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

nit: will this be removed before master merge ?

Yes


integration-tests/contract.go line 18 at r2 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

nit: as I mentioned earlier I don't think mainnet is the best word here. Because mainnet is network but contract version is independent on it

Or we can just use version inside name like we do for cored in crust
something like: ContractFilePathV002

Agree, updated.


integration-tests/contract.go line 24 at r2 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

nit: it is kinda bad practice when single func has multiple verbs. It was negligible when we had 2 but 3 is too much.

Maybe we should rename it ? My options: SetupContract or PrepareContract

We have 3 different functions which we use. With different actions, I agree, that it would be better to have better names, but I don't know better.


integration-tests/contract.go line 65 at r2 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

I think ContractFilePath could become parameter and then we can use this func for any version of contract

Or config could also change ?

The difference is that the deployment might be different (not it is the same just for an example, but later the init config will be different is it will be there at all), and passing the same contract path in all tests is redundant.


integration-tests/contract/cancel_pending_operation_test.go line 37 at r2 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

question: so now in each test instead of just instantiating latest contract version you setup old version then migrate to latest and only after this run integration tests ?

Correct, the intention is to check the backward compatibility.


relayer/cmd/cli/cli.go line 207 at r2 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

it is usually named migrate, not upgrade ?

Migrate


relayer/cmd/cli/cli.go line 1858 at r2 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

could you remind me what we decided to do if we migrate to new contract version but relayers still run old one ? Do we block them or allow to submit msgs normally ?

We plan to keep it backward-compatible for now. Or they will update the relayer docker image which will be able to work with both old and new.

Copy link
Collaborator

@ysv ysv left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 4 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @dzmitryhil and @wojtek-coreum)


README.md line 251 at r2 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

Owner - contract manager (logic)
Admin - who is able to redeploy

yes, but here you wrote:

Only owner(admin) is authorized to call that command.

So from this line it is not clear who is authorized.


contract/src/migration.rs line 16 at r2 (raw file):

if there is actual migration of the state

Yes exactly, That is what I mean. So once we have state migration lets not forget to add tests for it.
For now since it is still non-released version it is ok


integration-tests/contract.go line 65 at r2 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

The difference is that the deployment might be different (not it is the same just for an example, but later the init config will be different is it will be there at all), and passing the same contract path in all tests is redundant.

then it should be smth like DeployAndInstantiateContrantV002
Again lets avoid Mainnet everywhere

Copy link
Contributor Author

@dzmitryhil dzmitryhil left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @wojtek-coreum and @ysv)


README.md line 251 at r2 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

yes, but here you wrote:

Only owner(admin) is authorized to call that command.

So from this line it is not clear who is authorized.

Agree, updated. Only admin is authorized to call that command.


integration-tests/contract.go line 65 at r2 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

then it should be smth like DeployAndInstantiateContrantV002
Again lets avoid Mainnet everywhere

Done

ysv
ysv previously approved these changes Feb 27, 2024
Copy link
Collaborator

@ysv ysv left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @wojtek-coreum)

miladz68
miladz68 previously approved these changes Mar 8, 2024
Copy link
Contributor

@miladz68 miladz68 left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 4 files at r3, 3 of 3 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @wojtek-coreum)

# Conflicts:
#	README.md
#	relayer/client/bridge.go
#	relayer/cmd/cli/cli.go
#	relayer/cmd/main.go
@dzmitryhil dzmitryhil changed the base branch from migration to master March 14, 2024 08:01
@dzmitryhil dzmitryhil dismissed stale reviews from miladz68 and ysv March 14, 2024 08:01

The base branch was changed.

miladz68
miladz68 previously approved these changes Mar 14, 2024
Copy link
Contributor

@miladz68 miladz68 left a comment

Choose a reason for hiding this comment

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

Reviewed 22 of 22 files at r5, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @keyleu, @wojtek-coreum, and @ysv)

keyleu
keyleu previously approved these changes Mar 14, 2024
Copy link
Collaborator

@keyleu keyleu left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 25 files at r1, 22 of 22 files at r5, 2 of 2 files at r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @wojtek-coreum and @ysv)

Copy link
Collaborator

@wojtek-coreum wojtek-coreum left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 25 files at r1, 20 of 22 files at r5, 2 of 2 files at r6, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @dzmitryhil and @ysv)


integration-tests/contract/cancel_pending_operation_test.go line 37 at r6 (raw file):

	})

	owner, contractClient := integrationtests.DeployInstantiateAndMigrateContract(

do you need to migrate contract in every integration test?


integration-tests/processes/env_test.go line 163 at r6 (raw file):

		)
		require.NoError(t, err)
		require.NoError(t, contractClient.SetContractAddress(contractAddress))

could you pass contract address using a constructor?


relayer/coreum/contract.go line 586 at r6 (raw file):

	byteCode []byte,
) (*sdk.TxResponse, uint64, error) {
	txRes, codeID, err := c.deployContract(ctx, sender, byteCode)

Can't you simply put the body of c.deployContract here and use the exported method everywhere?

Copy link
Contributor Author

@dzmitryhil dzmitryhil left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @wojtek-coreum and @ysv)


integration-tests/contract/cancel_pending_operation_test.go line 37 at r6 (raw file):

Previously, wojtek-coreum (Wojtek) wrote…

do you need to migrate contract in every integration test?

To be sure that the new contract is backward compatible - yes.


integration-tests/processes/env_test.go line 163 at r6 (raw file):

Previously, wojtek-coreum (Wojtek) wrote…

could you pass contract address using a constructor?

We deploy the contract and instantiate using the same client. So we don't have the address at the time we create it.


relayer/coreum/contract.go line 586 at r6 (raw file):

Previously, wojtek-coreum (Wojtek) wrote…

Can't you simply put the body of c.deployContract here and use the exported method everywhere?

Done.

Copy link
Collaborator

@wojtek-coreum wojtek-coreum left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ysv)

Copy link
Collaborator

@keyleu keyleu left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r8, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ysv)

@dzmitryhil dzmitryhil merged commit 8e30198 into master Mar 18, 2024
8 checks passed
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.

5 participants