Repository navigation
refactor(relay): skip the WoT thresholds vec when the distance is None (#1264) - #1273
Conversation
🦋 Changeset detectedLatest commit: 7e7229e The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen 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 |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
[Low impact] The PR appears safe to merge; the early return preserves the required difficulty.
|
Description
Short-circuits
required_difficultyincrates/nostream-relay/src/handlers/event.rswhendistance.is_none(), returningcomputeddifficulty directly and avoiding mapping and collectinglimits.event.pow.wot_thresholdsinto a heap-allocatedVec<WotPowThreshold>.Related Issue
Closes #1264
Motivation and Context
In
required_difficulty,limits.event.pow.wot_thresholdswas mapped and collected into aVec<WotPowThreshold>on every admitted event before callingadaptive_pow::apply_wot_pow_policy. WhendistanceisNone(which is true at all current event handler and NIP-11 call sites),apply_wot_pow_policyreturns 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?
crates/nostream-relay/src/handlers/event.rs:required_difficulty_skips_thresholds_when_distance_is_none: verifies thatdistance: Nonereturns the computed difficulty without threshold discount, and thatdistance: 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.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)cargo fmt --check --package nostream-relaycargo clippy -p nostream-relay --all-targets -- -D warningsTypes of changes
Checklist: