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.
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.