Commit Graph

4252 Commits

Author SHA1 Message Date
Rusty Russell 41c9431ae0 closingd: use deconstructed read_peer_msg helpers.
This is more verbose but I still think it's clearer.  Almost exactly
the same as the openingd one, but just different enough to be painful
to share.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-08-05 02:03:58 +00:00
Rusty Russell 90b43a6f47 openingd: use deconstructed read_peer_msg helpers.
This is more verbose but I still think it's clearer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-08-05 02:03:58 +00:00
Rusty Russell 6b5462b637 channeld: use deconstructed read_peer_msg helpers.
This is clearer and neater, and even slightly more efficient, since
read_peer_msg() was calling poll() again on gossipfd.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-08-05 02:03:58 +00:00
Rusty Russell 0b08601951 sync_crypto_write/sync_crypto_read: just fail, don't return NULL.
There's only one thing the caller ever does, just do that internally.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-08-05 02:03:58 +00:00
Rusty Russell 09cce4a9c7 common/read_peer_msg: deconstruct into individual helper routines.
The One Big API is confusing, and has enough corner cases that we should
ditch it rather than add more.

See: https://www.sandimetz.com/blog/2016/1/20/the-wrong-abstraction

In particular, when openingd is changed to chat to peers even when
it's not actively opening a channel, it wants to handle (most) errors
by continuing, not calling peer_failed().

This exposes the constituent parts.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-08-05 02:03:58 +00:00
Rusty Russell 74d428109a channeld: it's OK to block on writing to peer.
In fact, it's good.  We don't want to queue up infinite gossip.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-08-05 02:03:58 +00:00
Rusty Russell c05bc7c8ab lightningd: don't try to delete peer from db on shutdown if it's opening.
Fortunately, we hit the assert in wallet_peer_delete() if this happens,
since there are still active channels.

This latent bug becomes far more likely in followup patches, where
openingd is used for idle peers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-08-05 02:03:58 +00:00
Rusty Russell 8bffd2b604 lightningd: centralize refcounting behaviour for peers.
It's mildly neater this way.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-08-05 02:03:58 +00:00
Rusty Russell 0ebad456b1 connectd: don't listen to UNIX sockets before activation.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-08-05 02:03:58 +00:00
Rusty Russell 3414b992a1 lightningd: don't dump core on subdaemon failure.
That tends to dump core over the top of the subdaemon; just exit non-zero.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-08-05 02:03:58 +00:00
Rusty Russell a409cc26d9 memleak: reenable CCAN_TAL_DEBUG in DEVELOPER mode.
It no longer has any effect on tal_len(), but it *does* give file and line
of allocations which is much nicer for tracking memory leaks!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-08-05 02:03:58 +00:00
Rusty Russell 4bdacea7b5 common/utils: don't free tmpctx, just the children.
In some daemons I want to hand it into a loop, which would call
clean_tmpctx().  This causes a subtle bug.

So just free the children directly: the pointer itself remains valid.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-08-05 02:03:58 +00:00
Christian Decker 2d1190d929 wallet: Add missing description field to the invoices iteration 2018-08-04 23:49:28 +00:00
tock203 80a8e57ede Fix example docker-compose.yml 2018-08-03 09:49:37 +02:00
gabridome 2db832ab3e Errors corrected
Also:
- the lines of code that contain more than one elements are no more inline. 
   This should improve visualization in small screens (no auto line wrapping).
- Found a "solution" for the references: people looking at markdown presentation
   will see one only reference to the Tor project.
   In the text source all the "references" are shown and also serve in markdown as 
   hypertext links.
Feel free to improve.
2018-08-03 02:23:48 +00:00
gabridome b4cb4da232 In-document links don't work if "." is present
When you refer to a title of the doc in a link and the title has a dot, you have to drop it when you build the link.
2018-08-03 02:23:48 +00:00
gabridome f95ef5f3ff Suggested changes incorporated.
- difference between --bind-addr=autotor and --addr=autotor
- typos corrected (non-persistent and Tor)
- "references" dropped
- table improved
- Outgoing case explained where is useful
The actual structure suffers of many repetitions. I could work on 
a compact structure based on a "decision tree modular" approach if that 
may seem useful.
2018-08-03 02:23:48 +00:00
gabridome a92d7f1490 File improvements
Adapted for the markdown format.
Also developed in the preparation parts and each case of use has been detailed.

A doubt in the non persistent address remain:
In the original document 

> --announce-addr=autotor:<torservice_ip:port> : try to generate an temp V2 onion addr.

 this doesn't seem to work for me (several errors are produced at start up).
instead the `--addr=autotor:127.0.0.1:9051`seems to work well (at least for version 0.6).
2018-08-03 02:23:48 +00:00
William Casarin 046a9c1a45 doc: document p2sh-segwit address gen for faucet coins
Now that the default newaddr type is bech32, this step seems to be tripping
people up.

Reported-by: #c-lightning users
Signed-off-by: William Casarin <jb55@jb55.com>
2018-08-03 02:21:25 +00:00
practicalswift a039630da1 lint: Add linter checking for use of discouraged standard library functions 2018-08-02 16:14:21 +09:30
practicalswift 9d9a9523d0 Use snprintf(...) instead of sprintf(...) 2018-08-02 16:14:21 +09:30
practicalswift 0f7b11bdc2 Remove redundant code 2018-08-02 15:58:14 +09:30
practicalswift a623fd8924 Make sure we're not using uninitialized values 2018-08-02 15:57:16 +09:30
practicalswift 7969cc335e Allocate off ctx instead of tmpctx in encode_short_channel_ids_start(const tal_t *ctx) 2018-08-01 13:09:16 +09:30
practicalswift 2c7170b858 Remove unused adjust_feerange(...) parameters: struct crypto_state *cs + const struct channel_id *channel_id 2018-08-01 13:09:16 +09:30
practicalswift 2627d0c33b Remove unused send_offer(...) parameter: const u8 *funding_wscript 2018-08-01 13:09:16 +09:30
William Casarin 6195839783 lightningd: show selected network defaults in usage
This gives the network options a chance to load from arguments before usage
exits, so that the proper defaults are shown.

This didn't work:

  lightningd --mainnet --help

before it showed testnet defaults, now it shows mainnet defaults.

Signed-off-by: William Casarin <jb55@jb55.com>
2018-08-01 13:08:02 +09:30
practicalswift ba4282f935 Don't advertise features we don't have in run-sphinx 2018-07-31 16:30:56 +02:00
practicalswift b5682a773b Remove dead stores 2018-07-31 12:45:02 +02:00
practicalswift 09ec0ae990 Return true or false from sqlite3_bind_* based on result from SQLite instead of always returning true 2018-07-31 12:44:44 +02:00
Mark Beckwith 1fca7ab562 Added json_tok_sha256 (#1779)
Added json_tok_sha256

Converted json_tok_tok over a few places.

[ Folded: fixed spacing ]
Signed-off-by: Mark Beckwith <wythe@intrig.com>
2018-07-31 04:11:01 +00:00
Christian Decker d3edfc8028 onion: Print the extracted channel_update and onionreply to debug
This adds one line with the onion and the channel_update we extract from
it. This in turn allows us to check that the channel_update in the onion is not
type prefixed, and that we patch it correctly before passing it to gossipd.
2018-07-30 21:19:04 +00:00
Christian Decker 6bbea741d1 pay: Strip the type prefix from nested channel_updates
This is the counterpart for the previous commit, stripping the type prefix
channel_update, to be consistent with lnd and eclair which do it like this.
2018-07-30 21:19:04 +00:00
Christian Decker f449f9d3ef onion: Make sure we understand the channel_update in the onionreply
As was pointed out by @robtex we have underspecified the format of the nested
`channel_update` in the onionreply: lnd and eclair inserted the raw
channel_update without the type prefix, while we went for the full wire format,
including the type prefix. While we agreed that with the type it is more
flexible, and consistent, we decided to adapt to the majority and at least be
compatibly broken.

This commit takes care of being able to interpret either format correctly. It's
not perfect since signatures can happen to start with 0x0102 (the channel_update
type) but that'll happen only once ever 65k failures.
2018-07-30 21:19:04 +00:00
Rusty Russell 52303029aa fundchannel: cap 'all' at 2^24-1 satoshi.
The easiest way to do this is to play with the 'wallet_tx' semantics
and have 'amount' have meaning even when 'all_funds' is set.

Note that we change the string 'Cannot afford funding transaction' to
'Cannot afford transaction' as this code is also used for withdrawls.

Inspired-by: molz on #c-lightning
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-07-30 11:46:41 +02:00
Rusty Russell e3d95f3768 Update common on CCAN_TAL_DEBUG
We don't need this any more: every CCAN object has a valid tal_bytelen().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-07-30 11:31:17 +02:00
Rusty Russell 480e32a236 channeld: don't resize tal_fmt() output.
This fixed a previous bug, but now tal/str makes this guaranteee.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-07-30 11:31:17 +02:00
Rusty Russell 5179025977 ccan: upgrade to new ccan/tal and ccan/tal/str.
The visible changes are:
1. tal_len() is renamed to tal_bytelen() for clarity.
2. tal allocations *always* know their length.
3. tal/str routines always set the length to strlen() + 1.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-07-30 11:31:17 +02:00
Rusty Russell 337075dc8c tal: don't access low-level tal functions.
In several places we use low-level tal functions because we want the
label to be something other than the default.  ccan/tal is adding
tal_*_label so replace them and shim it for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-07-30 11:31:17 +02:00
Rusty Russell 5cf34d6618 Remove tal_len, use tal_count() or tal_bytelen().
tal_count() is used where there's a type, even if it's char or u8, and
tal_bytelen() is going to replace tal_len() for clarity: it's only needed
where a pointer is void.

We shim tal_bytelen() for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-07-30 11:31:17 +02:00
Rusty Russell eae9b81099 json: json_add_hex_talarr for common case of dumping a tal object in hex.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-07-30 11:31:17 +02:00
Rusty Russell d752a0099c gossip_msg: make sure alias is NUL-terminated.
Valgrind error file: valgrind-errors.772802
==772802== Invalid read of size 1
==772802==    at 0x4C32D04: strlen (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==772802==    by 0x14479C: escape (json_escaped.c:41)
==772802==    by 0x144B6C: json_escape (json_escaped.c:117)
==772802==    by 0x118518: json_getnodes_reply (gossip_control.c:209)
==772802==    by 0x139394: sd_msg_reply (subd.c:281)
==772802==    by 0x139972: sd_msg_read (subd.c:418)
==772802==    by 0x17ABB1: next_plan (io.c:59)
==772802==    by 0x17B6A9: do_plan (io.c:387)
==772802==    by 0x17B6E7: io_ready (io.c:397)
==772802==    by 0x17D2C8: io_loop (poll.c:310)
==772802==    by 0x121973: main (lightningd.c:450)
==772802==  Address 0x6fe5168 is 0 bytes after a block of size 72 alloc'd
==772802==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==772802==    by 0x18843E: allocate (tal.c:245)
==772802==    by 0x18899D: tal_alloc_ (tal.c:421)
==772802==    by 0x188B5E: tal_alloc_arr_ (tal.c:464)
==772802==    by 0x119BAB: fromwire_gossip_getnodes_entry (gossip_msg.c:35)
==772802==    by 0x15CCD6: fromwire_gossip_getnodes_reply (gen_gossip_wire.c:111)
==772802==    by 0x118436: json_getnodes_reply (gossip_control.c:192)
==772802==    by 0x139394: sd_msg_reply (subd.c:281)
==772802==    by 0x139972: sd_msg_read (subd.c:418)
==772802==    by 0x17ABB1: next_plan (io.c:59)
==772802==    by 0x17B6A9: do_plan (io.c:387)
==772802==    by 0x17B6E7: io_ready (io.c:397)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-07-30 11:31:17 +02:00
Christian Decker fbbc5899e4 invoices: Make the invoice_details more idiomatic
This seems like a premature optimization: it tried to cut down the number of
allocations by reusing the same `struct invoice_details` while iterating through
a number of results. But this sidesteps the checks by `valgrind` and we'd miss a
missing field that was set by the previous iteration.

Reported-by: @rustyrussell
Signed-off-by: Christian Decker <@cdecker>
2018-07-30 03:04:45 +00:00
Christian Decker 259a69994d json-rpc: Retrieve the invoice description in listinvoices 2018-07-30 03:04:45 +00:00
Christian Decker 7f45947523 wallet: Store the description in the database for invoices 2018-07-30 03:04:45 +00:00
Christian Decker 687f171e17 json-rpc: Add description to `listpayments` and similar 2018-07-30 03:04:45 +00:00
Christian Decker 6bbe5b60f6 wallet: Extract the payment fields into a define
`wallet_stmt2payment` always expects the same fields in the same order, so we
should make sure that we always fetch them in that order and all of them.
2018-07-30 03:04:45 +00:00
Christian Decker bc7393bb64 pay: Reduce nesting and fix minor type inconsistency 2018-07-30 03:04:45 +00:00
Christian Decker 1738107598 json-rpc: Add description argument to `sendpay` 2018-07-30 03:04:45 +00:00
Christian Decker ab223c2ade pay: Pass description to send_payment
Extract the description from the bolt11 string and store it in the database.
2018-07-30 03:04:45 +00:00