Commit Graph

7804 Commits

Author SHA1 Message Date
SomberNight
cba073dfd1 lightning: change derivation of funding_pubkey
Ideally, given an on-chain backup, after the remote force-closes, we should be able to spend our anchor output,
to CPFP the remote commitment tx (assuming the channel used OPTION_ANCHORS).
To spend the anchor output, we need to be able to sign with the local funding_privkey.

Previously we derived the funding_key from the channel_seed (which comes from os.urandom).
Prior to anchors, there was no use case for signing with the funding_key given a channel backup.
Now with anchors, we should make its derivation deterministic somehow, in a way so that it can
be derived given just an on-chain backup.
- one way would be to put some more data into the existing OP_RETURN
  - uses block space
  - the OP_RETURNs can be disabled via "use_recoverable_channels"
  - only the initiator can use OP_RETURNs (so what if channel is in incoming dir?)
- instead, new scheme for our funding_key:
  - we derive the funding_privkey from the lnworker root secret (derived from our bip32 seed)
  - for outgoing channels:
    - lnworker_root_secret + remote_node_id + funding_tx_nlocktime
  - for incoming channels:
    - lnworker_root_secret + remote_node_id + remote_funding_pubkey
  - a check is added to avoid reusing the same key between channels:
      not letting to user open more than one channel with the same peer in a single block
  - only the first 16 bytes of the remote_node_id are used, as the onchain backup OP_RETURNs only contain that
- as the funding_privkey cannot be derived from the channel_seed anymore, it is included in the
imported channel backups, which in turn need a new version defined
  - a wallet db upgrade is used to update already stored imported cbs
  - alternatively we could keep the imported cbs as-is, so no new version, no new funding_privkey field, as it is clearly somewhat redundant given on-chain backups can reconstruct it
    - however adding the field seems easier
      - otherwise the existing code would try to derive the funding_privkey from the channel_seed
      - also note: atm there is no field in the imported backups to distinguish anchor channels vs static-remotekey channels
2025-01-14 17:56:48 +00:00
SomberNight
8f5b395ddc lnworker.open_channel: move max funding_sat check deeper in call stack
open_channel_with_peer was missing this check
2025-01-13 14:53:16 +00:00
ghost43
68a2e4e399 Merge pull request #9418 from SomberNight/202501_bump_min_python
bump min python to 3.10
2025-01-13 12:01:57 +00:00
ThomasV
ef08fb37a6 json_db: add StoredList.clear() method 2025-01-12 10:32:00 +01:00
ThomasV
3ffcac87ac maybe_forward_htlc: 'already_forwarded' must be passed to the recursive call.
if we are a trampoline and chain tip is stale, we must not fail the htlc.
2025-01-11 09:44:03 +01:00
SomberNight
be2cd02e54 some clean-ups now that we require python 3.10 2025-01-10 18:52:53 +00:00
ThomasV
0efe7e9bc8 swaps: make the zeroconf option non-persisted
Since we allow swaps with random servers, we should not persist that setting.
2025-01-10 16:19:01 +01:00
SomberNight
c43a691eee qt gui: qrreader: lower strong_count in qtmultimedia based reader
The qtmultimedia-based qrreader has the concept of "strong_count":
before the scanner returns a decoded qr code result, it waits until
it has seen at least "strong_count" (e.g. 10) frames in which the qr code was seen and successfully decoded.
I think the idea might have been to reduce false positives, mis-decoding qr codes from bad frames.
However in practice it makes scanning even moderately sized qr codes really difficult for the user:
it takes several seconds (at least on my laptop cam) to obtain enough "clear" frames that count into the strong_count.

So I am lowering the strong_count to 2, down from CAMERA_FPS/3,
which makes it easier to scan, and I still haven't seen false positives even with this value.
2025-01-10 12:59:56 +00:00
SomberNight
838490fea4 adb.add_transaction: try to ser-deser tx early
Previously calling add_transaction with a malformed Transaction obj could
result in an exception late in the flow, after the walletdb was already side-effected.
Rollback of such side-effects is not implemented :/
  but this small patch should at least cover and prevent some common cases.

```
File "/opt/electrum/electrum/address_synchronizer.py", line 358, in add_transaction
  self.db.add_transaction(tx_hash, tx)
File "/opt/electrum/electrum/json_db.py", line 42, in wrapper
  return func(self, *args, **kwargs)
File "/opt/electrum/electrum/wallet_db.py", line 1434, in add_transaction
  tx = tx_from_any(str(tx))
File "/opt/electrum/electrum/transaction.py", line 1339, in tx_from_any
  raise SerializationError(f"Failed to recognise tx encoding, or to parse transaction. "
```
2025-01-10 12:24:26 +00:00
SomberNight
043be2439e follow-up prev: add testcase and minor formatting
(minor reshuffling of check so that it matches following line
 and is more clear it is a bounds check)
2025-01-10 11:59:15 +00:00
thecockatiel
ddb67d9bca fix: transaction.py: add extra check to script_GetOp 2025-01-10 11:59:11 +00:00
ThomasV
fefd123275 wallet: always include wanted_height (for future tx) 2025-01-10 10:41:54 +01:00
ghost43
2547ac4e30 Merge pull request #9412 from f321x/plugin_hash
Add filehash of external plugins to PluginDialog
2025-01-09 17:54:24 +00:00
f321x
ea10c7cfc1 add filehash of external plugins to PluginDialog
remove hashlib import

add filehash of external plugins to PluginDialog

add emptyline

add filehash of external plugins to PluginDialog
2025-01-09 18:15:12 +01:00
SomberNight
30028520e0 qml/qeinvoice.py: show error details when scanning e.g. lnurl-withdraw
saying the lnurl type is not supported is more informative than "could not resolve"
2025-01-09 16:10:46 +00:00
SomberNight
264a5fe421 qt gui: add command for console use: "scan_qr()"
try
```
>>> scan_qr().data
```
to read a qr code from the screen
2025-01-09 12:18:10 +00:00
ThomasV
c4443b841f Merge pull request #9410 from f321x/fix_user_cancelled_swap
Catch UserCancelled exception in main window on user swap cancellation
2025-01-09 11:15:08 +01:00
f321x
c4fe8433c0 catch UserCancelled exception in main window 2025-01-09 11:12:30 +01:00
ThomasV
d2fa65b9aa fix qt wizard (follow-up 693210edbe) 2025-01-06 11:46:20 +01:00
ThomasV
ebff5b545d lnpeer: replace assert active_forwarding with if. force both incoming and outgoing MPP in test_mpp_consolidation 2025-01-06 11:09:45 +01:00
ThomasV
33d0e6dbec Attach labels to outpoints instead of txids.
Move labels logic from lnworker to wallet.

Due to batching, a single transaction may have several labels attached to it.
2025-01-03 10:54:11 +01:00
ThomasV
4d9c33c33f Qt: disable swapserver dialog if we are using http 2025-01-03 10:39:24 +01:00
ThomasV
29a8c41025 move watchtower to a plugin.
remove watchtower dialog in qt
2024-12-20 15:34:26 +01:00
ThomasV
7113cec4c7 minor fix, follow-up ee42e09387 2024-12-20 15:33:47 +01:00
ThomasV
ac1c9f088d Anchor channels: require deterministic wallet with software keystore.
This ends LN support in hardware and watching-only wallets.
2024-12-20 10:17:51 +01:00
ThomasV
ee42e09387 anchor channels: unlock wallet on startup if the wallet has channels 2024-12-20 10:10:07 +01:00
ThomasV
693210edbe Qt: stop support for password-protected wallets without
storage encryption.

The password will be needed on startup with anchor channels.

Note that it remains possible to use non-encrypted storage
and keystore encryption with the command line.
2024-12-20 09:24:45 +01:00
ThomasV
692a777da8 coins tab: if we do not know whether we can swap a utxo, assume we can 2024-12-17 17:43:43 +01:00
ThomasV
77ec49ac67 make_unsigned_transaction: ensure coins and inputs do not overlap
(follow-up 8bec974a39)
2024-12-17 10:54:21 +01:00
ThomasV
bae2bbf35d lnsweep: sweep anchor outputs 2024-12-16 12:13:39 +01:00
ThomasV
67470b92b7 lnchannel: fix extract_preimage for MPP.
- enforce MPP in the corresponding regtest.
 - fix get_invoice_status returning inflight if it was settled onchain
2024-12-15 10:46:18 +01:00
ThomasV
62af1ee887 fixes for txin.make_witness:
- add witness_sizehint
  - fix make_unsigned_transaction
  - do not remove witness_script in tx.finalize()
2024-12-13 14:44:35 +01:00
ThomasV
05266da707 lnwatcher: special-case non-anchor first stage htlcs 2024-12-12 10:52:21 +01:00
ThomasV
3b1dc194e4 Refactor lnsweep:
- txins have an optional make_witness method
 - instead of gen_tx, SweepInfo has a txin and
   an optional txout, for 1st stage HTLCs
 - sweep transactions are created by lnwatcher

The purpose of this change is to allow combining several
inputs in the same sweep transaction.
2024-12-11 17:14:14 +01:00
ThomasV
0e3b730cd9 lnsweep: remove dead code (we never sweep to_remote in non-anchor channels) 2024-12-11 10:56:27 +01:00
ThomasV
1da937f103 swaps: set nsequence in create_claim_tx (follow-up previous commit) 2024-12-11 10:24:40 +01:00
ThomasV
0599254e1f lnsweep and submarine_swaps: set txin.nsequence, instead of
calling set_rbf. set_rbf must be avoided if we batch transactions,
because it blindly overwrites nsequence of all txins.
2024-12-11 09:56:42 +01:00
ThomasV
6598507d3c lnwatcher: replace inspect_tx_candidate with get_spender.
inspect_tx_candidate assumes that htlc transactions have
only one input, which is not true for anchor channels.

inspect_tx_candidate is still used by the watchtower, because
it does not have access to channel information.
2024-12-11 09:33:47 +01:00
ThomasV
26ed696479 swaps: follow-up d838b6c9b9b4d669c81832f5be256aca148c89d7 2024-12-08 10:41:55 +01:00
ThomasV
8bec974a39 wallet: add inputs and base_tx parameters to make_unsigned_transaction 2024-12-08 09:54:10 +01:00
ThomasV
7b72655fba tx serialization: breakup tx witness into elements 2024-12-08 09:29:59 +01:00
ThomasV
62331aeb56 coin_chooser: make BIP69_sort optional 2024-12-04 11:24:06 +01:00
ThomasV
8bf505fc4b coin_chooser: allow to pass empty outputs to make_tx.
coins will be sent to a change address if there are no outputs.
2024-12-04 11:06:27 +01:00
ThomasV
9aa7222c5c swaps: let plugin override self.is_server (config variable may be ser and plugin not active) 2024-12-01 09:16:16 +01:00
ThomasV
acbb57036f Merge pull request #9327 from hishope/master
chore: fix 404 status URL
2024-11-29 10:42:36 +01:00
ThomasV
81baaa52cd CLI: raise UserFacingException when passed unknown channel point. fixes #9326 2024-11-29 10:38:57 +01:00
hishope
2a9ec0764d chore: fix 404 status URL
Signed-off-by: hishope <csqiye@126.com>
2024-11-29 17:09:29 +08:00
ThomasV
86c9eb4858 psbt_nostr: minor fix 2024-11-28 11:16:49 +01:00
bitromortac
dbfc27d73b watchtower: only send first-stage HTLC justice txs
Due to malleability of HTLC-transactions, we can't send presigned
justice transactions for the second-stage HTLC transactions, which is
why we now send first-stage justice transactions for anchor channels.
2024-11-26 10:00:21 +01:00
bitromortac
d535821516 htlctx: deal with possible peer htlctx batching
Due to anchor channel's sighash.SINGLE and sighash.ANYONECANPAY,
several HTLC-transactions can be combined. This means we must watch for
revoked outputs in the HTLC transaction not only at index 0 but at any
index.
2024-11-26 09:28:00 +01:00