rotki / rotki

A portfolio tracking, analytics, accounting and management application that protects your privacy
https://rotki.com
GNU Affero General Public License v3.0
2.87k stars 525 forks source link

PnL Report Error #7273

Closed dsystems-io closed 8 months ago

dsystems-io commented 10 months ago

Problem Definition

Profit and Loss Generator throws an error after generation. The resulting report shows $0.00 under "Taxable PnL" for all lines, despite taxable amount > 0. Error message shows:

An unexpected response was received while generating the profit and loss report. This might indicate an issue with the generation mechanism. Please check the logs for any error messages (you might have to enable debug logging first) and create an issue.

The backend query task died unexpectedly: [<class 'decimal.DivisionByZero'>]

I have Etherscan and Coinbase API's hooked up.

Logs

Address subbed with 0x000. This line was repeated over 100 times with different addresses and timestamps.

[11/01/2024 09:59:38 PST] ERROR rotkehlchen.tasks.utils Greenlet-0: Failed to find price for eip155:1/erc20:0x000 at 1704058427 in history event with identifier=5728. Unable to query a historical price for "eip155:1/erc20:0x000" to "USD" at 31/12/2023, 13:33:47. [11/01/2024 10:00:12 PST] ERROR rotkehlchen.api.rest Greenlet with id 139628983589248: Greenlet for task 30 dies with exception: [<class 'decimal.DivisionByZero'>]. Exception Name: <class 'decimal.DivisionByZero'> Exception Info: [<class 'decimal.DivisionByZero'>] Traceback: File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run File "rotkehlchen/api/rest.py", line 417, in _do_query_async File "rotkehlchen/api/rest.py", line 1532, in process_history File "rotkehlchen/rotkehlchen.py", line 847, in process_history File "rotkehlchen/accounting/accountant.py", line 167, in process_history File "rotkehlchen/accounting/accountant.py", line 307, in _process_event File "rotkehlchen/exchanges/data_structures.py", line 393, in process File "rotkehlchen/accounting/pot.py", line 269, in add_out_event File "rotkehlchen/accounting/cost_basis/base.py", line 698, in spend_asset File "rotkehlchen/accounting/cost_basis/base.py", line 601, in reduce_asset_amount File "rotkehlchen/accounting/cost_basis/base.py", line 378, in consume_result File "rotkehlchen/fval.py", line 98, in truediv

System Description

Operating system: PopOS 22.04 Rotki version: 1.31.2

LefterisJP commented 10 months ago

Hey @dsystems-io thanks a lot for opening a detailed issue with a traceback included! Weird, we have never seen this division by zero error before. What exact settings did you use for accounting to generate this report?

Is it the average cost basis method that did it? Does it happen with other methods?

Any more logs around the error? More details on what events were being processed?

We can also have more real time and you can chat with other users and the dev team via discord: https://discord.rotki.com/

dsystems-io commented 10 months ago

Hey @LefterisJP . I've attached a screenshot of the accounting settings. I tried again with FIFO instead of ACB and it worked. Seems to only affect the ACB method. There weren't any other logs around the error, just a repetition of the first line of the logs I posted with different addresses and times.

Screenshot from 2024-01-11 21-26-19

dsystems-io commented 10 months ago

So I went back and fixed all the missing prices. Now I still get the same error, but there are no more "Failed to find price for EIP..." messages. Here's the entirety of the log now:

[11/01/2024 22:21:52 PST] ERROR rotkehlchen.api.rest Greenlet with id 140276300690880: Greenlet for task 34 dies with exception: [<class 'decimal.DivisionByZero'>]. Exception Name: <class 'decimal.DivisionByZero'> Exception Info: [<class 'decimal.DivisionByZero'>] Traceback: File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run File "rotkehlchen/api/rest.py", line 417, in _do_query_async File "rotkehlchen/api/rest.py", line 1532, in process_history File "rotkehlchen/rotkehlchen.py", line 847, in process_history File "rotkehlchen/accounting/accountant.py", line 167, in process_history File "rotkehlchen/accounting/accountant.py", line 307, in _process_event File "rotkehlchen/exchanges/data_structures.py", line 393, in process File "rotkehlchen/accounting/pot.py", line 269, in add_out_event File "rotkehlchen/accounting/cost_basis/base.py", line 698, in spend_asset File "rotkehlchen/accounting/cost_basis/base.py", line 601, in reduce_asset_amount File "rotkehlchen/accounting/cost_basis/base.py", line 378, in consume_result File "rotkehlchen/fval.py", line 98, in truediv

LefterisJP commented 10 months ago

hey @dsystems-io thanks! This is gonna be easier if you hop in discord to chat. The reason for not enough logs is probably you don't have debug logs activated. You can do it by following what's said here: https://rotki.readthedocs.io/en/latest/contribute.html#id2

Then we could have some more context on the type of event that creates this error and perhaps the order in which we get into the division by zero.

LefterisJP commented 8 months ago

Closing this issue as we have reproduced and log this and handle it better.

This can happen if you somehow have negative amounts in events and use ACB. Should be fixed if you find and fix those negative amount events.