feat(bond): align AntiAbuseBondSettings with spec — slash split, claim window, drop unused dispute flag#728
Conversation
…m window, drop unused dispute flag
Three changes to `[anti_abuse_bond]` to match the
`docs/ANTI_ABUSE_BOND.md` spec:
- Add `slash_node_share_pct: f64` (default `0.5`). Fraction of a
slashed bond the node retains; the rest goes to the winning
counterparty. Funds solver compensation for dispute work without
introducing a new payment rail (the slash already routes through
Mostro's wallet on settle). `0.0` keeps the legacy
winner-takes-all semantics; `1.0` makes the bond a pure sybil/abuse
cost.
- Add `payout_claim_window_days: u32` (default `15`). Long-stop
forfeiture: if the wronged counterparty never submits a payout
invoice within this window, the bond closes as `forfeited` and the
node retains the counterparty share too. Removes the indefinite-
hold failure mode without operator intervention.
- Remove `slash_on_lost_dispute: bool`. The spec drops it explicitly
in §3 ("there is no `slash_on_lost_dispute` flag"); dispute slashes
are expressed by the solver per-resolution via the `BondResolution`
payload (Phase 2). The flag was opt-in dead code with no behaviour
wired up, so removing it does not change runtime. A toml file with
`slash_on_lost_dispute = true` from before this lands continues to
parse — serde silently ignores unknown fields on this struct — so
no operator action is needed at upgrade time.
Doc comments on `slash_on_waiting_timeout` and `payout_max_retries`
gain context: the former notes the `BondResolution` design for
disputes; the latter clarifies it counts only `send_payment` retries
against an already-received invoice (independent from the claim
window).
Tests cover the new defaults and a toml round-trip for both new
knobs. `settings.tpl.toml` updated to match.
No behaviour change in Phase 0/1 — the new fields are read by Phase
3+ scheduler logic that has not landed yet.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe PR refactors ChangesAntiAbuseBondSettings Configuration Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/config/types.rs (1)
458-473: ⚡ Quick winAdd a backward-compat parse test for removed
slash_on_lost_dispute.The PR states legacy TOML remains operator-safe, but tests don’t yet assert that explicitly. Adding one test fixture with
slash_on_lost_dispute = truewould lock this guarantee and prevent accidental regressions.Proposed test addition
+ #[test] + fn toml_legacy_removed_flag_is_ignored() { + #[derive(serde::Deserialize)] + struct Stub { + anti_abuse_bond: AntiAbuseBondSettings, + } + let parsed: Stub = toml::from_str( + r#"[anti_abuse_bond] +enabled = true +slash_on_lost_dispute = true"#, + ) + .expect("legacy unknown field should be ignored"); + + assert!(parsed.anti_abuse_bond.enabled); + assert_eq!(parsed.anti_abuse_bond.slash_node_share_pct, 0.5); + assert_eq!(parsed.anti_abuse_bond.payout_claim_window_days, 15); + }🤖 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 `@src/config/types.rs` around lines 458 - 473, Add a backward-compatibility unit test to ensure legacy TOML containing the removed field parses into AntiAbuseBondSettings: create a test similar to toml_slash_node_share_pct_and_claim_window_override (e.g., toml_legacy_slash_on_lost_dispute_parses) that defines the same Stub wrapper, provides TOML including slash_on_lost_dispute = true along with any other fields, deserializes via toml::from_str into Stub, and asserts that parsing succeeds (and optionally that other fields like slash_node_share_pct/payout_claim_window_days are preserved); locate the test near toml_slash_node_share_pct_and_claim_window_override and reuse AntiAbuseBondSettings as the target type.
🤖 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 `@src/config/types.rs`:
- Around line 72-73: The config currently allows any f64 for the field
slash_node_share_pct (with default default_slash_node_share_pct); add validation
during config deserialization or a post-parse validation step that rejects
values outside 0.0..=1.0 by returning a descriptive error (e.g., Err or
serde::de::Error) when slash_node_share_pct < 0.0 or > 1.0, update
default_slash_node_share_pct if needed to remain in range, and add unit tests
that parse the config to assert failure for values <0 and >1 and success for
valid boundary values 0.0 and 1.0 to cover parse/validation behavior.
---
Nitpick comments:
In `@src/config/types.rs`:
- Around line 458-473: Add a backward-compatibility unit test to ensure legacy
TOML containing the removed field parses into AntiAbuseBondSettings: create a
test similar to toml_slash_node_share_pct_and_claim_window_override (e.g.,
toml_legacy_slash_on_lost_dispute_parses) that defines the same Stub wrapper,
provides TOML including slash_on_lost_dispute = true along with any other
fields, deserializes via toml::from_str into Stub, and asserts that parsing
succeeds (and optionally that other fields like
slash_node_share_pct/payout_claim_window_days are preserved); locate the test
near toml_slash_node_share_pct_and_claim_window_override and reuse
AntiAbuseBondSettings as the target type.
🪄 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: 2f0207e7-a52f-4ae0-97e0-0e28c7f49fca
📒 Files selected for processing (2)
settings.tpl.tomlsrc/config/types.rs
…-config compat Two review nits on PR 728: - `slash_node_share_pct` now validates at deserialization: values outside `[0.0, 1.0]` (and NaN) are rejected with a descriptive serde error naming the field and the valid range. Out-of-range values would corrupt the `node_share_sats = floor(amount_sats * pct)` math (negative counterparty share, or node retention exceeding the bond), so failing fast at startup is safer than silent misbehaviour at slash time. The default `0.5` is in range so existing configs are unaffected. - New backward-compatibility test `toml_legacy_slash_on_lost_dispute_parses` locks down the contract the PR description claimed: a toml carrying the now-removed `slash_on_lost_dispute = true` parses without error and the surrounding fields deserialize normally. The test also flags the invariant for future maintainers — a later `#[serde(deny_unknown_fields)]` would silently break upgrade paths and this test would catch it. Three additional tests round out the validation surface: boundary values `0.0` and `1.0` are accepted; `-0.1` and `1.5` are rejected with the expected error message. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Three changes to `[anti_abuse_bond]` so the runtime config matches
the `docs/ANTI_ABUSE_BOND.md` spec:
Add `slash_node_share_pct: f64` (default `0.5`). Fraction of
a slashed bond the node retains; the rest goes to the winning
counterparty. Funds solver compensation for dispute work without
introducing a new payment rail. `0.0` keeps the legacy
winner-takes-all semantics; `1.0` makes the bond a pure sybil
cost.
Add `payout_claim_window_days: u32` (default `15`). Long-stop
forfeiture: if the wronged counterparty never submits a payout
invoice within this window, the bond closes as `forfeited` and
the node retains the counterparty share too.
Remove `slash_on_lost_dispute: bool`. The spec drops it
explicitly in §3 — dispute slashes are expressed by the solver
per-resolution via the `BondResolution` payload (Phase 2). The
flag was opt-in dead code with no runtime behaviour, so removal
does not change behaviour. A toml file with
`slash_on_lost_dispute = true` from before this lands continues
to parse (serde ignores unknown fields on this struct), so no
operator action is needed at upgrade time.
Doc comments on `slash_on_waiting_timeout` and `payout_max_retries`
gain context: the former notes the `BondResolution` design for
disputes; the latter clarifies it counts only `send_payment` retries
against an already-received invoice (independent from the claim
window).
`settings.tpl.toml` updated to match.
No behaviour change in Phase 0/1 — the new fields are read by Phase
3+ scheduler logic that has not landed yet.
Test plan
`toml_slash_node_share_pct_and_claim_window_override`)
🤖 Generated with Claude Code
Summary by CodeRabbit
slash_on_lost_disputeflag and addedslash_node_share_pctandpayout_claim_window_daysparameters for enhanced control over bond payouts and dispute slashing mechanisms.