Skip to content

fix: ZeroDivisionError in TwitterCountPenalty when response.count is 0 #333

@Grizouforever

Description

@Grizouforever

Description

In neurons/validators/penalty/twitter_count_penalty.py, the penalty is calculated as:

penalties[index] = 1 - results_count / response.count

If response.count == 0, this raises ZeroDivisionError at runtime.

A miner responding with count=0 (intentionally or due to a bug) will crash the validator's penalty computation for that entire batch.

Steps to Reproduce

  1. Submit a TwitterSearchSynapse response with count=0
  2. The penalty computation raises ZeroDivisionError

Expected Behavior

When response.count == 0, the penalty should be 0.0 (no tweets expected, no penalty) and the loop should continue to the next response.

Actual Behavior

ZeroDivisionError: division by zero is raised, crashing the penalty loop.

Fix

Add a guard before the division: if response.count == 0, set penalties[index] = 0.0 and continue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions