CounterpartyXCP / counterparty-core

Counterparty Protocol Reference Implementation
http://counterparty.io
MIT License
283 stars 206 forks source link

`KeyError:` with `create_send` #1438

Closed adamkrellenstein closed 5 months ago

adamkrellenstein commented 6 months ago

Request

curl -X POST http://api2.counterparty.io:4000/api/ --user rpc:rpc -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json, text/javascript' --data-binary '{
                  "method" : "create_send",
                  "params" : {
              "source": "1JDogZS6tQcSxwfxhv6XKKjcyicYA4Feev",
              "destination": "1FwkKA9cqpNRFTpVaokdRjT9Xamvebrwcu",
              "asset": "XCP",
              "quantity": 100000000,
              "allow_unconfirmed_inputs": true,
              "fee": 1000
                  },
                  "jsonrpc" : "2.0",
                  "id" : 0
              }'

Logs

[2024-02-21 08:53:00][ERROR] API Exception: {'type': 'KeyError', 'args': (('34a671e5d562306c32cead3b78c5608a852b7302fd5ae89a1de07aebe1d8cb6d', 0),), 'message': "('34a671e5d562306c32cead3b78c5608a852b7302fd5ae89a1de07aebe1d8cb6d', 0)"}
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/jsonrpc/manager.py", line 108, in _get_responses
    result = method(*request.args, **request.kwargs)
  File "/counterparty-lib/counterpartylib/lib/api.py", line 585, in create_method
    return compose_transaction(self.db, name=tx, params=transaction_args, **common_args)
  File "/counterparty-lib/counterpartylib/lib/api.py", line 450, in compose_transaction
    segwit=segwit)
  File "/counterparty-lib/counterpartylib/lib/transaction.py", line 491, in construct
    regular_dust_size, disable_utxo_locks
  File "/counterparty-lib/counterpartylib/lib/transaction.py", line 157, in construct_coin_selection
    if make_outkey(output) not in filter_unspents_utxo_locks and make_outkey_vin_txid(output['txid'], output['vout']) not in filter_unspents_p2sh_locks:
  File "/counterparty-lib/counterpartylib/lib/transaction.py", line 95, in make_outkey_vin_txid
    UTXO_P2SH_ENCODING_LOCKS_CACHE[(txid, vout)] = make_outkey_vin(txhex, vout)
  File "/usr/local/lib/python3.6/dist-packages/cachetools/ttl.py", line 89, in __setitem__
    self.expire(time)
  File "/usr/local/lib/python3.6/dist-packages/cachetools/ttl.py", line 169, in expire
    cache_delitem(self, curr.key)
  File "/usr/local/lib/python3.6/dist-packages/cachetools/cache.py", line 62, in __delitem__
    del self.__data[key]
KeyError: ('34a671e5d562306c32cead3b78c5608a852b7302fd5ae89a1de07aebe1d8cb6d', 0)
adamkrellenstein commented 6 months ago

Restarting the process fixed this.

adamkrellenstein commented 6 months ago

Just ran into this again:

[2024-02-28 12:52:31][WARNING] Not storing [dispenser] tx [177605b808ff5a30e899b384f6051d794a86b0957fdc0382202d40b5aa753bca]: invalid: address doesnt has an open dispenser for asset A18175683752647750000
[2024-02-28 12:52:32][WARNING] Not storing [dispenser] tx [177605b808ff5a30e899b384f6051d794a86b0957fdc0382202d40b5aa753bca]: invalid: address doesnt has an open dispenser for asset A18175683752647750000
[2024-02-28 12:52:32][ERROR] API Exception: {'type': 'KeyError', 'args': (('bbab91d54f4c21422675fb2c2109fa3995a1c3e2a62d6cf5527606228cc13873', 0),), 'message': "('bbab91d54f4c21422675fb2c2109fa3995a1c3e2a62d6cf5527606228cc13873', 0)"}
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/jsonrpc/manager.py", line 108, in _get_responses
    result = method(*request.args, **request.kwargs)
  File "/counterparty-lib/counterpartylib/lib/api.py", line 585, in create_method
    return compose_transaction(self.db, name=tx, params=transaction_args, **common_args)
  File "/counterparty-lib/counterpartylib/lib/api.py", line 450, in compose_transaction
    segwit=segwit)
  File "/counterparty-lib/counterpartylib/lib/transaction.py", line 491, in construct
    regular_dust_size, disable_utxo_locks
  File "/counterparty-lib/counterpartylib/lib/transaction.py", line 157, in construct_coin_selection
    if make_outkey(output) not in filter_unspents_utxo_locks and make_outkey_vin_txid(output['txid'], output['vout']) not in filter_unspents_p2sh_locks:
  File "/counterparty-lib/counterpartylib/lib/transaction.py", line 95, in make_outkey_vin_txid
    UTXO_P2SH_ENCODING_LOCKS_CACHE[(txid, vout)] = make_outkey_vin(txhex, vout)
  File "/usr/local/lib/python3.6/dist-packages/cachetools/ttl.py", line 89, in __setitem__
    self.expire(time)
  File "/usr/local/lib/python3.6/dist-packages/cachetools/ttl.py", line 169, in expire
    cache_delitem(self, curr.key)
  File "/usr/local/lib/python3.6/dist-packages/cachetools/cache.py", line 62, in __delitem__
    del self.__data[key]
KeyError: ('bbab91d54f4c21422675fb2c2109fa3995a1c3e2a62d6cf5527606228cc13873', 0)
[2024-02-28 12:52:32][WARNING] Not storing [dispenser] tx [177605b808ff5a30e899b384f6051d794a86b0957fdc0382202d40b5aa753bca]: invalid: address doesnt has an open dispenser for asset A18175683752647750000
[2024-02-28 12:52:33][WARNING] Not storing [dispenser] tx [177605b808ff5a30e899b384f6051d794a86b0957fdc0382202d40b5aa753bca]: invalid: address doesnt has an open dispenser for asset A18175683752647750000
ouziel-slama commented 5 months ago

hum...at first glance it's a problem with the Python module cachetools which is not thread safe.. and the API runs in a different thread..

ouziel-slama commented 5 months ago

for reference see https://github.com/tkem/cachetools/issues/231