From 0774c2fb42bc4196f0324a521ba97feb50ca25f1 Mon Sep 17 00:00:00 2001 From: Stanislav Tkach Date: Thu, 2 Jan 2025 18:17:47 +0100 Subject: [PATCH 1/3] Enable the 'arithmetic_side_effects' Clippy lint --- catalyst-gateway/Cargo.toml | 3 ++- catalyst-gateway/bin/Cargo.toml | 2 +- catalyst-gateway/bin/src/cardano/mod.rs | 21 ++++++++++++------- .../src/db/index/queries/sync_status/get.rs | 2 +- .../service/api/cardano/staking/assets_get.rs | 10 +++++++-- .../bin/src/service/common/auth/rbac/token.rs | 8 ++++++- .../bin/src/settings/chain_follower.rs | 7 ++++++- catalyst-gateway/clippy.toml | 1 + 8 files changed, 39 insertions(+), 15 deletions(-) diff --git a/catalyst-gateway/Cargo.toml b/catalyst-gateway/Cargo.toml index b819a6f6ca0..e0810b46c85 100644 --- a/catalyst-gateway/Cargo.toml +++ b/catalyst-gateway/Cargo.toml @@ -48,4 +48,5 @@ panic = "deny" string_slice = "deny" unchecked_duration_subtraction = "deny" unreachable = "deny" -missing_docs_in_private_items = "deny" \ No newline at end of file +missing_docs_in_private_items = "deny" +arithmetic_side_effects = "deny" diff --git a/catalyst-gateway/bin/Cargo.toml b/catalyst-gateway/bin/Cargo.toml index 75c578f6d92..4edb2e6dd3b 100644 --- a/catalyst-gateway/bin/Cargo.toml +++ b/catalyst-gateway/bin/Cargo.toml @@ -15,7 +15,7 @@ repository.workspace = true workspace = true [dependencies] -cardano-chain-follower = { version = "0.0.6", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "v0.0.10" } +cardano-chain-follower = {version = "0.0.6", git = "https://github.com/input-output-hk/catalyst-libs.git", tag="v0.0.10" } c509-certificate = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "v0.0.3" } rbac-registration = { version = "0.0.2", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "v0.0.8" } diff --git a/catalyst-gateway/bin/src/cardano/mod.rs b/catalyst-gateway/bin/src/cardano/mod.rs index 41e775865f4..4656961a416 100644 --- a/catalyst-gateway/bin/src/cardano/mod.rs +++ b/catalyst-gateway/bin/src/cardano/mod.rs @@ -158,7 +158,7 @@ impl SyncParams { /// Convert a result back into parameters for a retry. fn retry(&self) -> Self { - let retry_count = self.retries + 1; + let retry_count = self.retries.saturating_add(1); let mut backoff = None; @@ -200,7 +200,7 @@ impl SyncParams { done.first_is_immutable = first_immutable; done.last_indexed_block = last; done.last_is_immutable = last_immutable; - done.total_blocks_synced += synced; + done.total_blocks_synced = done.total_blocks_synced.saturating_add(synced); done.last_blocks_synced = synced; done.result = Arc::new(Some(result)); @@ -298,7 +298,7 @@ fn sync_subchain(params: SyncParams) -> tokio::task::JoinHandle { first_immutable = last_immutable; first_indexed_block = Some(block.point()); } - blocks_synced += 1; + blocks_synced = blocks_synced.saturating_add(1); }, cardano_chain_follower::Kind::Rollback => { warn!("TODO: Live Chain rollback"); @@ -423,7 +423,11 @@ impl SyncTask { } else if let Some(result) = finished.result.as_ref() { match result { Ok(()) => { - self.current_sync_tasks -= 1; + self.current_sync_tasks = + self.current_sync_tasks.checked_sub(1).unwrap_or_else(|| { + error!("current_sync_tasks -= 1 overflow"); + 0 + }); info!(chain=%self.cfg.chain, report=%finished, "The Immutable follower completed successfully."); @@ -472,9 +476,10 @@ impl SyncTask { if self.start_slot < self.immutable_tip_slot { // Will also break if there are no more slots left to sync. while self.current_sync_tasks < self.cfg.sync_tasks { - let end_slot = self - .immutable_tip_slot - .min(self.start_slot + self.cfg.sync_chunk_max_slots); + let end_slot = self.immutable_tip_slot.min( + self.start_slot + .saturating_add(self.cfg.sync_chunk_max_slots), + ); if let Some((first_point, last_point)) = self.get_syncable_range(self.start_slot, end_slot) @@ -484,7 +489,7 @@ impl SyncTask { first_point, last_point.clone(), ))); - self.current_sync_tasks += 1; + self.current_sync_tasks = self.current_sync_tasks.saturating_add(1); } // The one slot overlap is deliberate, it doesn't hurt anything and prevents all off diff --git a/catalyst-gateway/bin/src/db/index/queries/sync_status/get.rs b/catalyst-gateway/bin/src/db/index/queries/sync_status/get.rs index 2371a1378cf..819b58c9ffe 100644 --- a/catalyst-gateway/bin/src/db/index/queries/sync_status/get.rs +++ b/catalyst-gateway/bin/src/db/index/queries/sync_status/get.rs @@ -50,7 +50,7 @@ fn merge_consecutive_sync_records(mut synced_chunks: Vec) -> Vec token_age) + let Some(min_time) = now.checked_sub(max_age) else { + return false; + }; + let Some(max_time) = now.checked_add(max_skew) else { + return false; + }; + (min_time < token_age) && (max_time > token_age) } } diff --git a/catalyst-gateway/bin/src/settings/chain_follower.rs b/catalyst-gateway/bin/src/settings/chain_follower.rs index 2159e31681e..b6fd3968feb 100644 --- a/catalyst-gateway/bin/src/settings/chain_follower.rs +++ b/catalyst-gateway/bin/src/settings/chain_follower.rs @@ -92,7 +92,12 @@ impl EnvVars { default_dl_chunk_size, 1, MAX_DL_CHUNK_SIZE, - ) * ONE_MEGABYTE; + ) + .checked_mul(ONE_MEGABYTE) + .unwrap_or_else(|| { + info!("Too big 'CHAIN_FOLLOWER_DL_CHUNK_SIZE' value, default value {default_dl_chunk_size} is used"); + default_dl_chunk_size + }); dl_config = dl_config.with_chunk_size(chunk_size); let queue_ahead = StringEnvVar::new_as( diff --git a/catalyst-gateway/clippy.toml b/catalyst-gateway/clippy.toml index 0358cdb508c..f718e8c024b 100644 --- a/catalyst-gateway/clippy.toml +++ b/catalyst-gateway/clippy.toml @@ -1,2 +1,3 @@ allow-unwrap-in-tests = true allow-expect-in-tests = true +arithmetic-side-effects-allowed-binary = [["num_bigint::BigInt", "*"]] From 0fd2020833c33a08fefd8929a3a814d2e69cee16 Mon Sep 17 00:00:00 2001 From: Stanislav Tkach Date: Fri, 3 Jan 2025 17:56:59 +0100 Subject: [PATCH 2/3] Update catalyst-ci version --- catalyst-gateway/Earthfile | 2 +- catalyst-gateway/clippy.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/catalyst-gateway/Earthfile b/catalyst-gateway/Earthfile index bde5adb213f..744d387f833 100644 --- a/catalyst-gateway/Earthfile +++ b/catalyst-gateway/Earthfile @@ -1,6 +1,6 @@ VERSION 0.8 -IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.24 AS rust-ci +IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:enable-arithmetic-side-effects-clippy-lint AS rust-ci #cspell: words rustfmt toolsets USERARCH stdcfgs diff --git a/catalyst-gateway/clippy.toml b/catalyst-gateway/clippy.toml index f718e8c024b..a4a4797246a 100644 --- a/catalyst-gateway/clippy.toml +++ b/catalyst-gateway/clippy.toml @@ -1,3 +1,3 @@ allow-unwrap-in-tests = true allow-expect-in-tests = true -arithmetic-side-effects-allowed-binary = [["num_bigint::BigInt", "*"]] +arithmetic-side-effects-allowed = ["num_bigint::BigInt"] From 6078b145c7a8c0f8c181c7d344f0ffcc842599a6 Mon Sep 17 00:00:00 2001 From: Stanislav Tkach Date: Mon, 6 Jan 2025 17:45:33 +0100 Subject: [PATCH 3/3] Update the catalyst-ci version --- catalyst-gateway/Earthfile | 2 +- .../packages/libs/catalyst_key_derivation/rust/Cargo.toml | 3 ++- .../packages/libs/catalyst_key_derivation/rust/Earthfile | 2 +- .../packages/libs/catalyst_key_derivation/rust/clippy.toml | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/catalyst-gateway/Earthfile b/catalyst-gateway/Earthfile index 1abe9bb16b2..5ccd7eae33d 100644 --- a/catalyst-gateway/Earthfile +++ b/catalyst-gateway/Earthfile @@ -1,6 +1,6 @@ VERSION 0.8 -IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:enable-arithmetic-side-effects-clippy-lint AS rust-ci +IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.28 AS rust-ci #cspell: words rustfmt toolsets USERARCH stdcfgs diff --git a/catalyst_voices/packages/libs/catalyst_key_derivation/rust/Cargo.toml b/catalyst_voices/packages/libs/catalyst_key_derivation/rust/Cargo.toml index 48f6c3ce379..fbc58da51e3 100644 --- a/catalyst_voices/packages/libs/catalyst_key_derivation/rust/Cargo.toml +++ b/catalyst_voices/packages/libs/catalyst_key_derivation/rust/Cargo.toml @@ -56,4 +56,5 @@ panic = "deny" string_slice = "deny" unchecked_duration_subtraction = "deny" unreachable = "deny" -missing_docs_in_private_items = "deny" \ No newline at end of file +missing_docs_in_private_items = "deny" +arithmetic_side_effects = "deny" diff --git a/catalyst_voices/packages/libs/catalyst_key_derivation/rust/Earthfile b/catalyst_voices/packages/libs/catalyst_key_derivation/rust/Earthfile index af92fbbf323..992c7a6c0e6 100644 --- a/catalyst_voices/packages/libs/catalyst_key_derivation/rust/Earthfile +++ b/catalyst_voices/packages/libs/catalyst_key_derivation/rust/Earthfile @@ -1,6 +1,6 @@ VERSION 0.8 -IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.27 AS rust-ci +IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.28 AS rust-ci IMPORT ../ AS flutter-rust-bridge # builder : Setup the builder diff --git a/catalyst_voices/packages/libs/catalyst_key_derivation/rust/clippy.toml b/catalyst_voices/packages/libs/catalyst_key_derivation/rust/clippy.toml index 7bada5473be..caa289b27b2 100644 --- a/catalyst_voices/packages/libs/catalyst_key_derivation/rust/clippy.toml +++ b/catalyst_voices/packages/libs/catalyst_key_derivation/rust/clippy.toml @@ -1,3 +1,4 @@ allow-unwrap-in-tests = true allow-expect-in-tests = true allow-panic-in-tests = true +arithmetic-side-effects-allowed = ["num_bigint::BigInt"]