Commit graph

247 commits

Author SHA1 Message Date
ThomasV
9ff1bd4110 fix test following aac0fe9ae6 2019-10-22 18:54:00 +02:00
SomberNight
d9b5ab3086
wallet: fix bump_fee when there are only change outputs
closes #5718
closes #5603
2019-10-22 17:12:23 +02:00
ThomasV
90ce9f195b Allow user to enable lightning in the GUI. Make it a per-wallet setting. 2019-10-13 20:34:38 +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
7c283f9cd2
fix tests: follow-up prev 2019-10-01 20:42:34 +02:00
SomberNight
ec372adbb9
tests: fix test_find_path_for_payment. need to close sqlite connection
test was sometimes randomly failing
(always on Windows, as it's illegal to rm open files there)
2019-09-22 21:21:24 +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
SomberNight
65d896be5a
ecc: also use libsecp256k1 for point addition
time taken to add points changes to around 35% of what it was with python-ecdsa

-----

# benchmark runs before:
> python3.7-64 ..\wspace\201909_libsecp256k1_point_addition\bench.py
time taken: 3.7693 seconds
> python3.7-64 ..\wspace\201909_libsecp256k1_point_addition\bench.py
time taken: 3.8123 seconds
> python3.7-64 ..\wspace\201909_libsecp256k1_point_addition\bench.py
time taken: 3.7937 seconds

# benchmark runs after:
> python3.7-64 ..\wspace\201909_libsecp256k1_point_addition\bench.py
time taken: 1.3127 seconds
> python3.7-64 ..\wspace\201909_libsecp256k1_point_addition\bench.py
time taken: 1.3000 seconds
> python3.7-64 ..\wspace\201909_libsecp256k1_point_addition\bench.py
time taken: 1.3128 seconds

-----

# benchmark script:

import os
import time
from electrum.ecc import generator
from electrum.crypto import sha256

rand_bytes = os.urandom(32)
#rand_bytes = bytes.fromhex('d3d88983b91ee6dfd546ccf89b9a1ffb23b01bf2eef322c2808cb3d951a3c116')
point_pairs = []
for i in range(30000):
    rand_bytes = sha256(rand_bytes)
    rand_int = int.from_bytes(rand_bytes, "big")
    a = generator() * rand_int
    rand_bytes = sha256(rand_bytes)
    rand_int = int.from_bytes(rand_bytes, "big")
    b = generator() * rand_int
    point_pairs.append((a,b))

t0 = time.time()
for a, b in point_pairs:
    c = a + b
t = time.time() - t0
print(f"time taken: {t:.4f} seconds")
2019-09-16 20:43:13 +02:00
SomberNight
9eee36fe00
follow-up prev 2019-09-10 20:18:53 +02:00
SomberNight
098636c69a
fix tests 2019-09-10 19:39:52 +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
SomberNight
befa8ea771
transaction: kill "name", "csv_delay", "cltv_expiry" fields 2019-09-09 19:38:35 +02:00
SomberNight
712c3f1248
commands: try to fix tests 2019-09-05 23:22:11 +02:00
SomberNight
58681e4d07
follow-up prev (commands) 2019-09-05 18:30:04 +02:00
SomberNight
1bd9b3a66a
commands: fix "restore" cmd
Previously commands did not run on the asyncio thread but now they do.
"restore" was polling like "while 1: time.sleep()", blocking the event loop.

Now "restore" does not sync the wallet; which is actually cleaner
as previously this wallet would never get unloaded from the daemon (syncing forever).

This is also symmetric with the "create" cmd which also does not try to sync with the network.

However now it became difficult to write a script that restores a wallet and wants to wait
until it gets synced. Workaround for now is to poll with "list_wallets" whether it's synced.

We could create a new command that blocks until the loaded wallet gets synced.
2019-09-04 20:15:54 +02:00
ThomasV
7f870f5e09 replace daemon 'start' subdommand with -d 2019-09-02 19:04:08 +02:00
ThomasV
e79253b5e0 Syntax change: Require --offline to run commands without a daemon.
That makes the syntax less ambiguous. It also makes it possible to
implement a CLI that does not import all the electrum modules.
2019-08-31 09:24:00 +02:00
ThomasV
c67fb88e58 remove redundant 'stop' in regtest setUp (should run a bit faster) 2019-08-31 08:49:31 +02:00
ThomasV
3e8080b669 test_breach_with_spent_htlc: do not overwrite default_wallet, load toxic_wallet instead 2019-08-30 17:40:09 +02:00
ThomasV
10e186c1d3 revert ed086934e5
(this does not work well with travis)
2019-08-30 15:58:38 +02:00
ThomasV
6f333bd86d make regtests more robust 2019-08-30 15:18:04 +02:00
Jin Eguchi
523de5782b
Fix travis error 2019-08-29 04:32:32 +09:00
ThomasV
cf02e32f20
Merge pull request #5537 from xaya/test-verify-header
Unit tests for Blockchain.verify_header
2019-08-26 15:42:15 +02:00
ThomasV
58177c5bf3 Travis: run regtests in separate job 2019-08-26 13:52:55 +02:00
ThomasV
95383a5820
Merge pull request #5582 from JeremyRand/test-lnchannel-outputs
Use NamedTuple notation for TxOutput in test_lnchannel
2019-08-25 10:17:54 +02:00
JeremyRand
032810dace
test_lnrouter: Pull in chain_hash from constants 2019-08-25 07:19:36 +00:00
JeremyRand
334d3f2818
Use NamedTuple notation for TxOutput in test_lnchannel
This makes the code more resilient in case additional members are added
to TxOutput later.
2019-08-25 06:51:31 +00:00
ThomasV
246cda2928 fix Flake8 tests 2019-08-20 09:03:12 +02:00
ThomasV
9cfeadea70 Turn daemon subcommands into RPCs 2019-08-20 09:03:12 +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
SomberNight
02681c6664 tests: some regtest tests need to mine more blocks to expire CLTVs
as lnutil.MIN_FINAL_CLTV_EXPIRY_FOR_INVOICE was recently bumped
2019-08-20 09:03:12 +02:00
SomberNight
a9295e495c tests: regtest.sh now uses consistent indentation 2019-08-20 09:03:12 +02:00
SomberNight
ce54b5411e lnhtlc: htlcs_by_direction now returns dict keyed by htlc_id 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
107f271e58 move all ctn book-keeping to lnhtlc (from lnchannel) 2019-08-20 09:03:12 +02:00
SomberNight
44761972cb lnchannel: ctx output-ordering: identical htlcs are ordered by CLTV 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
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
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
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
4d76e84218 improve regtest.sh with wait functions 2019-08-20 09:03:12 +02:00