Repository navigation
Commit ead3997
authored
## 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
- [x] 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:
- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the **CONTRIBUTING** document.
- [x] I have added tests to cover my code changes.
- [x] I added a changeset, or this is docs-only and I added an empty
changeset.
- [x] All new and existing tests passed.
3 files changed
Lines changed: 60 additions & 0 deletions
File tree
- .changeset
- crates/nostream-relay
- src/handlers
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
735 | 735 | | |
736 | 736 | | |
737 | 737 | | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
738 | 761 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
424 | 424 | | |
425 | 425 | | |
426 | 426 | | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
427 | 460 | | |
428 | 461 | | |
429 | 462 | | |
| |||
0 commit comments