Page MenuHomePhabricator

[Chronik] Add `MempoolGroupUtxos` to store mempool UTXOs by group
ClosedPublic

Authored by tobias_ruck on Apr 23 2023, 20:11.

Details

Summary

To return to a user the UTXOs of an address, we also need to index the UTXOs in the mempool.

MempoolGroupUtxos stores all the UTXOs created in the mempool by group.

Note that it doesn't store which UTXOs have been destroyed in the mempool. This is because we already have this info in MempoolSpentBy.

We can query all the UTXOs of the DB using GroupUtxoReader, then remove all the UTXOs spent in the mempool using MempoolSpentBy, and add all the created UTXOs in the mempool using MempoolGroupUtxos.

In the NNG Chronik, we stored this data redundantly; but this actually only increases complexity so we don't do this here.

Depends on D13759.

Test Plan

ninja check-crates

Diff Detail

Repository
rABC Bitcoin ABC
Branch
chronik-utxos-mempool
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 23454
Build 46527: Build Diffbuild-chronik
Build 46526: arc lint + arc unit

Event Timeline

Fabien requested changes to this revision.Apr 25 2023, 08:58
Fabien added inline comments.
chronik/chronik-db/src/mem/group_utxos.rs
153 ↗(On Diff #39866)

This logic is duplicated in both add and remove and should better be a function. It would be easy to forget e.g. to remove the entry when it's empty in 1 case but not the other, and factoring the code will make it more robust against this class of issues.

Example: in this call, there is no unwrap(): self.utxos.remove(member_ser.as_ref()).unwrap();

This revision now requires changes to proceed.Apr 25 2023, 08:58
Fabien requested changes to this revision.Apr 25 2023, 15:09

IMO you'd better wrap the removal and the cleanup together. Just return an error if the outpoint doesn't exist and ignore that error for the remove_mined case. So each time you remove an outpoint, you don't need to remember to call the cleanup method

This revision now requires changes to proceed.Apr 25 2023, 15:09
Fabien added inline comments.
chronik/chronik-db/src/mem/group_utxos.rs
181 ↗(On Diff #39933)

Nit

This revision is now accepted and ready to land.Apr 25 2023, 16:11
This revision was landed with ongoing or failed builds.Apr 25 2023, 16:14
This revision was automatically updated to reflect the committed changes.