1
0
Commit Graph

14032 Commits

Author SHA1 Message Date
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
SomberNight
ee10e8e4d3 blockchain: bits_to_target: small clean-up
note: why is the first byte cut unconditionally? what if it's non-zero?
Maybe the intention of cutting the first two chars in the hex case intended to
cut a "0x" prefix?? But there was no such prefix with the given format string...
2021-11-13 03:07:36 +01:00
SomberNight
6033471853 blockchain: clarify MAX_TARGET by referencing bitcoin core source
change is no-op as the compact nBits form of both values are equal, that is:
```
>>> from electrum.blockchain import Blockchain
>>> MAX_TARGET1 = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
>>> MAX_TARGET2 = 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
>>> Blockchain.bits_to_target(Blockchain.target_to_bits(MAX_TARGET2)) == Blockchain.bits_to_target(Blockchain.target_to_bits(MAX_TARGET1))
True
```
2021-11-13 03:02:31 +01:00
SomberNight
2599010eed interface: scripthash.get_history: fix tx order check
logic bug
2021-11-11 15:28:16 +01:00
SomberNight
88a1c1a618 python 3.10: fix some deprecation warnings and compat with 3.10 2021-11-09 01:02:57 +01:00
SomberNight
ed0dd6eb22 kivy: implement ElectrumGui.stop 2021-11-05 20:35:28 +01:00
SomberNight
ca9b48e2d6 gui: add BaseElectrumGui base class for guis 2021-11-05 20:21:50 +01:00
SomberNight
c331c311db crash reporter: add EarlyExceptionsQueue
`util.send_exception_to_crash_reporter` is now useful and can be transparently
used even before the exception hook is set up.
2021-11-05 20:01:43 +01:00
SomberNight
e0246b30b9 daemon: if taskgroup dies, show error in GUI
If daemon.taskgroup dies
- in GUI mode, show a crash reporter window to the user,
  instead of immediately stopping the whole process.
- in daemon mode, log exception and stop process, as before.
2021-11-05 20:01:38 +01:00
SomberNight
3643b9f056 daemon: rework stopping
The CLI stop() command can now also stop the GUI.
2021-11-05 19:57:39 +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
SomberNight
4f907e3889 lnworker: change api of 'htlc_{fulfilled,failed}' events 2021-11-04 16:41:23 +01:00
SomberNight
16c6655892 lnpeer: make forwarding partly event-driven 2021-11-04 16:32:40 +01:00
yanmaani
82b9cd12eb tests: Add rudimentary integration test for Unix domain socket functionality 2021-11-03 12:00:00 +00:00
yanmaani
b1005694ec cli: Add support for Unix domain sockets 2021-11-03 12:00:00 +00:00
SomberNight
f066f25a30 win build: revert pyinstaller upgrade
Various issues with newer versions... needs more investigation.

This reverts part of 2b4bf19c06
2021-11-03 04:07:52 +01:00
SomberNight
2b4bf19c06 win build: update some build dependencies 2021-11-02 18:38:28 +01:00
SomberNight
7d5c5b75a1 android build: bump python 3.8.8->3.8.12 2021-11-02 18:38:24 +01:00
SomberNight
7409a32879 win build: bump python 3.8.8->3.9.7 2021-11-02 18:38:21 +01:00
SomberNight
f01ca726e4 mac build: bump python 3.7.9->3.9.7 2021-11-02 18:38:17 +01:00
SomberNight
6a0d7dfd48 rerun freeze_packages 2021-11-02 18:38:13 +01:00
SomberNight
d67e24438e lnsweep: rm code dupe: 2nd stage htlc tx out vs ctx to_local addr reuse 2021-11-01 18:05:33 +01:00
SomberNight
99836d5e5f kivy: confirm_tx_dialog: toggling "final" should update the tx
We create a tx when the dialog is created, and re-create it every time
the user moves the fee slider. However, we were not re-creating it if
the user toggles the "Final" checkbox, meaning its value was only taken
into account if the user moved the fee slider after setting the checkbox.

fixes https://github.com/spesmilo/electrum/issues/7547
2021-10-29 14:27:13 +02: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
e97f350597 add comment for safer forwarding 2021-10-27 16:27:16 +02:00
bitromortac
947693c90d check dust limits
* on channel opening we verify that the peer's dust limit is above 354
  sat, the limit for unknown segwit versions
* we constrain the allowed scriptpubkey types for channel closing
* we check that the remote's output is above the relay dust limit for
  the collaborative close case
2021-10-27 16:27: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
5c91212fab dns hacks: dns via proxy: special-case "localhost" string
fix https://github.com/spesmilo/electrum/issues/7546
2021-10-25 17:46:51 +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
SomberNight
4af103378a lnpeer: refactor some checks re open_channel/accept_channel 2021-09-28 19:48:27 +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
SomberNight
b9295eda09 ci: only run coveralls script if ENV var is set (for token)
As the token is typically not available for pull requests.
2021-09-28 16:30:41 +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
b431d8e9b8 follow-up eadd1bebb2 2021-09-24 17:36:33 +02:00
SomberNight
ca2d1eea45 build appimage: update appimagetool and stop using fork of mksquashfs
The latest release of appimagetool bundles a new enough version of
mksquashfs. We had been building a fork of mksquashfs but all the
relevant patches there had been upstreamed.

Note: we still need a wrapper when calling mksquashfs, as appimagetool
calls it with "-mkfs-time 0" and we have the SOURCE_DATE_EPOCH env var
set; and these two would conflict.
Two ways to fix: either unset SOURCE_DATE_EPOCH for that context, or
build a wrapper that removes the "-mkfs-time 0". The former would be
cleaner but for some reason I did not manage to build reproducibly
that way. The latter seems to work.

related:
- https://github.com/AppImage/AppImageKit/issues/929#issuecomment-580769875
  > Now official squashfs 4.4 makes reproducible images by default
- https://github.com/AppImage/AppImageKit/pull/996
2021-09-23 18:49:44 +02:00
ghost43
a555eb3106 Merge pull request #7504 from bitromortac/2109-sample-from-list
Python3.9 compat: sample from list
2021-09-22 15:24:58 +02:00
bitromortac
8913abdf9a python3.9: sample from list instead of set
electrum/electrum/channel_db.py:357: DeprecationWarning: Sampling from a
set deprecated since Python 3.9 and will be removed in a subsequent version.
2021-09-22 14:50:32 +02:00
SomberNight
11146d352f appimage build: bump python 3.8.12->3.9.7 2021-09-20 19:31:41 +02:00
SomberNight
fb3ce438d6 appimage build: bump python 3.7.10->3.8.12 2021-09-20 19:31:38 +02:00
SomberNight
5d0aa63adb appimage build: change base to ubuntu 18.04
ubuntu 16.04 is EOL
2021-09-20 19:31:33 +02:00
ThomasV
d570002b83 Merge pull request #7502 from spesmilo/no_convert_key
No convert key
2021-09-20 17:04:09 +02:00
ThomasV
eadd1bebb2 Do not convert StoredDict keys to str.
Instead, convert json keys to int when storage is read.
2021-09-20 14:49:59 +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
1188187431 wallet_db upgrade: in OnchainInvoice['outputs'], convert vals None->0
should fix https://github.com/spesmilo/electrum/issues/7500
2021-09-19 17:35:49 +02:00
SomberNight
b7cdf3fe11 wallet_db upgrades: (trivial) make upgrades more standalone
and robust to code changes
2021-09-19 17:32:25 +02:00
SomberNight
0b05edc705 wallet payreqs: trivial clean-up 2021-09-19 17:25:57 +02:00