Skip to content

feat(transport): Phase 1 — wire protocol v2 (NIP-44 direct) into mostrod#776

Merged
grunch merged 2 commits into
mainfrom
feat/transport-v2-phase1
Jun 16, 2026
Merged

feat(transport): Phase 1 — wire protocol v2 (NIP-44 direct) into mostrod#776
grunch merged 2 commits into
mainfrom
feat/transport-v2-phase1

Conversation

@grunch

@grunch grunch commented Jun 12, 2026

Copy link
Copy Markdown
Member

Summary

Phase 1 of the Messaging Transport Abstraction Layer (#626full proposal), on top of mostro-core 0.13.0 (Phase 0, MostroP2P/mostro-core#152).

The daemon now speaks the operator-configured wire transport — protocol v1 gift wraps (kind 1059, DEPRECATED) or protocol v2 signed kind-14 events with NIP-44 encrypted content. A node speaks exactly one; there is no dual mode. The headline design property holds: zero handler changes — both transports unwrap into the same UnwrappedMessage via mostro-core's kind dispatch, so the 28 action handlers are untouched.

Changes

  • mostro-core 0.12.1 → 0.13.0 — brings the transport module (Transport, wrap_message_with, unwrap_incoming) and PROTOCOL_VER = 2.
  • [mostro] transport setting ("gift-wrap" | "nip44", serde default gift-wrap): existing settings.toml files keep working unchanged, and the default wire behavior is byte-identical to pre-v2 daemons.
  • [expiration] dm_days knob (default 30): kind-14 events are visible to relays, so they always carry a NIP-40 expiration tag — send_dm() fills it on the nip44 transport when the caller didn't pass one. New DM_EVENT_KIND = 14 constant; fallback path in get_expiration_timestamp_for_kind kept in sync.
  • main.rs — subscription filter uses transport.event_kind() (1059 or 14).
  • app.rs — the event loop accepts only the configured kind and unwraps via unwrap_incoming(); everything downstream (PoW, freshness window, trade-index checks, signature-presence bail-out) applies unchanged to both transports.
  • nip33.rs — the kind-38385 info event now advertises protocol_versions ("1" or "2"), so clients discover which wire format a node accepts before sending anything.
  • docs/TRANSPORT_V2_SPEC.md — the spec for the whole effort: context and threat model, the v2 wire format (visible envelope, 3-element tuple, the trade-key-bound identity proof and why the domain tag exists), versioning, operator configuration, release timeline (v1 DEPRECATED in 0.18.0, removed in 0.19.0), and the detailed phase guide to drive the remaining work (Phase 2 anti-spam gates, Phase 3 protocol docs + client migration, Phase 4 cutover).

Tests

New: dm_days default/override for kind 14, and transport defaulting to gift-wrap. Full suite: 428 passed, clippy --all-targets --all-features -D warnings clean.

Notes for reviewers

  • transport = "nip44" is fully functional end-to-end (subscribe → unwrap → reply → expiration tag), but flipping it only makes sense once the community's clients implement protocol v2 (Phase 3) — clients discover support via the protocol_versions tag.
  • Phase 2 (cheap pre-validation of kind-14 senders against active trade keys, before any decryption) is daemon-only follow-up work and is specified in the SPEC.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added optional NIP-44 direct messaging transport and transport selection (gift-wrap or nip44)
    • Relay subscriptions and message handling now follow the configured transport kind
    • Automatic DM expiration handling with a default 30-day retention and configurable dm_days
    • Node advertises supported protocol versions in instance info
  • Documentation

    • Added Transport v2 specification (NIP-44 direct messaging)
  • Chores

    • Updated mostro-core dependency to 0.13.0

Phase 1 of the Messaging Transport Abstraction Layer (#626), on top of
mostro-core 0.13.0 (Phase 0, MostroP2P/mostro-core#152). The node now
speaks the operator-configured transport — protocol v1 gift wraps
(kind 1059, DEPRECATED) or protocol v2 signed kind-14 events with
NIP-44 encrypted content — with zero handler changes: both transports
unwrap into the same UnwrappedMessage via mostro-core's kind dispatch.

- Bump mostro-core 0.12.1 -> 0.13.0 (protocol v2 transport module,
  PROTOCOL_VER = 2).
- New `[mostro] transport` setting ("gift-wrap" | "nip44", serde
  default gift-wrap so existing settings.toml files keep working and
  the wire behavior is identical to pre-v2 daemons).
- New `[expiration] dm_days` knob (default 30): kind-14 events always
  carry a NIP-40 expiration tag; send_dm() fills it on the nip44
  transport when the caller didn't pass one.
- main.rs subscribes to the configured transport's kind only; app.rs
  accepts only that kind and unwraps via unwrap_incoming().
- Kind-38385 info event advertises `protocol_versions` ("1" or "2")
  so clients pick the right wire format before sending.
- docs/TRANSPORT_V2_SPEC.md: full context, v2 wire format (including
  the trade-key-bound identity proof), versioning, operator config,
  release timeline (v1 DEPRECATED in 0.18.0, removed in 0.19.0) and
  the phase guide (Phase 2 anti-spam gates, Phase 3 protocol docs,
  Phase 4 cutover).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5b0f00fa-2ef2-4db2-a251-4804618b1a81

📥 Commits

Reviewing files that changed from the base of the PR and between bb361db and a44fe34.

📒 Files selected for processing (3)
  • docs/TRANSPORT_V2_SPEC.md
  • src/config/settings.rs
  • src/util.rs
✅ Files skipped from review due to trivial changes (1)
  • docs/TRANSPORT_V2_SPEC.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/util.rs

Walkthrough

This PR makes transport selectable (gift-wrap vs nip44) via settings, filters and unwraps incoming events by the configured transport event kind, derives DM expirations for NIP‑44, updates send_dm to use wrap_message_with, advertises protocol_versions, and adds a Transport v2 spec plus a mostro-core bump.

Changes

Transport v2 Implementation

Layer / File(s) Summary
Configuration schema and constants for transport selection
src/config/constants.rs, src/config/types.rs, settings.tpl.toml
Add DM_EVENT_KIND (14); extend ExpirationSettings with optional dm_days (default 30 fallback); add transport: Transport to MostroSettings with serde defaults and template settings entries.
Event unwrapping and DM wrapping with transport configuration
src/app.rs, src/util.rs
Replace GiftWrap-specific unwrap_message with transport-agnostic unwrap_incoming; drop events whose kind != configured transport.event_kind() before decryption. Update send_dm to compute DM expiration for NIP‑44 and call wrap_message_with(..., WrapOptions{ signed:false, expiration }).
Relay subscription and protocol capability advertisement
src/main.rs, src/nip33.rs
Subscribe to configured transport.event_kind() instead of hardcoded GiftWrap; add protocol_versions tag to info events using transport.protocol_version().
Settings accessor for transport
src/config/settings.rs
Add Settings::get_transport() that returns configured mostro.transport or Transport::default() when uninitialized.
Transport v2 specification and mostro-core dependency update
Cargo.toml, docs/TRANSPORT_V2_SPEC.md
Bump mostro-core to 0.13.0 and add TRANSPORT_V2_SPEC.md documenting the NIP‑44 direct-message wire format, identity proof placement, versioning by kind, operator constraints, rollout plan, phases, and security notes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • arkanoider
  • Catrya
  • AndreaDiazCorreia

Poem

🐰 I hop through code with nimble paws,
Gift-wrap folds and nip44s,
Config set, events unrolled,
DM expiries and specs told,
Mostro hops toward transport laws.

🚥 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 accurately describes the main change: implementing protocol v2 (NIP-44 direct messaging) into mostrod as Phase 1 of a transport abstraction layer, which matches the comprehensive changeset across dependency updates, configuration, documentation, and code modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 feat/transport-v2-phase1

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb361db7c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/util.rs Outdated
Comment thread docs/TRANSPORT_V2_SPEC.md Outdated

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 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 `@docs/TRANSPORT_V2_SPEC.md`:
- Around line 95-97: Update the fenced code block showing the transport format
to include a language tag; edit the fence surrounding
"mostro-transport-v2-identity:<trade_pubkey_hex>:<message_json>" in
TRANSPORT_V2_SPEC.md and change the opening ``` to ```text so the block is
marked as plain text (satisfying MD040).
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d796198a-17bb-490c-9f36-a837ec657363

📥 Commits

Reviewing files that changed from the base of the PR and between c610c34 and bb361db.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (9)
  • Cargo.toml
  • docs/TRANSPORT_V2_SPEC.md
  • settings.tpl.toml
  • src/app.rs
  • src/config/constants.rs
  • src/config/types.rs
  • src/main.rs
  • src/nip33.rs
  • src/util.rs

Comment thread docs/TRANSPORT_V2_SPEC.md Outdated
Codex P2: send_dm() called Settings::get_mostro(), which panics when
the global MOSTRO_CONFIG isn't initialized — turning the previously
fallible call into an abort in unit tests that don't bring up the full
configuration (test_send_dm only survived by test-ordering luck).
Add Settings::get_transport(), which falls back to the gift-wrap
default when settings are absent, mirroring the existing get_bond /
get_price non-panicking accessors. The nip44 expiration path is
unreachable without initialized settings (the fallback is gift-wrap),
so no other panic path is introduced.

Note: test_send_dm's assertion was already order-dependent on main
(it expects Err, which only happens when another test has installed
NOSTR_CLIENT) — unchanged by this PR.

Also tag the identity-proof payload fence in the SPEC as `text`
(markdownlint MD040, flagged by Codex and CodeRabbit).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@AndreaDiazCorreia AndreaDiazCorreia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK

@arkanoider arkanoider left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ACK

@grunch
grunch merged commit ba86102 into main Jun 16, 2026
8 checks passed
@grunch
grunch deleted the feat/transport-v2-phase1 branch June 16, 2026 17:17
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.

3 participants