Skip to content

fix: update to alby go-nostr fork which reconnects after receiving CLOSED message#2331

Open
rolznz wants to merge 1 commit intomasterfrom
fix/go-nostr-reconnect-on-closed
Open

fix: update to alby go-nostr fork which reconnects after receiving CLOSED message#2331
rolznz wants to merge 1 commit intomasterfrom
fix/go-nostr-reconnect-on-closed

Conversation

@rolznz
Copy link
Copy Markdown
Member

@rolznz rolznz commented May 9, 2026

Tested running two local relays, switching between real relays and relays that always return CLOSED. Alby Hub reconnects as expected.

Summary by CodeRabbit

Release Notes

  • Chores
    • Updated Nostr library dependency to an alternative implementation.

Review Change Stack

@rolznz rolznz requested review from im-adithya and reneaaron May 9, 2026 07:48
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

📝 Walkthrough

Walkthrough

This PR replaces the external Nostr library dependency from github.com/nbd-wtf/go-nostr to github.com/getAlby/go-nostr across the entire codebase. The module manifest (go.mod) is updated, followed by corresponding import changes in 40+ source files, preserving all business logic and function signatures.

Changes

Nostr Dependency Migration

Layer / File(s) Summary
Dependency Manifest
go.mod
Direct dependency switched from github.com/nbd-wtf/go-nostr v0.52.3 to github.com/getAlby/go-nostr v0.0.0-20260509070347-31e205cac904.
Type Models & Contracts
nip47/controllers/models.go, nostr/models/models.go
Type definitions referencing nostr.Tags, nostr.Event, nostr.Filter now source from the new library; SimplePool interface structure unchanged.
Cipher & Cryptography
nip47/cipher/cipher.go, nip47/cipher/cipher_test.go
NIP04/NIP44 imports updated; NewNip47Cipher, Encrypt, and Decrypt methods continue to conditionally route to the appropriate algorithm via the new packages.
Core Event Handler
nip47/event_handler.go, nip47/event_handler_test.go
Event dispatcher and tests updated to use new nostr import; request decryption and response encryption flows preserved.
Core Services
nip47/nip47_service.go, service/keys/keys.go, service/start.go, apps/apps_service.go
Services updated to use new nostr library for key generation (GeneratePrivateKey, GetPublicKey) and utility functions (nip19).
NIP47 Controllers
nip47/controllers/... (20 files)
All command handlers (*_controller.go and *_controller_test.go) updated to reference nostr.Tags from new import; controller logic and response publishing unchanged.
Notifications & Publishing
nip47/notifications/nip47_notifier.go, nip47/publish_nip47_info.go
Notification sender and info publisher updated to use new nostr.Event, nostr.Filter, and nostr.Now from the new library.
App Consumers
service/create_app_consumer.go, service/delete_app_consumer.go, service/update_app_consumer.go
App lifecycle consumers updated to use new nostr import for key derivation; event processing logic unchanged.
Test Utilities
tests/create_app.go, tests/create_mock_relay.go
Test helpers updated; mockSimplePool method signatures now reference nostr.Event, nostr.PublishResult, and nostr.RelayEvent from the new import.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 From nbd-wtf to getAlby we hop,
One library swapped from bottom to top,
Type references dance in a synchronized way,
No logic was broken along the way!
Import by import, the migration's complete,
Cryptography signing still works so neat! 🔐

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: updating the Nostr library to the Alby fork which fixes reconnection behavior after receiving CLOSED messages.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/go-nostr-reconnect-on-closed

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
go.mod (1)

10-10: ⚡ Quick win

Migration to fork is complete; consider tagging releases for long-term maintainability.

Verification confirms no lingering references to github.com/nbd-wtf/go-nostr remain—the dependency swap is clean and go.sum has been properly regenerated.

The fork uses an untagged pseudo-version (v0.0.0-20260509070347-31e205cac904). For reproducibility and maintenance, consider:

  • Cutting tagged releases on the fork, or
  • Filing an upstream PR to nbd-wtf/go-nostr with the CLOSED-reconnect fix and retiring the fork later.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@go.mod` at line 10, The go.mod now points to the forked module
github.com/getAlby/go-nostr using an untagged pseudo-version; to ensure
reproducible builds and long-term maintainability, either create semantic
version tags on the fork (e.g., v0.1.0) and update go.mod to use that tag, or
prepare a PR against the original module (nbd-wtf/go-nostr) that includes the
CLOSED-reconnect fix so you can later switch back and remove the fork—update the
dependency entry for github.com/getAlby/go-nostr accordingly once a tagged
release or upstream merge is available.
service/start.go (1)

250-256: ⚡ Quick win

Update the inline comment to reflect the fork's automatic reconnection behavior.

The comment at lines 251–252 describes the original go-nostr behavior ("currently if the relay sends a close that is not 'auth-required:' this will trigger closing the subscription channel"). However, this PR updates to the Alby fork, which—as noted in commit 9d625f8—"reconnects after receiving CLOSED message."

Update the comment to clarify the current fork behavior and whether:

  • The subscription channel still closes for non-auth CLOSED messages (in which case the outer loop's resubscribe still applies and the comment should reference the fork's behavior), or
  • The fork now handles reconnection internally, and eventsChannelClosed only fires on context exit or true disconnects (in which case the surrounding error/resubscribe logic may need review to avoid redundant reconnection attempts).

Refreshing this comment will prevent future readers from being confused by references to the original upstream behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@service/start.go` around lines 250 - 256, Update the inline comment above the
eventsChannelClosed case to reflect the Alby fork's behavior: state that the
Alby fork (per commit 9d625f8) reconnects after receiving a CLOSED message, then
clearly explain whether eventsChannelClosed still fires for non-auth CLOSED
messages or only on context cancellation/true disconnects; reference the symbols
eventsChannelClosed, logger.Logger.Info("Subscription was exited abnormally"),
and the subsequent return errors.New("subscription exited abnormally") and,
based on the correct behavior, note whether the outer loop's resubscribe logic
is still required or redundant.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@nip47/notifications/nip47_notifier.go`:
- Line 8: The import and go.mod reference uses a non-public fork
"github.com/getAlby/go-nostr" which cannot be resolved; update the dependency
resolution by either switching imports and go.mod to the upstream
"github.com/nbd-wtf/go-nostr", adding a go.mod replace directive pointing to a
reachable module (or pushing the fork publicly), and ensure all references in
nip47_notifier.go import the corrected module path (the current import string
"github.com/getAlby/go-nostr") so the build can resolve the package; if the fork
is private, add a note in docs about access or change to the upstream module
accordingly.

---

Nitpick comments:
In `@go.mod`:
- Line 10: The go.mod now points to the forked module
github.com/getAlby/go-nostr using an untagged pseudo-version; to ensure
reproducible builds and long-term maintainability, either create semantic
version tags on the fork (e.g., v0.1.0) and update go.mod to use that tag, or
prepare a PR against the original module (nbd-wtf/go-nostr) that includes the
CLOSED-reconnect fix so you can later switch back and remove the fork—update the
dependency entry for github.com/getAlby/go-nostr accordingly once a tagged
release or upstream merge is available.

In `@service/start.go`:
- Around line 250-256: Update the inline comment above the eventsChannelClosed
case to reflect the Alby fork's behavior: state that the Alby fork (per commit
9d625f8) reconnects after receiving a CLOSED message, then clearly explain
whether eventsChannelClosed still fires for non-auth CLOSED messages or only on
context cancellation/true disconnects; reference the symbols
eventsChannelClosed, logger.Logger.Info("Subscription was exited abnormally"),
and the subsequent return errors.New("subscription exited abnormally") and,
based on the correct behavior, note whether the outer loop's resubscribe logic
is still required or redundant.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 17fe5d99-a970-447a-ac27-a723a87ada37

📥 Commits

Reviewing files that changed from the base of the PR and between 9f8da1a and 9d625f8.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (49)
  • apps/apps_service.go
  • go.mod
  • nip47/cipher/cipher.go
  • nip47/cipher/cipher_test.go
  • nip47/controllers/cancel_hold_invoice_controller.go
  • nip47/controllers/cancel_hold_invoice_controller_test.go
  • nip47/controllers/create_connection_controller.go
  • nip47/controllers/create_connection_controller_test.go
  • nip47/controllers/get_balance_controller.go
  • nip47/controllers/get_balance_controller_test.go
  • nip47/controllers/get_budget_controller.go
  • nip47/controllers/get_budget_controller_test.go
  • nip47/controllers/get_info_controller.go
  • nip47/controllers/get_info_controller_test.go
  • nip47/controllers/list_transactions_controller.go
  • nip47/controllers/list_transactions_controller_test.go
  • nip47/controllers/lookup_invoice_controller.go
  • nip47/controllers/lookup_invoice_controller_test.go
  • nip47/controllers/make_hold_invoice_controller.go
  • nip47/controllers/make_hold_invoice_controller_test.go
  • nip47/controllers/make_invoice_controller.go
  • nip47/controllers/make_invoice_controller_test.go
  • nip47/controllers/models.go
  • nip47/controllers/multi_pay_invoice_controller.go
  • nip47/controllers/multi_pay_invoice_controller_test.go
  • nip47/controllers/multi_pay_keysend_controller.go
  • nip47/controllers/multi_pay_keysend_controller_test.go
  • nip47/controllers/pay_invoice_controller.go
  • nip47/controllers/pay_invoice_controller_test.go
  • nip47/controllers/pay_keysend_controller.go
  • nip47/controllers/pay_keysend_controller_test.go
  • nip47/controllers/settle_hold_invoice_controller.go
  • nip47/controllers/settle_hold_invoice_controller_test.go
  • nip47/controllers/sign_message_controller.go
  • nip47/event_handler.go
  • nip47/event_handler_test.go
  • nip47/nip47_service.go
  • nip47/notifications/nip47_notifier.go
  • nip47/notifications/nip47_notifier_test.go
  • nip47/publish_nip47_info.go
  • nostr/models/models.go
  • service/create_app_consumer.go
  • service/delete_app_consumer.go
  • service/keys/keys.go
  • service/keys/keys_test.go
  • service/start.go
  • service/update_app_consumer.go
  • tests/create_app.go
  • tests/create_mock_relay.go

"encoding/json"
"errors"

"github.com/getAlby/go-nostr"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the Alby go-nostr fork exists and check the specified commit

# Check if the repository exists and the commit is valid
echo "Checking fork repository and commit..."
git ls-remote https://github.com/getAlby/go-nostr.git 31e205cac904* || echo "Commit not found"

# Check for available tags/releases
echo -e "\nChecking for tagged releases..."
git ls-remote --tags https://github.com/getAlby/go-nostr.git | tail -10

Repository: getAlby/hub

Length of output: 127


🏁 Script executed:

# First, find the file mentioned in the review
find . -name "nip47_notifier.go" -type f

# Check if go.mod exists and search for the nostr dependency
find . -name "go.mod" -type f | head -5

# List the repository structure
git ls-files | grep -E "(go.mod|go.sum)" | head -10

Repository: getAlby/hub

Length of output: 118


🏁 Script executed:

# Check line 8 of the nip47_notifier.go file
head -15 ./nip47/notifications/nip47_notifier.go

# Check go.mod for nostr dependency
cat ./go.mod | grep -A2 -B2 "nostr"

# Check go.sum for nostr entries
grep "nostr" ./go.sum

Repository: getAlby/hub

Length of output: 880


🏁 Script executed:

# Read the actual implementation to check for guideline compliance
cat -n ./nip47/notifications/nip47_notifier.go | head -100

# Check for error handling patterns
grep -n "fmt.Errorf\|errors\|return err" ./nip47/notifications/nip47_notifier.go | head -20

# Check for logging patterns
grep -n "logger\|logrus\|fmt.Print" ./nip47/notifications/nip47_notifier.go | head -20

Repository: getAlby/hub

Length of output: 5267


🌐 Web query:

getAlby go-nostr fork GitHub repository commit 31e205cac904

💡 Result:

I couldn’t find any public GitHub page for the commit hash 31e205cac904 in the getAlby “go-nostr”/Nostr Wallet Connect repositories. What I did find: - getAlby has a Go-based Nostr Wallet Connect server repo at https://github.com/getAlby/nostr-wallet-connect [1]. - There is also a forked/related repo at https://github.com/getAlby/nwc.getalby.com (it’s a fork of getAlby/nostr-wallet-connect) [2]. However, none of the searched results surfaced a GitHub commit URL or page matching 31e205cac904 for those repositories (or for a getAlby “go-nostr fork” specifically). So I can’t reliably identify which repository/commit you mean, or provide the commit details. If you share either (a) the exact repository name you mean (e.g., getAlby/nostr-wallet-connect vs getAlby/nwc.getalby.com), or (b) the full commit URL you expect, I can re-run the lookup against that exact path and extract the commit content.

Citations:


🌐 Web query:

getAlby/go-nostr repository GitHub

💡 Result:

There is no GitHub repository at getAlby/go-nostr. What I found instead: 1) The Alby repo getAlby/nostr-wallet-connect (NIP-47 “Nostr Wallet Connect” app) is at https://github.com/getAlby/nostr-wallet-connect and is the main getAlby/Nostr-related project with Go code [1][2]. 2) Another related getAlby repo is getAlby/http-nostr (HTTP endpoints bridging the Nostr protocol with NIP-47) at https://github.com/getAlby/http-nostr [3]. If you meant the Go Nostr library commonly used by these projects, that is github.com/nbd-wtf/go-nostr (separate repository/org) at https://github.com/nbd-wtf/go-nostr [4].

Citations:


🏁 Script executed:

# Check if go.mod has any replace directives
cat ./go.mod | grep -A5 "replace"

# Check entire go.mod for context
wc -l ./go.mod
head -50 ./go.mod
tail -20 ./go.mod

Repository: getAlby/hub

Length of output: 3205


Critical: The fork repository github.com/getAlby/go-nostr does not exist publicly.

The dependency in go.mod points to github.com/getAlby/go-nostr v0.0.0-20260509070347-31e205cac904, but this repository does not exist on GitHub. The original library is github.com/nbd-wtf/go-nostr (different organization).

This breaks the build—the dependency cannot be resolved. Either:

  1. This is a private repository (clarify access requirements in documentation)
  2. The import path in go.mod is incorrect and should reference the original library
  3. The fork needs to be pushed to a public repository, or a replace directive added to go.mod

Clarify the dependency resolution before merging.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@nip47/notifications/nip47_notifier.go` at line 8, The import and go.mod
reference uses a non-public fork "github.com/getAlby/go-nostr" which cannot be
resolved; update the dependency resolution by either switching imports and
go.mod to the upstream "github.com/nbd-wtf/go-nostr", adding a go.mod replace
directive pointing to a reachable module (or pushing the fork publicly), and
ensure all references in nip47_notifier.go import the corrected module path (the
current import string "github.com/getAlby/go-nostr") so the build can resolve
the package; if the fork is private, add a note in docs about access or change
to the upstream module accordingly.

Copy link
Copy Markdown
Member

@im-adithya im-adithya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK

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