Repository navigation
Fix builders filling in data fields named like an account - #349
Conversation
This PR fixes three bugs that meet when an omitted data field is named like an account and filled in from a PDA. Asynchronous builders read a renamed input property that only the synchronous input declares, the arguments inherited the account of the same name so the default never ran, and data fields received the `[address, bump]` pair of the PDA rather than its address. It also applies the quality findings of the second audit: a shared scope type for generated-node imports, private helpers no longer named like exported siblings, and test helpers moved to the shared setup.
🦋 Changeset detectedLatest commit: 77d617b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
trevor-cortex
left a comment
There was a problem hiding this comment.
Summary
Fixes the trio of bugs that surface when an omitted data field shares its name with an account and is filled in from a PDA:
getRenamedArgsMapnow takes the builder scope (useAsync) and is computed per builder ininstructionFunction.ts, so the async builder no longer mapsvault: input.vaultArgfrom a property only the sync input declares. The page-level warning and the program plugin use the right scope too (useAsync: falsefor the warning,isAsyncfor the builder the plugin calls).getArgumentsInitializationFragmentdestructures omitted args named like an account out ofinput(const { vault: _vault, ...originalArgs } = { ...input }) soargs.vault === undefinedactually holds and the default runs.- Linked PDA defaults on data fields are now indexed with
[0].
Plus the audit clean-up: GeneratedNodeModuleScope shared type, getDefinedTypeNodesToExtract made private to the render-map visitor, hasInstructionData requiring customInstructionData, private helpers renamed away from their exported siblings, readonly resolved inputs, getCodamaError moved to test/_setup.ts, and a linkVault E2E fixture with a runtime test. The logic refactor in getInstructionFunctionInputFlags is behaviour-preserving as far as I can tell.
The shadowing approach is sound: renamed args are input args and shadowed args are omitted (non-input) args, so the two sets are disjoint by construction and the { ...input, vault: input.vaultArg } / { vault: _vault, ...originalArgs } paths can't collide. TS also treats _vault as used because of the rest sibling, so noUnusedLocals in the E2E tsconfig is happy.
Blocking
The [0] fix only covers the linked PDA branch. The inlined pdaNode branch a few lines above (await getProgramDerivedAddress({ ... })) still assigns the [address, bump] pair to data fields, so an omitted data field defaulting to an inline PDA keeps the exact bug this PR describes. See the inline comment.
Notes for reviewers
- The E2E program address changed from
Instructions1111…to86ZVX2…. I assume that's becauseIisn't in the base58 alphabet and the new runtime test is the first thing to actually derive a PDA against it — worth a line in the PR description so it doesn't look like an unrelated churn. - The changeset is
major; with the repo on the2.0.0-rctrain that matches the pre-mode process, even though the[0]change is arguably a bug fix (the old output couldn't have encoded). CLAUDE.mdstill listsgetRenamedArgsMapconceptually underinstructionInputs.ts("the only module that knows how the IDL stores them") — now that it lives inasync.ts, theasync.tsbullet could mention it. Non-blocking.
| // Account values accept the derived address with its bump, whilst data fields hold the address. | ||
| const pda = fragment`await ${pdaFunction}(${mergeFragments(pdaArgs, c => c.join(', '))})`; | ||
| return defaultFragment(input.kind === 'account' ? pda : fragment`(${pda})[0]`); |
There was a problem hiding this comment.
This only covers linked PDAs. The inlined pdaNode branch above (return defaultFragment(fragment\await ${getProgramDerivedAddress}({ ... })`), ~L210) still assigns the [address, bump]tuple wheninput.kind === 'data', so an omitted data field defaulting to an inline pdaValueNode({ pda: pdaNode(...) })` keeps the bug this PR fixes.
Suggest lifting the kind check into a small helper used by both branches, e.g.
const pdaAddress = (pda: Fragment) => (input.kind === 'account' ? pda : fragment`(${pda})[0]`);and adding a unit test for the inline case alongside the linked one (it renders instruction arguments with linked PDA default values…).
Fixes inlined PDA defaults of data fields the same way as linked ones, with a test, and documents where arguments are renamed.
|
Inlined PDA defaults of data fields now hold the address too, through one |
trevor-cortex
left a comment
There was a problem hiding this comment.
Re-review
The blocking point from the previous pass is resolved: instructionInputDefault.ts now wraps both the inlined getProgramDerivedAddress branch and the linked findXPda branch through a shared pdaDefault helper that indexes [0] for data fields and leaves account values untouched, and there's a dedicated unit test (it renders instruction arguments with inlined PDA default values as addresses) covering the inline case. The non-blocking notes are also addressed: CLAUDE.md / AGENTS.md mention getRenamedArgsMap under async.ts, and the PR description explains the base58 fixture address change.
Re-checked the rest of the diff against the current head — instructionFunction.ts, async.ts, programPlugin.ts, instructionPage.ts, the render-map visitor, the E2E fixture and runtime test are unchanged from my first pass and still look right. Nothing further from me.
Notes for reviewers
- The new
const pdaDefault = …sits directly in thecase 'pdaValueNode':body without a block, alongside the existinglet pdaProgramValue. Lint evidently doesn't enforceno-case-declarationshere, so it's consistent with the surrounding code — just flagging in case anyone wonders. - The
[0]change is shipped asmajorto fit the2.0.0-rcpre-mode train; the generated output for affected data fields previously couldn't have type-checked, so no consumer should be relying on the old shape.
This PR fixes three bugs that meet when an omitted data field is named like an account and filled in from a PDA. Asynchronous builders read a renamed input property that only the synchronous input declares, the arguments inherited the account of the same name so the default never ran, and data fields received the
[address, bump]pair of the PDA rather than its address. It also applies the quality findings of the second audit: a shared scope type for generated-node imports, private helpers no longer named like exported siblings, and test helpers moved to the shared setup.The program address of the
instructionsfixture also changes, sinceInstructions111…contained anI, which is not a base58 character, and the new test is the first to derive a PDA from it at runtime.