Expand description
§dig-peer-protocol
The DIG Network peer wire — a native protocol, plus the narrow chia surface a DIG node needs to also speak to chia full nodes.
§The native DIG wire
DigMessage is the envelope for every DIG message: a raw u8 opcode, an optional
correlation id, and a Bytes payload, encoded by this crate and nothing else. It carries
the 200..=222 DIG opcode band, which chia_protocol::Message structurally cannot express —
its ProtocolMessageTypes is a closed #[repr(u8)] enum with no Unknown(u8), so a DIG
opcode is neither constructible nor decodable through it, and one inbound DIG frame drops a
whole chia-sdk-client connection rather than that one frame.
DIG answered that with vendored forks of chia-protocol and chia-sdk-client. This crate
replaces the forks: DigLink is a websocket peer link written directly against the wire
format, and the DIG types it carries — Bytes, NodeType, DigMessage,
DigMessageType, RegisterPeer, RegisterAck — are DIG’s own.
§What is deliberately still chia, and why
Decoupling from chia-protocol is not the same as decoupling from every crate whose name
starts with chia. Two are kept ON PURPOSE. Do not “finish the decoupling” by removing
them — they were assessed and retained:
chia-traits(Streamable) andchia_streamable_macro(streamable) — a serialization trait and a derive macro. Neither has the property this crate is escaping: there is no closed enum and no private-field wire authority in either. They serialize the bodies of DIG messages, and they do it with an encoding that is already live on the network. Replacing them would mean owning a serializer — new surface, and a fresh byte-identity risk — to buy nothing that matters.chia-protocol’sChiaProtocolMessageandTimestampedPeerInfo, andchia-sdk-client— these serve genuine chia traffic. A DIG node talks to chia full nodes too:DigLink’s typedsend/requestderive a chia opcode fromChiaProtocolMessage,RespondPeersIntroduceris chia opcode 64, andOpcodeRateLimitsre-keys chia’s own published rate-limit table so a chia opcode is limited exactly as a stock peer would limit it. Chia types for chia traffic is the design, not a leftover.
There is no blanket pub use chia_protocol::*. A glob re-export is how chia types reach
consumers that never asked for them, and it made a chia version bump a breaking change to
every downstream crate. What a chia-full-node path needs is named explicitly below.
§Feature flags
| Flag | Forwards to | Effect |
|---|---|---|
native-tls | chia-sdk-client/native-tls | OS-native TLS; enables Client, ClientState, Connector, create_native_tls_connector, DigLink::connect |
rustls | chia-sdk-client/rustls | Pure-Rust TLS; enables Client, ClientState, Connector, create_rustls_connector, DigLink::connect |
Neither is enabled by default. Without one, the TLS-dependent items above are unavailable;
DigLink::from_websocket and DigLink::from_server_websocket stay available, since
adopting an already-established socket needs no TLS backend of its own.
Structs§
- Bytes
- A length-prefixed byte payload.
- Chia
Certificate - DigLink
- A live websocket link to one peer, framing every message as a
DigMessage. - DigMessage
- The DIG peer envelope: a raw
u8opcode, an optional correlation id, and a payload. - Link
Options - Tunables for a single link.
- Network
- Opcode
Rate Limiter - A sliding-window outbound limiter over
OpcodeRateLimits. - Opcode
Rate Limits - Chia’s
V2_RATE_LIMITS, re-keyed fromProtocolMessageTypesto the wire byte. - Peer
- Peer
Options - Rate
Limit - Rate
Limiter - Rate
Limits - Register
Ack - Introducer acknowledgement.
success == falseis a valid wire outcome (policy rejection). - Register
Peer - Registration request: advertise this node’s P2P reachability to the introducer.
- Request
Peers Introducer - Empty introducer “get peers” request (protocol opcode 63).
- Respond
Peers Introducer - Introducer peer list response (protocol opcode 64).
- Timestamped
Peer Info - Unknown
DigMessage Type - Error returned by
TryFrom<u8>when the wire value is not a known DIG discriminant. - Unknown
Node Type - A wire byte that names no
NodeType.
Enums§
- Admission
- The verdict on one outbound message.
- Client
Error - DigMessage
Type - DIG L2 wire discriminants (
200..=219) extending Chia’s protocol namespace. - Link
Error - Everything that can go wrong on a DIG peer link.
- Node
Type - The service role a peer declares. One byte on the wire.
- Protocol
Message Types
Constants§
- ALL_
DIG_ OPCODES - Every opcode DIG has assigned, ascending — the 20 consensus opcodes plus the 3 free-band ones.
- DIG_
BAND_ START - First opcode of the DIG band. Everything below this belongs to Chia.
- DIG_
MESSAGE - Wire opcode for a directed dig-message envelope (WU6, epic #796).
- FREE_
BAND_ START - First opcode of the free half of the DIG band — application protocols, not L2 consensus.
- HOLDINGS_
ANNOUNCE - Wire opcode for a holdings-announce broadcast (#1428, spec #1394).
- STORE_
MELTED - Wire opcode for a store-melted broadcast (epic #1316).
Statics§
Traits§
Functions§
- is_
dig_ opcode - Whether
opcodebelongs to the DIG band rather than Chia’s namespace. - load_
ssl_ cert - Loads an SSL certificate, or creates it if it doesn’t exist already.