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

[CLI] Only use referenced dependencies in the linkage table #20509

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

stefan-mysten
Copy link
Member

@stefan-mysten stefan-mysten commented Dec 4, 2024

Description

When a package is added as a dependency in the Move.toml manifest file, it will become part of the linkage table regardless if any code in that package is actually referenced in the code or not.

This PR fixes that by making sure that a package's linkage table contains only the dependencies that are actually referenced in the code by computing the list of dependencies from the modules' dependencies after all modules and their transitive dependencies are compiled rather than the manifest files.

Test plan

Note that now source validation will not allow to publish such a package (see below) because it cannot find the dependency on-chain.

Structure:
A_v1 -> published
A_v2 -> upgrade A_v1
B -> dependency on A_v2, but no code is called from A_v2.

Locally: After the change

{
  "data": {
    "package": {
      "modules": {
        "nodes": [
          {
            "name": "b",
            "package": {
              "address": "0xb185657f36ad8af5c84e95884f674747bcfffe5bc51b98053bfbf2c349ef0633",
              "linkage": [
                {
                  "originalId": "0x0000000000000000000000000000000000000000000000000000000000000001",
                  "upgradedId": "0x0000000000000000000000000000000000000000000000000000000000000001",
                  "version": 1
                },
                {
                  "originalId": "0x0000000000000000000000000000000000000000000000000000000000000002",
                  "upgradedId": "0x0000000000000000000000000000000000000000000000000000000000000002",
                  "version": 1
                }
              ]
            }
          }
        ]
      }
    }
  }
}

Before the change

{
  "data": {
    "package": {
      "modules": {
        "nodes": [
          {
            "name": "b",
            "package": {
              "address": "0x1f7f5733d11a5556cddcf73d4642351159b77aafe1b7c5d3d0b2e310f315d4e6",
              "linkage": [
                {
                  "originalId": "0x0000000000000000000000000000000000000000000000000000000000000001",
                  "upgradedId": "0x0000000000000000000000000000000000000000000000000000000000000001",
                  "version": 1
                },
                {
                  "originalId": "0x0000000000000000000000000000000000000000000000000000000000000002",
                  "upgradedId": "0x0000000000000000000000000000000000000000000000000000000000000002",
                  "version": 1
                },
                {
                  "originalId": "0x40adad4ef6d528484468adabe558d051a1d98cd9202de1f4ed3d71724f3f43c3",
                  "upgradedId": "0x922ac7f39faf25f030db32835219e7deb7b87b08f1a7703e1b6e5beb6b5a96f2",
                  "version": 2
                }
              ]
            }
          }
        ]
      }
    }
  }
}

B's source code is:

module b::b {
    use std::string::{Self, String};
    use a_v1::a_v1;

    public fun hello_default(ctx: &mut TxContext) {
        let name = string::utf8(b"hello");
    }

    //public fun test(ctx: &mut TxContext): a_v1::Object {
    //    a_v1::default(ctx)
    //}
}

B's Move.toml dependency list is:

[dependencies]
sui = { git = "https://github.com/mystenlabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" }
a_v1 = { local = "../a_v2" }

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:
  • REST API:

Copy link

vercel bot commented Dec 4, 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 Jan 18, 2025 0:24am
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Jan 18, 2025 0:24am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Jan 18, 2025 0:24am
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Jan 18, 2025 0:24am

@stefan-mysten
Copy link
Member Author

stefan-mysten commented Dec 5, 2024

This PR breaks the following tests. Would have to look into them:

 TRY 4 FAIL [   0.897s] sui-core move_package_tests::package_digest_changes_with_dep_upgrades_and_in_sync_with_move_package_digest
 TRY 4 FAIL [   2.742s] sui-package-resolver tests::test_function_parameters
 TRY 4 FAIL [   2.010s] sui-package-resolver tests::test_relinking_layout
 TRY 4 FAIL [  23.935s] sui-source-validation tests::linkage_differs
 TRY 4 FAIL [  18.823s] sui-source-validation tests::successful_verification_upgrades
 TRY 4 FAIL [  16.837s] sui-source-validation tests::successful_verification_with_bytecode_dep

Copy link
Member

@amnn amnn left a comment

Choose a reason for hiding this comment

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

The implementation looks good, thanks @stefan-mysten. When it comes to updating the tests, I suspect many of them are now failing because before they were adding a dependency that was not referenced as a convenient short hand as part of the test set-up.

In most if not all cases the right thing to do is probably to introduce a reference to the non-existent dependency in the Move code, not expect that it will be stripped. I made a comment to that effect on the test that was already updated, but watch out for that when cleaning up the other tests too.

crates/sui-move-build/src/lib.rs Outdated Show resolved Hide resolved
crates/sui-move-build/src/lib.rs Outdated Show resolved Hide resolved
crates/sui-move-build/src/lib.rs Outdated Show resolved Hide resolved
"{}",
err
);
// publishing with a dependency that is not referenced in code is OK, as the dependency list
Copy link
Member

Choose a reason for hiding this comment

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

It seems like in this case you need to update the test such that the dependency is actually referenced but does not exist, because that is what we're trying to test here.

Copy link
Member Author

@stefan-mysten stefan-mysten Dec 6, 2024

Choose a reason for hiding this comment

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

Yes, but now the issue will be that source verification will trigger an error that it cannot find the on-chain version of this dependency which is a slightly different error than the one we had here with Dependency object does not exist or was deleted. FWIW, that Move package has set a random published-at field in the manifest.

Copy link
Member

Choose a reason for hiding this comment

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

It's okay that the error wording is different, the point is that we're testing the error case here.

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