Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = ["crates/*"]
default-members = ["crates/storb_cli"]

[workspace.package]
version = "0.2.2"
version = "0.2.3"
description = "An object storage subnet on the Bittensor network"
edition = "2021"
authors = ["Storb Technologies Ltd"]
Expand Down
2 changes: 1 addition & 1 deletion crates/storb_base/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ pub const CHUNK_M: usize = 8;
pub const INFO_REQ_TIMEOUT: Duration = Duration::from_secs(5);

/// Timeout params for upload requests
pub const MIN_BANDWIDTH: u64 = 20 * 1024; // minimum "bandwidth"
pub const MIN_BANDWIDTH: u64 = 100 * 1024; // 100 KiB/s

pub const SYNC_BUFFER_SIZE: usize = 32;
2 changes: 1 addition & 1 deletion crates/storb_miner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "storb_miner"
version = "0.2.2"
version = "0.2.3"
edition.workspace = true

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/storb_validator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "storb_validator"
version = "0.2.2"
version = "0.2.3"
edition.workspace = true

[dependencies]
Expand Down
12 changes: 7 additions & 5 deletions crates/storb_validator/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ pub const SYNTHETIC_CHALLENGE_FREQUENCY: u64 = 300;
pub const MAX_CHALLENGE_PIECE_NUM: i32 = 5;
pub const SYNTH_CHALLENGE_TIMEOUT: f64 = 1.0; // TODO: modify this
pub const SYNTH_CHALLENGE_WAIT_BEFORE_RETRIEVE: f64 = 3.0;
pub const MIN_SYNTH_CHUNK_SIZE: usize = 1024 * 10 * 10; // minimum size of synthetic data in bytes
pub const MAX_SYNTH_CHUNK_SIZE: usize = 1024 * 10 * 10 * 10 * 10; // maximum size of synthetic data in bytes
pub const MAX_SYNTH_CHALLENGE_MINER_NUM: usize = 25; // maximum number of miners to challenge
pub const MIN_SYNTH_CHUNK_SIZE: usize = 512 * 1024; // minimum size of synthetic data in bytes
pub const MAX_SYNTH_CHUNK_SIZE: usize = 8 * 1024 * 1024; // maximum size of synthetic data in bytes
pub const MAX_SYNTH_CHALLENGE_MINER_NUM: usize = 50; // maximum number of miners to challenge

// constants for MetadataDB
pub const DB_MAX_LIFETIME: u64 = 3600; // Close connections after 1 hour
Expand All @@ -34,5 +34,7 @@ pub const INFO_API_RATE_LIMIT_MAX_REQUESTS: usize = 10;

// Initial values for alpha and beta used in the scoring system
// These were empirically derived to minimise reliable node churn
pub const INITIAL_ALPHA: f64 = 500.0;
pub const INITIAL_BETA: f64 = 1000.0;
pub const INITIAL_ALPHA: f64 = 18.0;
pub const INITIAL_BETA: f64 = 36.0;
pub const LAMBDA: f64 = 0.99;
pub const AUDIT_WEIGHT: f64 = 1.0;
9 changes: 5 additions & 4 deletions crates/storb_validator/src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use tokio::sync::{mpsc, Mutex, RwLock};
use tokio_stream::StreamExt;
use tracing::{debug, error, trace};

use crate::constants::AUDIT_WEIGHT;
use crate::metadata;
use crate::metadata::db::MetadataDBCommand;
use crate::scoring::ScoringSystem;
Expand All @@ -34,7 +35,7 @@ pub async fn update_scoring_on_failure(
) -> Result<()> {
let mut scoring_system_rw = scoring_system.write().await;
scoring_system_rw
.update_alpha_beta_db(miner_uid, 1.0, false)
.update_alpha_beta_db(miner_uid, AUDIT_WEIGHT, false)
.await
.map_err(|e| anyhow!("Failed to update scoring system: {}", e))?;
drop(scoring_system_rw);
Expand Down Expand Up @@ -238,7 +239,7 @@ impl DownloadProcessor {
Err(e) => {
let mut scoring_system_rw = scoring_system.write().await;
scoring_system_rw
.update_alpha_beta_db(miner_uid, 1.0, false)
.update_alpha_beta_db(miner_uid, AUDIT_WEIGHT, false)
.await
.map_err(|e| anyhow!("Failed to update scoring system: {}", e))?;
drop(scoring_system_rw);
Expand Down Expand Up @@ -272,7 +273,7 @@ impl DownloadProcessor {
Err(e) => {
let mut scoring_system_rw = scoring_system.write().await;
scoring_system_rw
.update_alpha_beta_db(miner_uid, 1.0, false)
.update_alpha_beta_db(miner_uid, AUDIT_WEIGHT, false)
.await
.map_err(|e| anyhow!("Failed to update scoring system: {}", e))?;
drop(scoring_system_rw);
Expand All @@ -285,7 +286,7 @@ impl DownloadProcessor {
db.conn.lock().await.execute("UPDATE miner_stats SET total_successes = total_successes + 1 WHERE miner_uid = $1", [&miner_uid])?;
let mut scoring_system_rw = scoring_system.write().await;
scoring_system_rw
.update_alpha_beta_db(miner_uid, 1.0, true)
.update_alpha_beta_db(miner_uid, AUDIT_WEIGHT, true)
.await
.map_err(|e| anyhow!("Failed to update scoring system: {}", e))?;
drop(scoring_system_rw);
Expand Down
7 changes: 4 additions & 3 deletions crates/storb_validator/src/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rusqlite::params;
use serde::{Deserialize, Serialize};
use tracing::{debug, error, info, warn};

use crate::constants::{INITIAL_ALPHA, INITIAL_BETA};
use crate::constants::{INITIAL_ALPHA, INITIAL_BETA, LAMBDA};

/// ScoreState stores the scores for each miner.
///
Expand Down Expand Up @@ -39,6 +39,7 @@ pub struct ScoringSystem {
pub lambda: f64,
}

// normalization function that produces an s curve
#[inline]
pub fn normalize_min_max(arr: &Array1<f64>) -> Array1<f64> {
let min = arr.iter().cloned().fold(f64::INFINITY, f64::min);
Expand Down Expand Up @@ -100,7 +101,7 @@ impl ScoringSystem {
state_file: scoring_state_file.to_path_buf(),
initial_alpha: INITIAL_ALPHA,
initial_beta: INITIAL_BETA,
lambda: 0.99, // forgetting factor for challenges
lambda: LAMBDA, // forgetting factor for challenges
};

match scoring_system.load_state() {
Expand Down Expand Up @@ -163,7 +164,7 @@ impl ScoringSystem {
)?;

// calculate new alpha and beta
let (new_beta, new_alpha) = get_new_alpha_beta(beta, alpha, 0.99, weight, success);
let (new_beta, new_alpha) = get_new_alpha_beta(beta, alpha, LAMBDA, weight, success);
// update alpha and beta in the database
conn.execute(
"UPDATE miner_stats SET alpha = ?1, beta = ?2 WHERE miner_uid = ?3",
Expand Down
22 changes: 3 additions & 19 deletions crates/storb_validator/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use subxt::ext::codec::Compact;
use tokio::sync::{mpsc, RwLock};
use tracing::{debug, error, info, trace, warn};

use crate::constants::MIN_REQUIRED_MINERS;
use crate::constants::{AUDIT_WEIGHT, MIN_REQUIRED_MINERS};
use crate::metadata;
use crate::metadata::models::SqlAccountId;
use crate::quic::establish_miner_connections;
Expand Down Expand Up @@ -79,7 +79,6 @@ pub async fn upload_piece_data(
message,
};
let payload_bytes = bincode::serialize(&payload)?;
debug!("payload_bytes: {:?}", payload_bytes);

let piece_size = data.len();
let size: f64 = piece_size as f64;
Expand All @@ -101,11 +100,6 @@ pub async fn upload_piece_data(
send_stream.write_all(&data).await?;
send_stream.finish()?;

debug!(
"Timeout duration for upload acknowledgement: {} milliseconds",
timeout_duration.as_millis()
);

// Wrap the upload response operation in a timeout
let hash = tokio::time::timeout(timeout_duration, async {
// Read hash response
Expand Down Expand Up @@ -316,16 +310,6 @@ impl<'a> UploadProcessor<'a> {
..infohash_value
};

// display chunks_with_pieces
debug!("Chunks with pieces: {:?}", chunks_with_pieces);

// display hash of chunks_with_pieces
let serialized = bincode::serialize(&chunks_with_pieces)?;
debug!(
"HASH: {}",
hex::encode(blake3::hash(&serialized).as_bytes())
);

match metadata::db::MetadataDB::insert_object(
&metadatadb_sender,
signed_infohash_value,
Expand Down Expand Up @@ -691,12 +675,12 @@ pub async fn upload_piece_to_miner(
)?;
let mut scoring_system_guard = scoring_system.write().await;
scoring_system_guard
.update_alpha_beta_db(miner_uid, 1.0, true)
.update_alpha_beta_db(miner_uid, AUDIT_WEIGHT, true)
.await?;
} else {
let mut scoring_system_guard = scoring_system.write().await;
scoring_system_guard
.update_alpha_beta_db(miner_uid, 1.0, false)
.update_alpha_beta_db(miner_uid, AUDIT_WEIGHT, false)
.await?;
}

Expand Down
4 changes: 2 additions & 2 deletions migrations/scoresdb/20250222003351_db.up.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- Table for miner stats --
CREATE TABLE miner_stats (
miner_uid INTEGER PRIMARY KEY,
alpha FLOAT DEFAULT 500.0,
beta FLOAT DEFAULT 1000.0,
alpha FLOAT DEFAULT 18.0,
beta FLOAT DEFAULT 36.0,
challenge_successes INTEGER DEFAULT 0,
challenge_attempts INTEGER DEFAULT 0,
retrieval_successes INTEGER DEFAULT 0,
Expand Down
2 changes: 1 addition & 1 deletion settings.toml.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.2.2"
version = "0.2.3"
log_level = "INFO" # Must be one of TRACE, DEBUG, INFO, WARN, ERROR

netuid = 26 # Testnet is 269
Expand Down
Loading