From 5e72cad4600575934e14aac5498f4c7f71a23ea8 Mon Sep 17 00:00:00 2001 From: Dimitris Sarlis Date: Wed, 19 Feb 2025 10:52:50 +0100 Subject: [PATCH] chore(EXC-1841): Remove old pmap canister (#4002) This is a very old canister using quite unsafe operations and it was only added as part of the old COW implementation of Orthogonal Persistence that we have long abandoned (and was never shipped to production). Instead of fixing the TODO (that would basically require switching the canister to use a saner approach wrt handling its state), remove the canister as it doesn't seem to be used anywhere else. --------- Co-authored-by: IDX GitHub Automation --- Cargo.lock | 11 --- Cargo.toml | 1 - rs/coverage.py | 1 - rs/rust_canisters/pmap/BUILD.bazel | 55 --------------- rs/rust_canisters/pmap/Cargo.toml | 31 --------- rs/rust_canisters/pmap/Readme.md | 3 - rs/rust_canisters/pmap/canister/main.rs | 88 ------------------------ rs/rust_canisters/pmap/canister/pmap.did | 7 -- rs/rust_canisters/pmap/src/main.rs | 1 - rs/rust_canisters/pmap/test/main.rs | 37 ---------- 10 files changed, 235 deletions(-) delete mode 100644 rs/rust_canisters/pmap/BUILD.bazel delete mode 100644 rs/rust_canisters/pmap/Cargo.toml delete mode 100644 rs/rust_canisters/pmap/Readme.md delete mode 100644 rs/rust_canisters/pmap/canister/main.rs delete mode 100644 rs/rust_canisters/pmap/canister/pmap.did delete mode 100644 rs/rust_canisters/pmap/src/main.rs delete mode 100644 rs/rust_canisters/pmap/test/main.rs diff --git a/Cargo.lock b/Cargo.lock index 036c118a31e..f784118aa9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17746,17 +17746,6 @@ dependencies = [ "plotters-backend", ] -[[package]] -name = "pmap" -version = "0.9.0" -dependencies = [ - "canister-test", - "dfn_core", - "dfn_json", - "dfn_macro", - "ic-utils 0.9.0", -] - [[package]] name = "pocket-ic" version = "6.0.0" diff --git a/Cargo.toml b/Cargo.toml index f1b5b9886de..e3e5a087fb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -323,7 +323,6 @@ members = [ "rs/rust_canisters/load_simulator", "rs/rust_canisters/memory_test", "rs/rust_canisters/on_wire", - "rs/rust_canisters/pmap", "rs/rust_canisters/proxy_canister", "rs/rust_canisters/response_payload_test", "rs/rust_canisters/stable_reader", diff --git a/rs/coverage.py b/rs/coverage.py index c0b2f042faf..68fab707b5d 100755 --- a/rs/coverage.py +++ b/rs/coverage.py @@ -28,7 +28,6 @@ "registry-canister", # Run from wrong directory "rust-canister-tests", # Runs too slow "ledger-canister", # Runs too slow - "pmap", # Can not be compiled natively "dfn_core", # Can not be compiled natively ] diff --git a/rs/rust_canisters/pmap/BUILD.bazel b/rs/rust_canisters/pmap/BUILD.bazel deleted file mode 100644 index e4639a57082..00000000000 --- a/rs/rust_canisters/pmap/BUILD.bazel +++ /dev/null @@ -1,55 +0,0 @@ -load("@rules_rust//rust:defs.bzl", "rust_binary") -load("//bazel:canisters.bzl", "rust_canister") -load("//bazel:defs.bzl", "rust_ic_test") - -package(default_visibility = ["//visibility:public"]) - -DEPENDENCIES = [ - # Keep sorted. - "//rs/rust_canisters/dfn_core", - "//rs/rust_canisters/dfn_json", -] - -DEV_DEPENDENCIES = [ - # Keep sorted. - "//rs/rust_canisters/canister_test", - "//rs/utils", -] - -MACRO_DEPENDENCIES = [ - # Keep sorted. - "//rs/rust_canisters/dfn_macro", -] - -ALIASES = {} - -rust_binary( - name = "pmap", - srcs = ["src/main.rs"], - aliases = ALIASES, - proc_macro_deps = MACRO_DEPENDENCIES, - deps = DEPENDENCIES, -) - -rust_canister( - name = "pmap_canister", - srcs = ["canister/main.rs"], - aliases = ALIASES, - proc_macro_deps = MACRO_DEPENDENCIES, - service_file = ":canister/pmap.did", - deps = DEPENDENCIES, -) - -rust_ic_test( - name = "pmap_test", - srcs = ["test/main.rs"], - data = [ - ":pmap_canister", - ], - env = { - "CARGO_MANIFEST_DIR": "rs/rust_canisters/pmap", - "PMAP_CANISTER_WASM_PATH": "$(rootpath :pmap_canister)", - }, - proc_macro_deps = MACRO_DEPENDENCIES, - deps = DEPENDENCIES + DEV_DEPENDENCIES, -) diff --git a/rs/rust_canisters/pmap/Cargo.toml b/rs/rust_canisters/pmap/Cargo.toml deleted file mode 100644 index cd5a6a4c7d6..00000000000 --- a/rs/rust_canisters/pmap/Cargo.toml +++ /dev/null @@ -1,31 +0,0 @@ -[package] -name = "pmap" -version.workspace = true -authors.workspace = true -edition.workspace = true -description.workspace = true -documentation.workspace = true - -[dependencies] -# add dependencies that only canister uses here -dfn_core = { path = "../dfn_core" } -dfn_json = { path = "../dfn_json" } -dfn_macro = { path = "../dfn_macro" } - -[target.'cfg(not(target_os = "unknown"))'.dev-dependencies] -# add dependencies that only test driver uses -canister-test = { path = "../../rust_canisters/canister_test" } -ic-utils = { path = "../../utils" } - - -[[bin]] -name = "pmap" -path = "src/main.rs" - -[[bin]] -name = "pmap_canister" -path = "canister/main.rs" - -[[test]] -name = "test" -path = "test/main.rs" diff --git a/rs/rust_canisters/pmap/Readme.md b/rs/rust_canisters/pmap/Readme.md deleted file mode 100644 index 3f5a9a3ed78..00000000000 --- a/rs/rust_canisters/pmap/Readme.md +++ /dev/null @@ -1,3 +0,0 @@ -to run the test do : - -cargo test \ No newline at end of file diff --git a/rs/rust_canisters/pmap/canister/main.rs b/rs/rust_canisters/pmap/canister/main.rs deleted file mode 100644 index fbfbe9a8784..00000000000 --- a/rs/rust_canisters/pmap/canister/main.rs +++ /dev/null @@ -1,88 +0,0 @@ -// TODO: EXC-1841 -#![allow(static_mut_refs)] - -use dfn_core::api::print; -use dfn_macro::{query, update}; -use std::ptr::{addr_of, addr_of_mut}; - -static mut MYVEC: Vec = Vec::new(); -const ARRAYSIZE: usize = 10; -static mut TRAP: bool = false; - -#[update] -async fn create_array() -> Result { - unsafe { - MYVEC = vec![0; ARRAYSIZE]; - } - - print("Array created"); - Ok("Array created".into()) -} - -#[update] -async fn increment_array() -> Result { - unsafe { - if MYVEC.is_empty() { - return Err("Array not initialized".into()); - } else { - let hi = MYVEC[ARRAYSIZE - 1]; - let lo = MYVEC[0]; - - print(format!("Before increment hi {} lo {}", hi, lo)); - - for v in &mut *addr_of_mut!(MYVEC) { - *v += 1; - } - - let hi = MYVEC[ARRAYSIZE - 1]; - let lo = MYVEC[0]; - - print(format!("After increment hi {} lo {}", hi, lo)); - - if TRAP { - unreachable!() - } - } - } - print("Done !!! "); - Ok("Done !!! ".into()) -} - -#[query] -async fn compute_sum() -> Result { - unsafe { - if MYVEC.is_empty() { - Err("Array not initialized".into()) - } else { - let hi = MYVEC[ARRAYSIZE - 1]; - let lo = MYVEC[0]; - - print(format!("Compute sum hi {} lo {}", hi, lo)); - - let mut sum: u32 = 0; - - for v in &*addr_of!(MYVEC) { - sum += *v as u32; - } - - print(format!("Computed sum {}", sum)); - Ok(sum) - } - } -} - -#[update] -async fn toggle_trap() -> Result<(), String> { - unsafe { - TRAP = !TRAP; - } - Ok(()) -} - -#[query] -async fn test() -> Result { - print("hello world"); - Ok("Hello World".into()) -} - -fn main() {} diff --git a/rs/rust_canisters/pmap/canister/pmap.did b/rs/rust_canisters/pmap/canister/pmap.did deleted file mode 100644 index fdfb9b1af78..00000000000 --- a/rs/rust_canisters/pmap/canister/pmap.did +++ /dev/null @@ -1,7 +0,0 @@ -service : { - create_array : () -> (variant { Ok : text; Err : text }); - increment_array : () -> (variant { Ok : text; Err : text }); - compute_sum : () -> (variant { Ok : nat32; Err : text }) query; - toggle_trap : () -> (variant { Ok : null; Err : text }); - test : () -> (variant { Ok : text; Err : text }) query; -} \ No newline at end of file diff --git a/rs/rust_canisters/pmap/src/main.rs b/rs/rust_canisters/pmap/src/main.rs deleted file mode 100644 index f328e4d9d04..00000000000 --- a/rs/rust_canisters/pmap/src/main.rs +++ /dev/null @@ -1 +0,0 @@ -fn main() {} diff --git a/rs/rust_canisters/pmap/test/main.rs b/rs/rust_canisters/pmap/test/main.rs deleted file mode 100644 index cfc7fe10340..00000000000 --- a/rs/rust_canisters/pmap/test/main.rs +++ /dev/null @@ -1,37 +0,0 @@ -use canister_test::*; -use dfn_json::json; - -#[test] -fn test() { - local_test_e(|runtime| async move { - /////////////////////////////////////////////////////// - // Create a new instance of pmap - /////////////////////////////////////////////////////// - let proj = Project::new(); - - let create_canister = |c| proj.cargo_bin(c, &[]).install(&runtime).bytes(Vec::new()); - - let canister = create_canister("pmap_canister").await?; - - let res: Result = canister.query_("test", json, ()).await?; - assert!(res.is_ok()); - - let res: Result = canister.update_("create_array", json, ()).await?; - assert!(res.is_ok()); - - let res: Result = canister.update_("increment_array", json, ()).await?; - assert!(res.is_ok()); - - let res: Result = canister.update_("increment_array", json, ()).await?; - assert!(res.is_ok()); - - let res: Result = canister.update_("compute_sum", json, ()).await?; - assert_eq!(res, Ok(20)); - - let res: Result = canister.query_("test", json, ()).await?; - assert!(res.is_ok()); - Ok(()) - }); -} - -fn main() {}