Skip to content

Commit 444ff30

Browse files
committed
fix last details
1 parent 5364c2f commit 444ff30

File tree

5 files changed

+53
-144
lines changed

5 files changed

+53
-144
lines changed

subvortex/core/metagraph/database.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,22 @@ class NeuronReadOnlyDatabase(BaseDatabase):
2626
of modifying it.
2727
"""
2828

29-
def setup_neuron_models(self):
29+
def __init__(self, settings):
30+
super().__init__(settings=settings)
31+
3032
# Register neuron models keyed by their version
31-
self.models["neuron"] = {x.version: x for x in [NeuronModel210(), NeuronModel211()]}
33+
self.models["neuron"] = {
34+
x.version: x for x in [NeuronModel210(), NeuronModel211()]
35+
}
3236

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

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

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

4347
for version in reversed(active):
@@ -63,13 +67,13 @@ async def get_neuron(self, hotkey: str) -> scmm.Neuron:
6367
return None
6468

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

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

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

7579
for version in reversed(active):
@@ -98,10 +102,10 @@ async def get_neuron_last_updated(self):
98102
"""
99103
Get the block of the last time the metagraph has been updated
100104
"""
101-
# Ensure the connection is up and running
105+
# Ensure Redis connection is established before any operation.
102106
await self.ensure_connection()
103107

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

107111
try:
@@ -134,18 +138,14 @@ class NeuronDatabase(NeuronReadOnlyDatabase):
134138
Use this class in components responsible for managing or syncing neuron state.
135139
"""
136140

137-
def __init__(self, settings):
138-
super().__init__(settings=settings)
139-
self.setup_neuron_models()
140-
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,20 +225,18 @@ 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:
235235
# Get the current state of the metagraph
236236
state = await client.get(self._key("state:metagraph"))
237237

238238
# Notify downstream via Redis stream
239-
await client.xadd(
240-
self._key("state:metagraph:stream"), {"state": state}
241-
)
239+
await client.xadd(self._key("state:metagraph:stream"), {"state": state})
242240

243241
except Exception as ex:
244242
btul.logging.error(
@@ -255,10 +253,10 @@ def _key(self, key: str):
255253
return f"{self.settings.key_prefix}:{key}"
256254

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

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

264262
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

0 commit comments

Comments
 (0)