diff --git a/.travis.yml b/.travis.yml index b47659f..e0f7ac3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,7 @@ install: - pip install pycodestyle - pip install pylru - pip install pyrocksdb + - pip install pytest-asyncio - pip install pytest-cov - pip install Sphinx # hashes diff --git a/compact_history.py b/compact_history.py index 9186c64..0a4574b 100755 --- a/compact_history.py +++ b/compact_history.py @@ -48,7 +48,7 @@ async def compact_history(): environ['DAEMON_URL'] = '' # Avoid Env erroring out env = Env() db = DB(env) - await db.open_for_sync() + await db.open_for_compacting() assert not db.first_sync history = db.history diff --git a/contrib/query.py b/contrib/query.py index 955ff37..56dbda8 100755 --- a/contrib/query.py +++ b/contrib/query.py @@ -62,7 +62,7 @@ async def query(args): db = DB(env) coin = env.coin - await db._open_dbs(False) + await db.open_for_serving() if not args.scripts: await print_stats(db.hist_db, db.utxo_db) @@ -73,20 +73,23 @@ async def query(args): if not hashX: continue n = None - for n, (tx_hash, height) in enumerate(db.get_history(hashX, limit), - start=1): + history = await db.limited_history(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)}') if n is None: print('No history found') n = None - for n, utxo in enumerate(db.get_utxos(hashX, limit), start=1): + utxos = await db.all_utxos(hashX) + for n, utxo in enumerate(utxos, start=1): print(f'UTXO #{n:,d}: tx_hash {hash_to_hex_str(utxo.tx_hash)} ' f'tx_pos {utxo.tx_pos:,d} height {utxo.height:,d} ' f'value {utxo.value:,d}') + if n == limit: + break if n is None: print('No UTXOs found') - balance = db.get_balance(hashX) + balance = sum(utxo.value for utxo in utxos) print(f'Balance: {coin.decimal_value(balance):,f} {coin.SHORTNAME}') diff --git a/docs/protocol-changes.rst b/docs/protocol-changes.rst index fc0a4fe..7c0bcdd 100644 --- a/docs/protocol-changes.rst +++ b/docs/protocol-changes.rst @@ -146,3 +146,63 @@ Removed methods * :func:`blockchain.block.get_header` * :func:`blockchain.block.get_chunk` + +Version 1.5 +=========== + +This protocol version makes changes intended to allow clients and +servers to more easily scale to support queries about busy addresses. +It has changes to reduce the amount of round-trip queries made in +common usage, and to make results more compact to reduce bandwidth +consumption. + +RPC calls with potentially large responses have pagination support, +and the return value of :func:`blockchain.scripthash.subscribe` +changes. Script hash :ref:`status ` had to be recalculated +with each new transaction and was undefined if it included more than +one mempool transaction. Its calculation is linear in history length +resulting in quadratic complexity as history grows. Its calculation +for large histories was demanding for both the server to compute and +the client to check. + +RPC calls and notifications that combined the effects of the mempool +and confirmed history are removed. + +The changes are beneficial to clients and servers alike, but will +require changes to both client-side and server-side logic. In +particular, the client should track what block (by hash and height) +wallet data is synchronized to, and if that hash is no longer part of +the main chain, it will need to remove wallet data for blocks that +were reorganized away and get updated information as of the first +reorganized block. The effects are limited to script hashes +potentially affected by the reorg, and for most clients this will be +the empty set. + +New methods +----------- + + * :func:`blockchain.scripthash.history` + * :func:`blockchain.scripthash.utxos` + +New notifications +----------------- + + * :func:`mempool.changes` + +Changes +------- + + * :func:`blockchain.scripthash.subscribe` has changed its return value + and the notifications it sends + * :func:`blockchain.transaction.get` takes an additional optional + argument *merkle* + +Removed methods +--------------- + + * :func:`blockchain.scripthash.get_history`. Switch to + :func:`blockchain.scripthash.history` + * :func:`blockchain.scripthash.get_mempool`. Switch to + handling :func:`mempool.changes` notifications + * :func:`blockchain.scripthash.listunspent`. Switch to + :func:`blockchain.scripthash.utxos` diff --git a/docs/protocol-methods.rst b/docs/protocol-methods.rst index ee10416..a37e19f 100644 --- a/docs/protocol-methods.rst +++ b/docs/protocol-methods.rst @@ -50,7 +50,7 @@ Return the block header at the given height. **Example Result** -With *cp_height* zero: +With *height* 5 and *cp_height* 0 on the Bitcoin Cash chain: :: @@ -58,7 +58,7 @@ With *cp_height* zero: .. _cp_height example: -With *cp_height* 8 on the Bitcoin Cash chain:: +With *cp_height* 8:: { "branch": [ @@ -310,166 +310,68 @@ Return the confirmed and unconfirmed balances of a :ref:`script hash "unconfirmed": "0.236844" } -blockchain.scripthash.get_history -================================= +blockchain.scripthash.history +============================= -Return the confirmed and unconfirmed history of a :ref:`script hash -