Commit Graph

758 Commits

Author SHA1 Message Date
Sander van Grieken
7b96a83350 wallet: add sighash check to class Abstract_Wallet
qml: use backend sighash check and add user confirmation path
qt: use backend sighash check and add user confirmation path
qml: include get_warning_for_risk_of_burning_coins_as_fees test in txdetails
qt: add warning icon to sighash warning
add sighash and fee checks to wallet.sign_transaction, making all warnings fatal unless ignore_warnings is set to True
tests: test sign_transaction on both code paths with ignore_warnings True and False,
raise specific exceptions TransactionPotentiallyDangerousException and TransactionDangerousException
2023-11-30 12:53:46 +01:00
Sander van Grieken
6efd1fc768 followup prev 2023-11-27 14:49:20 +01:00
Sander van Grieken
c16b83f46a tests: add test verifying if privkey add to existing imported wallet persists correctly. 2023-11-27 14:45:40 +01:00
SomberNight
7f64ecc4bd wallet.bump_fee: the glorious return of BumpFeeStrategy :D
gui/qt/rbf_dialog.py (old) lines 57-64 were implementing logic that should not be part of GUI code.
Case in point, gui/qml/qetxfinalizer.py (old) lines 511-513 duplicated half of that logic but not the other half.
That logic is now moved to wallet.get_bumpfee_strategies_for_tx().

More context: a user on irc got confused when using the qml gui. They were sending "max" and wanted to bump_fee.
The qml gui selected the "preserve_payment" strategy by default, using which there was no solution, and the user
did not notice that the strategy can be altered (via the "method" dropdown). The qt gui had logic to select
"decrease_payment" by default in such a case (which does find a solution to bump) but this logic was not
duplicated in the qml gui.
Instead of duplicating the logic, this commit moves it to shared lib code.
2023-11-20 18:55:43 +00:00
ThomasV
1cc92d4890 trampoline forwarding: before failing payment, wait until all htcs
have failed and session is not longer active.
2023-11-18 16:08:11 +01:00
ThomasV
9b1c40e396 Refactor payment forwarding:
- all forwarding types use the same flow
 - forwarding callback returns a htlc_key or None
 - forwarding info is persisted in lnworker:
   - ongoing_forwardings
   - downstream to upstream htlc_key
   - htlc_key -> error_bytes
2023-11-18 16:03:18 +01:00
SomberNight
f1c63e2d51 commands: make payto/etc respect 'confirmed_only' config var
regression from 2f6d60c715

fixes https://github.com/spesmilo/electrum/issues/8693
2023-11-17 13:05:23 +00:00
ThomasV
a338459d45 just-in-time channels:
- a node scid alias is derived from the node ID
 - the channel opening fee is sent in a TLV field of open_channel
 - the server requires htlc settlement before broadcasting
   (server does not trust client)
2023-11-13 10:47:18 +01:00
SomberNight
511674a532 contacts: fix adding new contacts
This is a regression from 7ca89f56ee, which introduced StoredList.
The newly added test was failing without the change.

```
Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/gui/qt/main_window.py", line 1786, in new_contact_dialog
    self.set_contact(line2.text(), line1.text())
  File "/home/user/wspace/electrum/electrum/gui/qt/main_window.py", line 1435, in set_contact
    self.contacts[address] = ('address', label)
  File "/home/user/wspace/electrum/electrum/contacts.py", line 75, in __setitem__
    self.save()
  File "/home/user/wspace/electrum/electrum/contacts.py", line 62, in save
    self.db.put('contacts', dict(self))
  File "/home/user/wspace/electrum/electrum/json_db.py", line 42, in wrapper
    return func(self, *args, **kwargs)
  File "/home/user/wspace/electrum/electrum/json_db.py", line 318, in put
    self.data[key] = copy.deepcopy(value)
  File "/usr/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.10/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.10/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib/python3.10/copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.10/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.10/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib/python3.10/copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.10/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.10/copy.py", line 161, in deepcopy
    rv = reductor(4)
TypeError: cannot pickle '_thread.RLock' object
```
2023-11-01 17:28:29 +00:00
SomberNight
da8e6c2fbf wallet: check that multisig wallet does not have duplicate masterkeys
The wizard should technically disallows this at creation time,
but this second layer sanity check could not hurt.
Also, looks like the wizard check is not working properly atm
(regression from qt wizard refactor).
2023-10-30 17:22:08 +00:00
SomberNight
6506abf583 lnworker: use PaymentFeeBudget
- introduce PaymentFeeBudget, which contains limits for fee budget and cltv budget
  - when splitting a payment,
    - the fee budget is linearly distributed between the parts
      - this resolves a FIXME in lnrouter ("FIXME in case of MPP")
    - the cltv budget is simply copied
  - we could also add other kinds of budgets later, e.g. for the num in-flight htlcs
- resolves TODO in lnworker ("todo: compare to the fee of the actual route we found")
2023-10-27 16:01:23 +00:00
SomberNight
39ef1cd4b9 mpp_split: make SplitConfig a subclass of dict, not just a type-hint 2023-10-27 14:24:12 +00:00
ThomasV
4a6c55ef7b test_lnpeer: add more tests, combining forwarding and hold invoices 2023-10-27 16:09:56 +02:00
SomberNight
bb76b836a3 addr_sync.receive_tx_callback: rm redundant tx_hash arg 2023-10-24 16:07:30 +00:00
SomberNight
66e2c779ea Merge remote-tracking branch 'remotes/sombernight/202310_merge_duplicate_outputs'
see https://github.com/spesmilo/electrum/pull/8474
2023-10-24 14:51:51 +00:00
SomberNight
227e257444 (follow-up) wallet: add option to merge duplicate tx outputs 2023-10-24 14:41:39 +00:00
ThomasV
b0dbdfd5e4 test_lnpeer: split some tests, remove redundant test 2023-10-23 13:02:02 +02:00
ThomasV
f8781364d2 test_lnpeer:
- Refactor _run_mpp so that it takes only one set of arguments.
   Success and failure conditions are now tested by calling
   _run_mpp multiple times.

 - In test_payment_multipart with_timeout, check that the received
   failure message actually is MPP_TIMEOUT, and not a generic
   failure. Since the onion is obfuscated by the forwarding node,
   this tests that obfuscate_onion_packet and decode_onion_packet
   work as expected.
2023-10-20 11:36:50 +02:00
SomberNight
22a8348303 renames: use consistent naming of cltv delta vs cltv abs
to avoid confusing relative vs absolute cltvs
(see b0401a6386)
2023-10-19 16:40:05 +00:00
ThomasV
b645da6514 test_lnpeer: separate graph creation from run_trampoline 2023-10-19 18:32:04 +02:00
ThomasV
7ea2e68507 follow-up 4c42840c1c 2023-10-19 16:05:54 +02:00
SomberNight
04d8eec3be tests: change fake block height in test_lnpeer. 0 might hide bugs. 2023-10-18 17:09:53 +00:00
SomberNight
30c863d32c lnaddr: don't call validate_features in parser
- see comment in lnaddr.py
- Previously we used feature bit 50/51 for trampoline.
  The spec subsequently defined fbit 50/51 as option_zeroconf, which
  requires fbit 46/47 (option_scid_alias) to also be set.
  We moved the non-standard trampoline fbit to a different int.
  However, old wallets might have old invoices saved that set fbit 50/51
  for trampoline, and those would not have the dependent bit set.
  Invoices are parsed at wallet-open, so if the parser ran these checks,
  those wallets could not be opened.
- note: we could potentially also run lnaddr.validate_and_compare_features
  when saving new invoices into the wallet but this is not done here
2023-10-16 17:10:49 +00:00
ThomasV
98a4d7b60d public channels:
- send node and channel announcements.
 - store channel_flags in constraints
 - store signatures in local and remote configs
2023-10-16 13:54:16 +02:00
ThomasV
89023cc123 Remove trampoline hints from invoices
This has been deprecated for a long time, was kept only for
compatibility with old electrum clients.
2023-10-11 09:47:36 +02:00
SomberNight
57d2efc88d wallet: merge mktx and create_transaction 2023-10-10 17:45:26 +00:00
ThomasV
2f8325ca09 follow-up 455167136d (variable rename) 2023-10-09 12:31:23 +02:00
ThomasV
4e76ed6952 move INITIAL_TRAMPOLINE_FEE_LEVEL to config 2023-10-08 15:06:19 +02:00
ThomasV
4bfd3b2f46 test_lnpeer:
- do not use needs_test_with_all_chacha20_implementation,
   this is slow and not really useful here.
 - split TestPeer class in two classes, depending on the type
   of graph we use.
2023-09-26 10:44:43 +02:00
ThomasV
e206d264c8 trampoline forwarding: use routing hints
unit tests:
 - remove 'drop_dave' flag, replace it by depleted channel
 - add test for trampoline forwarding using routing hints
 - lower attempts to 2
2023-09-26 10:07:41 +02:00
ThomasV
56e80c20d7 wallet_db upgrade: do not use '/' in StoredDict keys 2023-09-23 11:05:36 +02:00
ThomasV
68159b3ef6 walletDB: replace 'manual_upgrades' parameter with 'upgrade', with opposite semantics 2023-09-22 15:02:07 +02:00
ThomasV
b5bc5ff9ed Separate WalletDB from storage upgrades.
Make sure that WalletDB.data is always a StoredDict.
Perform db upgrades in a separate class, since they
operate on a dict object.
2023-09-22 15:02:06 +02:00
ThomasV
6c4e603ff6 regtest: pass config options from regtest.py to script 2023-09-21 12:47:11 +02:00
SomberNight
4c63d8729b add sanity checks we don't sign tx including dummy addr
Somewhat a follow-up to 649ce979ab.

This adds some safety belts so we don't accidentally sign a tx that
contains a dummy address.
Specifically we check that tx does not contain output for dummy addr:
- in wallet.sign_transaction
- in network.broadcast_transaction

The second one is perhaps redundant, but I think it does not hurt.
2023-09-16 04:36:08 +00:00
SomberNight
139eb632d7 (trivial) follow-up paysession.use_two_trampolines arg change
follow-up b2053c68f1

- use_two_trampolines is already passed as arg to init
- strings in gui/messages.py should not end with a newline
2023-09-12 14:05:12 +00:00
SomberNight
6819f685d7 tests: add tests for "recv mpp confusion" bug
see https://github.com/spesmilo/electrum/security/advisories/GHSA-8r85-vp7r-hjxf
2023-09-12 13:58:57 +00:00
ThomasV
f245b347f1 Merge pull request #8609 from SomberNight/202309_getconfig_default_value
getconfig/setconfig to use configvars
2023-09-08 19:06:25 +02:00
SomberNight
8c9fec4ab8 commands: getconfig to use default values, add existence checks
- getconfig and setconfig now both check configvars for existence
- getconfig returns default values when applicable
- setconfig does not side-step type-checks for values

fixes https://github.com/spesmilo/electrum/issues/8607
closes https://github.com/spesmilo/electrum/pull/8608
2023-09-08 15:11:55 +00:00
ThomasV
136978e9d0 submarine swaps: fail received HTLCs of normal swap htlcs if
the swap is still unfunded and the refund delay has expired.
2023-09-08 16:38:08 +02:00
SomberNight
6a2806c2c5 simple_config: implement complex default values
Besides a literal value, the default can now also be a callable,
which gets called with the config and evaluated as needed, lazily.

This potentially allows e.g. the default value of one configvar to
depend on the current value of another configvar.
2023-09-07 15:30:46 +00:00
SomberNight
f29cd810e3 commands: "bumpfee" to accept either a raw tx or a txid as its 1st arg
closes https://github.com/spesmilo/electrum/issues/8603
2023-09-07 13:18:23 +00:00
SomberNight
c3562c00e6 tests: fix warnings in test_network.py
```
electrum/tests/test_network.py::TestNetwork::test_can_connect_during_backward
electrum/tests/test_network.py::TestNetwork::test_chain_false_during_binary
electrum/tests/test_network.py::TestNetwork::test_fork_conflict
electrum/tests/test_network.py::TestNetwork::test_fork_noconflict
  /tmp/cirrus-ci-build/electrum/interface.py:410: RuntimeWarning: coroutine 'Interface.run' was never awaited
    task = await self.network.taskgroup.spawn(self.run())
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.
```

closes https://github.com/spesmilo/electrum/pull/7817
2023-09-06 15:53:40 +00:00
SomberNight
dd3966070d tests: rm some redundant "electrum_path" temp dirs 2023-09-06 14:12:30 +00:00
SomberNight
4f90632b1d tests: fix warnings in test_storage_upgrade.py
Manage global event loop so that it is accessible to threads
other than the asyncio thread. In particular, the Plugins
thread needs to reference it in its on_stop().
2023-09-06 14:12:26 +00:00
SomberNight
00ae370a45 tests: split out wallets from test_storage_upgrade.py
so that Thomas' emacs does not crash when editing the file :D
2023-08-30 18:40:41 +00:00
ghost43
e8c0767ca7 Merge pull request #8584 from SomberNight/202308_fix8582
invoices: also run amount-validator on setter
2023-08-30 16:27:00 +00:00
ThomasV
b2053c68f1 make use_to_trampolines a user visible option, disable it by default 2023-08-27 11:43:17 +02:00
SomberNight
392f6d8e30 fix tests: another follow-up to daemon managing Plugins object
In python 3.8 and 3.9, asyncio.Event/Lock/etc cannot be created before the
event loop itself is created. Hence, to have Plugins.__init__ create an
Event, we need to postpone creating Plugins() from setUpClass to setUp.

follow-up 90f39bce88
2023-08-24 18:21:23 +00:00
SomberNight
ffa3acc013 invoices: don't modify .amount_msat directly 2023-08-22 18:12:15 +00:00