22
33## Changelog
44
5+ * 2025-12-21: Added Malachite internal architecture analysis and channel extensibility
56* 2025-12-07: Initial draft
67
78## Status
@@ -67,10 +68,114 @@ Use Malachite's native networking implementation.
6768- Seamless integration with Malachite consensus engine
6869- Consistent ecosystem (same maintainers)
6970- Already handles consensus message types
71+ - Uses libp2p internally (battle-tested transport layer)
72+ - Production validated (Arc/Circle blockchain uses Malachite)
7073
7174** Cons:**
72- - Less feature-rich than libp2p
7375- Tied to Malachite release cycle
76+ - Must extend Channel enum for custom message types
77+
78+ ## Malachite Internal Architecture
79+
80+ Investigation of the Malachite codebase reveals that it uses libp2p internally, providing the benefits of a battle-tested networking stack while offering a BFT-optimized API.
81+
82+ ### Transport Layer
83+
84+ Malachite's network layer (` malachitebft-network ` ) is built on top of libp2p:
85+
86+ ```
87+ ┌─────────────────────────────────────────────────────────────┐
88+ │ Malachite Network API │
89+ │ (BFT-optimized, channel-based) │
90+ ├─────────────────────────────────────────────────────────────┤
91+ │ libp2p Stack │
92+ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
93+ │ │ GossipSub │ │ Kademlia │ │ Identify/Ping │ │
94+ │ │ (pubsub) │ │ (DHT) │ │ (peer discovery) │ │
95+ │ └─────────────┘ └─────────────┘ └─────────────────────┘ │
96+ ├─────────────────────────────────────────────────────────────┤
97+ │ Transport Layer │
98+ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
99+ │ │ TCP/QUIC │ │ Noise │ │ Yamux │ │
100+ │ │ (transport) │ │ (encryption)│ │ (multiplexing) │ │
101+ │ └─────────────┘ └─────────────┘ └─────────────────────┘ │
102+ └─────────────────────────────────────────────────────────────┘
103+ ```
104+
105+ ### Channel System
106+
107+ Malachite uses a channel-based message routing system. Each channel maps to a separate GossipSub topic:
108+
109+ ``` rust
110+ // From malachite/code/crates/network/src/channel.rs
111+ pub enum Channel {
112+ /// Consensus messages (Proposal, Vote, Timeout)
113+ Consensus ,
114+ /// Liveness messages (protocol-specific)
115+ Liveness ,
116+ /// Proposal parts (for large proposals)
117+ ProposalParts ,
118+ /// State synchronization
119+ Sync ,
120+ }
121+ ```
122+
123+ ### Channel Extensibility for DCL
124+
125+ The Channel enum can be extended to support CipherBFT's DCL messages. This enables independent communication channels for different message types:
126+
127+ ``` rust
128+ /// Extended channel enum for CipherBFT (conceptual)
129+ pub enum CipherBftChannel {
130+ // Malachite built-in channels
131+ Consensus ,
132+ Liveness ,
133+ ProposalParts ,
134+ Sync ,
135+
136+ // CipherBFT DCL extensions
137+ DclCars , // Car broadcast and propagation
138+ DclAttestations , // Attestation collection
139+ WorkerBatches , // Worker-to-Worker batch sync
140+ TransactionGossip , // Transaction mempool gossip
141+ }
142+ ```
143+
144+ Each custom channel operates as an independent GossipSub topic, ensuring:
145+ - ** Isolation** : DCL traffic doesn't interfere with consensus messages
146+ - ** Priority** : Different channels can have different QoS settings
147+ - ** Scalability** : Channels can be subscribed/unsubscribed independently
148+
149+ ### Message Format
150+
151+ Messages in Malachite are opaque byte buffers. Serialization/deserialization (codec) is handled at the application layer:
152+
153+ ``` rust
154+ // Network layer deals with raw bytes
155+ pub struct NetworkMessage {
156+ pub channel : Channel ,
157+ pub data : Bytes , // Opaque payload
158+ }
159+
160+ // Application layer handles encoding
161+ impl DclMessage {
162+ pub fn encode (& self ) -> Bytes {
163+ bincode :: serialize (self ). unwrap (). into ()
164+ }
165+
166+ pub fn decode (data : & [u8 ]) -> Result <Self , Error > {
167+ bincode :: deserialize (data )
168+ }
169+ }
170+ ```
171+
172+ ### Production Validation
173+
174+ Malachite is used in production by [ Arc] ( https://www.circle.com/arc ) , Circle's blockchain platform. This provides real-world validation of:
175+ - Network stability under load
176+ - Peer discovery and management
177+ - Message propagation reliability
178+ - Integration with BFT consensus
74179
75180## Decision
76181
@@ -375,17 +480,20 @@ N/A - greenfield implementation.
3754803 . ** Seamless integration** : Works naturally with Malachite consensus
3764814 . ** Reduced complexity** : No need to bridge libp2p with Malachite
3774825 . ** Maintained together** : Networking and consensus evolve together
483+ 6 . ** Battle-tested transport** : Uses libp2p internally (TCP/QUIC, Noise, Yamux)
484+ 7 . ** Production validated** : Arc/Circle blockchain uses Malachite in production
485+ 8 . ** Channel extensibility** : Custom channels can be added for DCL messages
378486
379487### Negative
380488
381- 1 . ** Less feature-rich ** : Fewer features than libp2p (no QUIC, limited NAT traversal)
382- 2 . ** Smaller community** : Less documentation than libp2p
383- 3 . ** Coupled release ** : Must update with Malachite versions
489+ 1 . ** Coupled release ** : Must update with Malachite versions
490+ 2 . ** Smaller community** : Less documentation than raw libp2p
491+ 3 . ** Channel extension effort ** : Requires forking or contributing to Malachite for custom channels
384492
385493### Neutral
386494
387- 1 . ** TCP-based ** : Uses TCP (not QUIC) - adequate for validator networks
388- 2 . ** Learning curve ** : Must understand Malachite's networking model
495+ 1 . ** Learning curve ** : Must understand Malachite's channel-based networking model
496+ 2 . ** Abstraction trade-off ** : Higher-level API than raw libp2p (less control, more convenience)
389497
390498## Test Cases
391499
@@ -403,3 +511,6 @@ N/A - greenfield implementation.
403511* [ Malachite GitHub] ( https://github.com/informalsystems/malachite )
404512* [ Malachite Documentation] ( https://malachite.informal.systems )
405513* [ malachitebft-network crate] ( https://crates.io/crates/informalsystems-malachitebft-network )
514+ * [ Arc by Circle] ( https://www.circle.com/arc ) - Production blockchain using Malachite
515+ * [ libp2p] ( https://libp2p.io/ ) - Underlying transport layer used by Malachite
516+ * [ Malachite Network Channel Source] ( https://github.com/informalsystems/malachite/blob/main/code/crates/network/src/channel.rs ) - Channel enum definition
0 commit comments