Commit graph

100 commits

Author SHA1 Message Date
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
ThomasV
3d7f7dfc82 revamp fee updates (draft) 2019-08-20 09:03:12 +02:00
SomberNight
7431aac5cd lnhtlc: (fix) was locking in too many updates during commit/revoke 2019-08-20 09:03:12 +02:00
ThomasV
b55f9e9e6a Do not route through channels for which we did not receive
both updates, because this often means one of the nodes is
offline.
2019-08-20 09:03:12 +02:00
ThomasV
2be68ac4d2 Use one LNWatcher instance per wallet 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
f2d58d0e3f optimize channel_db:
- use python objects mirrored by sql database
 - write sql to file asynchronously
 - the sql decorator is awaited in sweepstore, not in channel_db
2019-08-20 09:03:12 +02:00
ThomasV
06b5299b0f comment out convert, add logging statement 2019-08-20 09:03:12 +02:00
SomberNight
7e8be3d2e7 lnpeer: some exception handling clean up
main_loop should dump traces of unexpected exceptions to log.
Coroutines/functions invoked inside main_loop should simply propagate it
up the chain.
Typical exceptions are handled in handle_disconnect without dumping the trace.
2019-08-20 09:03:12 +02:00
ThomasV
70cd29f9e1 GUI refactoring for Kivy and lightning.
This also touches Qt and wallet code.
2019-08-20 09:03:12 +02:00
ThomasV
67f1ade798 send data_loss_protect fields if we support it 2019-08-20 09:03:12 +02:00
ThomasV
9eddb9844c on_commitment_signed: distinguish between exceptions 2019-08-20 09:03:11 +02:00
SomberNight
69bffac86a lnhtlc: fix adding htlc between sending commitment_signed and receiving revoke_and_ack 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
SomberNight
acbb458ef7 set default to_self_delay to 1 day 2019-08-20 09:03:11 +02:00
SomberNight
6d8c605307 move lnworker.first_block to constants 2019-08-20 09:03:11 +02:00