Skip to content

docs: finish protocol v2 migration of the spec (action pages, anti-spam gates)#50

Open
grunch wants to merge 1 commit into
mainfrom
claude/protocol-v2-doc-gaps-i7uo7h
Open

docs: finish protocol v2 migration of the spec (action pages, anti-spam gates)#50
grunch wants to merge 1 commit into
mainfrom
claude/protocol-v2-doc-gaps-i7uo7h

Conversation

@grunch

@grunch grunch commented Jul 5, 2026

Copy link
Copy Markdown
Member

Completes the documentation gaps left after the Phase 3 transport docs (TRANSPORT_V2_SPEC.md §6 in mostrod tracks this as the pending protocol-repo work). The gaps were identified by auditing the v2 implementation in mostro (PRs #776, #780, #781, #782, #785, #800) and mostro-core (PRs #152, #158) against the current spec.

Action pages migrated to the v2 wire format (~25 pages)

Every action/flow page still described only the deprecated v1 transport. Now:

  • All JSON examples show version: 2 and the 3-element content tuple: identity-proof placeholder ["<identity pubkey>", "<identity signature>"] in reputation-mode requests, null, null in Mostro replies and full-privacy mode.
  • Gift-wrap/rumor wording replaced with transport-agnostic phrasing linking to Overview → Transports.
  • The five kind-1059 envelope examples (new_sell_order, new_buy_order, new_buy_order_ln_address, take_buy, take_sell_ln_address) replaced with the signed kind-14 NIP-44 envelope (p + NIP-40 expiration tags), keeping a pointer to the v1 envelope in Keys management.

Anti-spam gates documented (transport_migration.md)

The Phase 2 gates shipped in mostrod v0.18.0 (#780) had no spec coverage. New section documents, in evaluation order: base PoW (the advertised pow tag), the 60-second replay guard, first-contact PoW (pow_first_contact with fallback to base pow) with the active trade-key set fast path (non-terminal orders — disputes included — plus active-dispute solvers, refreshed every ~60 s), and the 10-second freshness window. Also states that all gate rejections are silent (no cant-do reply), and flags the discovery caveat: the info event does not advertise the first-contact difficulty.

Other fixes

  • version field semantics: the event kind is authoritative for unwrap; the inner version value is informative on the wire (matches #785 behavior).
  • overview.md: main new-order example bumped to version: 2.
  • other_events.md: info-event sample now shows ["protocol_version", "2"]; pow description notes it is the base difficulty on v2.
  • transport_migration.md: mostro-core reference updated (0.14.1 marks the gift-wrap variant deprecated at the library level).
  • chat.md / dispute_chat.md: scope notes clarifying the P2P/dispute chat keeps its simplified NIP-59 (kind 1059) scheme and is not affected by the v0.19.0 removal of the v1 daemon transport.

Intentionally untouched: the v1-labeled examples in overview.md and key_management.md (they document the deprecated transport side by side with v2).

🤖 Generated with Claude Code

https://claude.ai/code/session_018kz9Xo4SSaXz5Hxs57gfYJ


Generated by Claude Code

Summary by CodeRabbit

  • Documentation
    • Updated protocol examples across many trade, invoice, dispute, cancel, settle, restore, and rating flows to reflect the newer message format.
    • Clarified that most user-facing exchanges now use the active transport and protocol version 2, with revised example payload shapes.
    • Added guidance for message handling during the v1 to v2 migration, including transport scope and anti-spam checks.
    • Refreshed chat and status notes to explain which message types are affected by the migration.

…am gates)

Complete the documentation gaps left after the Phase 3 transport docs:

- Migrate all action pages to the v2 wire format: JSON examples now show
  version: 2 and the 3-element content tuple (identity proof placeholder
  in reputation-mode requests, null/null in Mostro replies and
  full-privacy mode), with transport-agnostic wording linking to
  Overview -> Transports instead of gift-wrap/rumor terminology.
- Replace the five kind-1059 envelope examples with the signed kind-14
  NIP-44 envelope (p + NIP-40 expiration tags), keeping a pointer to the
  v1 envelope in Keys management.
- Document the v2 anti-spam gates in the migration guide: base PoW,
  60-second replay guard, first-contact PoW with the active trade-key
  set fast path, the 10-second freshness window, silent drops (no
  cant-do replies), and the pow_first_contact discovery caveat.
- Clarify that the event kind is authoritative over the inner version
  field, and note the mostro-core 0.14.1 gift-wrap deprecation.
- Fix leftovers in already-migrated pages: overview.md new-order example
  version, other_events.md info-event sample protocol_version tag and
  base-pow description.
- Add scope notes to chat.md and dispute_chat.md: the P2P/dispute chat
  keeps its simplified NIP-59 scheme and is not affected by the v0.19.0
  removal of the v1 transport.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018kz9Xo4SSaXz5Hxs57gfYJ
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR updates the Mostro protocol documentation to reflect version 2 of the wire format across nearly all message-flow documents: order/restore version fields are bumped from 1 to 2, gift-wrap/rumor wording is replaced with active-transport/decrypted-content phrasing, JSON array examples are adjusted with null placeholders and identity signature elements, and transport_migration.md gains a new anti-spam gates section.

Changes

Protocol v2 documentation examples

Layer / File(s) Summary
Bond invoice and admin action examples
src/add_bond_invoice.md, src/pay_bond_invoice.md, src/admin_add_solver.md, src/admin_cancel_order.md, src/admin_settle_order.md, src/bond_slashed.md
Version fields bumped to 2, payment_request reply restructured with identity pubkey/signature, and bond_resolution payloads replaced with null in examples.
Order creation and listing flows
src/new_buy_order.md, src/new_buy_order_ln_address.md, src/new_sell_order.md, src/new_sell_range_order.md, src/orders.md, src/overview.md
Order creation/listing examples switch to active-transport wording, version 2, and kind-14 NIP-44 event samples replacing gift-wrap kind-1059 events.
Take-order (buy/sell) flow examples
src/take_buy.md, src/take_buy_range_order.md, src/take_sell.md, src/take_sell_ln_address.md, src/take_sell_range_order.md
Take-order examples updated to version 2, decrypted-content wording, and kind-14 NIP-44 event structures, with several payload examples replaced by null.
Cancel, dispute and chat scope notes
src/cancel.md, src/dispute.md, src/dispute_chat.md, src/chat.md
Cancel/dispute examples bumped to version 2 with adjusted array/null structures; scope notes added clarifying kind-1059 chat/dispute-chat flows are unaffected by the v1 transport removal.
Fiat-sent, hold-invoice, release, payment-failed and rating flows
src/fiatsent.md, src/seller_pay_hold_invoice.md, src/release.md, src/payment_failed.md, src/user_rating.md
Version fields bumped to 2 and message envelopes extended with identity signature/null elements across settlement-related flows.
Session restore, last-trade-index and transport migration guide
src/last_trade_index.md, src/restore_session.md, src/transport_migration.md, src/other_events.md
Restore/session examples bumped to version 2; transport_migration.md gains mostro-core version guidance and a new anti-spam gates section; other_events.md protocol_version and pow description updated.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • MostroP2P/protocol#46: Directly updates the same anti-abuse bond documentation pages (bond_slashed.md, add_bond_invoice.md, pay_bond_invoice.md) referenced in this PR's version bump.
  • MostroP2P/protocol#48: Builds on the same transport_migration.md, overview.md, and other_events.md protocol-v2 transport documentation extended here.
  • MostroP2P/protocol#21: Introduces the restore/last-trade-index message documented in last_trade_index.md, which this PR updates from version 1 to 2.

Poem

A rabbit hops through docs at dawn,
Bumping every "one" to "two" 🐇
Nulls slip neatly into place,
Gift-wraps fade, transport shines through.
Hop by hop, the specs align—
Version two, the burrow's fine! ✨

🚥 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 summarizes the main change: completing the protocol v2 docs migration and adding anti-spam gate documentation.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/protocol-v2-doc-gaps-i7uo7h

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.

@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: 6cc96eac75

ℹ️ 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 on lines +30 to +31
"<index N signature of the sha256 hash of the serialized first element of content>",
["<identity pubkey>", "<identity signature>"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Set Mostro reply tuple slots to null

This example is explicitly a Mostro → seller message, but the v2 tuple now shows a trade-key signature and identity proof. The v2 overview/key-management rules say Mostro-authored replies are unsigned and both tuple slots must be null; clients following this will expect identity material that Mostro never sends and can fail to handle the pay-invoice step.

Useful? React with 👍 / 👎.

Comment on lines +59 to +60
"<index N signature of the sha256 hash of the serialized first element of content>",
["<identity pubkey>", "<identity signature>"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Null the proof fields in this Mostro response

This is a Mostro-authored waiting-seller-to-pay response, so the added v2 identity proof is not valid: Mostro replies use null, null for the trade signature and identity-proof tuple elements. Leaving the proof placeholders here documents an impossible response shape for clients that implement the v2 decoder/verification rules.

Useful? React with 👍 / 👎.

Comment on lines +18 to 19
null,
null

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include the reputation proof for this range take

The message includes trade_index: 1, which marks the request as reputation mode, but the v2 tuple is documented here with both proof elements as null (the full-privacy shape). A seller following this range-order example would omit the trade-key signature and identity proof, so the take is not linked to reputation and may be treated differently from the adjacent non-range take-buy example.

Useful? React with 👍 / 👎.

@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: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/last_trade_index.md (1)

40-40: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Update the restore.version description.

This still says the current version is 1, which conflicts with the updated v2 examples above. It should read 2.

🤖 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 `@src/last_trade_index.md` at line 40, The documentation for restore.version is
outdated and still states the current protocol version as 1. Update the
restore.version description in last_trade_index.md to reflect the new version 2,
matching the updated v2 examples above and keeping the wording consistent with
the surrounding restore field descriptions.
🤖 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 `@src/cancel.md`:
- Line 22: The prose in cancel documentation is inconsistent with the emitted
action name; update the wording in the cancel message example so it matches the
actual action used by Mostro. Align the text in src/cancel.md with the action
emitted by the cancellation flow, using the same naming as the relevant
cancel/canceled example to avoid ambiguity for implementers.

In `@src/other_events.md`:
- Line 122: The instance-status example is internally inconsistent because the
sample daemon version in the example predates protocol v2 while the protocol tag
is set to "2". Update the example in the relevant instance-status section of the
documentation so the version fields match, either by changing the daemon version
to a v2-era value or by setting protocol_version back to "1" and keeping the
example consistent.

In `@src/take_sell_range_order.md`:
- Line 25: Update the range-order explanation in the take_sell_range_order.md
content so it no longer says the order amount is `0`; instead, describe that
Mostro uses the selected fiat amount from the range order to calculate the
required sats. Keep the rest of the flow intact, but make the wording in this
section consistent with the range-order example and its invoice payload rather
than the zero-amount sell flow.

In `@src/take_sell.md`:
- Line 114: The second “Mostro response” heading in the take_sell markdown
duplicates the earlier anchor, so rename this heading to a distinct title in the
same section to avoid repeated rendered anchors. Update the Markdown heading
near the repeated “Mostro response” text so it remains clear and unique without
changing the surrounding content structure.

---

Outside diff comments:
In `@src/last_trade_index.md`:
- Line 40: The documentation for restore.version is outdated and still states
the current protocol version as 1. Update the restore.version description in
last_trade_index.md to reflect the new version 2, matching the updated v2
examples above and keeping the wording consistent with the surrounding restore
field descriptions.
🪄 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: 1433d3bc-ea82-4d1d-a05f-f2c5aecf325c

📥 Commits

Reviewing files that changed from the base of the PR and between 779d1c4 and 6cc96ea.

📒 Files selected for processing (30)
  • src/add_bond_invoice.md
  • src/admin_add_solver.md
  • src/admin_cancel_order.md
  • src/admin_settle_order.md
  • src/bond_slashed.md
  • src/cancel.md
  • src/chat.md
  • src/dispute.md
  • src/dispute_chat.md
  • src/fiatsent.md
  • src/last_trade_index.md
  • src/new_buy_order.md
  • src/new_buy_order_ln_address.md
  • src/new_sell_order.md
  • src/new_sell_range_order.md
  • src/orders.md
  • src/other_events.md
  • src/overview.md
  • src/pay_bond_invoice.md
  • src/payment_failed.md
  • src/release.md
  • src/restore_session.md
  • src/seller_pay_hold_invoice.md
  • src/take_buy.md
  • src/take_buy_range_order.md
  • src/take_sell.md
  • src/take_sell_ln_address.md
  • src/take_sell_range_order.md
  • src/transport_migration.md
  • src/user_rating.md

Comment thread src/cancel.md
## Mostro response

Mostro will send a message with action `cancel` confirming the order was canceled, here an example of rumor's content of the message:
Mostro will send a message with action `cancel` confirming the order was canceled, here an example of decrypted content of the message:

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Match the prose to the emitted action.

The text says cancel, but the example emits canceled. Keep those aligned so implementers don't key off the wrong action name.

Suggested fix
- Mostro will send a message with action `cancel` confirming the order was canceled, here an example of decrypted content of the message:
+ Mostro will send a message with action `canceled` confirming the order was canceled, here an example of decrypted content of the message:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Mostro will send a message with action `cancel` confirming the order was canceled, here an example of decrypted content of the message:
Mostro will send a message with action `canceled` confirming the order was canceled, here an example of decrypted content of the message:
🤖 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 `@src/cancel.md` at line 22, The prose in cancel documentation is inconsistent
with the emitted action name; update the wording in the cancel message example
so it matches the actual action used by Mostro. Align the text in src/cancel.md
with the action emitted by the cancellation flow, using the same naming as the
relevant cancel/canceled example to avoid ambiguity for implementers.

Comment thread src/other_events.md
[
"protocol_version",
"1"
"2"

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map the relevant markdown file structure first
wc -l src/other_events.md
ast-grep outline src/other_events.md || true

# Show the nearby lines around the cited snippet
sed -n '90,150p' src/other_events.md

# Find other protocol/version mentions in the repo for context
rg -n '"protocol_version"|mostro_version|v2|transport timeline|instance-status' src src/other_events.md . -g '!**/node_modules/**' -g '!**/dist/**' -g '!**/build/**' || true

Repository: MostroP2P/protocol

Length of output: 13458


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Read the instance-status example around the cited lines
sed -n '60,135p' src/other_events.md

# Read the instance-status field descriptions
sed -n '200,235p' src/other_events.md

# Read the migration timeline and the v1/v2 mapping
sed -n '1,130p' src/transport_migration.md

Repository: MostroP2P/protocol

Length of output: 10645


Keep the instance-status example internally consistent. mostro_version: "0.12.8" predates protocol v2, so pairing it with protocol_version: "2" is misleading. Either update the sample to a v2-era daemon version or set the protocol tag back to "1".

🤖 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 `@src/other_events.md` at line 122, The instance-status example is internally
inconsistent because the sample daemon version in the example predates protocol
v2 while the protocol tag is set to "2". Update the example in the relevant
instance-status section of the documentation so the version fields match, either
by changing the daemon version to a v2-era value or by setting protocol_version
back to "1" and keeping the example consistent.

## Mostro response

In order to continue the buyer needs to send a lightning network invoice to Mostro, in this case the amount of the order is `0`, so Mostro will need to calculate the amount of sats for this order, then Mostro will send back a message asking for a LN invoice indicating the correct amount of sats that the invoice should have, here the rumor's content of the message:
In order to continue the buyer needs to send a lightning network invoice to Mostro, in this case the amount of the order is `0`, so Mostro will need to calculate the amount of sats for this order, then Mostro will send back a message asking for a LN invoice indicating the correct amount of sats that the invoice should have, here the decrypted content of the message:

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Correct the range-order response description.

This paragraph still says the order amount is 0, but this flow already carries the selected fiat amount and the example payload computes sats from that value. That reads like the zero-amount sell flow was copied here unchanged.

Suggested fix
- In order to continue the buyer needs to send a lightning network invoice to Mostro, in this case the amount of the order is `0`, so Mostro will need to calculate the amount of sats for this order, then Mostro will send back a message asking for a LN invoice indicating the correct amount of sats that the invoice should have, here the decrypted content of the message:
+ In order to continue the buyer needs to send a lightning network invoice to Mostro for the selected fiat amount, so Mostro can calculate the sats amount from that selection and then send back a message asking for a LN invoice with that exact amount:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
In order to continue the buyer needs to send a lightning network invoice to Mostro, in this case the amount of the order is `0`, so Mostro will need to calculate the amount of sats for this order, then Mostro will send back a message asking for a LN invoice indicating the correct amount of sats that the invoice should have, here the decrypted content of the message:
In order to continue the buyer needs to send a lightning network invoice to Mostro for the selected fiat amount, so Mostro can calculate the sats amount from that selection and then send back a message asking for a LN invoice with that exact amount:
🤖 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 `@src/take_sell_range_order.md` at line 25, Update the range-order explanation
in the take_sell_range_order.md content so it no longer says the order amount is
`0`; instead, describe that Mostro uses the selected fiat amount from the range
order to calculate the required sats. Keep the rest of the flow intact, but make
the wording in this section consistent with the range-order example and its
invoice payload rather than the zero-amount sell flow.

Comment thread src/take_sell.md

If the invoice includes an amount, the last element of the `payment_request` array should be set to `null`.

## Mostro response

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Rename the second Mostro response heading.

This repeats the earlier heading and creates a duplicate anchor in rendered Markdown.

Suggested fix
-## Mostro response
+## Mostro response (buyer LN invoice)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## Mostro response
## Mostro response (buyer LN invoice)
🧰 Tools
🪛 LanguageTool

[grammar] ~114-~114: Ensure spelling is correct
Context: ...estarray should be set tonull`. ## Mostro response Mostro sends a message to the...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🪛 markdownlint-cli2 (0.22.1)

[warning] 114-114: Multiple headings with the same content

(MD024, no-duplicate-heading)

🤖 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 `@src/take_sell.md` at line 114, The second “Mostro response” heading in the
take_sell markdown duplicates the earlier anchor, so rename this heading to a
distinct title in the same section to avoid repeated rendered anchors. Update
the Markdown heading near the repeated “Mostro response” text so it remains
clear and unique without changing the surrounding content structure.

Source: Linters/SAST tools

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