Commit Graph

694 Commits

Author SHA1 Message Date
Rusty Russell 69a8ea2ad9 daemon: pay command.
This is the command an actual user would use: it figures out the fee
and route, and pays it if it can.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 21a29d9b4d daemon: fix bug when we close two peers simulatneously.
If a block triggers two peers to close, we ran io_break() on both of them; the
second overrode the first and we didn't end up freeing that one.

Rather than chase such bugs in future, simply iterate to see if any
peers need freeing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 31a5de644a daemon: route fulfill back.
As soon as an HTLC we offered is fulfilled, fulfill the HTLC which
caused it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 21fe4fbba7 daemon: route failures back.
When an we offered HTLC fails, we fail the HTLC which caused it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 2aa8fe8df1 daemon: route payments onwards.
If the fee is high enough, we offer it onwards.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell f994a44827 daemon/peer: keep our own node connection information.
Note that the base fee is in millisatoshi, the proportional fee is
in microsatoshi per satoshi. ie. 1,000,000 means charge 1 satoshi for
every satoshi carried.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 37b269f53e daemon: link HTLCs together.
Most HTLCs we offer are triggered by an incoming HTLC from a different
peer.  Save this "source" htlc, so we can fail/fulfill it when we
fail/fulfill this one.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell cc4fc4b668 daemon: use htlc pointers everywhere.
No more copies!

I tried changing the cstate->side[].htlcs to htlc_map rather than a
simple pointer array, but we rely on those array indices heavily for
permutation mapping, and it turned into a major rewrite (especially
for the steal case).

Eventually, we're going to want to reconstruct the commit info for
older commit txs rather than keeping all the permutation and
per-commit-info HTLC information in memory, so we can do the work
then.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 67ac2d2081 daemon: code for HTLC maps.
We currently keep copies of HTLCs in each commit_info structure, but
that's redundant.  Keep per-peer per-direction maps of HTLCs, then we can
just throw pointers around (next patch).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell fecd91ab2a Move funding.[ch] to daemon/channel.[ch].
It's a more logical name, and a more logical place.  We change
"funding" to "channel" in the remaining exposed symbols, too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell b2fdc86740 daemon: check and use routing info in HTLC packet.
We only support being the end node for the moment.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell f4f0c1aa18 daemon: add dev-routefail command.
We're about to change the code so that if it can't route, it will fail
the HTLC.  The current low-level tests will hate this, so have a dev switch
to turn that off.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell bf3acfab62 daemon/htlc: including routing information.
This is the logical place for it to belong: with the HTLC.  For the manually-created
HTLCs, we create a simple one-hop route.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 4902907628 daemon: onion routing API
No meat; it doesn't encrypt as yet, but the API to wrap/unwrap routes is here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell f06855ff6c daemon: extract newhtlc code into common function.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 6fe5c1069e protocol: add routing information.
This will be onioned, but the structure (or something like it) should
survive.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell b1ac490bea daemon: add-route RPC command.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 26a03acfd0 daemon: routing infrastructure.
Simple routing topology, and ability to ask about the cheapest route.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 27da8f77b5 daemon: expose find_peer(), rename other to find_peer_json().
This is the more normal case; find by ID.  The low-level json commands are
really just for testing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell a3375516e5 daemon: don't ever use timeouts in seconds, always blocks,
The protocol still supports both, but we now only support blocks.

It's hard to do risk management with timeouts in seconds, given block
variance.  This is also signficantly simpler, as HTLC timeouts are
always fired in response to blocks, not wall-clock times.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell c1e1299249 daemon: always log error packets we create.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 5296b7f9a0 log: add structure logging.
Uses a gcc extension (cast to union) for typechecking, but that can be
removed for compilers which don't support it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 04b3e8f91d daemon: use siphash for hashes.
Remove ccan/hash (aka Jenkins lookup3) altogether.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 92246c427b ccan update: add siphash module, update htable.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell ba9df99770 daemon: wire in payment.
This actually uses the accept-payment data to make payments.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell 5027410ab1 daemon: payment infrastructure.
A new 'accept-payment' command tells the node to fulfill HTLCs using
the R value if the amount is correct.  It's not wired in yet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell f1af56fcee daemon: save acked changes, so we can process them when confirmed on both sides.
We need to know when changes are fully committed by both sides:
1) For their HTLC_ADDs, this is when we can fulfill/fail/route.
2) For their HTLC_FAILs, this is when we can fail incoming.

For HTLC_FULFULL we don't need to wait: as soon as we know the preimage
we can propogate it.

For the moment, we simply log and assert; acting on it comes later.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell eeb9b9de84 funding: make funding_htlc_by_id() return pointer, not offset.
While the pointer is only valid until the funding changes, that's also
true of the offset; and a pointer has a convenient "not found"
sentinal value.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell 156d1be9ed daemon: struct rval to represent r values.
We've been stuffing these into sha256s, but they're actually nonces.
Create a new structure for that for clarity.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell 1abc676c4f daemon: always take packets into pkt_in, then have it demultiplex.
Cleanly separates packet handling functions, and the weird transition cases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell b4f0d32b09 daemon: always terminate waiting manual update command on failure.
We missed some cases, resulting in hanging commands.  Just check whenever
we fail.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell 1444d407f3 daemon: remove normal operation loop from state.c
It's now in its own little state machine, which is more typesafe.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell bc5800b1c1 state: remove unused fields from union input
And make the add/fail/fulfill arg a pointer to a union htlc_staging
directly, removing struct htlc_progress.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell 50bffd67c2 daemon: don't save invalid commit signatures.
We don't want anyone to think the commitment tx is signed, so only
assign ci->sig after validation.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell d1416ea5b5 TAGS: don't go into git dirs.
Things get quite confusing when this happens.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell 43db90391a daemon: fix case where commit has nothing to do.
Prevents assert() triggering in queue_pkt_commit().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell b820f5a0dd Makefile: fix submodule.
Christian noted that missing daemon/jsmn/jsmn.h didn't trigger the git
submodule weirdness.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell 9046597344 daemon: tighten check for invalid IDs.
We don't have to, but helps debugging.  Language in latest rev of BOLT#2
has been tightened too (aa2e1919de0826beaf92e0b3b441a6ab9fce6261)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell 3928cbe30e daemon: fail connection if preimage isn't valid for shachain.
This means they generated it wrong.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-06-25 14:20:15 +09:30
Rusty Russell 6bbd05c001 Merge remote-tracking branch 'origin/pr/25' 2016-06-25 14:19:57 +09:30
Rusty Russell 2436207a7a test: detect segwit correctly, assume master branch.
Segwit was merged, but the strings changed between there and segwit4
(also, my BIP9 patch changed the output).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-06-25 14:13:08 +09:30
sstone be1a230ae8 fix formatting issues 2016-06-23 17:11:10 +02:00
sstone 07e6ed0c16 save received revocation preimages in shachain.
make sure that preimages are generated in reverse order.
2016-06-23 16:38:35 +02:00
Rusty Russell 1dbe001fdc Merge pull request #24 from ocinq/master
Makefile : adding ccan/asort.o target and binary
2016-06-17 05:59:20 +09:30
ocinq bcdab60694 Makefile : ccan/asort is referenced
Added explicit compilation and linking of ccan/asort as needed by daemon/chaintopology
2016-06-14 17:25:07 +02:00
Rusty Russell 49ebed737d daemon/test: test differential fees.
This would have revealed the previous breakage (and I tested that!),
plus now we test negotiate on closing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-30 11:18:46 +09:30
sstone 385c2a5905 setup_first_commit: initialize their remote commit with their commit fee rate 2016-05-27 16:53:01 +02:00
Rusty Russell 9bb070f5b6 0.3 release: Braydon Fuller: Nakamoto's Genesis Coins
Braydon wrote the INSTALL.md file; he gets to name this release,
in line with the theme.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:25 +09:30
Rusty Russell 40b550a9d2 daemon: don't log bogus warning on failed anchors.
We no longer get bitcoind to manage our transactions for us, so we don't
need to -zapwallettxs when an anchor fails.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:25 +09:30
Rusty Russell 773a6088e4 daemon: reorder and collapse functions.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:25 +09:30