refactor: Split util/system into exception, shell, and fs-specific files #25152

pull Empact wants to merge 6 commits into bitcoin:master from Empact:2022-05-split-system changing 164 files +2166 −1962
  1. Empact commented at 6:52 AM on May 17, 2022: member

    This is an attempt to significantly improve code organization while making changes as simple as possible to review.

    Here I split four files out of util/system:

    • util/exception, holding PrintExceptionContinue
    • util/shell, holding ShellEscape, runCommand
    • util/fs, holding various file, folder, and path-specific functions (building on fs.h and filesystem)
    • util/args, holding ArgsManager and related functions

    The goal was to minimize review burden, so I made an effort to minimize the diffs and only modify the code when it was easy to confirm that the change would not have negative consequences.

    That said, sourcing all of the windows-related headers was not straightforward, so I expect I'll need to touch this up to correct any issues there.

  2. Empact cross-referenced this on May 17, 2022 from issue refactor: Split ArgsManager out of util/system by Empact
  3. Empact commented at 6:54 AM on May 17, 2022: member

    See prior discussion in #24455 /cc @dongcarl @ryanofsky

  4. Empact force-pushed on May 17, 2022
  5. DrahtBot added the label Refactoring on May 17, 2022
  6. Empact force-pushed on May 17, 2022
  7. Empact force-pushed on May 17, 2022
  8. Empact force-pushed on May 17, 2022
  9. Empact force-pushed on May 17, 2022
  10. Empact force-pushed on May 17, 2022
  11. Empact force-pushed on May 17, 2022
  12. Empact force-pushed on May 17, 2022
  13. dongcarl commented at 5:33 PM on May 17, 2022: contributor

    Concept ACK

    I think you can fix this CI failure with:

    diff --git a/src/Makefile.am b/src/Makefile.am
    index 3d6143d1ee..d06e51852e 100644
    --- a/src/Makefile.am
    +++ b/src/Makefile.am
    @@ -923,6 +923,7 @@ libbitcoinkernel_la_SOURCES = \
       util/rbf.cpp \
       util/serfloat.cpp \
       util/settings.cpp \
    +  util/shell.cpp \
       util/strencodings.cpp \
       util/string.cpp \
       util/syscall_sandbox.cpp \
    
  14. Empact force-pushed on May 18, 2022
  15. Empact force-pushed on May 19, 2022
  16. Empact commented at 5:35 AM on May 19, 2022: member

    Thanks @dongcarl - I've got some issues to figure out, particularly on the WIN32 side, and I'll be doing it via CI so it's going to mean some back and forth on this PR. E.g. the change is 5 commits but I'm going to have to play them out one by one to validate them.

  17. Empact force-pushed on May 21, 2022
  18. Empact force-pushed on May 24, 2022
  19. Empact force-pushed on May 24, 2022
  20. Empact force-pushed on May 24, 2022
  21. Empact force-pushed on May 24, 2022
  22. DrahtBot commented at 1:28 PM on May 24, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK dongcarl
    Stale ACK TheCharlatan

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #26812 (test: add end-to-end tests for CConnman and PeerManager by vasild)
    • #26720 (wallet: coin selection, don't return results that exceed the max allowed weight by furszy)
    • #26715 (Introduce MockableDatabase for wallet unit tests by achow101)
    • #26690 (wallet: Refactor database cursor into its own object with proper return codes by achow101)
    • #26654 (util: Show descriptive error messages when FileCommit fails by john-moffett)
    • #26504 (Add UNREACHABLE macro and drop -Wreturn-type/C4715 warnings suppressions by hebasto)
    • #26226 (Bump minimum python version to 3.7 by MarcoFalke)
    • #26177 (refactor / kernel: Move non-gArgs chainparams functionality to kernel by TheCharlatan)
    • #25390 (sync: introduce a thread-safe generic container and use it to remove a bunch of "GlobalMutex"es by vasild)
    • #24914 (wallet: Load database records in a particular order by achow101)
    • #24545 (BIP324: Enable v2 P2P encrypted transport by dhruv)
    • #24479 (Bugfix: util: Correctly handle Number value types in GetArg/GetBoolArg by luke-jr)
    • #24128 (wallet: BIP 326 sequence based anti-fee-snipe for taproot inputs by MarcoFalke)
    • #23561 (BIP324: Handshake prerequisites by dhruv)
    • #22341 (rpc: add getxpub by Sjors)
    • #19463 (Prune locks by luke-jr)
    • #16545 (refactor: Implement missing error checking for ArgsManager flags by ryanofsky)
    • #15294 (refactor: Extract RipeMd160 by Empact)
    • #14485 (Try to use posix_fadvise with CBufferedFile by luke-jr)

    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.

  23. DrahtBot cross-referenced this on May 24, 2022 from issue util: Move error message formatting of NonFatalCheckError to cpp by maflcko
  24. DrahtBot cross-referenced this on May 24, 2022 from issue Re-enable external signer support for Windows by luke-jr
  25. DrahtBot cross-referenced this on May 24, 2022 from issue test: Unit tests for taproot/tapscript coverage in `interpreter.cpp` by david-bakin
  26. Empact force-pushed on May 24, 2022
  27. Empact force-pushed on May 25, 2022
  28. dongcarl added this to the "WIP PRs" column in a project

  29. dongcarl moved this from the "WIP PRs" to the "Relevant External PRs" column in a project

  30. DrahtBot cross-referenced this on May 28, 2022 from issue Handle invalid hex encoding in ParseHex by maflcko
  31. DrahtBot cross-referenced this on May 28, 2022 from issue refactor: Make FEELER_SLEEP_WINDOW type safe (std::chrono) by maflcko
  32. Empact force-pushed on Jun 7, 2022
  33. Empact force-pushed on Jun 7, 2022
  34. Empact force-pushed on Jun 7, 2022
  35. Empact force-pushed on Jun 7, 2022
  36. Empact force-pushed on Jun 7, 2022
  37. DrahtBot cross-referenced this on Jun 8, 2022 from issue [kernel 3a/n] Decouple `CTxMemPool` from `ArgsManager` by dongcarl
  38. DrahtBot cross-referenced this on Jun 8, 2022 from issue refactor: Pass reference to LookUpStats by maflcko
  39. DrahtBot cross-referenced this on Jun 8, 2022 from issue Strengthen thread safety assertions by ajtowns
  40. DrahtBot cross-referenced this on Jun 8, 2022 from issue util: Use ArgsManager::GetPathArg more widely by hebasto
  41. DrahtBot cross-referenced this on Jun 8, 2022 from issue indexes: Stop using node internal types and locking cs_main, improve sync logic by ryanofsky
  42. DrahtBot cross-referenced this on Jun 8, 2022 from issue More robust file/directory syncing and error handling by luke-jr
  43. DrahtBot cross-referenced this on Jun 8, 2022 from issue Try to use posix_fadvise with CBufferedFile by luke-jr
  44. Empact force-pushed on Jun 8, 2022
  45. Empact force-pushed on Jun 8, 2022
  46. Empact force-pushed on Jun 9, 2022
  47. DrahtBot cross-referenced this on Jun 9, 2022 from issue refactor: add most of src/util to iwyu by fanquake
  48. DrahtBot cross-referenced this on Jun 9, 2022 from issue refactor: Reduce number of LoadChainstate parameters and return values by ryanofsky
  49. DrahtBot added the label Needs rebase on Jun 10, 2022
  50. Empact force-pushed on Jun 16, 2022
  51. DrahtBot removed the label Needs rebase on Jun 16, 2022
  52. DrahtBot cross-referenced this on Jun 16, 2022 from issue logging: threshold log level by klementtan
  53. DrahtBot cross-referenced this on Jun 16, 2022 from issue refactor: use std:: prefix for std lib funcs by fanquake
  54. DrahtBot cross-referenced this on Jun 16, 2022 from issue Torcontrol opt check by amadeuszpawlik
  55. DrahtBot cross-referenced this on Jun 16, 2022 from issue wallet: Load database records in a particular order by achow101
  56. DrahtBot cross-referenced this on Jun 16, 2022 from issue wallet: Improve AvailableCoins performance by reducing duplicated operations by achow101
  57. Empact force-pushed on Jun 16, 2022
  58. DrahtBot cross-referenced this on Jun 16, 2022 from issue sync: introduce a thread-safe generic container and use it to remove a bunch of "GlobalMutex"es by vasild
  59. DrahtBot cross-referenced this on Jun 17, 2022 from issue wallet: Properly support a wallet id by achow101
  60. Empact force-pushed on Jun 18, 2022
  61. DrahtBot cross-referenced this on Jun 20, 2022 from issue build: globally define NOMINMAX when building with mingw-w64 by fanquake
  62. DrahtBot added the label Needs rebase on Jun 21, 2022
  63. TheCharlatan commented at 11:33 AM on September 18, 2022: contributor

    Code review ACK 2355b9c

    I reproduced much of the code move / split diff manually. The splitting makes sense to me, I had to overthink the split of functions into logging.* and exception.* , but keeping platform specific logging things in util/ (as done for the exceptions) seems sane to me. @Empact is there any platform testing I can do to get this PR moving again?

  64. TheCharlatan cross-referenced this on Sep 24, 2022 from issue refactor / kernel: Move non-gArgs chainparams functionality to kernel by TheCharlatan
  65. TheCharlatan cross-referenced this on Sep 24, 2022 from issue refactor / kernel: Move non-gArgs chainparams functionality to kernel by TheCharlatan
  66. Empact force-pushed on Oct 10, 2022
  67. Empact force-pushed on Oct 10, 2022
  68. Empact force-pushed on Oct 10, 2022
  69. Empact force-pushed on Oct 10, 2022
  70. DrahtBot cross-referenced this on Oct 10, 2022 from issue test: Remove unused txmempool include from tests by maflcko
  71. Empact force-pushed on Oct 10, 2022
  72. Empact force-pushed on Oct 10, 2022
  73. Empact force-pushed on Oct 10, 2022
  74. Empact force-pushed on Oct 10, 2022
  75. DrahtBot removed the label Needs rebase on Oct 10, 2022
  76. Empact force-pushed on Oct 10, 2022
  77. DrahtBot cross-referenced this on Oct 10, 2022 from issue Use util::Result in for calculating mempool ancestors by stickies-v
  78. DrahtBot cross-referenced this on Oct 11, 2022 from issue clang-tidy: fixup named argument comments by fanquake
  79. DrahtBot cross-referenced this on Oct 11, 2022 from issue rpc: Strict type checking for RPC boolean parameters by maflcko
  80. DrahtBot cross-referenced this on Oct 11, 2022 from issue rpc: Sanitize label name in various RPCs with tests by aureleoules
  81. DrahtBot cross-referenced this on Oct 11, 2022 from issue More verbose warning for multiple network argument error. by amovfx
  82. Empact force-pushed on Oct 11, 2022
  83. DrahtBot cross-referenced this on Oct 11, 2022 from issue Replace global g_cs_orphans lock with local by ajtowns
  84. DrahtBot cross-referenced this on Oct 11, 2022 from issue refactor: move interfaces/* to common/interfaces/* by fanquake
  85. DrahtBot cross-referenced this on Oct 11, 2022 from issue util: move threadinterrupt into util/ by fanquake
  86. DrahtBot cross-referenced this on Oct 11, 2022 from issue p2p: remove adjusted time by fanquake
  87. DrahtBot cross-referenced this on Oct 11, 2022 from issue util, config: error on startup if `conf` or `reindex` are set in config file by josibake
  88. DrahtBot cross-referenced this on Oct 11, 2022 from issue [Draft / POC] Silent Payments by w0xlt
  89. DrahtBot cross-referenced this on Oct 11, 2022 from issue BIP324: Enable v2 P2P encrypted transport by dhruv
  90. DrahtBot cross-referenced this on Oct 11, 2022 from issue Bugfix: util: Correctly handle Number value types in GetArg/GetBoolArg by luke-jr
  91. DrahtBot cross-referenced this on Oct 12, 2022 from issue wallet: BIP 326 sequence based anti-fee-snipe for taproot inputs by maflcko
  92. DrahtBot cross-referenced this on Oct 12, 2022 from issue BIP324: Handshake prerequisites by dhruv
  93. DrahtBot cross-referenced this on Oct 12, 2022 from issue rpc: add path to gethdkey by Sjors
  94. DrahtBot cross-referenced this on Oct 12, 2022 from issue cli: Parse and allow hash value by fjahr
  95. DrahtBot cross-referenced this on Oct 12, 2022 from issue multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky
  96. DrahtBot cross-referenced this on Oct 12, 2022 from issue multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky
  97. DrahtBot cross-referenced this on Oct 12, 2022 from issue util: Fix -norpcwhitelist, -norpcallowip, and similar corner case behavior by ryanofsky
  98. DrahtBot cross-referenced this on Oct 12, 2022 from issue refactor: Remove settings merge reverse precedence code by ryanofsky
  99. DrahtBot cross-referenced this on Oct 12, 2022 from issue refactor: Add ALLOW_LIST flags and enforce usage in CheckArgFlags by ryanofsky
  100. DrahtBot cross-referenced this on Oct 12, 2022 from issue util: Forbid ambiguous multiple assignments in config file by ryanofsky
  101. DrahtBot cross-referenced this on Oct 12, 2022 from issue ci: Integrate `bitcoin-tidy` clang-tidy plugin by fanquake
  102. Empact marked this as ready for review on Oct 12, 2022
  103. Empact marked this as a draft on Oct 12, 2022
  104. Empact cross-referenced this on Oct 12, 2022 from issue refactor: Extract util/exception from util/system by Empact
  105. DrahtBot cross-referenced this on Oct 13, 2022 from issue refactor: Use type-safe time point for CWallet::m_next_resend by maflcko
  106. DrahtBot cross-referenced this on Oct 18, 2022 from issue refactor: Implement missing error checking for ArgsManager flags by ryanofsky
  107. DrahtBot cross-referenced this on Oct 18, 2022 from issue refactor: Extract RipeMd160 by Empact
  108. DrahtBot cross-referenced this on Oct 18, 2022 from issue Add fee_est tool for debugging fee estimation code by ryanofsky
  109. DrahtBot cross-referenced this on Oct 18, 2022 from issue Multiprocess bitcoin by ryanofsky
  110. DrahtBot cross-referenced this on Oct 18, 2022 from issue Drop IO priority to idle while reading blocks for peer requests and startup verification by luke-jr
  111. DrahtBot added the label Needs rebase on Oct 19, 2022
  112. refactor: Extract util/exception from util/system
    This is a minimal extraction of a single public method, but also
    the only use of std::exception in util/system.
    
    Include libloaderapi.h for GetModuleFileNameA as that's the
    source noted here: https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamea
    f12cd1d77b
  113. refactor: Extract util/shell from util/system
    This is a minimal extraction of shell-specific functions
    from util/system.
    e5243d3676
  114. refactor: Move error() from util/system.h to logging.h
    error is a low-level function with a sole dependency on LogPrintf,
    which is defined in logging.h
    f1daaf1d89
  115. refactor: Extract util/fs from util/system 7745b29ca4
  116. refactor: Extract util/args from util/system 9ff4bb56ba
  117. refactor: Drop now-unnecessary includes of util/system.h b070db4f1f
  118. Empact force-pushed on Jan 10, 2023
  119. DrahtBot removed the label Needs rebase on Jan 10, 2023
  120. DrahtBot cross-referenced this on Jan 11, 2023 from issue test: add end-to-end tests for CConnman and PeerManager by vasild
  121. DrahtBot cross-referenced this on Jan 11, 2023 from issue ci: Use clang-15 and IWYU v0.19 in "tidy" task by hebasto
  122. DrahtBot cross-referenced this on Jan 11, 2023 from issue wallet: coin selection, don't return results that exceed the max allowed weight by furszy
  123. DrahtBot cross-referenced this on Jan 11, 2023 from issue Introduce `MockableDatabase` for wallet unit tests by achow101
  124. DrahtBot cross-referenced this on Jan 11, 2023 from issue wallet: Refactor database cursor into its own object with proper return codes by achow101
  125. DrahtBot cross-referenced this on Jan 11, 2023 from issue util: Show descriptive error messages when FileCommit fails by john-moffett
  126. DrahtBot cross-referenced this on Jan 11, 2023 from issue Add `UNREACHABLE` macro by hebasto
  127. DrahtBot cross-referenced this on Jan 11, 2023 from issue refactor: Avoid UniValue copies by maflcko
  128. DrahtBot cross-referenced this on Jan 11, 2023 from issue Prune locks by luke-jr
  129. in src/util/shell.cpp:26 in b070db4f1f
      21 | +#include <ostream>
      22 | +#include <vector>
      23 | +#if defined(__GNUC__)
      24 | +#pragma GCC diagnostic pop
      25 | +#endif
      26 | +#endif // ENABLE_EXTERNAL_SIGNER
    


    TheCharlatan commented at 10:20 PM on January 17, 2023:

    AFAICT the build failures are coming from including these lines and I don't think they are needed, so I'm guessing this was included to debug a windows problem? I'm keen on moving this PR forward,. Is there some deeper problem here with running this patch on windows, or is it a compile-time issue?


    fanquake commented at 10:48 AM on January 18, 2023:

    in e5243d3676136e4b0a590e76a07c86e62ca7d1f7:

    and I don't think they are needed,

    Yea, there is no Boost usage in this file (and is no-longer any in the util library), so the entire ENABLE_EXTERNAL_SIGNER chunk here should be removed.

  130. DrahtBot cross-referenced this on Jan 18, 2023 from issue Bump minimum python version to 3.7 by maflcko
  131. in src/util/exception.cpp:15 in f12cd1d77b outdated
      10 | +
      11 | +#include <iostream>
      12 | +#include <typeinfo>
      13 | +
      14 | +#ifdef WIN32
      15 | +#include <compat/compat.h>
    


    fanquake commented at 10:44 AM on January 18, 2023:

    In f12cd1d77bc062f1313f98a8aaea8afd96c4f52e: Why is compat being included here? if it's for a windows.h include (which isn't in compat anyways), then I'd rather we just include windows.h.

  132. in src/util/shell.cpp:38 in e5243d3676 outdated
      33 | +#include <cstdlib>
      34 | +#include <stdexcept>
      35 | +#include <string>
      36 | +
      37 | +#ifdef WIN32
      38 | +#include <compat/compat.h>
    


    fanquake commented at 10:49 AM on January 18, 2023:

    In e5243d3676136e4b0a590e76a07c86e62ca7d1f7: If this is for windows.h, would rather just include that.

  133. in src/util/shell.h:15 in e5243d3676 outdated
      10 | +#include <config/bitcoin-config.h>
      11 | +#endif
      12 | +
      13 | +#include <string>
      14 | +
      15 | +class UniValue;
    


    fanquake commented at 10:51 AM on January 18, 2023:

    In e5243d3676136e4b0a590e76a07c86e62ca7d1f7: Why is UniValue in here?

  134. in test/lint/lint-circular-dependencies.py:40 in 9ff4bb56ba outdated
      36 | @@ -37,7 +37,7 @@ def main():
      37 |  
      38 |      os.chdir(CODE_DIR)
      39 |      files = subprocess.check_output(
      40 | -        ['git', 'ls-files', '--', '*.h', '*.cpp'],
      41 | +        ["git", "ls-files", "--", "*.h", "*.cpp"],
    


    fanquake commented at 10:54 AM on January 18, 2023:

    In 9ff4bb56baa509c587698cb3a2877dfd4ff6d136: This seems unrelated to this commit, and is not mentioned in the commit message.

  135. DrahtBot commented at 4:26 PM on January 18, 2023: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->

    🐙 This pull request conflicts with the target branch and needs rebase.

  136. DrahtBot added the label Needs rebase on Jan 18, 2023
  137. TheCharlatan commented at 3:02 PM on March 7, 2023: contributor

    I redid this work (fixing more of the includes and splitting out a few more functions) and have a branch over here: https://github.com/TheCharlatan/bitcoin/pull/10 @Empact I'm still keen on moving this work forward. If you don't have the time right now, I'll attribute the commits to you and try to get my branch merged instead.

  138. christ79ma approved
  139. fanquake commented at 7:48 PM on March 7, 2023: member

    I'm still keen on moving this work forward. If you don't have the time right now, I'll attribute the commits to you and try to get my branch merged instead.

    Yep, it would be good to start getting some of this merged.

  140. TheCharlatan cross-referenced this on Mar 10, 2023 from issue refactor: Split logging utilities from system.h by TheCharlatan
  141. fanquake referenced this in commit b175bdb9b2 on Mar 14, 2023
  142. TheCharlatan cross-referenced this on Mar 14, 2023 from issue refactor: Extract util/fs from util/system by TheCharlatan
  143. fanquake commented at 11:37 AM on March 14, 2023: member

    Going to close this for now, given that it's being split out, and there's a thumbs up from the author above.

  144. fanquake closed this on Mar 14, 2023

  145. fanquake referenced this in commit 369d4c03b7 on Apr 3, 2023
  146. bitcoin locked this on Mar 13, 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: 2026-05-20 06:52 UTC

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