nym-api: make report/avg_uptime endpoints ignore blacklist

This commit is contained in:
Jędrzej Stuczyński
2024-05-17 11:01:16 +01:00
parent e5f41731ae
commit 7f87d42f9a
5 changed files with 101 additions and 65 deletions
+30 -24
View File
@@ -28,11 +28,11 @@ pub(super) fn to_rewarded_set_node_status(
}
pub(super) fn split_into_active_and_rewarded_set(
mixnodes_annotated: &[MixNodeBondAnnotated],
mixnodes_annotated: &HashMap<MixId, MixNodeBondAnnotated>,
rewarded_set_node_status: &HashMap<u32, RewardedSetNodeStatus>,
) -> (Vec<MixNodeBondAnnotated>, Vec<MixNodeBondAnnotated>) {
let rewarded_set: Vec<_> = mixnodes_annotated
.iter()
.values()
.filter(|mixnode| rewarded_set_node_status.get(&mixnode.mix_id()).is_some())
.cloned()
.collect();
@@ -88,12 +88,12 @@ pub(super) async fn annotate_nodes_with_details(
rewarded_set: &HashMap<MixId, RewardedSetNodeStatus>,
mix_to_family: Vec<(IdentityKey, FamilyHead)>,
blacklist: &HashSet<MixId>,
) -> Vec<MixNodeBondAnnotated> {
) -> HashMap<MixId, MixNodeBondAnnotated> {
let mix_to_family = mix_to_family
.into_iter()
.collect::<HashMap<IdentityKey, FamilyHead>>();
let mut annotated = Vec::new();
let mut annotated = HashMap::new();
for mixnode in mixnodes {
let stake_saturation = mixnode
.rewarding_details
@@ -138,17 +138,20 @@ pub(super) async fn annotate_nodes_with_details(
.get(mixnode.bond_information.identity())
.cloned();
annotated.push(MixNodeBondAnnotated {
blacklisted: blacklist.contains(&mixnode.mix_id()),
mixnode_details: mixnode,
stake_saturation,
uncapped_stake_saturation,
performance,
node_performance,
estimated_operator_apy,
estimated_delegators_apy,
family,
});
annotated.insert(
mixnode.mix_id(),
MixNodeBondAnnotated {
blacklisted: blacklist.contains(&mixnode.mix_id()),
mixnode_details: mixnode,
stake_saturation,
uncapped_stake_saturation,
performance,
node_performance,
estimated_operator_apy,
estimated_delegators_apy,
family,
},
);
}
annotated
}
@@ -158,8 +161,8 @@ pub(crate) async fn annotate_gateways_with_details(
gateway_bonds: Vec<GatewayBond>,
current_interval: Interval,
blacklist: &HashSet<IdentityKey>,
) -> Vec<GatewayBondAnnotated> {
let mut annotated = Vec::new();
) -> HashMap<IdentityKey, GatewayBondAnnotated> {
let mut annotated = HashMap::new();
for gateway_bond in gateway_bonds {
let performance = get_gateway_performance_from_storage(
storage,
@@ -180,13 +183,16 @@ pub(crate) async fn annotate_gateways_with_details(
}
.unwrap_or_default();
annotated.push(GatewayBondAnnotated {
blacklisted: blacklist.contains(&gateway_bond.gateway.identity_key),
gateway_bond,
self_described: None,
performance,
node_performance,
});
annotated.insert(
gateway_bond.identity().to_string(),
GatewayBondAnnotated {
blacklisted: blacklist.contains(&gateway_bond.gateway.identity_key),
gateway_bond,
self_described: None,
performance,
node_performance,
},
);
}
annotated
}