stratum-v2
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStratum v2 Mining Protocol
Stratum v2挖矿协议
Stratum v2 is the next-generation mining protocol developed by Braiins (Slush Pool), designed to address the limitations of Stratum v1. It introduces binary framing, end-to-end encryption, and decentralized job declaration.
Stratum v2是由Braiins(Slush Pool)开发的下一代挖矿协议,旨在解决Stratum v1的局限性。它引入了二进制帧、端到端加密和去中心化任务声明机制。
When to Use
适用场景
- Planning mining infrastructure upgrades
- Evaluating v1 to v2 migration
- Understanding modern mining security
- Implementing next-gen pool software
- Building decentralized mining solutions
- 规划挖矿基础设施升级
- 评估从v1到v2的迁移方案
- 了解现代挖矿安全机制
- 实现下一代矿池软件
- 构建去中心化挖矿解决方案
Key Improvements Over v1
相对v1的核心改进
| Feature | Stratum v1 | Stratum v2 |
|---|---|---|
| Format | JSON-RPC text | Binary framed |
| Bandwidth | ~100% baseline | ~30% reduction |
| Encryption | None (plaintext) | Noise Protocol (AEAD) |
| Authentication | Password-based | Cryptographic |
| Job Selection | Pool-controlled | Miner-declarable |
| Efficiency | Higher latency | Lower latency |
| 特性 | Stratum v1 | Stratum v2 |
|---|---|---|
| 格式 | JSON-RPC文本 | 二进制帧 |
| 带宽 | ~100%基准 | 减少约30% |
| 加密 | 无(明文传输) | Noise Protocol(AEAD) |
| 认证方式 | 基于密码 | 加密学认证 |
| 任务选择 | 矿池控制 | 矿工可自主声明 |
| 效率 | 高延迟 | 低延迟 |
Protocol Architecture
协议架构
Stratum v2 consists of three subprotocols:
Stratum v2包含三个子协议:
1. Mining Protocol
1. 挖矿协议
Core work distribution between pool and miners.
矿池与矿工之间的核心工作分配协议。
2. Job Declaration Protocol
2. 任务声明协议
Allows miners to construct their own block templates.
允许矿工自行构建区块模板。
3. Template Distribution Protocol
3. 模板分发协议
Distributes block templates from Bitcoin nodes to pools/miners.
将区块模板从比特币节点分发至矿池/矿工。
Binary Framing
二进制帧
Message Structure
消息结构
+------------------+------------------+------------------+
| Extension Type | Message Type | Message Length |
| (2 bytes) | (1 byte) | (3 bytes) |
+------------------+------------------+------------------+
| Payload |
| (variable length) |
+--------------------------------------------------------++------------------+------------------+------------------+
| Extension Type | Message Type | Message Length |
| (2 bytes) | (1 byte) | (3 bytes) |
+------------------+------------------+------------------+
| Payload |
| (variable length) |
+--------------------------------------------------------+Data Types
数据类型
| Type | Description | Size |
|---|---|---|
| U8 | Unsigned 8-bit | 1 byte |
| U16 | Unsigned 16-bit LE | 2 bytes |
| U24 | Unsigned 24-bit LE | 3 bytes |
| U32 | Unsigned 32-bit LE | 4 bytes |
| U256 | 256-bit hash | 32 bytes |
| STR0_255 | Length-prefixed string | 1 + n bytes |
| B0_32 | Length-prefixed bytes | 1 + n bytes |
| B0_64K | Length-prefixed bytes | 2 + n bytes |
| SEQ0_64K | Sequence of items | 2 + items |
| 类型 | 描述 | 大小 |
|---|---|---|
| U8 | 无符号8位整数 | 1字节 |
| U16 | 小端序无符号16位整数 | 2字节 |
| U24 | 小端序无符号24位整数 | 3字节 |
| U32 | 小端序无符号32位整数 | 4字节 |
| U256 | 256位哈希值 | 32字节 |
| STR0_255 | 长度前缀字符串 | 1 + n字节 |
| B0_32 | 长度前缀字节序列 | 1 + n字节 |
| B0_64K | 长度前缀字节序列 | 2 + n字节 |
| SEQ0_64K | 项序列 | 2 + 项总大小 |
Channel Types
通道类型
Standard Channel
标准通道
- Basic mining operations
- Fixed extranonce size
- Pool-assigned difficulty
- 基础挖矿操作
- 固定额外随机数大小
- 矿池分配难度
Extended Channel
扩展通道
- Larger extranonce support
- Custom coinbase prefix
- Header-only mining mode
- 支持更大的额外随机数
- 自定义交易前缀
- 仅头部挖矿模式
Group Channel
组通道
- Aggregates multiple miners
- Proxy/farm configurations
- Efficient multiplexing
- 聚合多个矿工
- 代理/矿场配置
- 高效多路复用
Encryption (Noise Protocol)
加密(Noise Protocol)
Stratum v2 uses the Noise Protocol Framework with:
- Handshake: Noise_NX_secp256k1_ChaChaPoly_SHA256
- Cipher: ChaCha20-Poly1305 (AEAD)
- Curve: secp256k1
- Hash: SHA-256
Stratum v2使用Noise Protocol Framework,配置如下:
- 握手协议: Noise_NX_secp256k1_ChaChaPoly_SHA256
- 加密算法: ChaCha20-Poly1305(AEAD)
- 椭圆曲线: secp256k1
- 哈希算法: SHA-256
Connection Flow
连接流程
1. Client initiates Noise handshake
2. Server provides certificate (signed by authority)
3. Encrypted channel established
4. All subsequent messages encrypted1. 客户端发起Noise握手
2. 服务器提供证书(由权威机构签名)
3. 建立加密通道
4. 后续所有消息均加密传输Security Benefits
安全收益
- Man-in-the-middle protection
- Hashrate hijacking prevention
- Pool impersonation prevention
- Privacy for miner operations
- 中间人攻击防护
- 哈希率劫持防护
- 矿池冒充防护
- 矿工操作隐私保护
Mining Protocol Messages
挖矿协议消息
Setup Messages
初始化消息
SetupConnection
{
protocol: U32,
min_version: U16,
max_version: U16,
flags: U32,
endpoint_host: STR0_255,
endpoint_port: U16,
vendor: STR0_255,
hardware_version: STR0_255,
firmware: STR0_255,
device_id: STR0_255
}SetupConnection.Success
{
used_version: U16,
flags: U32
}SetupConnection
{
protocol: U32,
min_version: U16,
max_version: U16,
flags: U32,
endpoint_host: STR0_255,
endpoint_port: U16,
vendor: STR0_255,
hardware_version: STR0_255,
firmware: STR0_255,
device_id: STR0_255
}SetupConnection.Success
{
used_version: U16,
flags: U32
}Channel Messages
通道消息
OpenStandardMiningChannel
{
request_id: U32,
user_identity: STR0_255,
nominal_hash_rate: F32,
max_target: U256
}OpenStandardMiningChannel.Success
{
request_id: U32,
channel_id: U32,
target: U256,
extranonce_prefix: B0_32,
group_channel_id: U32
}OpenStandardMiningChannel
{
request_id: U32,
user_identity: STR0_255,
nominal_hash_rate: F32,
max_target: U256
}OpenStandardMiningChannel.Success
{
request_id: U32,
channel_id: U32,
target: U256,
extranonce_prefix: B0_32,
group_channel_id: U32
}Job Messages
任务消息
NewMiningJob
{
channel_id: U32,
job_id: U32,
future_job: BOOL,
version: U32,
version_rolling_allowed: BOOL
}SetNewPrevHash
{
channel_id: U32,
job_id: U32,
prev_hash: U256,
min_ntime: U32,
nbits: U32
}NewMiningJob
{
channel_id: U32,
job_id: U32,
future_job: BOOL,
version: U32,
version_rolling_allowed: BOOL
}SetNewPrevHash
{
channel_id: U32,
job_id: U32,
prev_hash: U256,
min_ntime: U32,
nbits: U32
}Share Submission
提交结果
SubmitSharesStandard
{
channel_id: U32,
sequence_number: U32,
job_id: U32,
nonce: U32,
ntime: U32,
version: U32
}SubmitShares.Success
{
channel_id: U32,
last_sequence_number: U32,
new_submits_accepted_count: U32,
new_shares_sum: U64
}SubmitSharesStandard
{
channel_id: U32,
sequence_number: U32,
job_id: U32,
nonce: U32,
ntime: U32,
version: U32
}SubmitShares.Success
{
channel_id: U32,
last_sequence_number: U32,
new_submits_accepted_count: U32,
new_shares_sum: U64
}Job Declaration Protocol
任务声明协议
Enables miners to select transactions for blocks:
允许矿工选择区块中的交易:
Flow
流程
- Miner connects to Template Distribution node
- Miner receives block template with transactions
- Miner declares custom job to pool
- Pool validates and accepts declaration
- Miner works on self-constructed block
- 矿工连接到模板分发节点
- 矿工接收包含交易的区块模板
- 矿工向矿池声明自定义任务
- 矿池验证并接受声明
- 矿工处理自行构建的区块
Messages
消息
DeclareMiningJob
{
request_id: U32,
mining_job_token: B0_255,
version: U32,
coinbase_prefix: B0_64K,
coinbase_suffix: B0_64K,
tx_short_hash_nonce: U64,
tx_short_hash_list: SEQ0_64K[U64],
tx_hash_list_hash: U256,
excess_data: B0_64K
}DeclareMiningJob
{
request_id: U32,
mining_job_token: B0_255,
version: U32,
coinbase_prefix: B0_64K,
coinbase_suffix: B0_64K,
tx_short_hash_nonce: U64,
tx_short_hash_list: SEQ0_64K[U64],
tx_hash_list_hash: U256,
excess_data: B0_64K
}Benefits
收益
- Decentralizes transaction selection
- Reduces pool censorship risk
- Improves Bitcoin decentralization
- Miners control block content
- 去中心化交易选择
- 降低矿池审查风险
- 提升比特币去中心化程度
- 矿工控制区块内容
Template Distribution Protocol
模板分发协议
Distributes templates from Bitcoin node to pools/miners:
NewTemplate
{
template_id: U64,
future_template: BOOL,
version: U32,
coinbase_tx_version: U32,
coinbase_prefix: B0_64K,
coinbase_tx_input_sequence: U32,
coinbase_tx_value_remaining: U64,
coinbase_tx_outputs_count: U32,
coinbase_tx_outputs: B0_64K,
coinbase_tx_locktime: U32,
merkle_path: SEQ0_255[U256]
}将模板从比特币节点分发至矿池/矿工:
NewTemplate
{
template_id: U64,
future_template: BOOL,
version: U32,
coinbase_tx_version: U32,
coinbase_prefix: B0_64K,
coinbase_tx_input_sequence: U32,
coinbase_tx_value_remaining: U64,
coinbase_tx_outputs_count: U32,
coinbase_tx_outputs: B0_64K,
coinbase_tx_locktime: U32,
merkle_path: SEQ0_255[U256]
}Comparison: v1 vs v2 Session
会话对比:v1 vs v2
Stratum v1 Session
Stratum v1会话
Client: {"method":"mining.subscribe","params":["Agent/1.0"],"id":1}
Server: {"result":[[["mining.set_difficulty","1"],["mining.notify","1"]],"08000000",4],"id":1}
Client: {"method":"mining.authorize","params":["user.worker",""],"id":2}
Server: {"result":true,"id":2}
Server: {"method":"mining.set_difficulty","params":[1024]}
Server: {"method":"mining.notify","params":["job1","prev...","cb1","cb2",[],"ver","bits","time",true]}
Client: {"method":"mining.submit","params":["user.worker","job1","00000000","time","nonce"],"id":3}
Server: {"result":true,"id":3}Client: {"method":"mining.subscribe","params":["Agent/1.0"],"id":1}
Server: {"result":[[["mining.set_difficulty","1"],["mining.notify","1"]],"08000000",4],"id":1}
Client: {"method":"mining.authorize","params":["user.worker",""],"id":2}
Server: {"result":true,"id":2}
Server: {"method":"mining.set_difficulty","params":[1024]}
Server: {"method":"mining.notify","params":["job1","prev...","cb1","cb2",[],"ver","bits","time",true]}
Client: {"method":"mining.submit","params":["user.worker","job1","00000000","time","nonce"],"id":3}
Server: {"result":true,"id":3}Stratum v2 Session
Stratum v2会话
1. Noise handshake (encrypted channel established)
2. SetupConnection → SetupConnection.Success
3. OpenStandardMiningChannel → OpenStandardMiningChannel.Success
4. SetTarget (difficulty)
5. NewMiningJob + SetNewPrevHash (job assignment)
6. SubmitSharesStandard → SubmitShares.Success1. Noise handshake (encrypted channel established)
2. SetupConnection → SetupConnection.Success
3. OpenStandardMiningChannel → OpenStandardMiningChannel.Success
4. SetTarget (difficulty)
5. NewMiningJob + SetNewPrevHash (job assignment)
6. SubmitSharesStandard → SubmitShares.SuccessMigration Considerations
迁移注意事项
When to Migrate
何时迁移
- Security is priority (MITM protection needed)
- Bandwidth costs significant
- Decentralization goals
- Modern infrastructure refresh
- 安全为首要需求(需要中间人攻击防护)
- 带宽成本较高
- 追求去中心化目标
- 现代化基础设施升级
When to Stay on v1
何时保留v1
- Legacy hardware compatibility
- Existing stable infrastructure
- Simple pool operations
- No security concerns
- 需兼容老旧硬件
- 现有基础设施稳定运行
- 矿池操作简单
- 无安全顾虑
Hybrid Approach
混合方案
Many pools run both:
- v1 on port 3333 (legacy compatibility)
- v2 on port 3334 (modern miners)
Translation proxies can bridge v1 miners to v2 pools.
许多矿池同时运行两个版本:
- v1使用3333端口(兼容老旧设备)
- v2使用3334端口(面向现代矿工)
翻译代理可将v1矿工连接到v2矿池。
BSV Considerations
BSV相关考虑
Current State
当前状态
- BSV pools primarily use Stratum v1
- GorillaPool uses optimized v1 implementation
- v2 adoption depends on ASIC firmware support
- BSV矿池主要使用Stratum v1
- GorillaPool使用优化版v1实现
- v2的 adoption 依赖ASIC固件支持
BSV-Specific Features
BSV专属特性
- Large block templates (transaction selection matters)
- getminingcandidate RPC (BSV-specific)
- submitminingsolution RPC (BSV-specific)
- Higher transaction throughput
- 大区块模板(交易选择至关重要)
- getminingcandidate RPC(BSV专属)
- submitminingsolution RPC(BSV专属)
- 更高的交易吞吐量
Implementation Path
实施路径
- Start with Stratum v1 (proven, compatible)
- Add v2 support when ASIC ecosystem ready
- Maintain both for transition period
- 先基于Stratum v1启动(成熟、兼容)
- 当ASIC生态支持时添加v2支持
- 过渡期间同时维护两个版本
Reference Implementation
参考实现
Stratum Reference Implementation (SRI):
- GitHub: stratum-mining/stratum
- Rust-based implementation
- Production-ready components
Components:
- - Mining pool role
roles/pool - - Proxy/translator
roles/mining-proxy - - Job declaration client
roles/jd-client - - Job declaration server
roles/jd-server
Stratum参考实现(SRI):
- GitHub: stratum-mining/stratum
- 基于Rust的实现
- 可用于生产环境的组件
组件:
- - 矿池角色
roles/pool - - 代理/翻译器
roles/mining-proxy - - 任务声明客户端
roles/jd-client - - 任务声明服务器
roles/jd-server
Resources
资源
Implementation Status
实施状态
| Component | Availability |
|---|---|
| Protocol Spec | Complete |
| Reference Implementation | Production |
| Pool Support | Growing |
| ASIC Firmware | Limited |
| BSV Support | Future |
| 组件 | 可用性 |
|---|---|
| 协议规范 | 已完成 |
| 参考实现 | 可用于生产环境 |
| 矿池支持 | 持续增长 |
| ASIC固件 | 有限支持 |
| BSV支持 | 规划中 |
Quick Reference
快速参考
Stratum v2 Ports (typical):
- 3334 - Mining Protocol (encrypted)
- 8442 - Template Distribution
- 8443 - Job Declaration
Key Crates (Rust):
toml
[dependencies]
binary_sv2 = "1.0"
codec_sv2 = "1.0"
framing_sv2 = "1.0"
noise_sv2 = "1.0"Stratum v2常用端口:
- 3334 - 挖矿协议(加密)
- 8442 - 模板分发
- 8443 - 任务声明
核心Rust包:
toml
[dependencies]
binary_sv2 = "1.0"
codec_sv2 = "1.0"
framing_sv2 = "1.0"
noise_sv2 = "1.0"