Skip to content

sdk: reset subscription limit tracking when restoring a subscription - #1493

Merged
yukibtc merged 1 commit into
nostrdevkit:masterfrom
erskingardner:sdk/reset-limit-state-on-resubscribe
Oct 15, 2026
Merged

yukibtc merged 1 commit into
nostrdevkit:masterfrom
erskingardner:sdk/reset-limit-state-on-resubscribe

Conversation

@erskingardner

Copy link
Copy Markdown
Contributor

Description

When subscription verification is on (verify_subscriptions or ban_relay_on_mismatch), the SDK counts the stored events a subscription receives before EOSE if it has a single filter with a limit. Any event past the limit is rejected, and with ban_relay_on_mismatch the relay is banned.

Problem. When a subscription is restored after a reconnect, its REQ is sent again, so the relay starts a new stored-events query. update_subscription(.., true) kept the previous received_eose flag and received_events count, which causes two problems:

  • The connection dropped before EOSE: the count continues from the previous session. A well-behaved relay that resends its stored events goes over the limit, its events are rejected, and with ban_relay_on_mismatch it is banned.
  • EOSE had already been received: the limit check is skipped for the new query.

Fix. Reset both fields when the subscription is marked as subscribed again. This is the same reset that update_auto_closing_subscription already does for auto-closing subscriptions.

Notes to the reviewers

Checklist

  • I followed the contribution guidelines
  • I updated the relevant CHANGELOG.md (if applicable)
  • I understand and can explain all code in this PR

🤖 Generated with Claude Code

@codecov

codecov Bot commented Oct 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@erskingardner
erskingardner marked this pull request as ready for review October 14, 2026 12:28
With subscription verification enabled, a single filter with a `limit`
counts the stored events received before EOSE, and rejects (or bans the
relay for) any event beyond the limit.

Restoring a subscription after a reconnect sends its REQ again, so the
relay starts a new stored-events query. `update_subscription` kept the
previous EOSE flag and event count, though:

- if the connection dropped before EOSE, the count continued from the
  previous session, so a relay resending its stored events went over the
  limit and could be banned with `ban_relay_on_mismatch`;
- if EOSE had been received, the limit check was skipped for the new
  query.

Reset both when the subscription is marked as subscribed again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yukibtc
yukibtc force-pushed the sdk/reset-limit-state-on-resubscribe branch from a898ea7 to 7cd86a4 Compare October 15, 2026 09:27
@yukibtc
yukibtc merged commit 7cd86a4 into nostrdevkit:master Oct 15, 2026
42 checks passed
@erskingardner
erskingardner deleted the sdk/reset-limit-state-on-resubscribe branch October 15, 2026 13:57
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