Skip to content

Commit 7fdfa41

Browse files
committed
fix: clean up stale miner data when hotkey re-links to new GitHub account
1 parent ad759cd commit 7fdfa41

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

gittensor/validator/storage/queries.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,29 @@
2323
AND (uid != %s OR hotkey != %s)
2424
"""
2525

26+
# Reverse cleanup: Remove stale data when a (uid, hotkey) re-links to a new github_id
27+
CLEANUP_STALE_MINER_EVALUATIONS_BY_HOTKEY = """
28+
DELETE FROM miner_evaluations
29+
WHERE uid = %s AND hotkey = %s
30+
AND github_id != %s
31+
AND github_id != '0'
32+
AND created_at <= %s
33+
"""
34+
35+
CLEANUP_STALE_MINER_TIER_STATS_BY_HOTKEY = """
36+
DELETE FROM miner_tier_stats
37+
WHERE uid = %s AND hotkey = %s
38+
AND github_id != %s
39+
AND github_id != '0'
40+
"""
41+
42+
CLEANUP_STALE_MINERS_BY_HOTKEY = """
43+
DELETE FROM miners
44+
WHERE uid = %s AND hotkey = %s
45+
AND github_id != %s
46+
AND github_id != '0'
47+
"""
48+
2649
# Miner Queries
2750
SET_MINER = """
2851
INSERT INTO miners (uid, hotkey, github_id)

gittensor/validator/storage/repository.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
BULK_UPSERT_MINER_TIER_STATS,
2323
BULK_UPSERT_PULL_REQUESTS,
2424
CLEANUP_STALE_MINER_EVALUATIONS,
25+
CLEANUP_STALE_MINER_EVALUATIONS_BY_HOTKEY,
2526
CLEANUP_STALE_MINER_TIER_STATS,
27+
CLEANUP_STALE_MINER_TIER_STATS_BY_HOTKEY,
2628
CLEANUP_STALE_MINERS,
29+
CLEANUP_STALE_MINERS_BY_HOTKEY,
2730
DELETE_PREDICTIONS_FOR_ISSUE,
2831
SET_MINER,
2932
UPSERT_PREDICTION,
@@ -130,10 +133,18 @@ def cleanup_stale_miner_data(self, evaluation: MinerEvaluation) -> None:
130133
params = (evaluation.github_id, evaluation.uid, evaluation.hotkey)
131134
eval_params = params + (evaluation.evaluation_timestamp,)
132135

136+
# Clean up when same github_id re-registers on a new uid/hotkey
133137
self.execute_command(CLEANUP_STALE_MINER_EVALUATIONS, eval_params)
134138
self.execute_command(CLEANUP_STALE_MINER_TIER_STATS, params)
135139
self.execute_command(CLEANUP_STALE_MINERS, params)
136140

141+
# Clean up when same (uid, hotkey) re-links to a new github_id
142+
reverse_params = (evaluation.uid, evaluation.hotkey, evaluation.github_id)
143+
reverse_eval_params = reverse_params + (evaluation.evaluation_timestamp,)
144+
self.execute_command(CLEANUP_STALE_MINER_EVALUATIONS_BY_HOTKEY, reverse_eval_params)
145+
self.execute_command(CLEANUP_STALE_MINER_TIER_STATS_BY_HOTKEY, reverse_params)
146+
self.execute_command(CLEANUP_STALE_MINERS_BY_HOTKEY, reverse_params)
147+
137148
def store_pull_requests_bulk(self, pull_requests: List[PullRequest]) -> int:
138149
"""
139150
Bulk insert/update pull requests with efficient SQL conflict resolution

0 commit comments

Comments
 (0)