Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented Mar 25, 2024

The getchaintxstats RPC reply during AU background download may return non-zero, but invalid, values for window_tx_count and txrate.

For example, txcount may be zero for a to-be-downloaded block, but may be non-zero for an ancestor block which is already downloaded. Thus, the values returned may be negative (and cause intermediate integer sanitizer violations).

Also, txcount may be accurate for the snapshot base block, or a descendant of it. However it may be zero for an ancestor block that still needs to be downloaded. Thus, the values returned may be positive, but wrong.

Fix all issues by skipping the returned value if either txcount is unset (equal to zero).
Also, skip txcount in the returned value, if it is unset (equal to zero).

Fixes #29328

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 25, 2024

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK fjahr, mzumsande, achow101

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29656 (chainparams: Change nChainTx type to uint64_t by fjahr)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@fjahr
Copy link
Contributor

fjahr commented Apr 23, 2024

Concept ACK, could we add a test for this?

@maflcko
Copy link
Member Author

maflcko commented Apr 23, 2024

A test is already present in test/functional/feature_assumeutxo.py, see the diff. You can also test it by running this pull against a bitcoind compiled from master and observing the sanitizer crash and the test failure.

@maflcko maflcko requested a review from luke-jr April 23, 2024 17:41
@maflcko maflcko force-pushed the 2403-rpc-int-wrap- branch 2 times, most recently from fa146d9 to fa28613 Compare April 26, 2024 15:28
Copy link
Contributor

@fjahr fjahr left a comment

Choose a reason for hiding this comment

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

tACK fa28613

I have written some additional coverage to test the behavior and build my understanding, it could be added here or I can make a follow-up: fjahr@03a0f31

@maflcko
Copy link
Member Author

maflcko commented Apr 27, 2024

03a0f31

I think assert_equal can generally not be used on floating point values, no?

@maflcko maflcko force-pushed the 2403-rpc-int-wrap- branch from fa28613 to fa73710 Compare April 27, 2024 14:52
@fjahr
Copy link
Contributor

fjahr commented Apr 27, 2024

re-ACK fa737100af538f7257e55d88fe1f24246bcce7fc

I think assert_equal can generally not be used on floating point values, no?

Here is a version with assert_approx: fjahr@24e9a37

@maflcko maflcko force-pushed the 2403-rpc-int-wrap- branch from fa73710 to ef692e5 Compare May 20, 2024 14:41
@maflcko
Copy link
Member Author

maflcko commented May 20, 2024

@fjahr Thanks! I've pushed your test commit with small fixups.

@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the
documentation.

Possibly this is due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.

Leave a comment here, if you need help tracking down a confusing failure.

Debug: https://github.com/bitcoin/bitcoin/runs/25183174149

@fjahr
Copy link
Contributor

fjahr commented May 21, 2024

re-ACK ef692e52b4121ba3d8de91e45b2d33aff946e8d2

Also reviewed #30144 to confirm the failure is ok.

fanquake added a commit that referenced this pull request May 22, 2024
…task

fa73431 ci: Add mising -Wno-error=maybe-uninitialized to armhf task (MarcoFalke)

Pull request description:

  This happens after bd597c3 in many pull requests as a silent merge conflict. For example:

  * #29720 (comment)
  * #29521 (comment)
  * (Probably many undetected, because the CI task was not yet re-run)
  * ...

ACKs for top commit:
  fjahr:
    utACK fa73431
  fanquake:
    ACK fa73431 - many fixed with 13.x

Tree-SHA512: 6e6ff8dc6f3c6a2abcd04c4203d3468f6e98c1ad3a4da4ad0037a9ee2cbec6bec079a5f778aba0273e38e173849927abcdfcfba7643d08ed66c1168cb89fab08
@maflcko maflcko requested a review from Sjors May 22, 2024 13:12
@maflcko maflcko force-pushed the 2403-rpc-int-wrap- branch from ef692e5 to fac11c5 Compare July 2, 2024 06:46
@maflcko maflcko force-pushed the 2403-rpc-int-wrap- branch from fac11c5 to 2342b46 Compare July 2, 2024 06:47
@fjahr
Copy link
Contributor

fjahr commented Jul 2, 2024

re-ACK 2342b46

Confirmed only changes were rebase and typo-fix, per git range-diff master ef692e52b4121ba3d8de91e45b2d33aff946e8d2 2342b46c451658a418f8e28e50b2ad0e5abd284d.

Copy link
Contributor

@mzumsande mzumsande left a comment

Choose a reason for hiding this comment

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

ACK 2342b46

I reviewed the code and tested the getchaintxstats output with a snapshot.

@achow101
Copy link
Member

achow101 commented Jul 2, 2024

ACK 2342b46

@achow101 achow101 merged commit 173ab0c into bitcoin:master Jul 2, 2024
@maflcko maflcko deleted the 2403-rpc-int-wrap- branch July 3, 2024 05:24
@hebasto
Copy link
Member

hebasto commented Jul 11, 2024

This PR introduced a new -Wmaybe-uninitialized warning when building with GCC < 13:

  • GCC 11:
  CXX      rpc/libbitcoin_node_a-blockchain.o
rpc/blockchain.cpp: In function ‘getchaintxstats()::<lambda(const RPCHelpMan&, const JSONRPCRequest&)>’:
rpc/blockchain.cpp:1742:38: warning: ‘*(std::_Optional_payload_base<unsigned int>::_Storage<unsigned int, true>*)((char*)&window_tx_count + offsetof(const std::optional<unsigned int>,std::optional<unsigned int>::<unnamed>.std::_Optional_base<unsigned int, true, true>::<unnamed>)).std::_Optional_payload_base<unsigned int>::_Storage<unsigned int, true>::_M_value’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 1742 |                 ret.pushKV("txrate", double(*window_tx_count) / nTimeDiff);
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~
  • GCC 12:
  CXX      rpc/libbitcoin_node_a-blockchain.o
rpc/blockchain.cpp: In function ‘getchaintxstats()::<lambda(const RPCHelpMan&, const JSONRPCRequest&)>’:
rpc/blockchain.cpp:1742:38: warning: ‘*(std::_Optional_payload_base<unsigned int>::_Storage<unsigned int, true>*)((char*)&window_tx_count + offsetof(const std::optional<unsigned int>,std::optional<unsigned int>::<unnamed>.std::_Optional_base<unsigned int, true, true>::<unnamed>)).std::_Optional_payload_base<unsigned int>::_Storage<unsigned int, true>::_M_value’ may be used uninitialized [-Wmaybe-uninitialized]
 1742 |                 ret.pushKV("txrate", double(*window_tx_count) / nTimeDiff);
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~
rpc/blockchain.cpp:1725:16: note: ‘*(std::_Optional_payload_base<unsigned int>::_Storage<unsigned int, true>*)((char*)&window_tx_count + offsetof(const std::optional<unsigned int>,std::optional<unsigned int>::<unnamed>.std::_Optional_base<unsigned int, true, true>::<unnamed>)).std::_Optional_payload_base<unsigned int>::_Storage<unsigned int, true>::_M_value’ was declared here
 1725 |     const auto window_tx_count{
      |                ^~~~~~~~~~~~~~~

@maflcko
Copy link
Member Author

maflcko commented Jul 12, 2024

See #29359

hebasto added a commit to hebasto/bitcoin that referenced this pull request Jul 15, 2024
Add `-Wno-error=maybe-uninitialized` for GCC 11.4.
See: bitcoin#29720 (comment)
hebasto added a commit to hebasto/bitcoin that referenced this pull request Jul 15, 2024
Add `-Wno-error=maybe-uninitialized` for GCC 11.4.
See: bitcoin#29720 (comment)
hebasto added a commit to hebasto/bitcoin that referenced this pull request Jul 15, 2024
d8c2692 fixup! ci: Test CMake edge cases (Hennadii Stepanov)

Pull request description:

  This PR adds `-Wno-error=maybe-uninitialized` for GCC 11.4.

  See: bitcoin#29720 (comment).

ACKs for top commit:
  m3dwards:
    ACK d8c2692

Tree-SHA512: 9c5b5ebf67a0fcc29288943b8f089f4e93bd6cd18e87f0d887cc3f7bc39a59a675ee526158f5c55a6788c9aaddeafa8f3365e436cdee245b8c71fb9f7805f6e0
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 6, 2025
Summary:
The getchaintxstats RPC reply during AU background download may return non-zero, but invalid, values for window_tx_count and txrate.

For example, txcount may be zero for a to-be-downloaded block, but may be non-zero for an ancestor block which is already downloaded. Thus, the values returned may be negative (and cause intermediate integer sanitizer violations).

Also, txcount may be accurate for the snapshot base block, or a descendant of it. However it may be zero for an ancestor block that still needs to be downloaded. Thus, the values returned may be positive, but wrong.

Fix all issues by skipping the returned value if either txcount is unset (equal to zero).
Also, skip txcount in the returned value, if it is unset (equal to zero).

This is a backport of [[bitcoin/bitcoin#29720 | core#29720]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D18053
@bitcoin bitcoin locked and limited conversation to collaborators Jul 12, 2025
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.

assumeutxo: nTx and nChainTx in RPC results are off

8 participants