Implement Stratum V2 protocol support#111
Open
warioishere wants to merge 3 commits intoblitzpool-masterfrom
Open
Implement Stratum V2 protocol support#111warioishere wants to merge 3 commits intoblitzpool-masterfrom
warioishere wants to merge 3 commits intoblitzpool-masterfrom
Conversation
4f15445 to
559c4a6
Compare
7 tasks
9384412 to
f74d703
Compare
Implement the complete Stratum V2 mining protocol stack alongside the existing Stratum V1 infrastructure, enabling miners to connect via either protocol on configurable ports. ## Core SV2 Protocol Layer - Binary codec (sv2-binary-codec.ts): U8/U16/U24/U32/U64, BOOL, STR0_32/STR0_255, B0_32/B0_64/B0_16M, SEQ0_255/SEQ0_64K - Frame reader/writer (sv2-frame.ts): 6-byte header framing with extension_type, msg_type, msg_length, channel_msg bit flag - Constants (sv2-constants.ts): all message types, setup flags, channel message flag, Noise protocol constants - Message serializers/deserializers (sv2-messages.ts): SetupConnection, OpenStandardMiningChannel, NewMiningJob, SetNewPrevHash, SubmitSharesStandard/Success/Error, SetTarget, UpdateChannel, CloseChannel, Reconnect, OpenMiningChannelError ## Noise NX Encrypted Transport - Full Noise_NX_EllSwift+ChaChaPoly handshake (sv2-noise.ts) - EllSwift key encoding via @scure/btc-signer for BIP-324 compatible ECDH - ChaCha20-Poly1305 AEAD encryption with nonce rotation - Certificate signing with Schnorr signatures (tiny-secp256k1) - Authority key pair management from SV2_CERT_AUTHORITY_SECRET_KEY env var ## Extended Channel Support - Extended channel messages (sv2-extended-messages.ts): OpenExtendedMiningChannel, NewExtendedMiningJob, SubmitSharesExtended, SetExtranoncePrefix, SetGroupChannel - Extranonce manager (sv2-extranonce-manager.ts): unique prefix allocation per channel with configurable prefix size - Variable extranonce sizes with scriptSig varint patching for coinbase prefix when channel extranonce != MiningJob's 8-byte slot - Block reconstruction from extended shares: coinbase from prefix+extranonce+suffix, merkle root from path, 80-byte header ## Template Distribution Protocol (TDP) - TDP messages (sv2-tdp-messages.ts): NewTemplate, SetNewPrevHash, SubmitSolution, CoinbaseOutputConstraints, RequestTransactionData - Template distribution service bridging Bitcoin Core templates to SV2 format with coinbase output constraints and merkle paths - PM2-aware logging: routine TDP logs emitted only from primary worker ## Job Declaration Protocol (JDP) - JDP messages (sv2-jdp-messages.ts): AllocateMiningJobToken, DeclareMiningJob, IdentifyTransactions, ProvideMissingTransactions, SubmitSolutionJd - SipHash-2-4 (sv2-siphash.ts): pure TS implementation for short transaction ID computation, verified against official test vectors - Job declaration service and client for custom block template negotiation between miners and pool - SetCustomMiningJob bridge: declared jobs forwarded to extended channel clients for mining - Transaction validation against mempool wtxids per spec ## SV2 Client (StratumV2Client.ts) - Full connection lifecycle: Noise handshake → SetupConnection → channel open → job distribution → share validation → block submission - Multi-channel support per connection (standard + extended) - Version rolling support via SetupConnection flags - Job-specific difficulty tracking per SV2 spec - Vardiff with initial target from miner's nominal hash rate - Share duplicate detection via SHA-256 submission hashing - Block submission with DB persistence and notifications for all paths (standard, extended, TDP SubmitSolution, JDP SubmitSolutionJd) ## Spec Compliance - SubmitShares.Success sends per-batch values (not cumulative) - OpenMiningChannel.Error uses proper serializer with request_id - Wire error codes: stale-share, invalid-job-id, difficulty-too-low - Block submission checks result === 'SUCCESS!' consistently across SV1, SV2 standard, SV2 extended, and TDP paths - JDP transaction validation uses wtxids (not txids) - channel_msg bit set correctly on all channel-bound message types ## Infrastructure - PM2 cluster-safe extranonce prefix allocation (worker ID offset) - SV2 pool fee discovery API endpoint - Downstream miner reporting for JDC proxy visibility - Regtest and testnet4 Docker Compose stacks - 391 tests across 45 suites (224 SV2-specific unit tests) ## Configuration - SV2_PORT: SV2 listening port (default 3336) - SV2_JDP_PORT: JDP listening port (default 3337) - SV2_JDP_ENABLED: enable JDP server (default false) - SV2_CERT_AUTHORITY_SECRET_KEY: Noise authority key (hex)
f74d703 to
2f36455
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Complete implementation of the Stratum V2 mining protocol with full specification coverage (51/51 spec items). This adds support for modern, efficient mining with improved security and flexibility.
Key Features
Core Protocol Stack
Mining Protocols
Advanced Features
Implementation Details
Testing
Configuration
New environment variables:
Compatibility