1
0
Fork 0
mirror of https://github.com/bitcoin/bips.git synced 2025-03-04 19:16:28 +01:00
bitcoin-bips/bip-0040.mediawiki

106 lines
5.7 KiB
Text
Raw Normal View History

2024-03-07 16:26:28 +01:00
<pre>
BIP: 40
Layer: Applications
Title: Stratum wire protocol
Author: Marek Palatinus <slush@satoshilabs.com>
Ben van Hartingsveldt <ben.vanhartingsveldt@yocto.com>
Comments-Summary: No comments yet.
Comments-URI: https://github.com/bitcoin/bips/wiki/Comments:BIP-0040
Status: Draft
Type: Standards Track
Created: 2024-03-07
License: PD
</pre>
==Abstract==
This document describes the Stratum wire protocol used in clients such as Electrum, and which also laid the foundation for the Stratum mining protocol, used in many Bitcoin pools.
The specification is intended to set a standard for connections between clients and servers in which the client is able to request data without having to download the full blockchain.
The specification consists of three parts. In the first part, the data format is defined. In the second part, the possible transport protocols (including encapsulation) are described. In the third part, the available methods are documented.
==Motivation==
Many clients want to give users access to the Bitcoin ecosystem. However, for specific reasons not every user is able to download the full blockchain to their machine.
The Stratum wire protocol defines a way to access the blockchain without having it downloaded. For example, a client can request both the genesis block and the latest block with the same latency, because the server does synchronize and index all blocks for us.
==History==
Stratum wire protocol was introduced by Marek Palatinus in late 2011 and early 2012. It was a language independent alternative for the Python-based protocol in early versions of Electrum, created by Thomas Voegtlin. The Stratum wire protocol made it possible to create compatible servers which Electrum could connect to, but it also made it possible to write alternative clients.
Later in 2012, Marek Palatinus introduced Stratum also for mining pools: The Stratum mining protocol, as defined in [[bip-0041.mediawiki|BIP 41]].
2024-03-07 16:26:28 +01:00
==Specification: Data Format==
Stratum leverages [https://www.jsonrpc.org/ JSON-RPC]. Both versions 1.0 and 2.0 are allowed. Rules of that version apply accordingly.
2024-03-07 16:38:43 +01:00
Additionally, it is a convention to give all Stratum methods in the <code>method</code> property a name in the following form: <code><service>.<method></code>, where <code><service></code> is allowed to have dots and <code><method></code> isn't. For example, the the value <code>blockchain.block.subscribe</code>.
2024-03-07 16:26:28 +01:00
''Note: In JSON-RPC 1.0, the <code>param</code> property is an array, so everything should be passed in the right order. In JSON-RPC 2.0, also named parameters are allowed. In that case, the parameter names that are documented should be used. If not, the method can fail. It is maybe also possible that a specific method (or server) only does support <code>params</code> being an array, because it doesn't know how to handle the named ones, even if it supports JSON-RPC 2.0.''
2024-03-07 16:26:28 +01:00
==Specification: Transport Protocols==
It is possible to send JSON-RPC messages over different transport protocols, like TCP and HTTP. It is also possible to protect these protocols with SSL/TLS.
===TCP===
2024-03-19 11:14:46 +01:00
Stratum over a TCP connection. Every JSON-RPC message (including batch messages) is send on a single line, ending with a line-feed (<code>\n</code>), so <code>\r\n</code> is also allowed. Line-feeds inside the JSON should be encoded as usual. Both client and server can initiate a request on which the other side could respond with a result or an error.
2024-03-07 16:26:28 +01:00
2024-03-19 09:58:44 +01:00
* Default port: <code>50001</code>
* Letter: <code>t</code>
2024-03-07 16:26:28 +01:00
===TCP over SSL/TLS===
Stratum over a TCP connection with SSL/TLS. Just the same as normal TCP, but with SSL/TLS enabled.
2024-03-19 09:58:44 +01:00
* Default port: <code>50002</code>
* Letter: <code>s</code>
===HTTP===
Stratum over an HTTP connection.
2024-03-19 09:58:44 +01:00
* Default port: <code>8081</code>
* Letter: <code>h</code>
===HTTP over SSL/TLS===
Stratum over an HTTP connection with SSL/TLS. Just the same as normal HTTP, but with SSL/TLS enabled.
2024-03-19 09:58:44 +01:00
* Default port: <code>8082</code>
* Letter: <code>g</code>
===WebSocket===
2024-03-19 11:14:46 +01:00
Stratum over a WebSocket connection. Every JSON-RPC message (including batch messages) is sent encapsulated in a WebSocket message and therefore line-feeds are not needed. Still, line-feeds inside the JSON should be encoded as usual. Both client and server can initiate a request on which the other side could respond with a result or an error.
* Default port: <code>8083</code><ref name="extended">This is extended specification information of the Stratum wire protocol to make it more complete. This information will not be found in any code or specification before this BIP.</ref>
2024-03-19 11:14:46 +01:00
* Letter: <code>w</code><ref name="extended"/>
====Subprotocol====
In a WebSocket upgrade request, it is possible to use the <code>Sec-WebSocket-Protocol</code> header to let the WebSocket server know which subprotocol is desired to send over the connection. For Stratum, the value <code>stratum</code> is registered. The use of this header is optional. If the server supports the use of this subprotocol too, it will let the client know by sending a <code>Sec-WebSocket-Protocol</code> header back. If the server doesn't send a subprotocol back, the connection will continue without using one. Use of this feature is fully backwards compatible.
====Example====
<code>
new WebSocket('ws://stratum.example.com:8083',['stratum']); // Open WebSocket with using a subprotocol
new WebSocket('ws://stratum.example.com:8083'); // Open WebSocket without using a subprotocol
</code>
===WebSocket over SSL/TLS===
Stratum over a WebSocket connection with SSL/TLS. Just the same as normal WebSocket, but with SSL/TLS enabled.
2024-03-07 16:26:28 +01:00
2024-03-19 11:14:46 +01:00
* Default port: <code>8084</code><ref name="extended"/>
* Letter: <code>u</code><ref name="extended"/>
2024-03-07 16:26:28 +01:00
==Specification: Commands==
2024-03-19 11:14:46 +01:00
TODO
==References==
<references/>