Skip to content

refactor(relay): skip the WoT thresholds vec when the distance is None (#1264) - #1273

Merged
cameri merged 1 commit into
rewrite/mainfrom
fix/1264-skip-wot-thresholds-none
Nov 28, 2026
Merged

cameri merged 1 commit into
rewrite/mainfrom
fix/1264-skip-wot-thresholds-none

Conversation

@avantikonde

Copy link
Copy Markdown
Collaborator

Description

Short-circuits required_difficulty in crates/nostream-relay/src/handlers/event.rs when distance.is_none(), returning computed difficulty directly and avoiding mapping and collecting limits.event.pow.wot_thresholds into a heap-allocated Vec<WotPowThreshold>.

Related Issue

Closes #1264

Motivation and Context

In required_difficulty, limits.event.pow.wot_thresholds was mapped and collected into a Vec<WotPowThreshold> on every admitted event before calling adaptive_pow::apply_wot_pow_policy. When distance is None (which is true at all current event handler and NIP-11 call sites), apply_wot_pow_policy returns the computed difficulty unchanged and discards the thresholds.

By skipping threshold collection when distance.is_none(), we eliminate an unnecessary heap allocation on every admitted event whenever proof-of-work thresholds are configured.

How Has This Been Tested?

  • Added unit tests in crates/nostream-relay/src/handlers/event.rs:
    • required_difficulty_skips_thresholds_when_distance_is_none: verifies that distance: None returns the computed difficulty without threshold discount, and that distance: Some(d) applies the matching discount.
    • required_difficulty_handles_empty_or_absent_thresholds: verifies that empty and absent threshold lists are handled gracefully without error.
  • Ran all unit and integration tests across nostream-relay (287/287 passed):
    • cargo test -p nostream-relay --lib (24 passed)
    • cargo test -p nostream-relay --test nip11 (8 passed)
    • cargo test -p nostream-relay (all 287 passed)
  • Verified formatting and lints:
    • cargo fmt --check --package nostream-relay
    • cargo clippy -p nostream-relay --all-targets -- -D warnings

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 Nov 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7e7229e

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 Nov 28, 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: 72a94fc2-d1d1-42b7-9250-28b5a8dd419b

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 Nov 28, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; the early return preserves the required difficulty.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; the early return preserves the required difficulty.

Summary

required_difficulty now skips building the threshold vector when distance is None.

  • Relay difficulty checks skip unused trust thresholds when distance is missing.

Reviews (1) · Last reviewed commit: "refactor(relay): skip WoT thresholds vec..." · Reviewed by Greptile

@cameri
cameri merged commit 8cdbd0f into rewrite/main Nov 28, 2026
19 checks passed
@cameri
cameri deleted the fix/1264-skip-wot-thresholds-none branch November 28, 2026 22:49
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.

2 participants