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] Filter unused dependencies in the source code from being published #21168

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

Conversation

stefan-mysten
Copy link
Contributor

@stefan-mysten stefan-mysten commented Feb 11, 2025

Description

This PR filters out dependencies that might exist in the manifest but are not referenced in the source code such that they do not end up in the linkage table. However, it keeps backward compatibility with what's on chain today (a.k.a there might be dependencies in the linkage table but the code never references those deps).

In addition, it cleans up the compile_package function to just return the CompiledPackage type which holds all the needed data.

Test plan

Added tests: see crates/sui/tests/data/tree_shaking/README.md and

cargo test -- test_tree_shaking

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):
  • gRPC:
  • JSON-RPC:
  • GraphQL:
  • CLI: Added a feature to automatically filter out dependencies that are not referenced in the code from the linkage table on-chain. This feature is backwards compatible with whatever exists now on-chain.
  • Rust SDK:

Copy link

vercel bot commented Feb 11, 2025

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 Feb 12, 2025 0:29am
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Feb 12, 2025 0:29am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Feb 12, 2025 0:29am

Comment on lines +956 to +964

let (upgrade_policy, mut compiled_package) =
upgrade_result.map_err(|e| anyhow!("{e}"))?;

let compiled_modules =
compiled_package.get_package_bytes(with_unpublished_dependencies);
let package_id = compiled_package.published_at.clone()?;
let package_digest =
compiled_package.get_package_digest(with_unpublished_dependencies);
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 is just a refactor of the compile_package function to return a CompiledPackage type instead of a four-tuple.

@stefan-mysten stefan-mysten removed the request for review from ronny-mysten February 11, 2025 05:54
Copy link
Contributor

@mdgeorge4153 mdgeorge4153 left a comment

Choose a reason for hiding this comment

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

Overall, looks great; I left a few inline comments and questions. Only not approving because I think another set of more experienced eyes than mine would be useful =)

crates/sui/src/client_commands.rs Outdated Show resolved Hide resolved
crates/sui/src/client_commands.rs Outdated Show resolved Hide resolved
crates/sui/src/client_commands.rs Outdated Show resolved Hide resolved
crates/sui/src/client_commands.rs Outdated Show resolved Hide resolved
crates/sui/src/client_commands.rs Show resolved Hide resolved
let move_pkg_b = fetch_move_packages(&client, vec![package_b_id]).await?;
let linkage_table_b = move_pkg_b.first().unwrap().linkage_table();
// B depends on A, so the linkage table should contain A's object ID
assert!(linkage_table_b.contains_key(&package_a_id));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you could be a little more precise here - linkage_table_b should equal [&package_a_id].

Copy link
Contributor Author

@stefan-mysten stefan-mysten Feb 11, 2025

Choose a reason for hiding this comment

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

Not really, because linkage_table has the BTreeMap<ObjectID, UpgradeInfo> type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just asserting that the size is 1 like you do below (although BTreeMap does implement Eq and I assume Eq<ObjectID> and maybe Eq<UpgradeInfo> behave reasonably?)

crates/sui/tests/cli_tests.rs Show resolved Hide resolved
crates/sui/tests/cli_tests.rs Show resolved Hide resolved
.is_some_and(|x| x.upgraded_id == package_a_v1.reference.object_id));

Ok(())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

One test that's missing I think is the case where the existing package on-chain has more dependencies in its linkage table than it actually uses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I will add that right away.

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