Skip to content

Commit 43f59df

Browse files
committed
Merge commit '03b7587'
2 parents 84808a7 + 03b7587 commit 43f59df

File tree

2 files changed

+292
-0
lines changed

2 files changed

+292
-0
lines changed

README.mediawiki

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,13 @@ Those proposing changes should consider that ultimately consent may rest with th
827827
| Standard
828828
| Draft
829829
|-
830+
| [[bip-0310.mediawiki|310]]
831+
| Applications
832+
| Stratum protocol extensions
833+
| Pavel Moravec, Jan Čapek
834+
| Informational
835+
| Draft
836+
|-
830837
| [[bip-0320.mediawiki|320]]
831838
|
832839
| nVersion bits for general purpose use

bip-0310.mediawiki

Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
<pre>
2+
BIP: 310
3+
Layer: Applications
4+
Title: Stratum protocol extensions
5+
Author: Pavel Moravec <[email protected]>
6+
Jan Čapek <[email protected]>
7+
Comments-Summary: No comments yet.
8+
Comments-URI: https://github.com/bitcoin/bips/wiki/Comments:BIP-0310
9+
Status: Draft
10+
Type: Informational
11+
Created: 2018-03-10
12+
License: BSD-3-Clause
13+
CC0-1.0
14+
</pre>
15+
16+
==Abstract==
17+
18+
This BIP provides a generic mechanism for specifying stratum protocol
19+
extensions. At the same time, one of the important extensions that is
20+
specified by this BIP is configuration of bits for "version rolling"
21+
in nVersion field of bitcoin block header.
22+
23+
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
24+
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
25+
document are to be interpreted as described in RFC 2119.
26+
27+
==Motivation==
28+
29+
The initial motivation for specifying some general support for stratum
30+
protocol extensions was a need to allow miners to do so called
31+
"version rolling", changing value in the first field of the Bitcoin
32+
block header.
33+
34+
Version rolling is backwards incompatible change to the stratum protocol
35+
because the miner couldn't communicate different block version value to
36+
the server in the original version of the stratum protocol. Similarly,
37+
a server couldn't communicate safe bits for rolling to a miner. So
38+
both miners and pools need to implement some protocol extension to
39+
support version rolling.
40+
41+
Typically, if a miner sends an unknown message to a server, the server
42+
closes the connection (not all implementations do that but some
43+
do). So it is not very safe to try to send unknown messages to
44+
servers.
45+
46+
We can use this opportunity to make one backwards incompatible
47+
change to the protocol to support multiple extensions in the
48+
future. In a way that a miner can advertise its capabilities and at
49+
the same time it can request some needed features from the server.
50+
51+
It is preferable that the same mechanism for feature negotiation can
52+
be used for not yet known features. It SHOULD be easy to implement in
53+
the mining software too.
54+
55+
We introduce one new message to the stratum protocol ('''"mining.configure"''') which handles the initial configuration/negotiation of features in a generic way. So that adding features in the future can be done without a necessity to add new messages to stratum protocol.
56+
57+
Each extension has its unique string name, so called '''extension code'''.
58+
59+
60+
==Specification==
61+
Currently, the following extensions are defined:
62+
63+
* '''"version-rolling"'''
64+
* '''"minimum-difficulty"'''
65+
* '''"subscribe-extranonce"'''
66+
67+
68+
===Additional data types===
69+
70+
The following names are used as type aliases, making the message
71+
description easier.
72+
73+
* '''TMask''' - case independent hexadecimal string of length 8, encoding an unsigned 32-bit integer (~<code>[0-9a-fA-F]{8}</code>)
74+
75+
* '''TExtensionCode''' - non-empty string with a value equal to the name of some protocol extension.
76+
77+
* '''TExtensionResult''' - <code>true</code> / <code>false</code> / ''String''.
78+
** <code>true</code> = The requested feature is supported and its configuration understood and applied.
79+
** <code>false</code> = The feature is not supported or unknown.
80+
** ''String'' = Error message containing information about what went wrong.
81+
82+
83+
===Request "mining.configure"===
84+
85+
This message (JSON RPC Request) SHOULD be the '''first message''' sent
86+
by the miner after the connection with the server is established. The client
87+
uses the message to advertise its features and to request/allow some
88+
protocol extensions.
89+
90+
The reason for it being the first is that we want the implementation and
91+
possible interactions to be as easy and simple as possible. An extension
92+
can define explicitly what does a repeated configuration of that
93+
extension mean.
94+
95+
Each extension code provides a namespace for its extension parameters
96+
and extension return values. By convention, the names are formed from
97+
extension codes by adding "." and a parameter name. The same applies
98+
for the return values, which are transferred in a result map
99+
too. E.g. "version-rolling.mask" is the name of the parameter "mask" of
100+
extension "version-rolling".
101+
102+
'''Parameters''':
103+
104+
* '''extensions''' (REQUIRED, List of ''TExtensionCode'')
105+
::- Each string in the list MUST be a valid extension code. The meaning of each code is described independently as part of the extension definition. A miner SHOULD advertise all its available features.
106+
107+
* '''extension-parameters''' (REQUIRED, ''Map of (String -> Any)'')
108+
::- Parameters of the requested/allowed extensions from the first parameter.
109+
110+
111+
'''Return value''':
112+
113+
* ''Map of (String -> Any)''
114+
::- Each code from the '''extensions''' list MUST have a defined return value (''TExtensionCode'' -> ''TExtensionResult''). This way the miner knows if the extension is activated or not. E.g. <code>{"version-rolling":false}</code> for unsupported version rolling.
115+
::- Some extensions need additional information to be delivered to the miner. The return value map is used for this purpose.
116+
117+
118+
Example request (new-lines added):
119+
120+
<pre>
121+
{"method": "mining.configure",
122+
"id": 1,
123+
"params": [["minimum-difficulty", "version-rolling"],
124+
{"minimum-difficulty.value": 2048,
125+
"version-rolling.mask": "1fffe000", "version-rolling.min-bit-count": 2}]}
126+
</pre>
127+
128+
(The miner requests extensions <code>"version-rolling"</code> and
129+
<code>"minimum-difficulty"</code>. It sets the parameters according to the extensions'
130+
definitions.)
131+
132+
Example result (new-lines added):
133+
134+
<pre>
135+
{"error": null,
136+
"id": 1,
137+
"result": {"version-rolling": true,
138+
"version-rolling.mask": "18000000",
139+
"minimum-difficulty": true}}
140+
</pre>
141+
142+
=Defined extensions=
143+
144+
==Extension "version-rolling"==
145+
146+
This extension allows the miner to change the value of some bits in the
147+
version field in the block header. Currently there are no standard bits
148+
used for version rolling so they need to be negotiated between a
149+
miner and a server.
150+
151+
A miner sends the server a mask describing bits which the miner is
152+
capable of changing. 1 = changeable bit, 0 = not changeable (<code>miner_mask</code>)
153+
and a minimum number of bits that it needs for efficient version rolling.
154+
155+
A server typically allows you to change only some of the version bits
156+
(<code>server_mask</code>) and the rest of the version bits are
157+
fixed. E.g. because the block needs to be valid or some signaling is
158+
in place.
159+
160+
The server responds to the configuration message by sending a mask
161+
with common bits intersection of the miner's mask and its a mask
162+
(<code>response = server_mask & miner_mask</code>)
163+
164+
Example request (a miner capable of changing any 2 bits from a 16-bit mask):
165+
166+
{"method": "mining.configure", "id": 1, "params": [["version-rolling"], {"version-rolling.mask": "1fffe000", "version-rolling.min-bit-count": 2}]}
167+
168+
169+
Example result (success):
170+
171+
{"error": null, "id": 1, "result": {"version-rolling": true, "version-rolling.mask": "18000000"}}
172+
173+
174+
Example result (unknown extension):
175+
176+
{"error": null, "id": 1, "result": {"version-rolling": false}}
177+
178+
179+
'''Extension parameters''':
180+
181+
* '''"version-rolling.mask"''' (OPTIONAL, ''TMask'', default value <code>"ffffffff"</code>)
182+
::- Bits set to 1 can be changed by the miner. This value is expected
183+
to be stable for the whole mining session. A miner doesn't have to
184+
send the mask, in this case a default full mask is used.
185+
186+
'''Extension return values''':
187+
188+
* '''"version-rolling"''' (REQUIRED, ''TExtensionResult'')
189+
::- When responded with <code>true</code>, the server will accept new parameter of '''"mining.submit"''', see later.
190+
191+
* '''"version-rolling.mask"''' (REQUIRED, ''TMask'')
192+
::- Bits set to 1 are allowed to be changed by the miner. If a miner changes bits with mask value 0, the server will reject the submit.
193+
::- The server SHOULD return the largest mask possible (as many bits set to 1 as possible). This can be useful in a mining proxy setup when a proxy needs to negotiate the best mask for its future clients. There is a [Draft BIP](https://github.com/bitcoin/bips/pull/661/files) describing available nVersion bits. The server SHOULD pick a mask that preferably covers all bits specified in the BIP.
194+
195+
* '''"version-rolling.min-bit-count"''' (REQUIRED, ''TMask'')
196+
::- The miner also provides a minimum number of bits that it needs for efficient version rolling in hardware. Note that this parameter provides important diagnostic information to the pool server. If the requested bit count exceeds the limit of the pool server, the miner always has the chance to operate in a degraded mode without using full hashing power. The pool server SHOULD NOT terminate miner connection if this rare mismatch case occurs.
197+
198+
===Notification '''"mining.set_version_mask"'''===
199+
200+
Server notifies the miner about a new mask valid for the
201+
connection. This message can be sent at any time after the successful
202+
setup of the version rolling extension by the "mining.configure"
203+
message. The new mask is valid '''immediately''', so that the server
204+
doesn't wait for the next job.
205+
206+
207+
'''Parameters''':
208+
209+
* ''mask'' (REQUIRED, ''TMask''): The meaning is the same as the '''"version-rolling.mask"''' return parameter.
210+
211+
Example:
212+
213+
{"params":["00003000"], "id":null, "method": "mining.set_version_mask"}
214+
215+
216+
===Changes in request '''"mining.submit"'''===
217+
218+
Immediately after successful activation of the version-rolling extension
219+
(result to '''"mining.configure"''' sent by server), the server MUST accept
220+
an additional parameter of the message '''"mining.submit"'''. The client MUST
221+
send one additional parameter, '''version_bits''' (6th parameter, after
222+
''worker_name'', ''job_id'', ''extranonce2'', ''ntime'' and ''nonce'').
223+
224+
225+
'''Additional parameters''':
226+
227+
* ''version_bits'' (REQUIRED, ''TMask'') - Version bits set by miner.
228+
::- Miner can set only bits corresponding to the set bits in the last received mask from the server either as response to "mining.configure" or "mining.set_version_mask" notification (<code>last_mask</code>). This must hold:
229+
version_bits & ~last_mask == 0
230+
::- The server computes ''nVersion'' for the submit as follows:
231+
nVersion = (job_version & ~last_mask) | (version_bits & last_mask)
232+
where <code>job_version</code> is the block version sent to miner as part of job with id <code>job_id</code>.
233+
234+
==Extension "minimum-difficulty"==
235+
236+
This extension allows miner to request a minimum difficulty for the
237+
connected machine. It solves a problem in the original stratum
238+
protocol where there is no way how to communicate hard limit of the
239+
connected device.
240+
241+
'''Extension parameters''':
242+
* '''"minimum-difficulty.value"''' (REQUIRED, ''Integer/Float'', >= 0)
243+
::- The minimum difficulty value acceptable for the miner/connection. The value can be 0 for essentially disabling the feature.
244+
245+
'''Extension return values''':
246+
* '''"minimum-difficulty"''' (REQUIRED, ''TExtensionResult'')
247+
::- Whether the minimum difficulty was accepted or not.
248+
::- This extension can be configured multiple times by calling "mining.configure" with "minimum-difficulty" code again.
249+
250+
251+
==Extension "subscribe-extranonce"==
252+
253+
Parameter-less extension. Miner advertises its capability of receiving
254+
message '''"mining.set_extranonce"''' message (useful for hash rate
255+
routing scenarios).
256+
257+
==Extension "info"==
258+
259+
Miner provides additional text-based information.
260+
261+
'''Extension parameters''':
262+
* '''"info.connection-url"''' (OPTIONAL, ''String'')
263+
::- Exact URL used by the mining software to connect to the stratum server.
264+
265+
* '''"info.hw-version"''' (OPTIONAL, ''String'')
266+
::- Manufacturer specific hardware revision string.
267+
268+
* '''"info.sw-version"''' (OPTIONAL, ''String'')
269+
::- Manufacturer specific software version
270+
271+
* '''"info.hw-id"''' (OPTIONAL, ''String'')
272+
::- Unique identifier of the mining device
273+
274+
==Compatibility==
275+
276+
Currently, there is a similar protocol feature '''mining.capabilities''' that
277+
was intended for various protocol extensions. However, '''mining.configure'''
278+
is incompatible with this feature as it requires a server response confirming
279+
all accepted/negotatied extensions. The reason why we made it incompatible is
280+
that '''mining.capabilities''' request has no associated response.
281+
282+
283+
==Copyright==
284+
285+
This document is dual licensed as BSD 3-clause, and Creative Commons CC0 1.0 Universal.

0 commit comments

Comments
 (0)