Description
Just recapping the idea in this bounty https://bounties.monero.social/posts/10/implement-background-wallet-sync-via-view-keys-on-monerujo (also discussed in m2049r/xmrwallet#785)
The idea I'm proposing is to add a background-sync-cache that is separate from the main wallet cache, encrypted with its own secret key, and used to perform refreshes with the wallet viewkey while the main wallet is idle/off. The point is to allow the wallet to stay sync'd with the blockchain without leaving the private spendkey exposed or leaving the main wallet cache in decrypted state.
When the user returns to active use of the wallet and enters their passphrase to unlock/decrypt the main wallet cache, it can then suck in whatever transaction info was recorded in the background-sync-cache, thus avoiding having to wait for a refresh in realtime.
I haven't looked in detail at the wallet cache format recently but I suggest the background-sync-cache file should be written incrementally in append-only fashion, with each transaction record encrypted independently, and in a length-prefixed binary format. This way the refresher doesn't need to constantly re-read and re-encrypt the existing data before writing new records to the file.
The basic functionality to enable periodic background refreshing should be built into libwallet, with hooks to allow the frontend to turn it on and off (e.g. for a smartphone connecting/disconnecting wifi, etc.), set poll interval, etc.