Skip to content

Order book: take the PDA bump search out of the depth-cost test - #174

Open
mikemaccana wants to merge 1 commit into
mainfrom
claude/order-book-compute-test
Open

mikemaccana wants to merge 1 commit into
mainfrom
claude/order-book-compute-test

Conversation

@mikemaccana

Copy link
Copy Markdown
Collaborator

The flake

deepest_path_adds_little_compute_to_insert_fill_and_cancel compares an insert and a fill at depth 64 with the same instruction on a shallow book, and allows 15,000 extra compute units. In one CI run on #171 the Anchor v1 insert measured 15,228 extra. That program was identical to main's, and the re-run passed.

Cause

Both instructions create an order account with a bare bump, so Anchor searches for the bump at runtime and pays for every rejected seed. The market's address comes from generated mints, and tests running in parallel draw from shared key generation. So the search length changes from run to run, and with it the measured difference.

I reproduced this locally: the same code measured 37,306 and 38,806 units at depth 64 in different runs, exactly one 1,500-unit search step apart.

Fix

The test computes each order PDA's bump itself and subtracts the cost of the search:

Version Cost per rejected bump Why
Anchor v1 1,500 units sol_try_find_program_address
Anchor v2 334 units sol_sha256 plus the curve check, measured

With the search taken out, the extra cost of depth 64 is the same on every run:

Version Insert Fill
Anchor v1 about 10,650 about 10,660
Anchor v2 10,538 10,730

The 15,000 limit is unchanged.

Checks

  • I built both programs with cargo build-sbf (Agave 3.1.8).
  • Both full suites (34 tests each) passed five times in a row, with at most 31 units of jitter.
  • cargo fmt --check is clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JGEoAUjMm7Evv69k46eNcn


Generated by Claude Code

deepest_path_adds_little_compute_to_insert_fill_and_cancel compares an insert
and a fill at depth 64 with the same instruction on a shallow book, and allows
15,000 extra units. Both instructions create an order account with a bare
`bump`, so Anchor searches for the bump at runtime, paying for every rejected
seed. The market's address comes from generated mints, and tests running in
parallel draw from shared key generation, so the search length, and with it
the measured difference, changed from run to run. Anchor v1 measured 15,228 in
one CI run on a program identical to main, and passed on the re-run.

The test now computes each order PDA's bump itself and subtracts the search:
1,500 units per rejected bump in Anchor v1 (sol_try_find_program_address) and
334 in Anchor v2 (sol_sha256 plus the curve check). With that out, the extra
cost of depth 64 is about 10,650 units in v1 and 10,550 to 10,750 in v2, the
same on every run. The 15,000 limit is unchanged.

Claude-Session: https://claude.ai/code/session_01JGEoAUjMm7Evv69k46eNcn
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