Commit Graph

4850 Commits

Author SHA1 Message Date
Rusty Russell ea2c03e2e2 gossipd: don't have code to exit final loop; we always leave via master_gone.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-21 00:36:31 +00:00
Rusty Russell 4038061d0f gossipd: use take() in getroute_req.
Trivial optimization.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-21 00:36:31 +00:00
Rusty Russell 5c60d7ffb2 gossipd: split wire types into msgs from lightningd and msgs from per-peer daemons
This avoids some very ugly switch() statements which mixed the two,
but we also take the chance to rename 'towire_gossip_' to
'towire_gossipd_' for those inter-daemon messages; they're messages to
gossipd, not gossip messages.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-21 00:36:31 +00:00
Rusty Russell 07b16e37d0 daemon_conn: don't rely on outq_empty callback telling us to retry queue.
We had at least one bug caused by it not returning true when it had
queued something.  Instead, just re-check thq queue after it's called.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-21 00:36:31 +00:00
Rusty Russell 4e9eba1965 gossipd: rework query_channel_range to accept overlapping range.
We shouldn't insist on an exact reponse match: they can batch it and send
a whole batch, as long as it overlaps what we ask.

We also change to a bitmap to save some memory.

This isn't note in the CHANGELOG since we don't actually send gossip
range queries except for testing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-21 00:36:31 +00:00
Rusty Russell fac68630b8 ccan: add ccan/bitmap.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-21 00:36:31 +00:00
Rusty Russell 363564301f gossipd: be more rigorous in handling peer messages vs. daemon requests.
Messages from a peer may be invalid in many ways: we send an error
packet in that case.  Rather than internally calling peer_error,
however, we make it explicit by having the handle_ functions return
NULL or an error packet.

Messages from the daemon itself should not be invalid: we log an error
and close the fd to them if it is.  Previously we logged an error but
didn't kill them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-21 00:36:31 +00:00
Rusty Russell 1bd76861fd gossipd: reorder functions into related groups (MOVEONLY)
It's MOVEONLY but for the removal of the '#ifndef TESTING' which was
needed for old test code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-21 00:36:31 +00:00
Rusty Russell debbdc0781 bolt11: accept lightning: prefix.
The Blockstream store produces these, for example, so let's ignore them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-20 21:02:31 +01:00
Rusty Russell 8a246e2c0a jsonrpc: provide overview of how this all connects together.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-20 16:51:19 +01:00
Rusty Russell 6f7650e471 pytest: test using malformed JSONRPC commands.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-20 16:51:19 +01:00
Rusty Russell 7799368144 pytest: add test for multiplexed RPC output.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-20 16:51:19 +01:00
Rusty Russell 3f5487e247 jsonrpc: dev_slowcmd, a command which starts output then delays.
This lets us explicitly test that our JSON outputs don't intermingle.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-20 16:51:19 +01:00
Rusty Russell e0d14bddb9 jsonrpc: allow multiple commands at once.
We now keep multiple commands for a json_connection, and an array of
json_streams.

When a command wants to write something, we allocate a new json_stream
at the end of the array.

We always output from the first available json_stream; once that
command has finished, we free that and move to the next.  Once all are
done, we wake the reader.

This means we won't read a new command if output is still pending, but
as most commands don't start writing until they're ready to write
everything, we still get command parallelism.

In particular, you can now 'waitinvoice' and 'delinvoice' and it will
work even though the 'waitinvoice' blocks.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-20 16:51:19 +01:00
Rusty Russell f9fd802147 jsonrpc: make struct json_connection definition private.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-20 16:51:19 +01:00
Rusty Russell 47d2a71ef0 json.c and jsonrpc.c: move functions between them.
json_stream_success / json_stream_fail belong in jsonrpc.c, and the
json_tok helpers for special types belong in json.x

json_add_object() isn't used, remove it rather than moving it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-20 16:51:19 +01:00
Rusty Russell e17f69ce2d json_stream: disentangle JSON handling from command.
We promote 'struct json_stream' to contain the membuf; we only attach
the json_stream to the command when we actually call
json_stream_success / json_stream_fail.

This means we are closer to 'struct json_stream' being an independent
layer; the tests are already modified to use it directly to create
JSON.

This is also the first step toward re-enabling non-serial command
execution.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-20 16:51:19 +01:00
Rusty Russell db3f0ba965 CHANGELOG: note that pylightning uses double-newline.
Suggested-by: @ZmnSCPxj
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-20 16:51:19 +01:00
Rusty Russell b9b7411d88 lightning.py: use double-\n as marker for RPC parsing.
This doesn't make a performance difference, but even better, it
simplifies the code.

We hacked test_multirpc to send 200x as many commands, and timed the
pytest over 20 runs:

Before:
=================== 1 passed, 136 deselected in 8.550000-9.400000(9.0045+/-0.2) seconds ===================

After:
=================== 1 passed, 136 deselected in 8.540000-9.370000(8.97286+/-0.16) seconds ===================

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-19 21:36:40 +01:00
Rusty Russell b2378654d7 jsonrpc: add double '\n' to end of JSON RPC commands.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-19 21:36:40 +01:00
Rusty Russell 0c3f85d931 lightning.py: parse multiple JSON RPC commands accurately.
We need to keep the remaining buffer, and we need to try to parse it
before we read the next.  I first tried keeping it in the object, but
its lifetime is that of the *socket*, which we actually reopen for
every command.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-19 21:36:40 +01:00
Rusty Russell fe11ee5406 pytest: make test_multirpc check that RPC commands complete.
This was hanging sometimes in travis, but actually checking the result
of the commands makes it *always* hang.  We remove the waitinvoice
which will not return.

ZmnSCPxj points out that this behavior, introduced in
ce0bd7abd3, is a regression: it would be
nice to be able to cancel a waitinvoice.  But that fix is more complex,
and will have to be another PR.

This test will now hang, but it's OK: we're about to fix it!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-19 21:36:40 +01:00
Conor Scott 9a0f3a764c [pylightning] Fix lightning-pay script 2018-11-19 21:24:03 +01:00
arowser d5aaa11373 update match network log 2018-11-15 20:19:34 +01:00
Conor Scott 189fca4039 [doc] Remove old GOSSIPING state from docs 2018-11-15 11:29:04 +01:00
Conor Scott a92c7911a7 [docs]: Link developer guide to main README.md 2018-11-14 03:24:03 +00:00
Christian Decker 6c649ce775 docs: Mention that msatoshi on pay is not optional, but ignored
Reported-by: Tim Horie <@thorie7912>
Signed-off-by: Christian Decker <@cdecker>
2018-11-13 06:17:50 +01:00
Christian Decker b02861bfe1 plugin: Give each plugin their own log-prefix
There is no good naming just yet, so we just number them 1 to n.
2018-11-13 00:44:50 +01:00
Christian Decker 74c58e9f25 docs: Add an initial draft of the plugin documentation
Signed-off-by: Christian Decker <@cdecker>
2018-11-13 00:44:50 +01:00
Christian Decker 805a76a97f plugin: Make the plugins a list
Suggested-by: Rusty Russell <@rustyrussell>
Signed-off-by: Christian Decker <@cdecker>
2018-11-13 00:44:50 +01:00
Christian Decker 775e4b784d plugin: Get rid of redundant stdin and stdout members
Suggested-by: Rusty Russell <@rustyrussell>
Signed-off-by: Christian Decker <@cdecker>
2018-11-13 00:44:50 +01:00
Christian Decker e6ef675ea1 plugin: Send the configure request once we collected all options
This is the final step to get the plugins working. After parsing the
early options (including `--plugin`), then starting and asking the
plugins for options, and finally reading in the options we just
registered, we just need to assemble the options and send them over.

Signed-off-by: Christian Decker <@cdecker>
2018-11-13 00:44:50 +01:00
Christian Decker 2b3059be0c plugin: Have the helloworld plugin accept a configure message
Just customizes the greeting, the actual sending is in the next commit.

Signed-off-by: Christian Decker <@cdecker>
2018-11-13 00:44:50 +01:00
Christian Decker 3abc32cbbc plugin: Terminate objects with an empty line to signal end
This is just meant as a hint to the plugin that the message is done,
and it can try to parse the buffer.

Signed-off-by: Christian Decker <@cdecker>
2018-11-13 00:44:50 +01:00
Christian Decker 404352fc7e plugin: Configure plugins once we've collected all cli options 2018-11-13 00:44:50 +01:00
Christian Decker 55d6d6b0e7 plugin: Register plugin cli options
We also make `--help` a non-early arg so it allows for the plugins to
register their options before printing the help message. The options
themselves are stored in a separate struct inbetween them being
registered and them being forwarded to the plugin. Currently only
supports string options.

Signed-off-by: Christian Decker <@cdecker>
2018-11-13 00:44:50 +01:00
Christian Decker 10338983a6 plugin: Add logs to plugin and add method to kill a plugin
Also includes some sanity checks for the results returned by the
plugin, such as ensuring that the ID is as expected and that we have
either an error or a real result.
2018-11-13 00:44:50 +01:00
Christian Decker 8e83d43c39 opts: Split early from non-early args so plugins can register theirs
The idea is that `plugin` is an early arg that is parsed (from command
line or the config file). We can then start the plugins and have them
tell us about the options they'd like to add to the mix, before we
actually parse them.

Signed-off-by: Christian Decker <@cdecker>
2018-11-13 00:44:50 +01:00
Christian Decker 084224f134 plugin: Add request muxing to the plugin subsystem 2018-11-13 00:44:50 +01:00
Christian Decker d0de6e59c6 plugin: Start each plugin and setup the connection to it
Mostly copied from bitcoind.c
2018-11-13 00:44:50 +01:00
Christian Decker c71f4f3bd9 plugin: Add listconfigs stub for the --plugin option 2018-11-13 00:44:50 +01:00
Christian Decker 59e37c12cd plugin: Add plugins to lightningd and register arguments 2018-11-13 00:44:50 +01:00
Christian Decker b6a1735929 plugin: Basic scaffolding for the plugin subsystem 2018-11-13 00:44:50 +01:00
Christian Decker f7116c3a43 plugins: Add simple helloworld plugin to test against
It does double duty to show how a simple plugin might work.
2018-11-13 00:44:50 +01:00
Christian Decker 045f7ce7f7 ccan: Update ccan modules to include incomplete option parsing
Signed-off-by: Christian Decker <@cdecker>
2018-11-13 00:44:50 +01:00
Rusty Russell 62e6a9ff54 travis: add test for compilation with higher optimization.
This can give more warnings, so we should test it.  Bad for debugging,
though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-07 04:49:41 +01:00
Rusty Russell c5ee905c92 gossipwith: correctly replace all ccan/io operations in handshake.c.
This is kind of a hack, but let's make it a complete hack.  GCC with
-flto noticed we use different definitions of 'struct io_conn' here
and gave the warning:

ccan/ccan/io/io.h:620:17: warning: type of ‘io_close’ does not match original declaration [-Wlto-type-mismatch]
 struct io_plan *io_close(struct io_conn *conn);
                 ^
ccan/ccan/io/io.c:449:17: note: ‘io_close’ was previously declared here
 struct io_plan *io_close(struct io_conn *conn)
                 ^
ccan/ccan/io/io.c:449:17: note: code may be misoptimized unless -fno-strict-aliasing is used

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-07 04:49:41 +01:00
Rusty Russell c13a355cf2 subdaemon: suppress overzealous _FORTIFY_SOURCE warning.
Ubuntu defines _FORTIFY_SOURCE when compiling with optimization.  This
insanity is the result.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-11-07 04:49:41 +01:00
William Casarin ad1cf8b40c build: fix compilation error on gcc 7.3.0
Signed-off-by: William Casarin <jb55@jb55.com>
2018-11-04 04:22:40 +00:00
Christian Decker d5bb536ef0 docker: Parameterize the bitcoind and litecoind versions 2018-11-03 07:25:01 +00:00