queries
queries
¶
Validator-specific database queries.
Classes¶
Functions¶
delete_promoted_candidates
async
¶
delete_promoted_candidates(brotr: Brotr) -> int
Remove candidates that have already been promoted to the relay table.
Deletes CHECKPOINT records whose state_key matches a URL that now
exists in the relay table. Called during cleanup as a safety net
for candidates that were validated but whose deletion after promotion
failed.
Parameters:
Returns:
-
int–Number of deleted rows.
Source code in src/bigbrotr/services/validator/queries.py
delete_exhausted_candidates
async
¶
delete_exhausted_candidates(
brotr: Brotr, max_failures: int
) -> int
Remove candidates that have exceeded the failure threshold.
Deletes CHECKPOINT records whose failures counter meets or exceeds
max_failures. Called during cleanup when cleanup.enabled is
True to prevent permanently broken relays from consuming validation
resources indefinitely.
Parameters:
-
brotr(Brotr) –Brotr database interface.
-
max_failures(int) –Failure threshold above which candidates are removed.
Returns:
-
int–Number of deleted rows.
Source code in src/bigbrotr/services/validator/queries.py
count_candidates
async
¶
count_candidates(
brotr: Brotr,
networks: list[NetworkType],
attempted_before: int,
) -> int
Count pending validation candidates for the given networks.
Parameters:
-
brotr(Brotr) –Brotr database interface.
-
networks(list[NetworkType]) –Network types to include.
-
attempted_before(int) –Only count candidates whose last validation attempt
timestampis before this Unix timestamp. Candidates with zero failures (never attempted) are always counted.
Returns:
-
int–Total count of matching candidates.
Source code in src/bigbrotr/services/validator/queries.py
fetch_candidates
async
¶
fetch_candidates(
brotr: Brotr,
networks: list[NetworkType],
attempted_before: int,
limit: int,
) -> list[CandidateCheckpoint]
Fetch candidates prioritized by fewest failures, then oldest attempt.
Returns candidates that either have zero failures (never attempted)
or whose last attempt timestamp is before attempted_before.
Rows whose state_key is not a valid relay URL are skipped
with a warning.
Parameters:
-
brotr(Brotr) –Brotr database interface.
-
networks(list[NetworkType]) –Network types to include.
-
attempted_before(int) –Only fetch candidates whose last validation attempt
timestampis before this Unix timestamp. Candidates with zero failures (never attempted) are always included. -
limit(int) –Maximum candidates to return.
Returns:
-
list[CandidateCheckpoint]–List of CandidateCheckpoint
-
list[CandidateCheckpoint]–instances.
Source code in src/bigbrotr/services/validator/queries.py
promote_candidates
async
¶
promote_candidates(
brotr: Brotr, candidates: list[CandidateCheckpoint]
) -> int
Insert relays and remove their candidate records.
Parameters:
-
brotr(Brotr) –Brotr database interface.
-
candidates(list[CandidateCheckpoint]) –Validated CandidateCheckpoint objects to promote from
service_stateto the relays table.
Returns:
-
int–Number of relays inserted (duplicates skipped via
ON CONFLICT).
Source code in src/bigbrotr/services/validator/queries.py
fail_candidates
async
¶
fail_candidates(
brotr: Brotr, candidates: list[CandidateCheckpoint]
) -> int
Increment the failure counter on invalid candidates.
Builds ServiceState records
with failures + 1 and upserts them.
Parameters:
-
brotr(Brotr) –Brotr database interface.
-
candidates(list[CandidateCheckpoint]) –CandidateCheckpoint objects that failed validation.
Returns:
-
int–Number of records upserted.