Skip to content

feat: parse anti-abuse bond policy from kind-38385 info event#198

Open
AndreaDiazCorreia wants to merge 3 commits into
mainfrom
feat/bond-policy-kind-38385
Open

feat: parse anti-abuse bond policy from kind-38385 info event#198
AndreaDiazCorreia wants to merge 3 commits into
mainfrom
feat/bond-policy-kind-38385

Conversation

@AndreaDiazCorreia

@AndreaDiazCorreia AndreaDiazCorreia commented Jul 18, 2026

Copy link
Copy Markdown
Member

Closes #190. Part of the anti-abuse bond epic #145.

What

Parses and validates the anti-abuse bond policy advertised by a Mostro node in its kind-38385 info event, exposing it on MostroInstance for the rest of the app to consume. Parsing only — no UI (the About-screen display is tracked in #196).

Changes

  • Add a three-state BondPolicy enum (unsupported / disabled / enabled) so the app can tell "feature off" apart from a legacy daemon, plus a BondApplyTo enum (take / make / both).
  • Add seven bond fields to MostroInstance (bondPolicy defaults to unsupported; the six parameters are nullable and meaningful only when the policy is enabled).
  • Parse the bond tags in MostroInstance.fromTags with defensive sanitization:
    • Empty or whitespace-only bond_enabled="" is treated as missing (unsupported), not disabled, preserving the three-state semantics.
    • Malformed bond_enabled values fall back to unsupported.
    • Range validation: bond_amount_pct and bond_slash_node_share_pct in [0.0, 1.0], bond_base_amount_sats >= 0, bond_payout_claim_window_days > 0; out-of-range or unparseable values yield null.
  • The bond amount is never computed client-side for charging — the daemon always sends the exact bolt11; the pct/base fields exist only for up-front UI warnings.

Tests

  • 18 unit tests covering the three policy states, case-insensitive parsing, empty / whitespace / malformed / value-less tags, per-tag parsing, and range validation.
  • flutter analyze clean; existing non-bond parsing is unaffected.

Parity reference

Client-side behavior mirrors v1 (MostroP2P/mobile docs/architecture/ANTI_ABUSE_BOND.md section 2).

Summary by CodeRabbit

  • New Features

    • Added support for displaying Mostro instance bond configuration.
    • Bond settings now indicate whether bonds are enabled, disabled, or unsupported.
    • Added bond application scope and configurable amounts, percentages, timeout behavior, node share, and payout claim window.
  • Bug Fixes

    • Invalid, missing, or out-of-range bond values are safely ignored.
    • Bond configuration parsing now handles whitespace, casing, and malformed values consistently.
  • Tests

    • Added comprehensive coverage for bond settings, validation, defaults, and existing tag parsing.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@AndreaDiazCorreia, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 44 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f7c1a00d-e19e-4cd4-a7c0-0e6f1bab0413

📥 Commits

Reviewing files that changed from the base of the PR and between ce750e2 and 2e5c6e8.

📒 Files selected for processing (2)
  • lib/features/about/models/mostro_instance.dart
  • test/features/about/models/mostro_instance_test.dart

Walkthrough

MostroInstance now exposes anti-abuse bond configuration parsed from Kind 38385 tags. Parsing handles policy states, enum mappings, booleans, numeric validation, malformed values, and absent tags, with tests covering supported inputs and defaults.

Changes

Anti-abuse bond parsing

Layer / File(s) Summary
Bond model and tag parsing
lib/features/about/models/mostro_instance.dart
Adds bond enums and nullable configuration fields, then parses and validates corresponding Kind 38385 tags in MostroInstance.fromTags.
Bond parsing validation tests
test/features/about/models/mostro_instance_test.dart
Tests policy states, parameter mappings, malformed values, numeric boundaries, and default behavior without bond tags.

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

Possibly related issues

  • Issue 145 — Covers the epic objective for validated bond-policy parsing in the app.
  • Issue 196 — Describes the bond-policy model and parsing fields added by this change.
  • Mobile issue 591 — Defines the corresponding node-level anti-abuse bond configuration parsing.

Poem

A rabbit found tags in a neat little row,
With bonds to parse and values to know.
“True, false, or missing,” the bright bunny sings,
“Bounds keep the mischief from sprouting new wings!”
The model now hops with fields tucked inside.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The bond parsing and validation are in place, but the summary shows missing bond tags yield null instead of the required 15-day claim-window default. Default bond_payout_claim_window_days to 15 when the tag is absent, and add a unit test for the missing-tag case.
✅ 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 summarizes the main change: parsing the anti-abuse bond policy from kind-38385 events.
Out of Scope Changes check ✅ Passed The changes stay within the bond model/parser and test coverage, with no unrelated feature or UI work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/bond-policy-kind-38385

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: ce750e25bb

ℹ️ 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 lib/features/about/models/mostro_instance.dart Outdated

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

Requesting changes: the bond parameters are still parsed even when bondPolicy is unsupported or disabled. The spec says the six parameter fields should be non-null only when the policy is enabled, so this can surface contradictory state (bondPolicy = disabled with live bond values). Please gate the parameter parsing on bond_enabled == true or explicitly null them out for non-enabled policies.

Comment thread lib/features/about/models/mostro_instance.dart Outdated
…rity

- Only parse bond parameters when bondPolicy == BondPolicy.enabled, ensuring
  disabled/unsupported nodes never expose bond values even if tags are present
- Add enabledTagsWith() test helper to simplify bond parameter test setup
- Improve inline comments: remove redundant parser function docs, clarify
  empty-string handling and parameter gating logic
- Reformat long parameter assignments for consistency
- Add test coverage verifying disabled/unsupported nodes expose null bond

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

Approved. The bond parameters are now correctly gated on bond_enabled == true, so disabled/unsupported info events no longer expose contradictory non-null bond state. The added tests cover the fixed invariant and the current head looks good.

@AndreaDiazCorreia
AndreaDiazCorreia requested a review from grunch July 18, 2026 04: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.

Parse and validate bond policy from kind 38385 info events

1 participant