Skip to content

Commit

Permalink
zcash_client_sqlite: Fix bug in utxos_to_txos migration
Browse files Browse the repository at this point in the history
72d8df8 altered the
`v_received_notes` view to include transparent coins (renaming it to
`v_received_outputs`), and updated `v_transactions` to not separately
query transparent coins. The latter queried `v_received_notes` twice,
once to fetch notes received in a transaction, and again to fetch notes
spent in a transaction. The spent notes were obtained by joining on
the junction table `v_received_note_spends` to get the spent-in
transaction's ID. The commit retained the junction table join, but
didn't use it due to a typo, leading to notes being "spent-in" the
transaction they were received in. This bug had several effects:

- `account_balance_delta` showed `+change` for transactions in which a
  change note was received that had not yet been spent.
- `account_balance_delta` showed `0` for transactions in which all
  received notes had been subsequently spent.
- Transactions that spent funds with no change were omitted.
  • Loading branch information
str4d committed Jul 23, 2024
1 parent e29622e commit 1a562fb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion zcash_client_sqlite/src/wallet/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ notes AS (
ON ros.pool = ro.pool
AND ros.received_output_id = ro.id_within_pool_table
JOIN transactions
ON transactions.id_tx = ro.transaction_id
ON transactions.id_tx = ros.transaction_id
),
-- Obtain a count of the notes that the wallet created in each transaction,
-- not counting change notes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl RusqliteMigration for Migration {
ON ros.pool = ro.pool
AND ros.received_output_id = ro.id_within_pool_table
JOIN transactions
ON transactions.id_tx = ro.transaction_id
ON transactions.id_tx = ros.transaction_id
),
-- Obtain a count of the notes that the wallet created in each transaction,
-- not counting change notes.
Expand Down

0 comments on commit 1a562fb

Please sign in to comment.