Commit Graph

7590 Commits

Author SHA1 Message Date
Rusty Russell c92e782e22 wire: add fromwire_tal_arrn() helper.
Does the allocation and copying; this is useful because we can
avoid being fooled into doing giant allocations.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-03-09 16:04:56 +01:00
darosior 524d22e4cc doc: update listchannels manpage
After #3576 ..
2020-03-09 16:03:39 +01:00
Dave Scotese 53913c5119 Use of null
I added a hint how to specify source but not short channel id.
2020-03-07 15:48:22 +01:00
darosior 8e055a4506 bcli: remove a superfluous variable 2020-03-05 15:06:38 -06:00
darosior 1fd45a061b bitcoind: timeout if the Bitcoin plugin never completes the handshake
Reported-by: Vasil Dimov <@vasild>
2020-03-05 15:06:38 -06:00
Vasil Dimov 820f1b2f9d build: send cmp's stderr to /dev/null also
It was probably a typo to have 2>&2

Changelog-None
2020-03-05 14:58:57 -06:00
Vasil Dimov 53ecf098ab build: remove unrecognized option to libsodium
Silence a warning during libsodium's ./configure:

```
configure: WARNING: unrecognized options: --enable-tests
```

Changelog-None
2020-03-05 14:58:57 -06:00
Vasil Dimov 6e86022909 build: force libwally-core to compile in C99 mode
Without this gcc 4.8 defaults to an older standard and cannot compile
the code:

```
gcc-4.8 -DHAVE_CONFIG_H -I. -I../../libwally-core/src -I../../libwally-core -I../../libwally-core/src/ccan -DWALLY_CORE_BUILD=1 -Wall -Wextra -Wpedantic -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wformat -Wformat-security -Wformat-nonliteral -O0 -ggdb -DBUILD_ELEMENTS=1 -flax-vector-conversions -Wno-unused-function -Wno-long-long -Wno-overlength-strings -Wno-variadic-macros -fvisibility=hidden -g -O2 -MT libwallycore_la-elements.lo -MD -MP -MF .deps/libwallycore_la-elements.Tpo -c ../../libwally-core/src/elements.c -o libwallycore_la-elements.o
../../libwally-core/src/elements.c: In function ‘wally_asset_pak_whitelistproof’:
../../libwally-core/src/elements.c:629:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
     for (size_t i = 0; i < num_keys; ++i) {
     ^
../../libwally-core/src/elements.c:629:5: note: use option -std=c99 or -std=gnu99 to compile your code
```

Changelog-None
2020-03-05 14:58:57 -06:00
Christian Decker ac5cba2243 htlc: Return an invalid payload error if payload is invalid
We somehow were always returning `badonion` when really it is an invalid
payload inside the onion.
2020-03-04 22:57:24 +01:00
Christian Decker 959687bf6d onion: Pass the position and type of the failing TLV type out
We'll need this when returning an error to the sender.
2020-03-04 22:57:24 +01:00
Christian Decker 0ba6aba7d1 onion: Do not leak parsed TLV if it is invalid
We were freeing the payload but not the TLV from which we extracted the
payload.
2020-03-04 22:57:24 +01:00
Christian Decker 9529529815 pytest: Repro wrong error being returned on invalid onion payloads
We are returning a `BADONION` error despite the cause being an invalid onion
payload containing an unknown even TLV type. It really should return
`INVALID_ONION_PAYLOAD` errors instead.
2020-03-04 22:57:24 +01:00
Rusty Russell 3572d598bf tests: fix flake in libplugin test.
My test machine is fast enough that we might not have seen the plugin
msg yet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-03-04 16:42:34 +01:00
darosior 6f41d18a92 doc: add pyln-proto to PYTHONPATH for pytest in HACKING 2020-03-04 16:41:43 +01:00
Michael Schmoock 6c50185865 fix: cppcheck ignore two false positives on uninitvar 2020-03-04 14:04:51 +10:30
Michael Schmoock d3ece69a1b fix: adds bcli plugin to check-source targets
Changelog-None
2020-03-04 14:04:51 +10:30
Christian Decker 42d1d3b6d1 wally: Bump libwally to fix gcc 4.8 support 2020-03-04 13:29:39 +10:30
ZmnSCPxj jxPCSnmZ d9b2482415 lightningd/hsm_control.c: Implement `getsharedsecret`.
ChangeLog-Added: New `getsharedsecret` command, which lets you compute a shared secret with this node knowing only a public point. This implements the BOLT standard of hashing the ECDH point, and is incompatible with ECIES.
2020-02-28 14:45:50 +10:30
ZmnSCPxj jxPCSnmZ 1b0807444b hsmd/hsmd.c: Correct a comment.
ChangeLog-none
2020-02-28 14:45:50 +10:30
Rusty Russell f8a21f16c9 lightingd: do a local short_channel_id lookup for forwarding.
Even without optimization, it's faster to walk all the channels than
ping another daemon and wait for the response.

Changelog-Changed: Forwarding messages is now much faster (less inter-daemon traffic)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-28 09:44:47 +10:30
Rusty Russell 40e3566e9a lightningd: use the async mechanism for channel_update access.
Instead of saving a stripped_update, we use the new
local_fail_in_htlc_needs_update.

One minor change: we return the more correct
towire_temporary_channel_failure when the node is still syncing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-28 09:44:47 +10:30
Rusty Russell 247d249ea8 gossipd: provide helper to get a channels cupdate, create routine to use it.
The idea is that gossipd can give us the cupdate we need for an error, and
we wire things up so that we ask for it (async) just before we send the
error to the subdaemon.

I tried many other things, but they were all too high-risk.

1. We need to ask gossipd every time, since it produces these lazily
   (in particular, it doesn't actually generate an offline update unless
   the channel is used).
2. We can't do async calls in random places, since we'll end up with
   an HTLC in limbo.  What if another path tries to fail it at the same time?
3. This allows us to use a temporary_node_failure error, and upgrade it
   when gossipd replies.  This doesn't change any existing assumptions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-28 09:44:47 +10:30
Rusty Russell c51c6f9133 sphinx: use crypto_stream_chacha20_xor to generate stream and xor at once.
Slightly more efficient.  We still generate an overlong stream in a couple
of other places though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-27 14:16:16 +10:30
Rusty Russell 2aad3ffcf8 common: tal_dup_talarr() helper.
This is a common thing to do, so create a macro.

Unfortunately, it still needs the type arg, because the paramter may
be const, and the return cannot be, and C doesn't have a general
"(-const)" cast.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-27 14:16:16 +10:30
Rusty Russell 684ed4231f common/wireaddr: don't include lightningd/lightningd.
common should not include specific per-daemon files.  Turns out this
caused a lot of indirect includes to be exposed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-27 14:16:16 +10:30
Christian Decker 8f87579589 cleanup: Remove current_plugin from plugin_hook_request
It was a pointer into the list of plugins for the hook, but it was rather
unstable: if a plugin exits after handling the event we could end up skipping
a later plugin. We now rely on the much more stable `call_chain` list, so we
can clean up that useless field.
2020-02-27 09:21:44 +10:30
Christian Decker 23149c3daa plugin: Actually wait the 20 seconds promised in the docs
We promised we'd be waiting up to 20 seconds, but were only waiting for
10. Fix that by bumping to the documented 20.
2020-02-27 09:21:44 +10:30
Christian Decker 0987747ded plugin: Avoid calling a destructor on a request that was freed
We are attaching the destructor to notify us when the plugin exits, but we
also need to clear them once the request is handled correctly, so we don't
call the destructor when it exits later.
2020-02-27 09:21:44 +10:30
Christian Decker 41a5728fc3 plugin: Do not forward plugin hook calls during shutdown
We make the current state of `lightningd` explicit so we don't have to
identify a shutdown by its side-effects. We then use this in order to prevent
the killing and freeing of plugins to continue down the chain of registered
plugins.
2020-02-27 09:21:44 +10:30
Christian Decker 4a21883553 plugin: Fix hanging hook calls if the plugin dies
Changelog-Fixed: plugin: A crashing plugin will no longer cause a hook call to be delayed indefinitely
2020-02-27 09:21:44 +10:30
Christian Decker 644daa02e3 plugin: Cleanup a plugin as soon as its stdout closes
We were waiting for both stdin and stdout to close, however that resulted in
us deferring cleanup indefinitely since we did not poll stdout for being
writable most of the time. On the other hand we are almost always polling
the plugin's stdout, so that notifies us as soon as the plugin stops.

Changelog-Fixed: plugin: Plugins no longer linger indefinitely if their process terminates
2020-02-27 09:21:44 +10:30
Christian Decker 72757933f0 pytest: Test a plugin crash while handling a hook call 2020-02-27 09:21:44 +10:30
Christian Decker 7f6f324590 python2: Remove python2 dependency from docs and dockerfiles 2020-02-27 09:18:24 +10:30
Christian Decker 87e924e270 docker: Remove Dockerfile for i386 builder
We aren't using it and it's broken with the specified upstream image, so
remove it outright.
2020-02-27 09:18:24 +10:30
Christian Decker c49c869933 wally: Specify that we use python3 so we don't depend on python2
We specify `PYTHON_VERSION=3` to prevent libwally's ./configure from searchin
for python2, which some distros have started removing, and we were requiring
it only for the configuration step anyway.

Changelog-Changed: dependencies: We no longer depend on python2 which has reached end-of-life
2020-02-27 09:18:24 +10:30
Rusty Russell 73ad9b5c0a common: avoid locale dependent strtod(3)
Replace `json_to_double()` (which uses `strtod(3)`) with our own
floating-point parsing function `json_to_millionths()` that
specifically expects to receive such a number that can fit in a
64 bit integer after being multiplied by 1 million.

The main piece of the code in this patch comes from
https://github.com/ElementsProject/lightning/pull/3535#discussion_r381041419

Changelog-None
2020-02-27 09:07:04 +10:30
Vasil Dimov 89ceb273f5 wire: remove towire_double()
Before this patch we used to send `double`s over the wire by just
copying them. This is not portable because the internal represenation
of a `double` is implementation specific.

Instead of this, multiply any floating-point numbers that come from
the outside (e.g. JSONs) by 1 million and round them to integers when
handling them.

* Introduce a new param_millionths() that expects a floating-point
  number and returns it multipled by 1000000 as an integer.

* Replace param_double() and param_percent() with param_millionths()

* Previously the riskfactor would be allowed to be negative, which must
  have been unintentional. This patch changes that to require a
  non-negative number.

Changelog-None
2020-02-27 09:07:04 +10:30
Vasil Dimov 6b7db1ea7c common: remove unused json_add_double()
Changelog-None
2020-02-27 09:07:04 +10:30
Rusty Russell faac4b28ad plugins: support failure_message in invoice and htlc_accepted hooks.
As promised in the Changelog when we converted from failcodes to messages
internally.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-25 11:12:12 +10:30
Rusty Russell c9e73dc4e0 lightningd: rename htlc_in field from failcode to badonion.
That's all it's used for now.

And remove unreferenced failoutchannel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-25 11:12:12 +10:30
Rusty Russell 447730e70f wallet: only store BADONION codes in db for incoming htlcs: rest are all onionreplyies.
This completes the conversion; any in-flight HTLC failures get turned into temporary_node_failures.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-25 11:12:12 +10:30
Rusty Russell bbc7a79542 lightningd: always use an onionreply for locally generated incoming HTLC errors (unless BADONION).
This cleans up the "local failure" callers for incoming HTLCs to hand
an onionreply instead of making us generate it from the code inside
make_failmsg.

(The db path still needs make_failmsg, so that's next).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-deprecated: Plugins: htlc_accepted_hook "failure_code" only handles simple cases now, use "failure_message".
2020-02-25 11:12:12 +10:30
Rusty Russell 590b2db88e lightningd: make local htlc failures pass a wiremsg for errors, not a failcode.
Unfortunately the invoice_payment_hook can give us a failcode, so I simply
restrict it to the two sensible ones.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-deprecated: plugins: invoice_payment_hook "failure_code" only handles simple cases now, use "failure_message".
2020-02-25 11:12:12 +10:30
Rusty Russell 5af3a135be lightningd: separate path for failed_htlc when an onion is bad.
We tell channeld that an htlc is bad by sending it a 'struct
failed_htlc'.  This usually contains an onionreply to forward, but for
the case where the onion itself was bad, it contains a failure code
instead.

This makes the "send a failed_htlc for a bad onion" a completely
separate code path, then we can work on removing failcodes from the
other path.

In several places 'failcode' is now changed to 'badonion' to reflect
that it can only be a BADONION failcode.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-25 11:12:12 +10:30
Rusty Russell 72d55d3e3b lightningd: store raw msg rather than code for locally-failed outgoing HTLCs
At the moment, we store e.g. WIRE_TEMPORARY_CHANNEL_FAILURE, and then
lightningd has a large demux function which turns that into the correct
error message.

Such an enum demuxer is an anti-pattern.

Instead, store the message directly for output HTLCs; channeld now
sends us an error message rather than an error code.

For input HTLCs we will still need the failure code if the onion was
bad (since we need to prompt channeld to send a completely different
message than normal), though we can (and will!) eliminate its use in
non-BADONION failure cases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-25 11:12:12 +10:30
Rusty Russell 1a3ed18959 channeld: add routing to get our own channel's channel_update.
We'll use this in the next patch for when we need to create errors to
send back to lightningd; most commonly when the channel doesn't have
capacity for the HTLC.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-25 11:12:12 +10:30
Rusty Russell a150b09665 wallet: Add new htlc column "localfailmsg" for outgoing htlcs.
We're going to change our internal structure next, so this is preparation.
We populate existing errors with temporary node failures, for simplicity.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-25 11:12:12 +10:30
Rusty Russell cec18dfd6e lightningd: remove always-NULL argument to add_fail.
It's only called from the db code, and failing_channel is always NULL.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-25 11:12:12 +10:30
Rusty Russell ed839bfda0 channeld: get the onionreply back from lightningd for failed htlcs.
Instead of making it ourselves, lightningd does it.  Now we only have
two cases of failed htlcs: completely malformed (BADONION), and with
an already-wrapped onion reply to send.

This makes channeld's job much simpler.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-25 11:12:12 +10:30
Rusty Russell 7ab5c424b6 gossipd: provide (stripped) channel_update when resolving a channel.
I hadn't realized that lightningd asks gossipd every time we forward
a payment.  But I'm going to abuse it here to get the latest channel_update,
otherwise (as lightningd takes over error message generation) lightningd
needs to do an async request at various painful points.

So have gossipd tell us the lastest update (stripped so compatible with
the strange in-onion-error format).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-25 11:12:12 +10:30