Skip to content

Commit a67bc9a

Browse files
committed
feat: enhance get_revealed_commits method to filter unique docker_hub_ids and log commit details
1 parent 21c7938 commit a67bc9a

1 file changed

Lines changed: 54 additions & 16 deletions

File tree

services/rewarding/app.py

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,65 @@ def _init_active_challenges(self):
188188

189189
def get_revealed_commits(self) -> dict[str, list[MinerChallengeCommit]]:
190190
"""
191-
Get all revealed (decrypted) commits grouped by challenge name.
191+
Collects all revealed commits from miners.
192+
Filters unique docker_hub_ids in one pass and excludes previously scored submissions.
192193
193194
Returns:
194-
dict[str, list[MinerChallengeCommit]]: Dictionary mapping challenge names to lists of revealed commits
195+
A dictionary where the key is the challenge name and the value is a list of MinerChallengeCommit.
195196
"""
196-
revealed_commits: dict[str, list[MinerChallengeCommit]] = {}
197-
198-
for challenge_name in self.active_challenges.keys():
199-
revealed_commits[challenge_name] = []
197+
seen_docker_hub_ids: set[str] = set()
200198

201-
for (
202-
miner_uid,
203-
miner_hotkey,
204-
), challenge_commits in self.miner_commits.items():
205-
if challenge_name not in challenge_commits:
206-
continue
199+
revealed_commits: dict[str, list[MinerChallengeCommit]] = {}
200+
_list_existing_commits = []
201+
_list_revealed_commits = []
202+
_list_skipped_commits = []
203+
for (uid, hotkey), commits in self.miner_commits.items():
204+
for challenge_name, commit in commits.items():
205+
bt.logging.info(
206+
f"[GET REVEALED COMMITS] Try to reveal commit: {uid} - {hotkey} - {challenge_name} - {commit.encrypted_commit}"
207+
)
208+
if commit.commit:
209+
this_challenge_revealed_commits = revealed_commits.setdefault(
210+
challenge_name, []
211+
)
212+
docker_hub_id = commit.commit.split("---")[1]
207213

208-
commit = challenge_commits[challenge_name]
209-
# Check if commit is revealed (decrypted)
210-
if commit.commit is not None:
211-
revealed_commits[challenge_name].append(commit)
214+
if (
215+
docker_hub_id in seen_docker_hub_ids
216+
or docker_hub_id
217+
in self.challenge_managers[
218+
challenge_name
219+
].get_unique_scored_docker_hub_ids()
220+
):
221+
_list_existing_commits.append(
222+
f"{challenge_name}-{uid}-{hotkey}-{docker_hub_id}"
223+
)
224+
continue
225+
else:
226+
commit.docker_hub_id = docker_hub_id
227+
this_challenge_revealed_commits.append(commit)
228+
seen_docker_hub_ids.add(docker_hub_id)
229+
_list_revealed_commits.append(
230+
f"{challenge_name}-{uid}-{hotkey}-{docker_hub_id}"
231+
)
232+
else:
233+
_list_skipped_commits.append(
234+
f"{challenge_name}-{uid}-{hotkey}"
235+
)
236+
for list_name, list_data in [
237+
("Existing", sorted(_list_existing_commits)),
238+
("Revealed", sorted(_list_revealed_commits)),
239+
("Skipped", sorted(_list_skipped_commits)),
240+
]:
241+
if list_data:
242+
newline = "\n" # Define newline character separately
243+
bt.logging.info(
244+
f"[GET REVEALED COMMITS] {list_name} commits: {newline.join(list_data)}"
245+
)
246+
else:
247+
bt.logging.info(
248+
f"[GET REVEALED COMMITS] No {list_name.lower()} commits"
249+
)
212250

213251
return revealed_commits
214252

0 commit comments

Comments
 (0)