From 1a562fb2088f66b741f5ebddba5803cfa618a927 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 23 Jul 2024 16:45:46 +0000 Subject: [PATCH] zcash_client_sqlite: Fix bug in `utxos_to_txos` migration zcash/librustzcash@72d8df8e68c2180f06a0efe7a6ebf737b511e44d 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. --- zcash_client_sqlite/src/wallet/db.rs | 2 +- zcash_client_sqlite/src/wallet/init/migrations/utxos_to_txos.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zcash_client_sqlite/src/wallet/db.rs b/zcash_client_sqlite/src/wallet/db.rs index 65ce3b148..b57079041 100644 --- a/zcash_client_sqlite/src/wallet/db.rs +++ b/zcash_client_sqlite/src/wallet/db.rs @@ -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. diff --git a/zcash_client_sqlite/src/wallet/init/migrations/utxos_to_txos.rs b/zcash_client_sqlite/src/wallet/init/migrations/utxos_to_txos.rs index b1ccbbd7f..33ffbd1b8 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/utxos_to_txos.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/utxos_to_txos.rs @@ -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.