Skip to content

Commit ea4ea68

Browse files
committed
fix last issue
1 parent fed5d83 commit ea4ea68

4 files changed

Lines changed: 23 additions & 35 deletions

File tree

subvortex/core/model/neuron/model_neuron_210.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ async def write_all(self, redis: Redis, neurons: list[Neuron]):
5454
pipe.hmset(key, data)
5555
await pipe.execute()
5656

57-
async def delete(self, redis: Redis, hotkey: str):
58-
key = self._key(hotkey)
57+
async def delete(self, redis: Redis, neuron: Neuron):
58+
key = self._key(neuron.hotkey)
5959
await redis.delete(key)
6060

6161
async def delete_all(self, redis: Redis, neurons: list[Neuron]):

subvortex/validator/neuron/src/miner.py

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,26 @@ async def sync_miners(
7272
# Check if the miner did not exist
7373
if current_miner is None:
7474
# Create the new miner
75-
miner = Miner.create_new_miner(
75+
current_miner = Miner.create_new_miner(
7676
uid=neuron.uid,
7777
)
78+
elif current_miner.hotkey != hotkey:
79+
# Remove the old miner
80+
await database.remove_miner(miner=current_miner)
7881

79-
# Add the new miner
80-
await database.add_miner(miner)
82+
# Reset the updated miner
83+
current_miner.reset()
8184

82-
# Add the new miner to the list
83-
miners.append(miner)
85+
# Log the success
86+
btul.logging.success(
87+
f"[{current_miner.uid}] New miner {hotkey} added to the list"
88+
)
8489

85-
continue
90+
# Check if the miner has changed localisation
91+
if current_miner.ip != neuron.ip:
92+
btul.logging.success(
93+
f"[{current_miner.uid}] Miner moved from {current_miner.ip} to {neuron.ip}"
94+
)
8695

8796
# Create an updated miner
8897
miner = current_miner.clone()
@@ -97,26 +106,6 @@ async def sync_miners(
97106
miner.placeholder1 = neuron.placeholder1
98107
miner.placeholder2 = neuron.placeholder2
99108

100-
# Check if the miner has changed ownership
101-
if current_miner.hotkey != hotkey:
102-
# Remove the old miner
103-
await database.remove_miner(miner=miner)
104-
105-
# Reset the updated miner
106-
miner.reset()
107-
108-
# Add the new miner
109-
await database.add_miner(miner=miner)
110-
111-
# Log the success
112-
btul.logging.success(f"[{miner.uid}] New miner {hotkey} added to the list")
113-
114-
# Check if the miner has changed localisation
115-
if current_miner.ip != neuron.ip:
116-
btul.logging.success(
117-
f"[{miner.uid}] Miner moved from {miner} to {neuron.ip}"
118-
)
119-
120109
miners_updates.append(miner)
121110

122111
# Define the ip occurences

subvortex/validator/neuron/src/models/miner/model_miner_210.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ async def write_all(self, redis: Redis, miners: list[Miner]):
7373

7474
await pipe.execute()
7575

76-
async def delete(self, redis: Redis, ss58_address: str):
76+
async def delete(self, redis: Redis, miner: Miner):
7777
"""
7878
Delete the statistics entry for a given hotkey.
7979
"""
80-
key = self._key(ss58_address)
80+
key = self._key(miner.hotkey)
8181
await redis.delete(key)

subvortex/validator/neuron/tests/src/test_miner.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ async def test_sync_miners_adds_missing_miners():
5454
validator = fake_neuron(999, country="US")
5555
locations = ["US", "CA"]
5656

57-
await sync_miners(db, neurons, miners, validator, locations)
57+
result = await sync_miners(db, neurons, miners, validator, locations)
5858

59-
assert len(miners) == 1
60-
assert miners[0].uid == 1
61-
db.add_miner.assert_called_once()
59+
assert len(result) == 1
60+
assert result[0].uid == 1
61+
# db.add_miner.assert_called_once()
6262

6363

6464
@pytest.mark.asyncio
@@ -73,7 +73,6 @@ async def test_sync_miners_handles_hotkey_change():
7373
await sync_miners(db, neurons, miners, validator, locations)
7474

7575
db.remove_miner.assert_called_once()
76-
db.add_miner.assert_called()
7776

7877

7978
@pytest.mark.asyncio

0 commit comments

Comments
 (0)