From 459db5718ec2cccf6d60de6a9cbbc78975d7e3a9 Mon Sep 17 00:00:00 2001 From: Drazen Urch Date: Mon, 6 Jun 2022 14:19:24 +0200 Subject: [PATCH] Set probability to 1 if less nodes then the limit (#1306) * Set probability to 1 if less nodes then the limit * Check both sets independantly --- validator-api/src/node_status_api/routes.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/validator-api/src/node_status_api/routes.rs b/validator-api/src/node_status_api/routes.rs index 22ccbee404..f82206e32b 100644 --- a/validator-api/src/node_status_api/routes.rs +++ b/validator-api/src/node_status_api/routes.rs @@ -211,6 +211,7 @@ pub(crate) async fn get_mixnode_inclusion_probability( identity: String, ) -> Json> { let mixnodes = cache.mixnodes().await; + let rewarding_params = cache.epoch_reward_params().await.into_inner(); if let Some(target_mixnode) = mixnodes.iter().find(|x| x.identity() == &identity) { let total_bonded_tokens = mixnodes @@ -218,17 +219,23 @@ pub(crate) async fn get_mixnode_inclusion_probability( .fold(0u128, |acc, x| acc + x.total_bond().unwrap_or_default()) as f64; - let rewarding_params = cache.epoch_reward_params().await.into_inner(); let rewarded_set_size = rewarding_params.rewarded_set_size() as f64; let active_set_size = rewarding_params.active_set_size() as f64; let prob_one_draw = target_mixnode.total_bond().unwrap_or_default() as f64 / total_bonded_tokens; // Chance to be selected in any draw for active set - let prob_active_set = active_set_size * prob_one_draw; + let prob_active_set = if mixnodes.len() <= active_set_size as usize { + 1.0 + } else { + active_set_size * prob_one_draw + }; // This is likely slightly too high, as we're not correcting form them not being selected in active, should be chance to be selected, minus the chance for being not selected in reserve - let prob_reserve_set = (rewarded_set_size - active_set_size) * prob_one_draw; - // (rewarded_set_size - active_set_size) * prob_one_draw * (1. - prob_active_set); + let prob_reserve_set = if mixnodes.len() <= rewarded_set_size as usize { + 1.0 + } else { + (rewarded_set_size - active_set_size) * prob_one_draw + }; Json(Some(InclusionProbabilityResponse { in_active: prob_active_set.into(),