Index lightning requests with rhash instead of onchain address.
get_unused_addresses() has been broken since #7730, because
addresses are considered as permanently used if they are in
the list of keys of receive_requests. This is true even if
an address is used as fallback for a lightning payment. This
means that the number of lightning payments we can receive
is constrained by the gap limit.
If a payment succeeds off-chain, we want to be able to reuse
its fallback address in other requests (this does not reduce
privacy, because invoices already share the same public key).
This implies that we should not use the onchain address as key
for lightning-enabled requests in wallet.receive_requests. If
we did, paid invoices would be overwritten when the address is
reused. That is the reason for the wallet_db upgrade.
Related: a3faf85e3c
This commit is contained in:
@@ -52,7 +52,7 @@ if TYPE_CHECKING:
|
||||
|
||||
OLD_SEED_VERSION = 4 # electrum versions < 2.0
|
||||
NEW_SEED_VERSION = 11 # electrum versions >= 2.0
|
||||
FINAL_SEED_VERSION = 46 # electrum >= 2.7 will set this to prevent
|
||||
FINAL_SEED_VERSION = 47 # electrum >= 2.7 will set this to prevent
|
||||
# old versions from overwriting new format
|
||||
|
||||
|
||||
@@ -195,6 +195,7 @@ class WalletDB(JsonDB):
|
||||
self._convert_version_44()
|
||||
self._convert_version_45()
|
||||
self._convert_version_46()
|
||||
self._convert_version_47()
|
||||
self.put('seed_version', FINAL_SEED_VERSION) # just to be sure
|
||||
|
||||
self._after_upgrade_tasks()
|
||||
@@ -925,6 +926,22 @@ class WalletDB(JsonDB):
|
||||
del invoices[key]
|
||||
self.data['seed_version'] = 46
|
||||
|
||||
def _convert_version_47(self):
|
||||
from .lnaddr import lndecode
|
||||
if not self._is_upgrade_method_needed(46, 46):
|
||||
return
|
||||
# recalc keys of requests
|
||||
requests = self.data.get('payment_requests', {})
|
||||
for key, item in list(requests.items()):
|
||||
lnaddr = item.get('lightning_invoice')
|
||||
if lnaddr:
|
||||
lnaddr = lndecode(lnaddr)
|
||||
rhash = lnaddr.paymenthash.hex()
|
||||
if key != rhash:
|
||||
requests[rhash] = item
|
||||
del requests[key]
|
||||
self.data['seed_version'] = 47
|
||||
|
||||
def _convert_imported(self):
|
||||
if not self._is_upgrade_method_needed(0, 13):
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user