Repository navigation
chore(ICP-Ledger): migrate transfer and approve endpoints from dfn to cdk - #4316
Conversation
mbjorkqvist
left a comment
There was a problem hiding this comment.
Thanks @maciejdfinity! Regarding the change to traps, wouldn't it be better to return a TransferFromError/TransferError/ApproveError, rather than trap? I think the currently-returned errors are not spec-conformant, so changing them definitely makes sense. I believe trapping would be fine from a spec point of view, but returning the errors defined for the individual methods in the spec would be even better IIUC? I think we'd have to return GenericError enum variants since there's no better match, and I don't think we can add new variants.
nit: I find having the string explicitly specify "the anonymous principal" if the call to can_send returns fails isn't great, since based on the can_send name, it could also return false for other principals. Maybe a comment reminding us to change the message in case we do start failing for other principals as well would be enough?
As discussed offline, we have to check if
Good point! I added a comment in the function. |
I created FI-1695 for this, since it's not really related to the |
I used the same code as in the ICRC ledger.
Upgrades `rules_python` from 2.4.6 to [2.5.1](https://github.com/bazel-contrib/rules_python/releases/tag/2.5.1), its latest release. `python_version` stays at 3.12, which still resolves to CPython 3.12.16 from the same python-build-standalone 20261026 archive (same sha256). A follow-up moves `python_version` to a newer Python. The released artifacts don't change. Built unstamped, all their 133 output files are byte-identical to master's. That covers the GuestOS, HostOS and SetupOS images, GuestOS's `launch-measurements.json`, `//publish/binaries:bundle` and `//publish/canisters:bundle`. Python only runs as a build tool there, for example the `//toolchains/sysimage` image tools and sev-snp-measure. ## Changes - **`MODULE.bazel`**: version bump. BCR's `rules_python/2.5.1` only carries the usual patch that sets the module version. Its non-dev `bazel_dep`s are the same as 2.4.6's. 2.4.6 already declared `rules_rust` as a dev dependency. 2.5.0 declares it with `dev_dependency = TOOL_DEPS_DEV_ONLY`, which is `True` in the released module, so it stays a dev dependency. In our module graph only `rules_python` itself changes version. - **`bazel/conf/.bazelrc.build`**: comment only. 2.5.0 opts rules_python's own targets out of implicit `__init__.py` creation in its own `MODULE.bazel` ([bazel-contrib/rules_python#4451](bazel-contrib/rules_python#4451)), so our `--incompatible_default_to_explicit_init_py` no longer matters for its `py_console_script_gen_py`. The flag is still needed for the other four executables from other modules that the comment lists (see Verification). dfinity#12159 (rules_foreign_cc 0.17.0) rewords the meson entry of the same comment. Whichever of the two lands second gets a small conflict there, resolved by keeping both edits. ## Upstream changes that touch our setup - **Interpreter bytecode cache** ([dfinity#4233](bazel-contrib/rules_python#4233), [dfinity#4198](bazel-contrib/rules_python#4198), [dfinity#4264](bazel-contrib/rules_python#4264)): the `__pycache__` directories of the downloaded interpreter used to be symlinks into `/tmp/rules_python_pycache`. They now point into `$XDG_CACHE_HOME` or, if that is unset, `$HOME/.cache`, under `rules_python_pycache/<repo>/<hash of workspace and runtime>`. They are no longer part of any executable's runfiles. Where no such directory can be created, they become empty files, which turns off bytecode caching for the interpreter's standard library. In the dev container they point into `/home/ubuntu/.cache/rules_python_pycache/rules_python++python+python_3_12_x86_64-unknown-linux-gnu/1415731597/`, and running our tools fills that directory. These `.pyc` files are neither action inputs nor outputs. - **Wheel archives** ([dfinity#4316](bazel-contrib/rules_python#4316)): `pip.parse` now deletes each downloaded wheel after extracting it. The `:whl` and `:whl_file` targets fetch it again, on demand, from a sibling `<repo>_whl` repository. Wheels that `pip.parse` builds from an sdist keep their archive. Our only user of these targets is the `whl_filegroup` `//ic-os/dev-tools/bare_metal_deployment:redfish_scripts`, which extracts scripts from `@python_deps//idracredfishsupport:whl`: - idracredfishsupport is pinned to its sdist, so its wheel is still built at fetch time and kept in its repository. It is the only wheel the extraction action reads. - Its `:whl` target lists the `:whl` targets of its dependencies (requests, certifi, charset_normalizer, idna and urllib3) as `data`. Those are downloaded wheels, so building `redfish_scripts` now also fetches their five `_whl` repositories. `redfish_scripts` builds, and its 118 extracted scripts are byte-identical to 2.4.6's. - **Launcher scripts** ([dfinity#4386](bazel-contrib/rules_python#4386), [dfinity#4161](bazel-contrib/rules_python#4161)): the launcher of every `py_binary` and `py_test` changes: - The `bootstrap_impl=script` launcher, which our four `launch_bare_metal_main` binaries use, now quotes its paths. - The default `system_python` launcher, which all our other Python executables use, now forwards termination signals when it runs the program as a subprocess. It only does that for zipapps and for venvs created at runtime. Our executables still `exec` the interpreter. For `//ic-os:sev-snp-measure`, the launcher differs from 2.4.6's by exactly the upstream template diff. Because the launchers change, the actions that run our Python tools miss the cache once. Their outputs stay the same (see above). - **`stamp`** (2.5.1, [dfinity#4484](bazel-contrib/rules_python#4484)): the attribute no longer transitions `--stamp` for the whole executable, only for its build-data input. None of our Python targets sets `stamp`. `py_binary` defaults to `stamp = -1`, which transitions nothing in either version. `py_test` defaults to `stamp = 0`, which was a no-op transition under `--nostamp`, our default. So our configurations don't change. - **`py_console_script_binary`** ([dfinity#4219](bazel-contrib/rules_python#4219)): it now reads `entry_points.txt` in the exec configuration. The entry point generated for `//ic-os:sev-snp-measure` is byte-identical. - **Runtime archive selection** ([dfinity#4192](bazel-contrib/rules_python#4192)): the new `--@rules_python//python/config_settings:py_pbs_distribution` flag picks the python-build-standalone archive. Its default, `auto`, lets rules_python choose: 2.5.1 maps it to `install_only`, the archive we already use. 2.5.x also registers an `exe_zip_maker` toolchain in `@rules_python_tools`, which only `py_zipapp_binary` uses. We don't use `py_zipapp_binary`. ## Verification All of this ran in the dev container: - **Module graph:** `bazel mod graph` resolves `rules_python` to 2.5.1, and every other module to the same version as on master. It prints no version warnings. - **Analysis:** `bazel build //... --nobuild` analyzes all 3387 targets. Its only warning is the `rules_qemu` `use_repo` warning that master also prints. - **Implicit `__init__.py`:** I analyzed the five executables from other modules with `--incompatible_default_to_explicit_init_py=false`: - With 2.4.6, all five print the deprecation warning. - With 2.5.1, all except `py_console_script_gen_py` do. - With the flag as `.bazelrc.build` sets it, neither version prints any. On the command line, `--noincompatible_default_to_explicit_init_py` doesn't override the rc line; `=false` does. - **Builds:** all of these build: - all 26 Python targets (17 `py_binary`, 5 `py_test`, 4 `py_library`) - `//ic-os/dev-tools/bare_metal_deployment:redfish_scripts` - `//:mke2fs`, `//:fuse2fs` and `//:debugfs`, built with rules_foreign_cc's Python-based meson. They are byte-identical to 2.4.6's. - **Tests:** these pass: - `//:python-requirements.test` - `//bazel/inject_version_into_wasm_tests:inspect_stamped_trivial_wasm` - `//ci/githubstats:query_test` and `//ci/githubstats:query_help_test` - `//ci/scripts:repro_check_test` - `//rs/recovery/subnet_splitting/split_finder:split_finder_test` - `//rs/recovery/subnet_splitting:integration_test` - **Programs:** the 16 `py_binary`s other than `//:python-requirements.update` print the same `--help` with 2.4.6 and 2.5.1. That includes the four `launch_bare_metal_main` binaries. - **Release artifacts:** I built these unstamped: - the IC-OS bundles that `ci/container/build-ic.sh --icos` builds: GuestOS prod disk and update, GuestOS recovery update, HostOS update, and SetupOS - `//publish/binaries:bundle` and `//publish/canisters:bundle` All 133 output files are byte-identical to a build of master (c712eb2). The build re-ran 53 actions, 46 of them IC-OS image actions; everything else was a cache hit. - **Lint:** the Linter job's checks pass: shfmt, ruff, buf, DFINITY capitalization, do-not-merge, buildifier, gazelle and buf-breaking. Its autofixes leave the tree unchanged. - **Not verified locally:** Namespace RBE and macOS. This PR's CI builds and tests `//...`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
I made one functional change: in case of anonymous transfer/approve I trap instead of returning an error.