mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
Stored conversion rate updater (#1005)
* update conversion rate: initial commit * Rialto=Polkadot && Millau=Kusama + actually update conversion rates * update deployment scripts and readme * allow non-zero difference between stored and real rates * dummy commit * Revert "dummy commit" This reverts commit a438198180a8385feeaaca60c9d2da0950465215. * clippy * #[allow(clippy::float_cmp)] in conversion rate update * dummy * Revert "dummy" This reverts commit 90cd6e47cda56f655e94dbef76138e6cc58d664a. * spell * shared_value_ref() -> get() * Revert "shared_value_ref() -> get()" This reverts commit 20aa30de6a59b2099cfba3e9676e71200b7bb468.
This commit is contained in:
committed by
Bastian Köcher
parent
fc9363619a
commit
3ef4574594
@@ -17,9 +17,12 @@
|
||||
use crate::chain::Chain;
|
||||
use crate::client::Client;
|
||||
|
||||
use async_std::sync::{Arc, RwLock};
|
||||
use async_trait::async_trait;
|
||||
use codec::Decode;
|
||||
use relay_utils::metrics::{metric_name, register, Gauge, PrometheusError, Registry, StandaloneMetrics, F64};
|
||||
use relay_utils::metrics::{
|
||||
metric_name, register, F64SharedRef, Gauge, PrometheusError, Registry, StandaloneMetrics, F64,
|
||||
};
|
||||
use sp_core::storage::StorageKey;
|
||||
use sp_runtime::{traits::UniqueSaturatedInto, FixedPointNumber};
|
||||
use std::time::Duration;
|
||||
@@ -34,6 +37,7 @@ pub struct FloatStorageValueMetric<C: Chain, T: Clone> {
|
||||
storage_key: StorageKey,
|
||||
maybe_default_value: Option<T>,
|
||||
metric: Gauge<F64>,
|
||||
shared_value_ref: F64SharedRef,
|
||||
}
|
||||
|
||||
impl<C: Chain, T: Decode + FixedPointNumber> FloatStorageValueMetric<C, T> {
|
||||
@@ -47,13 +51,20 @@ impl<C: Chain, T: Decode + FixedPointNumber> FloatStorageValueMetric<C, T> {
|
||||
name: String,
|
||||
help: String,
|
||||
) -> Result<Self, PrometheusError> {
|
||||
let shared_value_ref = Arc::new(RwLock::new(None));
|
||||
Ok(FloatStorageValueMetric {
|
||||
client,
|
||||
storage_key,
|
||||
maybe_default_value,
|
||||
metric: register(Gauge::new(metric_name(prefix, &name), help)?, registry)?,
|
||||
shared_value_ref,
|
||||
})
|
||||
}
|
||||
|
||||
/// Get shared reference to metric value.
|
||||
pub fn shared_value_ref(&self) -> F64SharedRef {
|
||||
self.shared_value_ref.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -66,17 +77,17 @@ where
|
||||
}
|
||||
|
||||
async fn update(&self) {
|
||||
relay_utils::metrics::set_gauge_value(
|
||||
&self.metric,
|
||||
self.client
|
||||
.storage_value::<T>(self.storage_key.clone())
|
||||
.await
|
||||
.map(|maybe_storage_value| {
|
||||
maybe_storage_value.or(self.maybe_default_value).map(|storage_value| {
|
||||
storage_value.into_inner().unique_saturated_into() as f64
|
||||
/ T::DIV.unique_saturated_into() as f64
|
||||
})
|
||||
}),
|
||||
);
|
||||
let value = self
|
||||
.client
|
||||
.storage_value::<T>(self.storage_key.clone())
|
||||
.await
|
||||
.map(|maybe_storage_value| {
|
||||
maybe_storage_value.or(self.maybe_default_value).map(|storage_value| {
|
||||
storage_value.into_inner().unique_saturated_into() as f64 / T::DIV.unique_saturated_into() as f64
|
||||
})
|
||||
})
|
||||
.map_err(drop);
|
||||
relay_utils::metrics::set_gauge_value(&self.metric, value);
|
||||
*self.shared_value_ref.write().await = value.ok().and_then(|x| x);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user