Enforce displaying Amount with trailing zeros#2604
Enforce displaying Amount with trailing zeros#2604apoelstra merged 1 commit intorust-bitcoin:masterfrom 448-OG:amount_8decimal_precision
Conversation
Pull Request Test Coverage Report for Build 8316149718Details
💛 - Coveralls |
|
The CI failure is real -- you're introducing a dependence on In principle we shouldn't need one. Interestingly my local CI passes -- so we've found a blind spot in it! Let me investigate.. |
|
Oh, lol, the blind spot is the entire |
|
I forgot what our consensus was about respecting |
Yeah! Realized it was an issue with allocation but I was not able to make changes yesterday. Should be fixed now. My tests also passed locally. Not sure why |
|
What is the current policy on running rustfmt, my editor does auto format but when I do a diff I see so many changes related to formatting |
|
So I also need to fix it for tests, somehow they succeed locally |
Please do not commit unrelated changes. Usually there should not be very many because we have a weekly bot which does all the formatting changes, but lately we have been skipping the bot because one mantainer claims undue difficulty in rebasing. So you will need to override your editor or be careful about what changes you commit, for now. |
Yes, we "make an effort". But there are some exceptional cases, most notably |
|
@448-OG, you can use |
It is common to display bitcoins using trailing zeros upto 8 decimals. This commit enforces: - Displaying Amount in BTC with trailing zeroes by eight decimal places if a precision on the Amount is not specified. - Displaying Amount in BTC upto the precision specified truncating the insignificant zeros. - Displaying amount in BTC without any decimals if the remainder of the amount divided by the satoshis in 1 BTC is equal to zero using formula `satoshis.rem_euclid(Amount::ONE_BTC.to_sat()) != 0` These are not breaking changes and all previous tests pass. A testcase is added to for changes introduced. Resolves: #2136
|
WTF, this PR reversed what was previously intentionally changed for a good reason in #716 Honestly, I'm starting to get annoyed by people changing intentional design without a proper justification. In this case part of the problem is my fault for not including a test. Good learning experience for me, I'll definitely do better.
This is bad justification because people can just use |
|
@Kixunil if you want specific behavior from the amount display traits then you need tests and very specific comments. Because this module is insanely complicated and we have had multiple complaints about it and it's impossible to tell what is "deliberate" and what is not. I note that this claims to fix a linked bug where you replied "definitely a bug", and then alongside your comment here you commented on that issue suggesting a completely undiscoverable workaround. The linked issue also definitely is a bug because it involves Further, I don't even know what specifically you're complaining about. You say you "intentionally changed for a good reason" ...some specific aspect of formatting in a PR whose description is a "significant refactor" that "makes Amount configurable"? In general I appreciate you retroactively reviewing PRs like this, because it lets us move forward and then double-back to fix oversights rather than having half a dozen perma-stalled PRs that prevent everyone else from rebasing. But in this case I have no idea what you're talking about. |
Displaying with minimal number of zeros is the default in Rust and we want to follow it. This was originally implemented in rust-bitcoin#716 but rust-bitcoin#2604 reversed it claiming this is common, however it broke people who rely on minimal display (e.g. BIP21) without fixing the root cause of rust-bitcoin#2136. This reverts commit d887423 adds a test to prevent this change and also fixes the problem with `{:0.8}` not working. Closes rust-bitcoin#2136 Closes rust-bitcoin#2948
|
The PR literally states:
Though it doesn't provide justification. The justification is in #709 (which is linked). I think we should have a proptest checking roughly that |
|
If you can write that proptest properly I'd be thrilled. I tried doing this (as a fuzztest, not as a proptest) but I got constantly gummed up by the This should probably be promoted to its own issue. I really would like this fuzztest to exist because it would document exactly how we believe Amount should be formatted. |
To my knowledge it behaves correctly. However the proptest must not test the case with denomination (though maybe we can hack it).
Width means total width of the field but is precision is too big it'll be wider. With denomination we have to subtract the length of denomination from available width. (There's a potential question whether it should truncate the denomination. I don't think so.) |
3196c27 Deprecate `Amount::fmt_value_in` (Martin Habovstiak) 467546f Round `Amount` when requested precision is too low (Martin Habovstiak) 7c95a77 Fix `Amount` decimals handling (Martin Habovstiak) Pull request description: Displaying with minimal number of zeros is the default in Rust and we want to follow it. This was originally implemented in #716 but #2604 reversed it claiming this is common, however it broke people who rely on minimal display (e.g. BIP21) without fixing the root cause of #2136. This reverts commit d887423 adds a test to prevent this change and also fixes the problem with `{:0.8}` not working. Closes #2136 Closes #2948 Can we backport this one too? ACKs for top commit: tcharding: ACK 3196c27 apoelstra: ACK 3196c27 I also really like how this reduces the complexity of the module, basically passing everything through to `display_in` Tree-SHA512: 3221f83086ac55af3d4caad03fe2b619be303533bba12096040419d119600c8597938809e171662f11b515d469156b083b2072b901d445e4fdfc7b1062cf7b6a
It is common to display bitcoins using trailing zeros upto 8 decimals. This commit enforces:
satoshis.rem_euclid(Amount::ONE_BTC.to_sat()) != 0These are not breaking changes and all previous tests pass.
A testcase is added to for changes introduced.
Resolves: #2136