Skip to content

Commit 3cd7804

Browse files
committed
cleaning
1 parent 5364c2f commit 3cd7804

File tree

5 files changed

+46
-134
lines changed

5 files changed

+46
-134
lines changed

subvortex/core/metagraph/database.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ def setup_neuron_models(self):
3131
self.models["neuron"] = {x.version: x for x in [NeuronModel210(), NeuronModel211()]}
3232

3333
async def get_neuron(self, hotkey: str) -> scmm.Neuron:
34-
# Ensure the connection is up and running
34+
# Ensure Redis connection is established before any operation.
3535
await self.ensure_connection()
3636

37-
# Get a client
37+
# Get a connected Redis client, configured with the correct DB index and prefix.
3838
client = await self.get_client()
3939

40-
# Get the active versions
40+
# Get currently active versions of the "neuron" schema to use during read.
4141
_, active = await self._get_migration_status("neuron")
4242

4343
for version in reversed(active):
@@ -63,13 +63,13 @@ async def get_neuron(self, hotkey: str) -> scmm.Neuron:
6363
return None
6464

6565
async def get_neurons(self) -> typing.Dict[str, scmm.Neuron]:
66-
# Ensure the connection is up and running
66+
# Ensure Redis connection is established before any operation.
6767
await self.ensure_connection()
6868

69-
# Get a client
69+
# Get a connected Redis client, configured with the correct DB index and prefix.
7070
client = await self.get_client()
7171

72-
# Get the active versions
72+
# Get currently active versions of the "neuron" schema to use during read.
7373
_, active = await self._get_migration_status("neuron")
7474

7575
for version in reversed(active):
@@ -98,10 +98,10 @@ async def get_neuron_last_updated(self):
9898
"""
9999
Get the block of the last time the metagraph has been updated
100100
"""
101-
# Ensure the connection is up and running
101+
# Ensure Redis connection is established before any operation.
102102
await self.ensure_connection()
103103

104-
# Get a client
104+
# Get a connected Redis client, configured with the correct DB index and prefix.
105105
client = await self.get_client()
106106

107107
try:
@@ -139,13 +139,13 @@ def __init__(self, settings):
139139
self.setup_neuron_models()
140140

141141
async def update_neurons(self, neurons: typing.List[scmm.Neuron]):
142-
# Ensure the connection is up and running
142+
# Ensure Redis connection is established before any operation.
143143
await self.ensure_connection()
144144

145-
# Get a client
145+
# Get a connected Redis client, configured with the correct DB index and prefix.
146146
client = await self.get_client()
147147

148-
# Get the active versions
148+
# Get currently active versions of the "neuron" schema to use during read.
149149
_, active = await self._get_migration_status("neuron")
150150

151151
for version in reversed(active):
@@ -170,10 +170,10 @@ async def update_neurons(self, neurons: typing.List[scmm.Neuron]):
170170
return None
171171

172172
async def remove_neurons(self, neurons: list[Neuron]):
173-
# Ensure the connection is up and running
173+
# Ensure Redis connection is established before any operation.
174174
await self.ensure_connection()
175175

176-
# Get a client
176+
# Get a connected Redis client, configured with the correct DB index and prefix.
177177
client = await self.get_client()
178178

179179
for version, model in self.models["neuron"].items():
@@ -197,10 +197,10 @@ async def set_last_updated(self, block: int):
197197
"""
198198
Set the block of the last time the metagraph has been updated
199199
"""
200-
# Ensure the connection is up and running
200+
# Ensure Redis connection is established before any operation.
201201
await self.ensure_connection()
202202

203-
# Get a client
203+
# Get a connected Redis client, configured with the correct DB index and prefix.
204204
client = await self.get_client()
205205

206206
try:
@@ -225,10 +225,10 @@ async def mark_as_unready(self):
225225
await self._set_state(state="unready")
226226

227227
async def notify_state(self):
228-
# Ensure the connection is up and running
228+
# Ensure Redis connection is established before any operation.
229229
await self.ensure_connection()
230230

231-
# Get a client
231+
# Get a connected Redis client, configured with the correct DB index and prefix.
232232
client = await self.get_client()
233233

234234
try:
@@ -255,10 +255,10 @@ def _key(self, key: str):
255255
return f"{self.settings.key_prefix}:{key}"
256256

257257
async def _set_state(self, state: str):
258-
# Ensure the connection is up and running
258+
# Ensure Redis connection is established before any operation.
259259
await self.ensure_connection()
260260

261-
# Get a client
261+
# Get a connected Redis client, configured with the correct DB index and prefix.
262262
client = await self.get_client()
263263

264264
try:
Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import typing
2-
import traceback
3-
import bittensor.utils.btlogging as btul
4-
5-
from subvortex.miner.neuron.src.models.score import MinerScore100, Score
61
from subvortex.core.metagraph.database import NeuronReadOnlyDatabase
72

83

@@ -20,100 +15,3 @@ class Database(NeuronReadOnlyDatabase):
2015
It builds upon NeuronReadOnlyDatabase and adds write access and multi-model support
2116
for 'selection' and 'miner' domains.
2217
"""
23-
24-
def __init__(self, settings):
25-
super().__init__(settings=settings)
26-
27-
self.setup_neuron_models()
28-
self.models["score"] = {x.version: x for x in [MinerScore100()]}
29-
30-
async def get_scores(self) -> typing.List[Score]:
31-
# Ensure the connection is up and running
32-
await self.ensure_connection()
33-
34-
# Get a client
35-
client = await self.get_client()
36-
37-
# Get the active versions
38-
_, active = await self._get_migration_status("score")
39-
40-
for version in reversed(active):
41-
model = self.models["score"][version]
42-
if not model:
43-
continue
44-
45-
try:
46-
# Attempt to read all neurons using the model
47-
neurons = await model.read_all(client)
48-
return neurons
49-
50-
except Exception as ex:
51-
btul.logging.warning(
52-
f"[get_scores] Failed to read all scores using version={version}: {ex}",
53-
prefix=self.settings.logging_name,
54-
)
55-
btul.logging.debug(
56-
f"[get_scores] Exception type: {type(ex).__name__}, Traceback:\n{traceback.format_exc()}",
57-
prefix=self.settings.logging_name,
58-
)
59-
60-
return []
61-
62-
async def save_scores(self, score: Score, max_entries: int = 100):
63-
"""
64-
Bulk update for a list of miners using active model versions.
65-
"""
66-
await self.ensure_connection()
67-
68-
# Get a client
69-
client = await self.get_client()
70-
71-
_, active = await self._get_migration_status("score")
72-
73-
for version in reversed(active):
74-
model = self.models["score"][version]
75-
if not model:
76-
continue
77-
78-
try:
79-
await model.write(client, score)
80-
81-
except Exception as ex:
82-
btul.logging.warning(
83-
f"[{version}] Update score failed: {ex}",
84-
prefix=self.settings.logging_name,
85-
)
86-
btul.logging.debug(
87-
f"[update_score] Exception type: {type(ex).__name__}, Traceback:\n{traceback.format_exc()}",
88-
prefix=self.settings.logging_name,
89-
)
90-
91-
return None
92-
93-
async def prune_scores(self, max_entries: int):
94-
await self.ensure_connection()
95-
96-
# Get a client
97-
client = await self.get_client()
98-
99-
_, active = await self._get_migration_status("score")
100-
101-
for version in reversed(active):
102-
model = self.models["score"][version]
103-
if not model:
104-
continue
105-
106-
try:
107-
await model.prune(client, max_entries)
108-
109-
except Exception as ex:
110-
btul.logging.warning(
111-
f"[{version}] Update score failed: {ex}",
112-
prefix=self.settings.logging_name,
113-
)
114-
btul.logging.debug(
115-
f"[update_score] Exception type: {type(ex).__name__}, Traceback:\n{traceback.format_exc()}",
116-
prefix=self.settings.logging_name,
117-
)
118-
119-
return None

subvortex/validator/metagraph/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
bittensor==9.6.0
1+
bittensor==9.7.0
22
bittensor-wallet==3.0.10
33
loguru==0.7.0
44
numpy==2.0.1

subvortex/validator/neuron/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
aioredis==2.0.1
2-
bittensor==9.6.0
2+
bittensor==9.7.0
33
bittensor-wallet==3.0.10
44
loguru==0.7.0
55
numpy==2.0.1

subvortex/validator/neuron/src/database.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ async def get_selected_miners(self, ss58_address: str):
4747
"""
4848
Return selected uids for a hotkey using versioned selection models.
4949
"""
50+
# Ensure Redis connection is established before any operation.
5051
await self.ensure_connection()
5152

52-
# Get a client
53+
# Get a connected Redis client, configured with the correct DB index and prefix.
5354
client = await self.get_client()
5455

56+
# Get currently active versions of the "selection" schema to use during read.
5557
_, active = await self._get_migration_status("selection")
5658

5759
for version in reversed(active): # Prefer latest version
@@ -79,11 +81,13 @@ async def set_selection_miners(self, ss58_address: str, uids: list[int]):
7981
"""
8082
Store selected miner UIDs in all active selection model versions.
8183
"""
84+
# Ensure Redis connection is established before any operation.
8285
await self.ensure_connection()
8386

84-
# Get a client
87+
# Get a connected Redis client, configured with the correct DB index and prefix.
8588
client = await self.get_client()
8689

90+
# Get currently active versions of the "selection" schema to use during read.
8791
_, active = await self._get_migration_status("selection")
8892

8993
for version in active:
@@ -106,12 +110,13 @@ async def set_selection_miners(self, ss58_address: str, uids: list[int]):
106110
return None
107111

108112
async def get_miner(self, hotkey: str) -> Miner:
109-
# Ensure the connection is up and running
113+
# Ensure Redis connection is established before any operation.
110114
await self.ensure_connection()
111115

112-
# Get a client
116+
# Get a connected Redis client, configured with the correct DB index and prefix.
113117
client = await self.get_client()
114118

119+
# Get currently active versions of the "miner" schema to use during read.
115120
_, active = await self._get_migration_status("miner")
116121

117122
for version in reversed(active):
@@ -136,12 +141,13 @@ async def get_miner(self, hotkey: str) -> Miner:
136141
return None
137142

138143
async def get_miners(self) -> dict[str, Miner]:
139-
# Ensure the connection is up and running
144+
# Ensure Redis connection is established before any operation.
140145
await self.ensure_connection()
141146

142-
# Get a client
147+
# Get a connected Redis client, configured with the correct DB index and prefix.
143148
client = await self.get_client()
144149

150+
# Get currently active versions of the "miner" schema to use during read.
145151
_, active = await self._get_migration_status("miner")
146152

147153
for version in reversed(active):
@@ -169,11 +175,13 @@ async def add_miner(self, miner: Miner):
169175
"""
170176
Add a new miner record to all active versions of the miner schema.
171177
"""
178+
# Ensure Redis connection is established before any operation.
172179
await self.ensure_connection()
173180

174-
# Get a client
181+
# Get a connected Redis client, configured with the correct DB index and prefix.
175182
client = await self.get_client()
176183

184+
# Get currently active versions of the "miner" schema to use during read.
177185
_, active = await self._get_migration_status("miner")
178186

179187
for version in active:
@@ -200,11 +208,13 @@ async def update_miner(self, miner: Miner):
200208
"""
201209
Update an existing miner record.
202210
"""
211+
# Ensure Redis connection is established before any operation.
203212
await self.ensure_connection()
204213

205-
# Get a client
214+
# Get a connected Redis client, configured with the correct DB index and prefix.
206215
client = await self.get_client()
207216

217+
# Get currently active versions of the "miner" schema to use during read.
208218
_, active = await self._get_migration_status("miner")
209219

210220
for version in reversed(active):
@@ -231,11 +241,13 @@ async def update_miners(self, miners: List[Miner]):
231241
"""
232242
Bulk update for a list of miners using active model versions.
233243
"""
244+
# Ensure Redis connection is established before any operation.
234245
await self.ensure_connection()
235246

236-
# Get a client
247+
# Get a connected Redis client, configured with the correct DB index and prefix.
237248
client = await self.get_client()
238249

250+
# Get currently active versions of the "miner" schema to use during read.
239251
_, active = await self._get_migration_status("miner")
240252

241253
for version in reversed(active):
@@ -262,9 +274,10 @@ async def remove_miner(self, miner: Miner):
262274
"""
263275
Remove a single miner entry from all available versions.
264276
"""
277+
# Ensure Redis connection is established before any operation.
265278
await self.ensure_connection()
266279

267-
# Get a client
280+
# Get a connected Redis client, configured with the correct DB index and prefix.
268281
client = await self.get_client()
269282

270283
for version, model in self.models["miner"].items():
@@ -287,9 +300,10 @@ async def remove_miners(self, miners: List[Miner]):
287300
"""
288301
Remove a single miner entry from all available versions.
289302
"""
303+
# Ensure Redis connection is established before any operation.
290304
await self.ensure_connection()
291305

292-
# Get a client
306+
# Get a connected Redis client, configured with the correct DB index and prefix.
293307
client = await self.get_client()
294308

295309
for version, model in self.models["miner"].items():

0 commit comments

Comments
 (0)