Commit graph

330 commits

Author SHA1 Message Date
SomberNight
5c8455d00b
lnchannel: when adding HTLCs, run checks for both directions 2020-03-26 09:05:08 +01:00
SomberNight
01207316aa
storage upgrade: move "htlc_minimum_msat" to base channel config 2020-03-26 09:05:04 +01:00
SomberNight
53c6fc8cf1
lnchannel: test for max htlc value (needs to be below protocol maximum) 2020-03-26 09:05:00 +01:00
SomberNight
777e350fae
lnchannel: partly fix available_to_spend
we were looking at inconsistent ctns
and we were looking at the wrong subject's ctx

all the FIXMEs and TODOs here will still warrant some attention.

(note that test_DesyncHTLCs was passing incorrectly:
the "assertRaises" was catching a different exception)
2020-03-26 09:04:55 +01:00
SomberNight
2cc76fbbbd
lnworker: fix type error re pending_payments, and impl malformed htlcs
In old code, in lnpeer.htlc_switch(), "error" in lnworker.pending_payments
had incorrect type.

TODO: we need tests for payment failures...
2020-03-17 20:32:38 +01:00
SomberNight
5e59d1a0ed
lnonion: use random starting bytes in Sphinx packet as in updated BOLT4
see https://github.com/lightningnetwork/lightning-rfc/pull/697
2020-03-16 04:37:52 +01:00
ThomasV
fe2b40b83d Fix #6021: Do not transition channel state to CLOSED if tx is unconfirmed. 2020-03-11 11:49:53 +01: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
8eaf0004e1 follow-up 17a893441a: fix regtest 2020-03-06 10:26:11 +01:00
SomberNight
2aebcc5e26
commands: gate get_channel_ctx behind --iknowwhatimdoing 2020-03-05 17:27:43 +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
SomberNight
dae842e2ad
tests: made TestLNTransport.test_loop more robust 2020-03-04 17:57:40 +01:00
SomberNight
cdb72509a7
lnrouter: change edge cost estimate (distance metric)
Old estimate was heavily biased towards simply minimising CLTV sum.
(fees had a too low weight; typically they were ~noise)
Now also take payment_amount into account.
2020-03-03 02:12:42 +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
SomberNight
8560930bac
transaction: (fix) invalidate ser cache when changing locktime/version
we can keep the same API, using @property,
instead of introducing getters and setters
2020-03-01 09:57:59 +01:00
ThomasV
077f778632 Replace lightning_settle_delay with enable_htlc_settle (asyncio.Event) 2020-02-28 10:15:28 +01:00
SomberNight
ed234d3444
rename all TaskGroup() fields to "taskgroup"
for consistency
2020-02-27 19:13:56 +01:00
ThomasV
e159b1d468 test_close: add unsettled htlc (fails with the current code) 2020-02-27 13:41:40 +01:00
SomberNight
c744fc4e3d
follow-up prev: do all checks, and add tests 2020-02-27 05:13:31 +01:00
SomberNight
6703521f56
rm more cruft from test_lnchannel
follow-up e54c69b861
2020-02-27 02:53:03 +01:00
SomberNight
e54c69b861
add lnchannel.can_send_ctx_updates. just drop illegal updates for now 2020-02-26 20:35:46 +01:00
ghost43
28572197fb
Merge pull request #5992 from zebra-lucky/fix_spv_hash_merkle_root
fix SPV.hash_merkle_root, add tests/test_verifier.py
2020-02-25 19:56:27 +00:00
SomberNight
4f5f949979
follow-up prev
Clean up tests a bit, and rm some of them.
It's overkill to test with SPV._raise_if_valid_tx mocked out.
2020-02-25 20:45:17 +01:00
SomberNight
6937b87a7c
transaction.BCDataStream: minor fixes
- fix read/write_boolean (though unused...)
- sanity check in read_bytes
2020-02-25 20:05:46 +01:00
zebra-lucky
c0be0471f2
fix BCDataStream.read_bytes (#5991)
* fix BCDataStream.read_bytes

* followup fix BCDataStream.read_bytes: fix TestBCDataStream.test_bytes
2020-02-25 18:58:03 +00:00
zebra-lucky
d4f7c207a7 fix SPV.hash_merkle_root, add tests/test_verifier.py 2020-02-25 20:06:11 +02: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
SomberNight
16626a3386
lnutil.split_host_port: fix for IPv6 connection string 2020-02-17 19:43:21 +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
SomberNight
ab4e2dd9f0
wallet: fix is_mine/can_sign. don't just rely on ks, also check script
Previously a standard (single-sig) wallet would consider a multisig txin as is_mine
(if the keystore found its pubkey in the txin).

fixes #5948
2020-02-12 18:14:07 +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
SomberNight
de1ca27d63
tests: rm "needs_test_with_all_ecc_implementations" decorator
now libsecp256k1 is the only implementation
2020-02-11 16:46:31 +01:00
SomberNight
0a5ad9fda4
ecc: small API clean-up 2020-02-11 16:42:02 +01:00
SomberNight
2cf2135528
ecc: abstract away some usage of python-ecdsa: bytes<->int conversions 2020-02-11 16:41:49 +01:00