This commit is contained in:
Jędrzej Stuczyński
2022-06-10 09:56:35 +01:00
91 changed files with 1431 additions and 835 deletions
+4 -4
View File
@@ -33,8 +33,8 @@ serde = "1.0"
serde_json = "1.0"
thiserror = "1"
time = { version = "0.3", features = ["serde-human-readable", "parsing"]}
tokio = { version = "1.4", features = ["rt-multi-thread", "macros", "signal", "time"] }
tokio-stream = "0.1.8"
tokio = { version = "1.19.1", features = ["rt-multi-thread", "macros", "signal", "time"] }
tokio-stream = "0.1.9"
url = "2.2"
ts-rs = "6.1.2"
@@ -52,7 +52,7 @@ schemars = { version = "0.8", features = ["preserve_order"] }
## internal
coconut-bandwidth-contract-common = { path = "../common/cosmwasm-smart-contracts/coconut-bandwidth-contract" }
config = { path = "../common/config" }
cosmwasm-std = "1.0.0-beta8"
cosmwasm-std = "1.0.0"
crypto = { path="../common/crypto" }
gateway-client = { path="../common/client-libs/gateway-client" }
mixnet-contract-common = { path= "../common/cosmwasm-smart-contracts/mixnet-contract" }
@@ -75,7 +75,7 @@ no-reward = []
generate-ts = []
[build-dependencies]
tokio = { version = "1.4", features = ["rt-multi-thread", "macros"] }
tokio = { version = "1.19.1", features = ["rt-multi-thread", "macros"] }
sqlx = { version = "0.5", features = ["runtime-tokio-rustls", "sqlite", "macros", "migrate"] }
vergen = { version = "5", default-features = false, features = ["build", "git", "rustc", "cargo"] }
+11 -4
View File
@@ -211,6 +211,7 @@ pub(crate) async fn get_mixnode_inclusion_probability(
identity: String,
) -> Json<Option<InclusionProbabilityResponse>> {
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(),