-
Notifications
You must be signed in to change notification settings - Fork 36.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpc: Avoid unnecessary parsing roundtrip in number formatting, fix locale issue #6456
Conversation
This is the format that was always returned to JSON clients. The difference was not noticed before, because VREAL values are post-processed by univalue. By implementing the functionality directly it breaks the dependency of rpcserver on utilmoneystr. FormatMoney is now only used for debugging purposes. To test, port over the formatting tests from util_tests.cpp to rpc_tests.cpp.
JSON makes no distinction between numbers and reals, and our code doesn't need to do so either. This removes VREAL, as well as its specific post-processing in `UniValue::write`. Non-monetary amounts do not need to be forcibly formatted with 8 decimals, so the extra roundtrip was unnecessary (and potentially loses precision).
Use locale-indepent C++ based parsing instead of C's strtod, which checks for different input based on the user's locale. Fixes bitcoin#6443.
I can confirm this resolves #6443, thanks! As far as I can see the output is as expected, except for the difficulty, returned by |
Exactly - the fixed 8-digit formatting is for clarity in monetary amounts. |
Tested ACK. If i understand this right, then there is a slightly API change. Every double/float (non-monetary) comes now with a precision of 16 instead of 8 (because of https://github.com/bitcoin/bitcoin/pull/6456/files#diff-0f1b401041a14398229cf7e31b6db7eeR89). Because we are using |
Right. All numbers were 'cut' to %.8f notation, so it would have reported |
ACK. Happy to see VREAL go away. |
Add UniValue as subtree Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6637 - bitcoin/bitcoin#6239 - bitcoin/bitcoin#6379 - bitcoin/bitcoin#6456 - bitcoin/bitcoin#6788
Bitcoin 0.12 RPC PRs 1 Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6266 - bitcoin/bitcoin#6257 - bitcoin/bitcoin#6271 - bitcoin/bitcoin#6158 - bitcoin/bitcoin#6307 - bitcoin/bitcoin#6290 - bitcoin/bitcoin#6262 - bitcoin/bitcoin#6088 - bitcoin/bitcoin#6339 - bitcoin/bitcoin#6299 (partial, remainder in #2099) - bitcoin/bitcoin#6350 - bitcoin/bitcoin#6247 - bitcoin/bitcoin#6362 - bitcoin/bitcoin#5486 - bitcoin/bitcoin#6417 - bitcoin/bitcoin#6398 (partial, remainder was included in #1950) - bitcoin/bitcoin#6444 - bitcoin/bitcoin#6456 (partial, remainder was included in #2082) - bitcoin/bitcoin#6380 - bitcoin/bitcoin#6970 Part of #2074.
Three weakly related fixes to number handling after the
univalue
switch. These came to the surface while troubleshooting #6443.Make ValueFromAmount always return 8 decimals
This is the format that was always returned to JSON clients. The difference was not noticed before, because VREAL values are post-processed by univalue.
By implementing the functionality directly it breaks the dependency of rpcserver on utilmoneystr. FormatMoney is now only used for debugging purposes.
To test, port over the formatting tests from util_tests.cpp to rpc_tests.cpp.
univalue: Avoid unnecessary roundtrip through double for numbers
JSON makes no distinction between numbers and reals, and our code doesn't need to do so either.
This removes VREAL, as well as its specific post-processing in
UniValue::write
. Non-monetary amounts do not need to be forcibly formatted with 8 decimals, so the extra roundtrip was unnecessary (and potentially loses precision).util: use locale-independent parsing in ParseDouble
Use locale-indepent C++ based parsing instead of C's strtod, which checks for different input based on the user's locale.
Fixes #6443.