zcash / librustzcash

Rust-language assets for Zcash
Other
324 stars 243 forks source link

`zcash_client_sqlite`: Double-entry accounting not working for recover-from-seed #899

Open str4d opened 10 months ago

str4d commented 10 months ago

I have a mainnet wallet in which I have a bunch of transactions, generating a bunch of change, back when we didn't have internal viewing keys. I recovered from seed to set up a new instance of a mobile wallet, and then made a transaction. My balance went up by the value of the change output, instead of decreasing by the value of the sent amount.

Looking at the SQLite database, I see that my sent_notes table contains an output for the new recipient, and the new change note (that my balance increased by), but does not contain any entries for the old change notes (violating the double-entry accounting assumptions now baked into zcash_client_sqlite).

nuttycom commented 10 months ago

After a brief look over the code, I think what's happening is that the change notes that were created under the old rules where the note was sent back to the sending address are not correctly being added to the received_notes table in the same fashion as are notes that are now sent to the account's internal change address.

daira commented 10 months ago

Looking at the SQLite database, I see that my sent_notes table contains an output for the new recipient, and the new change note (that my balance increased by), but does not contain any entries for the old change notes (violating the double-entry accounting assumptions now baked into zcash_client_sqlite).

I can reproduce the absence of entries in sent_notes for notes sent prior to the wallet recovery, but I cannot reproduce the incorrect balance symptom. It's possible that the CLI wallet is doing something unusual (or that the behaviour of zcash_client_sqlite at the base of #908 is different than the revision you were testing with).

nuttycom commented 3 months ago

This may now be fixed by #1306