Skip to content

Order book: say how the program stops book spam - #170

Merged
mikemaccana merged 1 commit into
mainfrom
claude/order-book-eviction-4eciar
Sep 23, 2026
Merged

mikemaccana merged 1 commit into
mainfrom
claude/order-book-eviction-4eciar

Conversation

@mikemaccana

Copy link
Copy Markdown
Collaborator

The Order Book Exchange chapter's book spam failure mode listed the gates that reject spam, but it had no answer to a side filled with far-off orders. The companion program now evicts the worst order when a side is full, and this PR describes that.

Merge after quicknode/solana-program-examples#158. That PR ships eviction and every name this chapter now uses: EvictedAccountMismatch and the five eviction test names. Merging this first would name identifiers that have not shipped.

Changes

  • Book spam failure mode. It now explains how the program stops spam. When an order would rest on a full side, it must beat that side's worst price. If it does, the worst order is removed and refunded through its owner's unsettled balance, exactly as cancel_order() refunds, and the new order takes its slot. An order that is no better, including an equal price, gets OrderBookFull.
  • Capacity. Each side holds 512 orders, not 1,024. Every order after the first takes two of the tree's 1,024 nodes, a leaf and a branch point.
  • Invariants. Cancellation and eviction each return exactly the remainder's lock.
  • Testing considerations. The chapter lists the five eviction tests.
  • What You Learnt. A sixth concept: a full book evicts its worst order.
  • State machine figure. Both routes into Cancelled read "cancel_order() or eviction".
  • Glossary. A new eviction entry.

PR #119 also touches the book spam bullet and adds an eviction glossary entry, both describing eviction as something other order books do. Those two additions are removed from #119 so the two PRs don't conflict or contradict each other.

Verification

  • npm run lint: clean
  • node scripts/check-figure-geometry.mjs: clean across 99 figures
  • npm run build-pdf: built

🤖 Generated with Claude Code

https://claude.ai/code/session_01RBfNjrQd2J6muoi3thCUin


Generated by Claude Code

The companion program now evicts: when an order would rest on a full side
and beats that side's worst price, the worst order is refunded as a cancel
would refund it and the new order takes its slot. The book spam failure mode
now describes that mechanism, and the errors it names, instead of listing
the gates that only reject spam. The invariants, tests, What You Learnt list,
state machine figure, and glossary follow.

Also corrects the capacity: each side holds 512 orders, not 1,024, because
every order after the first takes two of the tree's 1,024 nodes.

Depends on quicknode/solana-program-examples#158, which ships eviction and
the names this chapter uses.

Claude-Session: https://claude.ai/code/session_01RBfNjrQd2J6muoi3thCUin
mikemaccana added a commit that referenced this pull request Sep 23, 2026
This branch described eviction as something other order books do, in the
book spam failure mode and a glossary entry. The companion program now
evicts (quicknode/solana-program-examples#158), and #170
describes the program's own eviction in both places. Restore main's book spam
bullet and drop the OpenBook footnote and glossary entry here, so the two PRs
neither conflict nor contradict each other.

Claude-Session: https://claude.ai/code/session_01RBfNjrQd2J6muoi3thCUin
@mikemaccana
mikemaccana merged commit ee5260c into main Sep 23, 2026
1 check passed
@mikemaccana
mikemaccana deleted the claude/order-book-eviction-4eciar branch October 13, 2026 00:23
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.

1 participant