Skip to content

feat(admin): Step1 - bond resolution foundation for dispute finalization#76

Merged
arkanoider merged 4 commits into
mainfrom
feat/admin-dispute-bond-resolution
May 19, 2026
Merged

feat(admin): Step1 - bond resolution foundation for dispute finalization#76
arkanoider merged 4 commits into
mainfrom
feat/admin-dispute-bond-resolution

Conversation

@arkanoider

@arkanoider arkanoider commented May 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Prepares Mostrix for anti-abuse bond slash options on admin dispute finalization (admin-settle / admin-cancel), aligned with Mostro protocol and daemon work in MostroP2P/mostro#738.

  • Bump mostro-core 0.11.0 → 0.11.3 (BondResolution, Payload::BondResolution, CantDoReason::InvalidPayload)
  • Add BondSlashChoice (None, SlashBuyer, SlashSeller, SlashBoth) with to_payload() and wire-format unit tests
  • Map InvalidPayload in get_cant_do_description for admin-facing errors
  • Update admin/finalization docs with implementation status (protocol layer done; execute + TUI pending)

Not in this PR: wiring BondSlashChoice into execute_admin_settle / cancel, bond-slash TUI step, or AddBondInvoice payout handling for traders.

Motivation

Admins resolving disputes must be able to settle or cancel the trade and independently choose whether to slash buyer/seller/both/none anti-abuse bonds. This PR lands the dependency bump and shared protocol helper so follow-up PRs can focus on execute + UI.

Test plan

  • cargo fmt --all
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test (includes 6 new tests in bond_resolution.rs)
  • Manual: no behavior change expected (finalization still sends payload: null)

Follow-up

  1. Thread BondSlashChoice through execute_finalize_dispute / execute_admin_*
  2. TUI: bond slash picker + confirm summary
  3. Gate slash step on bond_enabled from kind-38385 instance info
  4. (Optional) Action::AddBondInvoice / BondPayoutRequest for non-admin payout recipients

Summary by CodeRabbit

  • New Features

    • Added anti-abuse bond slash options (none/buyer/seller/both) for admin dispute finalization
  • Documentation

    • Expanded admin dispute finalization guide with bond resolution details and implementation status
    • Updated coding standards with dependency and protocol type guidance
    • Added CantDo error reasons documentation
  • Chores

    • Updated mostro-core dependency to version 0.11.3

Review Change Stack

…d slash

Prepare admin dispute finalization for anti-abuse bond_resolution payloads
(admin-settle / admin-cancel). Bump mostro-core to 0.11.3, add BondSlashChoice
wire mapping with unit tests, handle CantDo InvalidPayload, and document the
planned UI/execute follow-up.

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

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@arkanoider has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 50 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 98788134-2928-4249-be4e-acc60d3555ce

📥 Commits

Reviewing files that changed from the base of the PR and between f09c4aa and 8c958e2.

📒 Files selected for processing (5)
  • docs/FINALIZE_DISPUTES.md
  • docs/MESSAGE_FLOW_AND_PROTOCOL.md
  • src/util/order_utils/bond_resolution.rs
  • src/util/order_utils/execute_admin_cancel.rs
  • src/util/order_utils/execute_admin_settle.rs

Walkthrough

This PR introduces anti-abuse bond slash support for admin dispute finalization in Mostrix. It bumps the mostro-core dependency to 0.11.3, adds a new BondSlashChoice type that maps user selections to protocol bond-resolution payloads, extends error handling for invalid payloads, and documents the feature across multiple developer and user guides.

Changes

Anti-abuse bond slash support for admin dispute finalization

Layer / File(s) Summary
Protocol compatibility and development standards
Cargo.toml, docs/CODING_STANDARDS.md
Dependency bumped to mostro-core 0.11.3 with coding standards guidance for version pinning and protocol type imports.
BondSlashChoice type and core implementation
src/util/order_utils/bond_resolution.rs, src/util/order_utils/mod.rs
New BondSlashChoice enum with four variants (None, SlashBuyer, SlashSeller, SlashBoth) provides UI ordering via ALL, labels, boolean slash helpers, and conversions to BondResolution and Payload types. Unit tests verify JSON serialization with correct bond_resolution discriminator and slash fields across all choices, including round-trip deserialization.
Error handling for invalid bond payloads
src/util/types.rs
Extended get_cant_do_description to map CantDoReason::InvalidPayload to a user-facing message guiding users on bond slash choices and message format.
Comprehensive feature documentation
README.md, docs/ADMIN_DISPUTES.md, docs/FINALIZE_DISPUTES.md, docs/MESSAGE_FLOW_AND_PROTOCOL.md, docs/README.md
Documentation updates across multiple guides explain implementation status (which components are wired, what remains pending), the admin dispute UI flow with planned bond-slash selection, protocol details with order UUID usage and Rust/JSON examples, CantDo error handling behavior, and admin finalization entry points. Docs clarify that execute-layer and TUI wiring are still in progress.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • grunch
  • mostronatorcoder

🐰 A slashing choice now blooms so bright,
Four options guide the admin's might,
Bonds are dashed with purpose true,
Disputes settled, disputes through,
Protocol speaks in JSON hue. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 73.33% 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 clearly and specifically describes the main change: introducing bond resolution foundation for admin dispute finalization, which is the primary purpose of the PR.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/admin-dispute-bond-resolution

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.

@arkanoider arkanoider changed the title feat(admin): bond resolution foundation for dispute finalization feat(admin): Step1 - bond resolution foundation for dispute finalization May 19, 2026
@arkanoider

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review!

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read the new bond_resolution.rs file
cat src/util/order_utils/bond_resolution.rs

echo "---MOD---"
cat src/util/order_utils/mod.rs

echo "---TYPES---"
cat src/util/types.rs

echo "---CARGO---"
cat Cargo.toml

Length of output: 13007


🏁 Script executed:

#!/bin/bash
echo "---EXECUTE_ADMIN_SETTLE---"
cat src/util/order_utils/execute_admin_settle.rs

echo "---EXECUTE_ADMIN_CANCEL---"
cat src/util/order_utils/execute_admin_cancel.rs

echo "---EXECUTE_FINALIZE---"
cat src/util/order_utils/execute_finalize_dispute.rs

echo "---DOCS_FINALIZE---"
cat docs/FINALIZE_DISPUTES.md

Length of output: 23264


@arkanoider: The PR is well-scoped and cleanly implemented — the protocol layer foundation is solid, tests cover all four BondSlashChoice variants across both actions, and the documentation clearly communicates what's done vs. pending. A few things to address:


Review

src/util/order_utils/bond_resolution.rs

1. to_optional_payload always returns Some — misleading contract

The method name implies it may return None (e.g. for BondSlashChoice::None), but it unconditionally wraps. The docstring explains this, but anyone reading just the signature will be confused. Consider one of:

  • Rename to into_some_payload() to make the unconditional wrapping explicit, or
  • Make it actually optional for BondSlashChoice::None, returning None there and Some(_) for the three slash variants:
pub fn to_optional_payload(self) -> Option<Payload> {
    match self {
        Self::None => None,
        _ => Some(self.to_payload()),
    }
}

This would also let callers on legacy daemons fall back to payload: null naturally. Depends on whether you want to always send explicit {false,false} or only send the payload when there's an actual slash.

2. Missing Default implementation

BondSlashChoice::None is the natural default, and the upcoming TUI picker will almost certainly want one. Add:

impl Default for BondSlashChoice {
    fn default() -> Self {
        Self::None
    }
}

3. to_bond_resolution visibility

to_bond_resolution is only called by to_payload within the same file and by the unit tests in the same module. Consider pub(crate) unless external callers need direct access to BondResolution:

pub(crate) fn to_bond_resolution(self) -> BondResolution {

4. Missing doc comments on three methods

label(), slash_seller(), and slash_buyer() lack doc comments while to_payload() and to_optional_payload() have them. Minor inconsistency:

/// Human-readable label for TUI display.
pub fn label(self) -> &'static str {}

/// Returns `true` if the seller's bond should be slashed.
pub fn slash_seller(self) -> bool {}

/// Returns `true` if the buyer's bond should be slashed.
pub fn slash_buyer(self) -> bool {}

5. No explicit JSON field assertion for SlashBoth

bond_resolution_slash_both_roundtrip verifies deserialized field values but doesn't assert the raw JSON string. Consider adding wire assertions parallel to the SlashBuyer test:

#[test]
fn bond_resolution_wire_format_slash_both() {
    let msg = dispute_message(Action::AdminSettle, BondSlashChoice::SlashBoth);
    let json = msg.as_json().expect("serialize");
    assert!(json.contains("\"slash_seller\":true"));
    assert!(json.contains("\"slash_buyer\":true"));
}

src/util/order_utils/execute_admin_settle.rs / execute_admin_cancel.rs

The None payload is intentional and documented. One small note: the inline comment says // No payload needed — this will be stale once the bond-slash step lands. Consider:

// TODO: pass BondSlashChoice payload once TUI wiring is complete (see FINALIZE_DISPUTES.md)

docs/FINALIZE_DISPUTES.md

The Rust snippet uses use mostrix::util::order_utils::BondSlashChoice; — that's valid for an external consumer but internal callers would write use crate::util::order_utils::BondSlashChoice;. Worth making consistent with how it will actually appear in the execute files.


Cargo.toml

mostro-core = "0.11.3" is interpreted by Cargo as ^0.11.3 (>=0.11.3, <0.12.0), which is fine and consistent with the pinning guidance in docs/CODING_STANDARDS.md.


Summary table:

# Severity File Finding
1 🟡 Medium bond_resolution.rs to_optional_payload always returns Some — misleading name
2 🟡 Medium bond_resolution.rs Missing Default impl for BondSlashChoice
3 🔵 Low bond_resolution.rs to_bond_resolution could be pub(crate)
4 🔵 Low bond_resolution.rs Missing doc comments on label, slash_seller, slash_buyer
5 🔵 Low bond_resolution.rs No raw-JSON wire assertion for SlashBoth
6 🔵 Low execute_admin_*.rs Stale comment // No payload needed
7 🔵 Low FINALIZE_DISPUTES.md Use path in doc snippet uses crate name, not crate::
✅ Actions performed

Full review triggered.

@arkanoider

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review!

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

@arkanoider, triggering a fresh review of the PR. The findings from my previous pass (summarized below) remain outstanding — please let me know if any have already been addressed and I'll re-check:

# Severity File Finding
1 🟡 Medium bond_resolution.rs to_optional_payload always returns Some — misleading name/contract
2 🟡 Medium bond_resolution.rs Missing Default impl for BondSlashChoice
3 🔵 Low bond_resolution.rs to_bond_resolution could be pub(crate)
4 🔵 Low bond_resolution.rs Missing doc comments on label, slash_seller, slash_buyer
5 🔵 Low bond_resolution.rs No raw-JSON wire assertion for SlashBoth
6 🔵 Low execute_admin_*.rs // No payload needed comment will be stale once bond-slash wiring lands
7 🔵 Low FINALIZE_DISPUTES.md Doc snippet uses mostrix:: path instead of crate::
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@arkanoider

Copy link
Copy Markdown
Collaborator Author

I think they are fixed @coderabbitai, please check latest commits

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
echo "=== bond_resolution.rs ==="
cat src/util/order_utils/bond_resolution.rs

echo "=== execute_admin_settle.rs ==="
cat src/util/order_utils/execute_admin_settle.rs

echo "=== execute_admin_cancel.rs ==="
cat src/util/order_utils/execute_admin_cancel.rs

echo "=== FINALIZE_DISPUTES.md snippet ==="
grep -n "mostrix\|crate::" docs/FINALIZE_DISPUTES.md | head -30

Length of output: 11781


@arkanoider: Great progress! Items 1–5 are all confirmed fixed:

# Finding Status
1 to_optional_payload now returns None for BondSlashChoice::None ✅ Fixed
2 Default impl added ✅ Fixed
3 to_bond_resolution is now pub(crate) ✅ Fixed
4 Doc comments on label, slash_seller, slash_buyer ✅ Fixed
5 Wire-format + round-trip test for SlashBoth ✅ Fixed

Two small items are still outstanding:

#6execute_admin_settle.rs / execute_admin_cancel.rs — Both files still carry // No payload needed - just the order ID. Consider updating to a TODO so it doesn't become misleading when bond-slash wiring lands:

// TODO: pass BondSlashChoice::to_optional_payload() once TUI wiring is complete (see FINALIZE_DISPUTES.md)

#7docs/FINALIZE_DISPUTES.md line 143 — Still reads:

use mostrix::util::order_utils::BondSlashChoice;

Internal callers will write:

use crate::util::order_utils::BondSlashChoice;

(ᵔᴥᵔ) Almost there!

@arkanoider

Copy link
Copy Markdown
Collaborator Author

@coderabbitai look at new commit

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
echo "=== execute_admin_settle.rs ==="
cat src/util/order_utils/execute_admin_settle.rs

echo "=== execute_admin_cancel.rs ==="
cat src/util/order_utils/execute_admin_cancel.rs

echo "=== FINALIZE_DISPUTES.md use path ==="
grep -n "mostrix\|crate::" docs/FINALIZE_DISPUTES.md | head -30

Length of output: 4715


@arkanoider: Both remaining items are confirmed fixed in the latest commit:

# Finding Status
6 execute_admin_settle.rs / execute_admin_cancel.rs — stale comment replaced with // TODO(bond-slash): accept BondSlashChoice and pass bond.to_optional_payload() here. ✅ Fixed
7 docs/FINALIZE_DISPUTES.md — now uses use crate::util::order_utils::BondSlashChoice; ✅ Fixed

All 7 findings from this review are resolved. The PR looks great — the protocol layer foundation is solid and well-tested. 🎉

(ᵔᴥᵔ)

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