HomePhabricator

[Chronik] Add `UtxoData` and `UtxoProtobuf` to allow storing UTXOs' scripts in…

Description

[Chronik] Add UtxoData and UtxoProtobuf to allow storing UTXOs' scripts in the DB

Summary:
Currently GroupUtxoWriter is really only usable for groups where that group by script, as it doesn't store the script of the UTXO in the DB.

For ScriptGroup this is great, as storing the script in the UTXO would be redundant, but for other groups, e.g. those grouping by token ID, it really is important to have easy access to the script so we can return it.

We solve this by making UtxoEntry take a generic parameter for the UTXO data, which will be stored in the DB. This comes from the UtxoData trait. It doesn't change the existing data in the DB, so no schema version upgrade is neessary.

Note: It would be possible to instead of storing the script in the UTXO, to not store anything about the UTXO in the DB and to rely on lookup_spent_coins instead to re-use the node's data.

However:

  1. This would require a similar change anyway except with a UtxoData impl for () that doesn't store anything.
  2. It would then require us to lookup the coins in QueryGroupUtxos, but due to the validation interface queue they aren't guaranteed to be there if they are in the Chronik DB.
  3. Non-script groups right now would only index a small percentage of txs (e.g. token tx, plugins), so the redundancy of storing the UTXO in the group should be fine for now.

Depends on D15382.

Test Plan: ninja check-functional

Reviewers: Fabien, #bitcoin_abc

Reviewed By: Fabien, #bitcoin_abc

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

Details

Provenance
tobias_ruckAuthored on Feb 5 2024, 11:03
tobias_ruckPushed on Feb 12 2024, 12:15
Reviewer
Restricted Project
Differential Revision
D15383: [Chronik] Add `UtxoData` and `UtxoProtobuf` to allow storing UTXOs' scripts in the DB
Parents
rABCcbb985aad3ee: make chronik-client_blocktxs_and_tx_and_rawtx work even when the wallet is not…
Branches
Unknown
Tags
Unknown