making sure to stop nym-rewarder if nyxd scraper has terminated

This commit is contained in:
Jędrzej Stuczyński
2024-02-13 12:03:06 +00:00
parent 3088b69711
commit b03d737393
5 changed files with 45 additions and 34 deletions
+9 -1
View File
@@ -201,10 +201,18 @@ impl NyxdScraper {
}
pub async fn stop(self) {
info!("stopping the chain scrapper");
info!("stopping the chain scraper");
assert!(self.task_tracker.is_closed());
self.cancel_token.cancel();
self.task_tracker.wait().await
}
pub fn cancel_token(&self) -> CancellationToken {
self.cancel_token.clone()
}
pub fn is_cancelled(&self) -> bool {
self.cancel_token.is_cancelled()
}
}
@@ -120,7 +120,7 @@ pub async fn run_websocket_driver(driver: WebSocketClientDriver, cancel: Cancell
Ok(_) => info!("our websocket driver has finished execution"),
Err(err) => {
// TODO: in the future just attempt to reconnect
error!("our websocket driver has errored out: {err}")
error!("our websocket driver has errored out: {err}");
}
}
cancel.cancel()
+10 -15
View File
@@ -4513,7 +4513,6 @@ dependencies = [
"nym-network-defaults",
"nym-service-provider-directory-common",
"nym-vesting-contract-common",
"openssl",
"prost",
"reqwest",
"serde",
@@ -4660,15 +4659,6 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-src"
version = "111.27.0+1.1.1v"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06e8f197c82d7511c5b014030c9b1efeda40d7d5f99d23b4ceed3524a5e63f02"
dependencies = [
"cc",
]
[[package]]
name = "openssl-sys"
version = "0.9.91"
@@ -4677,7 +4667,6 @@ checksum = "866b5f16f90776b9bb8dc1e1802ac6f0513de3a7a7465867bfbc563dc737faac"
dependencies = [
"cc",
"libc",
"openssl-src",
"pkg-config",
"vcpkg",
]
@@ -5518,6 +5507,7 @@ dependencies = [
"wasm-bindgen-futures",
"wasm-streams",
"web-sys",
"webpki-roots 0.25.4",
"winreg 0.50.0",
]
@@ -6473,7 +6463,7 @@ dependencies = [
"thiserror",
"tokio-stream",
"url",
"webpki-roots",
"webpki-roots 0.22.6",
]
[[package]]
@@ -7262,9 +7252,8 @@ checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c"
dependencies = [
"futures-util",
"log",
"native-tls",
"rustls 0.21.7",
"tokio",
"tokio-native-tls",
"tungstenite",
]
@@ -7444,8 +7433,8 @@ dependencies = [
"http",
"httparse",
"log",
"native-tls",
"rand 0.8.5",
"rustls 0.21.7",
"sha1",
"thiserror",
"url",
@@ -7889,6 +7878,12 @@ dependencies = [
"webpki",
]
[[package]]
name = "webpki-roots"
version = "0.25.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1"
[[package]]
name = "webview2-com"
version = "0.19.1"
+18 -6
View File
@@ -1,4 +1,4 @@
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
// Copyright 2023-2024 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: GPL-3.0-only
use crate::config::Config;
@@ -10,13 +10,15 @@ use crate::rewarder::credential_issuance::CredentialIssuance;
use crate::rewarder::epoch::Epoch;
use crate::rewarder::nyxd_client::NyxdClient;
use crate::rewarder::storage::RewarderStorage;
use futures::future::{FusedFuture, OptionFuture};
use futures::FutureExt;
use nym_task::TaskManager;
use nym_validator_client::nyxd::{AccountId, Coin, Hash};
use nyxd_scraper::NyxdScraper;
use std::ops::Add;
use tokio::pin;
use tokio::time::{interval_at, Instant};
use tracing::{error, info, instrument};
use tracing::{error, info, instrument, warn};
mod block_signing;
mod credential_issuance;
@@ -263,10 +265,16 @@ impl Rewarder {
);
}
if let Some(epoch_signing) = &self.epoch_signing {
epoch_signing.nyxd_scraper.start().await?;
epoch_signing.nyxd_scraper.wait_for_startup_sync().await;
}
let mut scraper_cancellation: OptionFuture<_> =
if let Some(epoch_signing) = &self.epoch_signing {
let cancellation_token = epoch_signing.nyxd_scraper.cancel_token();
epoch_signing.nyxd_scraper.start().await?;
epoch_signing.nyxd_scraper.wait_for_startup_sync().await;
Some(Box::pin(async move { cancellation_token.cancelled().await }).fuse())
} else {
None
}
.into();
let until_end = self.current_epoch.until_end();
@@ -292,6 +300,10 @@ impl Rewarder {
}
break;
}
_ = &mut scraper_cancellation, if !scraper_cancellation.is_terminated() => {
warn!("the nyxd scraper has been cancelled");
break
}
_ = epoch_ticker.tick() => self.handle_epoch_end().await
}
}
+7 -11
View File
@@ -3454,7 +3454,6 @@ dependencies = [
"nym-network-defaults",
"nym-service-provider-directory-common",
"nym-vesting-contract-common",
"openssl",
"prost",
"reqwest",
"serde",
@@ -3686,15 +3685,6 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-src"
version = "111.27.0+1.1.1v"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06e8f197c82d7511c5b014030c9b1efeda40d7d5f99d23b4ceed3524a5e63f02"
dependencies = [
"cc",
]
[[package]]
name = "openssl-sys"
version = "0.9.91"
@@ -3703,7 +3693,6 @@ checksum = "866b5f16f90776b9bb8dc1e1802ac6f0513de3a7a7465867bfbc563dc737faac"
dependencies = [
"cc",
"libc",
"openssl-src",
"pkg-config",
"vcpkg",
]
@@ -4454,6 +4443,7 @@ dependencies = [
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"webpki-roots",
"winreg",
]
@@ -6270,6 +6260,12 @@ dependencies = [
"system-deps 6.1.1",
]
[[package]]
name = "webpki-roots"
version = "0.25.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1"
[[package]]
name = "webview2-com"
version = "0.19.1"