diff --git a/Cargo.lock b/Cargo.lock index 44d9c32910a..364d3919585 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17137,17 +17137,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 4a3f645d2a1..a46bff8ba76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -320,7 +320,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/packages/pocket-ic/src/lib.rs b/packages/pocket-ic/src/lib.rs index 393be384e36..cbcbc668a2a 100644 --- a/packages/pocket-ic/src/lib.rs +++ b/packages/pocket-ic/src/lib.rs @@ -1637,7 +1637,8 @@ To download the binary, please visit https://github.com/dfinity/pocketic." cmd.stderr(std::process::Stdio::null()); } } - cmd.spawn() + let process = cmd + .spawn() .unwrap_or_else(|_| panic!("Failed to start PocketIC binary ({:?})", bin_path)); loop { @@ -1652,6 +1653,9 @@ To download the binary, please visit https://github.com/dfinity/pocketic." } std::thread::sleep(Duration::from_millis(20)); } + + process.kill(); + process.wait().unwrap(); } #[derive(Error, Debug)] diff --git a/rs/artifact_pool/src/rocksdb_pool.rs b/rs/artifact_pool/src/rocksdb_pool.rs index ab35775a2f0..0c89925857b 100755 --- a/rs/artifact_pool/src/rocksdb_pool.rs +++ b/rs/artifact_pool/src/rocksdb_pool.rs @@ -568,7 +568,7 @@ fn deserialize_consensus_artifact( impl PoolSection for PersistentHeightIndexedPool { fn contains(&self, msg_id: &ConsensusMessageId) -> bool { - self.lookup_key(msg_id).map_or(false, |key| { + self.lookup_key(msg_id).is_some_and(|key| { let info = info_for_msg_id(msg_id); let cf_handle = check_not_none_uw!(self.db.cf_handle(info.name)); check_ok_uw!(self.db.get_pinned_cf(cf_handle, &key)).is_some() diff --git a/rs/canister_sandbox/src/rpc.rs b/rs/canister_sandbox/src/rpc.rs index 8cdef287c94..4dc06be5d51 100644 --- a/rs/canister_sandbox/src/rpc.rs +++ b/rs/canister_sandbox/src/rpc.rs @@ -5,7 +5,6 @@ use std::task::{Context, Poll}; /// Pieces for a very simple bidirectional RPC using an underlying /// duplex stream channel. - /// Describe RPC error -- can be either related to transport (i.e. /// failure to transport or parse a message) or to server (i.e. server /// responded, but gave us a message indicating an error). @@ -276,7 +275,6 @@ impl MessageSink for ReplyManager { /// An RPC result that is immediately "ready" (i.e. pass a value to /// a caller such that it does not need to wait). - pub struct ReadyResult { value: Mutex>, } diff --git a/rs/consensus/src/consensus/malicious_consensus.rs b/rs/consensus/src/consensus/malicious_consensus.rs index 5a9e5be9300..71e80f00c64 100644 --- a/rs/consensus/src/consensus/malicious_consensus.rs +++ b/rs/consensus/src/consensus/malicious_consensus.rs @@ -234,7 +234,6 @@ fn maliciously_notarize_all(notary: &Notary, pool: &PoolReader<'_>) -> Vec, diff --git a/rs/embedders/src/wasmtime_embedder/system_api_complexity.rs b/rs/embedders/src/wasmtime_embedder/system_api_complexity.rs index 4dc8a107589..304520fd6b8 100644 --- a/rs/embedders/src/wasmtime_embedder/system_api_complexity.rs +++ b/rs/embedders/src/wasmtime_embedder/system_api_complexity.rs @@ -1,7 +1,6 @@ /// /// System API Calls Complexity Module /// - /// The Fixed System API Overhead (in Instructions) /// /// The cost of the System API calls is proportional to the work the call performs. diff --git a/rs/execution_environment/src/canister_manager.rs b/rs/execution_environment/src/canister_manager.rs index 14877845010..6dd8409b862 100644 --- a/rs/execution_environment/src/canister_manager.rs +++ b/rs/execution_environment/src/canister_manager.rs @@ -912,7 +912,7 @@ impl CanisterManager { return false; } }; - module.memories.first().map_or(false, |m| m.memory64) + module.memories.first().is_some_and(|m| m.memory64) } /// Installs code to a canister. @@ -2190,9 +2190,7 @@ impl CanisterManager { .certified_data .clone_from(snapshot.certified_data()); - let is_wasm64_execution = new_execution_state - .as_ref() - .map_or(false, |es| es.is_wasm64); + let is_wasm64_execution = new_execution_state.as_ref().is_some_and(|es| es.is_wasm64); let mut new_canister = CanisterState::new(system_state, new_execution_state, scheduler_state); diff --git a/rs/execution_environment/src/execution/replicated_query.rs b/rs/execution_environment/src/execution/replicated_query.rs index b3b38b83fe7..a63c115e8d4 100644 --- a/rs/execution_environment/src/execution/replicated_query.rs +++ b/rs/execution_environment/src/execution/replicated_query.rs @@ -48,7 +48,7 @@ pub fn execute_replicated_query( let is_wasm64_execution = canister .execution_state .as_ref() - .map_or(false, |es| es.is_wasm64); + .is_some_and(|es| es.is_wasm64); let prepaid_execution_cycles = match round.cycles_account_manager.prepay_execution_cycles( &mut canister.system_state, diff --git a/rs/execution_environment/src/execution/response.rs b/rs/execution_environment/src/execution/response.rs index 7d41f7ddac1..ca8963046e7 100644 --- a/rs/execution_environment/src/execution/response.rs +++ b/rs/execution_environment/src/execution/response.rs @@ -101,7 +101,6 @@ const RESERVED_CLEANUP_INSTRUCTIONS_IN_PERCENT: u64 = 5; /// ▼ /// [end] ///``` - /// Contains fields of `ResponseHelper` that are necessary for resuming the /// response execution. #[derive(Debug)] @@ -575,7 +574,7 @@ impl ResponseHelper { .canister .execution_state .as_ref() - .map_or(false, |es| es.is_wasm64); + .is_some_and(|es| es.is_wasm64); round.cycles_account_manager.refund_unused_execution_cycles( &mut self.canister.system_state, diff --git a/rs/execution_environment/src/execution/update.rs b/rs/execution_environment/src/execution/update.rs index 6e8b5098d48..702d008229b 100644 --- a/rs/execution_environment/src/execution/update.rs +++ b/rs/execution_environment/src/execution/update.rs @@ -63,7 +63,7 @@ pub fn execute_update( let is_wasm64_execution = canister .execution_state .as_ref() - .map_or(false, |es| es.is_wasm64); + .is_some_and(|es| es.is_wasm64); let prepaid_execution_cycles = match round .cycles_account_manager @@ -268,7 +268,7 @@ fn finish_err( let is_wasm64_execution = canister .execution_state .as_ref() - .map_or(false, |es| es.is_wasm64); + .is_some_and(|es| es.is_wasm64); let instruction_limit = original.execution_parameters.instruction_limits.message(); round.cycles_account_manager.refund_unused_execution_cycles( @@ -537,7 +537,7 @@ impl UpdateHelper { .canister .execution_state .as_ref() - .map_or(false, |es| es.is_wasm64); + .is_some_and(|es| es.is_wasm64); round.cycles_account_manager.refund_unused_execution_cycles( &mut self.canister.system_state, diff --git a/rs/execution_environment/src/execution/upgrade.rs b/rs/execution_environment/src/execution/upgrade.rs index 924fed0cdf0..9bad4929b70 100644 --- a/rs/execution_environment/src/execution/upgrade.rs +++ b/rs/execution_environment/src/execution/upgrade.rs @@ -884,7 +884,7 @@ fn determine_main_memory_handling( let old_state_uses_orthogonal_persistence = || { old_state .as_ref() - .map_or(false, expects_enhanced_orthogonal_persistence) + .is_some_and(expects_enhanced_orthogonal_persistence) }; let new_state_uses_classical_persistence = || { new_state_candidate.is_ok() diff --git a/rs/execution_environment/src/hypervisor.rs b/rs/execution_environment/src/hypervisor.rs index 4e472eff012..b67705512da 100644 --- a/rs/execution_environment/src/hypervisor.rs +++ b/rs/execution_environment/src/hypervisor.rs @@ -535,11 +535,11 @@ impl Hypervisor { if let Err(err) = &mut result.wasm_result { let can_view = match &system_state.log_visibility { LogVisibilityV2::Controllers => { - caller.map_or(false, |c| system_state.controllers.contains(&c)) + caller.is_some_and(|c| system_state.controllers.contains(&c)) } LogVisibilityV2::Public => true, LogVisibilityV2::AllowedViewers(allowed) => { - caller.map_or(false, |c| allowed.get().contains(&c)) + caller.is_some_and(|c| allowed.get().contains(&c)) } }; if !can_view { diff --git a/rs/execution_environment/src/scheduler.rs b/rs/execution_environment/src/scheduler.rs index bd7a475ef66..3ebadda7d5f 100644 --- a/rs/execution_environment/src/scheduler.rs +++ b/rs/execution_environment/src/scheduler.rs @@ -138,7 +138,6 @@ impl SchedulerRoundLimits { //////////////////////////////////////////////////////////////////////// /// Scheduler Implementation - pub(crate) struct SchedulerImpl { config: SchedulerConfig, own_subnet_id: SubnetId, @@ -222,7 +221,7 @@ impl SchedulerImpl { state = new_state; ongoing_long_install_code |= state .canister_state(canister_id) - .map_or(false, |canister| canister.has_paused_install_code()); + .is_some_and(|canister| canister.has_paused_install_code()); let round_instructions_executed = as_num_instructions(instructions_before - round_limits.instructions); @@ -1658,7 +1657,7 @@ impl Scheduler for SchedulerImpl { //////////////////////////////////////////////////////////////////////// /// Filtered Canisters - +/// /// This struct represents a collection of canister IDs. struct FilteredCanisters { /// Active canisters during the execution of the inner round. @@ -1823,7 +1822,7 @@ fn execute_canisters_on_thread( &mut round_limits, subnet_size, ); - if instructions_used.map_or(false, |instructions| instructions.get() > 0) { + if instructions_used.is_some_and( |instructions| instructions.get() > 0) { // We only want to count the canister as executed if it used instructions. executed_canister_ids.insert(new_canister.canister_id()); } @@ -2324,7 +2323,7 @@ fn is_next_method_chosen( .system_state .task_queue .front() - .map_or(false, |task| task.is_hook()) + .is_some_and( |task| task.is_hook()) { return true; } diff --git a/rs/execution_environment/tests/hypervisor.rs b/rs/execution_environment/tests/hypervisor.rs index 7f9f649b104..a7a27426517 100644 --- a/rs/execution_environment/tests/hypervisor.rs +++ b/rs/execution_environment/tests/hypervisor.rs @@ -7587,7 +7587,7 @@ fn declaring_too_many_tables_fails() { fn use_wasm_memory_and_reply(bytes: u64) -> Vec { wasm() .stable64_grow( - (bytes + WASM_PAGE_SIZE_IN_BYTES as u64 - 1) / WASM_PAGE_SIZE_IN_BYTES as u64, + bytes.div_ceil(WASM_PAGE_SIZE_IN_BYTES as u64), ) .stable64_read(0, bytes) .blob_length() diff --git a/rs/messaging/tests/queue_tests.rs b/rs/messaging/tests/queue_tests.rs index a800f92b97f..2107d111210 100644 --- a/rs/messaging/tests/queue_tests.rs +++ b/rs/messaging/tests/queue_tests.rs @@ -204,7 +204,7 @@ impl SubnetPairProxy { do_until_or_panic(MAX_TICKS, |_| { let exit_condition = self .local_output_queue_snapshot() - .map_or(false, |q| q.len() >= min_num_messages); + .is_some_and(|q| q.len() >= min_num_messages); if !exit_condition { self.local_env.tick(); } diff --git a/rs/nns/governance/src/governance.rs b/rs/nns/governance/src/governance.rs index a4add42fe8a..b5c9845c045 100644 --- a/rs/nns/governance/src/governance.rs +++ b/rs/nns/governance/src/governance.rs @@ -1057,7 +1057,7 @@ impl Proposal { fn allowed_when_resources_are_low(&self) -> bool { self.action .as_ref() - .map_or(false, |a| a.allowed_when_resources_are_low()) + .is_some_and(|a| a.allowed_when_resources_are_low()) } fn omit_large_fields(self) -> Self { @@ -1177,7 +1177,7 @@ impl ProposalData { pub fn is_manage_neuron(&self) -> bool { self.proposal .as_ref() - .map_or(false, Proposal::is_manage_neuron) + .is_some_and(Proposal::is_manage_neuron) } pub fn reward_status( @@ -1938,6 +1938,10 @@ fn spawn_in_canister_env(future: impl Future + Sized + 'static) { } } +fn error_string_to_governance_error(error: String) -> GovernanceError { + GovernanceError::new_with_message(ErrorType::InvalidProposal, error) +} + impl Governance { /// Creates a new Governance instance with uninitialized fields. The canister should only have /// such state before the state is recovered from the stable memory in post_upgrade or @@ -5308,12 +5312,6 @@ impl Governance { } fn validate_proposal(&self, proposal: &Proposal) -> Result { - impl From for GovernanceError { - fn from(message: String) -> Self { - Self::new_with_message(ErrorType::InvalidProposal, message) - } - } - if proposal.topic() == Topic::Unspecified { Err(format!("Topic not specified. proposal: {:#?}", proposal))?; } diff --git a/rs/nns/governance/src/known_neuron_index.rs b/rs/nns/governance/src/known_neuron_index.rs index bc22e08b3d1..15c52982e92 100644 --- a/rs/nns/governance/src/known_neuron_index.rs +++ b/rs/nns/governance/src/known_neuron_index.rs @@ -8,7 +8,6 @@ use ic_stable_structures::{Memory, StableBTreeMap, Storable}; /// Note that the index only cares about the uniqueness of the names, not the ids - /// the caller should make sure the name-id is removed from the index when a neuron /// is removed or its name is changed. - pub struct KnownNeuronIndex { known_neuron_name_to_id: StableBTreeMap, } diff --git a/rs/registry/admin/src/main.rs b/rs/registry/admin/src/main.rs index c32e582296d..ca2abbcfd09 100644 --- a/rs/registry/admin/src/main.rs +++ b/rs/registry/admin/src/main.rs @@ -5962,7 +5962,7 @@ struct GovernanceCanisterClient(NnsCanisterClient); struct RootCanisterClient(NnsCanisterClient); fn is_mainnet(url: &Url) -> bool { - url.domain().map_or(false, |domain| { + url.domain().is_some_and(|domain| { IC_DOMAINS .iter() .any(|&ic_domain| domain.contains(ic_domain)) diff --git a/rs/rosetta-api/icp/src/convert.rs b/rs/rosetta-api/icp/src/convert.rs index d15d8496331..f24984635b5 100644 --- a/rs/rosetta-api/icp/src/convert.rs +++ b/rs/rosetta-api/icp/src/convert.rs @@ -36,7 +36,6 @@ use std::convert::{TryFrom, TryInto}; /// This module converts from ledger_canister data structures to Rosetta data /// structures - pub fn to_rosetta_core_transaction( transaction_index: BlockIndex, transaction: Transaction, diff --git a/rs/rosetta-api/icp/tests/integration_tests/tests/tests.rs b/rs/rosetta-api/icp/tests/integration_tests/tests/tests.rs index 9461ff50c0f..bafc1b14a30 100644 --- a/rs/rosetta-api/icp/tests/integration_tests/tests/tests.rs +++ b/rs/rosetta-api/icp/tests/integration_tests/tests/tests.rs @@ -412,7 +412,7 @@ fn matches_blockchain_is_empty_error(error: &rosetta_core::miscellaneous::Error) .as_ref() .unwrap() .get("error_message") - .map_or(false, |e| { + .is_some_and( |e| { e == "Blockchain is empty" || e == "Block not found: 0" || e == "RosettaBlocks was activated and there are no RosettaBlocks in the database yet. The synch is ongoing, please wait until the first RosettaBlock is written to the database." }) } 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 9bf061382c9..00000000000 --- a/rs/rust_canisters/pmap/canister/main.rs +++ /dev/null @@ -1,85 +0,0 @@ -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() {} diff --git a/rs/rust_canisters/random_traffic_test/src/main.rs b/rs/rust_canisters/random_traffic_test/src/main.rs index ce928a0553e..9dff81803fc 100644 --- a/rs/rust_canisters/random_traffic_test/src/main.rs +++ b/rs/rust_canisters/random_traffic_test/src/main.rs @@ -265,7 +265,7 @@ async fn handle_call(msg: Message) -> Vec { fn should_make_downstream_call() -> bool { RNG.with_borrow_mut(|rng| { WeightedIndex::new([CALL_WEIGHT.get(), REPLY_WEIGHT.get()]) - .map_or(false, |dist| dist.sample(rng) == 0) + .is_some_and(|dist| dist.sample(rng) == 0) }) } diff --git a/rs/sns/governance/src/proposal.rs b/rs/sns/governance/src/proposal.rs index 6aaae38eddc..41a24a5c0f6 100644 --- a/rs/sns/governance/src/proposal.rs +++ b/rs/sns/governance/src/proposal.rs @@ -104,7 +104,7 @@ impl Proposal { pub(crate) fn allowed_when_resources_are_low(&self) -> bool { self.action .as_ref() - .map_or(false, |a| a.allowed_when_resources_are_low()) + .is_some_and(|a| a.allowed_when_resources_are_low()) } /// Returns a clone of self, except that "large blob fields" are replaced diff --git a/rs/state_manager/src/manifest/tests/computation.rs b/rs/state_manager/src/manifest/tests/computation.rs index 53b7856a836..6ae1413da2b 100644 --- a/rs/state_manager/src/manifest/tests/computation.rs +++ b/rs/state_manager/src/manifest/tests/computation.rs @@ -402,7 +402,7 @@ fn test_validate_sub_manifest() { let encoded_manifest = encode_manifest(&manifest); let num = - (encoded_manifest.len() + DEFAULT_CHUNK_SIZE as usize - 1) / DEFAULT_CHUNK_SIZE as usize; + encoded_manifest.len().div_ceil(DEFAULT_CHUNK_SIZE as usize); assert!( num > 1, "This test does not cover the case where the encoded manifest is divided into multiple pieces." diff --git a/rs/tests/consensus/orchestrator/rotate_ecdsa_idkg_key_test.rs b/rs/tests/consensus/orchestrator/rotate_ecdsa_idkg_key_test.rs index 69bf064dea9..9698ce6611a 100644 --- a/rs/tests/consensus/orchestrator/rotate_ecdsa_idkg_key_test.rs +++ b/rs/tests/consensus/orchestrator/rotate_ecdsa_idkg_key_test.rs @@ -242,7 +242,7 @@ fn test(env: TestEnv) { assert!(last_rotation .duration_since(first_rotation) - .map_or(false, |d| d + gamma <= delta)); + .is_some_and(|d| d + gamma <= delta)); // Ensure signing still works for (key_id, public_key) in public_keys { diff --git a/rs/tests/consensus/orchestrator/unstuck_subnet_test.rs b/rs/tests/consensus/orchestrator/unstuck_subnet_test.rs index 97cb79cd63b..9f8f5f76692 100644 --- a/rs/tests/consensus/orchestrator/unstuck_subnet_test.rs +++ b/rs/tests/consensus/orchestrator/unstuck_subnet_test.rs @@ -205,7 +205,7 @@ fn test(test_env: TestEnv) { fn have_sha_errors(session: &Session) -> bool { let cmd = "journalctl | grep -c 'FileHashMismatchError'".to_string(); - execute_bash_command(session, cmd).map_or(false, |res| res.trim().parse::().unwrap() > 0) + execute_bash_command(session, cmd).is_some_and(|res| res.trim().parse::().unwrap() > 0) } fn main() -> Result<()> { diff --git a/rs/tests/consensus/subnet_recovery/common.rs b/rs/tests/consensus/subnet_recovery/common.rs index 4106012edd8..77c960d9aec 100644 --- a/rs/tests/consensus/subnet_recovery/common.rs +++ b/rs/tests/consensus/subnet_recovery/common.rs @@ -573,7 +573,7 @@ fn halt_subnet( message.cursor ), ); - if res.map_or(false, |r| r.trim().parse::().unwrap() > 0) { + if res.is_some_and(|r| r.trim().parse::().unwrap() > 0) { Ok(()) } else { bail!("Did not find log entry that consensus is halted.") @@ -660,7 +660,7 @@ fn corrupt_latest_cup(subnet: &SubnetSnapshot, recovery: &Recovery, logger: &Log message.cursor ), ); - if res.map_or(false, |r| r.trim().parse::().unwrap() > 0) { + if resis_some_and( |r| r.trim().parse::().unwrap() > 0) { Ok(()) } else { bail!("Did not find log entry that cup is corrupted.")