diff --git a/Cargo.lock b/Cargo.lock index 3a83e22..c69e199 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7322,7 +7322,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "storb_base" -version = "0.2.3" +version = "0.2.4" dependencies = [ "anyhow", "async-trait", @@ -7357,7 +7357,7 @@ dependencies = [ [[package]] name = "storb_cli" -version = "0.2.3" +version = "0.2.4" dependencies = [ "anyhow", "chrono", @@ -7385,7 +7385,7 @@ dependencies = [ [[package]] name = "storb_miner" -version = "0.2.3" +version = "0.2.4" dependencies = [ "anyhow", "axum", @@ -7413,7 +7413,7 @@ dependencies = [ [[package]] name = "storb_validator" -version = "0.2.3" +version = "0.2.4" dependencies = [ "anyhow", "axum", diff --git a/Cargo.toml b/Cargo.toml index 47fb42c..7760209 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ members = ["crates/*"] default-members = ["crates/storb_cli"] [workspace.package] -version = "0.2.3" +version = "0.2.4" description = "An object storage subnet on the Bittensor network" edition = "2021" authors = ["Storb Technologies Ltd"] diff --git a/crates/storb_miner/Cargo.toml b/crates/storb_miner/Cargo.toml index 599274f..79b03fd 100644 --- a/crates/storb_miner/Cargo.toml +++ b/crates/storb_miner/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "storb_miner" -version = "0.2.3" +version = "0.2.4" edition.workspace = true [dependencies] diff --git a/crates/storb_validator/Cargo.toml b/crates/storb_validator/Cargo.toml index 7c85e81..5a09516 100644 --- a/crates/storb_validator/Cargo.toml +++ b/crates/storb_validator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "storb_validator" -version = "0.2.3" +version = "0.2.4" edition.workspace = true [dependencies] diff --git a/crates/storb_validator/src/constants.rs b/crates/storb_validator/src/constants.rs index b886b9b..405f9b9 100644 --- a/crates/storb_validator/src/constants.rs +++ b/crates/storb_validator/src/constants.rs @@ -1,5 +1,10 @@ use std::time::Duration; +// Owner UID number on mainnet +pub const OWNER_UID: usize = 4; +// Weight to be assigned to the owner UID +pub const OWNER_WEIGHT: f64 = 0.9; + /// Buffer size for the metadatadb's MPSC channel. pub const DB_MPSC_BUFFER_SIZE: usize = 100; diff --git a/crates/storb_validator/src/validator.rs b/crates/storb_validator/src/validator.rs index 1a3cbcc..99d5af5 100644 --- a/crates/storb_validator/src/validator.rs +++ b/crates/storb_validator/src/validator.rs @@ -32,7 +32,8 @@ use tracing::{debug, error, info, warn}; use crate::constants::{ MAX_CHALLENGE_PIECE_NUM, MAX_SYNTH_CHALLENGE_MINER_NUM, MAX_SYNTH_CHUNK_SIZE, - MIN_SYNTH_CHUNK_SIZE, SYNTH_CHALLENGE_TIMEOUT, SYNTH_CHALLENGE_WAIT_BEFORE_RETRIEVE, + MIN_SYNTH_CHUNK_SIZE, OWNER_UID, OWNER_WEIGHT, SYNTH_CHALLENGE_TIMEOUT, + SYNTH_CHALLENGE_WAIT_BEFORE_RETRIEVE, }; use crate::metadata; use crate::metadata::models::SqlAccountId; @@ -506,7 +507,50 @@ impl Validator { config: ValidatorConfig, weights_counter: opentelemetry::metrics::Counter, ) -> Result<(), Box> { - let normed_scores = normalize_min_max(&scores); + let mut normed_scores = normalize_min_max(&scores); + + // We adjust OWNER_UID to have OWNER_WEIGHT proportion of total scores + // so if weights are: + // [0.1, 0.2, 0.3] and OWNER_WEIGHT is 0.9, then OWNER_UID (e.g. 0) will have + // 90% of the sum of all weights, so the array will be: + // [1., 0.04444444, 0.06666667], because 1 + 0.04444444 + 0.06666667 = 1.11111111 + // and 1 / 1.11111111 = 0.9 + // This is used to recycle emissions by redirecting a portion of the rewards to the owner + // If the OWNER_UID is not present in the weights, then we don't need to adjust it. + if let Some(_current_owner_score) = normed_scores.get(OWNER_UID) { + let mut adjusted_scores = normed_scores.to_vec(); + + // Calculate the sum of all scores except the owner + let non_owner_total: f64 = adjusted_scores + .iter() + .enumerate() + .filter(|(i, _)| *i != OWNER_UID) + .map(|(_, score)| *score) + .sum(); + + // Set OWNER_UID score to OWNER_WEIGHT proportion + adjusted_scores[OWNER_UID] = OWNER_WEIGHT; + + // Scale the remaining scores to use the remaining weight (1.0 - OWNER_WEIGHT) + let remaining_weight = 1.0 - OWNER_WEIGHT; + if non_owner_total > 0.0 { + for (i, score) in adjusted_scores.iter_mut().enumerate() { + if i != OWNER_UID { + *score = (*score / non_owner_total) * remaining_weight; + } + } + } + + let new_scores = normalize_min_max(&Array1::from(adjusted_scores)); + debug!("Adjusted scores with OWNER_UID: {:?}", new_scores); + normed_scores = new_scores; + } else { + debug!( + "OWNER_UID {} not found in scores, using normalized scores", + OWNER_UID + ); + } + debug!("weights: {:?}", normed_scores); // Convert normalized scores to Vec let weights: Vec = normed_scores diff --git a/settings.toml.example b/settings.toml.example index ba31fd2..733800b 100644 --- a/settings.toml.example +++ b/settings.toml.example @@ -1,4 +1,4 @@ -version = "0.2.3" +version = "0.2.4" log_level = "INFO" # Must be one of TRACE, DEBUG, INFO, WARN, ERROR netuid = 26 # Testnet is 269