Skip to main content

Module wire_shape

Module wire_shape 

Source
Expand description

Canonical Send / Recv NodeProto shape — the contract every wire-IR-touching pass + runtime gate agrees on.

Wire ops carry a specific NodeProto shape. Centralizing the contract here keeps the DSL emitters, compiler passes, and runtime gates from drifting on string literals or attribute layouts.

This module is the single declarative description of that shape. The DSL emits to it; the compiler passes mutate within it; the runtime consumes it. [crate::verify::wire_shape] checks a ModelProto against the contract.

§The shape

§Send

NodeProto {
    op_type: "Send",
    domain: "ai.bytesandbrains.wire",
    input: [payload_0, payload_1, ..., payload_{N-1}, peer],
    output: [handle],
    attribute: [
        (name: "peer", type: BYTES, t: <PeerId.to_bytes() multihash>),
        (name: "dest_suffix.{name}", type: BYTES, t: <multiaddr-bytes>),
        (name: "deadline_ns", type: INT, i: <i64-ns>),  // optional
    ],
    metadata_props: [
        ("ai.bytesandbrains.wire.wire_id", "<u64>"),
        ("ai.bytesandbrains.wire_transport", "data" | "trigger_only"),
        ("ai.bytesandbrains.batch_group_id", "<u32>"),
        ("ai.bytesandbrains.dest_site_name.{name}", "<recv-site-name>"),
    ],
}

§Recv

NodeProto {
    op_type: "Recv",
    domain: "ai.bytesandbrains.wire",
    input: [],
    output: [received_0, received_1, ..., received_{N-1}, sender],
    metadata_props: [
        ("ai.bytesandbrains.wire.wire_id", "<u64 matching paired Send>"),
        ("ai.bytesandbrains.wire_transport", "data" | "trigger_only"),
    ],
}

wire_id pairs the Send/Recv halves across the cut. wire_transport tells the runtime whether each fill carries a payload (data) or is firing-signal-only (trigger_only).

§Key invariants the contract pins

  • ATTR_PEER is bytes, not i64. The peer attribute on a Send carries the PeerId’s canonical multihash byte form (PeerId::to_bytes()), NOT a u64-collapsed identity hash. The runtime gates parse via PeerId::from_bytes(&attr.t).

  • wire_id is the pairing token. The DSL Graph::wire mints a monotonic u64 and stamps it on BOTH halves; the compiler’s discover_wire_edges pair Send/Recv by it.

  • wire_transport lives on the NodeProto itself. analyze_wire_edges stamps it onto partition.functions[0].node[i].metadata_props in place, so downstream passes and the runtime read a single source of truth.

  • SlotFill.type_hash is populated from the sender side’s T::HASH. Receivers dispatch wire bytes via if envelope.fill.type_hash == T::HASH { T::deserialize(&fill.payload) }.

Re-exports§

pub use crate::syscall_ids::ATTR_PEER;
pub use crate::keys::DEST_SUFFIX_ATTR_PREFIX;
pub use crate::syscall_ids::ATTR_DEADLINE_NS;
pub use crate::keys::WIRE_ID_KEY;
pub use crate::keys::WIRE_TRANSPORT_KEY;
pub use crate::keys::WIRE_TRANSPORT_DATA;
pub use crate::keys::WIRE_TRANSPORT_TRIGGER_ONLY;
pub use crate::keys::DEST_SITE_NAME_PREFIX;

Constants§

OP_RECV
op_type for a Recv node.
OP_SEND
op_type for a Send node.
WIRE_DOMAIN
Wire-op domain. All Send / Recv NodeProtos live under here.

Functions§

is_recv
Return true if the NodeProto is a wire.Recv.
is_send
Return true if the NodeProto is a wire.Send.
read_peer_bytes
Read the destination peer’s multihash bytes from a Send / gate NodeProto. Returns None if the attribute is absent or carries no byte content. The byte payload lives on attribute.s per the ONNX convention for raw bytes (paired with AttributeType::String); callers reconstruct the PeerId via PeerId::from_bytes(read_peer_bytes(node)?).
read_wire_id
Read the wire_id metadata stamp from a Send or Recv node. Returns None if the key is absent or non-numeric.
stamp_peer_bytes
Stamp the destination peer onto a Send / gate NodeProto’s attribute.s (bytes) using the canonical multihash form. Used by the compiler’s gate-insertion passes and any pass synthesizing new Send NodeProtos.
stamp_wire_transport
Stamp the WIRE_TRANSPORT_KEY classification onto a wire-op NodeProto’s metadata_props (idempotent: replaces an existing value).