self.oldfeeRate is initialized as int in `QETxRbfFeeBumper` and
`QETxCanceller`. However QML expects it to be a string. Initializing
it as string fixes the exception. Previously this didn't happen as
`Abstract_Wallet.add_info_from_wallet_and_network()` would never
return False, so the `get_tx()` method would immediately overwrite
the self.oldfeeRate variable with a string.
```
20.95 | D | gui.qml.qetxfinalizer | TxMonMixin.__init__
20.95 | E | gui.qml.qeapp.Exception_Hook | exception caught by crash reporter
TypeError: unable to convert a Python 'int' object to a C++ 'QString' instance
```
Early return the update() methods of QETxRbfFeeBumper and QETxCanceller
if it fails to fetch missing tx information from the Network to prevent
an exception in `Abstract_Wallet.bump_fee()` and
`Abstract_Wallet.dscancel()`. See
https://github.com/spesmilo/electrum/issues/5502#issuecomment-40213084270
`Transaction.add_info_from_network` would swallow a `NetworkException`
even when `ignore_network_issues=False` is passed.
This causes `Transaction.add_info_from_wallet_and_network` to
incorrectly return True even if the operation failed.
If `QETxRbfFeeBumper` then incorrectly proceeds assuming the call was
successful `Abstract_Wallet.bump_fee()` would raise an `Exception("tx
missing info from network")`.
Should fix the traceback in
https://github.com/spesmilo/electrum/issues/5502#issuecomment-4021308427.
Fixes exception in lookup_invoice:
```
62.69 | E | plugins.nwc.nwcserver.NWCServer | Error handling nwc request
Traceback (most recent call last):
File "/home/user/code/vibecoding_vm/electrum/electrum/plugins/nwc/nwcserver.py", line 381, in run_request_task
await task
File "/home/user/code/vibecoding_vm/electrum/electrum/util.py", line 1211, in wrapper
return await func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/code/vibecoding_vm/electrum/electrum/plugins/nwc/nwcserver.py", line 526, in handle_lookup_invoice
info = self.wallet.lnworker.get_payment_info(invoice.payment_hash, direction=RECEIVED)
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Invoice' object has no attribute 'payment_hash'
```
Always includes bolt11 invoice in response, even if the client already
sent it to us in the request. It doesn't seem useful and is marked
optional in the spec but https://sandbox.albylabs.com considers the
response invalid if the invoice is not included.
Also consider htlcs that are still inflight when calculating
the amount/fee of a payment to prevent calculating an incorrect
payment value/fee when calling get_payment_info directly after
a payment succeeds (one htlc settled, but others could still be
inflight).
This assumes that once a payments htlc got settled all other inflight
htlcs will also get settled.
Include the lightning routing fees into the payment budget accounting
to prevent untrusted nwc clients from exceeding the budget by crafting
a high fee route.
There is now only add_to_budget which will return None if the budget
doesn't allow for this spend. It will always add the spend to the
budget, even if the user has no budget so it can be used for display
purposes (and simpler code, only one path).
As there are two htlcs, the `alice_htlc_resolved` Event might get set either once or twice by the time `alice_htlc_resolved.wait()` returns. The previous code was assuming that both htlcs are resolved by then, but it could happen that only one htlc was resolved, due to timing.
Also stop timer when dialog is finished, to avoid re-generating txs with the same input coin set, which
results in an exception as these coins have signatures when the swap has started.
NIP-47 got extended to include an optional 'state' field in responses.
Implementing this acutally fixes an issue of Alby Go showing succeeded
payments as failed that appeared recently.
Increase the payment budget before attempting the payment
and decrease again if the payment fails. This prevents a race
where multiple concurrent payments could pass the budget check
before the budget is incremented through any of the other payments.
A lock around the budget is not suitable either as then one long
stuck payment (hold invoice) would render the budget inaccessible for
all other payment attempts.
Stores the currently open (right-click) menu in MyTreeView
and adds a `close_menu()` method so inheritants can cleanly
close the menu again if the context it was opened upon has changed.
This is utilized by `AddressList` and `UTXOList` to close the menu
if a call to `update()` has chenged the address list in some way or
removed a utxo from the list to prevent the user from trying to use
a utxo that doesn't exist anymore.
Fixes#10464
NIP-47 now defines how client/server should communicate their supported
encryption schemes. For backwards compatibility its not strictly
neccessary to implement this but it seems cleaner to explicitly handle
it.
otherwise, when selecting only frozen coins, the set of usable coins is empty, and the menu options
will instead fall back to using ALL coins without informing the user.
- (zbar requires [0] iconv)
- issues [1][3] compiling win-iconv:
- pre-existing issue: lots of "-Wincompatible-pointer-types" warnings when compiling zbar with win-iconv
- new debian means newer GCC
- new GCC changed that [2] warning type to "error"
- GNU libiconv works as an alternative
- drawback: win-iconv is more minimal, it uses the win32 API to do most of the work
- still, is a 25+ year old GNU project with one release every ~2 years, so IMO fine
[0]: https://github.com/mchehab/zbar/blob/a549566ea11eb03622bd4458a1728ffe3f589163/README-windows.md
[1]: https://github.com/SomberNight/electrum/commit/cb00cb60cf9a0cb059dcac5e7acfe5186620cabe
[2]: https://gcc.gnu.org/pipermail/gcc-cvs/2023-December/394351.html
[3]: see snippet when compiling libzbar:
```
decoder.c: In function ‘zbar_decoder_reset’:
decoder.c:116:22: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
116 | memset(dcode, 0, (long)&dcode->buf_alloc - (long)dcode);
| ^
decoder.c:116:48: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
116 | memset(dcode, 0, (long)&dcode->buf_alloc - (long)dcode);
| ^
CC processor/libzbar_la-win.lo
/bin/bash ../libtool --tag=RC \
--mode=compile x86_64-w64-mingw32-windres -DHAVE_CONFIG_H -I. -I../include \
-I../include -o libzbar-rc.lo libzbar.rc
CC processor/libzbar_la-lock.lo
CC decoder/libzbar_la-qr_finder.lo
CC qrcode/libzbar_la-qrdec.lo
In file included from ./processor.h:26,
from processor/lock.c:25:
../include/config.h:423:9: warning: "_WIN32_WINNT" redefined
423 | #define _WIN32_WINNT 0x0500
| ^~~~~~~~~~~~
In file included from /usr/share/mingw-w64/include/corecrt.h:10,
from /usr/share/mingw-w64/include/crtdefs.h:10,
from /usr/share/mingw-w64/include/assert.h:15,
from processor/lock.c:24:
/usr/share/mingw-w64/include/_mingw.h:232:9: note: this is the location of the previous definition
232 | #define _WIN32_WINNT 0xa00
| ^~~~~~~~~~~~
libtool: compile: x86_64-w64-mingw32-windres -DHAVE_CONFIG_H -I. -I../include -I../include libzbar.rc -o .libs/libzbar-rc.o
CC qrcode/libzbar_la-qrdectxt.lo
CC qrcode/libzbar_la-rs.lo
CC qrcode/libzbar_la-isaac.lo
CC qrcode/libzbar_la-bch15_5.lo
CC qrcode/libzbar_la-binarize.lo
CC qrcode/libzbar_la-util.lo
In file included from ./image.h:26,
from qrcode/binarize.c:10:
../include/config.h:423:9: warning: "_WIN32_WINNT" redefined
423 | #define _WIN32_WINNT 0x0500
| ^~~~~~~~~~~~
In file included from /usr/share/mingw-w64/include/corecrt.h:10,
from /usr/share/mingw-w64/include/crtdefs.h:10,
from /usr/share/mingw-w64/include/math.h:13,
from qrcode/binarize.c:7:
/usr/share/mingw-w64/include/_mingw.h:232:9: note: this is the location of the previous definition
232 | #define _WIN32_WINNT 0xa00
| ^~~~~~~~~~~~
CC video/libzbar_la-dshow.lo
CC window/libzbar_la-win.lo
In file included from ./window.h:26,
from window/win.c:26:
../include/config.h:423:9: warning: "_WIN32_WINNT" redefined
423 | #define _WIN32_WINNT 0x0500
| ^~~~~~~~~~~~
In file included from /usr/share/mingw-w64/include/corecrt.h:10,
from /usr/share/mingw-w64/include/crtdefs.h:10,
from /usr/share/mingw-w64/include/ctype.h:9,
from window/win.c:24:
/usr/share/mingw-w64/include/_mingw.h:232:9: note: this is the location of the previous definition
232 | #define _WIN32_WINNT 0xa00
| ^~~~~~~~~~~~
In file included from ./processor.h:26,
from processor/win.c:29:
../include/config.h:423:9: warning: "_WIN32_WINNT" redefined
423 | #define _WIN32_WINNT 0x0500
| ^~~~~~~~~~~~
In file included from /usr/share/mingw-w64/include/corecrt.h:10,
from /usr/share/mingw-w64/include/crtdefs.h:10,
from /usr/share/mingw-w64/include/assert.h:15,
from processor/win.c:24:
/usr/share/mingw-w64/include/_mingw.h:232:9: note: this is the location of the previous definition
232 | #define _WIN32_WINNT 0xa00
| ^~~~~~~~~~~~
processor/win.c: In function ‘_zbar_processor_open’:
processor/win.c:282:47: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
282 | proc->display = CreateWindowEx(EXT_STYLE, (LPCTSTR)(long)wca, "ZBar",
| ^
processor/win.c: In function ‘_zbar_processor_close’:
processor/win.c:297:25: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
297 | UnregisterClass((LPCTSTR)(long)proc->state->registeredClass, 0);
| ^
CC window/libzbar_la-dib.lo
qrcode/qrdectxt.c: In function ‘qr_code_data_list_extract_text’:
qrcode/qrdectxt.c:302:62: error: passing argument 2 of ‘iconv’ from incompatible pointer type [-Wincompatible-pointer-types]
302 | iconv(utf8_cd, &in, &inleft, &out,
| ^~~
| |
| char **
In file included from qrcode/qrdectxt.c:12:
/usr/x86_64-w64-mingw32/include/iconv.h:43:56: note: expected ‘const char **’ but argument is of type ‘char **’
43 | size_t iconv(iconv_t cd, WINICONV_CONST char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
qrcode/qrdectxt.c:352:71: error: passing argument 2 of ‘iconv’ from incompatible pointer type [-Wincompatible-pointer-types]
352 | err = iconv(enc_list[ei], &in,
| ^~~
| |
| char **
/usr/x86_64-w64-mingw32/include/iconv.h:43:56: note: expected ‘const char **’ but argument is of type ‘char **’
43 | size_t iconv(iconv_t cd, WINICONV_CONST char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
qrcode/qrdectxt.c:374:53: error: passing argument 2 of ‘iconv’ from incompatible pointer type [-Wincompatible-pointer-types]
374 | iconv(eci_cd, &in, &inleft, &out,
| ^~~
| |
| char **
/usr/x86_64-w64-mingw32/include/iconv.h:43:56: note: expected ‘const char **’ but argument is of type ‘char **’
43 | size_t iconv(iconv_t cd, WINICONV_CONST char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
make[2]: *** [Makefile:1089: qrcode/libzbar_la-qrdectxt.lo] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/opt/wine64/drive_c/electrum/contrib/zbar/zbar'
make[1]: *** [Makefile:1895: all-recursive] Error 1
make[1]: Leaving directory '/opt/wine64/drive_c/electrum/contrib/zbar'
make: *** [Makefile:989: all] Error 2
🗯 ERROR: Could not build zbar
🗯 ERROR: Could not build zbar
```
If the tx fee of the ctx is already higher than the required target it
is not useful to spend the anchor with a lower fee (the current target),
so instead it is skipped.
"When should we reveal preimages onchain?"
This commit tries to simplify the thinking by making the observation:
- we can reveal preimages (actually in any context) if they are already public
- a preimage is public if any other lightning node knows it besides us
- if we learn the preimage from another LN node, it is public
- if we send update_fulfill_htlc, it becomes public
- if we see a preimage onchain, it is public
- in lnsweep._maybe_reveal_preimage_for_htlc:
- partial mpp check is not relevant if preimage is already public
- let's just always do KeepWatchingTXO, for sanity/safety
Co-authored-by: ThomasV <thomasv@electrum.org>