|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## What is C2Pool |
| 6 | + |
| 7 | +C2Pool is a modern C++ reimplementation of the decentralized mining pool P2Pool, targeting the V36 share format with support for Litecoin and merged mining (Dogecoin, etc.). It implements a full P2P mining pool with Stratum protocol, PPLNS payouts, VARDIFF, and a web dashboard. |
| 8 | + |
| 9 | +## Build System |
| 10 | + |
| 11 | +**Requirements:** CMake 3.22+, GCC 13, Conan 2.x, C++20 |
| 12 | + |
| 13 | +**System packages (Ubuntu 24.04):** |
| 14 | +```bash |
| 15 | +sudo apt-get install -y g++ cmake make libleveldb-dev libsecp256k1-dev python3-pip |
| 16 | +pip install "conan>=2.0,<3.0" --break-system-packages |
| 17 | +conan profile detect --force |
| 18 | +``` |
| 19 | + |
| 20 | +**Build the main binary:** |
| 21 | +```bash |
| 22 | +mkdir build && cd build |
| 23 | +conan install .. --build=missing --settings=build_type=Debug |
| 24 | +cmake .. --preset conan-debug |
| 25 | +cmake --build . --target c2pool -j$(nproc) |
| 26 | +# Binary: build/src/c2pool/c2pool |
| 27 | +``` |
| 28 | + |
| 29 | +There is also `build-debug.sh` at the repo root as a convenience script. |
| 30 | + |
| 31 | +**Build and run all tests:** |
| 32 | +```bash |
| 33 | +cd build |
| 34 | +cmake --build . --target test_hardening test_share_messages test_coin_broadcaster \ |
| 35 | + test_redistribute_address core_test sharechain_test share_test -j$(nproc) |
| 36 | +ctest --output-on-failure -j$(nproc) |
| 37 | +# Expected: 265 tests passing |
| 38 | +``` |
| 39 | + |
| 40 | +**Run a single test binary:** |
| 41 | +```bash |
| 42 | +cd build && ./test/test_hardening |
| 43 | +cd build && ./src/core/test/core_test |
| 44 | +``` |
| 45 | + |
| 46 | +**Python integration tests** (require a running pool): |
| 47 | +```bash |
| 48 | +cd test && python3 smoke_test.py |
| 49 | +cd test && python3 integration_test.py |
| 50 | +``` |
| 51 | + |
| 52 | +## Architecture |
| 53 | + |
| 54 | +The codebase is split into layered modules under `src/`: |
| 55 | + |
| 56 | +``` |
| 57 | +btclibs/ Bitcoin/crypto primitives (uint256, SHA256, ECDSA, base58, Script) |
| 58 | +core/ Infrastructure: networking (Boost.ASIO), HTTP/Stratum server, |
| 59 | + logging, YAML config, LevelDB wrapper, binary serialization |
| 60 | +pool/ Generic P2P pool protocol (peer connections, message dispatch) |
| 61 | +sharechain/ V36 share format, share chain data structure, LevelDB storage |
| 62 | +impl/ltc/ Litecoin-specific: share validation, V36 authority messages, |
| 63 | + litecoind RPC/P2P client, payout redistribution modes |
| 64 | +c2pool/ Enhanced features + main entry point: |
| 65 | + node/ Enhanced node orchestration (ties all modules together) |
| 66 | + hashrate/ Real-time hashrate tracking |
| 67 | + difficulty/ Per-miner VARDIFF adjustment engine |
| 68 | + storage/ LevelDB sharechain persistence manager |
| 69 | + payout/ PPLNS payout calculation |
| 70 | + merged/ Merged mining support (DOGE, DGB) |
| 71 | +``` |
| 72 | + |
| 73 | +**Dependency direction:** `c2pool` → `impl/ltc` → `pool` + `sharechain` + `core` → `btclibs` |
| 74 | + |
| 75 | +The main entry point is `src/c2pool/c2pool_refactored.cpp`, which parses 100+ CLI arguments, selects an operating mode, and instantiates `EnhancedNode` from `c2pool/node/`. |
| 76 | + |
| 77 | +**Operating modes** (selected by CLI flags): |
| 78 | +- `--integrated` — Full pool: HTTP API + Stratum + P2P sharechain + payouts + web dashboard |
| 79 | +- `--sharechain` — P2P node only (no mining) |
| 80 | +- default — Solo mining (lightweight, no P2P) |
| 81 | + |
| 82 | +## Key Files |
| 83 | + |
| 84 | +| File | Purpose | |
| 85 | +|------|---------| |
| 86 | +| `src/c2pool/c2pool_refactored.cpp` | Main entry point, all CLI argument handling | |
| 87 | +| `src/core/web_server.cpp` | HTTP/JSON-RPC/Stratum server (~2500 LOC) | |
| 88 | +| `src/impl/ltc/share_check.hpp` | Share validation — the most complex file in the repo | |
| 89 | +| `src/impl/ltc/share_messages.hpp` | V36 authority message encryption/decryption | |
| 90 | +| `src/impl/ltc/node.cpp` | LTC pool node orchestration | |
| 91 | +| `src/c2pool/payout/payout_manager.cpp` | PPLNS distribution logic | |
| 92 | +| `src/c2pool/merged/merged_mining.cpp` | Merged mining adapter | |
| 93 | +| `src/core/pack.hpp` | Binary serialization framework used throughout | |
| 94 | + |
| 95 | +## REST API Endpoints |
| 96 | + |
| 97 | +| Endpoint | Description | |
| 98 | +|----------|-------------| |
| 99 | +| `/current_payouts` | Current PPLNS payout distribution by address | |
| 100 | +| `/local_stats` | Local node statistics (peers, hashrates, shares) | |
| 101 | +| `/global_stats` | Pool-wide statistics (pool hashrate, difficulty) | |
| 102 | +| `/miner_thresholds` | Minimum viable hashrate, min payout per share, DUST range | |
| 103 | +| `/recent_blocks` | Recently found blocks | |
| 104 | +| `/connected_miners` | Currently connected stratum workers | |
| 105 | +| `/stratum_stats` | Stratum server statistics | |
| 106 | +| `/sharechain_stats` | Share chain state (height, verified count) | |
| 107 | + |
| 108 | +## Configuration |
| 109 | + |
| 110 | +Configuration priority: CLI args > YAML file (`--config config.yaml`) > env vars > defaults. |
| 111 | + |
| 112 | +See `config/c2pool_testnet.yaml` for a full example. Key defaults: P2P port 9338, Stratum port 9327, HTTP port 8080. |
| 113 | + |
| 114 | +## Dependencies |
| 115 | + |
| 116 | +- **LevelDB** and **libsecp256k1** must be installed system-wide |
| 117 | +- **Boost 1.78** (ASIO, log, thread, filesystem), **nlohmann/json 3.11.3**, **yaml-cpp 0.8.0**, **GTest 1.14.0** are managed via Conan |
| 118 | +- `btclibs/` contains vendored/stripped Bitcoin Core utilities |
| 119 | + |
| 120 | +## CI/CD |
| 121 | + |
| 122 | +GitHub Actions (`.github/workflows/build.yml`) runs on Ubuntu 24.04 with GCC 13. The pipeline installs system deps, runs Conan, builds all targets, and runs `ctest`. Conan package cache is keyed by compiler/build_type. |
0 commit comments