1
0
Commit Graph

376 Commits

Author SHA1 Message Date
ThomasV
64e07732f8 Merge pull request #9430 from SomberNight/202501_funding_pubkey_deriv
lightning: change derivation of funding_pubkey
2025-01-17 10:49:16 +01:00
f321x
1f626f3ad8 add gossip address field serialization, parsing and tests
add space

add gossip address field serialization, parsing and tests

fix linter

consolidate tests, fix intendation

refactor test in loops

add gossip address field serialization, parsing and tests
2025-01-17 10:33:56 +01:00
SomberNight
6c2a4b61a1 tests: lnpeer: add test payment_trampoline_e2e A->T1->C>T2->E
Adds a new test case for e2e trampoline payment, where there are multiple
Trampoline Forwarders which themselves are not directly connected.

This adds a regression test for https://github.com/spesmilo/electrum/pull/9431
dffdebf778
2025-01-15 15:12:05 +00:00
SomberNight
cba073dfd1 lightning: change derivation of funding_pubkey
Ideally, given an on-chain backup, after the remote force-closes, we should be able to spend our anchor output,
to CPFP the remote commitment tx (assuming the channel used OPTION_ANCHORS).
To spend the anchor output, we need to be able to sign with the local funding_privkey.

Previously we derived the funding_key from the channel_seed (which comes from os.urandom).
Prior to anchors, there was no use case for signing with the funding_key given a channel backup.
Now with anchors, we should make its derivation deterministic somehow, in a way so that it can
be derived given just an on-chain backup.
- one way would be to put some more data into the existing OP_RETURN
  - uses block space
  - the OP_RETURNs can be disabled via "use_recoverable_channels"
  - only the initiator can use OP_RETURNs (so what if channel is in incoming dir?)
- instead, new scheme for our funding_key:
  - we derive the funding_privkey from the lnworker root secret (derived from our bip32 seed)
  - for outgoing channels:
    - lnworker_root_secret + remote_node_id + funding_tx_nlocktime
  - for incoming channels:
    - lnworker_root_secret + remote_node_id + remote_funding_pubkey
  - a check is added to avoid reusing the same key between channels:
      not letting to user open more than one channel with the same peer in a single block
  - only the first 16 bytes of the remote_node_id are used, as the onchain backup OP_RETURNs only contain that
- as the funding_privkey cannot be derived from the channel_seed anymore, it is included in the
imported channel backups, which in turn need a new version defined
  - a wallet db upgrade is used to update already stored imported cbs
  - alternatively we could keep the imported cbs as-is, so no new version, no new funding_privkey field, as it is clearly somewhat redundant given on-chain backups can reconstruct it
    - however adding the field seems easier
      - otherwise the existing code would try to derive the funding_privkey from the channel_seed
      - also note: atm there is no field in the imported backups to distinguish anchor channels vs static-remotekey channels
2025-01-14 17:56:48 +00:00
SomberNight
be2cd02e54 some clean-ups now that we require python 3.10 2025-01-10 18:52:53 +00:00
SomberNight
043be2439e follow-up prev: add testcase and minor formatting
(minor reshuffling of check so that it matches following line
 and is more clear it is a bounds check)
2025-01-10 11:59:15 +00:00
ThomasV
ebff5b545d lnpeer: replace assert active_forwarding with if. force both incoming and outgoing MPP in test_mpp_consolidation 2025-01-06 11:09:45 +01:00
ThomasV
29a8c41025 move watchtower to a plugin.
remove watchtower dialog in qt
2024-12-20 15:34:26 +01:00
ThomasV
67470b92b7 lnchannel: fix extract_preimage for MPP.
- enforce MPP in the corresponding regtest.
 - fix get_invoice_status returning inflight if it was settled onchain
2024-12-15 10:46:18 +01:00
bitromortac
de9fee706d unit tests: tests for both anchors and old ctx types
* in test_lnutil, patch htlc weight to pass original anchor commitment
  test vectors
* activate tests for both commitment types
2024-11-25 12:31:38 +01:00
ThomasV
19e993f39b fix test_lnchannel (follow-up ea584e13fc) 2024-11-25 12:05:06 +01:00
bitromortac
ea584e13fc anchors: switch to zero-fee-htlcs
* sets the weight of htlc transactions to zero, thereby putting a zero
  fee for the htlc transactions
* add inputs to htlc-tx for fee bumping
* switches feature flags
* disable anchor test vectors, which are now partially invalid
2024-11-25 10:56:50 +01:00
bitromortac
d4222432f4 enable anchor_channels for regtest
* lower the final balance of the backup regtest, which is due to additional
  sweep transactions

* adapt ctx index
2024-11-23 12:03:37 +01:00
ThomasV
6735ae5ec8 fix unit test (follow-up 78d19c6e2f) 2024-11-23 11:58:29 +01:00
ThomasV
ece1fb39d2 enable anchor outputs via config option 2024-11-23 10:10:16 +01:00
bitromortac
a3dc2b847e unit tests: test anchors in lnpeer and lnchannel
* testing of anchor channels is controlled via TEST_ANCHOR_CHANNELS
* rewrite tests in test_lnchannel.py
2024-11-22 12:23:51 +01:00
bitromortac
8f7c11f295 tests: add anchor commitment test vectors from rfc 2024-11-20 12:05:14 +01:00
bitromortac
7aa3dc1e40 lnutil+lnchannel: add anchors, adapt to_remote
* to_remote has now an additional csv lock of 1
* anchor outputs are added if to_local/remote outputs are present
* funder balance is reduced to accomodate anchors
2024-11-20 11:54:55 +01:00
bitromortac
7907b9c05d lnchannel+lnutil: change htlc output, send new sig
* changes the htlc outputs' witness script to have a csv lock of 1
* send signatures for remote ctx with ANYONECANPAY|SINGLE
* refactor htlc weight (useful for zero-fee-htlc)
2024-11-20 11:03:48 +01:00
bitromortac
c8bf515953 lnutil: update ctx fee calculation for anchors 2024-11-20 10:53:00 +01:00
ThomasV
19726c4427 try fo fix mpp unittests flakiness by waiting an extra iteration 2024-11-19 13:34:26 +01:00
ThomasV
60f13a977e Swaps over Nostr
- Separation between SwapManager and its transport:
   Legacy transpport uses http, Nostr uses websockets
 - The transport uses a context to open/close connections.
   This context is not async, because it needs to be called
   from the GUI
 - Swapserver fees values are initialized to None instead
   of 0, so that any attempt to use them before the swap
   manager is initialized will raise an exception.
 - Remove swapserver fees disk caching (swap_pairs file)
 - Regtests use http transport
 - Android uses http transport (until QML is ready)
2024-11-12 09:32:25 +01:00
accumulator
1b9f1dbb7f Merge pull request #9250 from accumulator/network_tor_stream_isolation
network: use TOR stream isolation
2024-10-28 09:50:00 +01:00
ThomasV
3c61f2a64a Fix #9280:
- Wait until HTLCs are irrevocably removed before cleaning up their
   data structures (MPP and forwarding)
 - keep methods maybe_cleanup_mpp and maybe_cleanup_forwarding separate
 - perform cleanup in htlc_switch, so that process_unfulfilled_htlc
   has less side effects
 - In htlc_switch, we blank the onion_packet_hex field to signal that
   an HTLC has been processed. An item of chan.unfulfilled_htlcs may
   go through 4 stages:
   - 1. not forwarded yet: (None, onion_packet_hex)
   - 2. forwarded: (forwarding_key, onion_packet_hex)
   - 3. processed: (forwarding_key, None), not irrevocably removed yet
   - 4. done: (forwarding_key, None), irrevocably removed
 - in test_lnpeer, an extra iteration of htlc_switch has been added to
   trampoline forwarding tests
2024-10-27 07:23:38 +01:00
Sander van Grieken
f4520b9e0d network: use TOR stream isolation
also refactor, for proxy instantiation, use Network instance, not a proxy dict.
2024-10-25 01:10:58 +02:00
ThomasV
f0d0c23869 Invalidate cache of sweep_info on each new block
Add regtest test for swapserver_forceclose
2024-10-24 11:20:12 +02:00
ThomasV
5708f7b1c8 Persist MPP resolution status in wallet file.
If we accept a MPP and we forward the payment (trampoline or swap),
we need to persist the payment accepted status, or we might wrongly
release htlcs on the next restart.

lnworker.received_mpp_htlcs used to be cleaned up in maybe_cleanup_forwarding,
which only applies to forwarded payments. However, since we now
persist this dict, we need to clean it up also in the case of
payments received by us. This part of maybe_cleanup_forwarding has
been migrated to lnworker.maybe_cleanup_mpp
2024-10-24 11:19:53 +02:00
ThomasV
c58c4d7451 Make lntransport not require lnutil.
This will be useful if we decide to ship lntransport as a separate
package. It is also a conceptual cleanup.

Notes:
 - lntransport still requires crypto.py
 - parsing node id from a bolt11 invoice is not supported.
2024-10-22 09:26:36 +02:00
SomberNight
bad965a2ac tests: test_wizard: fix warnings
```
=============================== warnings summary ===============================
tests/test_wizard.py::ServerConnectWizardTestCase::test_no_advanced
tests/test_wizard.py::ServerConnectWizardTestCase::test_proxy
tests/test_wizard.py::ServerConnectWizardTestCase::test_proxy_and_server
tests/test_wizard.py::ServerConnectWizardTestCase::test_server
tests/test_wizard.py::WalletWizardTestCase::test_2fa
tests/test_wizard.py::WalletWizardTestCase::test_create_standard_wallet_haveseed_bip39
tests/test_wizard.py::WalletWizardTestCase::test_create_standard_wallet_haveseed_electrum
tests/test_wizard.py::WalletWizardTestCase::test_create_standard_wallet_newseed
  /tmp/cirrus-ci-build/.tox/py3/lib/python3.10/site-packages/_pytest/threadexception.py:82: PytestUnhandledThreadExceptionWarning: Exception in thread Plugins

  Traceback (most recent call last):
    File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
      self.run()
    File "/tmp/cirrus-ci-build/electrum/plugin.py", line 360, in run
      self.on_stop()
    File "/tmp/cirrus-ci-build/electrum/util.py", line 430, in on_stop
      loop = get_asyncio_loop()
    File "/tmp/cirrus-ci-build/electrum/util.py", line 1578, in get_asyncio_loop
      raise Exception("event loop not created yet")
  Exception: event loop not created yet

    warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg))
```
2024-10-21 13:00:21 +00:00
accumulator
f9e342ebb2 Merge pull request #9254 from accumulator/tests_wizard
tests: initial wizard test cases
2024-10-21 14:13:46 +02:00
SomberNight
4e47e07550 lnchannel: (trivial) add/fix type-hints 2024-10-20 13:55:33 +00:00
SomberNight
ccc4cb7f57 follow-up prev: fix linter 2024-10-20 12:09:00 +00:00
SomberNight
cb0e234474 tests: test_lnpeer: extend close_upfront_shutdown_script
- make some checks more explicit, and
- explicitly test that closing tx pays to script specified by Bob using feature
2024-10-20 11:57:31 +00:00
SomberNight
3a28bb0957 follow-up prev: fix tests 2024-10-18 00:39:35 +00:00
Sander van Grieken
88d0ab300d tests: initial wizard test cases 2024-10-17 11:56:24 +02:00
SomberNight
8d79726ec5 tests: rm some ecc tests (moved to electrum-ecc)
see cd6bb9beb9
2024-10-11 18:46:30 +00:00
ThomasV
3721f04ac8 replace electrum/ecc with electrum_ecc package 2024-10-10 15:46:00 +00:00
SomberNight
d35ed6935d commands: extend "importprivkey" to allow importing a list of keys
This is most useful if the user wants to import a significant number of keys,
as every invocation of `importprivkey` results in rewriting the wallet file to disk.

The API of "importprivkey" is left unchanged for the single privkey case.
2024-10-08 14:11:19 +02:00
SomberNight
1257f21b1b constants: rm set_testnet/set_mainnet fns with AbstractNet.set_as_network 2024-09-16 15:27:45 +00:00
ghost43
287cb9ebb6 Merge pull request #9152 from shangchenglumetro/master
chore: fix some comments
2024-08-13 03:32:51 +00:00
SomberNight
16d2f0f9d4 wallet.get_tx_status: fix incorrect feerate for partial txs
The history tab would show an incorrect feerate for partial/unsigned (local) txs,
if they had any p2sh/p2wsh txins. We would just guess the script is p2wpkh, and
use that for the size calc. Now with calling add_info_from_wallet, the correct
size is used to calculate the feerate.

(The gui tx dialogs call add_info_from_wallet independently, so the size/feerate
shown there were already correct.)
2024-08-13 03:20:32 +00:00
shangchenglumetro
4064686359 chore: fix some comments 2024-07-26 01:41:36 +08:00
SomberNight
bec78b4210 util.error_text_str_to_safe_str: truncate long errors
The messages are sometimes logged and sometimes shown to the user,
- for logging we might not want to truncate or have higher limits,
- but when shown to the user, we definitely want to truncate the error text.
It is simplest to just do the truncation here, at the lowest level.

Note that we usually prepend the error text with a header e.g. "[DO NOT TRUST THIS MESSAGE]"
and if the error text is too long, this header at the beginning might get "lost" in some way.
Hence we should truncate the error text.
2024-06-17 16:52:13 +00:00
ThomasV
2f3d89f415 prepare for separation of ecc module:
- move encrypt/sign functions elsewhere
- remove local dependencies in ecc.py, ecc_fast.py (except logging)
2024-06-17 13:05:57 +02:00
ThomasV
8409503788 Merge pull request #9082 from SomberNight/202404_tx_taproot
transaction.py: impl taproot key-spends
2024-06-17 12:49:32 +02:00
SomberNight
300b986782 soothe flake8
```
./tests/test_mnemonic.py:249:9: B017 `assertRaises(Exception)` and `pytest.raises(Exception)` should be considered evil. They can lead to your test passing even if the code being tested is never executed due to a typo. Assert for a more specific exception (builtin or custom), or use `assertRaisesRegex` (if using `assertRaises`), or add the `match` keyword argument (if using `pytest.raises`), or use the context manager form with a target.
        with self.assertRaises(Exception):
        ^
1     B017 `assertRaises(Exception)` and `pytest.raises(Exception)` should be considered evil. They can lead to your test passing even if the code being tested is never executed due to a typo. Assert for a more specific exception (builtin or custom), or use `assertRaisesRegex` (if using `assertRaises`), or add the `match` keyword argument (if using `pytest.raises`), or use the context manager form with a target.
```
2024-06-10 20:22:20 +00:00
SomberNight
a2d5e31838 mnemonic: rename seed_type() fn
Some functions have an argument named "seed_type" in which it was annoying to call the seed_type() fn.
(especially for functions inside the same module)
2024-06-10 20:00:52 +00:00
SomberNight
b95fbbb86f wizard: fix regression: allow passphrase for some '2fa' seeds
fixes https://github.com/spesmilo/electrum/issues/9088
2024-06-10 19:35:56 +00:00
SomberNight
4f7dcc98bd tests: wallet_vertical: re pre-2.7 "2fa" seeds, test both 24 and 25 len 2024-06-10 18:22:59 +00:00
SomberNight
3a305881cc transaction.py: impl taproot key-spends
Add support for key-path-spending taproot utxos into transaction.py.

- no wallet support yet
- add some psbt, and minimal descriptor support
- preliminary work towards script-path spends
2024-06-07 10:58:26 +00:00