currencyrate: new rust plugin to provide the currencyconvert API#8842
currencyrate: new rust plugin to provide the currencyconvert API#8842daywalker90 wants to merge 4 commits intoElementsProject:masterfrom
currencyconvert API#8842Conversation
7e5e690 to
fbbf62b
Compare
|
Fixed the check-manpage error and disabled the plugin in |
7be7e22 to
55a8747
Compare
|
@daywalker90 I've had various conversations in Blockstream and confirmed we don't have a Blockstream-API for prices |
|
This is awesome! I've rebased, and I'm making the following trivial changes:
|
55a8747 to
cef88bd
Compare
|
OK, I love this, but I am going to ask for more changes :) I plan on using this inside bookkeeper, aggressively (when configured). So I think we need to buff up the algorithm. Here's my thinking: On request, we should return "immediately" if we have fresh enough results (say, < 1 hour, and algo below is not fetching more), and start refresh in the background. I think we should refresh lazily: if they're all over 1 hour old, pick one to refresh. If it has changed from its last value significantly, refresh others. Handwave over how this would work! But we should try for polling all the sources, even if we only do it very occasionally. If a source fails, don't randomly select it for some time (unless they all fail!). |
Changelog-Added: new plugin currencyrate to provide `currrencyconvert` API
…ate-add/disable-source. @daywalker90's was a little *too* faithful a reimplementation of the Python one! Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Instead of fetching prices on every request with a very short cache TTL we now start a background task instead with a way longer cache TTL. The background task fetches prices only from one source by default. If the price has changed much we fetch from different sources until two sources agree on a price. The background task exits if there wasn't a request for that currency in some time.
cef88bd to
6fe6c82
Compare
|
Thank you! The algorithm is now like this:
This enables
There is a backoff function for sources and if all sources are backed off of we just try all of them. |
Fixes #8825
I described my approach for doing API calls in the issue but i repeat it here:
I added 7 default price sources of which one (bitstamp) never seems to work (HTTP 403) when using a tor proxy. Out of these 6-7
CONVERT_SOURCES_COUNT(3) are chosen at random whencurrencyconvertis called, unless we are inside the cache time window.I like this approach because:
CACHE_DURATIONS_SECS(10)CONVERT_SOURCES_COUNT(3) sources aslong as enough are configured and return a valid resultCACHE_DURATIONS_SECS(10)CONVERT_SOURCES_COUNT(3)What i don't like about it:
SOURCE_TIMEOUT_SECS(5) * n (where n is >1 if any of the initial 3 fail but is at most thenumber of sources configured - 2) and i expect this to be called right before doing a payment, delaying it by up to that much. If it's only used for recurring payments i would assume response time is not that critical, so i found this acceptableTo always instantly have a response, we would either have to look for API endpoints that return all currency pairs and cache them or ask the user what currency they are interested in or use historic user queries to know wich currency to track.
I also tried my best to be compatible with the python version of
currencyrate, meaning i left the options and rpc methods the same, except for themsatsuffix. But i can see if you want to break this since the option names inside CLN are a little under-descriptive (add-source,disable-source). I also added support for positional members when usingadd-source(kraken needs it).Please let me know:
are you happy with the API call approach or do you prefer a different one, if so please let me know what you value more response time, data age, API rate limit etc.
where and how you want this documented
should i mark the tests as flaky since they make real-live API calls and they can easily fail if one of them doesn't return a valid result
The changelog has been updated in the relevant commit(s) according to the guidelines.
Tests have been added or modified to reflect the changes.
Documentation has been reviewed and updated as needed.
Related issues have been listed and linked, including any that this PR closes.
Important All PRs must consider how to reverse any persistent changes for
tools/lightning-downgrade