From 729f455e8053f998cd851ea8a3d1edf8fb2da033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Mon, 19 May 2025 11:58:53 +0100 Subject: [PATCH] clippy --- .../mixnet-contract/src/key_rotation.rs | 3 +- common/http-api-client/src/lib.rs | 3 + common/nymsphinx/params/src/packet_version.rs | 4 +- common/topology/src/wasm_helpers.rs | 11 ++- .../mixnet/schema/nym-mixnet-contract.json | 68 +++++++++++++++++++ contracts/mixnet/schema/raw/query.json | 28 ++++++++ .../raw/response_to_get_key_rotation_id.json | 16 +++++ .../response_to_get_key_rotation_state.json | 24 +++++++ contracts/mixnet/src/rewards/transactions.rs | 2 + contracts/mixnet/src/support/tests/mod.rs | 5 ++ contracts/mixnet/src/vesting_migration.rs | 1 + nym-node/src/node/key_rotation/controller.rs | 3 - .../src/node/replay_protection/bloomfilter.rs | 9 ++- 13 files changed, 165 insertions(+), 12 deletions(-) create mode 100644 contracts/mixnet/schema/raw/response_to_get_key_rotation_id.json create mode 100644 contracts/mixnet/schema/raw/response_to_get_key_rotation_state.json diff --git a/common/cosmwasm-smart-contracts/mixnet-contract/src/key_rotation.rs b/common/cosmwasm-smart-contracts/mixnet-contract/src/key_rotation.rs index de3f05d241..9c5900c612 100644 --- a/common/cosmwasm-smart-contracts/mixnet-contract/src/key_rotation.rs +++ b/common/cosmwasm-smart-contracts/mixnet-contract/src/key_rotation.rs @@ -22,8 +22,7 @@ pub struct KeyRotationState { impl KeyRotationState { pub fn key_rotation_id(&self, current_epoch_id: EpochId) -> KeyRotationId { let diff = current_epoch_id.saturating_sub(self.initial_epoch_id); - let full_rots = diff / self.validity_epochs; - full_rots + diff / self.validity_epochs } pub fn next_rotation_starting_epoch_id(&self, current_epoch_id: EpochId) -> EpochId { diff --git a/common/http-api-client/src/lib.rs b/common/http-api-client/src/lib.rs index 0ae63b62f4..4407260adf 100644 --- a/common/http-api-client/src/lib.rs +++ b/common/http-api-client/src/lib.rs @@ -606,6 +606,9 @@ impl Client { Client { base_url: new_url, reqwest_client: self.reqwest_client.clone(), + + #[cfg(target_arch = "wasm32")] + request_timeout: self.request_timeout, } } diff --git a/common/nymsphinx/params/src/packet_version.rs b/common/nymsphinx/params/src/packet_version.rs index 76c1957a54..02492ea77a 100644 --- a/common/nymsphinx/params/src/packet_version.rs +++ b/common/nymsphinx/params/src/packet_version.rs @@ -10,8 +10,8 @@ use thiserror::Error; // - packet_version (starting with v1.1.0) // - packet_size indicator // - packet_type -// - sphinx key rotation (starting with v1.11.0) -const TODO: &str = "update the ^ version number when this PR is almost ready"; +// - sphinx key rotation (starting with v1.12.0/v1.13.0 - either Cheddar or Dolcelatte release) + // it also just so happens that the only valid values for packet_size indicator include values 1-6 // therefore if we receive byte `7` (or larger than that) we'll know we received a versioned packet, // otherwise we should treat it as legacy diff --git a/common/topology/src/wasm_helpers.rs b/common/topology/src/wasm_helpers.rs index ecb451e8be..5ebce45455 100644 --- a/common/topology/src/wasm_helpers.rs +++ b/common/topology/src/wasm_helpers.rs @@ -5,7 +5,7 @@ #![allow(clippy::empty_docs)] use crate::node::{EntryDetails, RoutingNode, RoutingNodeError, SupportedRoles}; -use crate::{CachedEpochRewardedSet, NymTopology}; +use crate::{CachedEpochRewardedSet, NymTopology, NymTopologyMetadata}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::net::SocketAddr; @@ -38,6 +38,8 @@ impl From for JsValue { #[serde(rename_all = "camelCase")] #[serde(deny_unknown_fields)] pub struct WasmFriendlyNymTopology { + pub metadata: NymTopologyMetadata, + pub rewarded_set: CachedEpochRewardedSet, pub node_details: HashMap, @@ -53,13 +55,18 @@ impl TryFrom for NymTopology { .map(|details| details.try_into()) .collect::>()?; - Ok(NymTopology::new(value.rewarded_set, node_details)) + Ok(NymTopology::new( + value.metadata, + value.rewarded_set, + node_details, + )) } } impl From for WasmFriendlyNymTopology { fn from(value: NymTopology) -> Self { WasmFriendlyNymTopology { + metadata: value.metadata, rewarded_set: value.rewarded_set, node_details: value .node_details diff --git a/contracts/mixnet/schema/nym-mixnet-contract.json b/contracts/mixnet/schema/nym-mixnet-contract.json index 3b80f44e3a..716d29d452 100644 --- a/contracts/mixnet/schema/nym-mixnet-contract.json +++ b/contracts/mixnet/schema/nym-mixnet-contract.json @@ -3440,6 +3440,34 @@ } }, "additionalProperties": false + }, + { + "description": "Gets the current state config of the key rotation (i.e. starting epoch id and validity duration)", + "type": "object", + "required": [ + "get_key_rotation_state" + ], + "properties": { + "get_key_rotation_state": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Gets the current key rotation id", + "type": "object", + "required": [ + "get_key_rotation_id" + ], + "properties": { + "get_key_rotation_id": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false } ], "definitions": { @@ -5116,6 +5144,46 @@ } } }, + "get_key_rotation_id": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "KeyRotationIdResponse", + "type": "object", + "required": [ + "rotation_id" + ], + "properties": { + "rotation_id": { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + "get_key_rotation_state": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "KeyRotationState", + "type": "object", + "required": [ + "initial_epoch_id", + "validity_epochs" + ], + "properties": { + "initial_epoch_id": { + "description": "Records the initial epoch_id when the key rotation has been introduced (0 for fresh contracts). It is used for determining when rotation is meant to advance.", + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, + "validity_epochs": { + "description": "Defines how long each key rotation is valid for (in terms of epochs)", + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, "get_mix_node_bonds": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "PagedMixnodeBondsResponse", diff --git a/contracts/mixnet/schema/raw/query.json b/contracts/mixnet/schema/raw/query.json index fdf631ebce..6ec5fdf579 100644 --- a/contracts/mixnet/schema/raw/query.json +++ b/contracts/mixnet/schema/raw/query.json @@ -1486,6 +1486,34 @@ } }, "additionalProperties": false + }, + { + "description": "Gets the current state config of the key rotation (i.e. starting epoch id and validity duration)", + "type": "object", + "required": [ + "get_key_rotation_state" + ], + "properties": { + "get_key_rotation_state": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Gets the current key rotation id", + "type": "object", + "required": [ + "get_key_rotation_id" + ], + "properties": { + "get_key_rotation_id": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false } ], "definitions": { diff --git a/contracts/mixnet/schema/raw/response_to_get_key_rotation_id.json b/contracts/mixnet/schema/raw/response_to_get_key_rotation_id.json new file mode 100644 index 0000000000..f0bdf2fbd1 --- /dev/null +++ b/contracts/mixnet/schema/raw/response_to_get_key_rotation_id.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "KeyRotationIdResponse", + "type": "object", + "required": [ + "rotation_id" + ], + "properties": { + "rotation_id": { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + }, + "additionalProperties": false +} diff --git a/contracts/mixnet/schema/raw/response_to_get_key_rotation_state.json b/contracts/mixnet/schema/raw/response_to_get_key_rotation_state.json new file mode 100644 index 0000000000..efd32685f8 --- /dev/null +++ b/contracts/mixnet/schema/raw/response_to_get_key_rotation_state.json @@ -0,0 +1,24 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "KeyRotationState", + "type": "object", + "required": [ + "initial_epoch_id", + "validity_epochs" + ], + "properties": { + "initial_epoch_id": { + "description": "Records the initial epoch_id when the key rotation has been introduced (0 for fresh contracts). It is used for determining when rotation is meant to advance.", + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, + "validity_epochs": { + "description": "Defines how long each key rotation is valid for (in terms of epochs)", + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + }, + "additionalProperties": false +} diff --git a/contracts/mixnet/src/rewards/transactions.rs b/contracts/mixnet/src/rewards/transactions.rs index f07a9c64a1..7f0b18077e 100644 --- a/contracts/mixnet/src/rewards/transactions.rs +++ b/contracts/mixnet/src/rewards/transactions.rs @@ -313,6 +313,8 @@ pub(crate) fn try_update_rewarding_params( } } +#[allow(clippy::panic)] +#[allow(clippy::unreachable)] #[cfg(test)] pub mod tests { use super::*; diff --git a/contracts/mixnet/src/support/tests/mod.rs b/contracts/mixnet/src/support/tests/mod.rs index 61974e0da3..fed6a7e248 100644 --- a/contracts/mixnet/src/support/tests/mod.rs +++ b/contracts/mixnet/src/support/tests/mod.rs @@ -1,6 +1,11 @@ // Copyright 2021-2023 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +// fine in test code +#![allow(clippy::panic)] +#![allow(clippy::unreachable)] +#![allow(clippy::unimplemented)] + #[cfg(test)] pub mod fixtures; pub(crate) mod legacy; diff --git a/contracts/mixnet/src/vesting_migration.rs b/contracts/mixnet/src/vesting_migration.rs index 152c4adb87..683b7a6102 100644 --- a/contracts/mixnet/src/vesting_migration.rs +++ b/contracts/mixnet/src/vesting_migration.rs @@ -212,6 +212,7 @@ pub(crate) fn try_migrate_vested_delegation( )?)) } +#[allow(clippy::panic)] #[cfg(test)] mod tests { use super::*; diff --git a/nym-node/src/node/key_rotation/controller.rs b/nym-node/src/node/key_rotation/controller.rs index b80488afb4..48f67760fa 100644 --- a/nym-node/src/node/key_rotation/controller.rs +++ b/nym-node/src/node/key_rotation/controller.rs @@ -198,7 +198,6 @@ impl KeyRotationController { { // mutex poisoning - we have to exit self.shutdown_token.cancel(); - return; } // no need to send the information explicitly to nym-apis, as they're scheduled to refresh @@ -217,7 +216,6 @@ impl KeyRotationController { { // mutex poisoning - we have to exit self.shutdown_token.cancel(); - return; } } @@ -229,7 +227,6 @@ impl KeyRotationController { if self.replay_protection_manager.purge_secondary().is_err() { // mutex poisoning - we have to exit self.shutdown_token.cancel(); - return; } } diff --git a/nym-node/src/node/replay_protection/bloomfilter.rs b/nym-node/src/node/replay_protection/bloomfilter.rs index dda30f5534..5697f908ee 100644 --- a/nym-node/src/node/replay_protection/bloomfilter.rs +++ b/nym-node/src/node/replay_protection/bloomfilter.rs @@ -238,18 +238,21 @@ impl ReplayProtectionBloomfilters { } } +// map from particular rotation id to vector of results, based on the order of requests received +type BatchCheckResult = HashMap>; + impl ReplayProtectionBloomfilters { pub(crate) fn batch_try_check_and_set( &self, reply_tags: &HashMap>, - ) -> Option>, PoisonError<()>>> { + ) -> Option>> { let mut guard = match self.inner.try_lock() { Ok(guard) => guard, Err(TryLockError::Poisoned(_)) => return Some(Err(PoisonError::new(()))), Err(TryLockError::WouldBlock) => return None, }; - Some(Ok(guard.batch_check_and_set(&reply_tags))) + Some(Ok(guard.batch_check_and_set(reply_tags))) } pub(crate) fn batch_check_and_set( @@ -260,7 +263,7 @@ impl ReplayProtectionBloomfilters { return Err(PoisonError::new(())); }; - Ok(guard.batch_check_and_set(&reply_tags)) + Ok(guard.batch_check_and_set(reply_tags)) } }