Skip to content

Commit

Permalink
update metagraph sync
Browse files Browse the repository at this point in the history
  • Loading branch information
peterc-yuma committed Jan 9, 2025
1 parent ae7b18e commit 868c876
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions precog/validators/weight_setter.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,28 @@ async def resync_metagraph(self):
self.metagraph.sync(subtensor=self.subtensor)
bt.logging.info("Metagraph updated, re-syncing hotkeys, dendrite pool and moving averages")
# Zero out all hotkeys that have been replaced.
self.available_uids = asyncio.run(self.get_available_uids())
for uid, hotkey in enumerate(self.metagraph.hotkeys):
if (uid not in self.MinerHistory and uid in self.available_uids) or self.hotkeys[uid] != hotkey:
bt.logging.info(f"Replacing hotkey on {uid} with {self.metagraph.hotkeys[uid]}")
self.hotkeys = self.metagraph.hotkeys
self.available_uids = await self.get_available_uids()

new_hotkeys = self.metagraph.hotkeys

# Process each UID
for uid in range(len(new_hotkeys)):
# Check if this is a new UID or if the hotkey has changed
is_new_uid = uid not in self.MinerHistory and uid in self.available_uids
has_hotkey_changed = (
uid < len(self.hotkeys) and uid < len(new_hotkeys) and self.hotkeys[uid] != new_hotkeys[uid]
)

if is_new_uid or has_hotkey_changed:
bt.logging.info(f"Replacing hotkey on {uid} with {new_hotkeys[uid]}")
self.MinerHistory[uid] = MinerHistory(uid, timezone=self.timezone)
self.moving_average_scores[uid] = 0
self.scores = list(self.moving_average_scores.values())

# Update hotkeys after processing
self.hotkeys = new_hotkeys
self.scores = list(self.moving_average_scores.values())

# Save the updated state
self.save_state()

def query_miners(self):
Expand Down

0 comments on commit 868c876

Please sign in to comment.