1
0
Commit Graph

54 Commits

Author SHA1 Message Date
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
SomberNight
0866581b2c daemon error-handling: fix traceback.format_exception() on old python
The new API for traceback.format_exception was only added in python 3.10 (91e93794d5).
2024-06-05 14:45:28 +00:00
Sander van Grieken
9674ffc8ee bip21: add testcases for amount bounds 2024-05-29 10:22:28 +02:00
SomberNight
07c80d2ca1 ecc: ecdsa_verify to enforce low-S rule
The low-S rule for ecdsa signatures is mandated by Bitcoin Core policy/standardness (though not by consensus). If we get signatures from untrusted sources, we should mandate they obey the policy rules. (e.g. from LN peers)

Note that we normalize the signatures in the sig format conversion methods (DER <-> (r,s) <-> sig64).

The BOLTs treat high-S signatures as invalid, and this changes our behaviour to that.
(previously we would silently normalize the S value)

see https://github.com/bitcoin/bitcoin/pull/6769
see https://github.com/lightning/bolts/pull/807
2024-05-27 17:12:33 +00:00
SomberNight
d61c6037ea ecc: add test that verify_usermessage does not enforce low-S rule 2024-05-27 17:09:45 +00:00
SomberNight
bafd52ec6d lnsweep: rm one usage of Transaction.get_preimage_script()
get_preimage_script should really have been private API...
looks like everywhere it is used outside of transaction.py, it is actually abused :/
Other existing usages in plugin code I don't dare to touch without lots of manual testing...
2024-05-24 13:40:48 +00:00
Ondřej Vejpustek
70f0ed992f slip39: implement extendable backups 2024-05-20 16:57:11 +02:00
SomberNight
67d373357b lnworker: make PaymentFeeBudget defaults configurable
- make PaymentFeeBudget proportional fee and flat cutoff fee configurable
  - closes https://github.com/spesmilo/electrum/issues/7622
- increase flat cutoff fee default to 10 sat
  - closes https://github.com/spesmilo/electrum/issues/7669
- rm RouteEdge.is_sane_to_use() (per edge limit) and just rely on budgets (per route limit)
2024-05-08 15:53:22 +00:00
SomberNight
13d9677e53 transaction: tx.sign API change: rm hex usage 2024-04-29 17:10:30 +00:00
SomberNight
2f1095510c bitcoin.py/transaction.py: API changes: rm most hex usage
Instead of some functions operating with hex strings,
and others using bytes, this consolidates most things to use bytes.

This mainly focuses on bitcoin.py and transaction.py,
and then adapts the API usages in other files.

Notably,
- scripts,
- pubkeys,
- signatures
should be bytes in almost all places now.
2024-04-29 17:10:26 +00:00
SomberNight
cf2ed509b4 dependencies: remove bitstring
- `bitstring` started depending on `bitarray` in version 4.1 [0]
  - that would mean one additional dependency for us (from yet another maintainer), which is not even pure python
- we only use bitstring for bolt11-parsing
- hence this PR rewrites the bolt11-parsing and removes `bitstring` as dependency
- note: I benchmarked lndecode using [1], and the new code performs better,
  taking around 80% time needed for old code (when using bitstring 3.1.9, pure python).
  Though the variance is quite large in both cases.

[0]: 95ee533ee4/release_notes.txt (L108)
[1]: d7597d96d0
2024-04-24 14:14:31 +00:00
ThomasV
9a7195d5ab test_lnpeer: fix node_id in storage of created peers 2024-04-18 10:34:48 +02:00
momantech
2b6090429c Fix some comments
Signed-off-by: momantech <cuimoman@qq.com>
2024-04-17 18:46:05 +08:00
ThomasV
8759928ec0 Merge pull request #9000 from SomberNight/202404_ecc_schnorr
ecc: add bindings for schnorr sign/verify, and refactor
2024-04-15 11:57:29 +02:00
ThomasV
3e7d4749cf turn classmethod 'find_all_plugins' into an instance method.
change 'use_' prefix to 'enable_plugin_'
2024-04-13 11:35:49 +02:00
SomberNight
52f1a2ce25 ecc: add method "bip340_tagged_hash"
I decided to use the stdlib (hashlib) instead of libsecp for this,
as it is simple enough, and the former is faster on my PC.

Added a unit test that compares the two.
2024-04-12 14:20:45 +00:00
SomberNight
bd9d0ccc33 ecc: refactor/clean-up sign/verify APIs 2024-04-11 15:25:45 +00:00
SomberNight
44e27ac8b5 ecc: add bindings for schnorr sign/verify
and require "schnorrsig" and "extrakeys" modules of libsecp256k1
2024-04-11 13:09:57 +00:00
SomberNight
30c9f5b6b1 walletdb: chan dict: small clean-up (incl db upgrade)
- "fail_htlc_reasons" was removed in 9b1c40e396
- "unfulfilled_htlcs": rm 2 dead items from the 4-tuple,
   and convert False value of forwarding_key
2024-03-01 16:28:46 +00:00
ThomasV
94a8754bdd regtest: test swapserver with trampoline onions 2024-03-01 12:00:24 +01:00
SomberNight
51b7fc04ef walletdb: fix convert_version_58 for partial local txs
The transaction dict can also contain PSBTs (in addition to complete raw hex txs).
This is the case if the user has saved a partial (e.g. unsigned) tx as local into the history.

fixes https://github.com/spesmilo/electrum/issues/8913
2024-02-26 18:54:21 +00:00
SomberNight
d01582d58c fix tests (follow-up)
follow-up 197979063a
2024-02-22 12:26:25 +00:00
ThomasV
32775c1b5d regtest: fix varname in wait_until_htlcs_settled
(this was not affecting the tests)
2024-02-22 09:40:59 +01:00