-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Use int32_t type for most transaction size/weight values
#23962
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
|
Concept ACK. Could squash, given that the other pull was closed? Things to look out for in review:
|
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsNo conflicts as of last run. |
|
Updated 9a8a8ad -> 39c82fa (pr23962.01 -> pr23962.02).
Commits have been reordered to keep changes focused. |
shaavan
left a comment
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.
Concept ACK
I think it makes sense to use int64_t consistently for all transaction sizes.
I have yet to thoroughly review the file to check if all the transaction size variables are correctly covered in this PR; I still find some that could use a proper type assignment.
- Here. The type of
entry_sizecan be changed to int64_t. This will lead to making appropriate changes at the other places in the file. - Here. Type of
totalSizeWithAncestorscould be changed.
Btw I was curious about one thing. In line 232 in this file, there is implicit typecasting occurring:
totalSizeWithAncestors += stageit->GetTxSize();
because type of totalSizeWithAncestors is size_t and return type of GetTxSize() is changed to int64_t in this PR (line 114) . Shouldn't it cause implicit-conversion-warning for this.
glozow
left a comment
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.
Concept ACK to unifying types for transaction sizes. But if we're going to do this, why use a signed type? We don't have negative sizes, do we?
The rule of thumb is to use signed types for anything that involves arithmetic operations (addition or subtraction). Obviously the standard library doesn't make that easy with |
Also see Signed and Unsigned Types in Interfaces. |
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.
Concept NACK [edit: to 64-bit sizes, which this PR no longer is]. This wastes memory for no benefit - we should probably go to int32_t instead.
Transactions should never approach 2 GB, and it doesn't make sense to calculate a sum that large either (the largest package that could fit in a block is 4 MB).
If using int32_t produces warnings somewhere, those warnings are probably real issues that should be fixed.
39c82fa to
295a4f0
Compare
|
Updated 39c82fa -> 295a4f0 (pr23962.02 -> pr23962.03):
You are right. But such a pr could be unmanageable in size. So here, in the first commit, the minimal set of changes included which makes the second commit possible and concise. Other changes left for follow ups. |
295a4f0 to
960f996
Compare
|
Rebased 295a4f0 -> 960f996 (pr23962.03 -> pr23962.04) due to the conflict with #21464. |
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.
Changes since my review:
- Replaced int64_t with int32_t for the transaction variables. This is done for the reason suggested in this comment, with which I agree.
- Rebased over the current master.
I observed the following implicit conversion warning:
Ideally, this needs to be addressed by changing the ancestor_size_limit to int32_t and making other subsequent changes. But for this PR, we can go with at-place manual conversion, if that's possible.
You are right. But such a pr could be unmanageable in size. So here, in the first commit, the minimal set of changes included which makes the second commit possible and concise. Other changes left for follow ups.
That makes sense. Let's take up changing small sections of transaction_size variables one by one in follow-ups.
This change gets rid of a few casts and makes the following commit diff smaller.
murchandamus
left a comment
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.
codereview ACK 3ef756a
|
|
||
| uint64_t GetCountWithDescendants() const { return nCountWithDescendants; } | ||
| uint64_t GetSizeWithDescendants() const { return nSizeWithDescendants; } | ||
| int64_t GetSizeWithDescendants() const { return nSizeWithDescendants; } |
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.
Re-reviewing this basically from scratch, I stumble here. int32_t should be big enough to represent the weight of more than 5,000 max standard weight transactions. Are we actually bumping into overflow issues with int32_t somewhere for size with descendants?
I see that this was brought up before, so I assume it was left a 64-bit value to limit the scope of this PR. Is that right?
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.
Are we actually bumping into overflow issues with
int32_tsomewhere for size with descendants?
I don't think so.
However, UBSan raises "signed-integer-overflow" warnings about nSizeWithAncestors += modifySize; etc.
|
|
||
| uint64_t GetCountWithAncestors() const { return nCountWithAncestors; } | ||
| uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; } | ||
| int64_t GetSizeWithAncestors() const { return nSizeWithAncestors; } |
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.
As above
ryanofsky
left a comment
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.
Code review ACK 3ef756a. Since last review, just rebased with more type changes in test and tracing code
|
ACK 3ef756a |
|
Something that just occurred to me: do/should we consider tracepoints to be a stable api? Since this changes the types for some of the tracepoints, this would ostensibly break any third party programs that rely on those tracepoints. |
|
The silent conflict with the #26531 has been resolved in the recent push. As this PR touches tracepoints now, @0xB10C @virtu maybe you want to look into it?
No, we shouldn't. I think that classes like |
|
ACK 3ef756a. I've focused my testing and code review on the tracepoint related changes. The docs, the test, and the mempool_monitor.py demo script are updated. I ran the
The goal of the tracepoints is to expose implementation details. This means, if an implementation detail changes, the tracepoint interface can change too. As an extreme example: If we'd remove the mempool, we'd also drop the mempool tracepoints. Third party programs have to adapt in this case. |
|
This causes warnings when compiling for 32 bit? |
The relevant CI tasks logs are clean. How to reproduce it? |
|
Steps to reproduce:
|
@hebasto did you end up looking into this? |
…iables signed 92de74e refactor: Make more transaction size variables signed (Hennadii Stepanov) Pull request description: This PR is a continuation of bitcoin/bitcoin#23962 and it: - gets rid of two static casts, - addresses bitcoin/bitcoin#23962 (comment), - is useful for bitcoin/bitcoin#25972, see the failed ARM and multiprocess CI jobs. ACKs for top commit: MarcoFalke: lgtm ACK 92de74e 🥔 glozow: ACK 92de74e Tree-SHA512: 84225961af8e08439664e75661b98fe86560217e891e5633a28316bf248d88df317a0c6b5a5f6b03feb2b0e0fd40a1f91dd4a85a0610d567470805bf47a84487

From #23957 which has been incorporated into this PR: