Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement protocol 2.0; change db schema #101

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
dc7eb24
history db: change schema, and rm compaction
SomberNight Oct 22, 2020
1877119
history db: change schema: prefix entries with b'H'
SomberNight Oct 28, 2020
81d8dd1
history db: store a tx_hash->tx_num map
SomberNight Oct 28, 2020
92cb55c
history db: sort key insertion order
SomberNight Oct 29, 2020
9c22323
utxo db: change schema: no longer use compressed txid
SomberNight Oct 28, 2020
6d38d0f
db: rm upgrade logic
SomberNight Oct 28, 2020
1853023
session: blockchain.transaction.get_merkle: make "height" optional
SomberNight Oct 29, 2020
90561ef
env: add new cfg option "DAEMON_HAS_TXINDEX", and support "False"
SomberNight Oct 29, 2020
4ebda7a
history db: store a (prev_txnum, prev_idx)->spender_txnum map
SomberNight Oct 30, 2020
64189cc
(trivial) make TXNUM_PADDING a global
SomberNight Oct 30, 2020
95c6ce6
db: add parameter for TXOUTIDX_LEN
SomberNight Oct 30, 2020
4326ae7
db: change TXOUTIDX_LEN from 4 to 3, to save db storage size
SomberNight Oct 30, 2020
3a41279
session: implement "blockchain.outpoint.subscribe" RPC
SomberNight Nov 3, 2020
7c7612b
"blockchain.outpoint.subscribe" RPC: add optional "spk_hint" argument
SomberNight Jan 19, 2021
65a7dd3
"blockchain.outpoint.subscribe" RPC: implement notifications
SomberNight Nov 4, 2020
b87a8ea
"blockchain.outpoint.subscribe" RPC: distinguish heights "-1" and "0"
SomberNight Jan 27, 2021
79e2690
protocol change: server.version must be the first message on the wire
SomberNight Nov 5, 2020
8b7efde
session: wait for protocol ver negotiation to finish before other reqs
SomberNight Jan 19, 2021
f410565
(bugfix) db: change tx_num endianness (LE->BE) to match db comparator
SomberNight Nov 16, 2020
df12667
protocol change: define order of mempool txs in status of scripthash
SomberNight Dec 15, 2020
0494caf
DB storage: implement iterator.seek(key)
SomberNight Feb 3, 2021
312e61d
new scripthash status: impl protocol 1.5 status; inefficient for now
SomberNight Jan 19, 2021
660deec
new scripthash status: speed-up calc by storing intermed. state in db
SomberNight Feb 4, 2021
36202d3
"scripthash.get_history": impl updates for proto 1.5; no client_* yet
SomberNight Feb 4, 2021
3dcb9f1
"scripthash.get_history": handle client_statushash and client_height
SomberNight Feb 5, 2021
09a15fb
session: rework statushash calculation.
SomberNight Oct 20, 2021
cee2d3f
[AuxPow] Add Support for individual block headers instead of a combin…
ahmedbodi Jun 28, 2020
2bfbc5c
Array headers: fix type error
JeremyRand Mar 18, 2021
31f8427
Array headers: move variable initialization
JeremyRand Mar 18, 2021
264daec
Array headers: Refactor AuxPoW
JeremyRand Mar 18, 2021
ef830fd
Array headers: Refactor AuxPoW truncation
JeremyRand Mar 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def query(args):
if not hashX:
continue
n = None
history = await db.limited_history(hashX, limit=limit)
history = await db.limited_history(hashX=hashX, limit=limit)
for n, (tx_hash, height) in enumerate(history, start=1):
print(f'History #{n:,d}: height {height:,d} '
f'tx_hash {hash_to_hex_str(tx_hash)}')
Expand Down
11 changes: 7 additions & 4 deletions docs/HOWTO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ functions. For example, `x11_hash`_ is required for DASH. Scrypt coins
require a Python interpreter compiled and/or linked with OpenSSL 1.1.0
or higher.

You **must** be running a non-pruning bitcoin daemon with::
You **must** be running a non-pruning bitcoin daemon.
It is also recommended to have::

txindex=1

set in its configuration file. If you have an existing installation
of bitcoind and have not previously set this you will need to reindex
the blockchain with::
set in its configuration file, for better performance when serving many sessions.
If you have an existing installation of bitcoind and have not previously set this
but you do now, you will need to reindex the blockchain with::

bitcoind -reindex

which can take some time.
If you intend to use a bitcoind without txindex enabled, you need to configure the
`DAEMON_HAS_TXINDEX` :ref:`environment variable <environment>`.

While not a requirement for running ElectrumX, it is intended to be
run with supervisor software such as Daniel Bernstein's
Expand Down
14 changes: 8 additions & 6 deletions docs/environment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,14 @@ These environment variables are optional:
version string. For example to drop versions from 1.0 to 1.2 use
the regex ``1\.[0-2]\.\d+``.

.. envvar:: DROP_CLIENT_UNKNOWN
.. envvar:: DAEMON_HAS_TXINDEX

Set to anything non-empty to deny serving clients which do not
identify themselves first by issuing the server.version method
call with a non-empty client identifier. The connection is dropped
on first actual method call. This might help to filter out simple
robots. This behavior is off by default.
Set this environment variable to empty if the connected bitcoind
does not have txindex enabled. Defaults to True (has txindex).
We rely on bitcoind to lookup arbitrary txs, regardless of this setting.
Without txindex, tx lookup works as in `bitcoind PR #10275`_.
Note that performance when serving many sessions is better with txindex
(but initial sync should be unaffected).


Resource Usage Limits
Expand Down Expand Up @@ -506,3 +507,4 @@ your available physical RAM:

.. _lib/coins.py: https://github.com/spesmilo/electrumx/blob/master/electrumx/lib/coins.py
.. _uvloop: https://pypi.python.org/pypi/uvloop
.. _bitcoind PR #10275: https://github.com/bitcoin/bitcoin/pull/10275
9 changes: 8 additions & 1 deletion electrumx/lib/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from dataclasses import dataclass
from hashlib import blake2s
from typing import Sequence
from typing import Sequence, Optional

from electrumx.lib.hash import sha256, double_sha256, hash_to_hex_str
from electrumx.lib.script import OpCodes
Expand Down Expand Up @@ -105,6 +105,13 @@ def serialize(self):
))


@dataclass
class TXOSpendStatus:
prev_height: Optional[int] # block height TXO is mined at. None if the outpoint never existed
spender_txhash: bytes = None
spender_height: int = None


class Deserializer:
'''Deserializes blocks into transactions.

Expand Down
6 changes: 5 additions & 1 deletion electrumx/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import sys
from collections.abc import Container, Mapping
from struct import Struct
from typing import Optional


# Use system-compiled JSON lib if available, fallback to stdlib
Expand Down Expand Up @@ -162,7 +163,7 @@ def chunks(items, size):
yield items[i: i + size]


def resolve_limit(limit):
def resolve_limit(limit: Optional[int]) -> int:
if limit is None or limit < 0:
return -1
assert isinstance(limit, int)
Expand Down Expand Up @@ -316,6 +317,7 @@ def protocol_version(client_req, min_tuple, max_tuple):
struct_le_Q = Struct('<Q')
struct_be_H = Struct('>H')
struct_be_I = Struct('>I')
struct_be_Q = Struct('>Q')
structB = Struct('B')

unpack_le_int32_from = struct_le_i.unpack_from
Expand All @@ -329,6 +331,7 @@ def protocol_version(client_req, min_tuple, max_tuple):
unpack_le_uint32 = struct_le_I.unpack
unpack_le_uint64 = struct_le_Q.unpack
unpack_be_uint32 = struct_be_I.unpack
unpack_be_uint64 = struct_be_Q.unpack

pack_le_int32 = struct_le_i.pack
pack_le_int64 = struct_le_q.pack
Expand All @@ -337,6 +340,7 @@ def protocol_version(client_req, min_tuple, max_tuple):
pack_le_uint64 = struct_le_Q.pack
pack_be_uint16 = struct_be_H.pack
pack_be_uint32 = struct_be_I.pack
pack_be_uint64 = struct_be_Q.pack
pack_byte = structB.pack

hex_to_bytes = bytes.fromhex
Expand Down
Loading