Skip to content

Stratum v1 mining server core#102

Open
Boblepointu wants to merge 23 commits into
doged-io:masterfrom
FrenchBTC:pr/stratum-core
Open

Stratum v1 mining server core#102
Boblepointu wants to merge 23 commits into
doged-io:masterfrom
FrenchBTC:pr/stratum-core

Conversation

@Boblepointu
Copy link
Copy Markdown

@Boblepointu Boblepointu commented Apr 16, 2026

Summary

Embedded Stratum v1 mining server for doged, enabling pool-less solo mining directly from the node.

This is the foundational PR — later PRs will add upstream proxy routing, AuxPoW merge-mining RPCs, and multi-chain support on top.

What's included

Layer Files Description
Protocol stratumprotocol.{h,cpp} Stratum JSON-RPC message types, line-buffered parser, serializers
Config stratumconfig.{h,cpp} -stratum, -stratumbind, -stratumport, -stratumpassword, -stratumdiff, -coinbaseaddr CLI args
Worker stratumworker.{h,cpp} Per-connection session state machine: subscribe → authorize → mining, variable difficulty retarget
Job stratumjob.{h,cpp} Job manager: polls getblocktemplate, splits coinbase for extranonce, builds merkle branches
Submit stratumsubmit.{h,cpp} Share validation via scrypt PoW hash, duplicate detection, difficulty check
Stats stratumstats.{h,cpp} Connection count, hashrate estimate, accepted/rejected share counters, JSON formatter
Server stratum.{h,cpp} libevent TCP listener, accept/read/dispatch loop, thread-safe worker management
Lifecycle init.cpp Start/stop stratum in the node init sequence (after chainstate is loaded)
Logging logging.{h,cpp} BCLog::STRATUM category
Build CMakeLists.txt Compile stratum modules into libserver, wire Boost unit test suite
Unit tests src/stratum/test/*.cpp Protocol parsing, config edge cases, worker lifecycle, job creation, share validation, stats output
Functional test stratum_basic.py End-to-end: start node with -stratum=1, TCP connect, subscribe, authorize

Architecture

┌─────────────────────────────────┐
│           doged node            │
│  ┌───────────────────────────┐  │
│  │     StratumServer         │  │
│  │  libevent TCP :9334       │  │
│  │  ┌─────────────────────┐  │  │
│  │  │  StratumWorker[]    │  │  │
│  │  │  subscribe/auth/    │  │  │
│  │  │  vardiff/sessions   │  │  │
│  │  └────────┬────────────┘  │  │
│  │           │               │  │
│  │  ┌────────▼────────────┐  │  │
│  │  │  StratumJobManager  │  │  │
│  │  │  getblocktemplate   │  │  │
│  │  │  coinbase split     │  │  │
│  │  │  merkle branches    │  │  │
│  │  └────────┬────────────┘  │  │
│  │           │               │  │
│  │  ┌────────▼────────────┐  │  │
│  │  │  ValidateShare()    │  │  │
│  │  │  scrypt PoW check   │  │  │
│  │  │  submitblock on hit │  │  │
│  │  └─────────────────────┘  │  │
│  └───────────────────────────┘  │
└─────────────────────────────────┘

Usage

doged -stratum=1 -stratumport=9334 -coinbaseaddr=DYourDogeAddress

Follow-up PRs (stacked)

  • PR2: Upstream proxy connector + tiered routing (local → proxy → failover)
  • PR3: AuxPoW merge-mining RPCs (createauxblock, submitauxblock)
  • PR4: Multi-chain merge-mine manager with pluggable IAuxChainModule
  • PR5: Independent per-chain target checking + AuxPoW proof construction

Test plan

  • ninja check-stratum — 6 Boost unit test suites pass
  • test/functional/stratum_basic.py — e2e subscribe + authorize
  • Manual: start doged with -stratum=1, connect with any Stratum v1 miner, verify jobs received
  • Verify no regressions: ninja check on existing test suites

Comment thread src/stratum/stratum.cpp
Comment thread src/stratum/stratum.cpp
Comment thread src/init.cpp Outdated
Comment thread test/functional/stratum_basic.py Outdated
Comment thread src/rpc/mining.cpp Outdated
- Remove unrelated copyright header from src/rpc/mining.cpp
- Replace flaky time.sleep(1) with wait_until on debug log in stratum test
- Move stratum config log from AppInitServers to InitStratumServer call site
- Add AssertLockHeld(m_cs) in HandleSubmit for thread-safety sanity
- Add WIN32 compat for evthread (match httpserver.cpp pattern)
- Replace POSIX socket headers with compat.h for cross-platform builds

Made-with: Cursor
- Introduced a new HTML file for visualizing the dependency graph of pull requests.
- Implemented a responsive design with SVG elements to represent PR statuses (open, ready, queued, draft).
- Added a legend to explain the color coding of PR states.

This visualization aids in understanding the current state of pull requests in the project.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants