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

move: automated address mgmt for pkg upgrades #17931

Closed
wants to merge 1 commit into from
Closed

Conversation

rvantonder
Copy link
Contributor

@rvantonder rvantonder commented May 25, 2024

Description

This PR adds automated address management support for sui client upgrade. I'm building this out iteratively so that it's easier to reason about and ensure backwards-compatibility during the transition when a package does not yet have info tracking in Move.lock (i.e., supporting package publish will come next).

High-level:

  • If a package contains a Move.lock that contains info to support a package upgrade, then that is used, and a user does not have to (nor should they) maintain a published-at address in their Move.toml.

  • If a package does not have any Move.lock information to support a package upgrade, we will still fallback to Move.toml as we do today. Nothing changes.

  • If a package has both a Move.lock and Move.toml, then the Move.lock will be used (the user is free to delete published-at in their Move.toml). Caveat: If a published address is in both of these files, they must be the same (we will raise a Conflict error message otherwise).

  • Note after this PR it is still required to set [addresses] to 0x0 in Move.toml. This requirement will be removed after publish support is added (which also requires setting to 0x0 still). I didn't want to meddle with that logic all at once.

Test plan

How did you test the new or updated feature?

We cover three cases:

  • Upgrade with Move.toml only (existing package upgrade test)
  • Upgrade with Move.lock only (extension of existing package management test)
  • Upgrade with Move.lock and Move.toml with conflicting addresses error condition (new test)

Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

Copy link

vercel bot commented May 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 26, 2024 11:38pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview May 26, 2024 11:38pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview May 26, 2024 11:38pm
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview May 26, 2024 11:38pm

Comment on lines -661 to +660
let property = published_at_property(package);
let property = resolve_published_id(package, chain_id.clone());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Main top-level change: previously we resolved the published_at property only from the manifest. Now we do so from either the Move.lock or manifest in the resolve_published_id function.

Comment on lines -1882 to -1897
let mut buf = String::new();
move_toml.read_to_string(&mut buf).unwrap();

// Add a `published-at = "0x<package_object_id>"` to the Move manifest.
let mut lines: Vec<String> = buf.split('\n').map(|x| x.to_string()).collect();
let idx = lines.iter().position(|s| s == "[package]").unwrap();
lines.insert(
idx + 1,
format!(
"published-at = \"{}\"",
package.reference.object_id.to_hex_uncompressed()
),
);
let new = lines.join("\n");
move_toml.write_at(new.as_bytes(), 0).unwrap();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test test_package_management_on_upgrade_command previously performed an upgrade to check that we are writing the correct package management info to Move.lock. It previously used the same logic, relying on Move.toml to have the info.

Now, we remove the reliance on Move.toml to perform the upgrade in this test (and it ought to still succeed).

Comment on lines +2015 to +2016
// Purposely add a conflicting `published-at` address to the Move manifest.
lines.insert(idx + 1, "published-at = \"0xbad\"".to_string());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Main logic for this test: put a bogus address in Move.toml and expect the error message.

Comment on lines +1653 to +1660
"Conflicting published package address: `Move.toml` contains published-at address \
{id_manifest} but `Move.lock` file contains published-at address {id_lock}. \
You may want to:

- delete the published-at address in the `Move.toml` if the `Move.lock` address is correct; OR
- update the `Move.lock` address using the `sui manage-package` command to be the same as the `Move.toml`; OR
- check that your `sui active-env` {env_alias} corresponds to the chain on which the package is published (i.e., devnet, testnet, mainnet); OR
- contact the maintainer if this package is a dependency and request resolving the conflict."
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Open to ideas or comments on this error message. One part of me wants to cover the most obvious things that could go wrong, and another part of me wants to direct the user to the docs and just say something like "conflicting addresses error, check the docs on how to resolve this".

Copy link
Contributor

@stefan-mysten stefan-mysten May 29, 2024

Choose a reason for hiding this comment

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

Not needing to read the docs is a plus in some way. Doc links also get stale, so my opinion is to go with having here an explicit explanation on how to address this issue error.

Regarding the message itself, after I read it I am slightly conflicted which one to try first. Perhaps the sui manage-package could be the first line of defense. If a command can do it for me, that's what I would try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, fully agree, doc links are not the way to go. The idea was more of a soft "refer to the docs online for more information" rather than a specific link.

Copy link
Contributor

@stefan-mysten stefan-mysten left a comment

Choose a reason for hiding this comment

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

I am excited to see this rolled out!!! 👍

@rvantonder
Copy link
Contributor Author

thanks for your enthusiasm @stefan-mysten! There is a snag and I need to update some things in this PR, but we are indeed close!!

@stefan-mysten
Copy link
Contributor

thanks for your enthusiasm @stefan-mysten! There is a snag and I need to update some things in this PR, but we are indeed close!!

Cool, let me know when that's fixed and I will get a review in!

@rvantonder rvantonder closed this Jun 7, 2024
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