Have reward set updater run its own timer (#1200)

* Have reward set updater run its own timer

* Filter rocket log spam

* Take last day of uptime for rewarding (#1202)

* Take last day of uptime for rewarding

* Rejigger calculations

* Blacklist based on last 24 hr

* Cleanup

* Clippy
This commit is contained in:
Drazen Urch
2022-04-10 15:52:30 +02:00
committed by GitHub
parent 9aa5b98465
commit 74ab09b05f
14 changed files with 261 additions and 136 deletions
+5 -18
View File
@@ -17,7 +17,7 @@ use std::collections::HashSet;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::{Notify, RwLock};
use tokio::sync::RwLock;
use tokio::time;
use validator_api_requests::models::MixnodeStatus;
use validator_client::nymd::CosmWasmClient;
@@ -28,7 +28,6 @@ pub struct ValidatorCacheRefresher<C> {
nymd_client: Client<C>,
cache: ValidatorCache,
caching_interval: Duration,
update_rewarded_set_notify: Option<Arc<Notify>>,
}
#[derive(Clone)]
@@ -89,13 +88,11 @@ impl<C> ValidatorCacheRefresher<C> {
nymd_client: Client<C>,
caching_interval: Duration,
cache: ValidatorCache,
update_rewarded_set_notify: Option<Arc<Notify>>,
) -> Self {
ValidatorCacheRefresher {
nymd_client,
cache,
caching_interval,
update_rewarded_set_notify,
}
}
@@ -136,6 +133,7 @@ impl<C> ValidatorCacheRefresher<C> {
self.collect_rewarded_and_active_set_details(&mixnodes, rewarded_set_identities);
let epoch_rewarding_params = self.nymd_client.get_current_epoch_reward_params().await?;
let current_epoch = self.nymd_client.get_current_epoch().await?;
info!(
"Updating validator cache. There are {} mixnodes and {} gateways",
@@ -150,23 +148,10 @@ impl<C> ValidatorCacheRefresher<C> {
rewarded_set,
active_set,
epoch_rewarding_params,
current_epoch,
)
.await;
if let Some(notify) = &self.update_rewarded_set_notify {
let update_details = self
.nymd_client
.get_current_rewarded_set_update_details()
.await?;
if update_details.last_refreshed_block + (update_details.refresh_rate_blocks as u64)
< update_details.current_height
{
// there's only ever a single waiter -> the set updater
notify.notify_one()
}
}
Ok(())
}
@@ -221,6 +206,7 @@ impl ValidatorCache {
rewarded_set: Vec<MixNodeBond>,
active_set: Vec<MixNodeBond>,
epoch_rewarding_params: EpochRewardParams,
current_epoch: Interval,
) {
let mut inner = self.inner.write().await;
@@ -229,6 +215,7 @@ impl ValidatorCache {
inner.rewarded_set.update(rewarded_set);
inner.active_set.update(active_set);
inner.current_reward_params.update(epoch_rewarding_params);
inner.current_epoch.update(Some(current_epoch));
}
pub async fn mixnodes_blacklist(&self) -> Cache<HashSet<IdentityKey>> {