Commit Graph

62 Commits

Author SHA1 Message Date
SomberNight 22a8348303 renames: use consistent naming of cltv delta vs cltv abs
to avoid confusing relative vs absolute cltvs
(see b0401a6386)
2023-10-19 16:40:05 +00:00
SomberNight 1a46460d11 fix sweeping chan after local force-close using cb
scenario:
- user opens a lightning channel and exports an "imported channel backup"
- user closes channel via local-force-close
  - local ctx is published, to_local output has user's funds and they are CSV-locked for days
- user restores wallet file from seed and imports channel backup
- new wallet file should be able to sweep coins from to_local output (after CSV expires)

This was not working previously, as the local_payment_basepoint was not included in the
imported channel backups, and the code was interpreting the lack of this as the channel not
having option_static_remotekey enabled. This resulted in lnutil.extract_ctn_from_tx
using an incorrect funder_payment_basepoint, and lnsweep not recognising the ctx due to
the garbage ctn value.

The imported channel backup serialisation format is slightly changed to include the
previously missing field, and its version number is bumped (0->1). We allow importing
both version 0 and version 1 backups, however v0 backups cannot handle the above
described scenario (they can only be used to request a remote-force-close).

Note that we were/are setting the missing local_payment_basepoint to the pubkey of
one of the wallet change addresses, which is bruteforceable if necessary, but I
think it is not worth the complexity to add this bruteforce logic. Also note
that the bruteforcing could only be done after the local-force-close was broadcast.

Ideally people with existing channels and already exported v0 backups should re-export
v1 backups... Not sure how to handle this.

closes https://github.com/spesmilo/electrum/issues/8516
2023-07-14 14:29:21 +00:00
SomberNight 0647a2cf9f transaction.py: rm PartialTxInput.{num_sig, script_type} 2023-03-03 16:40:12 +00:00
SomberNight f1f39f0e82 descriptors: wallet/transaction: construct intermediate osd 2023-03-01 17:53:52 +00:00
SomberNight f6dc72899a lnsweep: use chan.logger instead of module _logger
to log the chan id for free
2023-03-01 15:27:13 +00:00
SomberNight 373db76ac9 util: kill bh2u
no longer useful, and the name is so confusing...
2023-02-17 11:43:11 +00:00
ThomasV f20b371737 fix #7959 2022-08-31 11:03:04 +02:00
ThomasV 1f403d1ca1 remove support for channels without static remote pubkey 2022-08-16 08:48:59 +02:00
ThomasV 30a98578c8 Refactor: move calls to lnworker methods out of the tx creation functions
(follow-up f0237e46be)
2022-05-26 15:04:43 +02:00
ThomasV f0237e46be lnsweep: do not redeem offered HTLCs unless payment was received in full 2022-05-26 14:28:25 +02: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
ThomasV e186214f6f (formatting) lnsweep indentation 2021-03-12 12:41:10 +01:00
SomberNight 89bd520185 bitcoin: move construct_witness from transaction.py to bitcoin.py 2020-10-24 05:18:16 +02:00
ThomasV 368229a4c3 lnsweep: claim our_ctx_to_local if we breach 2020-06-18 11:33:44 +02:00
ThomasV abe1bece2c remove UnknownPaymentHash (exception used as value) 2020-05-02 22:37:28 +02:00
ThomasV f53a10084d create_sweeptxs_for_our_ctx: fix static_remotekey 2020-05-01 16:54:50 +02:00
SomberNight f5eb91900a use correct feerate when sweeping htlcs
fixes #6131
2020-04-30 19:37:06 +02:00
SomberNight 8e8ab775eb lnchannel: make AbstractChannel inherit ABC
and add some type annotations, clean up method signatures
2020-04-13 15:57:53 +02:00
ThomasV 8f41aeb783 Replace wallet backup with channel backups
- channels can be backed up individually
 - backups are added to lnwatcher
 - AbstractChannel ancestor class
2020-04-10 14:45:23 +02:00
ThomasV 2255b07157 support option_static_remotekey 2020-02-20 21:02:01 +01:00
ThomasV dbceed2647 Restructure wallet storage:
- Perform json deserializations in wallet_db
 - use StoredDict class that keeps tracks of its modifications
2020-02-04 13:35:58 +01:00
ThomasV 757467782a Use attr.s instead of namedtuples for channel config 2020-01-31 12:19:26 +01:00
SomberNight bafe8a2fff integrate PSBT support natively. WIP 2019-11-04 22:24:36 +01:00
SomberNight 04edad9984 config: no longer singleton. it is passed to Wallet.__init__
The few other cases that used SimpleConfig.get_instance() now
either get passed a config instance, or they try to get a reference
to something else that has a reference to a config.
(see lnsweep, qt/qrcodewidget, qt/qrtextedit)
2019-09-22 20:46:01 +02:00
SomberNight befa8ea771 transaction: kill "name", "csv_delay", "cltv_expiry" fields 2019-09-09 19:38:35 +02:00
SomberNight 83fcdbd561 lnchannel: handle htlc-address collisions
We were previously generating an incorrect commitment_signed msg if there were
multiple htlcs sharing the same scriptPubKey.
2019-09-07 08:54:41 +02:00
ThomasV 6197cfbb3b Revert "Remove early return in create_sweeptxs_for_our_ctx."
This reverts commit d0cfb3ae12.
2019-08-30 17:40:46 +02:00
ThomasV d0cfb3ae12 Remove early return in create_sweeptxs_for_our_ctx.
- This was added because we did not store the complete htlc history.
 - It makes the result dependent on the current channel state
 - That creates a race condition in sweep_info, because the result is cached.
 - As a result, test_breach_with_spent_htlc was randomly failing.
2019-08-30 09:11:54 +02:00
SomberNight b1f606eaed lnchannel: start using "latest" and "next" instead of "current" and "pending"
"current" used to be "oldest_unrevoked"; and pending was "oldest_unrevoked + 1"
but this was very confusing...
so now we have "oldest_unrevoked", "latest", and "next"
where "next" is "latest + 1"
"oldest_unrevoked" and "latest" are either the same or are offset by 1
(but caller should know which one they need)

rm "got_sig_for_next" - it was a redundant sanity check, that really
just complicated things

rm "local_commitment", "remote_commitment", "set_local_commitment",
"set_remote_commitment" - just use "get_latest_commitment" instead
2019-08-20 09:03:12 +02:00
SomberNight 944e4f0ba0 implement data_loss_protect
so that we can spend their_ctx_to_remote even when we lost our state
but have an old backup
2019-08-20 09:03:12 +02:00
ThomasV f7c05f2602 Synchronize watchtower asynchronously:
- remove remote_commitment_to_be_revoked
- pass old ctns to lnsweep.create_sweeptxs_for_watchtower
- store the ctn of sweeptxs in sweepStore database
- request the highest ctn from sweepstore using get_ctn
- send sweeptxs asynchronously in LNWallet.sync_with_watchtower
2019-08-20 09:03:12 +02:00
ThomasV a8ce8109be Perform breach remedy without sweepstore:
- add functions to lnsweep
 - lnworker: analyze candidate ctx and htlc_tx
 - watchtower will be optional
 - add test for breach remedy with spent htlcs
 - save tx name as label
2019-08-20 09:03:12 +02:00
ThomasV dff1822c37 fix watchtower: sweep_tx must not be None 2019-08-20 09:03:12 +02:00
ThomasV d9b041e64d encapsulate detect_who_closed in channel 2019-08-20 09:03:11 +02:00
ThomasV 740ef09883 simplify_lnsweep 2019-08-20 09:03:11 +02:00
ThomasV 3349e941de lnsweep: minor fix 2019-08-20 09:03:11 +02:00
ThomasV 81d340b19c lnworker: do not create sweep transactions before outputs can be redeemed 2019-08-20 09:03:11 +02:00
ThomasV 8d99fe8243 Let lnworker sweep HTLC outputs after breach, instead of lnwatcher 2019-08-20 09:03:11 +02:00
ThomasV 7be4cdaf18 redeem htlcs:
- fix bug in lnsweep: lnwatcher transactions were indexed by prev_txid
 - add test for breach remedy with unsettled htlcs
 - add timeout option to lnpay, and replace DO_NOT_SETTLE with SETTLE_DELAY
   so that we can read intermediate commitment tx in regtest
2019-08-20 09:03:11 +02:00
ThomasV 7418bd4552 lnsweep: simplify a few methods 2019-08-20 09:03:11 +02:00
ThomasV 6bbdbf7596 rework on_channel_closed in LNWorker:
- use detect_who_closed; this allows us to redeem to_remote of breach ctx
 - do not redeem to_local of breach ctx, because it is redundant with lnwatcher
 - rename a few methods
2019-08-20 09:03:11 +02:00
SomberNight 930d21c31c channel close handling: detect situation based on output addresses
WIP...
2019-08-20 09:03:11 +02:00
SomberNight cc57da704b logging: adapt lightning branch to logging changes 2019-08-20 09:03:11 +02:00
ThomasV 3e443535a2 lnchannel: pass reference to lnworker 2019-08-20 09:03:11 +02:00
ThomasV 62be0c481c lightning: Save invoices and preimages separately. Save preimages when forwarding 2019-08-20 09:03:11 +02:00
ThomasV 3dce65dc73 Rename lnchan, lnchannel_verifier, lnbase
Auto-completions are a pain if files share a long prefix
2019-08-20 09:03:11 +02:00
Janus 8fc1779b0d ln: add test_lnwatcher 2019-08-20 09:03:11 +02:00
Janus 51bc02557d ln: fix sweeping htlc output from remote ctx (timeout e.g. without htlc tx) 2019-08-20 09:03:11 +02:00
Janus e56e849505 lnchan refactor
- replace undoing logic with new HTLCManager class
- separate SENT/RECEIVED
- move UpdateAddHtlc to lnutil
2019-08-20 09:03:11 +02:00
Janus 3ccd2fedff ln: two remaining encumberedTx removal remnants 2019-08-20 09:03:11 +02:00