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

feat: effective target canister ID for mgmt call #954

Merged
merged 3 commits into from
Nov 26, 2024

Conversation

peterpeterparker
Copy link
Member

@peterpeterparker peterpeterparker commented Nov 26, 2024

Description

Similarly to ic-js (see PR #773), the goal of this PR is to extend the transform function of the getManagementCanister to support calls on the mainnet to install_chunked_code. While I have not tested the function of agent-js irl, I can confirm that without extending the similar function in ic-js, I am unable to perform such calls on the mainnet.

This issue is due to the following specification:

If the request is an update call to the Management Canister (aaaaa-aa), then:

If the call is to the install_chunked_code method and the arg is a Candid-encoded record with a target_canister field of type principal, then the effective canister id must be that principal.

See documentation

Notes

Because I am not familiar with the agent-js codebase and want to avoid introducing too many changes, this PR solely focuses on adding the necessary code for the intended functionality. There are likely ways to improve the type declarations and address some code duplication after this implementation, but I did not want to add unnecessary noise.

There is also a potential "race condition" if a transform function is called with both canister_id and target_canister. In such cases, target_canister will take precedence over canister_id. For the same reasons mentioned above, I did not want to add additional complexity to the implementation, as this was not the primary goal of the PR. However, it is likely an issue worth addressing in the future.

Similarly, this PR includes a test specifically for the target_canister mapping to effective_canister_id, which duplicates some existing mocking. It would likely be beneficial to reduce code duplication in this area. Additionally, it would be useful to add tests for the other mappings of getManagementCanister, but this is beyond the scope of this feature.

@peterpeterparker peterpeterparker requested a review from a team as a code owner November 26, 2024 17:53
Copy link
Contributor

github-actions bot commented Nov 26, 2024

size-limit report 📦

Path Size
@dfinity/agent 87.14 KB (+0.02% 🔺)
@dfinity/candid 13.58 KB (0%)
@dfinity/principal 4.97 KB (0%)
@dfinity/auth-client 61 KB (0%)
@dfinity/assets 81.91 KB (+0.02% 🔺)
@dfinity/identity 58.15 KB (0%)
@dfinity/identity-secp256k1 132.17 KB (+0.02% 🔺)

Copy link
Contributor

@krpeacock krpeacock left a comment

Choose a reason for hiding this comment

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

Looks good! Can you add a line to the Changelog before we merge?

@peterpeterparker
Copy link
Member Author

peterpeterparker commented Nov 26, 2024

Sure. I added a line to the CHANGELOG in 5ea9b5b.

@krpeacock krpeacock enabled auto-merge (squash) November 26, 2024 18:21
@krpeacock krpeacock merged commit 7b119b3 into main Nov 26, 2024
16 checks passed
@krpeacock krpeacock deleted the feat/target-canister branch November 26, 2024 18:24
peterpeterparker added a commit to dfinity/ic-js that referenced this pull request Nov 27, 2024
# Motivation

It’s literally impossible to test the internal `transform` function used
within the static `create` function of the `ic-mgmt` class. However, as
we need to address an issue to support WASM installation with chunks
(#773), we must extend it. That’s why this PR extracts the function into
a module, allowing us to provide tests for the mapping.

# Notes

We delegate the responsibility of calling the `transform` function to
`agent-js`, as it is used internally there and as we are "just"
implementing the interface exposed by agent-js. While it is not
thoroughly covered at the moment in the agent, I submitted a PR
[#954](dfinity/agent-js#954) today that adds at
least one assertion.

No particular entry in CHANGELOG. This is an internal refactoring.

# Changes

- Extract internal `transform` function to a utility.
- JSdocs and tests.
- Improve types of the function (expected interface and return type)

---------

Signed-off-by: David Dal Busco <david.dalbusco@dfinity.org>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
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