Skip to content

Fix: Missing discriminator for instructions without parameters#52

Open
t0mpl wants to merge 1 commit intogagliardetto:mainfrom
t0mpl:main
Open

Fix: Missing discriminator for instructions without parameters#52
t0mpl wants to merge 1 commit intogagliardetto:mainfrom
t0mpl:main

Conversation

@t0mpl
Copy link

@t0mpl t0mpl commented Oct 17, 2025

Problem:

Instructions with no parameters were being generated with nil instruction data instead of including their 8-byte discriminator. This caused InstructionFallbackNotFound errors when calling these instructions on-chain.
The generator was only creating the buffer and writing the discriminator when len(instruction.Args) > 0. Instructions like cancel_order, force_void, initialize_market_factory, etc. would fail because Anchor always expects the discriminator, even for parameter-less instructions.

Solution:

Refactored the instruction generation logic to always:
Create the buffer and encoder
Write the instruction discriminator
Encode parameters only when they exist
The buffer is now always passed to NewInstruction() instead of conditionally passing nil.

Changes:

Modified generator/instructions.go to move discriminator encoding outside the parameter check
All instructions now include their discriminator in the instruction data
Parameter encoding remains conditional

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