Order book: take the PDA bump search out of the depth-cost test - #174
Open
mikemaccana wants to merge 1 commit into
Open
mikemaccana wants to merge 1 commit into
mikemaccana wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The flake
deepest_path_adds_little_compute_to_insert_fill_and_cancelcompares 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 tomain'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:
sol_try_find_program_addresssol_sha256plus the curve check, measuredWith the search taken out, the extra cost of depth 64 is the same on every run:
The 15,000 limit is unchanged.
Checks
cargo build-sbf(Agave 3.1.8).cargo fmt --checkis clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01JGEoAUjMm7Evv69k46eNcn
Generated by Claude Code