Commit Graph

4850 Commits

Author SHA1 Message Date
Rusty Russell 8238fe6acf common/json: only maintain array of nested types if DEVELOPER mode.
My test case is a mainnet gossip store with 22107 channels, and
time to do `lightning-cli listchannels`:

Before: `lightning-cli listchannels` DEVELOPER=0
	real	0m1.396000-1.409000(1.4022+/-0.005)s

After:
	real	0m1.307000-1.320000(1.3128+/-0.005)s

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-19 22:02:11 +00:00
Rusty Russell 20bed28759 jsonrpc: use empty flag instead of examining the tail of the JSON.
This is in preparation for streaming directly to the JSON RPC buffer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-19 22:02:11 +00:00
Rusty Russell 305795b01e common/json: move JSON creation routines into lightningd/
It's the only user of them, and it's going to get optimized.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

gossip.pydiff --git a/common/test/run-json.c b/common/test/run-json.c
index 956fdda35..db52d6b01 100644
2018-10-19 22:02:11 +00:00
Rusty Russell 71a40faae7 withdraw: fix incorrect error when we have an empty wallet.
This also highlights the danger of searching the logs: that error
appeared previously in the logs, so we didn't notice that the actual
withdraw call gave a different error.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-19 22:02:11 +00:00
Christian Decker f583e6bc58 pytest: Silence some more warnings about raw_strings in regexps 2018-10-19 22:01:22 +00:00
Christian Decker f3b4dcb1f6 channel: Set the billboard to reconnecting when we restarted
Some people were alarmed that the state was set to "Loaded from
database" indefinitely. Saying that we are trying to reconnect may be
more informative.
2018-10-19 22:01:22 +00:00
Rusty Russell 31d8a5a9a4 pytest: cleanup test_forward_stats.
Use dev_ignore_htlcs to make sure HTLC gets stuck.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-19 21:58:27 +00:00
Rusty Russell 604638712b jsonrpc: Only show total fees collected in getinfo.
And use wallet_forward_status_in_db() everywhere in db code.
And clean up extra CHANGELOG.md entry (looks like rebase error?)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-19 21:58:27 +00:00
Christian Decker 5471e3c0fc json-rpc: Mention `listforwards` and stats in CHANGELOG 2018-10-19 21:58:27 +00:00
Christian Decker 6b7546b94d json-rpc: Rename `getroutestats` and move stats to getinfo
Signed-off-by: Christian Decker <@cdecker>
2018-10-19 21:58:27 +00:00
Christian Decker 6d333f16cc wallet: Correctly handle forwards when channels or htlcs are deleted
The left join should make sure we still get the results but
referencing the fields and/or attempting to write them to the JSON-RPC
result will cause unforeseen problems. So just omit if we forgot
something.
2018-10-19 21:58:27 +00:00
Christian Decker facd7d16aa json-rpc: Add `listforwardings` command 2018-10-19 21:58:27 +00:00
Christian Decker 6efdd5275c pytest: Test that we record forwardings correctly
Adapts the `test_forward_stats` test to include checks for the
`forwarded_payments` table. Will add checks for the `listforwardings`
RPC call next.

Signed-off-by: Christian Decker <@cdecker>
2018-10-19 21:58:27 +00:00
Christian Decker 4b4c549c9d htlcs: Wire up the forward statistics on HTLC updates
Signed-off-by: Christian Decker <@cdecker>
2018-10-19 21:58:27 +00:00
Christian Decker 5b924a7eb7 wallet: Add primitives to add forwarded payments to the DB
Signed-off-by: Christian Decker <@cdecker>
2018-10-19 21:58:27 +00:00
Christian Decker 07ebc525e9 wallet: Add new `forwards` table to keep track of forwarded payments
Signed-off-by: Christian Decker <@cdecker>
2018-10-19 21:58:27 +00:00
Amin Shah Gilani 6d2e5bace3 Copy-edit README.md
Fix a few typos and grammatical errors in the README file.
2018-10-19 14:52:19 +02:00
Rusty Russell 09b33015c4 connectd: give user a hint when wrong key is used.
When the wrong key is used, the remote end simply hangs up.

We used to get a random errno, which tends to be "Operation now in progress."
Now it's defined to be 0, detect and provide a better error.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-19 00:53:00 +00:00
Rusty Russell cd8446f081 ccan: update to get new ccan/io which sets errno to 0 on EOF.
We get structeq and htable updates we don't need for free.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-19 00:53:00 +00:00
Rusty Russell acc01e6436 ccan: update.
This was from a different series, so I just cherry-picked it.

It adds ccan/membuf as a depenency of ccan/rbuf, though we don't use
it directly yet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-19 00:53:00 +00:00
Rusty Russell 6af8f29392 bolt11: better message when you try to 'lightning-cli pay' an onchain addr.
Give a clear error at the beginning if it's not bolt11 payment,
rather than falling foul of other checks.

This will work at least until some altcoin adapts the 'ln' prefix :)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-17 22:59:20 +00:00
Rusty Russell e2f4359c08 CHANGELOG: Fix up Added order, add note about htlc_maximum_msat.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-17 22:57:06 +00:00
Rusty Russell 81823e5fed CHANGELOG: add entry for help updates.
This covers both cbde3e20f7 which added
the parameter names, and d23a0e8adc which
added fallback for missing man page entries.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-17 22:57:06 +00:00
Rusty Russell 3e3543a12c CHANGELOG: note autotor port fix.
This was fixed in d5c3626fa73967ff59d60b36c8ec21394f357f9d; we're still
getting use to CHANGELOG.md.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-17 22:57:06 +00:00
Rusty Russell 6ff7beab1f CHANGELOG: note gossip fix 0855422110
This was the one causing us to spam old gossip onto the network!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-17 22:57:06 +00:00
Rusty Russell bbc36a7bec gossipd: update node announcement even if we change within a second.
Usually Travis triggers corner cases because it's so slow, but this
time the moons aligned, and it managed to fail test_node_reannounce
because it generated the updated node_announcement with the same
timestamp as the old one.

This is because we only updated "last_announce_timestamp" when
we generated the announcement, not when we got it off the wire or
loaded it from the gossip store.

The fix is to ask the routing code what the latest timestamp is;
we could still generate a clashing timestamp if (1) the gossip store
is lost, and (2) we restart within one second.  Hard to care.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-16 04:24:03 +00:00
lisa neigut 66ca2a333f channeld: use u64 fo `htlc_minimum_msat`
As per spec.
2018-10-16 03:32:27 +00:00
lisa neigut 0ae1d03513 BOLT7: broadcast `htlc_maximum_msat` in `channel_update s
Have c-lightning nodes send out the largest value for
`htlc_maximum_msat` that makes sense, ie the lesser of
the peer's max_inflight_htlc value or the total channel
capacity minus the total channel reserve.
2018-10-16 03:32:27 +00:00
Christian Decker e904fcc00c docker: Update docker images and docs to non-CVE-2018-17144 bitcoind
While not strictly necessary it's certainly a good idea to test
against the latest one and not encourage users to use old versions.

Reported-by: Jonas Nick <@jonasnick>
Signed-off-by: Christian Decker <@cdecker>
2018-10-15 23:05:25 +00:00
Rusty Russell afac01380d gossipd: don't initialize broadcast interval, make field name explicit.
We initialize it to 30 seconds, but it's *always* overridden by the
gossip_init message (and usually to 60 seconds, so it's doubly
misleading).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-15 23:04:17 +00:00
Rusty Russell 3991425111 gossipd: don't accept forwarding short_channel_ids we don't own.
Gossipd provided a generic "get endpoints of this scid" and we only
use it in one place: to look up htlc forwards.  But lightningd just
assumed that one would be us.

Instead, provide a simpler API which only returns the peer node
if any, and now we handle it much more gracefully.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-15 23:04:17 +00:00
Rusty Russell 030fe1ce53 gossipd: don't expose private channels for routeboost.
We don't create unannouncable channels, but other implementations can.
Not only is it rude to expose these via invoices, it's probably not
useable anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-15 23:04:17 +00:00
Christian Decker d0de7b49b2 libwally: Update to latest master to fix some compilation issues
Signed-off-by: Christian Decker <@cdecker>
2018-10-15 00:39:33 +00:00
Christian Decker a44491fff0 benchmark: Add two benchmarks for forwarded payments
We weren't benchmarking them, so do that now.
2018-10-13 10:58:53 +00:00
Christian Decker 81f5b89fe3 wallet: Actually load wallet stats when asked to
The call to `sqlite3_step` is actually needed, otherwise we'll always
get the default values for all types.
2018-10-13 10:58:53 +00:00
Christian Decker 2354b3e706 json-rpc: Create test showcasing the null-accounting issue
There is an issue with the way we retrieve the channel accounting info
that will result in always showing 0 for all stats. This tests for it
and the next commit will fix it.
2018-10-13 10:58:53 +00:00
Rusty Russell ea4308ce52 channeld: allow WIRE_ANNOUNCEMENT_SIGNATURES before funding_locked.
LND does this, and we get upset with it.  I had assumed we would only
do this after funding_locked (since we don't consider the channel
shortid stable until that point), but TBH 6 confirms is probably
enough.

Fixes: #1985
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-13 04:13:35 +00:00
trueserve dbb9b0c077 options: Parse config file before opening working directory
Right now, the `config` file is read *after* the configuration working directory is moved to in the software. However one configuration option `lightning-dir` settable in the `config` file sets this working directory. As the directory is already opened (which defaults to `$HOME/.lightning`) before the configuration is read, the configured directory will not be used.

This patch parses the configuration file before opening the working directory, fixing this bug.

[ Update CHANGELOG.md and man pages -- RR ]
2018-10-13 04:09:49 +00:00
Rusty Russell f6b0f794b2 jsonrpc: fix crash on bad JSON input.
It went something like:
   niftynei: Hey, cppcheck complains this might be NULL, so I put in a check.
   rusty: cppcheck is dumb.  Make it an assert("Rusty always right!").
   niftynei: You seem certain of this so I shall do that.
             https://github.com/ElementsProject/lightning/pull/1994
   ...
   renepickhardt: I asked fiatjaf to run
                  `lightning-cli sendpay "[{'id':'02db8f487fcc0a'}]" 4efe0ba89b`
                  and his node crashed!
   rusty: grep Assertion logs/*
          lightningd/jsonrpc.c:326: connection_complete_error: Assertion `Rusty is always right!' failed.

It turns out that in the 'can't parse' error case, we hand NULL cmd to
connection_compete_error.

Next time, less asserting, more grepping!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-12 21:19:52 +00:00
Simon Vrouwe c22d7012a3 lightningd: fail fundchannel command when feerate is below feerate_floor 2018-10-12 02:14:19 +00:00
Christian Decker 0ee0da0eb8 common: Add a test for io_lock
Totally forgot to add this test. It just shows how a writer can take
exclusive access of a socket over multiple `io_write` calls, and
queuing all others behind it.
2018-10-11 01:43:55 +00:00
Christian Decker b86edf3cf1 jsonrpc: Simple demonstration on how jcon can be locked for streams
This is a bit of overkill now that we simply accumulate the entire
JSON response in the buffer before flushing, but when we move to
streamed responses it allows us to have a single command that has
exclusive access to the out direction of the JSON-RPC connection.
2018-10-11 01:43:55 +00:00
Christian Decker bb38541d9e common: Added a small locking mechanism to simplify how we lock IO
We've done this a number of times already where we're getting
exclusive access to either the out direction of a connection, or we
try to lock out the read side while we are responding to a previous
request. They usually are really cumbersome because we reach around to
the other direction to stop it from proceeding, or we flag our
exclusive access somewhere, and we always need to know whom to notify.

PR ElementsProject/lightning#1970 adds two new instances of this:

 - Streaming a JSON response requires that nothing else should write
   while the stream is active.
 - We also want to stop reading new requests while we are responding
   to one.

To remove the complexity of having to know whom to stop and notify
when we're done, this adds a simple `io_lock` primitive that can be
used to get exclusive access to a connection. This inverts the
requirement for notifications, since everybody registers interest in
the lock and they get notified if the lock holder releases it.
2018-10-11 01:43:55 +00:00
practicalswift a46d712154 Avoid applying the unary minus operator to an unsigned value 2018-10-11 01:39:54 +00:00
Rusty Russell 1e467bb986 lightningd: fail HTLCs which are in-transit as we shut down.
This is the source of failure in the test_restart_many_payments stress
test: we don't commit the outgoing HTLC immediately, instead waiting for
gossip to tell us the peer for the outgoing channel, then waiting for
that channeld to tell is it's committed.  The result was incoming HTLCs
with no outgoing.

I initially pushed the HTLCs through that same path, but of course
(since peers are not connected yet!) the only result was that we failed
these HTLCs immediately.  So I chose the far simpler course of just
failing them directly.

To reproduce this, I had to increase the test_restart_many_payments
num to 10, and run it with nice -20 taskset -c 0.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-10 18:14:13 +02:00
William Casarin b3f7236201 python: add cheroot to requirements.txt
It looks like this is a new dependency.

Sort the list while we're at it.

Signed-off-by: William Casarin <jb55@jb55.com>
2018-10-10 18:00:22 +02:00
Rusty Russell fcb5310873 pytest: make wait_for do exponential backoff, start at 0.25 seconds.
This doesn't alter runtime very much, but does reduce log spam.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-10 06:10:42 +00:00
Rusty Russell 84b9e3e72b lightningd: reduce log spam from bitcoin-cli invocations.
During tests, this is half our log!  And Travis truncates it if we get
a failure in test_restart_many_payments.

Interestingly, test_logging had a bug which relied on this spam :)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-10-10 06:10:42 +00:00
William Casarin 8f405ca9a7 cli: fix human help output for the new jsonrpc help response
Now that we're returning all the help data, we need to update the human_help
formatter to handle the extra data.

Signed-off-by: William Casarin <jb55@jb55.com>
2018-10-10 06:09:29 +00:00
William Casarin d23a0e8adc cli: handle missing manpages gracefully
Instead of exiting when we can't find a manpage, set the command and continue so
that we can try the json rpc for help.

Signed-off-by: William Casarin <jb55@jb55.com>
2018-10-10 06:09:29 +00:00