zcash / librustzcash

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

Don't create new `WalletDb` wrappers outside `WalletDb::transactionally`: take `&mut WalletDb<SqlTransaction<'_>, P>` as argument instead #1435

Open daira opened 6 days ago

daira commented 6 days ago

I wrote at https://github.com/zcash/librustzcash/pull/1402#discussion_r1651118779_ :


Aside: I don't understand why we're creating a new WalletDb wrapper when we could instead pass in wdb: &mut WalletDb<SqlTransaction<'_>, P>.

If I understand correctly, the point of the SqlTransaction wrapper is to mark that it was constructed by WalletDb::transactionally. This does several useful things:

Here we don't call commit() in zcash_client_sqlite::wallet::truncate_to_height, which is correct because we take a rusqlite::Transaction as argument, but that means:

Please let's refactor (not in this PR) so that we never need to explicitly create a WalletDb wrapper like this outside WalletDb::transactionally.

daira commented 6 days ago

@nuttycom wrote:

SqlTransaction was added to the codebase much later on, to deal with some problems around how to implement the WalletCommitmentTrees trait. I can't recall all the problems that I ran into, but I remember spending several days and multiple pairings with @str4d figuring out an approach that could work here; there's some problem if the connection type is the same in WalletWrite as in WalletCommitmentTrees.