Add doc/design/libraries.md #24352

pull ryanofsky wants to merge 1 commits into bitcoin:master from ryanofsky:pr/libs changing 5 files +106 −2
  1. ryanofsky commented at 2:48 pm on February 15, 2022: member

    Prompted by the [libbitcoinkernel issue #24303](https://github.com/bitcoin/bitcoin/issues/24303) and PRs, I started looking at existing libraries and what their dependencies are and wrote this document to describe them and where libbitcoinkernel fits in.

    Readable link is: https://github.com/ryanofsky/bitcoin/blob/pr/libs/doc/design/libraries.md

    Feedback is welcome

  2. Add doc/design/libraries.md dc1e7ad7a5
  3. DrahtBot added the label Validation on Feb 15, 2022
  4. hebasto commented at 11:44 am on February 16, 2022: member
    Concept ACK.
  5. in doc/README.md:74 in 4131c5ff8e outdated
    70 * Discuss on the [BitcoinTalk](https://bitcointalk.org/) forums, in the [Development & Technical Discussion board](https://bitcointalk.org/index.php?board=6.0).
    71 * Discuss project-specific development on #bitcoin-core-dev on Libera Chat. If you don't have an IRC client, you can use [web.libera.chat](https://web.libera.chat/#bitcoin-core-dev).
    72 
    73 ### Miscellaneous
    74 - [Assets Attribution](assets-attribution.md)
    75-- [Assumeutxo design](assumeutxo.md)
    


    Sjors commented at 9:21 am on February 17, 2022:
    Maybe add a doc/design/README.md (although the above description doesn’t add much to just a directory view)

    ryanofsky commented at 3:10 pm on June 1, 2022:

    re: #24352 (review)

    Maybe add a doc/design/README.md (although the above description doesn’t add much to just a directory view)

    I think I’d hold off on adding another readme for now. It seems like it would be pretty bare and even if there were things to say, they might be more helpful and visible in the main readme. Could rethink in the future as more things are added here

  6. in doc/design/libraries.md:40 in 4131c5ff8e outdated
    30+## Dependencies
    31+
    32+- Libraries should generally be careful about what other libraries they depend on, and only reference symbols following the arrows shown in the dependency graph below:
    33+
    34+```mermaid
    35+graph TD;
    


    Sjors commented at 10:14 am on February 17, 2022:
    This looks a bit scary with all these curved lines. It’s probably better to use (a reasonably chosen set of) fixed positions and straight lines.

    ryanofsky commented at 10:48 am on February 17, 2022:
    Yeah this graph is atrocious. I thought mermaid might do a better job with it. I think the markdown source code is more undertandable than the graphic, but I will look for mermaid options (straight lines!) which might make this more readable.

    ryanofsky commented at 3:49 pm on June 1, 2022:
    FWIW, I figured out how to make the lines straight. I thinks it cuts down some of the chaos and helps a little. I also added a caption to the graph to call out more important aspects.

    unknown commented at 4:32 pm on June 20, 2022:

    Flow chart still looks confusing. I tried creating some flowcharts using mermaid live editor based on syntax shared here. I was able to simplify bitcoind, bitcoin-qt and bitcoin-wallet but not other things (used different color for binaries):

     0flowchart TB
     1    subgraph 1
     2    d[bitcoind]-->libbitcoin_wallet
     3    end
     4    subgraph 2
     5    qt[bitcoin-qt]-->libbitcoin_node
     6    qt[bitcoin-qt]-->libbitcoinqt
     7    qt[bitcoin-qt]-->libbitcoin_wallet
     8    end
     9    subgraph 3
    10    w[bitcoin-wallet]-->libbitcoin_wallet
    11    w[bitcoin-wallet]-->libbitcoin_wallet_tool
    12    end
    13
    14    classDef teal fill:#033E3E,stroke:#AFDCEC,stroke-width:1px;
    15    class d,qt,w teal
    
     0flowchart TB
     1    subgraph 1
     2    d[bitcoind]-->libbitcoin_wallet
     3    end
     4    subgraph 2
     5    qt[bitcoin-qt]-->libbitcoin_node
     6    qt[bitcoin-qt]-->libbitcoinqt
     7    qt[bitcoin-qt]-->libbitcoin_wallet
     8    end
     9    subgraph 3
    10    w[bitcoin-wallet]-->libbitcoin_wallet
    11    w[bitcoin-wallet]-->libbitcoin_wallet_tool
    12    end
    13
    14    classDef teal fill:#033E3E,stroke:#AFDCEC,stroke-width:1px;
    15    class d,qt,w teal
    

    ryanofsky commented at 8:46 pm on June 21, 2022:

    re: #24352 (review)

    Thanks! I applied some of the styling here to highlight the exe outputs, though I avoided black text on teal background, because that was not readable on my PC. I also experimented with subgraphs, but trying to apply them to complete graph always seemed to blow up the graph. Probably there is room to do fancier things here in the future, but for now I’m happy if graph just shows what symbol dependencies between libraries are allowed.


    unknown commented at 5:45 am on June 22, 2022:

    though I avoided black text on teal background, because that was not readable on my PC

    Just realized it looks different in github (light theme). Text is white in github (dark theme)

    Probably there is room to do fancier things here in the future, but for now I’m happy if graph just shows what symbol dependencies between libraries are allowed.

    Makes sense.

  7. dongcarl commented at 9:32 pm on February 22, 2022: member

    I had a conversation with Ryan about this and agree to the broad strokes of things. We decided that it would be good to move:

    • Everything in common that kernel depends on to util
    • Everything in util that kernel doesn’t depend on to common

    I need to make that move and see where things fall to make an educated assessment of the hierarchy described here (mostly the part about libbitcoinkernel not depending on common and only depending on util).

  8. dongcarl commented at 1:03 am on March 4, 2022: member

    We decided that it would be good to move:

    • Everything in common that kernel depends on to util
    • Everything in util that kernel doesn’t depend on to common

    Implemented this here: https://github.com/dongcarl/bitcoin/commits/2022-03-libbitcoinkernel-utilcommon-restructure

    Seems to me like a nice dividing line between util and common. Would love more Concept ACKs

  9. fanquake removed the label Validation on Apr 20, 2022
  10. fanquake added the label Docs on Apr 20, 2022
  11. fanquake commented at 1:46 pm on April 20, 2022: member
    Concept ACK (on adding docs for this) - will look at the actual content.
  12. dongcarl added this to the "WIP PRs" column in a project

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

  14. in doc/design/libraries.md:6 in 4131c5ff8e outdated
    0@@ -0,0 +1,90 @@
    1+# Libraries
    2+
    3+| Name                   | Description |
    4+|------------------------|-------------|
    5+| libbitcoin_cli         | RPC client functionality used by `bitcoin-cli` executable |
    6+| libbitcoin_common      | Home for common functionality shared by different executables and libraries. Similar to `libbitcoin_util`, but higher-level (see [Dependencies](#dependencies). |
    


    jamesob commented at 7:59 pm on May 24, 2022:
    Missing a closing paren on this line

    ryanofsky commented at 3:11 pm on June 1, 2022:

    re: #24352 (review)

    Missing a closing paren on this line

    Thanks! Also corrected below

  15. in doc/design/libraries.md:13 in 4131c5ff8e outdated
     8+| libbitcoinconsensus    | Shared library build of static `libbitcoin_consensus` library |
     9+| libbitcoin_kernel      | Consensus "engine" and support library used for validation by `libbitcoin_node` and also exposed as a [shared library](../doc/shared-libraries.md). |
    10+| libbitcoinqt           | GUI functionality used by `bitcoin-qt` and `bitcoin-gui` executables |
    11+| libbitcoin_ipc         | IPC functionality used by `bitcoin-node`, `bitcoin-wallet`, `bitcoin-gui` executables to communicate when [`--enable-multiprocess`](multiprocess.md) is used. |
    12+| libbitcoin_node        | P2P and RPC server functionality used by `bitcoind` and `bitcoin-qt` executables. |
    13+| libbitcoin_util        | Home for common functionality shared by different executables and libraries. Similar to `libbitcoin_common`, but lower-level (see [Dependencies](#dependencies). |
    


    jamesob commented at 8:00 pm on May 24, 2022:
    Another missing paren

    ryanofsky commented at 3:12 pm on June 1, 2022:

    re: #24352 (review)

    Another missing paren

    Thanks, fixed

  16. jamesob approved
  17. jamesob commented at 8:07 pm on May 24, 2022: member

    ACK

    Not sure how I missed this when it was filed, but I think this is really valuable documentation - thanks for writing it up! I also don’t think the mermaid graph looks too bad, and I think it’s certainly preferably to maintaining some kind of in-repo image. I say we keep it.

    I think the constraints you outline later in the document (module X should never depend on module Y etc.) is very helpful information - can it be enforced somehow at the build system level? Obviously we’d know if there were ever violations because it’d be clear (I think) from Makefile changes, but wondering if there’s some extra step we could take.

  18. ryanofsky force-pushed on Jun 1, 2022
  19. ryanofsky commented at 6:06 pm on June 1, 2022: member

    Updated 4131c5ff8e8905cdc23410d52c23979aa881e3b7 -> d076c18de5d9debc4b3304727712da59524a7ee9 (pr/libs.1 -> pr/libs.2, compare) with various edits and some clarifications about kernel and util and common libs Updated d076c18de5d9debc4b3304727712da59524a7ee9 -> 93fd8d9e98feb4e0e060b3de8a8cb1671a693e79 (pr/libs.2 -> pr/libs.3, compare) with minor edits

    re: #24352#pullrequestreview-983783293

    I think the constraints you outline later in the document (module X should never depend on module Y etc.) is very helpful information - can it be enforced somehow at the build system level?

    Probably it would not be too hard to write a linter to check this. It could run nm src/libbitcoin_util.a etc, look at all the symbols each library defines (T), and all the symbols each library uses (U), and make sure libraries only uses symbols from libraries they are allowed to depend on.

  20. ryanofsky marked this as ready for review on Jun 1, 2022
  21. ryanofsky renamed this:
    RFC: Add doc/design/libraries.md
    Add doc/design/libraries.md
    on Jun 1, 2022
  22. ryanofsky force-pushed on Jun 1, 2022
  23. dongcarl commented at 5:45 pm on June 16, 2022: member

    ACK 93fd8d9e98feb4e0e060b3de8a8cb1671a693e79

    Looks reasonable to me!

  24. in doc/design/libraries.md:87 in 93fd8d9e98 outdated
    82+
    83+- The graph shows what _symbols_ (functions and variables) from each library other libraries can call and reference directly, but it is not a call graph. For example, there is no arrow connecting *libbitcoin_wallet* and *libbitcoin_node* libraries, because these libraries are intended to be modular and not depend on each other's internal implementation details. But wallet code still is still able to call node code indirectly through the `interfaces::Chain` abstract class in [`interfaces/chain.h`](../../src/interfaces/chain.h) and node code calls wallet code through the `interfaces::ChainClient` and `interfaces::Chain::Notifications` abstract classes in the same file. In general, defining abstract classes in [`src/interfaces/`](../../src/interfaces/) can be a convenient way of avoiding unwanted direct dependencies or circular dependencies between libraries.
    84+
    85+- *libbitcoin_consensus* should be a standalone dependency that any library can depend on, and it should not depend on any other libraries itself.
    86+
    87+- *libbitcoin_util* should also be a standalone dependency that any library can depend on, and it should not depend on other internal libraries. (It does use currently use boost and univalue external libraries.)
    


    MarcoFalke commented at 9:42 am on June 20, 2022:
    0- *libbitcoin_util* should also be a standalone dependency that any library can depend on, and it should not depend on other internal libraries.
    

    ryanofsky commented at 8:49 pm on June 21, 2022:

    re: #24352 (review)

    Thanks. I’m a little unclear what the original reason was for this suggestion, but dropped this sentence because there’s no need to mention external libraries here, so probably better to be shorter.

  25. MarcoFalke approved
  26. in doc/design/libraries.md:36 in 93fd8d9e98 outdated
    31+
    32+- Libraries should minimize what other libraries they depend on, and only reference symbols following the arrows shown in the dependency graph below:
    33+
    34+<table><tr><td>
    35+
    36+```mermaid
    


    laanwj commented at 11:06 am on June 20, 2022:
    Huh TIL, had no idea github could do this. Cool.
  27. in doc/design/libraries.md:44 in 93fd8d9e98 outdated
    39+
    40+graph TD;
    41+
    42+bitcoin-cli-->libbitcoin_cli;
    43+
    44+bitcoind-->libbitcoin_node;
    


    laanwj commented at 11:09 am on June 20, 2022:
    I think it would be useful to make the “binary” boxes a different color or style from the library ones, if possible.

    ryanofsky commented at 8:47 pm on June 21, 2022:

    re: #24352 (review)

    I think it would be useful to make the “binary” boxes a different color or style from the library ones, if possible.

    Thanks, used style suggestion from 1440000bytes above

  28. laanwj commented at 11:12 am on June 20, 2022: member
    ACK, this matches with my understanding of the dependencies and library uses. At some point we could add something about the exported APIs of the shared libraries, but no need to do that here.
  29. ryanofsky force-pushed on Jun 21, 2022
  30. ryanofsky commented at 9:27 pm on June 21, 2022: member
    Updated 93fd8d9e98feb4e0e060b3de8a8cb1671a693e79 -> dc1e7ad7a5713d885f70ccc6c93e7a4c07e76559 (pr/libs.3 -> pr/libs.4, compare) just dropping comment about external libraries and making it easier to distinguish exes from libraries in the graph as suggested
  31. laanwj commented at 10:06 pm on June 21, 2022: member
    ACK dc1e7ad7a5713d885f70ccc6c93e7a4c07e76559
  32. hebasto commented at 11:02 pm on June 21, 2022: member
    Approach ACK dc1e7ad7a5713d885f70ccc6c93e7a4c07e76559, using this doc as a guide in https://github.com/hebasto/bitcoin/pull/3 :)
  33. laanwj merged this on Jun 22, 2022
  34. laanwj closed this on Jun 22, 2022

  35. laanwj moved this from the "Relevant External PRs" to the "Done or Closed or Rethinking" column in a project

  36. sidhujag referenced this in commit e2ee7243e2 on Jun 22, 2022
  37. ryanofsky referenced this in commit afc0561479 on Sep 20, 2022
  38. ryanofsky referenced this in commit d6f3841adf on Sep 26, 2022
  39. ryanofsky referenced this in commit 6554e9febb on Sep 26, 2022
  40. ryanofsky referenced this in commit 95224ba357 on Jan 20, 2023
  41. ryanofsky referenced this in commit c48e88efac on Jan 20, 2023
  42. ryanofsky referenced this in commit e661ace249 on Feb 6, 2023
  43. ryanofsky referenced this in commit a2e575ea5e on Feb 6, 2023
  44. ryanofsky referenced this in commit 346dd5e3ad on Feb 10, 2023
  45. ryanofsky referenced this in commit 0756dfe62c on Feb 10, 2023
  46. ryanofsky referenced this in commit 767d3687b2 on Feb 28, 2023
  47. ryanofsky referenced this in commit ab2548e2b2 on Feb 28, 2023
  48. ryanofsky referenced this in commit 5df8eb99b9 on Mar 16, 2023
  49. ryanofsky referenced this in commit 585f975ebf on Mar 16, 2023
  50. ryanofsky referenced this in commit 56ca7f2821 on Apr 13, 2023
  51. ryanofsky referenced this in commit be70a5d8ae on Apr 13, 2023
  52. ryanofsky referenced this in commit 27ad1a2d8e on May 2, 2023
  53. ryanofsky referenced this in commit 8087df6550 on May 2, 2023
  54. ryanofsky referenced this in commit 25a94f30a5 on May 4, 2023
  55. ryanofsky referenced this in commit 6f1dcf299b on May 4, 2023
  56. DrahtBot locked this on Jun 22, 2023

github-metadata-mirror

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

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