MikaLendingBot icon indicating copy to clipboard operation
MikaLendingBot copied to clipboard

Issue with AccountStats db initialization

Open seaduck13 opened this issue 8 years ago • 8 comments

Hello, I may be wrong about this, but it would appear that when the sqlite database is empty, AccountStats can't update correctly. I believe the issue is in AccountStats.py in the line 56:

if (self.get_db_version() == 0) and (self.get_first_timestamp() is not None):

If i'm not correct, the db_version is set to 0 when there's nothing in the database, but self.get_first_timestamp() will always return None if there is nothing in the database. I think this means that this if statement is never executed.

If this isn't correct, is there a standard way to initialize the database that I missed?

seaduck13 avatar Jun 01 '17 15:06 seaduck13

Hi, Thanks for reviewing the code.

In line 53 there is a call to fetch history the first time would be from BITCOIN_GENESIS_BLOCK_DATE (which also stores it in the DB). So if the call in line 53 worked and history was retrieved, self.get_first_timestamp() will not be None.

The logic of the if on line 56 is that if you don't have history so far there isn't a point to loop back and try and fetch the rest of the history.

Is there a reason why you are asking? is something not working as expected?

rnevet avatar Jun 01 '17 21:06 rnevet

I'm getting a constantly getting this message: self.log.log_error('AccountStats DB isn't ready.')

when I start. It repeats on the regular 5m period.

seaduck13 avatar Jun 01 '17 22:06 seaduck13

Well the DB tried to update it self every 5m, if it fails constantly for some reason you'll see that message.

Do you see other errors?

rnevet avatar Jun 02 '17 11:06 rnevet

No unfortunately not. Other than having sqlite3, and the python libraries for it, should there be anything else I need to do to get the DB working?

seaduck13 avatar Jun 02 '17 15:06 seaduck13

Not really, you can try deleting the sqlite3 file and restarting the bot.

rnevet avatar Jun 02 '17 15:06 rnevet

Actually, have you tested it with no loan history? On my account I just started loans and none have finished yet. What happens if the loan history is empty when it tries to fetch? I think get no results and nothing gets put in the database, right?

seaduck13 avatar Jun 02 '17 15:06 seaduck13

yeah... that makes sense now. :) Then you'll stop getting those errors ones one loan will be finished. Could improve on that maybe... there is no logic problem here.

rnevet avatar Jun 02 '17 15:06 rnevet

We should add a catch for this, or at least add a message explaining this could be the case.

Evanito avatar Jun 02 '17 17:06 Evanito