[Chronik] Shut down node after errors in merge operators gracefully
Summary:
Currently, when the merge operator full_merge_concat_trim failes, it panics. However, this may cause issues with corrupting the db or even the node.
Therefore, instead of panicing, we log the error message, turn the failed merge into a no-op, store the error in a static global, and handle errors as soon as they arrive (after calling write_batch). See chronik-db/src/io/merge.rs for a rationale and explored alternatives. Note that alternative DB methods (such as using TransactionDB etc.) have been explored, but the behavior is identical to the methods used in Chronik already.
Directly using log! in chronik-db, however, causes linker issues when running cargo test: When chronik-indexer tests are compiled, the dependency chronik-db is *not* compiled with cfg(test) on, because it's a dependency. Therefore, it will compile with the LogPrint function from the node, which in undefined during cargo test.
To avoid this, we set logging functions externally (during setup_chronik) to a OnceLock (static field that can only be set once), which are left to println! during cargo test.
Test Plan: ninja check-crates
Reviewers: Fabien, #bitcoin_abc
Reviewed By: Fabien, #bitcoin_abc
Differential Revision: https://reviews.bitcoinabc.org/D14408