-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Use a typedef for monetary values #4234
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
Conversation
|
ACK. To review, |
|
Looks good to me |
|
I get quite a few compile errors in the Qt GUI. I think you're missing some casts here and there: Mind that qint64 and int64_t are defined differently (long long versus long on AMD64), so converting between then needs casts. |
|
Maybe it should be CMoneyAmount or CSatoshis? CMoney doesn't seem to explain what it is (the whole program is arguably "money" to less-experienced people) |
|
Money sounds fine to me, "CCoins" might be better, alas. I'm not keen on using the base unit word there. If people wanted to change it CValue might be another alternative. |
|
CCoins sounds like a list of 'coins' which already have a clear-cut definition in the source code (alas, indeed), and CValue is very general (is it economic value, or some parameter value, or...). |
|
CCoins already is used for a collection of (specific) coins, isn't it? |
|
That was the "alas". |
|
I think a "coin" should include the entire txout including the scriptPubKey. But yeah, that ship has long-since sailed. @laanwj Your pastbin has expired, although I think I know what is going on with the qint64 and can figure it out. I'm not getting any errors or even warnings on my system however (clang on OS X 10.9.3) so I'm not sure if I'd catch them all. What compile and platform are you using? |
|
@maaku Ubuntu 14.04 64-bit |
|
Fixed the compilation issue on Ubuntu 14.04 with a static cast. Also rebased against current master branch. |
|
Needs rebase. This was ACK'd then sat. Shall we get this moving again? It is the sort of change that should be merged or dropped, as it is unfair to keep asking @maaku to keep rebasing it otherwise. |
|
Yes please. |
|
Back to bike-shedding I like CAmount, seems less general than CValue. |
|
I tend to focus on pulls that fix bugs, add tests or change functionality in a useful way, so 'all over the place' changes like this tend to end up in the back burner. Last time it introduced a build problem for me. As that's fixed, and when this is rebased, I'm fine with merging it. |
|
Ok, sounds like there is some consensus developing. I'll rebase ASAP. (Rebasing is a non-trivial process for this PR as it involves manually checking the entire diff history; hopefully I'll have it up this afternoon.) |
|
To join the shed: CMoney or CAmount are fine to me. So are Money or Amount. |
|
This is a version with replacing CMoney with Amount: https://github.com/jtimon/bitcoin/tree/typedef |
|
And here's another version after the rebase (by the way, no, it wasn't trivial): https://github.com/jtimon/bitcoin/tree/typedef2 |
|
Rebased version using Amount looks good to me (prefer it to Money/CMoney). |
|
I'm reviewing as well, comparing with my own rebase. I don't mind changing the name, but only if we get consensus. Amount is way too generic IMHO. Amount of what? Fees? We have a separate class (CFeeRate) for that. CMoney/Money isn't ideal, but I don't see a better, succinct option... |
|
Well it's better than Value. We should stop bike-shedding here and simply decide. Otherwise we'll still have this open in a month. @jtimon likes Amount, @sipa likes Amount, I like Amount. So that's our consensus. To be entirely clear, just add a comment what it is about in amount.h where you define the type. |
|
@jtimon Looks good at first glace; care to do a pullreq, so we get pulltester feedback etc? I'm very aware that this is a change that will pretty much instantly become non-mergable, so given that there seems reasonable support for it, let's move. |
|
I conserved maaku's commit, I thought he could fetch my branch and push here, but if that's simpler I'll open a new PR (#4614). |
|
So there were a dozen or so locations where int64_t/qint64 was still being used. Those have been fixed in the latest rebase, just pushed. |
src/miner.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change the initialization order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That... is a fine question. I swear at one point during the rebase I was getting out-of-order initialization warnings, so I switched it. But looking at the diff, the prior ordering is obviously correct. Thank you for catching it.
I've pushed a new squashed commit that reverses that one hunk.
|
Untested ACK (reviewed with above word diff command). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW we have many signal/slot definitions like this:
connect(model, SIGNAL(balanceChanged(qint64, qint64, qint64, qint64, qint64, qint64)), this, SLOT(setBalance(qint64, qint64, qint64, qint64, qint64, qint64)));I'm fairly sure that these need to be updated to use CAmount as well. No need to add & or const in these SIGNAL() and SLOT() definitions (they are ignored), but the type needs to match.
Also the CAmount type likely has to be registered to Qt at some point to be able to pass it in this way (see http://qt-project.org/doc/qt-4.8/custom-types.html).
As long as CAmount is the same type as qint64 I imagine it will keep working, but it seems brittle.
a8df996 to
a372168
Compare
|
Automatic sanity-testing: FAILED BUILD/TEST, see http://jenkins.bluematt.me/pull-tester/p4234_a372168e77a8a195613a02983f2589252698bf0f/ for binaries and test log. This could happen for one of several reasons:
If you believe this to be in error, please ping BlueMatt on freenode or TheBlueMatt here. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ |
|
Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4234_a372168e77a8a195613a02983f2589252698bf0f/ for binaries and test log. |
|
ACK. Verified type replacement + headers changes only. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be #endif // BITCOIN_AMOUNT_H!
|
@laanwj Is a |
|
@Diapolo That's not an assumption that you can make. Only that both are 64 bit and can be cast to each other, but they may be (and are in practice) defined differently. |
|
Let's not hold this up for stylistic reasons that can be trivially fixed later; it will very quickly start conflicting again probably... |
|
Wladimir made an in-line comment about that already. The right and proper thing to do is to abstract the interface between the two, and to register / provide the necessary hooks for Qt to handle CAmount natively in slot definitions. I'll be honest though, I'm not going to have time to write that in the next 1-2 weeks. Given how quickly this PR atrophies, it's probably better to do that as a separate PR. |
|
Yep, ACK, let's merge this before it needs rebase again. |
|
@laanwj Is that SLOT typing issue a blocker? If it's not, I think we can hold up other pull requests for a short while while this is being reviewed/merged, but not longer. |
|
@sipa The point is that I am not sure how Qt handles types, ie, CAmount that are not directly registered to the system but used nevertheless in slot/signal descriptions. It does some magic especially when serializing for cross-thread messages, and it may be that this only works by accident. Has anyone actually tested the wallet GUI with this? That amounts still work correctly when receiving and sending? That update signals still come through properly? |
|
Can we "abstract the interface between the two, and to register / provide the necessary hooks for Qt to handle CAmount natively in slot definitions" after merging this? |
|
I just opened it in main mode (with no funds) and in regtest mode (where the mined 50s are ok). |
|
Thanks for testing @jtimon . I don't like merging this in good faith. What if it breaks only on some platforms? Having wrong amounts would be the greatest screw-up possible in a GUI. So I'm going to do some testing myself and research the qt documentation on what to do here first. |
|
OK - I've verified all three signals involving CAmount:
I've also added code to make it possible to send CAmount over queued connections (just two lines). Fixes are here laanwj@c122f55 Note: after merging this, be sure to start building from scratch - I had some strange issues with setting the fee in the options that went away with a clean build. |
|
Merged via 3fd192f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jtimon Why was this included here? It isn't even used in util!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, a small mistake by @maaku I guess. Can you correct it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that can be removed. It's a leftover from when utilmoneystr was part of util. Should have been removed in the rebase.
…was used incorrectly. Is a continuation of bitcoin#4234.
Replaces int64_t with a typedef in all monetary contexts.
See #4067 for a more thorough description of this patch and associated context.