1200wd / bitcoinlib

Bitcoin and other Cryptocurrencies Library for Python. Includes a fully functional wallet, Mnemonic key generation and management and connection with various service providers to receive and send blockchain and transaction information.
http://bitcoinlib.readthedocs.io/
GNU General Public License v3.0
614 stars 204 forks source link

Errors decoding block #356

Closed yoprogramo closed 10 months ago

yoprogramo commented 11 months ago

Hello,

I'm doing a loop to search for wallets into transactions in new blocks... Usually it works fine, I retrieve the block i doing client.getBlock(i) and during the weekend everything works as expected on testnet, but today I'm receiving this errors:

btcservice  | 2023-12-05T09:42:03.179627223Z Traceback (most recent call last):
btcservice  | 2023-12-05T09:42:03.179631567Z   File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/bitcoinlib/keys.py", line 780, in __init__
btcservice  | 2023-12-05T09:42:03.180614531Z     kf = get_key_format(import_key)
btcservice  | 2023-12-05T09:42:03.180627334Z   File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/bitcoinlib/keys.py", line 220, in get_key_format
btcservice  | 2023-12-05T09:42:03.180632682Z     raise BKeyError("Unrecognised key format")
btcservice  | 2023-12-05T09:42:03.180637248Z bitcoinlib.keys.BKeyError: Unrecognised key format
btcservice  | 2023-12-05T09:42:03.180641718Z 
btcservice  | 2023-12-05T09:42:03.180646025Z During handling of the above exception, another exception occurred:
btcservice  | 2023-12-05T09:42:03.180650807Z 
btcservice  | 2023-12-05T09:42:03.180655016Z Traceback (most recent call last):
btcservice  | 2023-12-05T09:42:03.180659519Z   File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
btcservice  | 2023-12-05T09:42:03.180664251Z     self.run()
btcservice  | 2023-12-05T09:42:03.180668493Z   File "/usr/lib/python3.10/threading.py", line 1378, in run
btcservice  | 2023-12-05T09:42:03.182117433Z     self.function(*self.args, **self.kwargs)
btcservice  | 2023-12-05T09:42:03.182130993Z   File "/app/worker/watcher.py", line 76, in checkWalletsByBlocks
btcservice  | 2023-12-05T09:42:03.182135874Z     tx = self.checkHashTransactions(wallet['hash'],blockFrom)
btcservice  | 2023-12-05T09:42:03.182139984Z   File "/app/worker/watcher.py", line 270, in checkHashTransactions
btcservice  | 2023-12-05T09:42:03.182144661Z     block = client.getblock(i)
btcservice  | 2023-12-05T09:42:03.182149149Z   File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/bitcoinlib/services/services.py", line 544, in getblock
btcservice  | 2023-12-05T09:42:03.182179974Z     txs = self.cache.getblocktransactions(block.height, page, limit)
btcservice  | 2023-12-05T09:42:03.182184931Z   File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/bitcoinlib/services/services.py", line 854, in getblocktransactions
btcservice  | 2023-12-05T09:42:03.182189737Z     t = self._parse_db_transaction(db_tx)
btcservice  | 2023-12-05T09:42:03.182194056Z   File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/bitcoinlib/services/services.py", line 736, in _parse_db_transaction
btcservice  | 2023-12-05T09:42:03.182198824Z     t.add_input(n.ref_txid.hex(), n.ref_index_n, unlocking_script=n.script, address=n.address,
btcservice  | 2023-12-05T09:42:03.182203317Z   File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/bitcoinlib/transactions.py", line 2355, in add_input
btcservice  | 2023-12-05T09:42:03.183403243Z     Input(prev_txid=prev_txid, output_n=output_n, keys=keys, signatures=signatures, public_hash=public_hash,
btcservice  | 2023-12-05T09:42:03.183415130Z   File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/bitcoinlib/transactions.py", line 862, in __init__
btcservice  | 2023-12-05T09:42:03.183420088Z     self.keys = [Key(self.witnesses[1], network=self.network)]
btcservice  | 2023-12-05T09:42:03.183423850Z   File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/bitcoinlib/keys.py", line 783, in __init__
btcservice  | 2023-12-05T09:42:03.183428279Z     raise BKeyError("Unrecognised key format")
btcservice  | 2023-12-05T09:42:03.183432220Z bitcoinlib.keys.BKeyError: Unrecognised key format

There are some way we can avoid these errors and continue parsing the rest of transactions skiping these ones?

yoprogramo commented 11 months ago

I think I have found the error, hat is not propagate the strict flag to the key creation (at least in transaction parsing). I have included a change in: https://github.com/1200wd/bitcoinlib/pull/352/commits/4ee79c9c6baf6d7d9159a7316552ea79729f4f02

mccwdev commented 11 months ago

Yes, I think you are right. Do you want to create a pull request so I can merge, or shall I just update the code?

yoprogramo commented 11 months ago

I think it is already included in the previous pull request as the last commit.

mccwdev commented 10 months ago

PR merged in release 0.6.14