Skip to content

feat(protocol): apply v2 first-contact PoW on NewOrder and take actions#91

Merged
arkanoider merged 1 commit into
mainfrom
feat/protocol-v2-pow-first-contact
Jun 20, 2026
Merged

feat(protocol): apply v2 first-contact PoW on NewOrder and take actions#91
arkanoider merged 1 commit into
mainfrom
feat/protocol-v2-pow-first-contact

Conversation

@arkanoider

@arkanoider arkanoider commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

Protocol v2 step 8: Mostro daemons can require higher PoW for first contact from unseen trade keys (NewOrder, TakeBuy, TakeSell). Mostrix now mirrors the daemon’s max(pow, pow_first_contact) rule on v2 outbound protocol DMs.

Part of the protocol v2 NIP-44 migration (follows #90).

Changes

  • Parse optional pow_first_contact from kind 38385 into MostroInstanceInfo
  • Add effective_pow_first_contact_from_instance, is_v2_first_contact_protocol_action, and nostr_pow_for_protocol_dm
  • send_dm uses per-action PoW via nostr_pow_for_protocol_dm instead of base nostr_pow_from_instance
  • Mostro Info tab shows “Required PoW (first contact, v2)” when the tag is present
  • Docs: POW_AND_OUTBOUND_EVENTS.md, MESSAGE_FLOW_AND_PROTOCOL.md
  • Unit tests for tag parsing and v1/v2 PoW selection

Summary by CodeRabbit

  • New Features

    • UI now displays first-contact Proof-of-Work (PoW) requirements separately when available on v2 protocol nodes
    • Direct message protocol now correctly applies the maximum required Proof-of-Work difficulty for first-contact protocol actions on v2 nodes
  • Documentation

    • Updated Proof-of-Work and outbound message flow documentation to reflect new first-contact requirements, v2 node behavior, and how difficulty levels are determined and applied

Use max(pow, pow_first_contact) for protocol DMs on v2 nodes when introducing
a new trade key, mirroring the daemon spam gate. Parse optional pow_first_contact
from kind 38385 and show it in the Mostro Info tab when advertised.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jun 20, 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: 283dbe77-e118-4a3c-899f-8a7ae436d321

📥 Commits

Reviewing files that changed from the base of the PR and between 3926277 and e0da08d.

📒 Files selected for processing (5)
  • docs/MESSAGE_FLOW_AND_PROTOCOL.md
  • docs/POW_AND_OUTBOUND_EVENTS.md
  • src/ui/tabs/mostro_info_tab.rs
  • src/util/dm_utils/mod.rs
  • src/util/mostro_info.rs

Walkthrough

Adds pow_first_contact: Option<u32> to MostroInstanceInfo, parses it from kind 38385 tags, and introduces effective_pow_first_contact_from_instance and is_v2_first_contact_protocol_action. nostr_pow_for_protocol_dm applies max(pow, pow_first_contact) for v2 direct transport on first-contact actions. send_dm now deserializes the payload before computing PoW. The UI and docs are updated accordingly.

Changes

pow_first_contact support for v2 first-contact actions

Layer / File(s) Summary
MostroInstanceInfo field, tag parsing, PoW utilities, and tests
src/util/mostro_info.rs
MostroInstanceInfo gains pow_first_contact: Option<u32>; mostro_info_from_tags parses the new tag; nostr_pow_from_instance is refactored with a clamping helper; effective_pow_first_contact_from_instance and is_v2_first_contact_protocol_action are introduced; nostr_pow_for_protocol_dm applies max(base, first_contact) for v2 Nip44Direct transport on NewOrder, TakeBuy, and TakeSell; tests cover all new and fallback paths.
send_dm PoW import and ordering update
src/util/dm_utils/mod.rs
Imports nostr_pow_for_protocol_dm instead of nostr_pow_from_instance; send_dm now deserializes payload into a Message first, then derives PoW using the parsed action via nostr_pow_for_protocol_dm.
UI display and documentation updates
src/ui/tabs/mostro_info_tab.rs, docs/MESSAGE_FLOW_AND_PROTOCOL.md, docs/POW_AND_OUTBOUND_EVENTS.md
build_info_lines conditionally renders a "Required PoW (first contact, v2)" row when pow_first_contact is present; both docs files updated to document the max(pow, pow_first_contact) rule and the pow_first_contact tag in kind 38385.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • MostroP2P/mostrix#51: Introduced nostr_pow_from_instance and the initial instance-derived PoW plumbing that this PR extends with pow_first_contact and nostr_pow_for_protocol_dm.
  • MostroP2P/mostrix#86: Also extends MostroInstanceInfo and kind 38385 tag parsing in src/util/mostro_info.rs, adding protocol_version and transport_from_instance.
  • MostroP2P/mostrix#88: Modifies the same send_dm function in src/util/dm_utils/mod.rs for protocol v2, refactoring transport wrapping and v2 default expiration.

Poem

🐇 Hop hop, the first contact toll now stands clear,
A pow_first_contact tag makes the rule appear.
For v2 direct sends, we take the max of two,
No more guessing—just max(pow, pow_first_contact) will do!
The daemon and Mostrix now speak the same tongue,
This rabbit is proud of the code that was flung. 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: implementing v2 first-contact PoW on NewOrder and take actions, which aligns with the PR's primary objective of enabling higher PoW requirements for first-contact messages.
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/protocol-v2-pow-first-contact

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.

@mostronatorcoder

Copy link
Copy Markdown
Contributor

I did a strict pass on this PR and I do not currently see a correctness blocker.

What I specifically checked:

  • pow_first_contact parsing from instance info
  • the fallback semantics in effective_pow_first_contact_from_instance()
  • the v1/v2/action gating in nostr_pow_for_protocol_dm()
  • the send_dm() integration point, to make sure the higher toll is derived from the actual inner action being wrapped

This looks coherent to me.

In particular, I like that the rule is not “always use pow_first_contact on v2”, but only for the first-contact protocol actions (NewOrder, TakeBuy, TakeSell), while other actions stay on base pow. That matches the daemon-side intent much better than a blanket increase would.

So from my side this looks like a good step 8: small surface area, correct scope, and a clean mirror of the daemon’s effective PoW rule for first-contact v2 traffic.

@ermeme ermeme 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.

Code Review Summary

Verdict: Approve

Looks good overall. The new first-contact PoW handling matches the v2 protocol flow, the parser and UI updates are consistent, and the new tests cover the added branches.

@arkanoider arkanoider merged commit cdc0cb1 into main Jun 20, 2026
13 checks passed
@arkanoider arkanoider deleted the feat/protocol-v2-pow-first-contact branch June 20, 2026 13:32
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.

1 participant