Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions gittensor/validator/storage/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@
AND (uid != %s OR hotkey != %s)
"""

# Reverse cleanup: Remove stale data when a (uid, hotkey) re-links to a new github_id
CLEANUP_STALE_MINER_EVALUATIONS_BY_HOTKEY = """
DELETE FROM miner_evaluations
WHERE uid = %s AND hotkey = %s
AND github_id != %s
AND github_id != '0'
AND created_at <= %s
"""

CLEANUP_STALE_MINER_TIER_STATS_BY_HOTKEY = """
DELETE FROM miner_tier_stats
WHERE uid = %s AND hotkey = %s
AND github_id != %s
AND github_id != '0'
"""

CLEANUP_STALE_MINERS_BY_HOTKEY = """
DELETE FROM miners
WHERE uid = %s AND hotkey = %s
AND github_id != %s
AND github_id != '0'
"""

# Miner Queries
SET_MINER = """
INSERT INTO miners (uid, hotkey, github_id)
Expand Down
11 changes: 11 additions & 0 deletions gittensor/validator/storage/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
BULK_UPSERT_MINER_EVALUATION,
BULK_UPSERT_PULL_REQUESTS,
CLEANUP_STALE_MINER_EVALUATIONS,
CLEANUP_STALE_MINER_EVALUATIONS_BY_HOTKEY,
CLEANUP_STALE_MINER_TIER_STATS_BY_HOTKEY,
CLEANUP_STALE_MINERS,
CLEANUP_STALE_MINERS_BY_HOTKEY,
SET_MINER,
)

Expand Down Expand Up @@ -123,9 +126,17 @@ def cleanup_stale_miner_data(self, evaluation: MinerEvaluation) -> None:
params = (evaluation.github_id, evaluation.uid, evaluation.hotkey)
eval_params = params + (evaluation.evaluation_timestamp,)

# Clean up when same github_id re-registers on a new uid/hotkey
self.execute_command(CLEANUP_STALE_MINER_EVALUATIONS, eval_params)
self.execute_command(CLEANUP_STALE_MINERS, params)

# Clean up when same (uid, hotkey) re-links to a new github_id
reverse_params = (evaluation.uid, evaluation.hotkey, evaluation.github_id)
reverse_eval_params = reverse_params + (evaluation.evaluation_timestamp,)
self.execute_command(CLEANUP_STALE_MINER_EVALUATIONS_BY_HOTKEY, reverse_eval_params)
self.execute_command(CLEANUP_STALE_MINER_TIER_STATS_BY_HOTKEY, reverse_params)
self.execute_command(CLEANUP_STALE_MINERS_BY_HOTKEY, reverse_params)

def store_pull_requests_bulk(self, pull_requests: List[PullRequest]) -> int:
"""
Bulk insert/update pull requests with efficient SQL conflict resolution
Expand Down
Loading