In some parts of the application 0 (sec) == no expiry, however we
use `LN_EXPIRY_NEVER` (100 years) instead of 0 for lightning invoices.
This replaces a 0 second expiry with `LN_EXPIRY_NEVER` in
`LNWallet.create_payment_info()` to prevent htlcs for no-expiry invoices
from getting failed incorrectly (which the assert prevented)
and fix the assertion error in #10350.
Fixes#10350.
# Conflicts:
# electrum/lnworker.py
to work around https://github.com/kivy/python-for-android/issues/1866 :
> PyCryptodome >=3.6.0 crashes at runtime (since commit f5aa2c1618). So actually the currently pinned version in the recipe does not work:
> 80e4f059c1/pythonforandroid/recipes/pycryptodome/__init__.py (L5)
>
> The issue at runtime is with ctypes.
>
>
> Say I have a main script that just does the following (95ccce7ae8/lib/Crypto/Util/_raw_api.py (L200)):
> ```
> import ctypes
> ctypes.pythonapi.PyObject_GetBuffer
> ```
>
> This works with cpython on my laptop, but with the p4a-compiled python on Android it fails:
>
> ```
> 06-14 19:06:27.053 15246 15274 I python : Android kivy bootstrap done. __name__ is __main__
> 06-14 19:06:27.053 15246 15274 I python : AND: Ran string
> 06-14 19:06:27.053 15246 15274 I python : Run user program, change dir and execute entrypoint
> 06-14 19:06:27.092 15246 15274 I python : Traceback (most recent call last):
> 06-14 19:06:27.092 15246 15274 I python : File "/home/user/wspace/electrum/.buildozer/android/app/main.py", line 84, in <module>
> 06-14 19:06:27.093 15246 15274 I python : File "/home/user/wspace/electrum/.buildozer/android/platform/build/build/other_builds/python3-libffi-openssl-sqlite3/armeabi-v7a__ndk_target_21/python3/Lib/ctypes/__init__.py", line 369, in __getattr__
> 06-14 19:06:27.093 15246 15274 I python : File "/home/user/wspace/electrum/.buildozer/android/platform/build/build/other_builds/python3-libffi-openssl-sqlite3/armeabi-v7a__ndk_target_21/python3/Lib/ctypes/__init__.py", line 374, in __getitem__
> 06-14 19:06:27.094 15246 15274 I python : AttributeError: undefined symbol: PyObject_GetBuffer
> ```
>
> I have also tried to access some other attributes of `ctypes.pythonapi`, such as `Py_IncRef`, which raises the same exception.
---
Unclear if the issue still affects newer p4a: upstream seems to think it's fixed, but there multiple comments in the thread saying otherwise. Anyway, rebasing p4a has other blockers atm.
We had been using an ancient version of "cryptography" so far in our p4a fork,
however it is not compatible with OpenSSL 3.0. (Previously we were building it with OpenSSL 1.1)
Bumping "cryptography" is difficult, as building new versions of it from source requires a full rust toolchain.
Instead, this commit switches to "pycryptodomex", as a replacement, which is much easier to build from source.
- whitespaces are safe to remove from strings, and is convenient if we do this for users
- bytes-like inputs should be left alone: individual bytes that look like whitespaces can appear in them anywhere
- even stripping the leading/trailing whitespaces is not safe to do: the first byte of the nVersion or the last byte of the nLocktime might look like whitespace too!
- instead, leading/trailing whitespaces can be stripped closer to where they are input, e.g. in the GUI
- e.g. ".txn" files that we ourselves create contain a complete tx as a hex string, with a trailing final newline in the file
- instead of reading that as bytes, we can read it as text
- ".psbt" files OTOH are binary
no functional change (besides incorrect input now raising a different exception)
```
>>> bytes.fromhex(b"deadbeef")
TypeError: fromhex() argument must be str, not bytes
```
Removes all whitespace characters from a raw transaction string.
This is useful for example when loading raw transactions from text input
as it happens that there are some newline characters in the text.
I noticed this when copying-pasting from a timelock recovery pdf.
Handles `UserFacingException` in the `WCWalletPasswordHardware` step of
the hardware wallet wizard flow. This fixes the previous FIXME and
prevents the crash reporter from getting triggered if the the user e.g.
disconnects his hardware wallet during the wallet encryption step.
- lnworker.channels takes a copy of the whole dict, to make it thread-safe
- in LNWallet class, can just use self._channels.get(chan_id)
- otherwise there is lnworker.get_channel_by_id
- same for lnpeer.channels.get and lnpeer.get_channel_by_id
Throws UserFacingException if the communication with the ledger fails
due to an OSError. This happens e.g. if the Bitcoin app has been closed.
We shouldn't get crash reports for errors due to disconnection.
We tried to delete incoming channels that didn't get funded after
lnutil.CHANNEL_OPENING_TIMEOUT, however an assert prevented this:
```
3.63 | E | lnwatcher.LNWatcher.[default_wallet-LNW] | Exception in check_onchain_situation: AssertionError()
Traceback (most recent call last):
File "/home/user/code/electrum-fork/electrum/util.py", line 1233, in wrapper
return await func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/code/electrum-fork/electrum/lnwatcher.py", line 117, in check_onchain_situation
await self.update_channel_state(
...<5 lines>...
keep_watching=keep_watching)
File "/home/user/code/electrum-fork/electrum/lnwatcher.py", line 135, in update_channel_state
chan.update_onchain_state(
~~~~~~~~~~~~~~~~~~~~~~~~~^
funding_txid=funding_txid,
^^^^^^^^^^^^^^^^^^^^^^^^^^
...<2 lines>...
closing_height=closing_height,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
keep_watching=keep_watching)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/code/electrum-fork/electrum/lnchannel.py", line 341, in update_onchain_state
self.update_unfunded_state()
~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/home/user/code/electrum-fork/electrum/lnchannel.py", line 382, in update_unfunded_state
self.lnworker.remove_channel(self.channel_id)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "/home/user/code/electrum-fork/electrum/lnworker.py", line 3244, in remove_channel
assert chan.can_be_deleted()
~~~~~~~~~~~~~~~~~~~^^
AssertionError
```
Accept a `null` value as response for the `minWithdrawable` field in the
lnurlw response. Some servers seem to set this to `null` instead of 0
when having no minimum withdrawal amount.
Adds the invoice features to the `PaymentInfo` class so we can check if
the sender respects our requested features (e.g. if they tried to send
mpp if we requested no mpp).
Store the channel id instead of the scid in ReceivedMPPHtlc.
The scid can be None, in theory even for multiple channels at the same
time. Using the channel_id which is always available and unique seems
less error prone at the cost of temporarily higher storage requirements
in the db for the duration of the pending htlcs.
Alternatively we could use the local scid alias however using the
channel_id seems less complex and leaves less room for ambiguity.
Deduct the just in time channel opening fees from the total amount so
htlcs don't get timed out if they come from a just in time channel with
opening fee.
Related: https://github.com/spesmilo/electrum/pull/9584
Calling dnssec.query() with missing "cryptography" dep behaves the same as if DNSSEC validation failed: validated=False will be returned.
When used for openalias, we mandate validated=True.