Replace get_key_for_outgoing_invoice, get_key_for_incoming_request
with Invoice.get_id()
When a new request is created, reuse addresses of expired requests (fixes#7927)
The API is changed for the following commands:
get_request, get_invoice,
list_requests, list_invoices,
delete_request, delete_invoice
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
There is no point in adding new hww types to these lists every time support for a new hww is added.
These upgrades got released in 2.7.0 and any hw types added after are unrelated.
reverted to just-after last relevant change:
c820423b00
Change convert_version_25 to delete invoices instead of converting them.
convert_version_25 was released ~2 years ago. Wallet files not opened since will have old bip70 invoices deleted upon upgrading.
In general it is ~unsafe for convert_version_* to depend on other modules of the code.
(using e.g. sha256 is fine as its API will never change,
but using e.g. PaymentRequest is dangerous as its API might change over time)
I still have a mainnet wallet with some pre-static-remotekey channels
(though those channels are closed) that I do not want to delete yet.
follow-up https://github.com/spesmilo/electrum/pull/7636
```
E | gui.qt.exception_window.Exception_Hook | exception caught by crash reporter
Traceback (most recent call last):
File "...\electrum\electrum\gui\qt\__init__.py", line 307, in wrapper
return func(self, *args, **kwargs)
File "...\electrum\electrum\gui\qt\__init__.py", line 332, in start_new_window
wallet = self._start_wizard_to_select_or_create_wallet(path)
File "...\electrum\electrum\gui\qt\__init__.py", line 377, in _start_wizard_to_select_or_create_wallet
db = WalletDB(storage.read(), manual_upgrades=False)
File "...\electrum\electrum\wallet_db.py", line 73, in __init__
self.load_data(raw)
File "...\electrum\electrum\wallet_db.py", line 106, in load_data
self.upgrade()
File "...\electrum\electrum\util.py", line 439, in <lambda>
return lambda *args, **kw_args: do_profile(args, kw_args)
File "...\electrum\electrum\util.py", line 435, in do_profile
o = func(*args, **kw_args)
File "...\electrum\electrum\wallet_db.py", line 195, in upgrade
self._convert_version_44()
File "...\electrum\electrum\wallet_db.py", line 859, in _convert_version_44
if item['static_remotekey_enabled']:
KeyError: 'static_remotekey_enabled'
```
This is a regression from 64a931f21e,
which introduced "onchain_channel_backups", and renamed
the old "channel_backups" key to "imported_channel_backups".
The `save_backup` method was not changed to use the new "imported_channel_backups" key,
so the channel backups are in the backup file but they are ignored.
- use_recoverable_channel is a user setting, available
only in standard wallets with a 'segwit' seed_type
- if enabled, 'lightning_xprv' is derived from seed
- otherwise, wallets use the existing 'lightning_privkey2'
Recoverable channels:
- channel recovery data is added funding tx using an OP_RETURN
- recovery data = 4 magic bytes + node id[0:16]
- recovery data is chacha20 encrypted using funding_address as nonce.
(this will allow to fund multiple channels in the same tx)
GUI:
- whether channels are recoverable is shown in wallet info dialog.
- if the wallet can have recoverable channels but has an old node_id,
users are told to close their channels and restore from seed
to have that feature.
bump_fee was returning an invalid tx if its input was a
PartialTransaction that had signatures. It was relying on
line 1441 to remove signatures.
Relatedly, the WalletDB used to store such PartialTransactions as
PartialTransaction objects, but only until the program was restarted.
This is because serialising and de-serialising such a tx results in a
Transaction object.
So, combining these two, to reproduce a bug:
- create a tx, sign it, save as local
- bump fee, sign it, save as local
- bump fee --> tx already signed!? --> has old sigs, so it is invalid
The standard json module has an optimized C encoder, but that doesn't
currently support indentation. So if you request indentation, it falls
back on the slower Python encoder.
Readability doesn't matter for encrypted wallets, so this disables
indentation when the wallet is encrypted.
-----
based on b2399b6a3e
For a large encrypted wallet, compare:
before change:
JsonDB.dump 1.3153 sec
zlib.compress 1.281 sec
ECPubkey.encrypt_message 0.1744 sec
after change:
JsonDB.dump 0.5059 sec
zlib.compress 1.3120 sec
ECPubkey.encrypt_message 0.1630 sec
Co-authored-by: SomberNight <somber.night@protonmail.com>
The 'height' field was added in cdfaaa2609
At the time we thought we could just add it with a default value without a db upgrade;
however the issue is that if old code tries to open a new db, it will fail (due to unexpected new field).
Hence it is better to do an explicit conversion where old code *knows* it cannot open the new db.
E | gui.qt.ElectrumGui |
Traceback (most recent call last):
File "...\electrum\electrum\gui\qt\__init__.py", line 257, in start_new_window
wallet = self.daemon.load_wallet(path, None)
File "...\electrum\electrum\daemon.py", line 488, in load_wallet
db = WalletDB(storage.read(), manual_upgrades=manual_upgrades)
File "...\electrum\electrum\wallet_db.py", line 72, in __init__
self.load_data(raw)
File "...\electrum\electrum\wallet_db.py", line 103, in load_data
self._after_upgrade_tasks()
File "...\electrum\electrum\wallet_db.py", line 189, in _after_upgrade_tasks
self._load_transactions()
File "...\electrum\electrum\util.py", line 408, in <lambda>
return lambda *args, **kw_args: do_profile(args, kw_args)
File "...\electrum\electrum\util.py", line 404, in do_profile
o = func(*args, **kw_args)
File "...\electrum\electrum\wallet_db.py", line 1139, in _load_transactions
self.data = StoredDict(self.data, self, [])
File "...\electrum\electrum\json_db.py", line 79, in __init__
self.__setitem__(k, v)
File "...\electrum\electrum\json_db.py", line 44, in wrapper
return func(self, *args, **kwargs)
File "...\electrum\electrum\json_db.py", line 105, in __setitem__
v = self.db._convert_dict(self.path, key, v)
File "...\electrum\electrum\wallet_db.py", line 1182, in _convert_dict
v = dict((k, Invoice.from_json(x)) for k, x in v.items())
File "...\electrum\electrum\wallet_db.py", line 1182, in <genexpr>
v = dict((k, Invoice.from_json(x)) for k, x in v.items())
File "...\electrum\electrum\invoices.py", line 108, in from_json
return OnchainInvoice(**x)
TypeError: __init__() got an unexpected keyword argument 'height'
The keystore logic would need to be significantly changed to nicely
interoperate with StoredDict/json_db logic.
(just see KeyStore.__init__() and KeyStore.dump())
For now we exempt the keystore from the recursive StoredDict conversion, as
it is a smaller change that is also easier to review for correctness.
fixes#6066fixes#6401
also reverts 2d3c2eeea9 (which was an even hackier workaround for #6066)
(which is the logical thing to do, as it too will be rebuilt as part of
the history, and the parts of it that might not be present after the
rebuild is exactly what a call to "clear_history" is supposed to get rid of)
Traceback (most recent call last):
File "...\electrum\electrum\gui\qt\main_window.py", line 1503, in do_pay
self.do_pay_invoice(invoice)
File "...\electrum\electrum\gui\qt\main_window.py", line 1516, in do_pay_invoice
self.pay_onchain_dialog(self.get_coins(), outputs)
File "...\electrum\electrum\gui\qt\main_window.py", line 1570, in pay_onchain_dialog
self.preview_tx_dialog(make_tx=make_tx,
File "...\electrum\electrum\gui\qt\main_window.py", line 1574, in preview_tx_dialog
d = PreviewTxDialog(make_tx=make_tx, external_keypairs=external_keypairs,
File "...\electrum\electrum\gui\qt\transaction_dialog.py", line 654, in __init__
self.update()
File "...\electrum\electrum\gui\qt\transaction_dialog.py", line 392, in update
tx_details = self.wallet.get_tx_info(self.tx)
File "...\electrum\electrum\wallet.py", line 486, in get_tx_info
tx_we_already_have_in_db = self.db.get_transaction(tx_hash)
File "...\electrum\electrum\json_db.py", line 44, in wrapper
return func(self, *args, **kwargs)
File "...\electrum\electrum\wallet_db.py", line 822, in get_transaction
assert isinstance(tx_hash, str)
AssertionError
Traceback (most recent call last):
File "...\electrum\electrum\gui\qt\confirm_tx_dialog.py", line 65, in timer_actions
self.update()
File "...\electrum\electrum\gui\qt\transaction_dialog.py", line 392, in update
tx_details = self.wallet.get_tx_info(self.tx)
File "...\electrum\electrum\wallet.py", line 486, in get_tx_info
tx_we_already_have_in_db = self.db.get_transaction(tx_hash)
File "...\electrum\electrum\json_db.py", line 44, in wrapper
return func(self, *args, **kwargs)
File "...\electrum\electrum\wallet_db.py", line 822, in get_transaction
if tx_hash is None:
AssertionError