Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented Mar 17, 2016

No description provided.

MarcoFalke added 2 commits March 17, 2016 16:59
This reverts the hard-to-read and buggy code introduced in
d88af56 and adds documentation
@maflcko
Copy link
Member Author

maflcko commented Mar 17, 2016

@laanwj raised the concern that it should be mentioned in the release notes, but I would be really surprised if anyone was relying on this behavior.

Current master fails the unit test (see travis):

test/amount_tests.cpp(23): error: check feeRate.GetFee(0) == 0 has failed [1000 != 0]
test/amount_tests.cpp(32): error: check feeRate.GetFee(0) == 0 has failed [123 != 0]
test/amount_tests.cpp(33): error: check feeRate.GetFee(8) == 1 has failed [123 != 1]

@laanwj
Copy link
Member

laanwj commented Mar 17, 2016

I'd like some more details here, you left the opening post empty!

What do you mean with "make GetFee() monotonic", and what purpose does this have (from a user perspective)?

@maflcko
Copy link
Member Author

maflcko commented Mar 17, 2016

What do you mean with "make GetFee() monotonic",

The current behavior of the code is CFeeRate(1000).GetFee(0) == 1000 and CFeeRate(123).GetFee(8) == 123, which is obviously wrong. This was introduced in d88af56 (#4465).

monotonic

Please have a look at the following sketches:

master:
screenshot from 2016-03-17 17-53-24

patch:
screenshot from 2016-03-17 17-53-45

what purpose does this have

The purpose of this pull is to get rid of unexpected behavior.

if (nFee == 0 && nSatoshisPerK > 0)
nFee = nSatoshisPerK;
if (nFee == 0 && nSize != 0 && nSatoshisPerK != 0)
nFee = CAmount(1);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this code should be removed entirely, but I don't see that happening soon taking into account the limited effect and the substantial amount of refactoring in wallet code.

@laanwj
Copy link
Member

laanwj commented Mar 17, 2016

Thanks for the plots, that makes things a lot more clear. That outlier around 0 clearly looks wrong.
Yes, this change makes sense.

utACK

@jonasschnelli
Copy link
Contributor

utACK

src/amount.cpp Outdated

if (nFee == 0 && nSatoshisPerK > 0)
nFee = nSatoshisPerK;
if (nFee == 0 && nSize != 0 && nSatoshisPerK != 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the != 0 here. Why would you turn a small negative fee rate into a small positive one?
@sdaftuar can comment on the vagaries of negative CFeeRates, they are already fraught with peril, but they can exist at least via prioritisetransaction. I think it would be much safer to keep this as > 0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I didn't know negative rates exist.

Added tests for negative rates in another commit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@morcos Actually, I don't think we support negative amounts for nSatoshisPerK right now. 64-bit platforms will convert nSatoshisPerK to unsiged (size_t). 32-bit platforms will convert nSize to signed CAmount.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I'm not sure exactly what happens. Although I thought nSatoshiPerK was a CAmount which is an int64_t. I'm not sure it's meant to support negative rates, but at some point we need to either make sure they are supported or prevent against them. All I'm suggesting is that right now we don't change any edge case behavior around negative amounts, b/c its already fragile.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at some point we need to either make sure they are supported or prevent against them

I think we agree on this but I'd rather not do it as part of this pull.

@morcos
Copy link
Contributor

morcos commented Mar 19, 2016

@MarcoFalke thanks.

utACK fad13b1

@laanwj laanwj merged commit fad13b1 into bitcoin:master Mar 21, 2016
laanwj added a commit that referenced this pull request Mar 21, 2016
fad13b1 [amount] Preempt issues with negative fee rates (MarcoFalke)
faf756a [amount] Make GetFee() monotonic (MarcoFalke)
fab6880 [qa] Add amount tests (MarcoFalke)
@maflcko maflcko deleted the Mf1603-amountFix branch March 21, 2016 13:44
@jtimon
Copy link
Contributor

jtimon commented Mar 21, 2016

Somehow I missed this. Even if it's kind of meaningless now, "posthumous utACK".

I'll test this now by rebasing master...jtimon:0.12.99-feerate and repeating the rpc tests locally. I still don't know them all that well, does it make sense for me to run the all the rpc tests with the -extended label for anything that could be affected by changes in CFeeRate ?

feeRate = CFeeRate(123);
// Truncates the result, if not integer
BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0);
BOOST_CHECK_EQUAL(feeRate.GetFee(8), 1); // Special case: returns 1 instead of 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the special case is less special, but, yes, is still a special case, so thank you for documenting it.

@laanwj
Copy link
Member

laanwj commented Mar 21, 2016

Somehow I missed this. Even if it's kind of meaningless now, "posthumous utACK".

No, it's not meaningless. Reviewing commits that are merged is also essential.

@maflcko
Copy link
Member Author

maflcko commented Mar 21, 2016

repeating the rpc tests locally

I can't think of any way your results should be different by rebasing onto this pull. This only has an effect if the size and/or fee rate is really small.

@jtimon
Copy link
Contributor

jtimon commented Mar 21, 2016

I can't think of ...

Well, I can think of them. That doesn't mean they make sense, see #7731

codablock pushed a commit to codablock/dash that referenced this pull request Dec 19, 2017
fad13b1 [amount] Preempt issues with negative fee rates (MarcoFalke)
faf756a [amount] Make GetFee() monotonic (MarcoFalke)
fab6880 [qa] Add amount tests (MarcoFalke)
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants