1
0
Commit Graph

569 Commits

Author SHA1 Message Date
Marko Bencun
1d652a2a04 tests: unit test address_to_payload 2022-03-02 14:54:11 +01:00
ghost43
6603359c20 Merge pull request #7668 from SomberNight/202202_signmessage_segwit_trezor
signmessage: also accept Trezor-type sigs for p2wpkh and p2wpkh-p2sh addrs
2022-02-22 17:10:08 +00:00
SomberNight
556b98736e lnworker.try_force_closing: changed to not be async (and renamed)
This is to ensure that the channel is "immediately" set to FORCE_CLOSING.
(previously it took at least one event loop iteration)
2022-02-21 18:09:45 +01:00
ThomasV
b268877d53 Merge pull request #7636 from bitromortac/2201-channel-type
lightning: implement channel types
2022-02-21 12:08:54 +01:00
ThomasV
4ebe41b3a7 Trampoline MPP: save fee level in sent_htlcs_info.
If multiple HTLCs fail at the same fee level with
TRAMPOLINE_INSUFFICIENT_FEE, bump trampoline_fee_level only once.
2022-02-19 15:20:54 +01:00
ThomasV
9fd18ae7f4 Merge pull request #7623 from bitromortac/2201-multi-trampoline-mpp
Multi-trampoline multipart payments
2022-02-19 14:44:21 +01:00
ThomasV
b2f84187bc Split code in reestablish_channel:
Messages are sent in reestablish_channel (async)
  Message checks and force_close are performed in on_channel_reestablish (not async).
  That task should not be cancelled if the connection is closed.
  Revert 57583c05cf
2022-02-19 10:37:50 +01:00
SomberNight
2f549e84db fix tests: follow-up 96fcf68d84 2022-02-18 19:32:27 +01:00
bitromortac
a4f5cfc91a trampoline: refactor routes, enable e2e mpp
* Refactor `create_trampoline_route`.
* Enables end-to-end multi-trampoline multipart payments.
  Trampoline-to-legacy payments are still not enabled, as this is
  currently not supported by Eclair.
* Reverts to a global trampoline fee level, as trampoline failures
  are currently not handled properly, see (#7648), which doubles
  fee rates.
2022-02-18 10:14:51 +01:00
SomberNight
5cdb4471ec signmessage: also accept Trezor-type sigs for p2wpkh and p2wpkh-p2sh addrs
The signatures we create are unchanged but we now also accept signatures created by Trezor and others.

see https://github.com/spesmilo/electrum/issues/3861
2022-02-16 19:25:46 +01:00
SomberNight
9bbf92b80b tests: add test for signmessage with segwit address 2022-02-16 19:24:43 +01:00
SomberNight
4f9e4c520f ecc: API changes: verify_message_hash to return bool instead of raising
verify_message_hash and verify_message_for_address now return bool
instead of raising Exceptions on bad signatures.
2022-02-16 19:24:38 +01:00
SomberNight
40c1597c0a lntransport: change name used in logs to make collisions unlikely
In particular, in the regtests, with incoming peers, we can have multiple transports open with the same node simultaneously
(see e.g. lnworker._request_force_close_from_backup).
We now use the first few bytes of peer_pubkey, as that is potentially familiar to users,
and the first few bytes of sha256(id(self)) to mitigate collisions in case the peer_pubkeys collide.

log excerpt:
```
I/P | lnpeer.Peer.[LNWallet, 030f0bf260-e0b33756] | handshake done for 030f0bf260acdbd3edcad84d7588ec7c5df4711e87e6a23016f989b8d3a4147230@163.172.94.64:9735
D/P | lnpeer.Peer.[LNWallet, 030f0bf260-e0b33756] | Sending INIT
I/P | lnpeer.Peer.[LNWallet, 03933884aa-5e5dce45] | handshake done for 03933884aaf1d6b108397e5efe5c86bcf2d8ca8d2f700eda99db9214fc2712b134@34.250.234.192:9735
D/P | lnpeer.Peer.[LNWallet, 03933884aa-5e5dce45] | Sending INIT
D/P | lnpeer.Peer.[LNWallet, 030f0bf260-e0b33756] | Received INIT
I/P | lnpeer.Peer.[LNWallet, 02651acf4a-79696c42] | handshake done for 02651acf4a7096091bf42baad19b3643ea318d6979f6dcc16ebaec43d5b0f4baf2@82.119.233.36:19735
D/P | lnpeer.Peer.[LNWallet, 02651acf4a-79696c42] | Sending INIT
D/P | lnpeer.Peer.[LNWallet, 03933884aa-5e5dce45] | Received INIT
I/P | lnpeer.Peer.[LNWallet, 030f0bf260-e0b33756] | saved remote_update
D/P | lnpeer.Peer.[LNWallet, 030f0bf260-e0b33756] | Received CHANNEL_REESTABLISH
```
2022-02-16 18:53:24 +01:00
SomberNight
c9c094cfab requirements: bump min aiorpcx to 0.22.0
aiorpcx 0.20 changed the behaviour/API of TaskGroups.
When used as a context manager, TaskGroups no longer propagate
exceptions raised by their tasks. Instead, the calling code has
to explicitly check the results of tasks and decide whether to re-raise
any exceptions.
This is a significant change, and so this commit introduces "OldTaskGroup",
which should behave as the TaskGroup class of old aiorpcx. All existing
usages of TaskGroup are replaced with OldTaskGroup.

closes https://github.com/spesmilo/electrum/issues/7446
2022-02-15 18:22:44 +01:00
bitromortac
6915e3cb10 lnpeer+wallet: use channel type for channel open
* channel_type is put into storage, serialized as int and
  deserialized as ChannelType
* check for static_remotekey is done via channel type
2022-01-20 16:47:48 +01:00
bitromortac
401a429080 lnutil+lnwire: implement ChannelType 2022-01-20 16:47:48 +01:00
bitromortac
2d2b889312 lnpeer tests: add spp trampoline payment 2021-12-20 16:45:14 +01:00
bitromortac
e8c94cf5d7 tests: implement graph with flexible definitions 2021-12-20 16:45:07 +01:00
SomberNight
7354feeffe follow-up fix tests: logic typo
follow-up https://github.com/spesmilo/electrum/pull/7202

defaultdict[int] is a type!

```
>>> from collections import defaultdict
>>> d = defaultdict[int]
>>> d[2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: There are no type variables left in collections.defaultdict[int]
```

Also, prior to py3.9, it is a TypeError.
2021-12-17 15:21:21 +01:00
ghost43
c8f47ed4fe Merge pull request #7562 from SomberNight/202111_blockchain_target
blockchain.py: bugfixes re `bits_to_target` and `target_to_bits`
2021-12-17 14:07:55 +00:00
ghost43
ce44a03c24 Merge pull request #7202 from bitromortac/2104-mpp-channel-splitting
MPP splitting algorithm: redesign and split within channels
2021-12-17 13:58:54 +00:00
SomberNight
7e2d9c48d1 blockchain: fix bugs in bits_to_target and target_to_bits
This fixes three bugs:
- too large targets: the fixme in target_to_bits, which meant that we could
  not handle targets where the first bit was non-zero. This however cannot
  happen due to these being over MAX_TARGET. (difficulty 1)
- too small targets: in bits_to_target, very small targets were not handled well:
  ```
  >>> Blockchain.bits_to_target(0x03008000)
  32768
  ```
  We could not process headers with targets smaller than the above value.
  (note that these small targets would only occur at astronomically high mining difficulty)
- non-canonically encoded targets:
  we would not accept headers that had targets encoded in compact form (nBits) in a non-canonical way.
  I think this bug could actually be triggered by mining such a header.
  E.g. consider the target "1167130406913723784571467005534932607254396928"
  ```
  Blockchain.target_to_bits(1167130406913723784571467005534932607254396928).to_bytes(4, "big").hex()
  '13345600'
  ```
  Bitcoin Core when used to e.g. mine a block would encode this target as 0x13345600 in compact form.
  However, AFAICT, when validating Bitcoin Core would equally accept 0x14003456 which decodes to the
  same target. We were however rejecting such non-canonical compact nBits.
  ```
  >>> from electrum.blockchain import Blockchain
  >>> Blockchain.bits_to_target(0x14003456)
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/home/user/wspace/electrum/electrum/blockchain.py", line 548, in bits_to_target
      raise Exception("Second part of bits should be in [0x8000, 0x7fffff]")
  Exception: Second part of bits should be in [0x8000, 0x7fffff]
  >>> Blockchain.bits_to_target(0x13345600)
  1167130406913723784571467005534932607254396928
  ```
2021-11-13 04:31:08 +01:00
ghost43
a5c4b9e719 Merge pull request #7545 from yanmaani/unix_sockets
Add support for Unix domain sockets
2021-11-04 19:32:33 +01:00
SomberNight
56b03e2e8d lnpeer: more forwarding is now event-driven
This should make unit tests less reliant on sleeps.
2021-11-04 19:16:02 +01:00
SomberNight
12f3525df0 lnpeer: disable msg processing rate-limiting in tests 2021-11-04 18:04:16 +01:00
yanmaani
82b9cd12eb tests: Add rudimentary integration test for Unix domain socket functionality 2021-11-03 12:00:00 +00:00
ghost43
5787f3ab74 Merge pull request #7542 from bitromortac/2109-dust-limit
Implement recent spec changes regarding collab channel close outputs
2021-10-27 16:51:07 +02:00
SomberNight
cb55a2d654 tests: try to reduce flakyness of test_fail_pending_htlcs_on_shutdown
Alice sends and HTLC: Alice->Carol->Dave
we need a lot of messages back and forth to happen:
- Alice adds HTLC to chan_AC, sends sig, Carol revacks, sends sig, Alice revacks;
- only then Carol adds HTLC to chan_CD, sends sig, Dave revacks, sends sig, Carol revacks
on CI, 0.5 seconds is often not enough for this it seems.
2021-10-27 16:46:15 +02:00
bitromortac
f2f8c4533b implement option_shutdown_anysegwit
https://github.com/lightningnetwork/lightning-rfc/pull/672

We check the received shutdown script against higher segwit versions and
accept closing to that script if option_shutdown_anysegwit has been
negotiated.
2021-10-26 14:51:09 +02:00
SomberNight
1ff9f9910f ln update_fee: enforce that feerate is over default min relay fee
(this was always already the case when we are the funder, but we were
not checking it when remote is responsible for update_fee)
2021-09-28 19:48:31 +02:00
ghost43
437a9e4358 Merge pull request #7505 from bitromortac/2109-activate-watchtower
watchtower: continuously check for added channels
2021-09-28 16:46:19 +02:00
bitromortac
ff61020dd2 watchtower: watch new channels 2021-09-27 10:31:44 +02:00
ThomasV
baff4fa625 save_backup: do not remove deterministic LN key (see #7513) 2021-09-26 12:18:25 +02:00
ThomasV
7a0904c0f4 wallet update: move fields that have string keys out of channel log 2021-09-20 14:47:20 +02:00
SomberNight
85780eea1a multiple max spends: add unit test
re https://github.com/spesmilo/electrum/pull/7492
2021-09-15 16:42:32 +02:00
JeremyRand
b1c4bb8914 Add Cirrus CI (#7431)
* Cirrus: Add Tox task

* Cirrus: Add Locale task

* Cirrus: Add Flake8 Task

* Cirrus: Add Regtest task

* Regtest: Flush stdout

Allows viewing output sooner.

* Regtest: Read process.stdout in text mode

Improves ability to quickly see output.

* Cirrus: Add Windows task

* Cirrus: Add Android task

* Cirrus: Add macOS task

* Cirrus: Add AppImage task

* Cirrus: Add tarball task

* Cirrus: Add Submodules task

* Android: remove superfluous cp/rm

* Add .dockerignore

Symlink to .gitignore.
2021-09-13 16:20:54 +00:00
djboi
604cba8fb6 Added different Sighash_Types (#7453)
Implements signing for sighash types other than `ALL` for segwit inputs.

fixes https://github.com/spesmilo/electrum/issues/7408
2021-09-07 14:41:50 +00:00
SomberNight
a39bfba2d9 ecc: allow tests to disable ecdsa R-value grinding
see https://github.com/spesmilo/electrum/pull/7453#issuecomment-912594926
2021-09-03 17:18:13 +02:00
Siddhant Chawla
e9f08ef69e Adding BumpFee command to the CLI (#7438)
closes https://github.com/spesmilo/electrum/issues/5791
2021-08-11 11:30:26 +00:00
bitromortac
6716004b47 bolt11: fix amount encoding for large values 2021-07-30 08:44:15 +02:00
SomberNight
9f5370f9c6 util.format_satoshis: fix (add_thousands_sep & whitespaces) param combo 2021-07-28 15:29:12 +02:00
djboi
6a431aab8c Fixed issue with thousands separator for better readability (#7427)
util.format_satoshis: introduce new option to add thousands separators
2021-07-28 13:26:30 +00:00
SomberNight
46badd128e util.format_satoshis: fix whitespaces param for non-zero precision 2021-07-20 20:31:48 +02:00
SomberNight
5c80293696 util.format_satoshis: fix for amounts with higher than sat precision
Previously, msat precision was leaking through format_satoshis if the
user's base unit was set to "sat". This was a bug.
Some features of format_satoshis did not work well with such values, such
as the "whitespaces" param.

Old code:

>>> util.format_satoshis(Decimal('45831275.748'), decimal_point=2)
'458312.76'
>>> util.format_satoshis(Decimal('45831275.748'), decimal_point=0)
'45831275.748'

New code:

>>> util.format_satoshis(Decimal('45831275.748'), decimal_point=2)
'458312.76'
>>> util.format_satoshis(Decimal('45831275.748'), decimal_point=0)
'45831276.'
2021-07-20 20:02:45 +02:00
bitromortac
68bc9c2474 lnworker: improve route creation
- Separates the trampoline and local routing multi-part payment cases.
- Ask only for splits that don't send over a single channel (those have
  been tried already in the single-part case).
- Makes sure that create_routes_for_payment only yields partial routes
  that belong to a single split configuration.
- Tracks trampoline fee levels on a per node basis, previously, in the
  case of having two channels with a trampoline forwarder, the global
  fee level would have increased by two levels upon first try.
2021-07-16 11:27:36 +02:00
bitromortac
3c521f4ce3 mpp_split: split algorithm with channel splits
- The splitting algorithm is redesigned to use random distribution of
  subsplittings over channels.
- Splittings can include multiple subamounts within a channel.
- The single-channel splittings are implicitly activated once the
  liquidity hints don't support payments of large size.
2021-07-16 11:22:38 +02:00
bitromortac
3cd14a27bd tests: clarify keyword arguments, rename 2021-07-14 14:54:43 +02:00
SomberNight
3a7f5373ac trampoline: improve payment success
- better error handling: previously we stopped all attempts on any of
  TRAMPOLINE_EXPIRY_TOO_SOON, UNKNOWN_NEXT_PEER, TEMPORARY_NODE_FAILURE.
  Instead we should retry (but see code comments).
- previously payments failed if ALL of the following criteria applied:
  - sender is paying via trampoline, but not via the ACINQ node (which is
    special cased)
  - receiver only has private channels and has put r_tags into invoice, along
    with setting the trampoline feature bit in the invoice, however the receiver
    is not connected to any trampoline forwarders directly
  The sender would then assume that the private routing hints in the invoice
  correspond to trampoline forwarders.
- also, previously if both the sender and the recipient used trampoline and
  they shared a trampoline forwarder (that they were both connected to), the
  private channels the recipient had (with nodes other than the shared TF)
  would never be attempted.
2021-07-02 18:44:39 +02:00
ghost43
b828627dc6 Merge pull request #6917 from andrewkozlik/slip39
SLIP-0039 wallet recovery
2021-06-22 19:44:02 +02:00
SomberNight
60e0cd65cf slip39: follow-ups
- fix kivy wizard restore-from-seed
- qt seed dialog: disable "next share" if current share is invalid
- fix tests: file paths should not depend on $PWD (working dir)
2021-06-22 19:24:16 +02:00