Libbitcoinkernel Project Tracking #27587

issue TheCharlatan openend this issue on May 6, 2023
  1. TheCharlatan commented at 8:27 am on May 6, 2023: contributor

    Project Board: https://github.com/orgs/bitcoin/projects/3

    This is the tracking issue for the libbitcoinkernel project. The original tracking issue is found in #24303.

    The libbitcoinkernel project is a new attempt at extracting Bitcoin Core’s consensus engine. The kernel part of the name highlights one of the key functional differences from the deprecated libbitcoinconsensus and in fact, most libraries: it is a stateful library that can spawn threads, do caching, do I/O, and many other things that one may not normally expect from a library.

    This statefulness is necessary for libbitcoinkernel’s decidedly incremental approach to extracting our consensus engine. This approach favors:

    1. Reusing existing code …which allows us to be continually integrated with Bitcoin Core and benefit from our extensive test suite

    2. Incremental decoupling instead of building from scratch …which allows us to avoid having to prematurely optimize for a “perfect” boundary or API (tends to be highly subjective, non-obvious, may lead to unproductive bike-shedding before we’ve even done anything meaningful)

    The work of extracting the validation engine into a library and making the API ergonomic is likely to be a multi-release project involving multiple contributors. The incremental approach takes this into account and respects the sheer size of work (both in writing code and getting it through review) that needs to be undertaken.

    PRs

    Please see the project board: https://github.com/orgs/bitcoin/projects/3

    The Game Plan

    • Stage 1
      • Step 1: Create bitcoin-chainstate binary
      • Step 2: Prune unnecessary modules
      • Step 3: Prune unnecessary headers
    • Stage 2

    Stage 1: Extracting out a usable libbitcoinkernel.{so,dylib,dll}

    The introducedbitcoin-chainstate executable uses the validation engine to validate blocks passed to it on the command line. Its build system code revealed the minimal set of files needed to link in to use the consensus engine as-is. Over time, these files were further pruned to only include functionality that is strictly required for validation. This pruning is enforced by the build system such that future re-coupling of validation code with non-validation modules will result in linker errors.

    The mempool is not decoupled, because some users of libbitcoinkernel may want to have an embedded mempool with Bitcoin Core’s policies. Instead these kind of “Bitcoin Core specific” functionality (also includes assumevalid, assumeutxo, and checkpoints) should be completely optional and configurable by the user.

    The current design of the mempool within the validation code requires the boost headers to be exported. This is not ideal, since it forces the users of the kernel library to include the boost headers too if they wish to use this functionality. Removing them has been attempted in #28335, but the approach taken has received mixed review. In future, this might be solved by only exporting a C header to users, which would internalize any exported boost symbols.

    libbitcoinkernel could also be used as an internal library for libbitcoin_node. The desired library organization is shown in doc/design/libraries.md. This is attempted in #28690.

    Stage 2: Ship an external kernel API

    Now that an internal kernel library with a limited feature set exists, expose it to external users with a C header. Start with a reduced header, exposing just enough functionality to build a utility tool. Ideas for such a utility tool could be a rewrite of bitcoin-chainstate using the C header’s API, or a reindexer tool. These tools could also be written in other languages, such as Rust or Python. Care should be taken that the API is as consistent as possible in all respects, manages its own memory to the extent possible, minimizes type conversions between C and C++, and keeps versioning in mind.

    • Introduce initial C API #30595
    • Export symbols required for interface
    • Settle on library topology
    • Add fatal error return codes

    Ideally, users looking to integrate with libbitcoinkernel will provide inputs on which library features might be desirable to have exposed. The API will initially have a very idiosyncratic, Bitcoin Core-specific interface. Continual polishing over multiple versions will incrementally make the libbitcoinkernel API more ergonomic for users outside of Bitcoin Core. Note though, that there is a possible dichotomy here between optimizing the library interface for external users and for the internal interface within Bitcoin Core.

    Another goal of this final stage of the project could be to ship an “IO-less” version of the library. This would mean that the block store and coins database would have to be abstracted such that the user can provide their own implementations. It should optionally also not use any threads, atomics, or otherwise platform-dependent features. This would allow the library to target bare metal environment such as targeted by riscv-unknown-elf-g++.

    Action Items

    1. If you have any questions, please post them below!
    2. If you have any ideas for the future direction of “Stage 2: Polishing the API / Continual De-coupling”, please leave a comment below, I’d love to talk!

    Project-wide TODOs

    These are suggestions for further cleanup and improvements that came up during review:

    Other various items that arose during review and should be tracked

    • Cory’s request for cleaning up the kernel interface functions of pointer and reference types: #27636 (review)
    • Marcos’ request for unrolling the reindex loop: #27125 (review)
    • Marco’s request for getting rid of exceptions in the ArgsManager: #27491 (review)
    • Russell’s request for eliminating the BlockNotify signal: #27636 (review)
  2. fanquake pinned this on May 6, 2023
  3. willcl-ark commented at 1:16 pm on May 30, 2023: member

    Would it make sense to update the project page to https://github.com/orgs/bitcoin/projects/3/views/1 (which if I’m not mistaken seems to be the current one)?

    Could keep a link to the old project https://github.com/bitcoin/bitcoin/projects/18 for reference?

  4. TheCharlatan commented at 1:25 pm on May 30, 2023: contributor

    Re #27587 (comment)

    Would it make sense to update the project page to https://github.com/orgs/bitcoin/projects/3/views/1 (which if I’m not mistaken seems to be the current one)?

    Thanks for the notice, updated to the new one.

    Could keep a link to the old project https://github.com/bitcoin/bitcoin/projects/18 for reference?

    There is no useful extra information on the old board that is not in the new one, so I don’t think this is necessary.

  5. fanquake referenced this in commit 9564f98fee on May 30, 2023
  6. ryanofsky referenced this in commit 153a6882f4 on Jun 9, 2023
  7. ryanofsky referenced this in commit 75135c673e on Jul 6, 2023
  8. fanquake referenced this in commit b565485c24 on Aug 7, 2023
  9. darosior commented at 2:01 pm on September 8, 2023: member

    @TheCharlatan sometimes mentions sourcetrail as a tool to visually inspect the currently required kernel headers. I’ve set it up and figured it could be worth sharing with anyone who’s interested in having a quick look to the trail of headers without having to set up the tool themselves.

    The list of headers included in libbitcoinkernel as of current master d2ccca253f4294b8f480e1d192913f4985a1af08: bitcoin-chainstate_sourcetrail

  10. fanquake commented at 3:42 pm on September 8, 2023: member

    Nice. Played around with this. If you merge a couple things, and turn on c++20, so we can use <bit> (see corys branch), bitcoin-config.h disappears:

    less_headers

  11. fanquake referenced this in commit 1e9d367d0d on Sep 14, 2023
  12. Frank-GER referenced this in commit a202eda9b4 on Sep 19, 2023
  13. achow101 unpinned this on Oct 5, 2023
  14. bitcoin deleted a comment on Dec 3, 2023
  15. bitcoin deleted a comment on Jan 19, 2024
  16. willcl-ark added the label Brainstorming on Feb 4, 2024
  17. achow101 referenced this in commit c07935bcf5 on Mar 9, 2024
  18. TheCharlatan commented at 1:19 pm on April 11, 2024: contributor
    Updated with initial description of stage 2.
  19. achow101 referenced this in commit 2cedb42a92 on May 10, 2024
  20. ryanofsky referenced this in commit dbb3113082 on May 14, 2024
  21. achow101 referenced this in commit 058af75874 on May 17, 2024
  22. ryanofsky referenced this in commit 94d56b9def on Jul 8, 2024
  23. ryanofsky referenced this in commit 4687832680 on Jul 16, 2024
  24. fanquake referenced this in commit b27ef8ec7f on Jul 31, 2024
  25. denavila referenced this in commit 881e304866 on Sep 4, 2024

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-11-21 09:12 UTC

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