Improving currencyrate plugin#9011
Conversation
| const MSAT_PER_BTC: f64 = 1e11; | ||
|
|
||
| fn round_to_3dp(price: f64) -> f64 { | ||
| format!("{:.3}", price).parse::<f64>().unwrap_or(price) |
There was a problem hiding this comment.
Instead of moving from f64 to a string and then back again to f64, it would be better to do some purely mathematical operation.
eg. output = (input*1000.0).round() / 1000.0;
There was a problem hiding this comment.
to always get 3 decimal places you must return a String:
fn round_to_3dp(price: f64) -> String {
format!("{:.3}", (price * 1000.0).round() / 1000.0)
}There was a problem hiding this comment.
This method is not that reliable. See here the comment for very large number. That's why I opted for the f64 --> String --> f64 solution.
I need to return again f64 since the price is used to compute the median, so it is better to return f64 again in my opinion.
There was a problem hiding this comment.
Oh, the linked issue said to always have 3 decimal places not at most 3. So this is fine then if we can live with always rounding toward 0.
1f75db1 to
3ef67e3
Compare
3ef67e3 to
d945873
Compare
d945873 to
1a74aaa
Compare
We can do that, but personally i go to https://docs.corelightning.org/reference/lightningd-config first to see documentation on config options and we have the currencyrate options with instructions on how they need to be written included there.
No sure if it can be done with reckless but it can be done with just the
then to add a source:
But keep in mind that afaik any events happening while the plugin is stopped will have their currencyrate missing. |
| Value::Array(values) => { | ||
| if values.len() > 2 { | ||
| return Err(anyhow!( | ||
| "Too many arguments: expected at most 2 (amount currency), got {}", |
There was a problem hiding this comment.
nit: change this to expected 2.
| .to_owned(); | ||
| (amount, currency.to_uppercase()) | ||
| } | ||
| Value::Object(map) => { |
There was a problem hiding this comment.
We should then also do the same check for object based queries here aswell.
| let source = values.get(1).and_then(|v| v.as_str()).map(str::to_owned); | ||
| (currency, source) | ||
| } | ||
| Value::Object(map) => { |
There was a problem hiding this comment.
We should then also do the same check for object based queries here aswell.
| Value::Array(values) => { | ||
| if values.len() > 1 { | ||
| return Err(anyhow!( | ||
| "Too many arguments: expected at most 1 (currency), got {}", |
| .to_owned(); | ||
| currency.to_uppercase() | ||
| } | ||
| Value::Object(map) => { |
There was a problem hiding this comment.
We should then also do the same check for object based queries here aswell.
| .to_owned(); | ||
| currency.to_uppercase() | ||
| .to_uppercase(); | ||
| let source = values.get(1).and_then(|v| v.as_str()).map(str::to_owned); |
There was a problem hiding this comment.
We do allow sources to be named as numbers only and this would then cause currencyrate to silently ignore the sourrce and return a median result. I suggest changing this to:
let source = values.get(1).and_then(|v| {
v.as_str()
.map(str::to_owned)
.or_else(|| v.as_number().map(std::string::ToString::to_string))
});| .to_owned(); | ||
| currency.to_uppercase() | ||
| .to_uppercase(); | ||
| let source = map.get("source").and_then(|v| v.as_str()).map(str::to_owned); |
There was a problem hiding this comment.
Same as above:
let source = map.get("source").and_then(|v| {
v.as_str()
.map(str::to_owned)
.or_else(|| v.as_number().map(std::string::ToString::to_string))
});|
Usually we would use |
Important
26.04 FREEZE March 11th: Non-bugfix PRs not ready by this date will wait for 26.06.
RC1 is scheduled on March 23rd
The final release is scheduled for April 15th.
Checklist
Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:
tools/lightning-downgradeCurrencyrate plugin changes
As mentioned in #9010,
sourceargument to thecurrencyrateRPC callInfo Needed
I would personally suggest to add a
README.mdfile in the currencyrate plugin folder reporting how to configure new sources in the config file, plus some best practice usingrecklessto add and disable sources without restarting the node.