Skip to content

test(relay): pin the handler's PoW rate conversion at non-zero rates (#1263) - #1343

Merged
avantikonde merged 1 commit into
rewrite/mainfrom
fix/1263-relay-pow-rate-nonzero-case
Dec 1, 2026
Merged

avantikonde merged 1 commit into
rewrite/mainfrom
fix/1263-relay-pow-rate-nonzero-case

Conversation

@avantikonde

Copy link
Copy Markdown
Collaborator

Description

Pins the event handler's dynamic PoW rate conversion at a non-zero rate with a socket-level test where accepted events advance context.pow and raise required difficulty above the floor.

Related Issue

Closes #1263

Motivation and Context

In crates/nostream-relay/src/handlers/event.rs, context.pow computes the current events-per-second rate and passes it to required_difficulty(Some(limits), rate, None). Previously, all socket-level tests ran at a rate of zero (HandlerContext.pow starts empty and was never advanced in tests), meaning substituting the literal 0.0 for that conversion would leave the whole suite green.

This PR adds:

  • A socket-level test in tests/handlers.rs where an accepted event advances context.pow under target_events_per_second: 0.01, verifying that the gate dynamically raises required difficulty above the floor and rejects a subsequent event.
  • A unit test in handlers/event.rs verifying required_difficulty scaling at rates above target.

How Has This Been Tested?

  • Ran socket-level tests in crates/nostream-relay/tests/handlers.rs:
    • cargo test -p nostream-relay --test handlers -- the_handler_scales_difficulty_above_floor_as_accepted_events_arrive (passed)
    • cargo test -p nostream-relay --test handlers (67/67 passed)
  • Ran unit tests:
    • cargo test -p nostream-relay --lib (30/30 passed)
  • Ran formatting and lints:
    • cargo fmt --all --check
    • cargo clippy -p nostream-relay --all-targets --all-features -- -D warnings
    • Strict clippy with -D clippy::unwrap_used -D clippy::expect_used

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • I added a changeset, or this is docs-only and I added an empty changeset.
  • All new and existing tests passed.

@changeset-bot

changeset-bot Bot commented Dec 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e92993f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 87cdb2e3-56bb-4b6d-a8a0-1354a058beab

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@greptile-apps

greptile-apps Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

Adds tests for the handler’s proof-of-work difficulty at nonzero event rates.

  • Accepted events can raise the proof-of-work difficulty required for the next event.

Reviews (1) · Last reviewed commit: "test(relay): pin the handler's PoW rate ..." · Reviewed by Greptile

@avantikonde
avantikonde merged commit ead3997 into rewrite/main Dec 1, 2026
19 checks passed
@avantikonde
avantikonde deleted the fix/1263-relay-pow-rate-nonzero-case branch December 1, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant