Mempool Architecture Diagram
This diagram illustrates the architecture of the Zebra mempool, showing its main components and the flow of transactions through the system.
graph TD
%% External Components
Net[Network Service]
State[State Service]
TxVerifier[Transaction Verifier]
RPC[RPC Service]
%% Mempool Main Components
Mempool{{Mempool Service}}
Storage{{Storage}}
Downloads{{Transaction Downloads}}
Crawler{{Crawler}}
QueueChecker{{Queue Checker}}
%% Transaction Flow
Net -->|1- Poll peers| Mempool
RPC -->|1- Direct submit| Mempool
Crawler -->|1- Poll peers| Net
Crawler -->|2- Queue transactions| Mempool
Mempool -->|3- Queue for download| Downloads
Downloads -->|4a- Download request| Net
Net -->|4b- Transaction data| Downloads
Downloads -->|5a- Verify request| TxVerifier
TxVerifier -->|5b- Verification result| Downloads
Downloads -->|6a- Check UTXO| State
State -->|6b- UTXO data| Downloads
Downloads -->|7- Store verified tx| Storage
QueueChecker -->|8a- Check for verified| Mempool
Mempool -->|8b- Process verified| QueueChecker
Storage -->|9- Query responses| Mempool
Mempool -->|10- Gossip new tx| Net
%% State Management
State -->|Chain tip changes| Mempool
Mempool -->|Updates verification context| Downloads
%% Mempool responds to service requests
RPC -->|Query mempool| Mempool
Mempool -->|Mempool data| RPC
%% Styling
classDef external fill:#444,stroke:#888,stroke-width:1px,color:white;
classDef component fill:#333,stroke:#888,stroke-width:1px,color:white;
class Net,State,TxVerifier,RPC external;
class Mempool,Storage,Downloads,Crawler,QueueChecker component;
Component Descriptions
-
Mempool Service: The central coordinator that handles requests and manages the mempool state.
-
Storage: In-memory storage for verified transactions and rejection lists.
-
Transaction Downloads: Handles downloading and verifying transactions from peers.
-
Crawler: Periodically polls peers for new transactions.
-
Queue Checker: Regularly polls for newly verified transactions.
Transaction Flow
-
Transactions arrive via network gossiping, direct RPC submission, or crawler polling.
-
The mempool checks if transactions are already known or rejected. If not, it queues them for download.
-
The download service retrieves transaction data from peers.
-
Transactions are verified against consensus rules using the transaction verifier.
-
Verified transactions are stored in memory and gossiped to peers.
-
The queue checker regularly checks for newly verified transactions.
-
Transactions remain in the mempool until they are mined or evicted due to size limits.
-
When the chain tip changes, the mempool updates its verification context and potentially evicts invalid transactions.