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

Kill Addrindexrs #2864

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions .github/workflows/propertytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ jobs:
cd counterparty-rs && pip install -e . && cd ..
cd counterparty-core && pip install -e . && cd ..
pip install evdev
git clone https://github.com/CounterpartyXCP/addrindexrs.git
cd addrindexrs
cargo install --path=.
wget https://bitcoincore.org/bin/bitcoin-core-27.1/bitcoin-27.1-x86_64-linux-gnu.tar.gz
tar -xvf bitcoin-27.1-x86_64-linux-gnu.tar.gz
sudo cp bitcoin-27.1/bin/bitcoin-cli /usr/local/bin/bitcoin-cli
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/regtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ jobs:
cd counterparty-rs && pip install -e . && cd ..
cd counterparty-core && pip install -e . && cd ..
pip install evdev
git clone https://github.com/CounterpartyXCP/addrindexrs.git
cd addrindexrs
cargo install --path=.
wget https://bitcoincore.org/bin/bitcoin-core-27.1/bitcoin-27.1-x86_64-linux-gnu.tar.gz
tar -xvf bitcoin-27.1-x86_64-linux-gnu.tar.gz
sudo cp bitcoin-27.1/bin/bitcoin-cli /usr/local/bin/bitcoin-cli
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test_compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ sudo touch $LOG_PATH
docker compose --profile mainnet stop counterparty-core
docker compose --profile mainnet run counterparty-core reparse $REPARSE_FROM \
--backend-connect=bitcoind \
--indexd-connect=addrindexrs \
--rpc-host=0.0.0.0 \
--api-host=0.0.0.0

Expand Down
5,103 changes: 2,288 additions & 2,815 deletions apiary.apib

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions counterparty-core/counterpartycore/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,6 @@ def float_range_checker(arg):
"help": "pubkey to receive dust when multisig encoding is used for P2SH source (default: none)"
},
],
[
("--indexd-connect",),
{"default": "localhost", "help": "the hostname or IP of the indexd server"},
],
[("--indexd-port",), {"type": int, "help": "the indexd server port to connect to"}],
[
("--rpc-host",),
{
Expand Down Expand Up @@ -365,6 +360,12 @@ def float_range_checker(arg):
},
],
[("--bootstrap-url",), {"type": str, "help": "the URL of the bootstrap snapshot to use"}],
[
("--electr-url",),
{
"help": "the URL of the Electrum server",
},
],
]


Expand All @@ -384,7 +385,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
9 changes: 7 additions & 2 deletions counterparty-core/counterpartycore/lib/api/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,18 @@
exceptions.UnpackError,
CBitcoinAddressError,
script.AddressError,
exceptions.ElectrError,
) as e:
import traceback

Check warning

Code scanning / pylint

Import outside toplevel (traceback). Warning

Import outside toplevel (traceback).

print(traceback.format_exc())
return return_result(400, error=str(e), start_time=start_time, query_args=query_args)
except Exception as e:
capture_exception(e)
logger.error("Error in API: %s", e)
# import traceback
# print(traceback.format_exc())
import traceback

Check warning

Code scanning / pylint

Import outside toplevel (traceback). Warning

Import outside toplevel (traceback).

print(traceback.format_exc())
return return_result(
503, error="Unknown error", start_time=start_time, query_args=query_args
)
Expand Down
34 changes: 12 additions & 22 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 @@ -132,7 +131,7 @@
# check backend index
blocks_behind = backend.bitcoind.get_blocks_behind()
if blocks_behind > 5:
raise BackendError(f"Indexd is running {blocks_behind} blocks behind.")
raise BackendError(f"Bitcoind is running {blocks_behind} blocks behind.")

logger.debug("API Status Poller - Backend state check passed.")

Expand Down Expand Up @@ -820,22 +819,20 @@
last_message = None

try:
indexd_blocks_behind = backend.bitcoind.get_blocks_behind()
bitcoind_blocks_behind = backend.bitcoind.get_blocks_behind()
except: # noqa: E722
indexd_blocks_behind = latest_block_index if latest_block_index > 0 else 999999
indexd_caught_up = indexd_blocks_behind <= 1
bitcoind_blocks_behind = latest_block_index if latest_block_index > 0 else 999999
bitcoind_caught_up = bitcoind_blocks_behind <= 1

server_ready = caught_up and indexd_caught_up

addrindexrs_version = get_addrindexrs_version().split(".")
server_ready = caught_up and bitcoind_caught_up

return {
"server_ready": server_ready,
"db_caught_up": caught_up,
"bitcoin_block_count": latest_block_index,
"last_block": last_block,
"indexd_caught_up": indexd_caught_up,
"indexd_blocks_behind": indexd_blocks_behind,
"bitcoind_caught_up": bitcoind_caught_up,
"bitcoind_blocks_behind": bitcoind_blocks_behind,
"last_message_index": (last_message["message_index"] if last_message else -1),
"api_limit_rows": config.API_LIMIT_ROWS,
"running_testnet": config.TESTNET,
Expand All @@ -844,9 +841,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 @@ -925,17 +919,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 @@ -953,9 +943,9 @@
return backend.bitcoind.getrawtransaction(tx_hash, verbose=verbose)

@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
def getrawtransaction_batch(txhash_list, verbose=False):
return backend.bitcoind.getrawtransaction_batch(
txhash_list, verbose=verbose, return_dict=True
)

@dispatcher.add_method
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 @@ -172,10 +172,9 @@ def get_routes():
"/v2/fairmints": queries.get_all_fairmints,
"/v2/fairmints/<tx_hash>": queries.get_fairmint,
### /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 @@ -155,17 +155,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
4 changes: 1 addition & 3 deletions counterparty-core/counterpartycore/lib/api/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import gunicorn.app.base
import waitress
import waitress.server
from counterpartycore.lib import backend, config, database, ledger, log, util
from counterpartycore.lib import config, database, ledger, log, util
from counterpartycore.lib.api import api_watcher
from counterpartycore.lib.api.util import BackendHeight
from gunicorn import util as gunicorn_util
Expand All @@ -34,8 +34,6 @@ def refresh_current_state(ledger_db, state_db):
util.CURRENT_BLOCK_TIME = 0
util.CURRENT_BLOCK_INDEX = 0

backend.addrindexrs.clear_raw_transactions_cache()

if util.CURRENT_BACKEND_HEIGHT > util.CURRENT_BLOCK_INDEX:
logger.debug(
f"Counterparty is currently behind Bitcoin Core. ({util.CURRENT_BLOCK_INDEX} < {util.CURRENT_BACKEND_HEIGHT})"
Expand Down
Loading
Loading