cleanup: add explicit callconv(.c) to all extern fn FFI declarations in ethlibp2p.zig
- Dominant language
- Zig
- Stars
- 97
- Forks
- 39
- PR merge metrics
- No merged PRs in 30d
Description
## Context
PR #743 fixed the x86_64 GPF by adding `extern "C"` to the Rust side of the Zig→Rust FFI boundary. While reviewing that PR, an inconsistency was noticed on the Zig side.
## Issue
In `pkgs/network/src/ethlibp2p.zig`, the `pub extern fn` FFI declarations are inconsistent — some have explicit `callconv(.c)`, others do not:
```zig
// No explicit callconv — relies on extern fn defaulting to C ABI
pub extern fn create_and_run_network(...) void;
pub extern fn wait_for_network_ready(...) bool;
pub extern fn publish_msg_to_rust_bridge(...) void;
// Explicit callconv(.c)
pub extern fn send_rpc_request(...) callconv(.c) u64;
pub extern fn send_rpc_response_chunk(...) callconv(.c) void;
pub extern fn send_rpc_end_of_stream(...) callconv(.c) void;
pub extern fn send_rpc_error_response(...) callconv(.c) void;
```
## Why it matters
In Zig, `pub extern fn` defaults to C calling convention, so this is **not a bug today**. However:
- It is a maintenance hazard — a future reader may not know which functions have been audited for ABI correctness
- It is inconsistent with the established pattern in the same file
- Given that an ABI mismatch on this exact boundary just caused a production GPF (#743), explicit annotations serve as documentation that the ABI contract was intentionally verified
## Fix
Add `callconv(.c)` to all `pub extern fn` declarations in `pkgs/network/src/ethlibp2p.zig` that are missing it:
```zig
pub extern fn create_and_run_network(...) callconv(.c) void;
pub extern fn wait_for_network_ready(...) callconv(.c) bool;
pub extern fn publish_msg_to_rust_bridge(...) callconv(.c) void;
```
While at it, audit other FFI boundary files (e.g. `pkgs/xmss/`, `pkgs/key-manager/`) for the same inconsistency.
## References
- PR #743 (root cause: missing `extern "C"` on Rust side)
- `pkgs/network/src/ethlibp2p.zig` lines ~915–947
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in pkgs/network/src/ethlibp2p.zig around lines 915–947 and review every pub extern fn declaration against the existing callconv(.c) pattern. Then audit the FFI boundary files under pkgs/xmss/ and pkgs/key-manager/ for the same inconsistency. Done means the missing declarations have explicit callconv(.c) annotations and the affected FFI files are consistently documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- zig
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100