feat: parse anti-abuse bond tags from kind-38385 info event#601
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)
WalkthroughModels Mostro's anti-abuse bond as a three-state enum, adds nullable bond parameters, trims/nullable tag parsing, wires values into MostroInstance.fromEvent, and adds comprehensive tests for 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.
2f2a51f to
ab51fdc
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/features/mostro/mostro_instance.dart (1)
170-181: ⚡ Quick winStrict-parse
bond_enabledso malformed values don’t masquerade asdisabled.Line 178 currently treats every non-
"true"value asBondPolicy.disabled. That conflates malformed payloads with an explicitbond_enabled="false"policy.Proposed change
- /// - Any other value → [BondPolicy.disabled]. + /// - `"false"` → [BondPolicy.disabled]. + /// - Any other value → [BondPolicy.unsupported] (defensive fallback). BondPolicy get bondPolicy { - final raw = _getOptionalTagValue('bond_enabled'); - if (raw == null) return BondPolicy.unsupported; - return raw.toLowerCase() == 'true' - ? BondPolicy.enabled - : BondPolicy.disabled; + final raw = _getOptionalTagValue('bond_enabled')?.toLowerCase(); + switch (raw) { + case 'true': + return BondPolicy.enabled; + case 'false': + return BondPolicy.disabled; + case null: + default: + return BondPolicy.unsupported; + } }🤖 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 `@lib/features/mostro/mostro_instance.dart` around lines 170 - 181, The bondPolicy getter currently maps any non-"true" tag to BondPolicy.disabled; instead, parse strictly: call _getOptionalTagValue('bond_enabled') as before, return BondPolicy.unsupported if null, return BondPolicy.enabled only if raw.toLowerCase() == 'true', return BondPolicy.disabled only if raw.toLowerCase() == 'false', and for any other value return BondPolicy.unsupported (or treat as malformed). Update the bondPolicy getter to perform these explicit checks (referencing bondPolicy, _getOptionalTagValue, and the BondPolicy enum) so malformed values don't masquerade as disabled.
🤖 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.
Nitpick comments:
In `@lib/features/mostro/mostro_instance.dart`:
- Around line 170-181: The bondPolicy getter currently maps any non-"true" tag
to BondPolicy.disabled; instead, parse strictly: call
_getOptionalTagValue('bond_enabled') as before, return BondPolicy.unsupported if
null, return BondPolicy.enabled only if raw.toLowerCase() == 'true', return
BondPolicy.disabled only if raw.toLowerCase() == 'false', and for any other
value return BondPolicy.unsupported (or treat as malformed). Update the
bondPolicy getter to perform these explicit checks (referencing bondPolicy,
_getOptionalTagValue, and the BondPolicy enum) so malformed values don't
masquerade as disabled.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2ef586d6-bcc9-4af3-ad10-359ba1f171f8
📒 Files selected for processing (2)
lib/features/mostro/mostro_instance.darttest/features/mostro/mostro_instance_test.dart
There was a problem hiding this comment.
Hermes Agent Review
Re-checked the current head SHA. The previous blocking issue is fixed, but I still found one correctness problem before approval.
Blocking
bondPolicystill maps any non-true/ non-missing value toBondPolicy.disabled. That means malformed payloads likebond_enabled="foo"are indistinguishable from an intentionalfalse, which breaks the three-state semantics the PR is introducing. I would returnnull/unsupportedfor malformed values, or parsefalseexplicitly and treat everything else as invalid.
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