refactor: store positions as a 64 bits integer in flatfiles #36669

pull darosior wants to merge 2 commits into bitcoin:master from darosior:2610_64bit_blockstorage changing 9 files +54 −23
  1. darosior commented at 4:01 PM on October 26, 2026: member

    That field is the last 32-bit in flat files management that is only bounded indirectly by callers' usage (unlike the file number for instance). In the spirit of the ongoing effort to avoid unnecessarily using 32 bits integers or platform specific types (for instance #24214, #33724, #34109, #35097, #35616), i was scanning for fields it could be prudent to promote to prevent any possible future misuse. This one is a good candidate because it does not change on-disk representation, since we serialize positions as varints.

  2. flatfile: store position as a 64 bits integer
    This is the last field that is only bounded by the usage callers make of it
    (unlike the file number, for instance). Promoting it to a 64 bits integer also
    does not change on-disk representation since we serialize positions as varints.
    Therefore, widen them to prevent any possible future misuse.
    17556cb1f5
  3. flatfile: use 64-bit file positioning syscalls in Windows 48092a9042
  4. DrahtBot added the label Refactoring on Oct 26, 2026
  5. DrahtBot commented at 4:01 PM on October 26, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK sedited, hebasto, instagibbs, l0rinc

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  6. sedited approved
  7. sedited commented at 4:28 PM on October 26, 2026: contributor

    tACK 48092a9042d8fcfd6bb7ae5911a1d53b8746d546

    Also ran a few extra tests locally to stresss this a bit and tested and reproduced the windows code.

  8. hebasto approved
  9. hebasto commented at 4:34 PM on October 26, 2026: member

    ACK 48092a9042d8fcfd6bb7ae5911a1d53b8746d546, I have reviewed the code and it looks OK.

  10. instagibbs approved
  11. instagibbs commented at 4:36 PM on October 26, 2026: member

    ACK 48092a9042d8fcfd6bb7ae5911a1d53b8746d546

    reproduced on linux only

  12. in src/chain.h:93 in 48092a9042


    l0rinc commented at 4:51 PM on October 26, 2026:

    48092a9 flatfile: use 64-bit file positioning syscalls in Windows:

    This increases sizeof(CBlockIndex) slightly, we can bring that back in a followup PR by moving nTx after m_chain_tx_count.

    <details> <summary>Restore the CBlockIndex size</summary>

    diff --git a/src/chain.h b/src/chain.h
    index 830cabe3f6..b2380468b2 100644
    --- a/src/chain.h
    +++ b/src/chain.h
    @@ -117,17 +117,17 @@ public:
         //! (memory only) Total amount of work (expected number of hashes) in the chain up to and including this block
         arith_uint256 nChainWork{};
     
    -    //! Number of transactions in this block. This will be nonzero if the block
    -    //! reached the VALID_TRANSACTIONS level, and zero otherwise.
    -    //! Note: in a potential headers-first mode, this number cannot be relied upon
    -    unsigned int nTx{0};
    -
         //! (memory only) Number of transactions in the chain up to and including this block.
         //! This value will be non-zero if this block and all previous blocks back
         //! to the genesis block or an assumeutxo snapshot block have reached the
         //! VALID_TRANSACTIONS level.
         uint64_t m_chain_tx_count{0};
     
    +    //! Number of transactions in this block. This will be nonzero if the block
    +    //! reached the VALID_TRANSACTIONS level, and zero otherwise.
    +    //! Note: in a potential headers-first mode, this number cannot be relied upon
    +    unsigned int nTx{0};
    +
         //! Verification status of this block. See enum BlockStatus
         //!
         //! Note: this value is modified to show BLOCK_OPT_WITNESS during UTXO snapshot
    

    </details>

  13. l0rinc approved
  14. l0rinc commented at 4:52 PM on October 26, 2026: contributor

    tested ACK 48092a9042d8fcfd6bb7ae5911a1d53b8746d546

    About time we got rid of the 32-bit file offsets - checked the CBlockIndex layout with Clang and GCC, the padding nit can be addressed in a follow-up.

  15. fanquake merged this on Oct 26, 2026
  16. fanquake closed this on Oct 26, 2026

  17. fanquake commented at 5:04 PM on October 26, 2026: member

    Backported to 32.x in #36658.

  18. fanquake referenced this in commit 98f204f51b on Oct 26, 2026
  19. fanquake referenced this in commit 09a3519e3b on Oct 26, 2026
  20. fanquake commented at 5:19 PM on October 26, 2026: member

    Backported to 31.x in #36661.

  21. fanquake referenced this in commit d47e0d7e24 on Oct 26, 2026
  22. fanquake referenced this in commit 307fbeeaf4 on Oct 26, 2026
  23. sedited referenced this in commit f0de87f040 on Oct 26, 2026
  24. fanquake referenced this in commit adb363c753 on Oct 26, 2026
  25. fanquake referenced this in commit a9e7b35d06 on Oct 26, 2026
  26. fanquake commented at 6:25 PM on October 26, 2026: member

    Backported to 30.x in #36664.

  27. fanquake referenced this in commit 241537a697 on Oct 26, 2026
  28. fanquake commented at 7:42 PM on October 26, 2026: member

    Backported to 29.x in #36666.

  29. fanquake referenced this in commit 5c99cb6745 on Oct 26, 2026

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: 2026-10-26 20:51 UTC

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