Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Introduce internal kernel library #28690

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

TheCharlatan
Copy link
Contributor

@TheCharlatan TheCharlatan commented Oct 20, 2023

This PR introduces a new libbitcoin_kernel internal library. It completes the internal library design as laid out in doc/design/libraries.md. The external libbitcoinkernel library now uses the source lists of the internal library for its compilation.

Should also address #28548.

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 20, 2023

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK ryanofsky
Concept ACK stickies-v, theuni, kashifs, pablomartin4btc, ismaelsadeeq
Approach ACK hebasto

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29050 (Add OP_TXHASH and OP_CHECKTXHASHVERIFY opcodes by stevenroose)
  • #29015 (kernel: Streamline util library by ryanofsky)
  • #29001 (Ephemeral Anchors by instagibbs)
  • #28983 (Stratum v2 Template Provider (take 2) by Sjors)
  • #28960 (kernel: Remove dependency on CScheduler by TheCharlatan)
  • #28956 (Nuke adjusted time (attempt 2) by dergoegge)
  • #28948 (v3 transaction policy for anti-pinning by glozow)
  • #28676 ([WIP] Cluster mempool implementation by sdaftuar)
  • #28075 (util: Remove DirIsWritable, GetUniquePath by maflcko)
  • #28051 (Get rid of shutdown.cpp/shutdown.h, use SignalInterrupt directly by ryanofsky)
  • #27351 (wallet: add seeds argument to importdescriptors by apoelstra)
  • #27331 (refactor: extract CCheckQueue's data handling into a separate container "Bag" by martinus)
  • #22838 (descriptors: Be able to specify change and receiving in a single descriptor string by achow101)

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.

@hebasto
Copy link
Member

hebasto commented Oct 21, 2023

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

@TheCharlatan
Copy link
Contributor Author

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

@hebasto
Copy link
Member

hebasto commented Oct 21, 2023

Looks like the remaining test failure is a timeout?

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

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 6, 2023

Guix builds (on x86_64)

File commit 6d57909
(master)
commit d5b4ca0
(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...

@TheCharlatan
Copy link
Contributor Author

Thank you for the review @ryanofsky,

Rebased 5a23504 -> 2086d1d (kernelInternalLib_10 -> kernelInternalLib_11, compare)

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.

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

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`
- `G_TRANSLATION_FUN`

It looks good.

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 2086d1d.

Still reviewing the 4th commit (983d097).

@ismaelsadeeq
Copy link
Member

Concept ACK
Did a light review this looks good to me

Move util library files that are not used by the kernel library and are
not unopinionated utilities to the common library. This is consistent
with the library structure laid out in doc/design/libraries.md.

Moving util/message.cpp to the common library also breaks an
undocumented dependency of the util library on the consensus library's
CPubKey::RecoverCompact symbol.
The crypto library should not have any dependencies on the util library.
With this move the cleanse file can be removed from the explicit
libbitcoinconsensus dependency list, since it is now linked in through
the crypto library.
The files should not be duplicated between the consensus and util
libraries. Instead split off the part that is required by the consensus
library into a new file that is compiled as part of the crypto library.
See doc/design/libraries.md for an overview of the internal libraries.

Some of the internal libraries and bitcoin binaries do not link with the
libbitcoin kernel (e.g. libbitcoin_wallet, bitcoin-wallet,
libbitcoin_cli, libbitcoinqt). However they still rely on some of the
files that are also required by the kernel library. Move this class of
files into the util library, which all libraries and binaries can link
with. Files moved for this reason from the common to the util library
are:

coins.cpp
core_read.cpp
kernel/chainparams.cpp
key.cpp
policy/feerate.cpp
policy/policy.cpp
scheduler.cpp
script/solver.cpp
The external kernel library should use the same file list that the
internal kernel library uses.
@TheCharlatan
Copy link
Contributor Author

// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_CRYPTO_HEX_BASE_H
#define BITCOIN_CRYPTO_HEX_BASE_H
Copy link
Member

Choose a reason for hiding this comment

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

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

re: #28690 (comment)

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 (review), I think the idea was to have it in crypto since util and consensus libraries depend on the crypto library.

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 #28690 (comment)

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.

Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

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

Code review ACK 34970bd.

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.

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.

The last commit 34970bd 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.

@TheCharlatan
Copy link
Contributor Author

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

@DrahtBot
Copy link
Contributor

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

@DrahtBot
Copy link
Contributor

⌛ There hasn't been much activity lately and the patch still needs rebase. What is the status here?

  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready for Review PRs
Development

Successfully merging this pull request may close these issues.

None yet

10 participants