chore: stop re-broadcasting permanently-failed market settlements#1403
Conversation
Time Submission Status
Submit or update total time with: Add time on top of previous submission with: See available commands to help comply with our Guidelines. |
|
Warning Review limit reached
Next review available in: 19 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR adds permanent-failure detection to ChangesPermanent settle failure quarantine
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
|
@holdex pr submit-time 4h |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@extensions/tn_settlement/scheduler/scheduler.go`:
- Around line 267-299: The settlement loop in scheduler.go is consuming the DB
limit before applying in-memory quarantine checks, so quarantined markets can
block newer eligible ones from being processed. Update the market selection
logic around s.runSettlementCycle/FindUnsettledMarkets so it fetches or
paginates enough candidates to settle up to maxMarkets non-quarantined markets,
rather than stopping at the first maxMarkets results. Add a regression test
covering maxMarkets=1 with one quarantined older market and one eligible newer
market to verify the newer market is still settled.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: cb93293d-2cc9-4a2e-b8f9-5348dc129a68
📒 Files selected for processing (5)
extensions/tn_settlement/internal/engine_ops.goextensions/tn_settlement/internal/engine_ops_test.goextensions/tn_settlement/scheduler/constants.goextensions/tn_settlement/scheduler/scheduler.goextensions/tn_settlement/scheduler/scheduler_test.go
What changes
A prediction market whose signed attestation is unparseable — for example an empty, 128-byte binary payload captured when the source data landed after the attestation fired (the market-368 incident) — can never be settled:
settle_marketreverts deterministically on every attempt. Thetn_settlementscheduler previously treated that permanent failure as retryable, so it re-broadcast asettle_markettx that reverted identically every 5-minute poll forever, burning nonces on the settlement signer and committing a failed tx to a mainnet block each time (~36 failed txs/hour during the incident).This teaches the scheduler to tell a permanent failure from a transient one and stop:
internal/engine_ops.go): a settle_market revert whose error matches an attestation-parse-failure signature is permanent — the attestation is signed and immutable, so re-parsing the same bytes fails forever.settle_market → parse_attestation_booleanroutes binary markets (action_id 6–9) toparseBinaryActionResultand numeric markets (action_id 1–5) toparseNumericActionResult, so the signature list covers both: the binary failures (binary action result must be …,abi-encoded bool, the boolean-decode errors), the numeric failures (result payload contains no values,failed to decode ABI result payload,expected 2 arrays …,values must be []*big.Int), and the malformed-canonical /unsupported action_idfamily. Nonce and network/broadcast errors are explicitly excluded and keep retrying. The list is deliberately narrow: an unfamiliar error stays transient (no regression), so the fix can never wrongly strand a settleable market.BroadcastSettleMarketWithRetry): on a permanent failure it returns immediately with the newErrPermanentSettleFailuresentinel instead of burning the remaining retry attempts.scheduler/scheduler.go): the scheduler skips a permanently-failed market until a 1-hour re-probe cooldown, then probes it once. This bounds the failed-tx rate to at most one per cooldown per stuck market (vs every poll), logs it loudly for manual intervention, and auto-recovers — if an operator re-attests (a fresh 32-byte attestation overrides the bad one), the next probe settles it and clears the quarantine.The quarantine is in-memory and leader-local (only the leader runs settlement); on restart or leadership change it re-probes once and re-quarantines if still permanent. Nothing on-chain changes — no migration, no precompile output, no consensus behavior. This is defect (C) from the backlog; defects (A) gate empty/non-boolean attestations at signing and (B) soften
parse_attestation_booleanare consensus/migration changes left as separate follow-ups. The kept-deployedadmin_force_settle_marketremains the operator remedy.Tests
internal/engine_ops_test.go:TestIsPermanentSettleError(table: the 368 binary payload, malformed-canonical, boolean-decode, and the numeric empty/malformed/wrong-array-count cases all classify permanent; nonce/network/unrelated-revert stay transient) andTestBroadcastSettleMarketWithRetry_PermanentFailureStopsImmediately(permanent failure attempted exactly once, returns the sentinel).scheduler/scheduler_test.go:TestRunSettlementCycle_PermanentFailureQuarantinesMarket(attempted once, quarantined, then skipped and not re-broadcast) andTestRunSettlementCycle_SuccessClearsQuarantine(a market that settles after the cooldown clears its quarantine).Both
tn_settlementpackage suites pass;go build ./...andgo vet -tags kwiltest ./extensions/tn_settlement/...are clean.