Commit graph

60 commits

Author SHA1 Message Date
SomberNight
54e1520ee4
ln: check if chain tip is stale when receiving HTLC
if so, don't release preimage / don't forward HTLC
2020-04-13 17:04:27 +02:00
SomberNight
12283d625b
(trivial) rename lnchannel.channel_states to ChannelState 2020-04-13 16:02:05 +02:00
ThomasV
e50f6d29ed export channel backup from kivy gui 2020-04-10 20:04:24 +02:00
SomberNight
7dabbdd082
tests_lnpeer: trivial fix 2020-04-08 13:18:56 +02:00
ThomasV
d2a58a2ec3 lnpeer: do not assume our privkey is the same as lnworker's privkey. 2020-04-06 19:06:27 +02:00
SomberNight
1be0a710c3
ln: implement option payment_secret 2020-04-01 21:49:12 +02:00
SomberNight
6ba08cc8d4
ln feature bits: flatten namespaces, and impl feature deps and ctxs
This implements:
- flat feature bits https://github.com/lightningnetwork/lightning-rfc/pull/666
- feature bit dependencies https://github.com/lightningnetwork/lightning-rfc/pull/719
2020-04-01 21:41:24 +02:00
SomberNight
c69937395e
lnmsg: add more tests (for encode_msg, decode_msg) 2020-04-01 21:40:13 +02:00
ThomasV
beac1c4ddc channel_db: raise specific exception if database is not loaded when we try to find a route 2020-03-10 15:13:20 +01:00
ThomasV
2f31e9fa44 follow-up prev commit 2020-03-10 13:51:08 +01:00
SomberNight
c95c0dcb80
lnrouter: add comments about path-finding blocking the asyncio loop 2020-03-09 20:39:13 +01:00
SomberNight
5b23d5ee97
lnchannel/lnhtlc: speed up balance calculation for recent ctns
Move the balance calculation from lnchannel to lnhtlc.
Maintain a running balance in lnhtlc that is coupled with _maybe_active_htlc_ids
for practicality reasons.
2020-03-07 05:05:05 +01:00
SomberNight
ec7473789e
lnhtlc: speed-up methods for recent ctns
we maintain a set of interesting htlc_ids
2020-03-06 21:54:05 +01:00
ThomasV
fbf6af5d07 fix test_lnpeer 2020-03-06 12:40:42 +01:00
ThomasV
584e0a38aa follow-up previous commit: fix test_lnpeer 2020-03-06 12:29:39 +01:00
ThomasV
dbd77b7d8e
Merge pull request #6014 from SomberNight/20200304_pycryptodomex
add 'cryptography' as optional dependency; clean README and sdist
2020-03-05 09:17:42 +01:00
ThomasV
8f3fcdd1a8 Fix detection of payments.
1. In lnhtlc, sent_in_ctn and failed_in_ctn need to look at the
remote ctx, and they need to be called when we receive a revocation,
not when we send one.

2. In lnchannel, we use 3 lnworker callbacks:
   - payment sent/payment failed (called when we receive a revocation)
   - payment received (called when we send a revocation)

3. Make revoke_current_commitment return a single value.
The second value was only used in tests, there is no need
to bloat the code with that
2020-03-05 07:03:09 +01:00
ThomasV
b9eaba3e85 replace await_local/remote 2020-03-05 07:03:09 +01:00
SomberNight
74a3faf803
crypto: add 'cryptography' as alt dependency for 'pycryptodomex' 2020-03-04 18:54:20 +01:00
ThomasV
f801307a08 move htlc_switch task to lnpeer 2020-03-02 15:41:50 +01:00
ThomasV
da67fda92a HTLC switch:
- fulfills/fails/forwards HTLCs
- onion_packets are saved when update_add_htlc is received
2020-03-02 11:19:04 +01:00
ThomasV
077f778632 Replace lightning_settle_delay with enable_htlc_settle (asyncio.Event) 2020-02-28 10:15:28 +01:00
ThomasV
e159b1d468 test_close: add unsettled htlc (fails with the current code) 2020-02-27 13:41:40 +01:00
SomberNight
e54c69b861
add lnchannel.can_send_ctx_updates. just drop illegal updates for now 2020-02-26 20:35:46 +01:00
ThomasV
2927478192 lnpeer: closing fee negociation:
- use fee_rate from config
 - set upper bound on fee
 - add test_close to test_lnpeer
2020-02-25 15:23:15 +01:00
SomberNight
5fda2cbb42
fix test: test_reestablish_with_old_state
Messages sent as part of the payment were getting interleaved with the channel_reestablish.
It does not actually make sense to do a payment and then reestablish the channel in the same transport -- the channel is supposed to already have been reestablished to do a payment in the first place.
So, after payment, strip down the transport, and set up a new transport before reestablishing.

Traceback (most recent call last):
  File "...\Python\Python38\lib\unittest\case.py", line 60, in testPartExecutor
    yield
  File "...\Python\Python38\lib\unittest\case.py", line 676, in run
    self._callTestMethod(testMethod)
  File "...\Python\Python38\lib\unittest\case.py", line 633, in _callTestMethod
    method()
  File "...\electrum\electrum\tests\test_lnpeer.py", line 262, in test_reestablish_with_old_state
    run(f())
  File "...\electrum\electrum\tests\test_lnpeer.py", line 302, in run
    return asyncio.run_coroutine_threadsafe(coro, loop=asyncio.get_event_loop()).result()
  File "...\Python\Python38\lib\concurrent\futures\_base.py", line 439, in result
    return self.__get_result()
  File "...\Python\Python38\lib\concurrent\futures\_base.py", line 388, in __get_result
    raise self._exception
  File "...\electrum\electrum\tests\test_lnpeer.py", line 260, in f
    await gath
  File "...\electrum\electrum\lnpeer.py", line 439, in _message_loop
    self.process_message(msg)
  File "...\electrum\electrum\lnpeer.py", line 159, in process_message
    execution_result = f(payload)
  File "...\electrum\electrum\lnpeer.py", line 1308, in on_revoke_and_ack
    chan.receive_revocation(rev)
  File "...\electrum\electrum\lnchannel.py", line 556, in receive_revocation
    raise Exception('revoked secret not for current point')
Exception: revoked secret not for current point
2020-02-24 21:09:34 +01:00
SomberNight
46d8080c76
ln gossip: don't put own channels into db; always pass them to fn calls
Previously we would put fake chan announcement and fake outgoing chan upd
for own channels into db (to make path finding work). See Peer.add_own_channel().
Now, instead of above, we pass a "my_channels" param to the relevant ChannelDB methods.
2020-02-17 20:38:41 +01:00
ThomasV
36f32651cc Define network.try_broadcasting() method.
Use it when rebroadcasting a force-close tx,
because the channel state is already set.
2020-02-16 12:59:09 +01:00
ThomasV
88d5cdf87c fix test_lnpeer 2020-02-15 16:28:15 +01:00
ThomasV
9734546fe9 test_lnpeer: use less side-effects 2020-02-12 10:32:55 +01:00
ThomasV
e3630d87b2 test_lnpeer: test_reestablish_with_old_state 2020-02-12 10:22:22 +01:00
ThomasV
69ef9aa3d7 channel_reestablish: assume that DLP is enabled, because we require it 2020-02-11 21:39:23 +01:00
ThomasV
ece75c3244 test_lnpeer: simple test of channel_reestablish 2020-02-11 19:53:21 +01:00
ThomasV
e1ce3aace7 Separate db from storage
- storage is content-agnostic
 - db and storage are passed to wallet contructor
2020-02-10 17:45:23 +01:00
SomberNight
308517d473
python 3.8: adapt to breaking changes re asyncio.CancelledError
(and TimeoutError)

closes #5798
2019-12-11 23:07:47 +01:00
Janus Troelsen
3ac8f461a9 Tests: Remove on_channels_updated (#5819) 2019-12-04 19:40:52 +00:00
ThomasV
61dfcba092 Refactor channel states:
- persisted states are saved
 - state transitions are checked
 - transient states are stored in channel.peer_state
 - new channel states: 'PREOPENING', 'FUNDED' and 'REDEEMED'
 - upgrade storage to version 21
2019-11-22 20:14:54 +01:00
ThomasV
9ff1bd4110 fix test following aac0fe9ae6 2019-10-22 18:54:00 +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
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
bcb10e6e53 remove redundant test from lnworker._pay, rename pay_to_route parameter to lnaddr 2019-10-04 18:06:53 +02: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
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
ThomasV
54257cbcca Rewrite JsonRPC requests using asyncio.
- commands are async
 - the asyncio loop is started and stopped from the main script
 - the daemon's main loop runs in the main thread
 - use jsonrpcserver and jsonrpcclient instead of jsonrpclib
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
6d9ef29690 redo LNWorker pay:
- wait until htlc has been fulfilled
 - raise if htlc is not fulfilled
 - return boolean success
 - try multiple paths in GUI
2019-08-20 09:03:11 +02:00
ThomasV
3c0df28c98 do not include 'force_closing' in channel states, because it is not part of the peer protocol 2019-08-20 09:03:11 +02:00
ThomasV
95376226e8 save lightning invoice descriptions as labels and allow user to edit them 2019-08-20 09:03:11 +02:00
SomberNight
e4ed15f683 fix tests 2019-08-20 09:03:11 +02:00