build: Introduce internal kernel library #28690

pull sedited wants to merge 2 commits into bitcoin:master from sedited:kernelInternalLib changing 7 files +126 −120
  1. sedited commented at 11:01 AM on October 20, 2023: contributor

    This PR introduces a new libbitcoin_kernel internal library. It completes the internal library design as laid out in doc/design/libraries.md. Since the util library contains a bunch of modules that are not required by the kernel library, a new kernel_util library is introduced as well that only consists of the modules required by the kernel library. The external libbitcoinkernel library now re-uses the compiled objects from the internal libraries.

    There is a trade-off to this. Since we don't manually export symbols from the kernel library yet, this would make the library unusable if REDUCE_EXPORTS=ON. For now this means that the patch here introduces a separate source file list for the external library that gets populated by the source files of its static dependents.

  2. DrahtBot commented at 11:01 AM on October 20, 2023: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/28690.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK stickies-v, theuni, kashifs, pablomartin4btc, ismaelsadeeq, Sjors
    Approach ACK hebasto, BrandonOdiwuor
    Stale ACK ryanofsky, yuvicc, janb84

    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.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #35167 (Convert check-deps.sh to python by ajtowns)
    • #35113 (net: introduce block tracker to retry to download blocks after failure by optout21)
    • #34566 (feature: Use different datadirs for different signets by ekzyis)
    • #34075 (fees: Introduce Mempool Based Fee Estimation to reduce overestimation by ismaelsadeeq)
    • #34042 (doc: clarify libbitcoinkernel usage in libraries design by Galoretka)
    • #32427 ((RFC) kernel: Replace leveldb-based BlockTreeDB with flat-file based store by sedited)
    • #31132 (validation: fetch block inputs on parallel threads by andrewtoth)
    • #26022 (Add util::ResultPtr class by ryanofsky)
    • #25722 (refactor: Use util::Result class for wallet loading by ryanofsky)
    • #25665 (refactor: Add util::Result failure types and ability to merge result values by ryanofsky)

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  3. DrahtBot added the label Build system on Oct 20, 2023
  4. DrahtBot added the label CI failed on Oct 20, 2023
  5. sedited force-pushed on Oct 20, 2023
  6. sedited force-pushed on Oct 20, 2023
  7. in src/Makefile.am:650 in a5e49603f8 outdated
     643 | @@ -668,45 +644,45 @@ libbitcoin_common_a_SOURCES = \
     644 |    base58.cpp \
     645 |    bech32.cpp \
     646 |    chainparams.cpp \
     647 | -  coins.cpp \
     648 | +  chainparamsbase.cpp \
     649 |    common/args.cpp \
     650 | +  common/asmap.cpp \
     651 | +  common/bip32.cpp \
    


    hebasto commented at 10:04 AM on October 21, 2023:

    This change should be accompanied with another one:

    --- a/test/sanitizer_suppressions/ubsan
    +++ b/test/sanitizer_suppressions/ubsan
    @@ -62,5 +62,5 @@ shift-base:arith_uint256.cpp
     shift-base:crypto/
     shift-base:hash.cpp
     shift-base:streams.h
    -shift-base:util/bip32.cpp
    +shift-base:common/bip32.cpp
     shift-base:xoroshiro128plusplus.h
    
  8. sedited force-pushed on Oct 21, 2023
  9. hebasto commented at 10:46 AM on October 21, 2023: member

    To fix the MSVC build, suggesting to apply the diff as follows:

    --- a/build_msvc/bitcoin.sln
    +++ b/build_msvc/bitcoin.sln
    @@ -82,6 +82,10 @@ Global
             {460FEE33-1FE1-483F-B3BF-931FF8E969A5}.Debug|x64.Build.0 = Debug|x64
             {460FEE33-1FE1-483F-B3BF-931FF8E969A5}.Release|x64.ActiveCfg = Release|x64
             {460FEE33-1FE1-483F-B3BF-931FF8E969A5}.Release|x64.Build.0 = Release|x64
    +        {A938586F-1016-4C60-9B82-56123264EE14}.Debug|x64.ActiveCfg = Debug|x64
    +        {A938586F-1016-4C60-9B82-56123264EE14}.Debug|x64.Build.0 = Debug|x64
    +        {A938586F-1016-4C60-9B82-56123264EE14}.Release|x64.ActiveCfg = Release|x64
    +        {A938586F-1016-4C60-9B82-56123264EE14}.Release|x64.Build.0 = Release|x64
             {5724BA7D-A09A-4BA8-800B-C4C1561B3D69}.Debug|x64.ActiveCfg = Debug|x64
             {5724BA7D-A09A-4BA8-800B-C4C1561B3D69}.Debug|x64.Build.0 = Debug|x64
             {5724BA7D-A09A-4BA8-800B-C4C1561B3D69}.Release|x64.ActiveCfg = Release|x64
    
  10. sedited force-pushed on Oct 21, 2023
  11. sedited commented at 2:31 PM on October 21, 2023: contributor

    Thanks for the fixes @hebasto! Looks like the remaining test failure is a timeout?

  12. hebasto commented at 3:36 PM on October 21, 2023: member

    Looks like the remaining test failure is a timeout?

    I believe that this PR changes are unrelated to that timeout. See: #28703.

  13. sedited force-pushed on Oct 23, 2023
  14. sedited force-pushed on Oct 23, 2023
  15. sedited marked this as ready for review on Oct 24, 2023
  16. DrahtBot removed the label CI failed on Oct 25, 2023
  17. DrahtBot added the label Needs rebase on Oct 26, 2023
  18. hebasto commented at 3:44 PM on October 27, 2023: member

    Concept ACK on improving internal library boundaries.

    Should also address #28548.

    I've tested lightly this branch. There still exist a circle dependency between libbitcoin_crypto and libbitcoin_util. In particular, the former depends on the memory_cleanse symbol.

  19. sedited force-pushed on Oct 30, 2023
  20. sedited commented at 1:08 PM on October 30, 2023: contributor

    Thank you for taking a look at @hebasto,

    Rebased 04d7a985b4c58a37dc3f99c05d16810720d60957 -> 84a8cae915308dcdea6c579e7e24168d3d3eb030 (kernelInternalLib_0 -> kernelInternalLib_1, compare)

    • Resolved conflicts

    Updated 84a8cae915308dcdea6c579e7e24168d3d3eb030 -> 815eaef0e1a30b746aef2a1112bb9b7895d119de (kernelInternalLib_1 -> kernelInternalLib_2, compare)

  21. DrahtBot removed the label Needs rebase on Oct 30, 2023
  22. DrahtBot added the label CI failed on Oct 30, 2023
  23. sedited force-pushed on Oct 31, 2023
  24. sedited commented at 11:27 AM on October 31, 2023: contributor

    Updated 815eaef0e1a30b746aef2a1112bb9b7895d119de -> 4052c2d5b9f84289752093981f475ea2ca5b64e7 (kernelInternalLib_2 -> kernelInternalLib_3, compare)

    • Fixed silent merge conflict.
  25. DrahtBot removed the label CI failed on Oct 31, 2023
  26. laanwj requested review from laanwj on Oct 31, 2023
  27. DrahtBot added the label Needs rebase on Nov 2, 2023
  28. sedited force-pushed on Nov 2, 2023
  29. sedited commented at 1:30 PM on November 2, 2023: contributor

    Rebased 4052c2d5b9f84289752093981f475ea2ca5b64e7 -> 1a589335617944b755235597aafc254e28e4acf9 (kernelInternalLib_3 -> kernelInternalLib_4, compare)

    • Fixed merge conflict.
  30. DrahtBot removed the label Needs rebase on Nov 2, 2023
  31. DrahtBot added the label Needs rebase on Nov 7, 2023
  32. sedited force-pushed on Nov 9, 2023
  33. sedited commented at 11:27 AM on November 9, 2023: contributor

    Rebased 1a589335617944b755235597aafc254e28e4acf9 -> 40e151697d3d1ed594364498d9e6220219d9b545 (kernelInternalLib_4 -> kernelInternalLib_5, compare)

    • Fixed merge conflict.
  34. DrahtBot removed the label Needs rebase on Nov 9, 2023
  35. DrahtBot added the label Needs rebase on Nov 15, 2023
  36. sedited force-pushed on Nov 15, 2023
  37. DrahtBot removed the label Needs rebase on Nov 15, 2023
  38. sedited commented at 4:07 PM on November 15, 2023: contributor

    Rebased 40e151697d3d1ed594364498d9e6220219d9b545 -> de6d79847537cd7d0dfc3e2dd7a57b39b4281b5a (kernelInternalLib_5 -> kernelInternalLib_6, compare)

    • Fixed merge conflict.
  39. stickies-v commented at 1:23 PM on November 16, 2023: contributor

    Concept ACK

    It turned out to be a bit less clean than I'd hoped, but I made this branch with a scripted-diff (with a second commit to re-order includes alphabetically) as an alternative to the manual first commit. I'm not sure it makes reviewing easier (and it needs some more manual edits to Makefile, ubsan and an unrelated include), but at least it's a helpful check:

    https://github.com/bitcoin/bitcoin/compare/master...stickies-v:bitcoin:182d54aed91bfb1c161033642c322a542c8f2e04

    % git diff 515c9952829256f4c75c82d90f9ea4994b03baee 182d54aed91bfb1c161033642c322a542c8f2e04 --stat
     src/Makefile.am                   | 48 ++++++++++++++++++++++++------------------------
     src/common/sock.h                 |  1 -
     test/sanitizer_suppressions/ubsan |  1 -
    

    nit: in be0b6233ec6cd21e5730380a3bc7f868189dabc9: is there a reason we move hex_base.{h, cpp} to crypto, and not consensus? It seems unrelated to our crypto library.

  40. sedited commented at 1:48 PM on November 16, 2023: contributor

    Re #28690#pullrequestreview-1734365185

    nit: in https://github.com/bitcoin/bitcoin/commit/be0b6233ec6cd21e5730380a3bc7f868189dabc9: is there a reason we move hex_base.{h, cpp} to crypto, and not consensus? It seems unrelated to our crypto library.

    Currently both the consensus and util library share the strencodings files. This is not ideal, because the file will then have to be compiled twice (once for each of them). Further, the util library should not be relying on symbols from the consensus library according to the diagram. So I split the symbols that both the consensus and utill library needs from the strencodings file and put them into a new file in the crypto library, which both the util and consensus library depend on.

  41. theuni commented at 10:07 PM on November 22, 2023: member

    Concept ACK. Nice. @stickies-v Thanks! That's super helpful.

    I agree that crypto isn't the most ideal home for hex/string functions, but it does actually make it easier to use the lib as a standalone and not have to write your own versions. I don't really see any downside to having them there (no nasty dependencies, nothing stateful, etc) other than being out of place. Curious if @sipa has any specific opposition.

    I'd also like to hear what @ryanofsky things about this PR, as he's been involved in many of the layout discussions.

  42. in src/Makefile.am:945 in de6d798475 outdated
     942 | @@ -923,85 +943,7 @@ libbitcoinkernel_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -fvisibility=default
     943 |  # TODO: libbitcoinkernel is a work in progress consensus engine library, as more
     944 |  #       and more modules are decoupled from the consensus engine, this list will
     945 |  #       shrink to only those which are absolutely necessary.
    


    stickies-v commented at 4:54 PM on November 24, 2023:

    I think this docstring needs to move as well


    sedited commented at 7:56 PM on November 24, 2023:

    Could just remove it to be honest.


    sedited commented at 10:12 PM on November 24, 2023:

    Yeah, will do this on the next push.

  43. kashifs commented at 5:36 PM on November 26, 2023: contributor

    Concept ACK. I just reviewed all the code and the design in preparation for the upcoming PR Review Club

  44. theuni commented at 7:03 PM on November 26, 2023: member

    Also ping @hebasto for 👀 as this would require some CMake attention :\

  45. in src/Makefile.am:142 in 515c995282 outdated
     135 | @@ -136,9 +136,18 @@ BITCOIN_CORE_H = \
     136 |    clientversion.h \
     137 |    coins.h \
     138 |    common/args.h \
     139 | +  common/asmap.h \
     140 | +  common/bip32.h \
     141 |    common/bloom.h \
     142 | +  common/bytevectorhash.h \
    


    ryanofsky commented at 4:54 PM on November 28, 2023:

    In commit "build: Prepare libbitcoin_util for kernel integration" (515c9952829256f4c75c82d90f9ea4994b03baee)

    The changes in this commit generally make sense, but IMO bytevectorhash.h readwritefile.h and sock.h feel more like general purpose utilities that fit better in with the util library than the common library. I don't think there should be a barrier to calling these functions in kernel code even if they aren't called currently.

    This came before up in #27989. In general, I think it makes sense to move functions from util to common when those functions shouldn't be called by kernel code, not just when they aren't called by kernel code.


    sedited commented at 9:10 PM on November 28, 2023:

    I think for simple utilities like the bytevectorhash module, I kind of agree, since it does not pull in further unwanted deps, nor is used for anything opinionated (and similarly readwritefile.h). sock.h however includes compat.h, which we've previously worked to remove from the kernel header tree, so I think I'll leave that one as is.

  46. in test/sanitizer_suppressions/ubsan:74 in 515c995282 outdated
      70 | @@ -71,4 +71,5 @@ shift-base:crypto/
      71 |  shift-base:ROTL32
      72 |  shift-base:streams.h
      73 |  shift-base:FormatHDKeypath
      74 | +shift-base:common/bip32.cpp
    


    ryanofsky commented at 4:58 PM on November 28, 2023:

    In commit "build: Prepare libbitcoin_util for kernel integration" (515c9952829256f4c75c82d90f9ea4994b03baee)

    Is this an unrelated change? Could the reason for it be explained in the commit description?

    In general, I don't really get the commit description. I don't know what "kernel integration" is specifically, or why parts of util need to be moved for it to happen.

  47. in src/Makefile.am:324 in 1f98ed5e56 outdated
     320 | @@ -319,6 +321,7 @@ BITCOIN_CORE_H = \
     321 |    util/result.h \
     322 |    util/serfloat.h \
     323 |    util/signalinterrupt.h \
     324 | +  util/strencodings.h \
    


    ryanofsky commented at 5:06 PM on November 28, 2023:

    In commit "build: Introduce libbitcoin_kernel as an internal compilation unit" (1f98ed5e56230a61b699f669459e39fa101a1ca5)

    Reason for adding strencodings.h this commit? Can it be explained in the commit description, or does it maybe belong the previous commit?

  48. in src/Makefile.am:747 in 1f98ed5e56 outdated
     742 |  # util #
     743 |  libbitcoin_util_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
     744 |  libbitcoin_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
     745 |  libbitcoin_util_a_SOURCES = \
     746 |    clientversion.cpp \
     747 | +  coins.cpp \
    


    ryanofsky commented at 5:23 PM on November 28, 2023:

    In commit "build: Introduce libbitcoin_kernel as an internal compilation unit" (1f98ed5e56230a61b699f669459e39fa101a1ca5)

    It's surprising to coins.cpp moving from common library to the util library instead kernel library. Curious if this is necessary.

    It might be nice to explain general reasoning behind moves in the commit description and call out any special cases.

    I'm guessing that certain of these files that are moved to the util library like coins.cpp and kernel/chainparams.cpp probably could be split up later and mostly moved back to the kernel, since wallet and gui code shouldn't need most of what is in them.

  49. in src/Makefile.am:946 in de6d798475 outdated
    1019 | -  util/tokenpipe.cpp \
    1020 | -  validation.cpp \
    1021 | -  validationinterface.cpp \
    1022 | -  versionbits.cpp \
    1023 | -  warnings.cpp
    1024 | +libbitcoinkernel_la_SOURCES = kernel/bitcoinkernel.cpp $(libbitcoin_kernel_a_SOURCES) $(libbitcoin_util_a_SOURCES) $(libbitcoin_consensus_a_SOURCES)
    


    ryanofsky commented at 5:30 PM on November 28, 2023:

    In commit "kernel: De-duplicate source file list" (de6d79847537cd7d0dfc3e2dd7a57b39b4281b5a)

    Can code comment above be updated to explain why util and consensus sources are added to kernel library sources, instead of the kernel library just depending on these libraries?


    sedited commented at 10:37 PM on November 28, 2023:

    I did not want to change the way libbitcoinkernel_la is compiled in this pull request. The way it is now, it just follows the same pattern of libbitcoinconsensus_la when it comes to defining its sources. So there should be no change in linking behavior of the external libbitcoinkernel arising from this patchset. Besides, linking against the static internal libraries probably won't work anyway.

  50. ryanofsky approved
  51. ryanofsky commented at 5:33 PM on November 28, 2023: contributor

    Code review ACK de6d79847537cd7d0dfc3e2dd7a57b39b4281b5a. I had a few questions, but most of the changes here seem good, and all look like they should work and be safe.

  52. DrahtBot requested review from theuni on Nov 28, 2023
  53. DrahtBot requested review from hebasto on Nov 28, 2023
  54. DrahtBot requested review from stickies-v on Nov 28, 2023
  55. sedited force-pushed on Nov 29, 2023
  56. sedited commented at 9:24 AM on November 29, 2023: contributor

    Thank you for the review @ryanofsky!

    Rebased de6d79847537cd7d0dfc3e2dd7a57b39b4281b5a -> 35ad530fd951ebdc3cb4b36aaa5ca2af77c527e4 (kernelInternalLib_6 -> kernelInternalLib_7, compare)

    Updated 35ad530fd951ebdc3cb4b36aaa5ca2af77c527e4 -> 511e3fc74cdd03c36764eaf3bb637e7bbe98b335 (kernelInternalLib_7 -> kernelInternalLib_8, compare)

    • Addressed @ryanofsky's comment, moving bytevectorhash and readwritefile modules back to the util library.
    • Addressed @ryanofsky's comment, dropped change in the sanitizer suppression that became redundant after #28865 was merged.
    • Addressed @ryanofsky's comment, moved strencodings change to the correct commit.
    • Addressed @ryanofsky's comment, explaining in the commit message why some files are moved from common to util.
  57. in src/Makefile.am:645 in 5a6a0b1693 outdated
     642 | @@ -657,8 +643,6 @@ libbitcoin_consensus_a_SOURCES = \
     643 |    tinyformat.h \
     644 |    uint256.cpp \
     645 |    uint256.h \
    


    maflcko commented at 9:45 AM on November 30, 2023:

    unrelated: What is the point of having headers in here? Wouldn't it be better to move them all to the CORE_H list, like for all other libraries (common/*.h, util/*.h, node/*.h, ...)?


    sedited commented at 9:48 AM on November 30, 2023:

    That point is that you can compile a more minimal libbitcoin_consensus without having to drag in the full BITCOIN_CORE_H and accidentally introduce new stuff into the consensus lib.


    maflcko commented at 9:57 AM on November 30, 2023:

    accidentally introduce new stuff into the consensus lib.

    Is it true? I don't think the list is enforced in any way. Nothing in C++ is holding anyone back from including a header with header-only code. Moreover, the current code includes headers that are not listed here:

    src/consensus/tx_verify.cpp:#include <util/check.h>
    src/consensus/tx_verify.cpp:#include <util/moneystr.h>
    

    Also, it should be possible to include other headers without running into compile or link issues, as long as no new link symbols are required from other libraries, no?


    sedited commented at 12:01 PM on November 30, 2023:

    tx_verify is not part of the consensus library though.

    EDIT: To be clear, I still have a bad grasp of how our header accounting actually works and I think your point still stands, e.g. you can move any of the headers between CORE_H and the source definitions.


    maflcko commented at 12:26 PM on November 30, 2023:

    Ok, but the following diff on tx_check compiles for me, or am I missing something?

    diff --git a/src/consensus/tx_check.cpp b/src/consensus/tx_check.cpp
    index b3fee1e8b1..1be8686bea 100644
    --- a/src/consensus/tx_check.cpp
    +++ b/src/consensus/tx_check.cpp
    @@ -7,9 +7,14 @@
     #include <consensus/amount.h>
     #include <primitives/transaction.h>
     #include <consensus/validation.h>
    +#include <util/check.h>
    +#include <util/fs.h>
     
     bool CheckTransaction(const CTransaction& tx, TxValidationState& state)
     {
    +Assert(true);
    +fs::path foo{"bar"};
    +(void)foo;
         // Basic checks that don't depend on any context
         if (tx.vin.empty())
             return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-vin-empty");
    

    sedited commented at 3:20 PM on November 30, 2023:

    Mmh, looking at the history, similar things are said in the commit message introducing the headers in libbitcoin_crypto: https://github.com/bitcoin/bitcoin/commit/4791b99e2dea0593775a8c75f62c8406d340191e. Maybe a regression was introduced at some point?


    maflcko commented at 3:23 PM on November 30, 2023:

    Or it is a typo? "headers"/"modules"? cc @theuni

  58. DrahtBot added the label Needs rebase on Nov 30, 2023
  59. sedited force-pushed on Nov 30, 2023
  60. sedited commented at 8:01 PM on November 30, 2023: contributor

    Rebased 511e3fc74cdd03c36764eaf3bb637e7bbe98b335 -> 0af5d4d2d6c4201c7c6f1ba8b497cce23dc9f3ad (kernelInternalLib_8 -> kernelInternalLib_9, compare)

  61. DrahtBot removed the label Needs rebase on Nov 30, 2023
  62. ryanofsky commented at 3:19 PM on December 1, 2023: contributor

    re: #28690 (comment) and earlier discussion about libcrypto starting #28690#pullrequestreview-1734365185:

    I agree that crypto isn't the most ideal home for hex/string functions, but it does actually make it easier to use the lib as a standalone and not have to write your own versions.

    Just want to note that libbitcoin_crypto and src/crypto/ are not currently mentioned in the libraries document: https://github.com/bitcoin/bitcoin/blob/master/doc/design/libraries.md. It'd be good to mention libbitcoin_crypto there, especially if the intent is for libbitcoin_crypto to be a standalone library that doesn't depend on any other bitcoin libraries, not just a normal internal library using some util functions.

  63. DrahtBot added the label Needs rebase on Dec 1, 2023
  64. sedited force-pushed on Dec 1, 2023
  65. sedited commented at 10:42 PM on December 1, 2023: contributor

    Rebased 0af5d4d2d6c4201c7c6f1ba8b497cce23dc9f3ad -> 5a235048500a38fae691396cb59f6697032b4deb (kernelInternalLib_9 -> kernelInternalLib_10, compare)

  66. DrahtBot removed the label Needs rebase on Dec 1, 2023
  67. maflcko added the label DrahtBot Guix build requested on Dec 5, 2023
  68. pablomartin4btc commented at 10:34 PM on December 5, 2023: member

    Concept ACK

    I'd recommend reading Review Club notes from @stickies-v (thanks!) since those are great, well structured and very useful in order to have a wider context of most of the changes involved.

  69. in src/util/string.h:8 in 8b3623769e outdated
       4 | @@ -5,7 +5,7 @@
       5 |  #ifndef BITCOIN_UTIL_STRING_H
       6 |  #define BITCOIN_UTIL_STRING_H
       7 |  
       8 | -#include <util/spanparsing.h>
       9 | +#include <common/spanparsing.h>
    


    ryanofsky commented at 11:18 PM on December 5, 2023:

    In commit "build: Prepare libbitcoin_util for internal kernel library" (8b3623769e1307c122959fbdc8c4c93ddd81d5c9)

    It seems like a bug to have a util header depending on a common header. I think I'd suggest splitting up the spanparsing header and renaming it, since right now it is not very focused. Would suggest moving the spanparsing Split function to src/util/string.h where it is being used, and probably moving the rest of the functions to src/script/parsing.h since they are only used for descriptor and miniscript parsing. Would suggest doing these things in a separate commit to avoid adding complexity to this commit.


    sedited commented at 9:11 AM on December 6, 2023:

    Good catch, I think though this file also falls in the category of #28690 (review), and since it does not introduce any further potentially controversial headers, I'd rather drop this change altogether. This can be re-visited once/if we have some accounting of the headers.

  70. DrahtBot commented at 5:04 AM on December 6, 2023: contributor

    <!--9cd9c72976c961c55c7acef8f6ba82cd-->

    Guix builds (on x86_64)

    File commit 6d5790956f45e3de5c6c4ee6fda21878b0d1287b<br>(master) commit d5b4ca0a29b5de1ca7d6a42aae71d22f7d606f15<br>(master and this pull)
    SHA256SUMS.part 070f2d87d6e3f214... 19a6fb1710c51e6a...
    *-aarch64-linux-gnu-debug.tar.gz e50e6cf360642fd3... 2af0b043bf9b07cf...
    *-aarch64-linux-gnu.tar.gz d1994e5d2e586f1c... e019631b69fa2e31...
    *-arm-linux-gnueabihf-debug.tar.gz cc20ddb16663d398... a93994efdf7e0f2a...
    *-arm-linux-gnueabihf.tar.gz 908022604cd339e1... 927f97d5ab73a208...
    *-arm64-apple-darwin-unsigned.tar.gz f3a3d8672e487573... 77dd77541a24a84f...
    *-arm64-apple-darwin-unsigned.zip e696a59082f4df02... 8aaf698673af3c8f...
    *-arm64-apple-darwin.tar.gz 76f681aeb99ce7a2... 173cdc19e0e0d801...
    *-powerpc64-linux-gnu-debug.tar.gz afa1b69ff9326a5c... ba90f1389a9baf85...
    *-powerpc64-linux-gnu.tar.gz 64d0ab4b97a56739... 2dc8c59666e7ddb2...
    *-powerpc64le-linux-gnu-debug.tar.gz 19e1304c77570866... 263b55c0fedf493a...
    *-powerpc64le-linux-gnu.tar.gz c1b8a29c208746c7... 74e087c831f84e3b...
    *-riscv64-linux-gnu-debug.tar.gz 7641821f6aa71788... 09a24ac522ca8565...
    *-riscv64-linux-gnu.tar.gz 87cf896dd53b4ee9... 6dc6c75525aa52ba...
    *-x86_64-apple-darwin-unsigned.tar.gz 264bb8d7474ea91a... 1d9cede0c41f8b6a...
    *-x86_64-apple-darwin-unsigned.zip 888c6e62d5eba0eb... fd6a1047be61c33a...
    *-x86_64-apple-darwin.tar.gz 056d123f3f51d08a... 0365849a12370358...
    *-x86_64-linux-gnu-debug.tar.gz f14054fdbe8c170e... 98c2d2ebdd07f837...
    *-x86_64-linux-gnu.tar.gz da8fdd90d2ff7e72... ccb3035d61661db9...
    *.tar.gz f8989c183ea48bef... 79e1c877aa931cd0...
    guix_build.log 291ae30442da67cc... c3d56b67abbf2db5...
    guix_build.log.diff a68430b6b8712fee...
  71. DrahtBot removed the label DrahtBot Guix build requested on Dec 6, 2023
  72. sedited force-pushed on Dec 6, 2023
  73. sedited commented at 10:10 AM on December 6, 2023: contributor

    Thank you for the review @ryanofsky,

    Rebased 5a235048500a38fae691396cb59f6697032b4deb -> 2086d1d4c3f40cce34647995ead4bff22967ffd8 (kernelInternalLib_10 -> kernelInternalLib_11, compare)

  74. hebasto commented at 3:07 PM on December 6, 2023: member

    I've reviewed the first commit (7651c93749557839f7db3b73eb6df6357649e2d3).

    Not counting the symbols from the libbitcoin_crypto library, the libbitcoin_util has undefined symbols as follows:

    • on the master branch:
    - `ArgsManager::AddArg`
    - `ArgsManager::SelectConfigNetwork`
    - `CKey::SignCompact`
    - `CPubKey::RecoverCompact`
    - `DecodeDestination`
    - `gArgs`
    - `G_TRANSLATION_FUN`
    - `IsValidDestination`
    - `PKHash::PKHash`
    
    • for 7651c93749557839f7db3b73eb6df6357649e2d3:
    - `G_TRANSLATION_FUN`
    

    It looks good.

  75. hebasto commented at 3:57 PM on December 6, 2023: member

    Approach ACK 2086d1d4c3f40cce34647995ead4bff22967ffd8.

    Still reviewing the 4th commit (983d0978a973a12c3128b2c8e13b73ed08155e67).

  76. ismaelsadeeq commented at 4:58 PM on December 6, 2023: member

    Concept ACK Did a light review this looks good to me

  77. DrahtBot added the label Needs rebase on Dec 6, 2023
  78. sedited force-pushed on Dec 6, 2023
  79. sedited commented at 8:44 PM on December 6, 2023: contributor

    Rebased 2086d1d4c3f40cce34647995ead4bff22967ffd8 -> 34970bde23dd87fc0fea5a1970880761f7184774 (kernelInternalLib_11 -> kernelInternalLib_12, compare)

  80. in src/crypto/hex_base.h:6 in 36f95a360e outdated
       0 | @@ -0,0 +1,23 @@
       1 | +// Copyright (c) 2009-present The Bitcoin Core developers
       2 | +// Distributed under the MIT software license, see the accompanying
       3 | +// file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4 | +
       5 | +#ifndef BITCOIN_CRYPTO_HEX_BASE_H
       6 | +#define BITCOIN_CRYPTO_HEX_BASE_H
    


    maflcko commented at 9:05 PM on December 6, 2023:

    Is this commit needed? I guess there could be issues if the same translation unit is compiled twice?

    Not sure if Hex is correct to put into "crypto".

    If this isn't needed, maybe leave this for a follow-up?

    An alternative would be to just remove it from the util library and keep it only in consensus?


    ryanofsky commented at 10:37 PM on December 6, 2023:

    re: #28690 (review)

    Is this commit needed? I guess there could be issues if the same translation unit is compiled twice?

    Not sure if Hex is correct to put into "crypto".

    If this isn't needed, maybe leave this for a follow-up?

    An alternative would be to just remove it from the util library and keep it only in consensus?

    Not sure about the current state, but when this was asked previously #28690#pullrequestreview-1734365185, I think the idea was to have it in crypto since util and consensus libraries depend on the crypto library.


    sedited commented at 10:49 PM on December 6, 2023:

    Re #28690 (review)

    An alternative would be to just remove it from the util library and keep it only in consensus?

    These functions are used by components of bitcoin-cli. The bitcoin-cli binary should not have to rely on the consensus library, so I don't think that is an alternative.


    maflcko commented at 7:39 AM on December 7, 2023:

    Ok, so the reason to put Hex into crypto is because it happens to be convenient at this time? No objection, but it would be good to extend the motivation a bit. I asked if this is needed, and what would happen if the commit was dropped, so it may be good to include a compile/link failure in the motivation, if there is one.


    sedited commented at 8:16 AM on December 7, 2023:

    If you drop the commit splitting strencodings and moving the hex function to the crypto library you get a bunch of errors when compiling the last commit:

    /usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x23
    util/.libs/libbitcoinkernel_la-strencodings.o: in function `SanitizeString[abi:cxx11](std::basic_string_view<char, std::char_traits<char> >, int)':
    strencodings.cpp:(.text+0x0): multiple definition of `SanitizeString[abi:cxx11](std::basic_string_view<char, std::char_traits<char> >, int)'; /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x23
    

    This is because the external libbitcoinkernel library now re-uses the existing source file lists and will find two strencodings files, one from the util sources and one from the consensus sources.

  81. DrahtBot removed the label Needs rebase on Dec 6, 2023
  82. ryanofsky approved
  83. ryanofsky commented at 10:43 PM on December 6, 2023: contributor

    Code review ACK 34970bde23dd87fc0fea5a1970880761f7184774.

    Main change since last review is no longer moving the spanparsing.h file here, to avoid making util depend on common. I have since opened a separate PR #29015 to remove spanparsing.h functions from util by splitting it up.

  84. DrahtBot requested review from hebasto on Dec 6, 2023
  85. DrahtBot requested review from pablomartin4btc on Dec 6, 2023
  86. DrahtBot requested review from ismaelsadeeq on Dec 6, 2023
  87. hebasto commented at 1:24 PM on December 10, 2023: member

    The last commit 34970bde23dd87fc0fea5a1970880761f7184774 effectively extends the libbitcoinkernel_la_SOURCES with the following source files:

    • script/bitcoinconsensus.cpp
    • util/bytevectorhash.cpp
    • util/readwritefile.cpp
    • util/spanparsing.cpp
    • util/threadinterrupt.cpp

    The resulted libbitcoinkernel.a and libbitcoinkernel.so.0.0.0 get bigger, obviously.

    This change is not mentioned in the commit message, and it's not clear whether it is done intentionally.

  88. DrahtBot requested review from hebasto on Dec 10, 2023
  89. sedited commented at 2:28 PM on December 10, 2023: contributor

    Putting this on draft while we figure out the desired contents of the util library in #29015.

  90. sedited marked this as a draft on Dec 10, 2023
  91. DrahtBot added the label Needs rebase on Dec 13, 2023
  92. achow101 referenced this in commit 011a895a82 on Jun 12, 2024
  93. sedited force-pushed on Jul 2, 2024
  94. sedited force-pushed on Jul 2, 2024
  95. sedited commented at 12:35 PM on July 2, 2024: contributor

    Rebased and updated 34970bde23dd87fc0fea5a1970880761f7184774 -> 1a1e2dac0c657c3ee96c7faf9594aa0bed770702 (kernelInternalLib_12 -> kernelInternalLib_13)

    #29015 got merged in the meantime and there are some implications for this pull request. We decided that the util library may contain a superset of the utilities that the kernel strictly requires.

    For this reason I decided to implement aj's suggestion (https://github.com/bitcoin/bitcoin/pull/29015#issuecomment-1849208455) of introducing a slimmed-down version of the util library for the kernel containing only the components that the kernel requires. I'd appreciate the opinion of previous reviewers of this PR on this new approach. Having some modules in the util library that are not required is not all bad - they might become useful in the future when working with the kernel. On the other hand they do bloat the library and may make it harder in future to use the kernel library on some platforms.

    The external consensus library was also removed while waiting for #29015. I wonder if we should remove the internal consensus library as well and drop its contents into the new internal kernel library.

    I will keep this in draft for now - its msvc build is broken and I'm not sure if it is worth going through this exercise again if cmake is going to land soon.

  96. DrahtBot removed the label Needs rebase on Jul 2, 2024
  97. DrahtBot added the label Needs rebase on Jul 3, 2024
  98. sedited force-pushed on Aug 28, 2024
  99. DrahtBot removed the label Needs rebase on Aug 28, 2024
  100. DrahtBot added the label CI failed on Aug 28, 2024
  101. DrahtBot commented at 1:45 PM on August 28, 2024: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Debug: https://github.com/bitcoin/bitcoin/runs/29358890178</sub>

    <details><summary>Hints</summary>

    Make sure to run all tests locally, according to the documentation.

    The failure may happen due to a number of reasons, for example:

    • Possibly 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.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

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

    </details>

  102. sedited force-pushed on Aug 29, 2024
  103. sedited force-pushed on Aug 29, 2024
  104. DrahtBot removed the label CI failed on Aug 29, 2024
  105. DrahtBot added the label Needs rebase on Sep 3, 2024
  106. sedited force-pushed on Sep 3, 2024
  107. DrahtBot removed the label Needs rebase on Sep 3, 2024
  108. DrahtBot added the label CI failed on Sep 3, 2024
  109. DrahtBot added the label Needs rebase on Sep 4, 2024
  110. sedited force-pushed on Sep 4, 2024
  111. DrahtBot removed the label Needs rebase on Sep 4, 2024
  112. DrahtBot removed the label CI failed on Oct 1, 2024
  113. DrahtBot added the label Needs rebase on Oct 11, 2024
  114. sedited force-pushed on May 16, 2025
  115. bitcoin deleted a comment on May 16, 2025
  116. bitcoin deleted a comment on May 16, 2025
  117. DrahtBot removed the label Needs rebase on May 16, 2025
  118. sedited force-pushed on May 16, 2025
  119. DrahtBot added the label CI failed on May 16, 2025
  120. in src/util/CMakeLists.txt:33 in bb3ac254fc outdated
      26 | @@ -36,11 +27,32 @@ add_library(bitcoin_util STATIC EXCLUDE_FROM_ALL
      27 |    ../sync.cpp
      28 |  )
      29 |  
      30 | -target_link_libraries(bitcoin_util
      31 | +target_link_libraries(bitcoin_kernel_util
      32 |    PRIVATE
      33 |      core_interface
      34 |      bitcoin_clientversion
    


    fanquake commented at 4:20 PM on May 16, 2025:

    Should also be easy to get bitcoin_clientversion out of here.


    sedited commented at 4:38 PM on May 16, 2025:

    I think it is just used for logging. I could just stub it out, like we do for the translation function, but I am also not as sure how important it really is to be printing the clientversion there for these logs.


    fanquake commented at 4:41 PM on May 16, 2025:

    Yea, we could probably drop that. There's also CLIENT_VERSION fed into the env RNG, which could also likely be dropped.

  121. sedited force-pushed on May 16, 2025
  122. DrahtBot removed the label CI failed on May 16, 2025
  123. sedited marked this as ready for review on May 17, 2025
  124. sedited commented at 8:36 AM on May 17, 2025: contributor

    Undrafting this again after some recent discussions on splitting the kernel library out in the future.

  125. DrahtBot added the label Needs rebase on May 27, 2025
  126. sedited force-pushed on May 29, 2025
  127. sedited force-pushed on May 29, 2025
  128. sedited commented at 2:27 PM on May 29, 2025: contributor

    Rebased 7e6e43a581c6fbf4f979206b0cabadc5476a35bd -> e4d80d721b8336047fcd75eb1891e08ac156a903 (kernelInternalLib_17 -> kernelInternalLib_18, compare)

    Fixed confilict with #31375

  129. DrahtBot removed the label Needs rebase on May 29, 2025
  130. yuvicc commented at 2:46 PM on July 12, 2025: contributor

    Concept ACK

    The external consensus library was also removed while waiting for #29015. I wonder if we should remove the internal consensus library as well and drop its contents into the new internal kernel library

    I agree with you, was having a similar thought on the internal library libbitcoin_consensus despite removal of external libbitcoinconsensus library. If we go this way then we can remove the libbitcoin_consensus from the libraries.md as well.

  131. DrahtBot added the label Needs rebase on Jul 18, 2025
  132. sedited force-pushed on Jul 30, 2025
  133. sedited commented at 7:04 PM on July 30, 2025: contributor

    Rebased e4d80d721b8336047fcd75eb1891e08ac156a903 -> 81387424d37650e186535b9868d71c5882bc7b20 (kernelInternalLib_18 -> kernelInternalLib_19, compare)

  134. DrahtBot removed the label Needs rebase on Jul 30, 2025
  135. DrahtBot added the label Needs rebase on Aug 6, 2025
  136. sedited force-pushed on Aug 7, 2025
  137. sedited commented at 10:17 AM on August 7, 2025: contributor

    Rebased 81387424d37650e186535b9868d71c5882bc7b20 -> 78ed83ba337c97798134f4bd0f9307facde3a59d (kernelInternalLib_19 -> kernelInternalLib_20, compare)

    Fixed conflict with #33077

  138. DrahtBot removed the label Needs rebase on Aug 7, 2025
  139. DrahtBot added the label Needs rebase on Oct 28, 2025
  140. sedited force-pushed on Oct 28, 2025
  141. sedited commented at 8:36 PM on October 28, 2025: contributor

    Rebased 78ed83ba337c97798134f4bd0f9307facde3a59d -> a9ec7cdc0a1f6d4a3bd532649e79459074ed9f3b (kernelInternalLib_20 -> kernelInternalLib_21, compare)

  142. DrahtBot removed the label Needs rebase on Oct 28, 2025
  143. yuvicc commented at 8:47 AM on November 5, 2025: contributor

    ACK a9ec7cdc0a1f6d4a3bd532649e79459074ed9f3b

  144. DrahtBot requested review from ryanofsky on Nov 5, 2025
  145. DrahtBot added the label Needs rebase on Nov 25, 2025
  146. sedited force-pushed on Nov 25, 2025
  147. sedited commented at 5:08 PM on November 25, 2025: contributor

    Rebased a9ec7cdc0a1f6d4a3bd532649e79459074ed9f3b -> 4c387e938015de197860215d94b9c9aee9a82da8 (kernelInternalLib_21 -> kernelInternalLib_22, compare)

  148. DrahtBot removed the label Needs rebase on Nov 25, 2025
  149. janb84 commented at 4:01 PM on December 8, 2025: contributor

    ACK 4c387e938015de197860215d94b9c9aee9a82da8

    Looks good to me, next to several builds & tests, I did a (subsection of a ) Guix build to see if there where any issues with that. It ran fine, see below.

    my Guix Build Output

    Host architecture: aarch64 Commit: 4c387e938015

    0eea1fa55868cf288544de481d7ae5e8285f068074536723e927c20b9ece0518  guix-build-4c387e938015/output/dist-archive/bitcoin-4c387e938015.tar.gz
    bf648f3ef27667e011b2c4547987527111c3d5c286933d092ad82697181c7918  guix-build-4c387e938015/output/x86_64-apple-darwin/SHA256SUMS.part
    da7d979957fb90516e47e1c2a976888e934776eee59f3248be798ffb57f2a781  guix-build-4c387e938015/output/x86_64-apple-darwin/bitcoin-4c387e938015-x86_64-apple-darwin-codesigning.tar.gz
    902f1ed15f8bae87129447d24de0356ec20781a813808e1b0274c815ac89072f  guix-build-4c387e938015/output/x86_64-apple-darwin/bitcoin-4c387e938015-x86_64-apple-darwin-unsigned.tar.gz
    6c23aa0d3c94029af56e0573927f5d634cd32444c5cebf97f405864fb2e30139  guix-build-4c387e938015/output/x86_64-apple-darwin/bitcoin-4c387e938015-x86_64-apple-darwin-unsigned.zip
    dfa686c73f0f54f71d5d81cba48e8d809106ca708c2619b641df412a48d43efa  guix-build-4c387e938015/output/x86_64-w64-mingw32/SHA256SUMS.part
    34f7c1142fcab95318de2c15b10e3ef2f511137c3da196cf275061d2e7921095  guix-build-4c387e938015/output/x86_64-w64-mingw32/bitcoin-4c387e938015-win64-codesigning.tar.gz
    9c6aec8c60d30ef857da2538c939f0d16642bb05f0dd50f2d282ea56c533f2cf  guix-build-4c387e938015/output/x86_64-w64-mingw32/bitcoin-4c387e938015-win64-debug.zip
    45132cb1e70e6930ad4ca85ab9ae6258e61eeee4aef8858a4902e8dceb71db5e  guix-build-4c387e938015/output/x86_64-w64-mingw32/bitcoin-4c387e938015-win64-setup-unsigned.exe
    7bffc2f307b721320cc5358ce79945fe241eec208b86d969affecbe5d14f9667  guix-build-4c387e938015/output/x86_64-w64-mingw32/bitcoin-4c387e938015-win64-unsigned.zip
    
  150. DrahtBot added the label Needs rebase on Dec 9, 2025
  151. sedited force-pushed on Dec 9, 2025
  152. sedited commented at 12:17 PM on December 9, 2025: contributor

    Rebased 4c387e938015de197860215d94b9c9aee9a82da8 -> 5656bfa9cab334cf1ab1c1a9956160c708bb15ff (kernelInternalLib_22 -> kernelInternalLib_23, compare)

  153. janb84 commented at 12:21 PM on December 9, 2025: contributor

    re ACK 5656bfa9cab334cf1ab1c1a9956160c708bb15ff

    changes since last ACK:

    • rebase
  154. maflcko commented at 12:40 PM on December 9, 2025: member

    It could make sense to keep ../util/expected.cpp? Otherwise, iwyu won't run and the file could just be fully deleted?

  155. sedited force-pushed on Dec 9, 2025
  156. DrahtBot added the label CI failed on Dec 9, 2025
  157. sedited commented at 12:51 PM on December 9, 2025: contributor

    It could make sense to keep ../util/expected.cpp? Otherwise, iwyu won't run and the file could just be fully deleted?

    That was not the intention, forgot that it was just empty for now and was expecting a compile error in case I missed it. Fixed it now.

  158. DrahtBot removed the label Needs rebase on Dec 9, 2025
  159. DrahtBot removed the label CI failed on Dec 9, 2025
  160. ?
    project_v2_item_status_changed sedited
  161. yuvicc commented at 9:00 AM on December 16, 2025: contributor

    re-ACK 5f096da0ae22fd60a8d44e49ed3c53269e062cf9

    Only rebased since last review.

  162. DrahtBot requested review from janb84 on Dec 16, 2025
  163. janb84 commented at 4:09 PM on December 16, 2025: contributor

    re ACK 5f096da0ae22fd60a8d44e49ed3c53269e062cf9

    changes since last ACK:

    • added expected.cpp to util for IWYU
  164. DrahtBot added the label Needs rebase on Jan 12, 2026
  165. sedited force-pushed on Jan 13, 2026
  166. sedited commented at 3:31 PM on January 13, 2026: contributor

    Rebased 5656bfa9cab334cf1ab1c1a9956160c708bb15ff -> ba91c516a518dc11de1cea8e21451745c0fcd2ea (kernelInternalLib_23 -> kernelInternalLib_24, compare)

    • Resolved conflict with #29415
  167. DrahtBot removed the label Needs rebase on Jan 13, 2026
  168. DrahtBot added the label Needs rebase on Jan 19, 2026
  169. sedited force-pushed on Jan 19, 2026
  170. sedited commented at 9:01 PM on January 19, 2026: contributor

    Rebased ba91c516a518dc11de1cea8e21451745c0fcd2ea -> b828264f2b2016edc03095e625df9f79fc4bbe10 (kernelInternalLib_24 -> kernelInternalLib_25, compare)

  171. DrahtBot removed the label Needs rebase on Jan 19, 2026
  172. DrahtBot added the label Needs rebase on Feb 13, 2026
  173. sedited force-pushed on Feb 20, 2026
  174. sedited commented at 10:23 AM on February 20, 2026: contributor

    Rebased b828264f2b2016edc03095e625df9f79fc4bbe10 -> db85819200c3196aa6033ea59d48ddb69f41b520 (kernelInternalLib_25 -> kernelInternalLib_26, compare)

  175. DrahtBot removed the label Needs rebase on Feb 20, 2026
  176. DrahtBot added the label Needs rebase on Mar 13, 2026
  177. sedited force-pushed on Mar 14, 2026
  178. sedited commented at 9:11 AM on March 14, 2026: contributor

    Rebased db85819200c3196aa6033ea59d48ddb69f41b520 -> 1188944c2128fef58bc8d273acb2aba91dd915d5 (kernelInternalLib_26 -> kernelInternalLib_27, compare)

  179. DrahtBot removed the label Needs rebase on Mar 14, 2026
  180. DrahtBot added the label Needs rebase on Mar 19, 2026
  181. sedited force-pushed on Mar 19, 2026
  182. sedited commented at 11:49 AM on March 19, 2026: contributor

    Rebased 1188944c2128fef58bc8d273acb2aba91dd915d5 -> fdf80892b305eaee17d50a665e821d356b570640 (kernelInternalLib_27 -> kernelInternalLib_28, compare)

  183. DrahtBot removed the label Needs rebase on Mar 19, 2026
  184. Sjors commented at 12:27 AM on March 21, 2026: member

    Concept ACK

    I whipped up an PoC iPhone app that uses the kernel: https://github.com/Sjors/kernel-i-node

    It's not a serious node, e.g. it fetches blocks from mempool.space. It exercises 100% of the API bindings, though not always in a useful way.

    Switching from master to this PR in that project makes no difference, so that's good.

  185. BrandonOdiwuor commented at 8:33 AM on March 24, 2026: contributor

    Approach ACK fdf80892b305eaee17d50a665e821d356b570640 refactoring how the external libbitcoinkernel SHARED library is built, to re-use source files from the new internal libbitcoin_kernel, libbitcoin_kernel_util, and bitcoin_consensus STATIC libraries.

    Tested on Ubuntu 24.04 with CMake 3.28.3 and gcc 13.3.0

    $ cmake --build build_dev_mode --target bitcoinkernel --verbose 2>&1 | grep -E 'Linking|bitcoinkernel.so'
    
    [ 16%] Linking CXX static library ../../lib/libbitcoin_crypto.a
    [ 25%] Linking CXX static library libcrc32c.a
    [ 50%] Linking CXX static library libleveldb.a
    [ 50%] Linking CXX static library ../lib/libbitcoin_clientversion.a
    [ 50%] Linking C static library ../lib/libsecp256k1.a
    [100%] Linking CXX shared library ../../lib/libbitcoinkernel.so
    /usr/bin/c++ -fPIC -O2 -g -fstack-reuse=none -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wl,-z,relro -Wl,-z,now -Wl,-z,separate-code -shared -Wl,-soname,libbitcoinkernel.so -o ../../lib/libbitcoinkernel.so CMakeFiles/bitcoinkernel.dir/bitcoinkernel.cpp.o CMakeFiles/bitcoinkernel.dir/__/chain.cpp.o CMakeFiles/bitcoinkernel.dir/__/coins.cpp.o CMakeFiles/bitcoinkernel.dir/__/compressor.cpp.o CMakeFiles/bitcoinkernel.dir/__/consensus/tx_verify.cpp.o CMakeFiles/bitcoinkernel.dir/__/dbwrapper.cpp.o CMakeFiles/bitcoinkernel.dir/__/deploymentinfo.cpp.o CMakeFiles/bitcoinkernel.dir/__/deploymentstatus.cpp.o CMakeFiles/bitcoinkernel.dir/__/flatfile.cpp.o CMakeFiles/bitcoinkernel.dir/chain.cpp.o CMakeFiles/bitcoinkernel.dir/chainparams.cpp.o CMakeFiles/bitcoinkernel.dir/checks.cpp.o CMakeFiles/bitcoinkernel.dir/coinstats.cpp.o CMakeFiles/bitcoinkernel.dir/context.cpp.o CMakeFiles/bitcoinkernel.dir/cs_main.cpp.o CMakeFiles/bitcoinkernel.dir/disconnected_transactions.cpp.o CMakeFiles/bitcoinkernel.dir/mempool_removal_reason.cpp.o CMakeFiles/bitcoinkernel.dir/__/node/blockstorage.cpp.o CMakeFiles/bitcoinkernel.dir/__/node/chainstate.cpp.o CMakeFiles/bitcoinkernel.dir/__/node/utxo_snapshot.cpp.o CMakeFiles/bitcoinkernel.dir/__/policy/ephemeral_policy.cpp.o CMakeFiles/bitcoinkernel.dir/__/policy/feerate.cpp.o CMakeFiles/bitcoinkernel.dir/__/policy/packages.cpp.o CMakeFiles/bitcoinkernel.dir/__/policy/policy.cpp.o CMakeFiles/bitcoinkernel.dir/__/policy/rbf.cpp.o CMakeFiles/bitcoinkernel.dir/__/policy/settings.cpp.o CMakeFiles/bitcoinkernel.dir/__/policy/truc_policy.cpp.o CMakeFiles/bitcoinkernel.dir/__/pow.cpp.o CMakeFiles/bitcoinkernel.dir/__/script/sigcache.cpp.o CMakeFiles/bitcoinkernel.dir/__/script/solver.cpp.o CMakeFiles/bitcoinkernel.dir/__/signet.cpp.o CMakeFiles/bitcoinkernel.dir/__/txdb.cpp.o CMakeFiles/bitcoinkernel.dir/__/txgraph.cpp.o CMakeFiles/bitcoinkernel.dir/__/txmempool.cpp.o CMakeFiles/bitcoinkernel.dir/__/validation.cpp.o CMakeFiles/bitcoinkernel.dir/__/validationinterface.cpp.o CMakeFiles/bitcoinkernel.dir/__/versionbits.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/chaintype.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/check.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/feefrac.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/fs.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/fs_helpers.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/hasher.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/expected.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/moneystr.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/rbf.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/readwritefile.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/serfloat.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/syserror.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/signalinterrupt.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/threadnames.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/time.cpp.o CMakeFiles/bitcoinkernel.dir/__/util/tokenpipe.cpp.o CMakeFiles/bitcoinkernel.dir/__/logging.cpp.o CMakeFiles/bitcoinkernel.dir/__/random.cpp.o CMakeFiles/bitcoinkernel.dir/__/randomenv.cpp.o CMakeFiles/bitcoinkernel.dir/__/streams.cpp.o CMakeFiles/bitcoinkernel.dir/__/support/lockedpool.cpp.o CMakeFiles/bitcoinkernel.dir/__/sync.cpp.o CMakeFiles/bitcoinkernel.dir/__/arith_uint256.cpp.o CMakeFiles/bitcoinkernel.dir/__/consensus/merkle.cpp.o CMakeFiles/bitcoinkernel.dir/__/consensus/tx_check.cpp.o CMakeFiles/bitcoinkernel.dir/__/hash.cpp.o CMakeFiles/bitcoinkernel.dir/__/primitives/block.cpp.o CMakeFiles/bitcoinkernel.dir/__/primitives/transaction.cpp.o CMakeFiles/bitcoinkernel.dir/__/pubkey.cpp.o CMakeFiles/bitcoinkernel.dir/__/script/interpreter.cpp.o CMakeFiles/bitcoinkernel.dir/__/script/script.cpp.o CMakeFiles/bitcoinkernel.dir/__/script/script_error.cpp.o CMakeFiles/bitcoinkernel.dir/__/uint256.cpp.o ../CMakeFiles/bitcoin_clientversion.dir/clientversion.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/aes.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/chacha20.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/chacha20poly1305.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/hex_base.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/hkdf_sha256_32.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/hmac_sha256.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/hmac_sha512.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/muhash.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/poly1305.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/ripemd160.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/sha1.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/sha256.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/sha256_sse4.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/sha3.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/sha512.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/siphash.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/__/support/cleanse.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/sha256_sse41.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/sha256_avx2.cpp.o ../crypto/CMakeFiles/bitcoin_crypto.dir/sha256_x86_shani.cpp.o ../CMakeFiles/leveldb.dir/leveldb/db/builder.cc.o ../CMakeFiles/leveldb.dir/leveldb/db/c.cc.o ../CMakeFiles/leveldb.dir/leveldb/db/db_impl.cc.o ../CMakeFiles/leveldb.dir/leveldb/db/db_iter.cc.o ../CMakeFiles/leveldb.dir/leveldb/db/dbformat.cc.o ../CMakeFiles/leveldb.dir/leveldb/db/dumpfile.cc.o ../CMakeFiles/leveldb.dir/leveldb/db/filename.cc.o ../CMakeFiles/leveldb.dir/leveldb/db/log_reader.cc.o ../CMakeFiles/leveldb.dir/leveldb/db/log_writer.cc.o ../CMakeFiles/leveldb.dir/leveldb/db/memtable.cc.o ../CMakeFiles/leveldb.dir/leveldb/db/repair.cc.o ../CMakeFiles/leveldb.dir/leveldb/db/table_cache.cc.o ../CMakeFiles/leveldb.dir/leveldb/db/version_edit.cc.o ../CMakeFiles/leveldb.dir/leveldb/db/version_set.cc.o ../CMakeFiles/leveldb.dir/leveldb/db/write_batch.cc.o ../CMakeFiles/leveldb.dir/leveldb/table/block.cc.o ../CMakeFiles/leveldb.dir/leveldb/table/block_builder.cc.o ../CMakeFiles/leveldb.dir/leveldb/table/filter_block.cc.o ../CMakeFiles/leveldb.dir/leveldb/table/format.cc.o ../CMakeFiles/leveldb.dir/leveldb/table/iterator.cc.o ../CMakeFiles/leveldb.dir/leveldb/table/merger.cc.o ../CMakeFiles/leveldb.dir/leveldb/table/table.cc.o ../CMakeFiles/leveldb.dir/leveldb/table/table_builder.cc.o ../CMakeFiles/leveldb.dir/leveldb/table/two_level_iterator.cc.o ../CMakeFiles/leveldb.dir/leveldb/util/arena.cc.o ../CMakeFiles/leveldb.dir/leveldb/util/bloom.cc.o ../CMakeFiles/leveldb.dir/leveldb/util/cache.cc.o ../CMakeFiles/leveldb.dir/leveldb/util/coding.cc.o ../CMakeFiles/leveldb.dir/leveldb/util/comparator.cc.o ../CMakeFiles/leveldb.dir/leveldb/util/crc32c.cc.o ../CMakeFiles/leveldb.dir/leveldb/util/env.cc.o ../CMakeFiles/leveldb.dir/leveldb/util/env_posix.cc.o ../CMakeFiles/leveldb.dir/leveldb/util/filter_policy.cc.o ../CMakeFiles/leveldb.dir/leveldb/util/hash.cc.o ../CMakeFiles/leveldb.dir/leveldb/util/histogram.cc.o ../CMakeFiles/leveldb.dir/leveldb/util/logging.cc.o ../CMakeFiles/leveldb.dir/leveldb/util/options.cc.o ../CMakeFiles/leveldb.dir/leveldb/util/status.cc.o ../CMakeFiles/leveldb.dir/leveldb/helpers/memenv/memenv.cc.o ../CMakeFiles/crc32c.dir/crc32c/src/crc32c.cc.o ../CMakeFiles/crc32c.dir/crc32c/src/crc32c_portable.cc.o ../CMakeFiles/crc32c.dir/crc32c/src/crc32c_sse42.cc.o ../secp256k1/src/CMakeFiles/secp256k1.dir/secp256k1.c.o ../secp256k1/src/CMakeFiles/secp256k1_precomputed.dir/precomputed_ecmult.c.o ../secp256k1/src/CMakeFiles/secp256k1_precomputed.dir/precomputed_ecmult_gen.c.o
    

    Installing libbitcoinkernel component

    <img width="1412" height="356" alt="Image" src="https://github.com/user-attachments/assets/73268fee-b4a2-4365-9c51-ccccedd7ca4c" />

    Building internal libbitcoin_kernel, libbitcoin_consensus, libbitcoin_kernel_util, libbitcoin_util STATIC libraries

    $ cmake --build build_dev_mode --target bitcoin_kernel bitcoin_util bitcoin_kernel_util bitcoin_consensus
    

    <img width="939" height="245" alt="Image" src="https://github.com/user-attachments/assets/7af03570-ed1d-4691-b70c-98e76b2ab139" />

  186. janb84 commented at 1:24 PM on March 26, 2026: contributor

    re ACK fdf80892b305eaee17d50a665e821d356b570640

    changes sinds last ack:

    • rebase

    "There is a trade-off to this. Since we don't manually export symbols from the kernel library yet, this would make the library unusable if REDUCE_EXPORTS=ON. For now this means that the patch here introduces a separate source file list for the external library that gets populated by the source files of its static dependents."

    Form the PR description, this reads if there are issues when compiled with REDUCE_EXPORTS=ON. But as per description there is a patch also introduced so it just works (just wanted to clarify this) :

    <details>

    Build with:

    cmake --preset dev-mode  -DREDUCE_EXPORTS=ON -DWITH_USDT=OFF
    

    Check exports:

    llvm-nm -gU build_dev_mode/lib/libbitcoinkernel.dylib | grep ' _btck_' | head -n 60
    000000000000a160 T _btck_block_copy
    000000000000a1e0 T _btck_block_count_transactions
    0000000000009efc T _btck_block_create
    000000000000a640 T _btck_block_destroy
    000000000000a5d0 T _btck_block_get_hash
    000000000000a2e0 T _btck_block_get_header
    000000000000a248 T _btck_block_get_transaction_at
    000000000000aaec T _btck_block_hash_copy
    000000000000aa80 T _btck_block_hash_create
    000000000000ac48 T _btck_block_hash_destroy
    000000000000abb8 T _btck_block_hash_equals
    000000000000ab58 T _btck_block_hash_to_bytes
    000000000000bf04 T _btck_block_header_copy
    000000000000bce8 T _btck_block_header_create
    000000000000c190 T _btck_block_header_destroy
    000000000000c094 T _btck_block_header_get_bits
    000000000000bf80 T _btck_block_header_get_hash
    000000000000c13c T _btck_block_header_get_nonce
    000000000000bfec T _btck_block_header_get_prev_hash
    000000000000c040 T _btck_block_header_get_timestamp
    000000000000c0e8 T _btck_block_header_get_version
    000000000000a708 T _btck_block_read
    000000000000af38 T _btck_block_spent_outputs_copy
    000000000000afb8 T _btck_block_spent_outputs_count
    000000000000b0d8 T _btck_block_spent_outputs_destroy
    000000000000b02c T _btck_block_spent_outputs_get_transaction_spent_outputs_at
    000000000000accc T _btck_block_spent_outputs_read
    000000000000a35c T _btck_block_to_bytes
    000000000000aa24 T _btck_block_tree_entry_equals
    000000000000a9d0 T _btck_block_tree_entry_get_block_hash
    000000000000a894 T _btck_block_tree_entry_get_block_header
    000000000000a97c T _btck_block_tree_entry_get_height
    0000000000007560 T _btck_block_tree_entry_get_previous
    0000000000007674 T _btck_block_validation_state_copy
    000000000000760c T _btck_block_validation_state_create
    000000000000777c T _btck_block_validation_state_destroy
    00000000000078c8 T _btck_block_validation_state_get_block_validation_result
    0000000000007860 T _btck_block_validation_state_get_validation_mode
    000000000000bc28 T _btck_chain_contains
    000000000000bb70 T _btck_chain_get_by_height
    000000000000bae4 T _btck_chain_get_height
    0000000000006440 T _btck_chain_parameters_copy
    0000000000005f8c T _btck_chain_parameters_create
    00000000000064d4 T _btck_chain_parameters_destroy
    00000000000087e0 T _btck_chainstate_manager_create
    00000000000097c8 T _btck_chainstate_manager_destroy
    000000000000ba44 T _btck_chainstate_manager_get_active_chain
    000000000000974c T _btck_chainstate_manager_get_best_entry
    0000000000009644 T _btck_chainstate_manager_get_block_tree_entry_by_hash
    0000000000009908 T _btck_chainstate_manager_import_blocks
    0000000000007950 T _btck_chainstate_manager_options_create
    00000000000084a0 T _btck_chainstate_manager_options_destroy
    0000000000008600 T _btck_chainstate_manager_options_set_wipe_dbs
    0000000000008430 T _btck_chainstate_manager_options_set_worker_threads_num
    00000000000086f0 T _btck_chainstate_manager_options_update_block_tree_db_in_memory
    0000000000008768 T _btck_chainstate_manager_options_update_chainstate_db_in_memory
    000000000000b8a4 T _btck_chainstate_manager_process_block
    000000000000b930 T _btck_chainstate_manager_process_block_header
    000000000000b6ec T _btck_coin_confirmation_height
    000000000000b50c T _btck_coin_copy
    

    </details>

    This PR introduces a new libbitcoin_kernel internal library. It completes the internal library design as laid out in doc/design/libraries.md.

    I wanted to see how close we are to the design document after this change, so I generated some graphs with cmake graphviz:

    Master:

    Image

    This PR:

    Image

  187. DrahtBot requested review from BrandonOdiwuor on Mar 26, 2026
  188. DrahtBot requested review from Sjors on Mar 26, 2026
  189. DrahtBot added the label Needs rebase on Mar 30, 2026
  190. in src/CMakeLists.txt:374 in fdf80892b3
     370 | @@ -354,6 +371,7 @@ if(BUILD_CLI)
     371 |      core_interface
     372 |      bitcoin_cli
     373 |      bitcoin_common
     374 | +    bitcoin_kernel
    


    achow101 commented at 10:29 PM on March 30, 2026:

    I would be surprised if bitcoin-cli needed to be linked with the kernel. It appears to build without this.

  191. in src/CMakeLists.txt:210 in fdf80892b3
     206 | @@ -165,7 +207,7 @@ if(ENABLE_WALLET)
     207 |        core_interface
     208 |        bitcoin_wallet
     209 |        bitcoin_common
     210 | -      bitcoin_util
     211 | +      bitcoin_kernel
    


    achow101 commented at 10:30 PM on March 30, 2026:

    It would be surprising to me if bitcoin-wallet needs the kernel. It builds without this.

  192. ryanofsky commented at 1:28 PM on April 8, 2026: contributor

    Since the util library contains a bunch of modules that are not required by the kernel library, a new kernel_util library is introduced as well that only consists of the modules required by the kernel library.

    It seems like an alternative to introducing a new library would just be to move parts of util not needed by the kernel to the common library. I think the main reason common exists at this point is to hold code needed by node/wallet/gui code but not needed by the kernel.

  193. sedited force-pushed on Apr 22, 2026
  194. sedited commented at 10:39 AM on April 22, 2026: contributor

    Rebased fdf80892b305eaee17d50a665e821d356b570640 -> 6cb62624cd59e74fc2b5d8bffb5c3f149f7d4d2b (kernelInternalLib_28 -> kernelInternalLib_29, compare)

    • Addressed @achow101's comments 1, and 2, dropped left over kernel library links where they are no longer needed.
  195. sedited commented at 10:42 AM on April 22, 2026: contributor

    It seems like an alternative to introducing a new library would just be to move parts of util not needed by the kernel to the common library. I think the main reason common exists at this point is to hold code needed by node/wallet/gui code but not needed by the kernel.

    That was what this PR originally did, but it did not seem to get much approval at the time, and I switched approach as mentioned in my comment on this PR a few years ago here:

    "https://github.com/bitcoin/bitcoin/pull/29015 got merged in the meantime and there are some implications for this pull request. We decided that the util library may contain a superset of the utilities that the kernel strictly requires. For this reason I decided to implement aj's suggestion (https://github.com/bitcoin/bitcoin/pull/29015#issuecomment-1849208455) of introducing a slimmed-down version of the util library for the kernel containing only the components that the kernel requires. I'd appreciate the opinion of previous reviewers of this PR on this new approach. Having some modules in the util library that are not required is not all bad - they might become useful in the future when working with the kernel. On the other hand they do bloat the library and may make it harder in future to use the kernel library on some platforms."

  196. ryanofsky commented at 2:22 PM on April 22, 2026: contributor

    Having some modules in the util library that are not required is not all bad

    I guess I don't understand what specifically is bad about not using parts of util in the kernel. Things that aren't unused seem unlikely to be included or linked or cause bloat. And if there are things in util that don't belong in the kernel for any reason, they can be moved to common. I can understand wanting to have util and kernel_util libraries(*) and then getting rid of common but I don't understand a reason for wanting 3 libraries.

    (*) Though I don't think kernel_util is a great name for the library if it will also be used by the wallet.

    switched approach as mentioned in my comment on this PR a few years ago #28690 (comment):

    Interestingly that comment says it is implementing a suggestion from #29015 (comment), but is not really doing this. The suggestion there is to get rid of common, put everything in the util namespace and src/util but have separate util and util-core static libraries.

    If that's still the long term goal and this PR is a first step, then that seems good, but in this case maybe kernel_util should be called util-core

  197. sedited commented at 4:14 PM on April 22, 2026: contributor

    I guess I don't understand what specifically is bad about not using parts of util in the kernel. Things that aren't unused seem unlikely to be included or linked or cause bloat. And if there are things in util that don't belong in the kernel for any reason, they can be moved to common. I can understand wanting to have util and kernel_util libraries(*) and then getting rid of common but I don't understand a reason for wanting 3 libraries.

    I'm less concerned about bloat, or making it harder to further isolate components for targets that don't have certain OS features. Like previous build system moves and changes motivated by the kernel, this is more about establishing a moat to prevent new entanglements on the build system level. This also was a motivation for the initial introduction of the library and the reason why we have been moving code out of it. For example I never want someone to include the sock header from a kernel source without making it clear something is being moved on the build system level and hopefully further alerting the reviewer.

    With this goal in mind, it doesn't really matter to me if this is achieved as it is here, or by moving the non-kernel parts of util to common, or have a kernel_util and core_util. If you have a clear preference and would be willing to move forward and eventually merge one of the approaches, I'd be happy to change to that.

  198. ryanofsky commented at 5:16 PM on April 22, 2026: contributor

    Hmm, can you explain the sock header example a little bit? I am having some trouble understanding the goal there. It seems like including a socket header would be bad for "targets that don't have certain OS features", but you say you are "less concerned" about that. Is the concern maybe that you want to prevent high level application code from including lower-level code that is supposed to be abstracted?

    I'd be happy with any solution where it's reasonably clear which library code belongs in. Having common and util where common is for things like config file parsing that we don't want in the kernel has seemed like a reasonable approach, but dropping common and putting everything in util could also be good.

    More specifically, the concern I have about this PR just is the kernel references sneaking into the util and wallet directories. I'd think kernel would be a user of util and util would be oblivious of it, and wallet should not depend on kernel. So I'm wondering what the goal is exactly.

  199. sedited commented at 7:38 PM on April 22, 2026: contributor

    Hmm, can you explain the sock header example a little bit? I am having some trouble understanding the goal there. It seems like including a socket header would be bad for "targets that don't have certain OS features", but you say you are "less concerned" about that. Is the concern maybe that you want to prevent high level application code from including lower-level code that is supposed to be abstracted?

    Mmh, maybe we are talking past each other a bit. The layering argument is confusing. I'm not really distinguishing between an "application specific" and a "lower level utility" here, and I'm not sure that even makes sense, or at least it seems like a question of taste. From my point of view, anything that is not required strictly to get the consensus engine working acts on a different semantic level than the kernel code. This includes stuff like sockets, asmap, exec, etc. Preventing developers from trivially entangling this again with some small build system changes is just another way to communicate this in code in a minimally obtrusive manner. We currently (on master) communicate this through the kernel library cmake sources list. However that is insufficient, because the sources list may deviate (by accident) from what we are actually using on the production path, so we re-use the production path list for the external library in this PR. To keep enforcing the split we also split the utilities in a kernel and non-kernel section.

  200. DrahtBot removed the label Needs rebase on Apr 23, 2026
  201. in src/util/CMakeLists.txt:5 in 6cb62624cd
       1 | @@ -2,30 +2,20 @@
       2 |  # Distributed under the MIT software license, see the accompanying
       3 |  # file COPYING or https://opensource.org/license/mit/.
       4 |  
       5 | -add_library(bitcoin_util STATIC EXCLUDE_FROM_ALL
       6 | -  asmap.cpp
       7 | -  batchpriority.cpp
       8 | -  bip32.cpp
       9 | -  bytevectorhash.cpp
      10 | +add_library(bitcoin_kernel_util STATIC EXCLUDE_FROM_ALL
    


    ajtowns commented at 9:52 AM on April 27, 2026:

    If we're introducing new libraries, should update doc/design/libraries.md correspondingly.

    Weak preference for naming it bitcoin_util_kernel or bitcoin_util_core instead, fwiw.

  202. in src/CMakeLists.txt:143 in 6cb62624cd
     142 | @@ -93,7 +143,6 @@ add_library(bitcoin_common STATIC EXCLUDE_FROM_ALL
     143 |    chain.cpp
    


    ajtowns commented at 1:11 PM on April 27, 2026:

    You're leaving chain.cpp in common and adding it to kernel?

  203. in src/CMakeLists.txt:299 in 6cb62624cd outdated
     295 | @@ -280,6 +296,7 @@ target_link_libraries(bitcoin_node
     296 |      bitcoin_util
     297 |      $<TARGET_NAME_IF_EXISTS:bitcoin_zmq>
     298 |      leveldb
     299 | +    bitcoin_kernel
    


    ajtowns commented at 2:46 PM on April 27, 2026:

    I think you should be updating check-deps.sh as well. It shows up a lot of errors.

    --- a/contrib/devtools/check-deps.sh
    +++ b/contrib/devtools/check-deps.sh
    @@ -9,6 +9,8 @@ LIBS[cli]="libbitcoin_cli.a"
     LIBS[common]="libbitcoin_common.a"
     LIBS[consensus]="libbitcoin_consensus.a"
     LIBS[crypto]="libbitcoin_crypto.a"
    +LIBS[kernel]="libbitcoin_kernel.a"
    +LIBS[kernel_util]="libbitcoin_kernel_util.a"
     LIBS[node]="libbitcoin_node.a"
     LIBS[util]="libbitcoin_util.a"
     LIBS[wallet]="libbitcoin_wallet.a"
    @@ -20,16 +22,24 @@ ALLOWED_DEPENDENCIES=(
         "cli util"
         "common consensus"
         "common crypto"
    +    "common kernel_util"
         "common util"
         "consensus crypto"
    +    "kernel kernel_util"
    +    "kernel consensus"
    +    "kernel crypto"
    +    "kernel_util crypto"
         "node common"
         "node consensus"
         "node crypto"
         "node kernel"
    +    "node kernel_util"
         "node util"
         "util crypto"
    +    "util kernel_util"
         "wallet common"
         "wallet crypto"
    +    "wallet kernel_util"
         "wallet util"
     )
    

    I have a python version of check-deps which I'll PR shortly and I think is a bit easier to follow the output of. EDIT: #35167

  204. ajtowns commented at 2:48 PM on April 27, 2026: contributor

    Should be updating the design doc, and it would be nicer if this was reducing the complexity of all our libraries rather than adding another one to menagerie.

  205. ajtowns commented at 3:22 PM on April 27, 2026: contributor

    I couldn't figure out an opinion on splitting things:

    • Having bitcoin-cli, bitcoin-tx, and bitcoin-wallet all be fairly small is nice;
    • bitcoin-kernel is already large, but not having extraneous dependencies is definitely nice;
    • Having "consensus", "common", "util", and "kernel-util" seems a pretty messy way of achieving those goals
  206. Introduce internal kernel library
    To facilitate compiling the external kernel library with different
    symbol visibility, re-use the same source file list from its dependent
    internal counterpart.
    a47a701003
  207. sedited force-pushed on Apr 27, 2026
  208. sedited commented at 9:40 PM on April 27, 2026: contributor

    Thank you for the review @ajtowns!

    I couldn't figure out an opinion on splitting things:

    How many developers does it take to establish a library topology... ?

    6cb62624cd59e74fc2b5d8bffb5c3f149f7d4d2b -> bc54dc869bf22b8ef5dfa71debbf9fdaac5624c6 (kernelInternalLib_29 -> kernelInternalLib_30, compare)

    doc/dependencies.md still has a bunch of internal inconsistencies after this,. We've treated that document as aspirational so far anyway, so I think those are best resolved later.

  209. ajtowns commented at 3:45 AM on April 28, 2026: contributor

    Thank you for the review @ajtowns!

    I couldn't figure out an opinion on splitting things:

    How many developers does it take to establish a library topology... ?

    One. It's when you've got more than that that you have problems? :)

    Addressed @ajtowns' comment, updated doc/dependencies.md

    doc/design/libraries.md

    It misses these changes that were added to check-deps:

    -libbitcoin_consensus-->libbitcoin_util;
    
    +libbitcoin_common-->libbitcoin_kernel;
    +libbitcoin_util-->libbitcoin_util_kernel;
    +libbitcoin_wallet-->libbitcoin_kernel;
    

    I think you should also add libbitcoinkernel[libbitcoinkernel]-->libbitcoin_kernel; and class [...],libbitcoinkernel bold (and maybe change the classDef bold to include fill:white as well)

    With those changes, and removing transitive deps, the full graph after this PR looks like:

    %%{ init : { "flowchart" : { "curve" : "basis" }}}%%
    
    graph TD;
    
    bitcoin-cli[bitcoin-cli]-->libbitcoin_cli;
    
    bitcoind[bitcoind]-->libbitcoin_node;
    bitcoind[bitcoind]-->libbitcoin_wallet;
    
    bitcoin-qt[bitcoin-qt]-->libbitcoinqt;
    
    bitcoin-wallet[bitcoin-wallet]-->libbitcoin_wallet;
    
    libbitcoinkernel[libbitcoin-kernel]-->libbitcoin_kernel;
    
    libbitcoin_cli-->libbitcoin_common;
    
    libbitcoin_common-->libbitcoin_util;
    libbitcoin_common-->libbitcoin_kernel;
    
    libbitcoin_consensus-->libbitcoin_crypto;
    
    libbitcoin_kernel-->libbitcoin_consensus;
    libbitcoin_kernel-->libbitcoin_util_kernel;
    
    libbitcoin_util_kernel-->libbitcoin_crypto;
    
    libbitcoin_node-->libbitcoin_common;
    
    libbitcoinqt-->libbitcoin_cli;
    libbitcoinqt-->libbitcoin_node;
    libbitcoinqt-->libbitcoin_wallet;
    
    libbitcoin_util-->libbitcoin_crypto;
    libbitcoin_util-->libbitcoin_util_kernel;
    
    libbitcoin_wallet-->libbitcoin_common;
    
    classDef bold fill:white, stroke-width:2px, font-weight:bold, font-size: smaller;
    class bitcoin-qt,bitcoind,bitcoin-cli,bitcoin-wallet,libbitcoinkernel bold
    

    doc/dependencies.md [doc/design/libraries.md] still has a bunch of internal inconsistencies after this,. We've treated that document as aspirational so far anyway, so I think those are best resolved later.

    Adding deps from common/util/wallet to the kernel seems backwards to me. I think what we'd like might be something more like this?

    
    %%{ init : { "flowchart" : { "curve" : "basis" }}}%%
    
    graph TD;
    
    libbitcoinkernel[libbitcoinkernel]-->_kernel;
    
    bitcoin-cli[bitcoin-cli]-->_cli;
    
    bitcoind[bitcoind]-->_node;
    bitcoind[bitcoind]-->_wallet;
    
    bitcoin-qt[bitcoin-qt]-->qt;
    
    bitcoin-wallet[bitcoin-wallet]-->_wallet;
    
    _cli-->_kernel_lite;
    _cli-->_util;
    
    _kernel-->_kernel_lite;
    _kernel_lite-->_util_kernel;
    
    _node-->_util;
    _node-->_kernel;
    
    qt-->_cli;
    qt-->_node;
    qt-->_wallet;
    
    _util-->_util_kernel;
    
    _wallet-->_util;
    _wallet-->_kernel_lite;
    
    classDef bold fill:white, stroke-width:2px, font-weight:bold, font-size: smaller;
    class bitcoin-qt,bitcoind,bitcoin-cli,bitcoin-wallet,libbitcoinkernel bold
    

    That's essentially:

    • consensus is replaced by kernel_lite -- essentially whatever parts of consensus-ish logic needed by bitcoin-wallet or bitcoin-cli
    • common is dropped, with code moved to util or node
    • crypto is moved into util_kernel (or util)

    With the main property being that each lib is included by a different combination of binaries.

    One place where dropping transitive deps is misleading is that the bitcoin-cli, -tx, -util and -wallet utilities currently include the util lib, but not the crypto lib. So rather than merging crypto into util, maybe it would be better to move the modules that depend on crypto out of util and into crypto/kernel/node.

    OTOH, I'm not entirely sure how much that matters at all, if the linker just cleans everything up anyway, what are we actually achieving?

  210. Update docs and check-deps for util kernel lib 2a77b5fde4
  211. sedited commented at 10:48 AM on April 28, 2026: contributor

    Adding deps from common/util/wallet to the kernel seems backwards to me. I think what we'd like might be something more like this?

    Yeah, there are some confusing deps there. kernel_lite might indeed better describe such a shared component between wallet and kernel. AFAICT many of the components the wallet currently requires from the kernel are policy related, so putting them into something called "consensus" would be very confusing. I've had a branch splitting the mempool from the kernel on the back burner for a while now. Maybe it is time to finally work on that?

    OTOH, I'm not entirely sure how much that matters at all, if the linker just cleans everything up anyway, what are we actually achieving?

    The impact of all of this is pretty marginal. I laid out my main motivation for it here: #28690 (comment).

    Updated bc54dc869bf22b8ef5dfa71debbf9fdaac5624c6 -> 2a77b5fde4a7324047e0f8e480071b5b0f72de00 (kernelInternalLib_30 -> kernelInternalLib_31, compare)

    • Addressed @ajtowns' comment, adding some more edges that were documented by check-deps, and a new libbitcoinkernel node to the mermaid diagram.
  212. sedited force-pushed on Apr 28, 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-05-02 15:13 UTC

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