Commit Graph

687 Commits

Author SHA1 Message Date
Christian Decker c15511cf39 routing: Actually return the port when parsing node_announcements
We parsed it, but did not pass it back out.
2017-02-18 13:09:08 +01:00
Rusty Russell 0fe53cc8e7 permute_tx: reintroduce permute map.
We used to have a permutation map; this reintroduces a variant which
uses the htlc pointers directly.

We need this because we have to send the htlc-tx signatures in output
order as part of the protocol: without two-stage HTLCs we only needed
to wire them up in the unilateral spend case so we simply brute-forced
the ordering.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-07 12:14:22 +10:30
Christian Decker eb75ae55e4 cleanup: Removed broadcast_queue from dstate
This is a left-over from the gossip refactoring.
2017-02-03 13:50:39 +01:00
Christian Decker c2764c10c5 broadcast: Implement replacing messages in the broadcast queue
If type and tag match, then we replace any existing message in the
queue. This allows us to drop old announcements. Special care needs to
be taken so that dependent messages are not reordered, but for gossip
this is the case, since the `channel_announcement` cannot be updated.
2017-02-03 05:52:11 +10:30
Christian Decker 6e63429fab gossip: Cleanup queued_message
The list and timestamp are no longer used since we are using the
intmap based broadcast queue.
2017-02-03 05:52:11 +10:30
Christian Decker fb814a7a9e gossip: Adding announcement handling to the gossip subdaemon.
We now have all the pieces to wire in the handling functionality to
the new gossip subdaemon.
2017-02-03 05:52:11 +10:30
Christian Decker 9de880dce7 refactor: Move the gossip handlers to routing
Moving the common functionality out of p2p_announce, sharing it
between legacy and subdaemon architecture.
2017-02-03 05:52:11 +10:30
Christian Decker d966961fbe gossip: Refactoring the gossip handlers to use the routing_state 2017-02-03 05:52:11 +10:30
Christian Decker d200a16988 irc: Rename irc handlers to avoid name clash 2017-02-03 05:52:11 +10:30
Christian Decker 92bc0abdc3 refactor: Move JSONRPC methods to separate compilation unit
This allows us to not care too much about bringing JSON into the new
subdaemons.
2017-02-03 05:52:11 +10:30
Christian Decker 76e2c980e1 gossip: Moving to intmap-based broadcast for the legacy daemon
Moved the broadcast functionality to broadcast.[ch]. So far this
includes only the enqueuing side of broadcasts, the dequeuing and
actual push to the peer is daemon dependent. This also adds the
broadcast_state to the routing_state and the last broadcast index to
the peer for the legacy daemon.
2017-02-03 05:52:11 +10:30
Christian Decker 3aa45a6d0b refactor: Moving write_ip and read_ip into routing.h
Further reduction in things in p2p_message so we can deprecate it
later.
2017-02-03 05:52:11 +10:30
Christian Decker 2a7e757053 refactor: Moving functionality out of p2p_announce
Further decoupling the old daemons from the new daemons.
2017-02-03 05:52:11 +10:30
Christian Decker 2c06524165 refactor: Moving legacy sync method out of routing
This was the only time we actually reference non-routing structs in
routing, so moving this out should allow us to get it working in the
new subdaemons.
2017-02-03 05:52:11 +10:30
Christian Decker 5d10093da3 refactor: Moving the node_map definition into routing.h
This allows us to move some legacy functions closer to where they are
actually used, and not worry about them when including routing.h into
the new subdaemons. `struct peer` is the main culprit here.
2017-02-03 05:52:11 +10:30
Christian Decker 3cb576d69d refactor: Moving gossip/routing specific state into its own struct
This used to be part of `lightningd_state` which is being split up for
the various subdaemons. The main change is the addition of the `struct
routing_state` in `routing.h` and the addition of `rstate` in `struct
lightningd_state` for backwards compatibility.
2017-02-03 05:52:11 +10:30
Rusty Russell 940053d000 htlc: move enum side crom daemon/channel.h to daemon/htlc.h
lightningd wants htlcs, but not the old struct channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-02 14:48:00 +10:30
Rusty Russell d97e3489a0 daemon/htlc_state: split off from daemon/htlc.
We want to use struct htlc inside lightningd, and we need the state
bits.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-02 14:48:00 +10:30
Rusty Russell c6997f15c7 bitcoin/preimage: struct preimage.
We had a hack for 'struct rval' in protobuf_convert.h; make an
explicit header and put it in bitcoin/preimage.h.  It's not really
bitcoin-specific, but it's better than having bitcoin/script depend on
an external header.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-02 14:48:00 +10:30
Rusty Russell 279f216208 gen_peer_wire_csv: update to latest spec.
In particular, 860990fa0afb55f839e882a5e9abe8abe6ccb981 reordered
channel_announcement and c93bf5cf8c48eab1b028e85214cb35feeeffcbb3
reordered the update_fail_malformed_htlc message.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-02 14:48:00 +10:30
Rusty Russell 8522a5ea64 struct bitcoin_tx: remove explicit lengths, use tal_len()/tal_count()
They're always tal objects, so we can simply ask tal for the length,
simplifying the API.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-25 11:03:55 +10:30
Rusty Russell 8159c4458a bitcoin/script.h: remove struct bitcoin_signature
Technically this incudes the sighash flags, but we only handle SIGHASH_ALL
anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-25 11:03:55 +10:30
Rusty Russell 1edce4878d bitcoin/signature.h: remove struct signature.
It's a wrapper around secp256k1_ecdsa_signature, so use that directly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-25 11:03:55 +10:30
Christian Decker 091c2fc8f5 log: Flushing logs on each new entry
This is to speed up the python testing framework and should not have a
big impact on performance.
2017-01-23 10:37:34 +01:00
Christian Decker 3f79a0e117 log: Flushing logs on every line
This is needed for the new testing framework since we wait for
messages to be printed on stdout. Buffering delays this
arbitrarily. Flushing so often should not have much of a performance
impact.
2017-01-23 10:45:36 +10:30
Christian Decker d6ccf90063 jsonrpc: Renamed `awaitpayment` -> `waitinvoice` -> `waitanyinvoice`
As suggested by Rusty
2017-01-23 10:22:13 +10:30
Christian Decker 1a9bfe7be4 jsonrpc: Added `awaitpayment` method
`awaitinvoice` can be used to wait on a specific invoice to be
completed. If the invoice was previously paid, then the command
returns immediately, otherwise it'll block until the invoice is
paid. This complements `waitinvoice` which uses a highwatermark and
waits for the next invoice. I found waitinvoice a bit hard to use
since it doesn't allow waiting for a specific invoice to be completed,
just the next in the insertion order.
2017-01-23 10:22:13 +10:30
Christian Decker ba83430b5f trivial: Removing unused constant 2017-01-22 16:19:11 +01:00
Christian Decker cae283087d sphinx: Committing the onion packet to the payment-hash
The sphinx onion packet now commits to the HTLC payment-hash it is
associated with. This prevents replay attacks with the same onion.
2017-01-16 11:14:30 +10:30
Christian Decker 91b17d45d8 sphinx: Removing last vestiges of the end-to-end payload
So far this was simply set to a zero-length end-to-end payload. We
don't have any plans of re-adding it for the moment, so let's get rid
of the unused code.
2017-01-16 11:14:15 +10:30
Christian Decker 285b8b4698 sphinx: Use libsecp256k1 to generate shared secrets
So far we did it on our own, but since the spec specifies that we use
the libsecp256k1 version anyway, we can remove our own implementation.
2017-01-16 11:08:36 +10:30
Christian Decker 679dec3e6a sphinx: Actually use the full pubkey in ECDH key generation
The spec says that we use the libsecp256k1 style ECDH, which uses the
full compressed pubkey from the scalar multiplication which is then
hashed. This is in contrast to the btcsuite implementation which was
only using the hashed X-coordinate.
2017-01-16 11:08:36 +10:30
Rusty Russell 6bf3c30a10 lightningd/Makefile: fix check-source
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-13 10:51:57 +10:30
Rusty Russell 73d07ce441 libsodium: use our local submodule.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-11 10:04:26 +10:30
Rusty Russell e39d09d5a5 daemon/test/scripts: maek slightly more general for lightningd/lightningd
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:38:33 +10:30
Rusty Russell 015eb072b8 Makefile: split CORE_SRC into CORE_SRC, CORE_TX_SRC and CORE_PROTOBUF_SRC
With the lightningd daemon split, we don't need them all.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:38:33 +10:30
Rusty Russell a0ac5c276e status: API for status reporting.
The API formalizes how daemons should report their statuses back to
the main lightningd.  It's a simple write API, which includes tracing
support (currently it always sends traces, later it could send iff
there's a failure, for example).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:24:20 +10:30
Rusty Russell 42f474af18 wire: make lengths of variable fields implied by tal_count()
This is a much nicer interface, and works better in practice too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:19:25 +10:30
Rusty Russell 7b1a4fc765 utils: add tal_hex() helper.
This is a shortcut when the data being dumped is a tal array.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:19:25 +10:30
Rusty Russell 4a233090ae log: rename struct log_record to struct log_book.
I think "log entry" when I see "log record", so this name is better.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:18:26 +10:30
Rusty Russell 350d8edb7e log: don't include dstate any more.
Before we had a global secp256k1_ctx we needed to hold this to print
out pubkeys, now it's completely orthogonal.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:17:51 +10:30
Christian Decker af43cc5e2c makefile: Be more verbose in `check-daemon-headers`
So far it was failing silently, now it diffs the Makefile state
against the directory listing. This also fixes a bug when the locale
was not set the sort order would not match.
2017-01-10 09:26:06 +10:30
Rusty Russell b59fe5a2b6 daemon/Makefile: objects depend on wire headers too.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-06 13:23:50 +10:30
Christian Decker 96af89139e base58: Unittests need in-tree libbase58 2017-01-05 12:12:30 +10:30
Lucas Betschart 3e6bb958eb Add libbase58 as git submodule
Pointing to the latest release (0.1.4)
2017-01-05 12:11:18 +10:30
Rusty Russell bdc4972df6 wire/gen_peer_wire_csv: update to latest spec #2
828eda61df5a7be27051c605f7808e4f690739e4, in particular, it has the
new address format for node_announcement.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-04 14:09:21 +10:30
Rusty Russell d3bdb073b5 wire/gen_peer_wire_csv: update to latest spec #1
In particular, add features bitfields.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-04 14:09:21 +10:30
Rusty Russell bdaa22e247 generate-wire.py: allow NULL len parameter from fromwire_*
It implies tal_count() gives the length. Great for almost all callers which
don't care if there are extra bytes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-04 14:09:21 +10:30
Rusty Russell e076d56709 generate-wire.py: include type bytes in towire/fromwire routines.
This removes some redundancy in creating messages, but also allows
a lazy form or parsing without explicitly checking the type.

A helper fromwire_peektype() is added to look up the type and handle
the too-short-for-type problem.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-04 14:09:21 +10:30
Rusty Russell c864b28068 generate-wire.py: don't generate structures, hand in all values.
This is a bit more awkward for large structures, but avoids
indirection for the simpler ones (I copied the structures for the test
code, however).  We also remove explicit padding.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-04 14:09:20 +10:30