Commit Graph

1906 Commits

Author SHA1 Message Date
Christian Decker 02aba77698 channel: Passing channel_flags through to channeld 2017-06-30 19:55:17 +09:30
Rusty Russell ac1172c7b0 lightningd: check scriptpubkey in shutdown.
Important: a non-standard one can make the closing tx not propagate.

Drive-by cut&paste message fix, too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-29 00:08:21 +02:00
Rusty Russell 4881129f54 peer_fail_permanent: handle take() arg.
We assume this in at least one caller.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-29 00:08:21 +02:00
Rusty Russell ee9ebbc184 channeld: fix `funding_locked` retransmission using latest revision of BOLT2.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-29 00:08:21 +02:00
Rusty Russell 42c9cb58c7 channeld: rename commit_index to next_index.
This is what it actually is, and makes it clearer when we refer to the
spec.  It's the commitment we're currently updating, which is the next
commitment.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-29 00:08:21 +02:00
Rusty Russell d411b07ba2 channeld: fix make_revocation_msg() to take index of revoke.
It currently takes index + 1 (ie. current commit), which is confusing
in this context.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-29 00:08:21 +02:00
Rusty Russell 1679f2da06 channeld: update to send next commitment number on connection reestablish.
As per latest BOLT revision.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-29 00:08:21 +02:00
Rusty Russell 05b9e0d538 channeld: do connection reestablishment synchronously.
We currently have the problem that the master can send new HTLCs before
we've processed the incoming reestablish message.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-29 00:08:21 +02:00
Rusty Russell 456fa39380 sync_crypto_write: support take(msg)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-29 00:08:21 +02:00
Rusty Russell de5bf56ffa opening: update to new open_channel with channel_flags.
While we're there, make the announcement conditional on it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-29 00:08:21 +02:00
Rusty Russell d492f3872c wire/peer_wire: rename gossip_msg / unknown_msg / unknown_msg_discardable
The next patch includes wire/peer_wire.h and causes a compile error
as lightningd/gossip_control.c defined its own gossip_msg function.

New names are clearer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-29 00:08:21 +02:00
Rusty Russell fc4e2d8b48 lightningd: fix typo.
If we're going to die, at least we can do so with dignity.

Reported-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell 99289bece7 lightningd/peer_control.c: fix memleak.
Reported-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell 5edc14ee1a tests/test_lightningd.py: make test less flaky.
When we drop an HTLC_ADD packet, sometimes the commit timer fires
before we try to read from the fd.  In this case, the payment is
considered committed and we don't fail.

We need manual commit to work around this, and also we'd need to do
the pay command asynchronously from python because it will block.
That's a bit out of scope for now, so just handle either way.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell ac703ff9dc lgihtningd: remove extraneous whitespace.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell e2c5104aab lightningd: immediately fail HTLCs coming in from shutting down channels.
This can happen even without a protocol violation, if the incoming
update_add_htlc crosses over our outgoing shutdown.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell 866ac79850 channeld: shutdown support.
We keep the scriptpubkey to send until after a commitment_signed (or,
in the corner case, if there's no pending commitment).  When we
receive a shutdown from the peer, we pass it up to the master.

It's up to the master not to add any more HTLCs, which works because
we move from CHANNELD_NORMAL to CHANNELD_SHUTTING_DOWN.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell be6347b814 tools/generate-wire.py: unmarshall zero-length arrays as NULL.
This is symmetrical with marshalling.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell da18645901 tools/generate-wire.py: don't avoice tal_count() on NULL.
It actually works fine with recent ccan/tal (returning 0).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell a0800e352a wallet_get_newindex: encapsulate routine to get a new keyindex.
We'll want this for shutdown.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell ee00c2c508 lightningd: remove peer->gossip_client_fd
We don't need to keep this around any more: by handing it to
subdaemons we ensure we'll close it if the peer disconnects, and we
also add code to get a new one on reconnection.

Because getting a gossip_fd is async, we re-check the peer state after
it gets back.  This is kind of annoying: perhaps if we were to hand
the reconnected peer through gossipd (with a flag to immediately
return it) we could get the gossip fd that way and unify the paths?

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell 4185153d81 gossipd: interface to get a client gossip_fd for a reconnect.
At the moment, master simply keeps the gossip fd open when peer
disconnects.  That's inefficient, and wrong anyway (it may want a
complete new sync, or may not, but we'll currently send all the
messages including stale ones).

This interface will be required for restart anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell ea52b0a8ff openingd: pass back gossip fd on completion.
For the moment, master still keeps a dup of gossip_fd, but that's the next
patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell 2ff50107ac lightningd/hsm_control: use a simple fd for HSM.
Now we're always sync, just use an fd.  Put the hsm_sync_read() helper
here, too, and do HSM init sync which makes things much simpler.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell 6e59f85666 subd: expose raw API for getting a single fd to a subdaemon.
We're going to use this for the HSM.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell 8631539822 wallet: talk to HSM synchronously.
We temporarily play games with the hsm fd; those will go away once
we're done.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell 4ef3e9e3fb lightningd/peer_control: get announcement signature from HSM synchronously.
We temporarily play games with the hsm fd; those will go away once
we're done.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell d1d84a81d2 lightningd/new_connection: get handshake fd from HSM synchronously.
We temporarily play games with the hsm fd; those will go away once
we're done.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell 7213312f57 lightningd: remove fd from struct peer.
With no async calls left, we can just use a stack variable for the fd.

And we're now *always* in the hands of some daemon, unless we're
disconnected, so owner is only NULL in that case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell f2d4309add lightningd/subd: explicit failure reply support.
We had a terrible hack in gossip when a peer didn't exist.  Formalize
a pattern when code+200 is a failure (with no fds passed), and use it
here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell 31ff5a49f4 lightningd/peer_control: remove cs from struct peer.
Now we're not async, we don't need to pack it into struct peer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell 232a182b25 lightningd: get fd from HSM synchronously.
This means there's no GETTING_HSMFD state at all any more.  We
temporarily play games with the hsm fd; those will go away once we're
done.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell 77620ea06f lightningd: get funding signature from HSM synchronously.
This means there's no GETTING_SIG_FROM_HSM state at all any more.  We
temporarily play games with the hsm fd; those will go away once we're
done.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell 40ce29beac wire_sync_write: support take()
We often want it to free the message after writing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Christian Decker 8c6fab0ec4 wallet: Do not create dust from withdrawal transactions 2017-06-23 16:02:20 +09:30
Christian Decker a1faccb9dc walletrpc: Split owned output detection out and use it for change
Splitting the detection for outputs that we own into a separate
`wallet_extract_owned_outputs` function and use it when the broadcast
succeeds to re-add the change output back to the database.
2017-06-23 16:02:20 +09:30
Christian Decker 938ab67a01 wallet: move can_spend to wallet.c and json_addfunds to walletrpc.c 2017-06-23 16:02:20 +09:30
Christian Decker d6656358b5 wallet: Add bip32_base to the wallet struct
Wallet should really be the container for anything bip32 related, so
I'd like to slowly wean off of `ld->bip32_base` in favor of
`ld->wallet->bip32_base`
2017-06-23 16:02:20 +09:30
Christian Decker 8cdab9da1e wallet: Move json_newaddr to wallet.c 2017-06-23 16:02:20 +09:30
Christian Decker 462d936f25 wallet: Add unit test for withdrawal 2017-06-23 16:02:20 +09:30
Christian Decker b4e4a744aa walletrpc: Implemented the withdrawal flow 2017-06-23 16:02:20 +09:30
Christian Decker 8c4f381afb hsm: Sign withdrawal transactions 2017-06-23 16:02:20 +09:30
Christian Decker a775b52941 wallet: Return change satoshis when selecting coins
We'd be computing them later most of the time anyway.
2017-06-23 16:02:20 +09:30
Christian Decker 3f594172b2 hsm: Add messages for withdrawal signature requests 2017-06-23 16:02:20 +09:30
Christian Decker 479036604b wallet: Implement withdrawal transaction generation
This will be used by both the master daemon and the HSM to
generate (hopefully) identical transactions for signature and
broadcast.
2017-06-23 16:02:20 +09:30
Christian Decker 7738bccf42 wallet: Move coin-selection primitives to wallet
We'll re-use them a few times so having them at a central location is
nice. We also fix a bug that was unreserving UTXO entries upon free,
instead of promoting them to being spent.
2017-06-23 16:02:20 +09:30
Christian Decker 28030c3d6b bitcoind: peer argument to bitcoind_sendrawtx is unused
This was a bit misleading, and we were passing in NULL sometimes
anyway. Removed unused argument.
2017-06-23 16:02:20 +09:30
Christian Decker 1522eee528 unittests: Test some more of the db primitives. 2017-06-23 16:02:20 +09:30
Christian Decker 40165ba6d5 script: Use pkh to construct p2pkh output scripts
So far we always needed to know the public key, which was not the case
for addresses that we don't own. Moving the hashing outside of the
script construction allows us to send to arbitrary addresses. I also
added the hash computation to the pubkey primitives.
2017-06-23 16:02:20 +09:30
Christian Decker f10b779c83 pubkey: valgrind was reporting about unset memory in address parsing
This is likely due to `libbase58` implicitly relying on the passed in
buffer to be memset to 0, in order to report the correct decoded
length.
2017-06-23 16:02:20 +09:30