Work around the Anchor 2.0.0-rc.1 IDL enum bug, and fix the one failure that was ours - #132
Merged
Merged
Conversation
…output
TEMPORARY. Delete the block in anchor.yml when a release after 2.0.0-rc.1
ships; the upstream fix is already merged.
anchor-derive-accounts 2.0.0-rc.1 emits enum type definitions with the JSON
key "fields" where anchor-lang-idl-spec requires "variants", so `anchor build`
cannot deserialize the IDL it just generated:
Error: missing field `variants` at line 1 column N
The defect is one shared helper: `type_def_header_parts` in
anchor-derive-accounts' `src/idl.rs` hardcodes "fields" and is called by both
the struct emitter (kind_name = "struct", correct) and the enum emitter
(kind_name = "enum", wrong). A two-variant enum reproduces it.
Fixed upstream in otter-sec/anchor#4947, unreleased
at the time of writing. Patching only the derive crate to that commit does not
work: it requires solana-address 2.7, and these programs pin `>=2.6, <2.7`
because anchor-lang 2.0.0-rc.1 is built against wincode 0.5 while
solana-address 2.7 moved to 0.6.
Eight projects have an enum reachable from their IDL and hit it. None of them
consumes a generated IDL, so `--no-idl` costs nothing today: the program is
still compiled and its tests still run.
vault-strategy was failing for an unrelated and genuine reason, fixed here
rather than skipped: it has `BorshAccount<AssetRate>` fields whose type is
declared in mock-swap-router, and `#[account]` only generates the IDL glue
when the declaring crate has its own `idl-build` feature enabled. Its
`idl-build` now forwards to `mock-swap-router/idl-build`. Verified locally
with `anchor idl build`: the "has no IDL type information" error is gone.
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.
Nine projects fail
anchor build. Eight are one upstream bug, already fixed upstream but unreleased; the ninth was ours and is fixed here.The upstream bug
anchor-derive-accounts2.0.0-rc.1 emits enum type definitions with the JSON key"fields"whereanchor-lang-idl-specrequires"variants", soanchor buildcannot deserialize the IDL it just generated:One shared helper causes it.
type_def_header_partsin the derive crate'ssrc/idl.rshardcodes the key:Both emitters call it:
build_struct_type_def_emissionwithkind_name = "struct", which is correct, andbuild_enum_type_def_emissionwithkind_name = "enum", which is not. The spec isIdlTypeDefTy::Enum { variants: Vec<IdlEnumVariant> }, with noserde(default), so deserialization hard-fails.Reproduced end to end with a twenty-line program containing
#[derive(IdlType)] pub enum Side { Bid, Ask }. The emitted JSON is:The variant objects are correct; only the container key is wrong. Unit variants are enough, tuple variants fail identically, and the failure is invisible to
cargo check,cargo clippyandcargo testbecauseidl-buildis a feature onlyanchor idl buildturns on.Fixed upstream in otter-sec/anchor#4947 (commit
51323eb, 19 Aug 2026), which adds exactly the missing branch:That is not in the
v2.0.0-rc.1tag (12 Aug) and is not on crates.io.Why the workaround is
--no-idland not a dependency patchPatching only the derive crate to the fixed commit was tried and does not resolve:
anchor-derive-accountsonanchor-nextrequiressolana-address 2.7.0, and every program here pins>=2.6, <2.7because anchor-lang 2.0.0-rc.1 is built against wincode 0.5 while solana-address 2.7 moved to 0.6. Cargo fails with a version conflict onsolana-address. The comment inanchor.ymlrecords this so nobody retries it.Skipping IDL generation costs nothing today. None of the eight consumes a generated IDL: no
idls/directory, nodeclare_program!in any Rust source. The program is still compiled to a.soand its tests still run, which is what the workflow is actually checking.The workflow block is marked
TEMPORARY WORKAROUND, says to delete it once a release after 2.0.0-rc.1 ships, and links the upstream PR.The one that was ours
finance/vault-strategywas failing for an unrelated reason:It has
BorshAccount<AssetRate>fields whose type is declared inmock-swap-router, and#[account]only generates the IDL glue when the declaring crate has its ownidl-buildfeature enabled.vault-strategy'sidl-buildwas["anchor-lang/idl-build"]and never forwarded. It now forwards tomock-swap-router/idl-build, with a comment saying why it is required rather than optional.Verified locally with
anchor idl build: that error is gone. It is not in the skip list, so CI will exercise its IDL generation for real.Still outstanding, not addressed here
finance/order-bookcarriesimpl anchor_lang::IdlBuild for OrderTreeRoot {}atordertree.rs:37for a trait v2 removed. It is behind#[cfg(feature = "idl-build")], so nothing compiles it while that project skips IDL generation, but it is dead code that will need the v2 equivalent when the skip is lifted.basics/pythis in the skip list rather than fixed because fixing it properly runs into the same upstream bug: its vendoredPriceUpdateV2needs#[derive(IdlType)], which requires itsverification_level: VerificationLevelfield's enum to be an IDL type too.Generated by Claude Code