Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 51 additions & 47 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ syn = "1"
sysinfo = "0.37.0"
tap = "1.0.1"
tar = "0.4.44"
test-with = { version = "0.15.4", default-features = false }
tempfile = "3.20"
thiserror = "2.0"
time = "0.3.41"
Expand Down
12 changes: 12 additions & 0 deletions common/task/src/cancellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@ impl ShutdownToken {
// exposed method with the old name for easier migration
// it will eventually be removed so please try to use `.clone_with_suffix` instead
#[must_use]
#[deprecated(note = "use .clone_with_suffix instead")]
pub fn fork<S: Into<String>>(&self, child_suffix: S) -> Self {
self.clone_with_suffix(child_suffix)
}

// exposed method with the old name for easier migration
// it will eventually be removed so please try to use `.clone().named(name)` instead
#[must_use]
#[deprecated(note = "use .clone().named(name) instead")]
pub fn fork_named<S: Into<String>>(&self, name: S) -> Self {
self.clone().named(name)
}
Expand Down Expand Up @@ -232,6 +234,16 @@ impl ShutdownManager {
manager.with_shutdown(async move { cancel_watcher.cancelled().await })
}

pub fn empty_mock() -> Self {
ShutdownManager {
root_token: ShutdownToken::ephemeral(),
legacy_task_manager: None,
shutdown_signals: Default::default(),
tracker: Default::default(),
max_shutdown_duration: Default::default(),
}
}

pub fn with_legacy_task_manager(mut self) -> Self {
let mut legacy_manager =
TaskManager::default().named(format!("{}-legacy", self.root_token.name()));
Expand Down
1 change: 0 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ exceptions = [
#{ allow = ["Zlib"], crate = "adler32" },
{ allow = ["GPL-3.0"], crate = "nym-api" },
{ allow = ["GPL-3.0"], crate = "nym-gateway" },
{ allow = ["GPL-3.0"], crate = "nym-mixnode" },
{ allow = ["GPL-3.0"], crate = "nym-network-requester" },
{ allow = ["GPL-3.0"], crate = "nym-node" },
{ allow = ["GPL-3.0"], crate = "nym-validator-rewarder" },
Expand Down
3 changes: 2 additions & 1 deletion nym-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ cw3 = { workspace = true }
cw-utils = { workspace = true }
rand_chacha = { workspace = true }
sha2 = { workspace = true }
dotenv = "0.15"
dotenvy = { workspace = true }
test-with = { workspace = true, default-features = false }

[lints]
workspace = true
12 changes: 6 additions & 6 deletions nym-api/src/ecash/dkg/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use anyhow::{bail, Result};
use nym_coconut_dkg_common::types::{Epoch, EpochId, EpochState};
use nym_crypto::asymmetric::ed25519;
use nym_dkg::bte::keys::KeyPair as DkgKeyPair;
use nym_task::{TaskClient, TaskManager};
use nym_task::{ShutdownManager, ShutdownToken};
use rand::rngs::OsRng;
use rand::{CryptoRng, Rng, RngCore};
use std::path::PathBuf;
Expand Down Expand Up @@ -273,7 +273,7 @@ impl<R: RngCore + CryptoRng + Clone> DkgController<R> {
tick_duration < min
}

pub(crate) async fn run(mut self, mut shutdown: TaskClient) {
pub(crate) async fn run(mut self, shutdown: ShutdownToken) {
let mut interval = interval(self.polling_rate);
interval.set_missed_tick_behavior(MissedTickBehavior::Delay);

Expand All @@ -282,7 +282,7 @@ impl<R: RngCore + CryptoRng + Clone> DkgController<R> {
let mut last_polled = OffsetDateTime::now_utc();
let mut last_tick_duration = Default::default();

while !shutdown.is_shutdown() {
while !shutdown.is_cancelled() {
tokio::select! {
_ = interval.tick() => {
let now = OffsetDateTime::now_utc();
Expand All @@ -300,7 +300,7 @@ impl<R: RngCore + CryptoRng + Clone> DkgController<R> {
error!("failed to update the DKG state: {err}")
}
}
_ = shutdown.recv() => {
_ = shutdown.cancelled() => {
trace!("DkgController: Received shutdown");
}
}
Expand All @@ -314,12 +314,12 @@ impl<R: RngCore + CryptoRng + Clone> DkgController<R> {
dkg_bte_keypair: DkgKeyPair,
identity_key: ed25519::PublicKey,
rng: R,
shutdown: &TaskManager,
shutdown_manager: &ShutdownManager,
) -> Result<()>
where
R: Sync + Send + 'static,
{
let shutdown_listener = shutdown.subscribe();
let shutdown_listener = shutdown_manager.clone_token("DKG controller");
let dkg_controller = DkgController::new(
config,
nyxd_client,
Expand Down
14 changes: 9 additions & 5 deletions nym-api/src/ecash/state/cleaner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::node_status_api::models::NymApiStorageError;
use crate::support::config::Config;
use crate::support::storage::NymApiStorage;
use nym_ecash_time::ecash_today_date;
use nym_task::TaskClient;
use nym_task::ShutdownToken;
use std::time::Duration;
use time::Date;
use tokio::task::JoinHandle;
Expand All @@ -20,11 +20,15 @@ pub struct EcashBackgroundStateCleaner {
verified_tickets_retention_period_days: u32,

storage: NymApiStorage,
task_client: TaskClient,
shutdown_token: ShutdownToken,
}

impl EcashBackgroundStateCleaner {
pub fn new(global_config: &Config, storage: NymApiStorage, task_client: TaskClient) -> Self {
pub fn new(
global_config: &Config,
storage: NymApiStorage,
shutdown_token: ShutdownToken,
) -> Self {
EcashBackgroundStateCleaner {
run_interval: global_config.ecash_signer.debug.stale_data_cleaner_interval,
issued_ticketbooks_retention_period_days: global_config
Expand All @@ -36,7 +40,7 @@ impl EcashBackgroundStateCleaner {
.debug
.verified_tickets_retention_period_days,
storage,
task_client,
shutdown_token,
}
}

Expand Down Expand Up @@ -68,7 +72,7 @@ impl EcashBackgroundStateCleaner {
let mut ticker = tokio::time::interval(self.run_interval);
loop {
tokio::select! {
_ = self.task_client.recv() => {
_ = self.shutdown_token.cancelled() => {
trace!("EcashBackgroundStateCleaner: Received shutdown");
break;
}
Expand Down
Loading
Loading