Skip to content

Route module IPC replies and events through one reader - #73

Merged
secsovereign merged 1 commit into
BTCDecoded:mainfrom
keegreil:codex/module-ipc-dispatch
Nov 22, 2026
Merged

secsovereign merged 1 commit into
BTCDecoded:mainfrom
keegreil:codex/module-ipc-dispatch

Conversation

@keegreil

Copy link
Copy Markdown
Contributor

Problem

In beta.6, ModuleIntegration starts a background receiver that holds the IPC client mutex while waiting for a frame. A module API call can then wait indefinitely on an idle connection. If a call does get the mutex, its synchronous request path assumes the next frame is the reply. An ordinary block-event burst interleaves events and replies, producing Received unexpected message type and response correlation mismatches. We observed this when blvm-zmq fetched blocks for rawblock; see BTCDecoded/blvm-zmq#1 for the complementary module startup and wire-framing fixes.

Change

After the existing handshake and CLI registration, a single task owns the session. It routes replies to the outstanding request by correlation ID, broadcasts events, and forwards invocations without waiting on the invocation handler before reading again. Request and invocation queues are bounded. The wire format, handshake, permissions, and direct synchronous client remain unchanged.

Verification

  • Four focused native IPC tests passed, including a Unix-socket regression for an event arriving in front of its request's reply and a request starting on an idle session.
  • Rebuilt the ZMQ v0.1.7 candidate from Fix remaining v0.1.7 ZMQ startup and hashblock delivery issues blvm-zmq#1 against this library and ran it under the unmodified beta.6 node. The BLVM/SRI/GridPool regtest passed all 41 checks. GridPool received both hashblock and rawblock with sequence 102 for the same SV2-mined tip, and validated the header from the raw notification. Transaction topics were disabled for this block-notification test.
  • No Windows runtime test was run.

The separate manifest-grant issue for ReadMempool is not addressed here.

@secsovereign secsovereign left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Direction is right. This is the node-side fix for the GridPool ZMQ path where an interleaved Event before a Response blew up correlation / unexpected message type, and where a background reader held the client mutex so concurrent NodeAPI calls stalled. One session owner demuxing by correlation ID is the correct shape.

Clippy / Format / Docs / Fuzz / Verify / Frozen paths are green. The red checks break down as follows.

Must-fix before merge (this PR)

  1. Conventional Commits — subject Route module IPC replies and events through one reader fails the checker. Re-title / amend to something like fix(module): route IPC replies and events through one reader.
  2. Test — sole failure is the new unit test:
    module::ipc::session::tests::routes_event_before_response_and_keeps_idle_session_writable
    Panic at session.rs:95:
    UnixListener::bind → InvalidInput: path must be shorter than SUN_LEN
    Runner tempfile paths are longer than sockaddr_un. Bind under a short path (e.g. /tmp/blvm-ipc-XXXX.sock or a short tempfile name), not tempdir()/module.sock.

Pre-existing on main (not introduced here, but blocks CI)

  1. Security / cargo-deny — hard-fail on url 2.5.8 → RUSTSEC-2026-0592 (Url::origin() stack overflow on nested blob:). Fix is cargo update -p url (≥2.5.9) on main (or a tiny follow-up). Unmaintained advisories (bincode, chrono, …) are warnings only; the hard fail is url.

Design notes (non-blocking)

  • One outstanding request (pending) is a deliberate serialization of the session; fine for modules, worth a one-line comment so nobody “optimizes” it into a map without thinking about write ordering.
  • Invocation backpressure at 32 + try_send → error result is good; same for dropping events when no subscribers.
  • Windows client still mutex-gated; OK for now given unix is the native module path.

Merge posture

Approve the design once (1)+(2) are fixed and either url is bumped on main or this branch picks up that lock bump. Stack with #75 (grants → instance id) after this lands; pair with BTCDecoded/blvm-zmq#1 / 0.1.7 for the module binary rebuild against 0.1.104 IPC.

@secsovereign
secsovereign merged commit 3f329dd into BTCDecoded:main Nov 22, 2026
13 of 18 checks passed
secsovereign pushed a commit that referenced this pull request Nov 22, 2026
Register nonempty capability lists on the issued session id so hub
authz matches the running module (fixes ReadMempool deny for ZMQ).
Subscribe only after a successful response; revoke grants on teardown.

Depends on the session demux from #73.
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.

2 participants