HomePhabricator

[Chronik] Refactor bridge: Split into `chronik-bridge` and `chronik-lib`

Description

[Chronik] Refactor bridge: Split into chronik-bridge and chronik-lib

Summary:
Currently, all the ffi code is in chronik-ffi. However, other crates might want to depend on the ffi code.

However, chronik-ffi is the staticlib that is linked to bitcoind at the end, it'll be the "root" crate depending on all the crates comprising Chronik.

For that reason, other crates cannot depend on chronik-ffi, as it will create a circular reference, which is not allowed for crates.

Say a crate chronik-log wants to reference log_println, defined in chronik-ffi. Also, chronik-ffi wants to use the logging defined in chronik-log.

It would create circular dependencies: chronik-log -> chronik-ffi -> chronik-log.

Therefore, we have to split the ffi into two parts:

  1. chronik-bridge: This defines shared types and functions defined in C++, e.g. log_println.
  2. chronik-lib: This defines all the functions that C++ will need to call, like setup_bridge and methods from CValidationInterface.

This way, there's no circular dependencies: chronik-bridge -> chronik-log -> chronik-lib.

Note: There's a linking issue, and we apparently need to link to chronik-bridge twice. We added this because linking otherwise fails on gcc. This was quite tricky to solve, and Fabien and I aren't sure yet why this fixes it.
In short, somehow lld (with clang) compiles fine, whereas ld and gold fail to compile it.

This *might* be a bug with either of the linkers, and we'll need more investigation.

Fabien's guess is that the symbols are not propagated to libchronik.a because it doesn't use it (he checked and it's not in the lib) and gets optimized out or something like that.

My guess is as good as yours.

I left a "TODO" comment in CMake so maybe someone wiser than us can stumble over it and solve it, or it gets fixed in either of the two linkers.

Test Plan:

  1. ninja
  2. ./src/bitcoind -regtest prints "Starting Chronik..." as before

Reviewers: Fabien, #bitcoin_abc

Reviewed By: Fabien, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D11909

Details

Provenance
tobias_ruckAuthored on Sep 2 2022, 13:24
tobias_ruckPushed on Sep 21 2022, 13:58
Reviewer
Restricted Project
Differential Revision
D11909: [Chronik] Refactor bridge: Split into `chronik-bridge` and `chronik-lib`
Parents
rABCc5ee973305d6: [Cashtab] Remove console.log statement
Branches
Unknown
Tags
Unknown