Search additional programs when identifying and parsing data - #1024
Open
plutohan wants to merge 1 commit into
Open
Search additional programs when identifying and parsing data#1024plutohan wants to merge 1 commit into
plutohan wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 06941f4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Member
trevor-cortex
approved these changes
Jul 29, 2026
trevor-cortex
left a comment
There was a problem hiding this comment.
Summary
Fixes the long-standing gap where identifyData / parseInstruction only ever searched root.program, causing instructions from additionalPrograms (e.g. ATA embedded in a token IDL) to be misidentified against the main program's discriminators. The change:
- Introduces
IdentifyDataOptionswith aprogramAddressfield, threaded through everyidentify*/parse*entry point. getByteIdentificationVisitornow iterates all candidate programs via a newgetCandidateProgramshelper — main program first (viagetAllPrograms), then additional programs.parseInstructionautomatically passesinstruction.programAddressdown, so callers get correct routing for free.- When
programAddressis provided but no program in the IDL matches, all programs are searched — this preserves behavior for IDLs whosepublicKeyfields are placeholders rather than real on-chain addresses. - The single-non-discriminated-node fallback now applies per candidate program with the same selection logic.
Things to watch
- Fallback behavior is subtly broader. Previously the "single non-discriminated instruction" fallback only inspected
root.program. It now inspects every candidate program (main first). For most IDLs this is a strict improvement, but any IDL that relied on the fallback returningundefinedwhen the main program had multiple candidates — while an additional program happened to have exactly one non-discriminated node — would now get a match. Almost certainly desirable, worth being aware of. - Program-address matching is exact string equality on
publicKey. No normalization / case handling — fine givenpublicKeyis a base58 address, just noting it in case future IDLs ever carry non-canonical strings. - Ordering guarantee (main program wins over additional programs on ambiguous discriminators) is enforced by
getAllProgramsreturning main first. There's a test covering this, so the contract is pinned.
Notes for subsequent reviewers
- The changeset is
minoron@codama/dynamic-parsers, which matches: new optional option + expanded (non-breaking) identification surface. getByteIdentificationVisitoris exported; itsoptionstype widened from{ stack?: NodeStack }toIdentifyDataOptions & { stack?: NodeStack }. Backwards compatible for existing callers.- Test coverage is thorough: main-first ordering, address-restricted search, no-match-falls-back-to-all, and the additional-program single-non-discriminated fallback all have dedicated cases. The new
parsers.test.tscase realistically models the ATA-vs-token discriminator collision from the linked issue.
Nice, tight fix.
Member
|
Thanks! Looks good to me. @mikhd Let me know if that's good on your side as well since that touches the dynamic packages. |
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.
Fixes #553.
identifyDataonly visited the root node's main program, so instructions living inadditionalPrograms(e.g. the ATA program embedded in the token IDLs) could never be identified and were misparsed against the main program's discriminators.parseInstructionpasses the instruction'sprogramAddressdown, restricting the search to programs matching that address. When no program matches, all programs are searched, which keeps the existing behavior for roots whose program IDs are placeholders.identify*/parse*functions accept an optionalprogramAddressoption.With this, an ATA
createAssociatedTokenIdempotentcarried in a token IDL's additional programs parses through the ATA program instead of colliding with the token program'sinitializeAccounton the shared one-byte discriminator.