feat: parse anti-abuse bond tags from kind-38385 info event#601
feat: parse anti-abuse bond tags from kind-38385 info event#601AndreaDiazCorreia wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThis 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. ChangesAnti-Abuse Bond Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
lib/features/mostro/mostro_instance.darttest/features/mostro/mostro_instance_test.dart
There was a problem hiding this comment.
Code review
No la aprobaría todavía.
Lo que me frena
bondSlashOnWaitingTimeoutconvierte cualquier valor no-trueenfalse.
Eso aplana valores malformados ("foo","", etc.) en un estado válido y hace que un dato corrupto sea indistinguible de unfalsereal.- Dado que el resto de los nuevos campos ya usan
tryParse/nullpara no inventar valores, aquí esperaría la misma defensa:nullpara valores inválidos, o al menos un parser explícito paratrue/falseבלבד.
Lo que sí está bien
- La separación entre
unsupportedydisabledparabond_enabledtiene 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.
There was a problem hiding this comment.
Code review
Still not approvable.
Blocking issue
bondSlashOnWaitingTimeoutstill collapses every non-truevalue intofalse.
That means malformed input like"foo"or""becomes indistinguishable from a deliberatefalse.
Since the rest of the new bond fields are parsed defensively (tryParse/null), this one should follow the same pattern and returnnullfor invalid values, or use a strict boolean parser.
What looks good
- The
unsupportedvsdisabledsplit forbond_enabledis correct. - The new tests around the optional numeric fields are useful.
Fix that parser and I’d be comfortable approving it.
There was a problem hiding this comment.
Code review
✅ Approved.
Re-checked the exact head SHA and the blocker is gone:
bond_slash_on_waiting_timeoutnow returnsnullfor malformed values.- The test suite covers both valid booleans and malformed inputs explicitly.
The rest of the bond parsing looks solid enough to merge.
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_enabledis the only bond tag emitted unconditionally on modern daemons. Modelled as aBondPolicyenum rather thanbool?to prevent silently collapsing "tag absent" withbond_enabled = "false":unsupported— tag absent (legacy daemon)disabled—bond_enabled = "false"enabled—bond_enabled = "true"(six other bond tags present)Changes
lib/features/mostro/mostro_instance.dart: newBondPolicyandBondApplyToenums, seven new fields onMostroInstance, matching getters on theNostrEventextension 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
Tests