librustzcash
librustzcash copied to clipboard
`zcash_client_sqlite`: Add migration to link `utxo` table to `transactions`
Currently the utxo table has columns for storing the transaction ID, and the mined block height. These are almost always duplicative of entries in the transaction table, and having them stored separately inhibits other possible relational queries.
We should implement a migration to:
- Add a
txforeign key column. - Migrate existing
utxoentries to reference matchingtransactionsentries. - For those
utxoentries that do not have matches, fetch the corresponding transactions fromlightwalletdto populate the remainingtransactionsentries that the wallet assumes are populated during scanning.
The division of this work between the database migration and the network fetching might affect internals, but at a high level the migration API provided to zcash_client_sqlite users should hopefully be straightforward in the instructions it gives them.
We discovered that is more challenging than we thought, because if we set the block height of the transactions entry, this requires an entry in the blocks table and we'd need at least the block hash to create such an entry; in addition, we now have the property "every entry in the blocks table corresponds to a block that we have scanned" so supporting this database refactoring will likely require other kinds of changes.
This was partially closed by #1402. We added the migrations, but did not add logic to fetch extra data for the previously-missing transactions table rows, as it turned out the tables seem to work fine with just what we knew from the utxo table. We still need to fetch that data though, so leaving this issue open until we either do that, or move the remaining work into a new issue (which we might already have done without noticing, but it's a weekend so I'm not checking).
This was completed by #1402, #1493, #1476