librustzcash icon indicating copy to clipboard operation
librustzcash copied to clipboard

`sqlite_crate`: Unify cache_db and wallet_db

Open pacu opened this issue 3 years ago • 0 comments

Problem: Shared custody of the DB files between light clients' native environment (kotlin/swift) has been problematic. The access to the databases must be orchestrated perfectly in order to avoid database locked and similar errors from SQLite. see https://github.com/zcash/zcash-android-wallet-sdk/issues/344

Also "shared custody" of database files means that SQLite WAL mode can't be used. Which limits concurrency and performance.

Proposal:

  • cache_db ceases to exist or there's support for clients to actually pass the same file as wallet_db
  • shared custody of cache_db should be no longer needed.
  • APIs are provided to know:
    • latest downloaded blockheight
    • validate cached Blocks
    • rewind
    • save a compactblock or a range.

This API shouldn't no longer be needed to be implemented in the SDK and should be provided through data access api FFI instead

protocol CompactBlockDAO {
    func createTable() throws
    
    func insert(_ block: ZcashCompactBlock) throws
    
    func insert(_ blocks: [ZcashCompactBlock]) throws
    
    /**
    Query the latest block height, returns -1 if no block is stored
    */
    func latestBlockHeight() throws -> BlockHeight
    
    func rewind(to height: BlockHeight) throws
}

pacu avatar Jan 07 '22 21:01 pacu