DefiantLabs / cosmos-upgrades

a tool to search for scheduled cosmos upgrades
MIT License
4 stars 2 forks source link

Datetime format string error during update loop #27

Open pharr117 opened 11 months ago

pharr117 commented 11 months ago

One of the update loop iterations is failing on a bad date string:

cosmos-upgrades Completed fetch data for network rsprovidertestnet                                                                                                       │
│ cosmos-upgrades Completed fetch data for network persistencetestnet2                                                                                                     │
│ cosmos-upgrades Completed fetch data for network sixtestnet                                                                                                              │
│ cosmos-upgrades Found 1 rest endpoints and 1 rpc endpoints for permtestnet                                                                                               │
│ cosmos-upgrades 35.191.10.132 - - [19/Oct/2023 17:44:11] "GET /healthz HTTP/1.1" 200 -                                                                                   │
│ cosmos-upgrades Completed fetch data for network permtestnet                                                                                                             │
│ cosmos-upgrades Traceback (most recent call last):                                                                                                                       │
│ cosmos-upgrades   File "/app/app.py", line 703, in update_data                                                                                                           │
│ cosmos-upgrades     testnet_data = list(                                                                                                                                 │
│ cosmos-upgrades   File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 609, in result_iterator                                                              │
│ cosmos-upgrades     yield fs.pop().result()                                                                                                                              │
│ cosmos-upgrades   File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 439, in result                                                                       │
│ cosmos-upgrades     return self.__get_result()                                                                                                                           │
│ cosmos-upgrades   File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 391, in __get_result                                                                 │
│ cosmos-upgrades     raise self._exception                                                                                                                                │
│ cosmos-upgrades   File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run                                                                          │
│ cosmos-upgrades     result = self.fn(*self.args, **self.kwargs)                                                                                                          │
│ cosmos-upgrades   File "/app/app.py", line 707, in <lambda>                                                                                                              │
│ cosmos-upgrades     lambda network, path: fetch_data_for_network(                                                                                                        │
│ cosmos-upgrades   File "/app/app.py", line 623, in fetch_data_for_network                                                                                                │
│ cosmos-upgrades     current_block_datetime = parse_isoformat_string(current_block_time)                                                                                  │
│ cosmos-upgrades   File "/app/app.py", line 207, in parse_isoformat_string                                                                                                │
│ cosmos-upgrades     return datetime.fromisoformat(date_string)                                                                                                           │
│ cosmos-upgrades Error in update_data loop after 95.593695 seconds: Invalid isoformat string: '2023-10-19T17:43:49.9951+00:00'                                            │
│ cosmos-upgrades Error encountered. Sleeping for 1 minute before retrying...                                                                                              │
│ cosmos-upgrades ValueError: Invalid isoformat string: '2023-10-19T17:43:49.9951+00:00'                                                                                   │
│ cosmos-upgrades 35.191.10.130 - - [19/Oct/2023 17:44:12] "GET /healthz HTTP/1.1" 200 -

We need to catch the error and/or parse the string differently depending on the issue.

pharr117 commented 11 months ago

The error is here:

https://github.com/DefiantLabs/cosmos-upgrades/blob/b595fed83bd47f840f568a7d2699586d5fa36162/app.py#L617-L627

This means that the RPC endpoint is giving back a date that is not ISO format. I will need to figure out which network is throwing the error and what date format it is returning.

pharr117 commented 11 months ago

This actually has to do with the time returned by the RPC endpoint having a variable number of milliseconds.

We had anticipated this in our date parser function here:

https://github.com/DefiantLabs/cosmos-upgrades/blob/b595fed83bd47f840f568a7d2699586d5fa36162/app.py#L204-L207

However, the regex only looks for times that have MORE than 6 levels of precision, and the error is indicating 5 levels of precision: 2023-10-19T17:43:49.9951+00:00.

I will try to just turn the regex into a string split + add/remove levels of precision to get to the required 6 levels of precision for ISO.