Skip to content

Commit 8e26c35

Browse files
committed
add new protocol version 1.6
This is a minimal changeset for a new protocol version. The ideas for the less trivial changes are deferred a bit, just so we get something out. ref spesmilo#2 ref spesmilo/electrumx#90
1 parent c366dc6 commit 8e26c35

3 files changed

Lines changed: 78 additions & 27 deletions

File tree

docs/protocol-basics.rst

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ revision number.
6868

6969
A party to a connection will speak all protocol versions in a range,
7070
say from `protocol_min` to `protocol_max`, which may be the same.
71-
When a connection is made, both client and server must initially
72-
assume the protocol to use is their own `protocol_min`.
7371

74-
The client should send a :func:`server.version` RPC call as early as
75-
possible in order to negotiate the precise protocol version; see its
76-
description for more detail. All responses received in the stream
77-
from and including the server's response to this call will use its
78-
negotiated protocol version.
72+
The client must send a :func:`server.version` RPC call as the first
73+
message on the wire, in order to negotiate the precise protocol
74+
version; see its description for more detail.
75+
All responses received in the stream from and including the server's
76+
response to this call will use its negotiated protocol version.
7977

8078

8179
.. _script hashes:
@@ -144,23 +142,31 @@ Status
144142
To calculate the `status` of a :ref:`script hash <script hashes>` (or
145143
address):
146144

147-
1. order confirmed transactions to the script hash by increasing
148-
height (and position in the block if there are more than one in a
149-
block)
145+
1. Consider all transactions touching the script hash (both those spending
146+
from it, and those funding it), both confirmed and unconfirmed (in mempool).
150147

151-
2. form a string that is the concatenation of strings
148+
2. Order confirmed transactions by increasing height (and position in the
149+
block if there are more than one in a block).
150+
151+
3. form a string that is the concatenation of strings
152152
``"tx_hash:height:"`` for each transaction in order, where:
153153

154154
* ``tx_hash`` is the transaction hash in hexadecimal
155155

156156
* ``height`` is the height of the block it is in.
157157

158-
3. Next, with mempool transactions in any order, append a similar
159-
string for those transactions, but where **height** is ``-1`` if the
160-
transaction has at least one unconfirmed input, and ``0`` if all
161-
inputs are confirmed.
158+
4. For mempool transactions, we define **height** to be ``-1`` if the
159+
transaction has at least one unconfirmed input, and ``0`` if all inputs are
160+
confirmed.
161+
162+
5. Order mempool transactions by ``(-height, tx_hash)``, that is,
163+
``0`` height txs come before ``-1`` height txs, and secondarily the
164+
txid (in network byteorder) is used to arrive at a canonical ordering.
165+
166+
6. Next, with mempool transactions in the specified order, append a similar
167+
string.
162168

163-
4. The :dfn:`status` of the script hash is the :func:`sha256` hash of the
169+
7. The :dfn:`status` of the script hash is the :func:`sha256` hash of the
164170
full string expressed as a hexadecimal string, or :const:`null` if the
165171
string is empty because there are no transactions.
166172

docs/protocol-changes.rst

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Protocol Changes
33
================
44

5-
This documents lists changes made by protocol version.
5+
This document lists changes made by protocol version.
66

77
Version 1.0
88
===========
@@ -175,3 +175,30 @@ New methods
175175
-----------
176176

177177
* :func:`blockchain.name.get_value_proof` to resolve a name (with proof). Name index coins (e.g. Namecoin) only.
178+
179+
180+
Version 1.5
181+
===========
182+
183+
(this version number was skipped, no corresponding protocol is defined)
184+
185+
186+
.. _version 1.6:
187+
188+
Version 1.6
189+
===========
190+
191+
Changes
192+
-------
193+
194+
* Breaking change for the version negotiation: we now mandate that
195+
the :func:`server.version` message must be the first message sent.
196+
That is, version negotiation must happen before any other messages.
197+
* The status of a scripthash has its definition tightened in a
198+
backwards-compatible way: mempool txs now have a canonical ordering
199+
defined for the calculation (previously their order was undefined).
200+
* :func:`blockchain.scripthash.get_mempool` previously did not define
201+
an order for mempool transactions. We now mandate a specific ordering.
202+
* Optional *mode* argument added to :func:`blockchain.estimatefee`.
203+
* :func:`blockchain.block.headers` now returns headers as a list,
204+
instead of a single concatenated hex string.

docs/protocol-methods.rst

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ With *cp_height* 8::
7676
blockchain.block.headers
7777
========================
7878

79-
Return a concatenated chunk of block headers from the main chain.
79+
Return a chunk of block headers from the main chain.
8080

8181
**Signature**
8282

@@ -85,6 +85,8 @@ Return a concatenated chunk of block headers from the main chain.
8585
.. versionchanged:: 1.4
8686
*cp_height* parameter added
8787
.. versionchanged:: 1.4.1
88+
.. versionchanged:: 1.6
89+
response contains *headers* field instead of *hex*
8890

8991
*start_height*
9092

@@ -106,17 +108,16 @@ Return a concatenated chunk of block headers from the main chain.
106108
A dictionary with the following members:
107109

108110
* *count*
109-
110111
The number of headers returned, between zero and the number
111112
requested. If the chain has not extended sufficiently far, only
112113
the available headers will be returned. If more headers than
113114
*max* were requested at most *max* will be returned.
114115

115-
* *hex*
116+
* *headers*
116117

117-
The binary block headers concatenated together in-order as a
118-
hexadecimal string. Starting with version 1.4.1, AuxPoW data (if present
119-
in the original header) is truncated if *cp_height* is nonzero.
118+
An array containing the binary block headers in-order; each header is a
119+
hexadecimal string. AuxPoW data (if present in the original header) is
120+
truncated if *cp_height* is nonzero.
120121

121122
* *max*
122123

@@ -149,7 +150,11 @@ See :ref:`here <cp_height example>` for an example of *root* and
149150

150151
{
151152
"count": 2,
152-
"hex": "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c010000006fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000982051fd1e4ba744bbbe680e1fee14677ba1a3c3540bf7b1cdb606e857233e0e61bc6649ffff001d01e36299"
153+
"headers":
154+
[
155+
"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c",
156+
"010000006fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000982051fd1e4ba744bbbe680e1fee14677ba1a3c3540bf7b1cdb606e857233e0e61bc6649ffff001d01e36299"
157+
],
153158
"max": 2016
154159
}
155160

@@ -161,12 +166,21 @@ be confirmed within a certain number of blocks.
161166

162167
**Signature**
163168

164-
.. function:: blockchain.estimatefee(number)
169+
.. function:: blockchain.estimatefee(number, mode=None)
170+
.. versionchanged:: 1.6
171+
*mode* argument added
165172

166173
*number*
167174

168175
The number of blocks to target for confirmation.
169176

177+
*mode*
178+
179+
A string to pass to the bitcoind *estimatesmartfee* RPC as the
180+
*estimate_mode* parameter. Optional. If omitted, the corresponding
181+
parameter to the bitcoind RPC is also omitted, i.e. the default
182+
value is determined by bitcoind.
183+
170184
**Result**
171185

172186
The estimated transaction fee in whole coin units per kilobyte, as a
@@ -359,15 +373,18 @@ hashes>`.
359373

360374
.. function:: blockchain.scripthash.get_mempool(scripthash)
361375
.. versionadded:: 1.1
376+
.. versionchanged:: 1.6
377+
results must be sorted (previously undefined order)
362378

363379
*scripthash*
364380

365381
The script hash as a hexadecimal string.
366382

367383
**Result**
368384

369-
A list of mempool transactions in arbitrary order. Each mempool
370-
transaction is a dictionary with the following keys:
385+
A list of mempool transactions. The order is the same as when computing the
386+
:ref:`status <status>` of the script hash.
387+
Each mempool transaction is a dictionary with the following keys:
371388

372389
* *height*
373390

@@ -991,6 +1008,7 @@ server.version
9911008
==============
9921009

9931010
Identify the client to the server and negotiate the protocol version.
1011+
This must be the first message sent on the wire.
9941012
Only the first :func:`server.version` message is accepted.
9951013

9961014
**Signature**

0 commit comments

Comments
 (0)