-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Fix fee priority for block fill #1631
Conversation
Instead of this, can we use the default comparison for the set? It will sort correctly, and be less comparisons. |
And to be more clear I am suggesting that this be removed from the code entirely. By default |
@vtnerd it is better to invert the division and avoid the possibility of divide by zero. The descending sort is still needed. |
although it would be possible to use -(fee/byte) as the sort key and the use the default comparison. |
The function dividing by fee checks that the transaction fee has met the minimum requirements before adding it to the pool. The function check only allows a fee of zero if the byte count is 0 so it is currently not possible to do an insert of size 0. An explicit check in this function would also be nice for clarity (the cost is small). If this is the preferred way, that's fine. I think it is strange to do a |
Or the case where someone modifies the file on disk so that it contains an incorrect fee value is possible too I suppose. Wondering if that deserialization function has an incorporated checksum, that would be nice. |
@vtnerd 0 fee is allowed by the protocol, and there are some blocks containing 0 fee transactions. They normally don't enter the pool but I believe still enter the pool during processing of blocks and can stay there if there is a reorg. Given that it is not entirely disallowed, it is better to use fee/bytes rather than bytes/fee. Despite all that, divide by zero would probably "work okay" but is poor style. As for the "extra" conditionals, that seems to be the preferred way to do a descending sort in C++, which is inherently a less intuitive operation given the way compare functions are defined in only one direction. Ascending could still be used here without introducing the complication of divide-by-zero by using -(fee/bytes) as a I noted in my previous comment. |
I was not stating that zero fee transactions are impossible, just that this data structure will not allow them. A division by zero can only occur with state file corruption (still possible), or when As for the number of conditional checks, I apologize for skipping a step in my description. The |
Two follow-ups:
|
Sorry about the zero fee noise @iamsmooth , I made an ass(out of myself)umption how about how/when this function was called. A miner can add zero fee transactions to a block, and every transaction in a block is forcibly inserted into The one positive is that I can update the comments to explain the check on line 164. |
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.
Reviewed
This changes the priority of TXs when considering them for inclusion in a block template, prioritising TXs with the highest fee per KB. It also properly takes the transaction fees into account when considering whether to include them in the block, and prevents the overall block reward falling below the reward of an empty block.