Skip to content

Commit fcc099c

Browse files
committed
debug: add stake logging for metagraph sync troubleshooting
1 parent 63ed510 commit fcc099c

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

bins/validator-node/src/main.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,23 @@ async fn main() -> Result<()> {
808808
let mut added = 0;
809809
let mut state = chain_state.write();
810810

811+
// Debug: collect top stakes for logging
812+
let mut top_stakes: Vec<(u64, u128, u128, u128)> = metagraph.neurons
813+
.iter()
814+
.map(|(uid, n)| (*uid, n.stake, n.root_stake, n.stake.saturating_add(n.root_stake)))
815+
.collect();
816+
top_stakes.sort_by(|a, b| b.3.cmp(&a.3));
817+
818+
info!("Top 10 neurons by effective stake:");
819+
for (uid, alpha, root, total) in top_stakes.iter().take(10) {
820+
info!(" UID {}: alpha={:.2} TAO, root={:.2} TAO, total={:.2} TAO",
821+
uid,
822+
*alpha as f64 / 1e9,
823+
*root as f64 / 1e9,
824+
*total as f64 / 1e9
825+
);
826+
}
827+
811828
for neuron in metagraph.neurons.values() {
812829
// Convert AccountId32 hotkey to our Hotkey type
813830
let hotkey_bytes: &[u8; 32] = neuron.hotkey.as_ref();
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use bittensor_rs::metagraph::sync_metagraph;
2+
use bittensor_rs::BittensorClient;
3+
4+
#[tokio::main]
5+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
6+
println!("Connecting to Bittensor finney...");
7+
8+
let client = BittensorClient::new("wss://entrypoint-finney.opentensor.ai:443").await?;
9+
10+
println!("Querying subnet 100 metagraph...\n");
11+
12+
let metagraph = sync_metagraph(&client, 100).await?;
13+
14+
println!("Total neurons: {}", metagraph.n);
15+
println!("\nTop 30 by effective stake (alpha + root):");
16+
println!("{:-<90}", "");
17+
18+
// Collect stakes
19+
let mut stakes: Vec<(u16, String, u128, u128, u128)> = metagraph.neurons
20+
.iter()
21+
.map(|(uid, neuron)| {
22+
let alpha = neuron.stake;
23+
let root = neuron.root_stake;
24+
let total = alpha.saturating_add(root);
25+
let hotkey_str = format!("{}", neuron.hotkey);
26+
(*uid as u16, hotkey_str, alpha, root, total)
27+
})
28+
.filter(|(_, _, _, _, total)| *total > 0)
29+
.collect();
30+
31+
// Sort by total stake descending
32+
stakes.sort_by(|a, b| b.4.cmp(&a.4));
33+
34+
println!("{:<6} {:<50} {:>12} {:>12} {:>12}", "UID", "Hotkey", "Alpha", "Root", "Total TAO");
35+
println!("{:-<90}", "");
36+
37+
for (uid, hotkey, alpha, root, total) in stakes.iter().take(30) {
38+
let alpha_tao = *alpha as f64 / 1_000_000_000.0;
39+
let root_tao = *root as f64 / 1_000_000_000.0;
40+
let total_tao = *total as f64 / 1_000_000_000.0;
41+
println!("{:<6} {:<50} {:>12.2} {:>12.2} {:>12.2}",
42+
uid, hotkey, alpha_tao, root_tao, total_tao);
43+
}
44+
45+
let gte_1000 = stakes.iter().filter(|(_, _, _, _, t)| *t as f64 / 1e9 >= 1000.0).count();
46+
let gte_100 = stakes.iter().filter(|(_, _, _, _, t)| *t as f64 / 1e9 >= 100.0).count();
47+
let gte_10 = stakes.iter().filter(|(_, _, _, _, t)| *t as f64 / 1e9 >= 10.0).count();
48+
let gt_0 = stakes.len();
49+
50+
println!("\n{:-<90}", "");
51+
println!("Validators with >= 1000 TAO: {}", gte_1000);
52+
println!("Validators with >= 100 TAO: {}", gte_100);
53+
println!("Validators with >= 10 TAO: {}", gte_10);
54+
println!("Validators with > 0 TAO: {}", gt_0);
55+
56+
Ok(())
57+
}

0 commit comments

Comments
 (0)