atomicals / atomicals-electrumx

Electrumx Atomicals Indexer Server
MIT License
187 stars 55 forks source link

fix CBORTag #165

Closed shadowv0vshadow closed 7 months ago

shadowv0vshadow commented 7 months ago

In testnet block processor, We found some invalid payload.

...  File "/usr/local/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 685, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/Documents/atomicals-electrumx/electrumx/lib/server_base.py", line 129, in run
    await server_task
  File "/Users/Documents/atomicals-electrumx/electrumx/lib/server_base.py", line 102, in serve
    await self.serve(shutdown_event)
  File "/Users/Documents/atomicals-electrumx/electrumx/server/controller.py", line 134, in serve
    async with OldTaskGroup() as group:
  File "/Users/Documents/atomicals-electrumx/venv/lib/python3.12/site-packages/aiorpcx/curio.py", line 297, in aexit
    await self.join()
  File "/Users/Documents/atomicals-electrumx/electrumx/lib/util.py", line 370, in join
    task.result()
  File "/Users/Documents/atomicals-electrumx/electrumx/server/block_processor.py", line 3586, in fetch_and_process_blocks
    async with OldTaskGroup() as group:
  File "/Users/Documents/atomicals-electrumx/venv/lib/python3.12/site-packages/aiorpcx/curio.py", line 297, in aexit
    await self.join()
  File "/Users/Documents/atomicals-electrumx/electrumx/lib/util.py", line 370, in join
    task.result()
  File "/Users/Documents/atomicals-electrumx/electrumx/server/block_processor.py", line 3548, in _process_prefetched_blocks
    await self.check_and_advance_blocks(blocks)
  File "/Users/Documents/atomicals-electrumx/electrumx/server/block_processor.py", line 330, in check_and_advance_blocks
    await self.run_in_thread_with_lock(self.advance_blocks, blocks)
  File "/Users/Documents/atomicals-electrumx/electrumx/server/block_processor.py", line 313, in run_in_thread_with_lock
    return await asyncio.shield(run_in_thread_locked())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Documents/atomicals-electrumx/electrumx/server/block_processor.py", line 312, in run_in_thread_locked
    return await run_in_thread(func, *args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Documents/atomicals-electrumx/venv/lib/python3.12/site-packages/aiorpcx/curio.py", line 57, in run_in_thread
    return await get_event_loop().run_in_executor(None, func, *args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Documents/atomicals-electrumx/electrumx/server/block_processor.py", line 515, in advance_blocks
    undo_info, atomicals_undo_info = self.advance_txs(block.transactions, is_unspendable, block.header, height)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Documents/atomicals-electrumx/electrumx/server/block_processor.py", line 2972, in advance_txs
    created_atomical_id = self.create_or_delete_atomical(atomicals_operations_found_at_inputs, atomicals_spent_at_inputs, header, height, tx_num, atomical_num, tx, tx_hash, False)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Documents/atomicals-electrumx/electrumx/server/block_processor.py", line 1568, in create_or_delete_atomical
    self.put_or_delete_init_state_updates(mint_info, operations_found_at_inputs['payload'], Delete)
  File "/Users/Documents/atomicals-electrumx/electrumx/server/block_processor.py", line 1620, in put_or_delete_init_state_updates
    copied_data_state = copy.deepcopy(data_payload)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/copy.py", line 136, in deepcopy
    y = copier(x, memo)
        ^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/copy.py", line 221, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
                             ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/copy.py", line 136, in deepcopy
    y = copier(x, memo)
        ^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/copy.py", line 221, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
                             ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/copy.py", line 151, in deepcopy
    rv = reductor(4)
         ^^^^^^^^^^^
TypeError: cannot pickle '_cbor2.CBORTag' object
...

Deepcopy cannot pickle '_cbor2.CBORTag' object, so we change deepcopy to a new dict. And we also change auto_encode_bytes_elements.