Commit Graph

115 Commits

Author SHA1 Message Date
ThomasV 0966edc637 fine-grained callbacks for lightning network dialog 2019-10-12 19:15:51 +02:00
ThomasV dd0be1541e Improve handling of lightning payment status:
- Move 'handle_error_code_from_failed_htlc' to channel_db,
and call it from pay_to_route, because it should not be
called when HTLCs are forwarded.
- Replace 'payment_received' and 'payment_status'
callbacks with 'invoice_status' and 'request_status'.
- Show payment error logs in the Qt GUI
- In the invoices list, show paid invoices for which
we still have the log.
2019-10-11 17:51:33 +02:00
ThomasV d6d644190e lnworker: return error reason in await_payment 2019-10-11 13:37:54 +02:00
ThomasV c4ab1e6fad Encapsulate lightning payment events:
- make LNWorker.pending_payments private
 - public methods: payment_sent, payment_received, await_payment
2019-10-11 10:18:28 +02:00
ThomasV 638de63f13 lnworker: rename 'invoices' to 'payments' when they can be in both directions 2019-10-09 20:16:11 +02:00
ThomasV 788d54f9a6 remove another instance of lnworker accessed in lnchannel 2019-10-09 19:54:43 +02:00
ThomasV 8331f0049c Remove lnpeer.payment_preimages:
- we can await lnworker.pending_payments instead, because the preimage is saved
 - also, remove one instance of lnworker being accessed from lnchannel
2019-10-09 19:40:25 +02:00
ThomasV f08e5541ae Refactor invoices in lnworker.
- use InvoiceInfo (NamedTuple) for normal operations,
   because lndecode operations can be very slow.
 - all invoices/requests are stored in wallet
 - invoice expiration detection is performed in wallet
 - CLI commands: list_invoices, add_request, add_lightning_request
 - revert 0062c6d695 because it forbids self-payments
2019-09-22 16:06:53 +02:00
SomberNight b2920db8b8 config: enforce that SimpleConfig is singleton
related: #5629
2019-09-10 18:01:10 +02:00
ThomasV cefa4762ba do not create multiple instances of SimpleConfig (fix #5629). Add config field to wallet 2019-09-10 08:57:40 +02:00
ThomasV 35761d1241 Save remote policy of chanel in wallet file (for private channels) 2019-09-08 19:14:28 +02:00
SomberNight 00f15d491b lnpeer: somewhat nicer log messages 2019-09-07 07:29:22 +02:00
SomberNight 509df9ddaf create class for ShortChannelID and use it 2019-09-06 18:09:05 +02:00
SomberNight edf186da0d channeldb.load_data: attempt at fixing race
closes #5525
2019-09-05 18:32:45 +02:00
SomberNight 4f741cfccc lnpeer: longer timeouts 2019-09-05 18:31:51 +02:00
ThomasV e286ed1c13 add_own_channel does not need to be async 2019-09-03 21:01:45 +02:00
SomberNight 956bd3baaf lnpeer: make per-peer TaskGroup a field (as for interfaces), and use it
lnpeer (and interface) response-handling-code should not run in the
network main_taskgroup as the remote could force an exception
to be raised and that would kill the whole network instead of just the peer
2019-08-30 19:51:17 +02:00
SomberNight f403735191 lnpeer: reestablish_channel - don't replay unacked msgs they alrdy have
e.g. Alice sends upd1, upd2, upd3, commitment_signed, upd4, upd5.
Bob receives all of these; and sends a revoke_and_ack but there is
a disconnect before Alice receives the revoke_and_ack.
During reestablish, if Bob claims to have received the commitment_signed,
Alice must not replay the msgs before that; but she should replay upd4 and upd5.
2019-08-29 12:37:25 +02:00
ThomasV 65cf0ebce8 lnpeer, minor fixes:
- pass orphaned_ids to lnworker.add_new_ids
 - fix enumeration of get_unacked_local_updates()
2019-08-20 13:27:09 +02:00
SomberNight bce74717a6 lnpeer: in onion errors, handle channel updates both with and w/o type 2019-08-20 09:03:12 +02:00
SomberNight beeb81e179 lnpeer: use correct failure codes in _maybe_forward_htlc 2019-08-20 09:03:12 +02:00
SomberNight e54f0fbafa do not raise BaseException 2019-08-20 09:03:12 +02:00
SomberNight 47ee02569a lnpeer: send own outgoing channel updates to remote peer 2019-08-20 09:03:12 +02:00
SomberNight f0588846d5 channeldb: also store "message_flags" field for channel updates
this is a breaking change for the db format.
As in comment in diff,
"It would make more sense to store the raw gossip messages in the db."
2019-08-20 09:03:12 +02:00
SomberNight d229bb4e4d lnpeer: restore "temp save orphan channel updates" functionality
needed to handle race where remote might send chan_upd too soon
(before we save the short channel id for the channel after it reaches funding locked)
2019-08-20 09:03:12 +02:00
SomberNight 159fe04daf lnpeer: on_channel_open should not fail on server error 2019-08-20 09:03:12 +02:00
SomberNight a9239bd40f lnpeer: shutdown should wait until no HTLCs remain
in either ctx
2019-08-20 09:03:12 +02:00
SomberNight 2e38bcf416 lnpeer: failed htlc error handling ignored length of channel_update 2019-08-20 09:03:12 +02:00
SomberNight d2d4d19fcb lnpeer: add a few sanity checks to payment-forwarding (and related) 2019-08-20 09:03:12 +02:00
SomberNight 8ad25b3a52 lnpeer: make sure forwarding is disabled by default 2019-08-20 09:03:12 +02:00
SomberNight a27b03be6d lnhtlc: local update raw messages must not be deleted before acked
In recv_rev() previously all unacked_local_updates were deleted
as it was assumed that all of them have been acked at that point by
the revoke_and_ack itself. However this is not necessarily the case:
see new test case.

renamed log['unacked_local_updates'] to log['unacked_local_updates2']
to avoid breaking existing wallet files
2019-08-20 09:03:12 +02:00
SomberNight 4fc9f243f7 lnpeer: reestablish_channel - always replay unacked local updates
Even if we haven't signed them yet (did not send commitment_signed).
Alternatively, if they are not yet signed, we could discard them here,
like we do already for remote updates above (chan.hm.discard_unsigned_remote_updates).
One of these two options must be done, and before this commit we were not doing either.
2019-08-20 09:03:12 +02:00
ThomasV 9f8e2c689e test funding_txn_minimum_depth, show it in GUI 2019-08-20 09:03:12 +02:00
ThomasV bbec1dceda lnpeer: fix and simplify tests in maybe_send_commitment 2019-08-20 09:03:12 +02:00
SomberNight bb63bd98fb lnpeer: should not mark channel as OPEN if reestablish did not complete 2019-08-20 09:03:12 +02:00
SomberNight 940fc86749 lnpeer: reestablish_channel - fix data_loss_protect edge case 2019-08-20 09:03:12 +02:00
SomberNight 107f271e58 move all ctn book-keeping to lnhtlc (from lnchannel) 2019-08-20 09:03:12 +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
SomberNight fdf8d8609b lnpeer: make feature-bit testing easier
so that we can always test like: self.localfeatures & FEATURE_BIT_OPT
2019-08-20 09:03:12 +02:00
SomberNight 014b921393 lnpeer: reestablish_channel - replay un-acked local updates
Replay un-acked local updates (including commitment_signed) byte-for-byte.
If we have sent them a commitment signature that they "lost" (due to disconnect),
we need to make sure we replay the same local updates, as otherwise they could
end up with two (or more) signed valid commitment transactions at the same ctn.
Multiple valid ctxs at the same ctn is a major headache for pre-signing spending txns,
e.g. for watchtowers, hence we must ensure these ctxs coincide.
2019-08-20 09:03:12 +02:00
SomberNight e81ae1921b lnpeer: reestablish_channel - discard unsigned remote updates 2019-08-20 09:03:12 +02:00
SomberNight c046f2cc1c lnhtlc: move 'next_htlc_id' from ChannelConfig to lnhtlc log 2019-08-20 09:03:12 +02:00
SomberNight c8b19aec2a lnpeer: make reestablish_channel saner
clear up expectations about ctns
2019-08-20 09:03:12 +02:00
SomberNight bdbc662a36 lnpeer: channel_reestablished is now a queue (instead of future) 2019-08-20 09:03:12 +02:00
SomberNight 0d84873a75 lnchannel: trivial clean-up 2019-08-20 09:03:12 +02:00
ThomasV fa3eefa479 refactor a few lnchannel methods 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
SomberNight f060e53912 (trivial) fix type annotation 2019-08-20 09:03:12 +02:00
SomberNight 087994e39a lnchannel: move fee update logic to lnhtlc (and hopefully fix it) 2019-08-20 09:03:12 +02:00