Skip to content

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Jan 3, 2022

From #23957 which has been incorporated into this PR:

A file-wide suppression is problematic because it will wave through future violations, potentially bugs.

Fix that by using per-statement casts.

This refactor doesn't change behavior because the now explicit casts were previously done implicitly.

Similar to commit 8b5a4de

@maflcko
Copy link
Member

maflcko commented Jan 4, 2022

Concept ACK. Could squash, given that the other pull was closed?

Things to look out for in review:

  • On 32-bit this will potentially (minimally) reduce the number of txs that fit into the mempool
  • types in cstdint aren't type safe and call sites will need to be reviewed as well

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 4, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK Xekyo, ryanofsky, achow101, 0xB10C
Concept NACK luke-jr
Concept ACK MarcoFalke, shaavan, glozow, stickies-v

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@hebasto
Copy link
Member Author

hebasto commented Jan 4, 2022

Updated 9a8a8ad -> 39c82fa (pr23962.01 -> pr23962.02).

Could squash, given that the other pull was closed?

Commits have been reordered to keep changes focused.

Copy link
Contributor

@shaavan shaavan left a 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.

  1. Here. The type of entry_size can be changed to int64_t. This will lead to making appropriate changes at the other places in the file.
  2. Here. Type of totalSizeWithAncestors could 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.

Copy link
Member

@glozow glozow left a 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?

@maflcko
Copy link
Member

maflcko commented Jan 4, 2022

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 size_t being unsigned.

@hebasto
Copy link
Member Author

hebasto commented Jan 5, 2022

@glozow

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?

Also see Signed and Unsigned Types in Interfaces.

Copy link
Member

@luke-jr luke-jr left a 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.

@hebasto hebasto changed the title Use int64_t type for transaction sizes consistently Use int32_t type for transaction sizes consistently Jan 24, 2022
@hebasto hebasto changed the title Use int32_t type for transaction sizes consistently Use int32_t type for transaction size/weight consistently Jan 24, 2022
@hebasto
Copy link
Member Author

hebasto commented Jan 24, 2022

Updated 39c82fa -> 295a4f0 (pr23962.02 -> pr23962.03):

This wastes memory for no benefit - we should probably go to int32_t instead.


@shaavan

I think it makes sense to use int64_t consistently for all transaction sizes.

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.

@hebasto
Copy link
Member Author

hebasto commented Jan 25, 2022

Rebased 295a4f0 -> 960f996 (pr23962.03 -> pr23962.04) due to the conflict with #21464.

Copy link
Contributor

@shaavan shaavan left a 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:

Screenshot from 2022-01-25 20-06-15

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.

@hebasto

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.

@hebasto hebasto marked this pull request as draft June 12, 2023 17:35
Copy link
Contributor

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

codereview ACK 3ef756a

@@ -152,13 +154,13 @@ class CTxMemPoolEntry
}

uint64_t GetCountWithDescendants() const { return nCountWithDescendants; }
uint64_t GetSizeWithDescendants() const { return nSizeWithDescendants; }
int64_t GetSizeWithDescendants() const { return nSizeWithDescendants; }
Copy link
Contributor

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?

Copy link
Member Author

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_t somewhere for size with descendants?

I don't think so.

However, UBSan raises "signed-integer-overflow" warnings about nSizeWithAncestors += modifySize; etc.

CAmount GetModFeesWithDescendants() const { return nModFeesWithDescendants; }

bool GetSpendsCoinbase() const { return spendsCoinbase; }

uint64_t GetCountWithAncestors() const { return nCountWithAncestors; }
uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
int64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
Copy link
Contributor

Choose a reason for hiding this comment

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

As above

@DrahtBot DrahtBot requested review from achow101 and ryanofsky June 12, 2023 19:32
Copy link
Contributor

@ryanofsky ryanofsky left a 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

@hebasto hebasto marked this pull request as ready for review June 12, 2023 20:30
@achow101
Copy link
Member

ACK 3ef756a

@DrahtBot DrahtBot removed the request for review from achow101 June 12, 2023 21:52
@achow101
Copy link
Member

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.

@hebasto
Copy link
Member Author

hebasto commented Jun 13, 2023

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?

Something that just occurred to me: do/should we consider tracepoints to be a stable api?

No, we shouldn't. I think that classes like CTxMemPoolEntry and their public access method return types should be considered as mempool implementation details for all purposes. Maybe tracepoint docs need an explicit note about that?

@0xB10C
Copy link
Contributor

0xB10C commented Jun 13, 2023

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 interface_usdt_mempool.py test and the mempool_monitor.py script. The mempool_monitor.py output looks correct.

Something that just occurred to me: do/should we consider tracepoints to be a stable api?

No, we shouldn't. I think that classes like CTxMemPoolEntry and their public access method return types should be considered as mempool implementation details for all purposes.

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.

@achow101 achow101 merged commit 58b36fc into bitcoin:master Jun 13, 2023
@hebasto hebasto deleted the 220103-txsize branch June 13, 2023 16:23
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 15, 2023
@maflcko
Copy link
Member

maflcko commented Jun 15, 2023

This causes warnings when compiling for 32 bit?

txmempool.cpp:174:60: error: comparison of integers of different signs: 'long long' and 'uint64_t' (aka 'unsigned long long') [-Werror,-Wsign-compare]
        if (stageit->GetSizeWithDescendants() + entry_size > static_cast<uint64_t>(limits.descendant_size_vbytes)) {
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

@hebasto
Copy link
Member Author

hebasto commented Jun 15, 2023

This causes warnings when compiling for 32 bit?

The relevant CI tasks logs are clean. How to reproduce it?

@maflcko
Copy link
Member

maflcko commented Jun 15, 2023

Steps to reproduce:

( cd depends && make HOST=i686-pc-linux-gnu CC='clang -m32' CXX='clang++ -m32 -Wsign-compare' NO_QT=1 NO_WALLET=1 NO_ZMQ=1 NO_UPNP=1 NO_NATPMP=1 -j $(nproc) ) && ./autogen.sh && CONFIG_SITE="$PWD/depends/i686-pc-linux-gnu/share/config.site" ./configure && make -j $(nproc) src/bitcoind

@glozow
Copy link
Member

glozow commented Jul 20, 2023

This causes warnings when compiling for 32 bit?

@hebasto did you end up looking into this?

@hebasto
Copy link
Member Author

hebasto commented Jul 20, 2023

This causes warnings when compiling for 32 bit?

This causes warnings when compiling for 32 bit?

@hebasto did you end up looking into this?

I apologise for forgetting to mention that #28059 addresses that warnings.

glozow added a commit to bitcoin-core/gui that referenced this pull request Aug 3, 2023
…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
@bitcoin bitcoin locked and limited conversation to collaborators Jul 19, 2024
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.