merge #5512 again after reverting due to incorrect rebase (#5520)

* setup workspace global lints to prevent needless panics

* removed sources of panic in nym-crypto, nym-node and nym-api

* adjusted test code
This commit is contained in:
Jędrzej Stuczyński
2025-02-26 10:52:09 +00:00
committed by GitHub
parent 69b2448500
commit 65175fee09
40 changed files with 181 additions and 69 deletions
+5
View File
@@ -125,6 +125,8 @@ impl TryFrom<i64> for Uptime {
impl From<Uptime> for Performance {
fn from(uptime: Uptime) -> Self {
// SAFETY: uptime has a valid range to be transformed into a `Performance`
#[allow(clippy::unwrap_used)]
Performance::from_percentage_value(uptime.0 as u64).unwrap()
}
}
@@ -481,6 +483,9 @@ pub enum NymApiStorageError {
// this one would never be returned to users since it's only possible on startup
#[error("failed to perform startup SQL migration - {0}")]
StartupMigrationFailure(#[from] sqlx::migrate::MigrateError),
#[error("{value} is not a valid unix timestamp")]
InvalidTimestampProvided { value: i64 },
}
impl From<sqlx::Error> for NymApiStorageError {
@@ -8,7 +8,8 @@ use crate::node_status_api::ONE_DAY;
use crate::storage::NymApiStorage;
use nym_task::{TaskClient, TaskManager};
use std::time::Duration;
use time::{OffsetDateTime, PrimitiveDateTime, Time};
use time::macros::time;
use time::{OffsetDateTime, PrimitiveDateTime};
use tokio::time::{interval_at, Instant};
use tracing::error;
use tracing::{info, trace, warn};
@@ -75,18 +76,20 @@ impl HistoricalUptimeUpdater {
// nodes update for different days
// the unwrap is fine as 23:00:00 is a valid time
let update_time = Time::from_hms(23, 0, 0).unwrap();
let update_time = time!(23:00:00);
let now = OffsetDateTime::now_utc();
// is the current time within 0:00 - 22:59:59 or 23:00 - 23:59:59 ?
let update_date = if now.hour() < 23 {
now.date()
} else {
// the unwrap is fine as (**PRESUMABLY**) we're not running this code in the year 9999
#[allow(clippy::unwrap_used)]
now.date().next_day().unwrap()
};
let update_datetime = PrimitiveDateTime::new(update_date, update_time).assume_utc();
// the unwrap here is fine as we're certain `update_datetime` is in the future and thus the
// resultant Duration is positive
#[allow(clippy::unwrap_used)]
let time_left: Duration = (update_datetime - now).try_into().unwrap();
info!(
+1
View File
@@ -109,6 +109,7 @@ impl NodeUptimes {
// the unwraps in Uptime::from_ratio are fine because it's impossible for us to have more "up" results
// than total test runs as we just bounded them
#[allow(clippy::unwrap_used)]
NodeUptimes {
most_recent: most_recent.try_into().unwrap(),
last_hour: Uptime::from_uptime_sum(last_hour_sum, last_hour_test_runs).unwrap(),