Add Rust ABI support for WASM subgraphs#6462
Add Rust ABI support for WASM subgraphs#6462cargopete wants to merge 6 commits intographprotocol:masterfrom
Conversation
- Add Ethereum ToRustBytes impl for Log/Call/Block triggers - Add NEAR ToRustBytes stub (unimplemented, Ethereum-only for now) - Propagate ToRustBytes trait bounds through instance_manager - Skip parity_wasm gas injection for Rust modules (can't parse bulk-memory opcodes) - Skip AS-specific exports (id_of_type, _start) for Rust modules - Add handle_trigger_rust and invoke_handler_rust calling convention - Add Rust host function wrappers in module/context.rs
|
Can you explain a bit what the motivation for this is? Another ABI is a huge commitment in terms of maintenance etc. If another ABI is called for, it would be good to also see if we can avoid some of the mistakes the current ASC ABI makes. |
|
@lutter ▎ Thanks for the feedback! Motivation Meanwhile The Graph has already validated Rust→WASM as a first-class path with Substreams. A Rust mapping language is the natural extension of that investment to the subgraph layer — same WASM runtime, same graph-node infrastructure, just a different serialization boundary. Maintenance argument What we tried to learn from the ASC ABI's mistakes
Happy to discuss any of these design choices further, or to write a formal docs/rust-abi-spec.md or a forum post if that would help the review. |
Summary
Adds support for Rust-compiled WASM subgraphs as an alternative to AssemblyScript. This introduces a new
rust_abi/module parallel to the existingasc_abi/, with a clean ptr+len FFI protocol and TLV entity serialization.rust_abi/module (~1,450 LOC) —ToRustWasm/FromRustWasmtraits, TLV entity serialization, trigger serialization (RustLogTrigger/RustCallTrigger/RustBlockTrigger), and all host function linker wrappers (store, crypto, logging, data sources, IPFS, ethereum calls) with async + gas meteringis_rust_module()detects "graphite" namespace imports;MappingLanguageenum stored onValidModulebuild_linker()branches on language;handle_trigger_rust()uses Rust calling convention (allocate → write bytes → call handler(ptr, len) → reset_arena)parity_wasmgas injection for Rust modules (parity_wasm can't parse modern WASM features like bulk-memory); skips AS-specific exports (id_of_type,_start)ToRustBytesimpl for all 3 trigger types (Log, Call, Block)Live-tested
Deployed an ERC20 subgraph (compiled with Graphite SDK) to this fork, indexing real USDC Transfer events from Ethereum mainnet. Full pipeline verified: block ingestion → event scanning → Rust WASM handler → entity storage → correct GraphQL query results.
Architecture
Known gaps (not blocking review)
unimplemented!(Ethereum-only for now)Test plan