feat: support Codama root-node IDLs and variable discriminators#114
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR adds Codama
Confidence Score: 5/5The change is safe to merge. All correctness concerns raised in earlier review rounds have been addressed — discriminant extraction now errors on missing defaults, account discriminator lookups return errors when the map is non-empty but an account is absent, and both parser errors are surfaced together. Resolver mutations are still combined with primary mutations in a single batch before emission. The IDL parsing, macro codegen, and runtime changes are well-structured, each new code path is covered by targeted tests, and the previous blocking concerns have been resolved. The embedded-discriminator heuristic is sound for Steel/Codama naming conventions, and the gRPC backoff and resolver semaphore additions improve resilience without introducing new data-path risks. arete-macros/src/codegen/vixen_runtime.rs — largest surface area of new generated runtime code; worth a second read on the ManagedYellowstoneGrpcSource SourceTrait implementation and the async_resolver_order counter lifetime. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[parse_idl_content] -->|try| B[serde_json: IdlSpec]
B -->|Ok| C[IdlSpec returned]
B -->|Err: IdlSpec error| D[try Codama fallback]
D -->|serde_json: CodamaRoot| E{kind == rootNode?}
E -->|No| F[Return error]
E -->|Yes| G[Extract accountDiscriminator\nfrom defined_types]
G --> H[codama_account_to_idl\nfor each account]
G --> I[codama_instruction_to_idl\nfor each instruction]
G --> J[codama_defined_type_to_idl\nfor each defined type]
H --> K[Lookup discriminator\nfrom HashMap]
K -->|found| L[vec discriminator byte]
K -->|not found, map non-empty| M[Return Err - missing variant]
K -->|map empty| N[vec empty - Anchor fallback]
I --> O[Find discriminator arg\nwith numberValueNode default]
O -->|found| P[SteelDiscriminant with value]
O -->|missing default| Q[Return Err - cannot determine]
L & P & J --> R[IdlSpec assembled]
D -->|Err: Codama error| S[Both errors surfaced]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[parse_idl_content] -->|try| B[serde_json: IdlSpec]
B -->|Ok| C[IdlSpec returned]
B -->|Err: IdlSpec error| D[try Codama fallback]
D -->|serde_json: CodamaRoot| E{kind == rootNode?}
E -->|No| F[Return error]
E -->|Yes| G[Extract accountDiscriminator\nfrom defined_types]
G --> H[codama_account_to_idl\nfor each account]
G --> I[codama_instruction_to_idl\nfor each instruction]
G --> J[codama_defined_type_to_idl\nfor each defined type]
H --> K[Lookup discriminator\nfrom HashMap]
K -->|found| L[vec discriminator byte]
K -->|not found, map non-empty| M[Return Err - missing variant]
K -->|map empty| N[vec empty - Anchor fallback]
I --> O[Find discriminator arg\nwith numberValueNode default]
O -->|found| P[SteelDiscriminant with value]
O -->|missing default| Q[Return Err - cannot determine]
L & P & J --> R[IdlSpec assembled]
D -->|Err: Codama error| S[Both errors surfaced]
Reviews (10): Last reviewed commit: "fix: surface errors for unsupported Coda..." | Re-trigger Greptile |
…lent fallbacks - Include Codama parse error alongside IdlSpec error in fallback message (was discarded by |_| closure, leaving users with misleading errors) - Error when a Codama account is missing from a non-empty accountDiscriminator map instead of silently falling back to an unmatchable 8-byte Anchor hash - Error when a discriminator argument lacks a numeric default_value instead of silently leaving discriminant=None, which could cause discriminant collisions in generated parsers - Add #[serde(other)] Unknown catch-all variants to CodamaTypeNode and CodamaCountNode so unmodelled node kinds produce clear unsupported errors instead of opaque deserialization failures
Summary
rootNodeIDLs inarete-idlIdlSpecarete-a4-sdkchanges formatting-onlyWhy
Some Steel/Codama-generated IDLs are emitted as Codama root-node JSON rather than the legacy format
arete-idlexpects today. Those IDLs also use discriminator patterns that are not always 8-byte Anchor-style discriminators. This branch teaches the IDL layer and generated parsers to accept those layouts without regressing the existing path.What Changed
arete-idlparse_idl_contentnow falls back to deserializing a Codama root node when directIdlSpecparsing failsIdlSpecaccountDiscriminatorenum when presentdiscriminatorargument default value and removes that field from emitted argsspec: "codama"andorigin: "codama-rootNode"arete-macrosstarts_with(...)instead of assuming an 8-byte discriminator slicerust/arete-a4-sdkConstraints
arete-idlonly models fieldless enums todayaccountDiscriminatorTesting
cargo test -p arete-idl -p arete-macros -p arete-a4-sdk