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 toolchain: fix multiple issues with bytecode dependencies #16523

Merged
merged 14 commits into from
Sep 11, 2024

Conversation

kklas
Copy link
Contributor

@kklas kklas commented Mar 4, 2024

Description

This PR fixes multiple issues caused by bytecode dependencies not being included in CompiledPackage:

  • multiple functionalities failing due to topo sort in Modules panicking on missing dependencies
  • running move test on packages with bytecode deps failing due to them not being included in VM storage
  • source verification failing because bytecode deps aren't handled
  • commands such as publish and upgrade failing due to bytecode deps not being referenced in the construction of transaction blocks

Summary of changes:

  • removed move_bytecode_utils::dependency_graph module and instead added a compute_topological_order method to Modules. Replaced all calls to compute_dependency_graph with a direct call to compute_topological_order (2 in total)
  • added bytecode deps to VM storage for test runs by loading them from ResolvedGraph
  • include bytecode deps in sui_move_build::CompiledPackage and fix various module fetching methods to return modules from bytecode deps also
  • include bytecode deps in local_modules function to fix LocalDependencyNotFound errors in source verification

This is part of the work to enable compiling against on-chain dependencies #14178.

cc @rvantonder @amnn

Test Plan

Added unit tests for move test and source verification.


If your changes are not user-facing and do not break anything, you can skip the following section. Otherwise, please briefly describe what has changed under the Release Notes section.

Type of Change (Check all that apply)

  • protocol change
  • user-visible impact
  • breaking change for a client SDKs
  • breaking change for FNs (FN binary must upgrade)
  • breaking change for validators or node operators (must upgrade binaries)
  • breaking change for on-chain data layout
  • necessitate either a data wipe or data migration

Release notes

Copy link

vercel bot commented Mar 4, 2024

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

Name Status Preview Comments Updated (UTC)
sui-core ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 11, 2024 0:56am
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 11, 2024 0:56am
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Sep 11, 2024 0:56am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Sep 11, 2024 0:56am
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Sep 11, 2024 0:56am

@rvantonder
Copy link
Contributor

Thanks @kklas! Kicking off CI so long, review to follow!

Copy link
Contributor

@tnowacki tnowacki left a comment

Choose a reason for hiding this comment

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

A few comments but going to tag in @tzakian and @cgswords here too.
Overall, I just want to make sure this feels like something core to the package system and not bolted on top

crates/sui-move-build/src/lib.rs Show resolved Hide resolved
Comment on lines +240 to +242
// collect bytecode dependencies as these are not returned as part of core
// `CompiledPackage`
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like they should be? If this is an issue

Copy link
Contributor

Choose a reason for hiding this comment

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

Though needing the full deserialized bytes feels maybe like a Sui specific thing? Unsure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not nearly as familiar with this codebase as any of you are, but I'm also unsure. Though here the only reason I've added these here is because of source verification (to avoid having to hackily load them somehow in the source verification implementation), which is a Sui specific thing.So perhaps it's justifiable keeping them here unless there's another reason to have them in core CompiledPackage?

external-crates/move/crates/move-bytecode-utils/src/lib.rs Outdated Show resolved Hide resolved
external-crates/move/crates/move-unit-test/src/lib.rs Outdated Show resolved Hide resolved
@kklas
Copy link
Contributor Author

kklas commented Mar 13, 2024

@tnowacki agree with everything. I'm waiting for other comments to do round 2 here.

Copy link
Contributor

@rvantonder rvantonder 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 happy to see a move-bytecode-utils file get nuked 😄

See inline comments!

}

match petgraph::algo::toposort(&graph, None) {
Err(_) => panic!("Circular dependency detected"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we have a Result return type, think it makes sense to trickle this up in stead of panicking? anyhow::bail? The match might also simplify?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was like that in the old code too. My impression is that you should never be able to end up with a circular dependency on what is essentially a CompiledModule list. Because otherwise these modules wouldn't even compile. So it's not like a user error here but some serious bug somewhere else so a panic seems fine here.

external-crates/move/crates/move-unit-test/src/lib.rs Outdated Show resolved Hide resolved
crates/sui-move-build/src/lib.rs Show resolved Hide resolved
Copy link
Contributor

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@kklas
Copy link
Contributor Author

kklas commented Sep 2, 2024

I apologize for this unreasonably long delay. I have restarted the work on this:

  • rebase
  • move bytecode_deps_modules inside TestRunner
  • use IndexMap in compute_topological_order

@amnn @rvantonder @tnowacki I would appreciate another look

Copy link
Contributor

@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.

Thanks for this @kklas ! This looks reasonable to me -- let me give @tnowacki a couple of days into next week to take a look as well, (he's out at the moment), but then I'm happy to stamp.

crates/sui-source-validation/src/tests.rs Outdated Show resolved Hide resolved
crates/sui-source-validation/src/tests.rs Outdated Show resolved Hide resolved
crates/sui-source-validation/src/tests.rs Outdated Show resolved Hide resolved
external-crates/move/crates/move-unit-test/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@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.

Let's :shipit: !

@amnn
Copy link
Contributor

amnn commented Sep 11, 2024

@kklas, my hand is hovering over "Squash and Merge" but let me know if you want to do a final rebase, etc before I send it.

@kklas
Copy link
Contributor Author

kklas commented Sep 11, 2024

@amnn rebase done, all good to go!

@amnn amnn merged commit 9a275a4 into MystenLabs:main Sep 11, 2024
45 checks passed
@amnn
Copy link
Contributor

amnn commented Sep 11, 2024

It's in, 🚀 , thanks very much @kklas!

@kklas kklas deleted the bytecode-deps-fixes branch September 16, 2024 06:13
suiwombat pushed a commit that referenced this pull request Sep 16, 2024
## Description 

This PR fixes multiple issues caused by bytecode dependencies not being
included in `CompiledPackage`:
- multiple functionalities failing due to topo sort in `Modules`
panicking on missing dependencies
- running `move test` on packages with bytecode deps failing due to them
not being included in VM storage
- source verification failing because bytecode deps aren't handled
- commands such as publish and upgrade failing due to bytecode deps not
being referenced in the construction of transaction blocks

Summary of changes:
- removed `move_bytecode_utils::dependency_graph` module and instead
added a `compute_topological_order` method to `Modules`. Replaced all
calls to `compute_dependency_graph` with a direct call to
`compute_topological_order` (2 in total)
- added bytecode deps to VM storage for test runs by loading them from
`ResolvedGraph`
- include bytecode deps in `sui_move_build::CompiledPackage` and fix
various module fetching methods to return modules from bytecode deps
also
- include bytecode deps in `local_modules` function to fix
`LocalDependencyNotFound` errors in source verification

This is part of the work to enable compiling against on-chain
dependencies #14178.

cc @rvantonder @amnn

## Test Plan 

Added unit tests for `move test` and source verification.

---
If your changes are not user-facing and do not break anything, you can
skip the following section. Otherwise, please briefly describe what has
changed under the Release Notes section.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants