Skip to content

Conversation

@fanquake
Copy link
Member

@fanquake fanquake commented Oct 11, 2022

This came up in #26196: #26196 (comment). Opening this as a draft for the minute, to point to from another PR.

Ultimately the goal here (aside from common quite possibly being a better home for this code) is to move the Boost Signals2 using code out of libbitcoin_util, which is/will be used by the kernel.

When this is done, we can drop $(BOOST_CPPFLAGS) from libbitcoin_util (last commit).

@fanquake fanquake requested a review from ryanofsky October 11, 2022 07:51
@fanquake fanquake force-pushed the move_interfaces_lib_common branch from fe97d8f to 4294f2f Compare October 11, 2022 08:02
@DrahtBot
Copy link
Contributor

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26292 (util: move threadinterrupt into util/ by fanquake)
  • #26251 (refactor: add cs_main.h by fanquake)
  • #26177 (refactor / kernel: Move non-gArgs chainparams functionality to kernel by TheCharlatan)
  • #25729 (wallet: Check max transaction weight in CoinSelection by aureleoules)
  • #25152 (refactor: Split util/system into exception, shell, and fs-specific files by Empact)
  • #24897 ([Draft / POC] Silent Payments by w0xlt)
  • #24539 (Add a "tx output spender" index by sstone)
  • #19461 (multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky)
  • #19460 (multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky)
  • #15294 (refactor: Extract RipeMd160 by Empact)
  • #10102 (Multiprocess bitcoin 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.

@theuni
Copy link
Member

theuni commented Oct 11, 2022

Concept ACK.

@ryanofsky
Copy link
Contributor

ryanofsky commented Oct 11, 2022

I think something should be done about the inconsistency of having libbitcoin_common.a source files outside of the src/common/ and this is one possible option. Other possible options are:

  1. Move src/interface/ files to a libbitcoin_interfaces.a library
  2. Delete src/interface/*.cpp files and make src/interfaces/ directory only contain headers

I think I like these options a little better, because they would keep source structure flat and avoid too much nesting. They would also avoid namespace inconsistencies or the need to have a nested common::interfaces:: namespace that would make function declarations in headers more verbose.

I want look into option 2 a little more since it seems like the 3 .cpp files in the interfaces directory are very minimal and don't contain much real code.

@shaavan
Copy link
Contributor

shaavan commented Oct 12, 2022

@ryanofsky

As you mentioned, I agree that we should go for a less nested option when possible.

Now considering the alternatives you mentioned, Option 2 seems like a pretty interesting idea. I thought it to be a preferable option because it seemed a cleaner way to achieve our goal.
However, on second thought, what if we need to expand src/interfaces in the future for some reason, and going with a header-only route for the expansion might be unreasonable? So we might have to move to an option similar to your first suggestion.

This might be an infeasible scenario, and there might exist other options than the two you mentioned to achieve this goal, which I haven't considered. But I just wanted to explain why I think the second option, though cleaner, might not be feasible in the long run.

@ryanofsky
Copy link
Contributor

ryanofsky commented Oct 12, 2022

I implemented option 2 above in #26298. It changes fewer files than this PR and avoids the nested directory structure.

However, on second thought, what if we need to expand src/interfaces in the future for some reason, and going with a header-only route for the expansion might be unreasonable?

I don't see this happening, just because the point of src/interfaces/ directory is just to define abstract classes with virtual methods. Implementation of the interfaces belongs in the node, wallet, or common libraries, or in the GUI. If implementation code sneaks into the interfaces directory it's probably a mistake. Or if it is really intentional, it could logically go into a libbitcoin_interfaces.a library that without requiring all the interfaces to move somewhere.

@fanquake
Copy link
Member Author

because they would keep source structure flat and avoid too much nesting.

Is this something we are actively trying to avoid? i.e in #26250 (comment) we seem to be going the other direction.

In any case, closing this in favour of #26298.

@fanquake fanquake closed this Oct 13, 2022
@fanquake fanquake deleted the move_interfaces_lib_common branch October 13, 2022 05:19
@ryanofsky
Copy link
Contributor

ryanofsky commented Oct 13, 2022

because they would keep source structure flat and avoid too much nesting.

Is this something we are actively trying to avoid? i.e in #26250 (comment) we seem to be going the other direction.

I think both changes make sense. In that case, the file mempool_utils.cpp is renamed util/mempool.cpp, so it's really just swapping out a _ separator for the / separator, not actually adding a deeper level of nesting. I think that change is an improvement because it groups mempool utils with other utils instead of grouping them with mempool tests. It should make mempool utils more discoverable so they can be used by tests using mempool indirectly, not just tests directly testing the mempool.

In this case, this PR isn't just changing a _ separator to a / separator or :: separator, but really adding an extra level to the hierarchy, renaming "interfaces" to "common interfaces" where I think the word "common" isn't helpful descriptively, and isn't great organizationally since it groups wallet and node interface definitions in with libbitcoin_common library code that shouldn't know anything about nodes or wallets. It could also make headers more verbose with identifiers like common::interfaces::Wallet instead of interfaces::Wallet, or introducing an inconsistency between the directory structure and namespace structure.

The idea for src/interfaces/ is that it defines abstract interfaces that libraries can use to call each other without depending on each other at link time. Since #20494, the libbitcoin_node library provides Node and Chain implementations, the libbitcoin_wallet library provides Wallet and WalletLoader implementations. #26298 just extends #20494 so the libbitcoin_common provides now provides Handler implementations.

Hope that makes sense.

fanquake added a commit that referenced this pull request Nov 1, 2022
3a0b352 refactor: move url.h/cpp from lib util to lib common (fanquake)
058eb69 build: add missing event cflags to libbitcoin_util (fanquake)

Pull request description:

  Move `util/url` to `common/url`.

  Also add missing `event_*` flags to `libbitcoin_util`. #26293 + the commit dropping boost cppflags from `libbitcoin_util` shows this issue. i.e:
  ```bash
    CXX      util/libbitcoin_util_a-url.o
  util/url.cpp:7:10: fatal error: 'event2/http.h' file not found
  #include <event2/http.h>
           ^~~~~~~~~~~~~~~
  1 error generated.
  ```

ACKs for top commit:
  hebasto:
    ACK 3a0b352
  ryanofsky:
    Code review ACK 3a0b352

Tree-SHA512: 600a76fd334267a02d332df9b67891a38d3fd7f5baf8a82b2447879b3bc65eab2552d2c081c0a5f1ec927bf80df7fc1f0cbbdda4cb76994b46dadf260b8e1cb3
fanquake added a commit that referenced this pull request Dec 7, 2022
…_common.a

b19c412 refactor: Rename ambiguous interfaces::MakeHandler functions (Ryan Ofsky)
dd6e8bd build: remove BOOST_CPPFLAGS from libbitcoin_util (fanquake)
82e272a refactor: Move src/interfaces/*.cpp files to libbitcoin_common.a (Ryan Ofsky)

Pull request description:

  These belong in `libbitcoin_common.a`, not `libbitcoin_util.a`, because they aren't general-purpose utilities, they just contain some common glue code that is used by both the node and the wallet. Another reason not to include these in `libbitcoin_util.a` is to prevent them from being used by the kernel library.

  Also rename ambiguous `MakeHandler` functions to `MakeCleanupHandler` and `MakeSignalHandler`. Cleanup function handler was introduced after boost signals handler, so original naming didn't make much sense.

  This just contains a move-only commit, and a rename commit. There are no actual code or behavior changes.

  This PR is an alternative to #26293, and solves the same issue of removing a boost dependency from the _util_ library. The advantages of this PR compared to #26293 are that it keeps the source directory structure more flat, and it avoids having to change #includes all over the codebase.

ACKs for top commit:
  hebasto:
    ACK b19c412

Tree-SHA512: b3a1d33eedceda7ad852c6d6f35700159d156d96071e59acae2bc325467fef81476f860a8855ea39cf3ea706a1df2a341f34fb2dcb032c31a3b0e9cf14103b6a
@bitcoin bitcoin locked and limited conversation to collaborators Oct 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants