Commit Graph

2205 Commits

Author SHA1 Message Date
Christian Decker 71c090745b channel: Defer sending the announcement_signature until both lock
We were sending the announcement_signatures as soon as we locally
locked and got the announcement_depth, this doesn't make the channel
usable any sooner and forces the other side to stash the
signature. This defers the announcement_signature until the channel
really is usable.

This is done by adding an additional check for the remote locked
message and adding a trigger on remote lock.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-14 23:00:01 +00:00
Jonas Nick d07b827050 Mention in README that 6 confirmations are required to fund a channel 2017-11-13 16:26:34 +01:00
Rusty Russell f95afc55d8 rpc: report netaddr as array.
Thought we don't handle it at the moment, nodes can certainly have multiple
addresses, and we should display them all.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-12 12:16:22 +01:00
Christian Decker 89f016f524 jsonrpc: Only print netaddr in getpeers when we know it
Fixes #285
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-12 12:16:22 +01:00
Rusty Russell 956350e62e lightningd: check peers don't leave dangling HTLCs when they die.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-11 01:29:51 +00:00
Rusty Russell e9337820a0 onchaind: remove htlcs when peer is irrevocably committed.
We don't track them accurately when in onchaind, but we don't want to:
onchaind can be restarted at any time.

Once it's all settled, we're clear to clean them up.

Before this, valgrind could complain about deferncing hout->key.peer:

Valgrind error file: valgrind-errors.10876
==10876== Invalid read of size 4
==10876==    at 0x41F8AF: peer_on_chain (peer_control.h:127)
==10876==    by 0x42340D: notify_new_block (peer_htlcs.c:1461)
==10876==    by 0x40A08D: connect_block (chaintopology.c:96)
==10876==    by 0x40A96B: topology_changed (chaintopology.c:313)
==10876==    by 0x40AC85: add_block (chaintopology.c:384)
==10876==    by 0x40ABF0: gather_previous_blocks (chaintopology.c:363)
==10876==    by 0x4051B3: process_rawblock (bitcoind.c:410)
==10876==    by 0x4044DD: bcli_finished (bitcoind.c:155)
==10876==    by 0x454665: destroy_conn (poll.c:183)
==10876==    by 0x454685: destroy_conn_close_fd (poll.c:189)
==10876==    by 0x45DF89: notify (tal.c:240)
==10876==    by 0x45E43A: del_tree (tal.c:400)
==10876==  Address 0x6929208 is 2,120 bytes inside a block of size 2,416 free'd
==10876==    at 0x4C2EDEB: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10876==    by 0x45E513: del_tree (tal.c:421)
==10876==    by 0x45E849: tal_free (tal.c:509)
==10876==    by 0x41A8E9: handle_irrevocably_resolved (peer_control.c:1172)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-11 01:29:51 +00:00
Christian Decker 07e5a9ef9f htlc: Allow for exactly min_final_cltv_expiry cltv delta
We are announcing that we are willing to accept incoming payments with
current_height + min_final_cltv_expiry + slack, assuming that the
sender adds some slack. In particular we'd reject the payment if
slack=0 which is allowed by the spec.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-11 01:28:03 +00:00
Christian Decker d6af14a869 pytest: Valgrind errors trump exit value errors
Raising the exception about non-zero exit values into the
teardown. This was previously masking the valgrind errors. Now
valgrind errors > crash errors > non-zero return value.

Still hoping to catch that elusive [7, 0] return value on travis.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-10 02:20:00 +00:00
Christian Decker bab0693fc4 contrib: Add py.test to builder Dockerfiles
With the previous commit this enables py.test on travis, which should
give us some better way of hunting down bugs on travis.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-10 02:20:00 +00:00
Christian Decker fc176b6cc0 pytest: Use the py.test utility if available
The py.test unit test runner offers a number of more advanced features
than simply running using unittest.main. In particular it allows us to
capture a tests output and print it if it fails. This change checks
whether we have pytest available and if yes, enables verbose tests and
runs using pytest. This'll give the usual experience (with colors!)
and show us the stdout if a test fails making travis a lot easier to
handle.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-10 02:20:00 +00:00
Rusty Russell 5320cab2de generate-wire.py: create structures for optional fields.
If a structure foo has a optional fields opt1 and opt2, this creates
towire_foo, towire_foo_opt1 and towire_foo_opt2 (since opt2 implies opt1),
similarly for fromwire_*.

This requires the callers to be updated to call the correct routines (eg.
try fromwire_foo_opt2, then fromwire_foo_opt1, then finally fromwire_foo),
but this is a minimal change to the generation code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-09 13:55:24 +01:00
Rusty Russell 9fd81ab06d db: make db_exec() an internal function.
Every caller is using prepared statements now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-06 10:24:34 +01:00
Rusty Russell 4fb472b7a7 db: we must always be in a transaction, remove nested, call fatal()
We save location where transaction was started, in case we try to nest.
There's now no error case; db_exec_mayfail() is the only one.

This means the tests need to override fatal() if they want to intercept
these errors.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-06 10:24:34 +01:00
Rusty Russell f4d27eefa1 wallet: remove internal transactions.
We're going to be always in a transaction soon.

Note the rollback we used to do was an optimization: the utxo destructors
would already clean up the new UTXOs in the database.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-06 10:24:34 +01:00
Rusty Russell 7133a2f9b3 wallet: assume db errors will be fatal, don't check.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-06 10:24:34 +01:00
Rusty Russell 3282768302 wallet: don't fail, assume db ops will call fatal.
And override fatal() in wallet_tests to be sure.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-06 10:24:34 +01:00
Rusty Russell 1eb7e92a30 db_migrate: get version inside transaction.
we should never be doing two startups at once, but why take chances?  Plus,
we can then assert that all db calls are in transactions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-06 10:24:34 +01:00
Rusty Russell bccd2f8cf4 bitcoind: wrap callbacks in transaction.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-06 10:24:34 +01:00
Rusty Russell 8229769438 lightningd: do initial database load within a transaction.
Safest, and we can then assert that all db calls are in transactions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-06 10:24:34 +01:00
Rusty Russell 7586f3ed54 timers: wrap all calls in transactions.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-06 10:24:34 +01:00
Rusty Russell 01361ab21b jsonrpc: wrap all calls in transaction. 2017-11-06 10:24:34 +01:00
Rusty Russell 3a596d6dda subd: wrap all message callbacks in a transaction.
Including destructors.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-06 10:24:34 +01:00
Rusty Russell bbe7a03300 wallet: use db_exec_mayfail() for wallet_add_utxo.
This is the only case where we actually rely on the db to ensure we don't
do something twice: don't error out if it fails.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-06 10:24:34 +01:00
Rusty Russell b148b89baf db_exec_mayfail: variant of db_exec where we actually expect an error.
There's one caller where db_exec can actually fail due to constraints,
and we rely on it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-06 10:24:34 +01:00
Rusty Russell 1f7e370fda db: rollback transaction if we had an error.
This is temporary; we'll eventually fail on error.  However, since
db_exec() is a NOOP if we have an error, we need to do something.
2017-11-06 10:24:34 +01:00
Rusty Russell 360aa15e4d db_query: don't remove transaction or set error if query fails.
We return NULL in this case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-06 10:24:34 +01:00
Rusty Russell 5e46af64fc db: keep in_transaction as a counter, so we can nest commits.
Otherwise we find ourselves outside a commitment.  This is a bandaid
until we remove nested commitments again at the end of this series.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-06 10:24:34 +01:00
Christian Decker 77789bb705 db: Implemented poor mans nested transactions
Nesting is provided by only actually performing the outermost
transaction and simulating the nested ones. This still allows us to
ensure on lower levels that we are in the context of a transaction
without having to resort to keeping explicitly track of it in the
calling code.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-06 10:24:34 +01:00
Konstantin Nick 62ca15d6aa Fix python-api example 2017-11-06 10:24:09 +01:00
Jonas Nick 2543bc81b9 Fix docker tag in README 2017-11-04 11:35:32 +01:00
Rusty Russell 8cef36cbd7 lightningd: fail htlcs we fulfill if peer unresponsive after deadline.
Closes: #241
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-03 05:18:49 +00:00
Rusty Russell 1142c44c29 lightningd: fail htlcs we offer if peer unresponsive after deadline.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-03 05:18:49 +00:00
Rusty Russell 9662589ed8 lightningd: move notify_new_block() callback to peer_htlcs.
And change prototype to take the lightningd structure.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-03 05:18:49 +00:00
Rusty Russell bdabb24734 lightningd: note our complience on not forwarding an HTLC post deadline.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-03 05:18:49 +00:00
Rusty Russell c14b159166 lightningd: remove --deadline-blocks option.
We will derive it from other factors.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-03 05:18:49 +00:00
Rusty Russell a55ce607a1 bitcoind: contain ld pointer.
This is a subset of a "bitcoind: wrap callbacks in transaction." from
the everything-in-transaction branch, but we need the ld pointer now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-03 05:18:49 +00:00
Rusty Russell 860a76b1c9 lightningd: update to add `wire_expiry_too_far`.
From recently-merged BOLT update.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 09:46:05 +01:00
Rusty Russell 1ae57fb72c Update to latest BOLT.
Nothing changes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 09:46:05 +01:00
Rusty Russell 5502a19d1e json: reject incoming JSON which has any unusual characters in tokens.
ie. non-printable, quotes or escapes.  We allow these outside tokens
(we expect tabs and \n for example).

This is a big hammer, but if someone really wants we can add support
later.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 09:46:05 +01:00
Rusty Russell 112ae0d0f5 common/test/run-json: test JSON escaping.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 09:46:05 +01:00
Rusty Russell ab634dfcdd common/test_sphinx: change to standard run- format.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 09:46:05 +01:00
Rusty Russell b7774fcb0a bolt11: comment on weird assignment-then-check test.
Suggested-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 01:09:23 +00:00
Rusty Russell 8f17effeeb json: just blatt weird characters in string.
Don't try to escape them.  It's whack-a-mole and they shouldn't do it anyway.

Suggested-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 01:09:23 +00:00
Rusty Russell 1ec19093f7 Travis: check bolt quotes.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 01:09:23 +00:00
Rusty Russell a9002eac52 Update to latest BOLT.
And nail "make check-source" to that specific version (which is a commit id,
not a branch name, so needs a different syntax for git).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 01:09:23 +00:00
Rusty Russell 6c21da69e6 bolt11: 'c' support for min_final_cltv_expiry.
Based on latest draft spec, using variable length encoding.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 01:09:23 +00:00
Rusty Russell e1dc75e954 pay: new all-in-one RPC command.
Closes: #240
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 01:09:23 +00:00
Rusty Russell d577769350 invoice: provide bolt11 invoice.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 01:09:23 +00:00
Rusty Russell 8d09734536 bolt11: add decodepay RPC helper.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 01:09:23 +00:00
Rusty Russell 15e1e4b099 bolt11: support for encoding/decoding and checking.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 01:09:23 +00:00