lnworker: differentiate PaymentInfo by direction

Allows storing two different payment info of the same payment hash by
including the direction into the db key.
We create and store PaymentInfo for sending attempts and for requests (receiving),
if we try to pay ourself (e.g. through a channel rebalance) the checks
in `save_payment_info` would prevent this and throw an exception.
By storing the PaymentInfos of outgoing and incoming payments separately in
the db this collision is avoided and it makes it easier to reason about
which PaymentInfo belongs where.
This commit is contained in:
f321x
2025-11-28 16:22:22 +01:00
parent 828fc569c9
commit 923d48f9db
12 changed files with 125 additions and 88 deletions
+20 -1
View File
@@ -69,7 +69,7 @@ class WalletUnfinished(WalletFileException):
# seed_version is now used for the version of the wallet file
OLD_SEED_VERSION = 4 # electrum versions < 2.0
NEW_SEED_VERSION = 11 # electrum versions >= 2.0
FINAL_SEED_VERSION = 63 # electrum >= 2.7 will set this to prevent
FINAL_SEED_VERSION = 64 # electrum >= 2.7 will set this to prevent
# old versions from overwriting new format
@@ -235,6 +235,7 @@ class WalletDBUpgrader(Logger):
self._convert_version_61()
self._convert_version_62()
self._convert_version_63()
self._convert_version_64()
self.put('seed_version', FINAL_SEED_VERSION) # just to be sure
def _convert_wallet_type(self):
@@ -1269,6 +1270,24 @@ class WalletDBUpgrader(Logger):
self.data['seed_version'] = 63
def _convert_version_64(self):
"""Key payment_info by "rhash:direction" instead of just rhash to allow storing a PaymentInfo
for each direction"""
if not self._is_upgrade_method_needed(63, 63):
return
new_payment_infos = {}
old_payment_infos = self.data.get('lightning_payments', {})
for payment_hash, old_values in old_payment_infos.items():
amount_msat, direction, status, min_final_cltv_expiry, expiry, creation_ts = old_values
# drop direction
new_values = (amount_msat, status, min_final_cltv_expiry, expiry, creation_ts)
new_key = f"{payment_hash}:{direction}"
new_payment_infos[new_key] = new_values # save new entry
self.data['lightning_payments'] = new_payment_infos
self.data['seed_version'] = 64
def _convert_imported(self):
if not self._is_upgrade_method_needed(0, 13):
return