Skip to content

feat: parse anti-abuse bond tags from kind-38385 info event#601

Open
AndreaDiazCorreia wants to merge 2 commits into
mainfrom
feat/anti-abuse-bond-info-tags
Open

feat: parse anti-abuse bond tags from kind-38385 info event#601
AndreaDiazCorreia wants to merge 2 commits into
mainfrom
feat/anti-abuse-bond-info-tags

Conversation

@AndreaDiazCorreia
Copy link
Copy Markdown
Member

@AndreaDiazCorreia AndreaDiazCorreia commented May 22, 2026

Closes #594

Summary

Adds the reader/cache layer for the seven new anti-abuse bond tags shipped on mostrod's kind-38385 info event (ad1f74a). Required by the upcoming Anti-Abuse Bond Support work in #591.

Scope is intentionally limited to parsing and caching. UI, trade-flow integration, and payout deadline computation land with #591.

Three-state semantics

bond_enabled is the only bond tag emitted unconditionally on modern daemons. Modelled as a BondPolicy enum rather than bool? to prevent silently collapsing "tag absent" with bond_enabled = "false":

  • unsupported — tag absent (legacy daemon)
  • disabledbond_enabled = "false"
  • enabledbond_enabled = "true" (six other bond tags present)

Changes

  • lib/features/mostro/mostro_instance.dart: new BondPolicy and BondApplyTo enums, seven new fields on MostroInstance, matching getters on the NostrEvent extension with defensive parsing.
  • test/features/mostro/mostro_instance_test.dart: unit tests covering the three policy states, enum parsing, and malformed values.

Summary by CodeRabbit

  • New Features

    • Added Mostro anti-abuse bond support, letting instances advertise bond policy, where it applies, and configurable bond parameters with sensible defaults and validation.
  • Tests

    • Added extensive tests covering bond flag parsing, enum mapping, numeric/boolean validation, edge cases, and ensuring existing metadata parsing remains unaffected.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

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: eeb7dca5-dfe4-4b7c-9ee7-851a4db965ca

📥 Commits

Reviewing files that changed from the base of the PR and between f77f9d6 and 2f2a51f.

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

Walkthrough

This PR models Mostro's anti-abuse bond as a three-state enum, parses seven bond-related tags from kind-38385 info events (with validation and nullable semantics), wires the parsed values into MostroInstance, and adds comprehensive tests covering absent/disabled/enabled states and edge cases.

Changes

Anti-Abuse Bond Support

Layer / File(s) Summary
Bond Policy Data Model
lib/features/mostro/mostro_instance.dart
BondPolicy enum distinguishes three states (unsupported, disabled, enabled); BondApplyTo enum models trade-side applicability (take, make, both); MostroInstance gains required bondPolicy and nullable bond-parameter fields.
Bond Tag Parsing from NostrEvent
lib/features/mostro/mostro_instance.dart
_getOptionalTagValue helper safely retrieves tag values; new parsing getters interpret bond_enabled as three-state, map bond_apply_to to enum, and parse nullable numeric/boolean bond parameters with range/validity checks.
Bond Data Constructor & Factory Integration
lib/features/mostro/mostro_instance.dart
Constructor accepts bond fields with bondPolicy defaulting to BondPolicy.unsupported; fromEvent factory passes parsed bond values from NostrEvent extension into the constructor.
Bond Parsing Test Suite
test/features/mostro/mostro_instance_test.dart
Test helper builds baseline NostrEvent; tests validate legacy behavior (absent/empty/whitespace tag), disabled behavior, enabled behavior with parameters, BondApplyTo mapping and unknown handling, boolean parsing, defensive numeric parsing and range checks, and coexistence with other info-event fields.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • mostronatorcoder

Poem

I nibble tags in midnight code,
Three states, small and neatly sowed,
Parsers hum and tests applaud,
A rabbit cheers the bonded nod. 🐇

🚥 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 and concisely summarizes the main change: adding parsing for anti-abuse bond tags from the kind-38385 Mostro info event, which is the core objective of this PR.
Linked Issues check ✅ Passed All coding requirements from issue #594 are met: three-state BondPolicy enum implemented, all seven bond tags parsed with defensive validation, and cached on MostroInstance matching existing info-event patterns.
Out of Scope Changes check ✅ Passed Changes are tightly scoped to the reader/cache layer for anti-abuse bond tags; UI integration, trade-flow handling, and BondPayoutRequest processing are appropriately deferred to issue #591.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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/anti-abuse-bond-info-tags

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.

Copy link
Copy Markdown

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

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

ℹ️ 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/mostro/mostro_instance.dart Outdated
Comment thread lib/features/mostro/mostro_instance.dart Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@lib/features/mostro/mostro_instance.dart`:
- Around line 204-207: The getter bondSlashNodeSharePct currently parses any
double; update it to parse using
double.tryParse(_getOptionalTagValue('bond_slash_node_share_pct')) and then
validate the parsed value is between 0.0 and 1.0 inclusive, returning null for
parse failures or out-of-range values so downstream logic never sees invalid
percentages; use the existing _getOptionalTagValue call and return the validated
double only when value != null && value >= 0.0 && value <= 1.0.
- Around line 129-133: _guard optional-tag parsing in _getOptionalTagValue: the
predicate passed to firstWhere must check t.length>0 before accessing t[0] to
avoid runtime errors for malformed tags, and returned tag values should map
empty strings to null. Change the predicate to (t) => t.length > 0 && t[0] ==
key, keep orElse: () => [], then after finding tag check tag.length < 2 => null,
then treat an empty tag[1] (tag[1].isEmpty) as null before returning the string.
🪄 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: 0caceccf-9f2e-4670-8af2-e53a089cc425

📥 Commits

Reviewing files that changed from the base of the PR and between df7490c and f77f9d6.

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

Comment thread lib/features/mostro/mostro_instance.dart
Comment thread lib/features/mostro/mostro_instance.dart
Copy link
Copy Markdown

@ermeme ermeme Bot left a comment

Choose a reason for hiding this comment

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

Code review

No la aprobaría todavía.

Lo que me frena

  • bondSlashOnWaitingTimeout convierte cualquier valor no-true en false.
    Eso aplana valores malformados ("foo", "", etc.) en un estado válido y hace que un dato corrupto sea indistinguible de un false real.
  • Dado que el resto de los nuevos campos ya usan tryParse/null para no inventar valores, aquí esperaría la misma defensa: null para valores inválidos, o al menos un parser explícito para true/false בלבד.

Lo que sí está bien

  • La separación entre unsupported y disabled para bond_enabled tiene sentido.
  • La cobertura de tests para los nuevos campos numéricos está bien encaminada.

Si ajustan el parser booleano, sí lo vería en condiciones de aprobar.

Copy link
Copy Markdown

@ermeme ermeme Bot left a comment

Choose a reason for hiding this comment

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

Code review

Still not approvable.

Blocking issue

  • bondSlashOnWaitingTimeout still collapses every non-true value into false.
    That means malformed input like "foo" or "" becomes indistinguishable from a deliberate false.
    Since the rest of the new bond fields are parsed defensively (tryParse/null), this one should follow the same pattern and return null for invalid values, or use a strict boolean parser.

What looks good

  • The unsupported vs disabled split for bond_enabled is correct.
  • The new tests around the optional numeric fields are useful.

Fix that parser and I’d be comfortable approving it.

Comment thread lib/features/mostro/mostro_instance.dart
Copy link
Copy Markdown

@ermeme ermeme Bot left a comment

Choose a reason for hiding this comment

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

Code review

Approved.

Re-checked the exact head SHA and the blocker is gone:

  • bond_slash_on_waiting_timeout now returns null for malformed values.
  • The test suite covers both valid booleans and malformed inputs explicitly.

The rest of the bond parsing looks solid enough to merge.

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.

Read & cache new anti-abuse-bond tags from the kind-38385 info event

1 participant