File size: 1,373 Bytes
e5457b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64fdbb7
 
e5457b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64fdbb7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import bittensor as bt
import requests
import json

subtensor = bt.subtensor()
metagraph = bt.metagraph(netuid=36)

#print(metagraph.axons)

#print(metagraph.validator_permit[48])


def get_validator_ids():
    return [i for i in range(len(metagraph.validator_permit)) if metagraph.validator_permit[i]]

def get_validator_axons(list):
    return [metagraph.axons[uid].ip_str().split('/')[-1] for uid in list]


#print(get_validator_axons(get_validator_ids()))


response = requests.get('http://' + metagraph.axons[178].ip_str().split('/')[-1] + '/step')
response.raise_for_status()
print(response.json())
def get_validator_bits(validator_ids, timeout=5, retries=3):
    results = []
    for uid in validator_ids:
        for attempt in range(retries):
            try:
                ip = metagraph.axons[uid].ip_str().split('/')[-1]
                response = requests.get(f'http://{ip}/step', timeout=timeout)
                response.raise_for_status()
                results.append(response.json())
                break  # Success, exit retry loop
            except requests.exceptions.RequestException as e:
                if attempt == retries - 1:  # Last attempt
                    print(f"Failed to get bits from validator {uid} after {retries} attempts: {str(e)}")
                continue
    return results

#print(get_validator_bits(get_validator_ids()))