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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
env: add new cfg option "DAEMON_HAS_TXINDEX", and support "False"
SomberNight committed Oct 20, 2021
commit 90561efb1f5d33b8b32243954a8c1c255025a261
11 changes: 7 additions & 4 deletions docs/HOWTO.rst
Original file line number Diff line number Diff line change
@@ -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
14 changes: 8 additions & 6 deletions docs/environment.rst
Original file line number Diff line number Diff line change
@@ -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
@@ -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
11 changes: 8 additions & 3 deletions electrumx/server/daemon.py
Original file line number Diff line number Diff line change
@@ -277,11 +277,16 @@ async def relayfee(self):
network_info = await self.getnetworkinfo()
return network_info['relayfee']

async def getrawtransaction(self, hex_hash, verbose=False):
async def getrawtransaction(self, hex_hash, verbose=False, blockhash=None):
'''Return the serialized raw transaction with the given hash.'''
# Cast to int because some coin daemons are old and require it
return await self._send_single('getrawtransaction',
(hex_hash, int(verbose)))
verbose = int(verbose)
if blockhash is None:
return await self._send_single('getrawtransaction', (hex_hash, verbose))
else:
# given a blockhash, modern bitcoind can lookup the tx even without txindex:
# https://github.com/bitcoin/bitcoin/pull/10275
return await self._send_single('getrawtransaction', (hex_hash, verbose, blockhash))

async def getrawtransactions(self, hex_hashes, replace_errs=True):
'''Return the serialized raw transactions with the given hashes.
1 change: 1 addition & 0 deletions electrumx/server/env.py
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@ def __init__(self, coin=None):
self.blacklist_url = self.default('BLACKLIST_URL', self.coin.BLACKLIST_URL)
self.cache_MB = self.integer('CACHE_MB', 1200)
self.reorg_limit = self.integer('REORG_LIMIT', self.coin.REORG_LIMIT)
self.daemon_has_txindex = self.boolean('DAEMON_HAS_TXINDEX', True)

# Server limits to help prevent DoS

14 changes: 12 additions & 2 deletions electrumx/server/session.py
Original file line number Diff line number Diff line change
@@ -1436,12 +1436,22 @@ async def transaction_get(self, tx_hash, verbose=False):
tx_hash: the transaction hash as a hexadecimal string
verbose: passed on to the daemon
'''
assert_tx_hash(tx_hash)
tx_hash_bytes = assert_tx_hash(tx_hash)
tx_hash_hex = tx_hash
del tx_hash
if verbose not in (True, False):
raise RPCError(BAD_REQUEST, '"verbose" must be a boolean')

self.bump_cost(1.0)
return await self.daemon_request('getrawtransaction', tx_hash, verbose)

blockhash = None
if not self.env.daemon_has_txindex:
height, tx_pos = await self.db.get_blockheight_and_txpos_for_txhash(tx_hash_bytes)
if height is not None:
block_header = self.db.raw_header(height)
blockhash = self.coin.header_hash(block_header).hex()

return await self.daemon_request('getrawtransaction', tx_hash_hex, verbose, blockhash)

async def transaction_merkle(self, tx_hash, height=None):
'''Return the merkle branch to a confirmed transaction given its hash