Skip to content

Conversation

ryanofsky
Copy link
Contributor

@ryanofsky ryanofsky commented Feb 15, 2022

Prompted by the libbitcoinkernel issue #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

@hebasto
Copy link
Member

hebasto commented Feb 16, 2022

Concept ACK.


### Resources
* Discuss on the [BitcoinTalk](https://bitcointalk.org/) forums, in the [Development & Technical Discussion board](https://bitcointalk.org/index.php?board=6.0).
* 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).

### Miscellaneous
- [Assets Attribution](assets-attribution.md)
- [Assumeutxo design](assumeutxo.md)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #24352 (comment)

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

- 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:

```mermaid
graph TD;
Copy link
Member

@Sjors Sjors Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link

@ghost ghost Jun 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

flowchart TB
    subgraph 1
    d[bitcoind]-->libbitcoin_wallet
    end
    subgraph 2
    qt[bitcoin-qt]-->libbitcoin_node
    qt[bitcoin-qt]-->libbitcoinqt
    qt[bitcoin-qt]-->libbitcoin_wallet
    end
    subgraph 3
    w[bitcoin-wallet]-->libbitcoin_wallet
    w[bitcoin-wallet]-->libbitcoin_wallet_tool
    end

    classDef teal fill:#033E3E,stroke:#AFDCEC,stroke-width:1px;
    class d,qt,w teal
flowchart TB
    subgraph 1
    d[bitcoind]-->libbitcoin_wallet
    end
    subgraph 2
    qt[bitcoin-qt]-->libbitcoin_node
    qt[bitcoin-qt]-->libbitcoinqt
    qt[bitcoin-qt]-->libbitcoin_wallet
    end
    subgraph 3
    w[bitcoin-wallet]-->libbitcoin_wallet
    w[bitcoin-wallet]-->libbitcoin_wallet_tool
    end

    classDef teal fill:#033E3E,stroke:#AFDCEC,stroke-width:1px;
    class d,qt,w teal
Loading

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #24352 (comment)

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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dongcarl
Copy link
Contributor

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).

@dongcarl
Copy link
Contributor

dongcarl commented Mar 4, 2022

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

@dongcarl dongcarl mentioned this pull request Mar 4, 2022
14 tasks
@fanquake fanquake added Docs and removed Validation labels Apr 20, 2022
@fanquake
Copy link
Member

Concept ACK (on adding docs for this) - will look at the actual content.

Copy link
Contributor

@jamesob jamesob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

| Name | Description |
|------------------------|-------------|
| libbitcoin_cli | RPC client functionality used by `bitcoin-cli` executable |
| libbitcoin_common | Home for common functionality shared by different executables and libraries. Similar to `libbitcoin_util`, but higher-level (see [Dependencies](#dependencies). |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a closing paren on this line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #24352 (comment)

Missing a closing paren on this line

Thanks! Also corrected below

| libbitcoinqt | GUI functionality used by `bitcoin-qt` and `bitcoin-gui` executables |
| libbitcoin_ipc | IPC functionality used by `bitcoin-node`, `bitcoin-wallet`, `bitcoin-gui` executables to communicate when [`--enable-multiprocess`](multiprocess.md) is used. |
| libbitcoin_node | P2P and RPC server functionality used by `bitcoind` and `bitcoin-qt` executables. |
| libbitcoin_util | Home for common functionality shared by different executables and libraries. Similar to `libbitcoin_common`, but lower-level (see [Dependencies](#dependencies). |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another missing paren

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #24352 (comment)

Another missing paren

Thanks, fixed

Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

re: #24352 (review)

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.


### Resources
* Discuss on the [BitcoinTalk](https://bitcointalk.org/) forums, in the [Development & Technical Discussion board](https://bitcointalk.org/index.php?board=6.0).
* 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).

### Miscellaneous
- [Assets Attribution](assets-attribution.md)
- [Assumeutxo design](assumeutxo.md)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #24352 (comment)

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

| Name | Description |
|------------------------|-------------|
| libbitcoin_cli | RPC client functionality used by `bitcoin-cli` executable |
| libbitcoin_common | Home for common functionality shared by different executables and libraries. Similar to `libbitcoin_util`, but higher-level (see [Dependencies](#dependencies). |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #24352 (comment)

Missing a closing paren on this line

Thanks! Also corrected below

| libbitcoinqt | GUI functionality used by `bitcoin-qt` and `bitcoin-gui` executables |
| libbitcoin_ipc | IPC functionality used by `bitcoin-node`, `bitcoin-wallet`, `bitcoin-gui` executables to communicate when [`--enable-multiprocess`](multiprocess.md) is used. |
| libbitcoin_node | P2P and RPC server functionality used by `bitcoind` and `bitcoin-qt` executables. |
| libbitcoin_util | Home for common functionality shared by different executables and libraries. Similar to `libbitcoin_common`, but lower-level (see [Dependencies](#dependencies). |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #24352 (comment)

Another missing paren

Thanks, fixed

- 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:

```mermaid
graph TD;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ryanofsky ryanofsky marked this pull request as ready for review June 1, 2022 18:06
@ryanofsky ryanofsky changed the title RFC: Add doc/design/libraries.md Add doc/design/libraries.md Jun 1, 2022
@dongcarl
Copy link
Contributor

ACK 93fd8d9

Looks reasonable to me!


<table><tr><td>

```mermaid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh TIL, had no idea github could do this. Cool.

@laanwj
Copy link
Member

laanwj commented Jun 20, 2022

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.

@ryanofsky
Copy link
Contributor Author

Updated 93fd8d9 -> dc1e7ad (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

@laanwj
Copy link
Member

laanwj commented Jun 21, 2022

ACK dc1e7ad

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach ACK dc1e7ad, using this doc as a guide in hebasto#3 :)

@laanwj laanwj merged commit a4e066a into bitcoin:master Jun 22, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 22, 2022
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Sep 20, 2022
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Sep 26, 2022
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Sep 26, 2022
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jan 20, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jan 20, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Feb 6, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Feb 6, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Feb 10, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Feb 10, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Feb 28, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Feb 28, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Mar 16, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Mar 16, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Apr 13, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Apr 13, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request May 2, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request May 2, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request May 4, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request May 4, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Status: Done or Closed or Rethinking
Development

Successfully merging this pull request may close these issues.

9 participants