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

Clean up upgradeable contract examples #1697

Merged
merged 16 commits into from
Mar 3, 2023

Conversation

HCastano
Copy link
Contributor

@HCastano HCastano commented Mar 1, 2023

This PR improves the set_code_hash example by simplifying the code a little bit, adding
more comments, and adding an E2E test to show the workflow.

It also removes the forward-calls example. This example was supposed to demonstrate the
usage of proxies for upgrades, but since it used regular calls instead of delegate calls
it didn't really work as intended.

This is because the state was being stored in the logic/implementation contract as opposed
to the proxy, which would get lost between upgrades.

I'm not sure if we want to replace this with an upgradeable proxy example, or if we
should stick to using set_code_hash as the "recommended" upgradeability pattern.

@HCastano HCastano requested review from a team, cmichi, ascjones and SkymanOne as code owners March 1, 2023 20:08
/// In a production contract you would do some authorization here!
#[ink(message)]
pub fn set_code(&mut self, code_hash: [u8; 32]) {
ink::env::set_code_hash(&code_hash).unwrap_or_else(|err| {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering whether we should add this to EnvAccess so you can do self.env().set_code_hash()

Copy link
Collaborator

Choose a reason for hiding this comment

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

Like this: #1698

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya that'd be nice

Copy link
Collaborator

@ascjones ascjones left a comment

Choose a reason for hiding this comment

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

LGTM!

P.S. ink-waterfall needs updating for the new contract structure, see https://github.com/paritytech/ink-waterfall/blob/master/.gitlab-ci.yml#L21

let get_res = client.call_dry_run(&ink_e2e::alice(), &get, 0, None).await;

// Remember, we updated our incrementer contract to increment by `4`.
assert!(matches!(get_res.return_value(), 4));
Copy link
Collaborator

Choose a reason for hiding this comment

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

An extremely tiny 🔎 🤏 nitpick, we should call inc on the original contract to increment by one first, before calling inc on the upgraded one. Then test for 5 here. Because it would be possible for this test to pass by having the original contract increment by 4 and not upgrading itself. Not absolutely necessary just pointing it out.

Copy link
Collaborator

@ascjones ascjones left a comment

Choose a reason for hiding this comment

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

LGTM

Edit I liked this PR so much I approved it twice 🙈

@HCastano
Copy link
Contributor Author

HCastano commented Mar 3, 2023

P.S. ink-waterfall needs updating for the new contract structure, see https://github.com/paritytech/ink-waterfall/blob/master/.gitlab-ci.yml#L21

Ah yeah, good point. I'm so used to ignoring the waterfall I was going to merge it anyways 😆

HCastano added a commit to paritytech/ink-waterfall that referenced this pull request Mar 3, 2023
HCastano added a commit to paritytech/ink-waterfall that referenced this pull request Mar 3, 2023
@HCastano
Copy link
Contributor Author

HCastano commented Mar 3, 2023

Hmm okay it looks like the waterfall failure is related to Flipper, not any outdated paths

Copy link
Collaborator

@cmichi cmichi left a comment

Choose a reason for hiding this comment

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

Thanks!

Can you reflect those changes on https://github.com/paritytech/ink-examples?

Aaand is there anything you think should be put into https://use.ink/basics/upgradeable-contracts as a consequence?

@cmichi cmichi merged commit 4dd006d into master Mar 3, 2023
@cmichi cmichi deleted the hc-clean-up-upgradeable-contracts branch March 3, 2023 12:25
cmichi added a commit to paritytech/ink-waterfall that referenced this pull request Mar 3, 2023
ascjones pushed a commit that referenced this pull request Mar 3, 2023
* Move `set-code-hash` example out of `upgradeable-contracts` folder

* Clean up code a bit

* Rename folder to use snake_case

* More snake casing

* Make it more explicit that upgraded constructor won't be called

* Add an E2E test showing upgrade workflow

* Remove `forward-calls` example

This wasn't really a good showcase of an upgradeable contract.

This is because it didn't use `delegate_call`, meaning that the `Proxy`
contract wouldn't be able to retain state between updates.

* Remove `upgradeable-contracts` from CI

* Move `edition` after `author` field

* Use American spelling, I guess...

* Fix some paths

* More path fixes

* Remove comment

* Move `edition` below `authors` key

* Appease Clippy

* Ensure that initial `inc` is only by `1`
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.

4 participants