chainparams: Change nChainTx type to uint64_t #29656

pull fjahr wants to merge 3 commits into bitcoin:master from fjahr:2024-03-nchaintx-64 changing 12 files +75 βˆ’69
  1. fjahr commented at 11:34 pm on March 14, 2024: contributor

    This picks up the work from #29331 and closes #29258.

    This simply changes the type and addresses the comments from #29331 by changing the type in all relevant places and removing unnecessary casts. This also adds an extremely simple unit test.

    Additionally this modernizes the name of nChainTx which helps reviewers check all use of the symbol and can make silent merge conflicts.

  2. DrahtBot commented at 11:34 pm on March 14, 2024: contributor

    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 maflcko, glozow
    Concept ACK naiyoma
    Stale ACK Randy808, marcofleon, BrandonOdiwuor

    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:

    • #30560 (refactor: Add consteval uint256 constructor by hodlinator)
    • #30377 (refactor: Add consteval uint256{“str”} by hodlinator)
    • #30364 (logging: Replace LogError and LogWarning with LogAlert by ryanofsky)
    • #30214 (refactor: Improve assumeutxo state representation by ryanofsky)
    • #29641 (scripted-diff: Use LogInfo/LogDebug over LogPrintf/LogPrint by maflcko)

    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.

  3. DrahtBot added the label CI failed on Mar 15, 2024
  4. DrahtBot commented at 0:33 am on March 15, 2024: 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/22684534883

  5. fanquake commented at 2:34 pm on March 15, 2024: member
     0==25794==ERROR: LeakSanitizer: detected memory leaks
     1
     2Direct leak of 152 byte(s) in 1 object(s) allocated from:
     3    [#0](/bitcoin-bitcoin/0/) 0x5597c4ef3931 in operator new(unsigned long) (/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/test/test_bitcoin+0x1276931) (BuildId: dc550d0a0634dbe1f98f193b152915bbb7968f28)
     4    [#1](/bitcoin-bitcoin/1/) 0x5597c53b3398 in CreateBlockIndexWithNbits(unsigned int) src/test/blockchain_tests.cpp:24:32
     5    [#2](/bitcoin-bitcoin/2/) 0x5597c53b1e58 in blockchain_tests::num_chain_tx_max_invoker() src/test/blockchain_tests.cpp:77:1
     6    [#3](/bitcoin-bitcoin/3/) 0x5597c4fea063 in boost::function0<void>::operator()() const /usr/include/boost/function/function_template.hpp:771:14
     7    [#4](/bitcoin-bitcoin/4/) 0x5597c5070afa in boost::detail::forward::operator()() /usr/include/boost/test/impl/execution_monitor.ipp:1395:32
     8    [#5](/bitcoin-bitcoin/5/) 0x5597c5070afa in boost::detail::function::function_obj_invoker0<boost::detail::forward, int>::invoke(boost::detail::function::function_buffer&) /usr/include/boost/function/function_template.hpp:137:18
     9    [#6](/bitcoin-bitcoin/6/) 0x5597c4f2922f in int boost::detail::do_invoke<boost::shared_ptr<boost::detail::translator_holder_base>, boost::function<int ()>>(boost::shared_ptr<boost::detail::translator_holder_base> const&, boost::function<int ()> const&) /usr/include/boost/test/impl/execution_monitor.ipp:308:30
    10    [#7](/bitcoin-bitcoin/7/) 0x5597c4f2922f in boost::execution_monitor::catch_signals(boost::function<int ()> const&) /usr/include/boost/test/impl/execution_monitor.ipp:910:16
    11    [#8](/bitcoin-bitcoin/8/) 0x5597c4f297fe in boost::execution_monitor::execute(boost::function<int ()> const&) /usr/include/boost/test/impl/execution_monitor.ipp:1308:16
    12    [#9](/bitcoin-bitcoin/9/) 0x5597c4f214fb in boost::execution_monitor::vexecute(boost::function<void ()> const&) /usr/include/boost/test/impl/execution_monitor.ipp:1404:5
    13    [#10](/bitcoin-bitcoin/10/) 0x5597c4f214fb in boost::unit_test::unit_test_monitor_t::execute_and_translate(boost::function<void ()> const&, unsigned long) /usr/include/boost/test/impl/unit_test_monitor.ipp:49:9
    14    [#11](/bitcoin-bitcoin/11/) 0x5597c4fa3c92 in boost::unit_test::framework::state::execute_test_tree(unsigned long, unsigned long, boost::unit_test::framework::state::random_generator_helper const*) /usr/include/boost/test/impl/framework.ipp:815:44
    15    [#12](/bitcoin-bitcoin/12/) 0x5597c4fa2c0f in boost::unit_test::framework::state::execute_test_tree(unsigned long, unsigned long, boost::unit_test::framework::state::random_generator_helper const*) /usr/include/boost/test/impl/framework.ipp:784:58
    16    [#13](/bitcoin-bitcoin/13/) 0x5597c4fa2c0f in boost::unit_test::framework::state::execute_test_tree(unsigned long, unsigned long, boost::unit_test::framework::state::random_generator_helper const*) /usr/include/boost/test/impl/framework.ipp:784:58
    17    [#14](/bitcoin-bitcoin/14/) 0x5597c4f1f4a5 in boost::unit_test::framework::run(unsigned long, bool) /usr/include/boost/test/impl/framework.ipp:1722:29
    18    [#15](/bitcoin-bitcoin/15/) 0x5597c4f54a47 in boost::unit_test::unit_test_main(boost::unit_test::test_suite* (*)(int, char**), int, char**) /usr/include/boost/test/impl/unit_test_main.ipp:250:9
    19    [#16](/bitcoin-bitcoin/16/) 0x7f0c325b31c9  (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: b58ab3be268281d0cf45f2b22cbd4ba8b4aac9bd)
    20    [#17](/bitcoin-bitcoin/17/) 0x7f0c325b328a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: b58ab3be268281d0cf45f2b22cbd4ba8b4aac9bd)
    21    [#18](/bitcoin-bitcoin/18/) 0x5597c4e17804 in _start (/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/test/test_bitcoin+0x119a804) (BuildId: dc550d0a0634dbe1f98f193b152915bbb7968f28)
    22
    23SUMMARY: AddressSanitizer: 152 byte(s) leaked in 1 allocation(s).
    
  6. fjahr force-pushed on Mar 15, 2024
  7. fjahr force-pushed on Mar 15, 2024
  8. DrahtBot removed the label CI failed on Mar 15, 2024
  9. fjahr commented at 5:34 pm on March 15, 2024: contributor
    Fixed CI
  10. Randy808 commented at 12:52 pm on March 18, 2024: contributor
    ACK afa67033772d750a15231aa0aa998a0454848bea
  11. maflcko commented at 1:03 pm on March 18, 2024: member

    In some draft by sjors from 5 years ago I saw that he took the chance to rename the variable to m_chain_num_tx. I didn’t do this now because nChainTx isn’t terrible IMO, just outdated, but happy to do this if people think it’s valuable while I touch these lines.

    I’d say it should. Reviewers will have to look up every use of the symbol anyway. Also, a rename turns silent merge conflicts into compile failures, so devs are notified if an old use of the symbol remains, which may assume a 32-bit width.

  12. fjahr commented at 10:30 pm on March 18, 2024: contributor
    Added a scripted diff renaming nChainTx to m_chain_tx_count.
  13. fjahr force-pushed on Mar 18, 2024
  14. DrahtBot added the label CI failed on Mar 18, 2024
  15. DrahtBot removed the label CI failed on Mar 19, 2024
  16. in src/kernel/chainparams.h:72 in cef04348bc outdated
    68@@ -69,7 +69,7 @@ struct AssumeutxoData {
    69  */
    70 struct ChainTxData {
    71     int64_t nTime;    //!< UNIX timestamp of last known number of transactions
    72-    int64_t nTxCount; //!< total number of transactions between genesis and that timestamp
    73+    uint64_t nTxCount; //!< total number of transactions between genesis and that timestamp
    


    maflcko commented at 9:34 am on March 20, 2024:
    0    uint64_t tx_count; //!< total number of transactions between genesis and that timestamp
    

    Should this also be renamed in the scripted diff?


    fjahr commented at 2:36 pm on March 20, 2024:
    sure, added
  17. fjahr force-pushed on Mar 20, 2024
  18. fjahr commented at 2:42 pm on March 20, 2024: contributor
    @maflcko @ryanofsky curious about your thoughts on https://github.com/fjahr/bitcoin/commit/b9382041e541569a2b8ec7ed1f7fb10aa602277f , i.e. if should take that route with memory optimization or if you think it’s not necessary after all.
  19. DrahtBot added the label Needs rebase on Mar 20, 2024
  20. fjahr force-pushed on Mar 20, 2024
  21. DrahtBot removed the label Needs rebase on Mar 20, 2024
  22. maflcko commented at 2:32 pm on March 24, 2024: member

    @maflcko @ryanofsky curious about your thoughts on fjahr@b938204 , i.e. if should take that route with memory optimization or if you think it’s not necessary after all.

    I don’t think it is needed. If it was done, it should be a bitfield instead, no? See also #29258 (comment) ?

  23. fjahr commented at 8:42 pm on March 25, 2024: contributor

    I don’t think it is needed. If it was done, it should be a bitfield instead, no? See also #29258 (comment) ?

    I could change the approach to bitfields, sure. I don’t think we are using them anywhere yet so I wasn’t sure if it would really be the preferred approach. But if it’s not needed, I will just leave the PR as is for now.

  24. maflcko commented at 8:08 am on March 28, 2024: member

    I don’t think it is needed. If it was done, it should be a bitfield instead, no? See also #29258 (comment) ?

    I could change the approach to bitfields, sure. I don’t think we are using them anywhere yet so I wasn’t sure if it would really be the preferred approach. But if it’s not needed, I will just leave the PR as is for now.

    Yeah, I think the current approach is fine. bitfields can be done in a follow-up, if needed. One thing to look out for would be to check that the integer sanitizer works properly on bitfields as well.

  25. maflcko commented at 8:15 am on March 28, 2024: member
    Concept ACK. I think the pull description can be rewritten, since it ends up in plain text in the merge commit. Instead of writing “Thing A is not included. It is now”, it would be better to say why it is included and remove the formatting/negation: “Thing A is included, because (…motivation…)”
  26. fjahr commented at 9:45 pm on April 27, 2024: contributor

    Concept ACK. I think the pull description can be rewritten, since it ends up in plain text in the merge commit. Instead of writing “Thing A is not included. It is now”, it would be better to say why it is included and remove the formatting/negation: “Thing A is included, because (…motivation…)”

    I have updated the description.

  27. DrahtBot added the label Needs rebase on Jul 3, 2024
  28. in src/chain.h:176 in 64d35be20c outdated
    173@@ -174,7 +174,7 @@ class CBlockIndex
    174     //! to the genesis block or an assumeutxo snapshot block have reached the
    175     //! VALID_TRANSACTIONS level.
    176     //! Change to 64-bit type before 2024 (assuming worst case of 60 byte transactions).
    


    glozow commented at 11:09 am on July 3, 2024:
    64d35be20c43f764e5c22657085a790d0adcfe22 should remove this todo comment

    fjahr commented at 4:09 pm on July 5, 2024:
    Done
  29. glozow commented at 11:10 am on July 3, 2024: member
    concept ACK
  30. in src/rpc/blockchain.cpp:2802 in 557a9cfb6c outdated
    2715@@ -2716,7 +2716,7 @@ UniValue CreateUTXOSnapshot(
    2716     result.pushKV("base_height", tip->nHeight);
    2717     result.pushKV("path", path.utf8string());
    2718     result.pushKV("txoutset_hash", maybe_stats->hashSerialized.ToString());
    2719-    result.pushKV("nchaintx", tip->nChainTx);
    


    naiyoma commented at 10:02 am on July 5, 2024:
    Would it make sense to also change this string nchaintx to m_chain_tx_count for consistency?

    fjahr commented at 4:09 pm on July 5, 2024:
    This would mean that we return a different key in the JSON returned from the RPC. We usually don’t do this unless it’s needed in order to not break things on the user side. We also only use the m_ prefix for class members.
  31. naiyoma commented at 10:26 am on July 5, 2024: contributor
    Concept ACK. Nit: IMO, https://github.com/bitcoin/bitcoin/commit/64d35be20c43f764e5c22657085a790d0adcfe22 message should be amended to also include nTxCount and nTxDiff, since it’s not just nChainTx that’s changing to uint64_t.
  32. fjahr force-pushed on Jul 5, 2024
  33. fjahr force-pushed on Jul 5, 2024
  34. fjahr commented at 4:30 pm on July 5, 2024: contributor

    Rebased and addressed comments

    Nit: IMO, https://github.com/bitcoin/bitcoin/commit/64d35be20c43f764e5c22657085a790d0adcfe22 message should be amended to also include nTxCount and nTxDiff, since it’s not just nChainTx that’s changing to uint64_t.

    Naming all the local variables that are touched isn’t necessary I think but I added a comment in the commit description.

  35. DrahtBot removed the label Needs rebase on Jul 5, 2024
  36. DrahtBot added the label Needs rebase on Jul 9, 2024
  37. fjahr force-pushed on Jul 10, 2024
  38. fjahr commented at 9:18 am on July 10, 2024: contributor
    Rebased (caused by #30329)
  39. DrahtBot added the label CI failed on Jul 10, 2024
  40. DrahtBot removed the label Needs rebase on Jul 10, 2024
  41. in src/test/blockchain_tests.cpp:83 in e78cf83bee outdated
    75@@ -76,4 +76,11 @@ BOOST_AUTO_TEST_CASE(get_difficulty_for_very_high_target)
    76     TestDifficulty(0x12345678, 5913134931067755359633408.0);
    77 }
    78 
    79+BOOST_AUTO_TEST_CASE(num_chain_tx_max)
    80+{
    81+    std::unique_ptr<CBlockIndex> block_index{CreateBlockIndexWithNbits(0x1f111111)};
    82+    block_index->nChainTx = std::numeric_limits<uint64_t>::max();
    83+    BOOST_CHECK_EQUAL(block_index->nChainTx, std::numeric_limits<uint64_t>::max());
    


    maflcko commented at 12:17 pm on July 10, 2024:

    nit in e78cf83beec2f508823803947bdc3d9bcb7c7217: Not sure why nbits matter for this test.

    I think you can just write CBlockIndex block{.nChainTx=..max()};, replacing the first two lines.


    fjahr commented at 3:45 pm on July 10, 2024:

    nit in e78cf83: Not sure why nbits matter for this test.

    Yeah, I had just reused the helper method from this test but it’s not needed indeed. I am using an empty constructor now.

    I think you can just write CBlockIndex block{.nChainTx=..max()};, replacing the first two lines.

    I am unfamiliar with the ..max() syntax and I am also getting a compiler error when I try to use a designated initializer here, I didn’t investigate deeper why that is though.


    maflcko commented at 6:36 pm on August 1, 2024:
    Yes, looks good, thanks! (Can be resolved)
  42. maflcko commented at 12:39 pm on July 10, 2024: member

    ACK 242116cdf3fac6fa9af1d01387cca2cf4be1ccb πŸ••

    Signature:

    0untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
    1RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
    2trusted comment: ACK 242116cdf3fac6fa9af1d01387cca2cf4be1ccb πŸ••
    3KrtFcepn0TtAJ0W7GfxawMzY3jMtWFrv0xnB2Ns8BxeEtkJRw9IZoH2BkP3m719p6mBJGmYKIIPBIZZLjpECDw==
    
  43. DrahtBot requested review from glozow on Jul 10, 2024
  44. DrahtBot requested review from naiyoma on Jul 10, 2024
  45. maflcko commented at 12:43 pm on July 10, 2024: member

    Additionally this modernizes the name of nChainTx to m_chain_num_tx which helps reviewers check all use of the symbol and can make silent merge conflicts.

    I think you can drop the new name from the pull description. It is wrong right now (doesn’t match the scripted diff), and if anyone wanted to find it, they can look at the scripted diff.

  46. fjahr force-pushed on Jul 10, 2024
  47. fjahr commented at 3:45 pm on July 10, 2024: contributor

    I think you can drop the new name from the pull description. It is wrong right now (doesn’t match the scripted diff), and if anyone wanted to find it, they can look at the scripted diff.

    done

  48. DrahtBot removed the label CI failed on Jul 10, 2024
  49. DrahtBot added the label Needs rebase on Jul 10, 2024
  50. fjahr force-pushed on Jul 10, 2024
  51. fjahr commented at 10:20 pm on July 10, 2024: contributor
    Rebased
  52. DrahtBot removed the label Needs rebase on Jul 10, 2024
  53. marcofleon commented at 5:57 pm on August 1, 2024: contributor
    ACK fab49990eb787aabd908f6ba88f5e00ed9844f91. Reviewed the changes, grepped for the old variable names, and ran make check and the individual test. I read a bit of the background (links provided in the PR description) and there doesn’t seem to be any issue with this change in validation.
  54. DrahtBot requested review from maflcko on Aug 1, 2024
  55. maflcko commented at 6:32 pm on August 1, 2024: member

    Only small test-only change since my last review.

    re-ACK fab49990eb787aabd908f6ba88f5e00ed9844f91 πŸ˜€

    Signature:

    0untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
    1RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
    2trusted comment: re-ACK fab49990eb787aabd908f6ba88f5e00ed9844f91 πŸ˜€
    3Fsjrn1dY2sNZN+BXoOuWHpOVhTzOtT0SOzaN6cIZIETwTJLL2IVNRIzT1/frUp+yAK9F3ug64qRRRpIHBVuADQ==
    
  56. maflcko added this to the milestone 28.0 on Aug 1, 2024
  57. DrahtBot added the label Needs rebase on Aug 2, 2024
  58. glozow commented at 2:32 pm on August 2, 2024: member
    utACK fab49990eb787aabd908f6ba88f5e00ed9844f91, happy to reack after rebase
  59. BrandonOdiwuor commented at 4:07 pm on August 2, 2024: contributor

    Code Review ACK fab49990eb787aabd908f6ba88f5e00ed9844f91

    Looks Good To Me

  60. chainparams: Change nChainTx to uint64_t
    Also update types of assumeutxo chainparams and some related local variables for
    consistency.
    
    Co-authored-by: russeree <reese.russell@ymail.com>
    dc2938e979
  61. test: Add basic check for nChainTx type 72e5d1be1f
  62. scripted-diff: Modernize naming of nChainTx and nTxCount
    -BEGIN VERIFY SCRIPT-
    sed -i 's/nChainTx/m_chain_tx_count/g' $(git grep -l 'nChainTx' ./src)
    sed -i 's/nTxCount/tx_count/g' $(git grep -l 'nTxCount' ./src)
    -END VERIFY SCRIPT-
    bf0efb4fc7
  63. fjahr force-pushed on Aug 4, 2024
  64. DrahtBot removed the label Needs rebase on Aug 4, 2024
  65. fjahr commented at 1:49 pm on August 4, 2024: contributor
    Thanks for the reviews! Rebased now.
  66. maflcko commented at 6:58 am on August 5, 2024: member

    only rebase in scripted-diff, re-ACK bf0efb4fc72d3c49a2c498c944e55466dfa046dc πŸ”ˆ

    Signature:

    0untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
    1RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
    2trusted comment: only rebase in scripted-diff, re-ACK bf0efb4fc72d3c49a2c498c944e55466dfa046dc πŸ”ˆ
    3ruOHRLnefy5sonIHAM71FuUUYpKz/jrDSkuVcFSapzqkvh3kq31AlfTk8GrfX+nBCW3RmnogkSesMTaFxEtkAg==
    
  67. DrahtBot requested review from glozow on Aug 5, 2024
  68. DrahtBot requested review from marcofleon on Aug 5, 2024
  69. DrahtBot requested review from BrandonOdiwuor on Aug 5, 2024
  70. glozow commented at 8:23 am on August 5, 2024: member
    reACK bf0efb4fc72 via range-diff
  71. glozow removed review request from BrandonOdiwuor on Aug 5, 2024
  72. glozow removed review request from glozow on Aug 5, 2024
  73. glozow removed review request from naiyoma on Aug 5, 2024
  74. glozow merged this on Aug 5, 2024
  75. glozow closed this on Aug 5, 2024


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-24 06:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me