How btccom/bccpool works
This project is the legacy branch of BTCPool for Bitcoin Cash – a backend system for managing a cryptocurrency mining pool. The pool backend is designed to handle mining work for Bitcoin Cash (and by extension Bitcoin and similar SHA256 coins in the newer version), and it integrates closely with external systems like Bitcoind (via ZMQ), Zookeeper, Kafka, and MySQL. Given its purpose as a high-performance and scalable pool backend, the system is composed of numerous specialized components that interact through message queues and network communication.
Main Components
• External Dependencies:
• Bitcoind: A Bitcoin Cash (and related coin) node that provides blockchain data through its ZMQ interface.
• Zookeeper: For coordination and configuration management.
• Kafka: Used as the messaging backbone for transmitting mining tasks and results.
• MySQL: Likely used for storing state, statistics, and pool-related information.
• Docker Containers: Various Docker configurations (found in the “docker” directory) indicate the deployment environment of different Bitcoind versions and pool configurations.
• Core Backend Services (located under the “src” directory):
• BlockMaker (src/blkmaker): Responsible for constructing valid blocks.
• GbtMaker (src/gbtmaker): Produces “getblocktemplate” messages for miners.
• JobMaker (src/jobmaker): Creates mining jobs based on incoming data.
• NMCAuxMaker (src/nmcauxmaker): Likely handles auxiliary proof-of-work for merged mining.
• Stratum Server and Stratum-related modules (src/sserver, src/Stratum*): Handle miner connections through the stratum protocol.
• PoolWatcher (src/poolwatcher): Monitors pool performance, health, or operational data.
• ShareLogger (src/sharelogger): Logs miner shares.
• Simulator (src/simulator): As described in the README for testing; simulates numerous miners.
• Additional utilities and modules (e.g., Statistics, Zookeeper integration (src/Zookeeper.cc), Kafka integration (src/Kafka.cc), and others).
Relationships and Interactions
• Data Flow:
• Bitcoind streams block and transaction data via ZMQ.
• Incoming blockchain data is processed by components such as BlockMaker and GbtMaker, which then formulate mining tasks.
• JobMaker distributes these tasks through Kafka, ensuring decoupling between services.
• The Stratum Server communicates mining job information to connected miners (including through BtcAgent – the pool’s custom stratum proxy referenced in the README).
• Results (shares) from the miners are captured by the ShareLogger and fed back into the system (possibly stored in MySQL and monitored by PoolWatcher).
• Control Flow:
• Zookeeper is used for service coordination and possibly for dynamic configuration, ensuring services are synchronized in a distributed environment.
• Each backend service (indicated by separate executables/config files in the src directory) is responsible for a single aspect of the mining pool workflow.
Architectural Patterns and Design Principles
• Modular and Microservices-Like Design:
• The separation into distinct executables (block maker, job maker, etc.) suggests modularization where each component handles a dedicated function.
• Message-driven Communication:
• The integration with Kafka implies that many interactions between modules occur through asynchronous message passing.
• External Dependency Integration:
• Usage of Zookeeper for configuration/coordination and Bitcoind for blockchain information exemplify how the system interacts with other critical components.
• Deployment and Configuration:
• The presence of numerous Dockerfiles indicates containerized deployment, which is useful for scalability and reproducibility.
Final Recommendations
• Incorporate annotations where necessary to explain the use of external systems like Kafka and Zookeeper.