Page MenuHomePhabricator

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

Authored by tobias_ruck on Feb 5 2024, 11:04.

Details

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

Diff Detail

Repository
rABC Bitcoin ABC
Branch
chronik-group-utxo-data
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 26921
Build 53409: Build Diffbuild-chronik · chronik-client-integration-tests · build-chronik-plugins
Build 53408: arc lint + arc unit

Event Timeline

Fabien added inline comments.
chronik/chronik-indexer/src/query/group_utxos.rs
54

That's not a very explanatory name but I can't find a good one so let's go with that for now

This revision is now accepted and ready to land.Feb 12 2024, 11:08
chronik/chronik-indexer/src/query/group_utxos.rs
54

I was trying to find one for a long time; UtxoData came to mind but that's already taken

chronik/chronik-indexer/src/query/group_utxos.rs
54

also it's literally only used in the following 60 lines, so the name isn't very important