Skip to content

Rework the instruction parse API around per-input account borrows - #93

Open
squadgazzz wants to merge 3 commits into
mainfrom
interface/parse-api-cleanup
Open

Rework the instruction parse API around per-input account borrows#93
squadgazzz wants to merge 3 commits into
mainfrom
interface/parse-api-cleanup

Conversation

@squadgazzz

@squadgazzz squadgazzz commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Description

Review of cowprotocol/services#4666 (the indexer parses instructions read-only) surfaced three rough edges in the interface crate: every input demanded &'a mut [A] even when parsing only reads, callers had to recover the discriminator and dispatch by hand, and buffer pairs came back as positional [A; 2] arrays.

Changes

  • InstructionInputParsing gains an associated type Accounts. Read-only inputs (initialize, create order, create buffer, reclaim order) now parse from &'a [A], the two settle inputs keep &'a mut [A].
  • New parse_instruction entry point dispatches by discriminator and returns a ParsedInstruction enum.
  • CreateBufferInput yields named BufferAccounts { buffer_pda, mint } pairs instead of index-addressed arrays.
  • Input fields the parser never writes through (order PDA, state PDA, reclaim recipient) are now shared refs. The program copies the handle locally where it writes, an AccountView copy writes through to the same runtime account.

How to test

Updated unit tests.

@squadgazzz
squadgazzz requested a review from a team as a code owner August 5, 2026 10:21
@squadgazzz
squadgazzz marked this pull request as draft August 5, 2026 10:22
@squadgazzz
squadgazzz marked this pull request as ready for review August 5, 2026 10:27
@kaze-cow

kaze-cow commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

hi @squadgazzz ,

We have started reviewing this PR internally. While we aren't ready to share a comprehensive review, a couple things that have caught our attention so far is, broadly:

  1. The parse_instruction code probably doesn't belong in the interface. It also feels like its kind of duplicating what is already happening in the existing parsers, but to solve a different type of problem outside of the program scope
  2. There doesn't seem to be a great practical way to resolve the issue of mutability/immutable in the parser. Since the interface is also servicing the solana program, we have some concerns about if this is going to impact performance (CU cost, etc)

We are in the process of getting CU benchmarks up and running btw #67 , but until then it may be a bit longer before we can fully review the PR 🙏

@linear-code

linear-code Bot commented Aug 7, 2026

Copy link
Copy Markdown

BE-205

@squadgazzz

Copy link
Copy Markdown
Contributor Author

Thanks for the early look @kaze-cow 🙇

Agree on the placement, moved to the client crate. The interface only keeps the per-input parsers the program itself uses. Regarding the duplication, it doesn't re-parse anything, it's a single discriminator match that delegates to those same per-input parsers. Our indexer needs one entry point for "here's an instruction, tell me what it is", and without this it would hand-roll that match against the interface anyway.

Regarding the second comment, the borrow split is compile-time only. The two settle inputs keep &'a mut [A] exactly as before, the read-only inputs now take &'a [A], and nothing moves differently at runtime. The one new runtime operation is copying the AccountView handle before the write in three processors. I'd expect the #67 benchmarks to show no measurable CU difference, but still curious to see the actual numbers.

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