From cee22abcb5544c5a6fa7f8a8108ccda9c32c2e29 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Thu, 17 Aug 2023 14:04:05 +0000 Subject: [PATCH] wallet_db: upgrade to version 53, for imported chan backups follow-up https://github.com/spesmilo/electrum/pull/8536 This replaces 69336befee959992da811774465f1d49f35f3f42, which was insufficient. #8536 added a new field into the struct, which older versions do not ignore but raise: opening a wallet file with new code updated the struct to include it, after which old code could no longer open the wallet file. i.e. #8536 was an invisible wallet upgrade, breaking compat. This commit simply formalises the wallet upgrade: old code will now show an understandable error when trying to open new files. --- electrum/lnutil.py | 2 +- electrum/wallet_db.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/electrum/lnutil.py b/electrum/lnutil.py index e5fe62009..c7fb8a7a5 100644 --- a/electrum/lnutil.py +++ b/electrum/lnutil.py @@ -285,7 +285,7 @@ class ImportedChannelBackupStorage(ChannelBackupStorage): remote_delay = attr.ib(type=int, converter=int) remote_payment_pubkey = attr.ib(type=bytes, converter=hex_to_bytes) remote_revocation_pubkey = attr.ib(type=bytes, converter=hex_to_bytes) - local_payment_pubkey = attr.ib(type=bytes, converter=hex_to_bytes, default=None) # type: Optional[bytes] + local_payment_pubkey = attr.ib(type=bytes, converter=hex_to_bytes) # type: Optional[bytes] def to_bytes(self) -> bytes: vds = BCDataStream() diff --git a/electrum/wallet_db.py b/electrum/wallet_db.py index 6ef2fe341..31700c3e1 100644 --- a/electrum/wallet_db.py +++ b/electrum/wallet_db.py @@ -54,7 +54,7 @@ from .version import ELECTRUM_VERSION OLD_SEED_VERSION = 4 # electrum versions < 2.0 NEW_SEED_VERSION = 11 # electrum versions >= 2.0 -FINAL_SEED_VERSION = 52 # electrum >= 2.7 will set this to prevent +FINAL_SEED_VERSION = 53 # electrum >= 2.7 will set this to prevent # old versions from overwriting new format @@ -238,6 +238,7 @@ class WalletDB(JsonDB): self._convert_version_50() self._convert_version_51() self._convert_version_52() + self._convert_version_53() self.put('seed_version', FINAL_SEED_VERSION) # just to be sure self._after_upgrade_tasks() @@ -1066,6 +1067,15 @@ class WalletDB(JsonDB): raise Exception(f'unsupported wallet file: version_51 with error {error_code}') self.data['seed_version'] = 52 + def _convert_version_53(self): + if not self._is_upgrade_method_needed(52, 52): + return + cbs = self.data.get('imported_channel_backups', {}) + for channel_id, cb in list(cbs.items()): + if 'local_payment_pubkey' not in cb: + cb['local_payment_pubkey'] = None + self.data['seed_version'] = 53 + def _convert_imported(self): if not self._is_upgrade_method_needed(0, 13): return