Renamed the type alias NodeId to MixId and fixed some usages (#1682)
* Renamed the type alias NodeId to MixId and fixed some usages * fix(wallet): bonding context * fix(wallet): remove ip field (type error) Co-authored-by: pierre <dommerc.pierre@gmail.com>
This commit is contained in:
committed by
GitHub
parent
6a3ac6b9be
commit
c3bea668d5
@@ -3,7 +3,7 @@
|
||||
|
||||
use crate::contract_cache::{Cache, CacheNotification, ValidatorCache};
|
||||
use mixnet_contract_common::rewarding::helpers::truncate_decimal;
|
||||
use mixnet_contract_common::{MixNodeDetails, NodeId, RewardingParams};
|
||||
use mixnet_contract_common::{MixId, MixNodeDetails, RewardingParams};
|
||||
use rocket::fairing::AdHoc;
|
||||
use serde::Serialize;
|
||||
use std::{sync::Arc, time::Duration};
|
||||
@@ -46,8 +46,10 @@ pub(crate) struct InclusionProbabilities {
|
||||
}
|
||||
|
||||
impl InclusionProbabilities {
|
||||
pub fn node(&self, mix_id: NodeId) -> Option<&InclusionProbability> {
|
||||
self.inclusion_probabilities.iter().find(|x| x.id == mix_id)
|
||||
pub fn node(&self, mix_id: MixId) -> Option<&InclusionProbability> {
|
||||
self.inclusion_probabilities
|
||||
.iter()
|
||||
.find(|x| x.mix_id == mix_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,7 +230,7 @@ fn compute_inclusion_probabilities(
|
||||
})
|
||||
}
|
||||
|
||||
fn unzip_into_mixnode_ids_and_total_bonds(mixnodes: &[MixNodeDetails]) -> (Vec<NodeId>, Vec<u128>) {
|
||||
fn unzip_into_mixnode_ids_and_total_bonds(mixnodes: &[MixNodeDetails]) -> (Vec<MixId>, Vec<u128>) {
|
||||
mixnodes
|
||||
.iter()
|
||||
.map(|m| (m.mix_id(), truncate_decimal(m.total_stake()).u128()))
|
||||
@@ -236,14 +238,14 @@ fn unzip_into_mixnode_ids_and_total_bonds(mixnodes: &[MixNodeDetails]) -> (Vec<N
|
||||
}
|
||||
|
||||
fn zip_ids_together_with_results(
|
||||
ids: &[NodeId],
|
||||
ids: &[MixId],
|
||||
results: &inclusion_probability::SelectionProbability,
|
||||
) -> Vec<InclusionProbability> {
|
||||
ids.iter()
|
||||
.zip(results.active_set_probability.iter())
|
||||
.zip(results.reserve_set_probability.iter())
|
||||
.map(|((&id, a), r)| InclusionProbability {
|
||||
id,
|
||||
.map(|((&mix_id, a), r)| InclusionProbability {
|
||||
mix_id,
|
||||
in_active: *a,
|
||||
in_reserve: *r,
|
||||
})
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::storage::ValidatorApiStorage;
|
||||
use crate::{NodeStatusCache, ValidatorCache};
|
||||
use cosmwasm_std::Decimal;
|
||||
use mixnet_contract_common::reward_params::Performance;
|
||||
use mixnet_contract_common::{Interval, NodeId, RewardedSetNodeStatus};
|
||||
use mixnet_contract_common::{Interval, MixId, RewardedSetNodeStatus};
|
||||
use rocket::http::Status;
|
||||
use rocket::State;
|
||||
use validator_api_requests::models::{
|
||||
@@ -18,7 +18,7 @@ use validator_api_requests::models::{
|
||||
|
||||
pub(crate) async fn _mixnode_report(
|
||||
storage: &ValidatorApiStorage,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> Result<MixnodeStatusReport, ErrorResponse> {
|
||||
storage
|
||||
.construct_mixnode_report(mix_id)
|
||||
@@ -28,7 +28,7 @@ pub(crate) async fn _mixnode_report(
|
||||
|
||||
pub(crate) async fn _mixnode_uptime_history(
|
||||
storage: &ValidatorApiStorage,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> Result<MixnodeUptimeHistory, ErrorResponse> {
|
||||
storage
|
||||
.get_mixnode_uptime_history(mix_id)
|
||||
@@ -38,7 +38,7 @@ pub(crate) async fn _mixnode_uptime_history(
|
||||
|
||||
pub(crate) async fn _mixnode_core_status_count(
|
||||
storage: &State<ValidatorApiStorage>,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
since: Option<i64>,
|
||||
) -> Result<MixnodeCoreStatusResponse, ErrorResponse> {
|
||||
let count = storage
|
||||
@@ -51,7 +51,7 @@ pub(crate) async fn _mixnode_core_status_count(
|
||||
|
||||
pub(crate) async fn _get_mixnode_status(
|
||||
cache: &ValidatorCache,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> MixnodeStatusResponse {
|
||||
MixnodeStatusResponse {
|
||||
status: cache.mixnode_status(mix_id).await,
|
||||
@@ -60,7 +60,7 @@ pub(crate) async fn _get_mixnode_status(
|
||||
|
||||
pub(crate) async fn _get_mixnode_reward_estimation(
|
||||
cache: &State<ValidatorCache>,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> Result<RewardEstimationResponse, ErrorResponse> {
|
||||
let (mixnode, status) = cache.mixnode_details(mix_id).await;
|
||||
if let Some(mixnode) = mixnode {
|
||||
@@ -98,7 +98,7 @@ pub(crate) async fn _get_mixnode_reward_estimation(
|
||||
}
|
||||
|
||||
async fn average_mixnode_performance(
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
current_interval: Interval,
|
||||
storage: &ValidatorApiStorage,
|
||||
) -> Result<Performance, ErrorResponse> {
|
||||
@@ -115,7 +115,7 @@ async fn average_mixnode_performance(
|
||||
pub(crate) async fn _compute_mixnode_reward_estimation(
|
||||
user_reward_param: ComputeRewardEstParam,
|
||||
cache: &ValidatorCache,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> Result<RewardEstimationResponse, ErrorResponse> {
|
||||
let (mixnode, actual_status) = cache.mixnode_details(mix_id).await;
|
||||
if let Some(mut mixnode) = mixnode {
|
||||
@@ -198,7 +198,7 @@ pub(crate) async fn _compute_mixnode_reward_estimation(
|
||||
|
||||
pub(crate) async fn _get_mixnode_stake_saturation(
|
||||
cache: &ValidatorCache,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> Result<StakeSaturationResponse, ErrorResponse> {
|
||||
let (mixnode, _) = cache.mixnode_details(mix_id).await;
|
||||
if let Some(mixnode) = mixnode {
|
||||
@@ -231,7 +231,7 @@ pub(crate) async fn _get_mixnode_stake_saturation(
|
||||
|
||||
pub(crate) async fn _get_mixnode_inclusion_probability(
|
||||
cache: &NodeStatusCache,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> Result<InclusionProbabilityResponse, ErrorResponse> {
|
||||
cache
|
||||
.inclusion_probabilities()
|
||||
@@ -248,7 +248,7 @@ pub(crate) async fn _get_mixnode_inclusion_probability(
|
||||
pub(crate) async fn _get_mixnode_avg_uptime(
|
||||
cache: &ValidatorCache,
|
||||
storage: &ValidatorApiStorage,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> Result<UptimeResponse, ErrorResponse> {
|
||||
let current_interval = cache
|
||||
.current_interval()
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use crate::node_status_api::utils::NodeUptimes;
|
||||
use crate::storage::models::NodeStatus;
|
||||
use mixnet_contract_common::reward_params::Performance;
|
||||
use mixnet_contract_common::{IdentityKey, NodeId};
|
||||
use mixnet_contract_common::{IdentityKey, MixId};
|
||||
use okapi::openapi3::{Responses, SchemaObject};
|
||||
use rocket::http::{ContentType, Status};
|
||||
use rocket::response::{self, Responder, Response};
|
||||
@@ -115,7 +115,7 @@ impl From<Uptime> for Performance {
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Debug, JsonSchema)]
|
||||
pub struct MixnodeStatusReport {
|
||||
pub(crate) mix_id: NodeId,
|
||||
pub(crate) mix_id: MixId,
|
||||
pub(crate) identity: IdentityKey,
|
||||
pub(crate) owner: String,
|
||||
|
||||
@@ -128,7 +128,7 @@ pub struct MixnodeStatusReport {
|
||||
impl MixnodeStatusReport {
|
||||
pub(crate) fn construct_from_last_day_reports(
|
||||
report_time: OffsetDateTime,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
identity: IdentityKey,
|
||||
owner: String,
|
||||
last_day: Vec<NodeStatus>,
|
||||
@@ -192,7 +192,7 @@ impl GatewayStatusReport {
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Debug, JsonSchema)]
|
||||
pub struct MixnodeUptimeHistory {
|
||||
pub(crate) mix_id: NodeId,
|
||||
pub(crate) mix_id: MixId,
|
||||
pub(crate) identity: String,
|
||||
pub(crate) owner: String,
|
||||
|
||||
@@ -201,7 +201,7 @@ pub struct MixnodeUptimeHistory {
|
||||
|
||||
impl MixnodeUptimeHistory {
|
||||
pub(crate) fn new(
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
identity: String,
|
||||
owner: String,
|
||||
history: Vec<HistoricalUptime>,
|
||||
@@ -305,9 +305,9 @@ impl OpenApiResponderInner for ErrorResponse {
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ValidatorApiStorageError {
|
||||
MixnodeReportNotFound(NodeId),
|
||||
MixnodeReportNotFound(MixId),
|
||||
GatewayReportNotFound(String),
|
||||
MixnodeUptimeHistoryNotFound(NodeId),
|
||||
MixnodeUptimeHistoryNotFound(MixId),
|
||||
GatewayUptimeHistoryNotFound(String),
|
||||
|
||||
// I don't think we want to expose errors to the user about what really happened
|
||||
|
||||
@@ -14,7 +14,7 @@ use crate::node_status_api::models::{
|
||||
};
|
||||
use crate::storage::ValidatorApiStorage;
|
||||
use crate::ValidatorCache;
|
||||
use mixnet_contract_common::NodeId;
|
||||
use mixnet_contract_common::MixId;
|
||||
use rocket::http::Status;
|
||||
use rocket::serde::json::Json;
|
||||
use rocket::State;
|
||||
@@ -73,7 +73,7 @@ pub(crate) async fn gateway_core_status_count(
|
||||
#[get("/mixnode/<mix_id>/report")]
|
||||
pub(crate) async fn mixnode_report(
|
||||
storage: &State<ValidatorApiStorage>,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> Result<Json<MixnodeStatusReport>, ErrorResponse> {
|
||||
Ok(Json(_mixnode_report(storage, mix_id).await?))
|
||||
}
|
||||
@@ -82,7 +82,7 @@ pub(crate) async fn mixnode_report(
|
||||
#[get("/mixnode/<mix_id>/history")]
|
||||
pub(crate) async fn mixnode_uptime_history(
|
||||
storage: &State<ValidatorApiStorage>,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> Result<Json<MixnodeUptimeHistory>, ErrorResponse> {
|
||||
Ok(Json(_mixnode_uptime_history(storage, mix_id).await?))
|
||||
}
|
||||
@@ -91,7 +91,7 @@ pub(crate) async fn mixnode_uptime_history(
|
||||
#[get("/mixnode/<mix_id>/core-status-count?<since>")]
|
||||
pub(crate) async fn mixnode_core_status_count(
|
||||
storage: &State<ValidatorApiStorage>,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
since: Option<i64>,
|
||||
) -> Result<Json<MixnodeCoreStatusResponse>, ErrorResponse> {
|
||||
Ok(Json(
|
||||
@@ -103,7 +103,7 @@ pub(crate) async fn mixnode_core_status_count(
|
||||
#[get("/mixnode/<mix_id>/status")]
|
||||
pub(crate) async fn get_mixnode_status(
|
||||
cache: &State<ValidatorCache>,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> Json<MixnodeStatusResponse> {
|
||||
Json(_get_mixnode_status(cache, mix_id).await)
|
||||
}
|
||||
@@ -112,7 +112,7 @@ pub(crate) async fn get_mixnode_status(
|
||||
#[get("/mixnode/<mix_id>/reward-estimation")]
|
||||
pub(crate) async fn get_mixnode_reward_estimation(
|
||||
cache: &State<ValidatorCache>,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> Result<Json<RewardEstimationResponse>, ErrorResponse> {
|
||||
Ok(Json(_get_mixnode_reward_estimation(cache, mix_id).await?))
|
||||
}
|
||||
@@ -125,7 +125,7 @@ pub(crate) async fn get_mixnode_reward_estimation(
|
||||
pub(crate) async fn compute_mixnode_reward_estimation(
|
||||
user_reward_param: Json<ComputeRewardEstParam>,
|
||||
cache: &State<ValidatorCache>,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> Result<Json<RewardEstimationResponse>, ErrorResponse> {
|
||||
Ok(Json(
|
||||
_compute_mixnode_reward_estimation(user_reward_param.into_inner(), cache, mix_id).await?,
|
||||
@@ -136,7 +136,7 @@ pub(crate) async fn compute_mixnode_reward_estimation(
|
||||
#[get("/mixnode/<mix_id>/stake-saturation")]
|
||||
pub(crate) async fn get_mixnode_stake_saturation(
|
||||
cache: &State<ValidatorCache>,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> Result<Json<StakeSaturationResponse>, ErrorResponse> {
|
||||
Ok(Json(_get_mixnode_stake_saturation(cache, mix_id).await?))
|
||||
}
|
||||
@@ -145,7 +145,7 @@ pub(crate) async fn get_mixnode_stake_saturation(
|
||||
#[get("/mixnode/<mix_id>/inclusion-probability")]
|
||||
pub(crate) async fn get_mixnode_inclusion_probability(
|
||||
cache: &State<NodeStatusCache>,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> Result<Json<InclusionProbabilityResponse>, ErrorResponse> {
|
||||
Ok(Json(
|
||||
_get_mixnode_inclusion_probability(cache, mix_id).await?,
|
||||
@@ -157,7 +157,7 @@ pub(crate) async fn get_mixnode_inclusion_probability(
|
||||
pub(crate) async fn get_mixnode_avg_uptime(
|
||||
cache: &State<ValidatorCache>,
|
||||
storage: &State<ValidatorApiStorage>,
|
||||
mix_id: NodeId,
|
||||
mix_id: MixId,
|
||||
) -> Result<Json<UptimeResponse>, ErrorResponse> {
|
||||
Ok(Json(_get_mixnode_avg_uptime(cache, storage, mix_id).await?))
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ use crate::node_status_api::models::Uptime;
|
||||
use crate::node_status_api::{FIFTEEN_MINUTES, ONE_HOUR};
|
||||
use crate::storage::models::NodeStatus;
|
||||
use log::warn;
|
||||
use mixnet_contract_common::NodeId;
|
||||
use mixnet_contract_common::MixId;
|
||||
use std::convert::TryInto;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
// A temporary helper structs used to produce reports for active nodes.
|
||||
pub(crate) struct ActiveMixnodeStatuses {
|
||||
pub(crate) mix_id: NodeId,
|
||||
pub(crate) mix_id: MixId,
|
||||
|
||||
pub(crate) identity: String,
|
||||
pub(crate) owner: String,
|
||||
|
||||
Reference in New Issue
Block a user