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

[v11.0.0] Kill Addrindexrs #2343

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
7 changes: 6 additions & 1 deletion counterparty-core/counterpartycore/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ def float_range_checker(arg):
"help": "number of worker processes for gunicorn",
},
],
[
("--electr-url",),
{
"help": "the URL of the Electrum server",
},
],
]


Expand All @@ -344,7 +350,6 @@ def welcome_message(action, server_configfile):
pass_str = f":{urlencode(config.BACKEND_PASSWORD)}@"
cleaned_backend_url = config.BACKEND_URL.replace(pass_str, ":*****@")
cprint(f"Bitcoin Core: {cleaned_backend_url}", "light_grey")
cprint(f"AddrIndexRs: {config.INDEXD_URL}", "light_grey")

api_url = "http://"
if config.API_USER and config.API_PASSWORD:
Expand Down
1 change: 1 addition & 0 deletions counterparty-core/counterpartycore/lib/api/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ def handle_route(**kwargs):
exceptions.UnpackError,
CBitcoinAddressError,
script.AddressError,
exceptions.ElectrError,
) as e:
return return_result(400, error=str(e), start_time=start_time, query_args=query_args)
except Exception as e:
Expand Down
18 changes: 3 additions & 15 deletions counterparty-core/counterpartycore/lib/api/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
)
from counterpartycore.lib.messages.versions import enhanced_send # noqa: E402
from counterpartycore.lib.telemetry.util import ( # noqa: E402
get_addrindexrs_version,
get_uptime,
is_docker,
is_force_enabled,
Expand Down Expand Up @@ -832,8 +831,6 @@

server_ready = caught_up and indexd_caught_up

addrindexrs_version = get_addrindexrs_version().split(".")

return {
"server_ready": server_ready,
"db_caught_up": caught_up,
Expand All @@ -849,9 +846,6 @@
"version_major": config.VERSION_MAJOR,
"version_minor": config.VERSION_MINOR,
"version_revision": config.VERSION_REVISION,
"addrindexrs_version_major": int(addrindexrs_version[0]),
"addrindexrs_version_minor": int(addrindexrs_version[1]),
"addrindexrs_version_revision": int(addrindexrs_version[2]),
"uptime": int(get_uptime()),
"dockerized": is_docker(),
"force_enabled": is_force_enabled(),
Expand Down Expand Up @@ -930,17 +924,13 @@

@dispatcher.add_method
def search_raw_transactions(address, unconfirmed=True, only_tx_hashes=False):
return backend.addrindexrs.search_raw_transactions(
return backend.electr.get_history(

Check warning

Code scanning / pylint

Unexpected keyword argument 'only_tx_hashes' in function call. Warning

Unexpected keyword argument 'only_tx_hashes' in function call.
address, unconfirmed=unconfirmed, only_tx_hashes=only_tx_hashes
)

@dispatcher.add_method
def get_oldest_tx(address):
return backend.addrindexrs.get_oldest_tx(address, block_index=util.CURRENT_BLOCK_INDEX)

@dispatcher.add_method
def get_unspent_txouts(address, unconfirmed=False, unspent_tx_hash=None, order_by=None):
results = backend.addrindexrs.get_unspent_txouts(
results = backend.electr.get_utxos(
address, unconfirmed=unconfirmed, unspent_tx_hash=unspent_tx_hash
)
if order_by is None:
Expand All @@ -959,9 +949,7 @@

@dispatcher.add_method
def getrawtransaction_batch(txhash_list, verbose=False, skip_missing=False):
return backend.addrindexrs.getrawtransaction_batch(
txhash_list, verbose=verbose, skip_missing=skip_missing
)
return backend.bitcoind.getrawtransaction_batch(txhash_list)

@dispatcher.add_method
def get_tx_info(tx_hex, block_index=None):
Expand Down
2 changes: 1 addition & 1 deletion counterparty-core/counterpartycore/lib/api/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def compose_dispenser(
:param escrow_quantity: The quantity of the asset to reserve for this dispenser (in satoshis, hence integer) (e.g. 1000)
:param mainchainrate: The quantity of the main chain asset (BTC) per dispensed portion (in satoshis, hence integer) (e.g. 100)
:param status: The state of the dispenser. 0 for open, 1 for open using open_address, 10 for closed (e.g. 0)
:param open_address: The address that you would like to open the dispenser on; MUST be equal to `address` from block 900000 onwards
:param open_address: The address that you would like to open the dispenser on; MUST be equal to `address` from block 866000 onwards
:param oracle_address: The address that you would like to use as a price oracle for this dispenser
"""
params = {
Expand Down
9 changes: 4 additions & 5 deletions counterparty-core/counterpartycore/lib/api/routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from counterpartycore.lib.api import compose, queries, util
from counterpartycore.lib.backend import addrindexrs, bitcoind
from counterpartycore.lib.backend import bitcoind, electr


def get_routes():
Expand Down Expand Up @@ -161,10 +161,9 @@ def get_routes():
"/v2/fairminters/<tx_hash>": queries.get_fairminter,
"/v2/fairminters/<tx_hash>/mints": queries.get_fairmints_by_fairminter,
### /bitcoin ###
"/v2/bitcoin/addresses/utxos": addrindexrs.get_unspent_txouts_by_addresses,
"/v2/bitcoin/addresses/<address>/transactions": addrindexrs.get_transactions_by_address,
"/v2/bitcoin/addresses/<address>/transactions/oldest": util.get_oldest_transaction_by_address,
"/v2/bitcoin/addresses/<address>/utxos": addrindexrs.get_unspent_txouts,
"/v2/bitcoin/addresses/utxos": electr.get_utxos_by_addresses,
"/v2/bitcoin/addresses/<address>/transactions": electr.get_history,
"/v2/bitcoin/addresses/<address>/utxos": electr.get_utxos,
"/v2/bitcoin/addresses/<address>/pubkey": util.pubkeyhash_to_pubkey,
"/v2/bitcoin/transactions/<tx_hash>": util.get_transaction,
"/v2/bitcoin/estimatesmartfee": bitcoind.fee_per_kb,
Expand Down
11 changes: 0 additions & 11 deletions counterparty-core/counterpartycore/lib/api/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,6 @@ def get_transaction(tx_hash: str, format: str = "json"):
return backend.bitcoind.getrawtransaction(tx_hash, verbose=format == "json")


def get_oldest_transaction_by_address(address: str, block_index: int = None):
"""
Get the oldest transaction for an address.
:param address: The address to search for. (e.g. $ADDRESS_9)
:param block_index: The block index to search from.
"""
return backend.addrindexrs.get_oldest_tx(
address, block_index=block_index or util.CURRENT_BLOCK_INDEX
)


def get_backend_height():
block_count = backend.bitcoind.getblockcount()
blocks_behind = backend.bitcoind.get_blocks_behind()
Expand Down
5 changes: 2 additions & 3 deletions counterparty-core/counterpartycore/lib/api/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import gunicorn.app.base
import waitress
import waitress.server
from counterpartycore.lib import backend, config, ledger, util
from counterpartycore.lib import config, ledger, util
from counterpartycore.lib.api.util import get_backend_height
from counterpartycore.lib.database import get_db_connection
from flask import request
Expand Down Expand Up @@ -65,7 +65,6 @@ def refresh_backend_height(db, start=False):
BACKEND_HEIGHT = get_backend_height()
# print(f"BACKEND_HEIGHT: {BACKEND_HEIGHT} ({os.getpid()})")
refresh_current_block(db)
backend.addrindexrs.clear_raw_transactions_cache()
if not is_server_ready():
if BACKEND_HEIGHT > util.CURRENT_BLOCK_INDEX:
logger.debug(
Expand All @@ -76,7 +75,7 @@ def refresh_backend_height(db, start=False):
f"Bitcoin Core is currently behind the network. ({util.CURRENT_BLOCK_INDEX} > {BACKEND_HEIGHT})"
)
else:
# starting the timer is not blocking in case of Addrindexrs is not ready
# starting the timer is not blocking in case of Bitcoin Core is not ready
BACKEND_HEIGHT_TIMER = Timer(0.5, refresh_backend_height, (db,))
BACKEND_HEIGHT_TIMER.start()
return
Expand Down
Loading
Loading