Skip to content

Save wallet DB after adding or removing payment requests#6435

Merged
SomberNight merged 1 commit intospesmilo:masterfrom
johnzweng:add-savedb
Sep 1, 2020
Merged

Save wallet DB after adding or removing payment requests#6435
SomberNight merged 1 commit intospesmilo:masterfrom
johnzweng:add-savedb

Conversation

@johnzweng
Copy link
Contributor

@johnzweng johnzweng commented Jul 23, 2020

Description

When using the add_request command I realized that the returned address will be reused in the next payment request after I restart my electrum daemon (if no other operation which saves the walletDB has been performed in the meantime).

It seems that the add_request, add_lightning_request and rmrequest commands change the wallet DB (by adding or removing payment requests), but do not flush the changes down to the disk.

If any other operation later on changes the wallet DB, then the changes of the 3 commands will also be flushed. If not, then the changes (payment requests) might get lost.

(clear_requests is not affected as self.save_db() is called in wallet.py in clear_requests(self).)

This PR:

  • adds wallet.save_db() to RPC commands which change the Wallet DB but didn't save them

@SomberNight
Copy link
Member

This looks okay. I am just wondering whether this is the right place to call wallet.save_db() in general; maybe it should be done by the callee not the caller. That would involve a larger change though probably.

@SomberNight SomberNight merged commit 2c7da6a into spesmilo:master Sep 1, 2020
@SomberNight SomberNight added topic-invoice-payreq invoices and payment requests topic-walletstorage 💾 not wallet itself but storage/db-related labels Jul 5, 2021
SomberNight added a commit that referenced this pull request Jul 5, 2021
Fixes: after adding a payment request, if the process was killed,
the payreq might get lost. In case of using the GUI, neither the
callee nor the caller called wallet.save_db().

Unclear where wallet.save_db() should be called...
Now each method tries to persist their changes by default,
but as an optimisation, the caller can pass write_to_disk=False
e.g. when calling multiple such methods and then call wallet.save_db() itself.

If we had partial writes, which would either rm the need for wallet.save_db()
or at least make it cheaper, this code might get simpler...

related: #6435
related: #4823
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLI/RPC ▶ topic-invoice-payreq invoices and payment requests topic-walletstorage 💾 not wallet itself but storage/db-related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants