Closed yashasvi-ranawat closed 4 months ago
Why didn't the tests trigger?
Why didn't the tests trigger?
Good question. We've always had this issue I believe. The tests are supposed to run on your fork. I'll see if there's some settings preventing this in this repo.
Settings look OK...
Anyway, I'll review and test locally for now.
This is very clever! Nice work!
I'm thinking a way to mitigate this would be to cache the provider so the block height is not fetched every time.
I implemented a time-to-live cache for blockheight with cache time limit of 120s.
Implementation | Wall time |
---|---|
No blockheight based sanitation | 365ms |
Cached blockheight, first hit | 2.71s |
Cached blockheight, second hit | 1.05s |
Cached blockheight, no unresponsive bitcoin.com api, first hit | 1.34s |
Cached blockheight, no unresponsive bitcoin.com api, second hit | 514ms |
We can remove the second default API in BitcoinDotComAPI, which is the, now unresponsive, rest.bitcoin.com. It causes much delay in blockheight retrieval.
oh python 3.8 functools does not have cache! Although it'll be at its end-of-life this October; don't know if I want to implement a custom cache for it.
Thanks! Yes we can definitely remove rest.Bitcoin.com and drop Python 3.8 support.
However, there is already a caching system present in BitCash for currency conversion support: set_rate_cache_time
Why not use something like this instead? Just a question, no need to re-implement everything. I can submit a PR removing rest.Bitcoin.com in the meantime.
@yashasvi-ranawat I have prepared a PR removing rest.Bitcoin.com. Feel free to review it if you have the time (I completely understand if not; in which case I will merge).
However, there is already a caching system present in BitCash for currency conversion support: set_rate_cache_time
yeah, good idea! I'll have a look.
I had a look at the cache setup for rates API! It was similar to the one I added to utils, but was specific to use for rates API. I refactored the one in utils to cache multiple entries with LRU cache. This is now usable by both blockheight caching and rates caching. I updated the tests accordingly.
I further refactored to caching of sanitized endpoints, instead of endpoint's blockheight. This drastically improves wall time. | Implementation | Wall time |
---|---|---|
No blockheight based sanitisation | 365 ms | |
Cached sanitized endpoints, first hit | 1.28 s | |
Cached sanitized endpoints, second hit | 198 ms |
This PR is ready for review!
A method is added to NetworkAPI that sanitizes the endpoints; where the endpoints that are unreachable or are un-synced (based on their given blockheight) are removed.
This fixes issues like #140