Skip to content

fix(markets): fail closed when difficulty-adjustment is unreachable - #42

Merged
adrienlacombe merged 2 commits into
mainfrom
cursor/markets-halt-fail-closed-972e
Aug 16, 2026
Merged

fix(markets): fail closed when difficulty-adjustment is unreachable#42
adrienlacombe merged 2 commits into
mainfrom
cursor/markets-halt-fail-closed-972e

Conversation

@adrienlacombe

Copy link
Copy Markdown
Owner

Summary

Client trading halt for the v1 Bitcoin difficulty market must refuse new bets when mempool.space is down — not silently fall back to tip-height 2016-block math.

What changed

  • fetch_difficulty_halt_status now calls only GET https://mempool.space/api/v1/difficulty-adjustment and parses remainingBlocks (halt iff <= 24).
  • Removed MEMPOOL_TIP_HEIGHT_URL / height_fallback from the product path.
  • HTTP/JSON/field failure → Err; place_bet aborts before signing with “Betting is unavailable…” copy.
  • Extracted difficulty_halt_status_from_adjustment for unit tests: 25 open, 24/0 halted, missing/null remainingBlocks fails closed.
  • Docs + helper comments updated so height math stays test-only, not a live betting fallback.

Unchanged (by design)

  • UI already disables Place bet when difficulty_halt_status errors (market stays null / loadError) — no UI churn.
  • Height helpers in buzz-core / halt.ts kept for unit tests.
  • No Lightning fund halt; no INDEXER_URL / AVNU_PROXY_URL / infra/aws/paymaster.tf changes.

Related issue

N/A — CEO ask on PR 31 tip-height fallback hole.

Testing

  • cargo test -p buzz-core remaining_blocks_signal_halts_at_24
  • cargo test --manifest-path desktop/src-tauri/Cargo.toml commands::markets::tests (4 passed, including fail-closed parse)
  • pnpm test -- src/features/markets/lib/markets.test.mjs (remainingBlocks thresholds)
Open in Web Open in Cursor 

cursoragent and others added 2 commits August 16, 2026 19:12
Product betting halt must use mempool remainingBlocks only. Drop the
tip-height 2016-block fallback so a down height source cannot silently
allow place_bet; UI already disables Place bet on command error.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: Adrien Lacombe <adrienlacombe@users.noreply.github.com>
Satisfy desktop Tauri fmt check on import wrap and map_err chain.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: Adrien Lacombe <adrienlacombe@users.noreply.github.com>
@adrienlacombe
adrienlacombe marked this pull request as ready for review August 16, 2026 20:04
@adrienlacombe
adrienlacombe merged commit 86907f3 into main Aug 16, 2026
35 checks passed
@adrienlacombe
adrienlacombe deleted the cursor/markets-halt-fail-closed-972e branch August 16, 2026 20:04
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.

2 participants