Commit Graph

341 Commits

Author SHA1 Message Date
Christian Decker d966961fbe gossip: Refactoring the gossip handlers to use the routing_state 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 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 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 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 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
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
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 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
Rusty Russell c2cc164d6d daemon: disable old BOLT checks.
This is useful for the next patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-04 14:09:20 +10:30
Rusty Russell dec3b9d030 peer: don't ever set up listener on dynamic port.
Simplifies the logic somewhat.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-04 14:09:15 +10:30
Rusty Russell 12b30ab4fc jsonrpc: register base on linkage.
Other than being neater (no more global list to edit!), this lets the
new daemon and old daemon have their own separate routines.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-04 14:08:15 +10:30
Rusty Russell ca4d03aa2a lightningd_state: move invoices into separate structure.
It's all maintained by invoice.c, so make it private to that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-04 13:18:47 +10:30
Christian Decker 0ed23c46a9 gossip: Implemented routing table sync with newly connected peers 2017-01-03 15:08:05 +10:30
Christian Decker 71a18fdd2e gossip: Trigger announce on channel establishment
Since we ultimately want to have a very long re-announcement timeout
we better trigger an announcement upon channel state change to normal.
2017-01-03 15:08:05 +10:30
Christian Decker d93ce12afa gossip: Broadcasting and handling gossip messages 2017-01-03 15:08:05 +10:30
Christian Decker db481d881a proto: Added handling for nested packets 2017-01-03 15:08:05 +10:30
Rusty Russell e109977df7 peer: don't print uninitialized commit_num.
Reported-by: Lucas Betschart <lucasbetschart@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-15 11:44:48 +10:30
Rusty Russell 2a68a984c3 peer: fix unassigned error packet on receiving non-ASCII error.
Reported-by: Lucas Betschart <lucasbetschart@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-15 11:42:24 +10:30
Rusty Russell 1b170c85bb Revert "Fix -Wsometimes-uninitialized and -Wuninitialized"
This reverts commit ff9cdda4fa.

These are real bugs, so I prefer to fix them explicitly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-15 11:41:31 +10:30
Lucas Betschart ff9cdda4fa Fix -Wsometimes-uninitialized and -Wuninitialized 2016-12-14 08:45:40 +01:00
Rusty Russell a4fdaab5b3 Use global secp256k1_ctx instead of passing it around.
If I'd known how large this patch would be (though trivial), I'd
have done it in parts.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-02 18:12:58 +10:30
Christian Decker bf81f7af15 Merge pull request #93 from ElementsProject/fix-87-open-too-small-for-fee
json_connect: don't try to double-fail if amount insufficient.
2016-11-16 13:04:26 +01:00
Rusty Russell 94adbd241d json_connect: don't try to double-fail if amount insufficient.
Closes: #87
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-14 11:46:09 +10:30
Christian Decker 34b4134cb0 bugfix: Removed spurious printf in peer.c
I must've left that on in. Fixes #89
2016-11-14 00:29:01 +01:00
Rusty Russell f5c00deec7 Remove trailing whitespace from source.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-11 09:32:04 +10:30
Rusty Russell e7e7345596 peer: fix steal (penalty tx) generation code.
In particular, we got a segv because we were measuring the wrong
wscript, then we miswired the inputs.  It only worked because our
current steal tests don't have a to_us_idx output.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-10 23:28:35 +10:30
Rusty Russell 3372645d8e peer_disconnect: simply free if in STATE_INIT.
db_forget_peer() was harmless, but we haven't been entered into the
database yet anyway, and it asserted that we should have been STATE_CLOSED.

Closes: #67
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-10 11:21:16 +10:30
Rusty Russell 4bed6c8c67 controlled_time: remove
We don't need it for testing at the moment, and if we do it'll have
to change to relative anyway now we're going to use time_mono().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 18:54:15 +10:30
Rusty Russell 3aca5c87e3 init: rebroadcast anchors on restart if we haven't seen them.
It's possible that we won't have sent the anchor, but state is
committed in db.  And our current philosophy is that we retransmit all
the txs dumbly, all the time.

Our --restart --timeout-anchor test trigger this case, too, so
re-enable that now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 18:52:15 +10:30
Rusty Russell 6f360422d4 chaintopology: restore anchor timeout.
Instead of using wall-clock time, we use blocks.  This is simpler and
better for database restores.  And both sides will time out.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 17:14:22 +10:30
Rusty Russell 56b0f03c5a peer: fix retransmission before open packet.
Re-enabling the next test revealed bugs: if we need to retransmit the
initial open_commit_sig packet, we currently tried to send it as an
UPDATE_COMMIT, which isn't allowed.  Fixing that revealed that if
we have to retransmit the initial open, we didn't do that either.

Thus the initial open should count towards the ack count, and we should
special case transmissions of 0 (pkt_open) and 1
(pkt_open_commit_sig).

We also save those early state changes to the database.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:28 +10:30
Rusty Russell 41f3f8e067 db: store anchor input.
If we die before we've established connection, we should remember how
we were going to fund it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:28 +10:30
Rusty Russell adae62e261 peer: determine fees earlier.
Sure, information might be out of date, but at least we can report an
error earlier.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:28 +10:30
Rusty Russell 9463e1b630 wallet: use pubkey as API, not pointer.
Much easier to save/restore to/from database in coming patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:28 +10:30
Rusty Russell 7f0a56f674 queue_pkt_open: take bool for API.
No need to leak protobuf enum outside.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:28 +10:30
Rusty Russell 536a48940e protocol: don't ever reply to PKT_ERR with PKT_ERR.
The simplest way is to always use peer_received_unexpected_pkt() which
sends the error packet, and ensure it doesn't do so in response to
pkt_err.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:27 +10:30
Rusty Russell cf91409ff2 start_closing: always switch states inside transaction.
This means checks in multiple places, but ensures atomicity.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:26 +10:30
Rusty Russell 6b05436a7a open: use a single transaction when shutdown, so it's atomic.
This covers the case of shutdown during open.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:26 +10:30
Rusty Russell 41d4779abe peer_database_err: helper for database error packet.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:26 +10:30
Rusty Russell eedf95a8fc state_types: simplify open states.
The state now doesn't differentiate between who is funding.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:26 +10:30
Rusty Russell 1f23905bee peer: move start_closing() function higher in peer.c
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:26 +10:30
Rusty Russell 99e48c7c87 peer: don't differentiate who is funding via state when waiting for open.
It doesn't actually help here; we only did it because we differentiate
the states later, and with refactoring we do that via the explicit
offer_anchor flag.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:25 +10:30
Rusty Russell ea74bac8b8 state: hoist open-they-are-funding states handling into peer.c, remove state.[ch]
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:25 +10:30
Rusty Russell 75ff09b310 state: hoist open-we-are-funding states handling into peer.c
This means we can now do all database changes, including db_set_visible_state,
within a single transaction (ie. atomically).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:25 +10:30
Rusty Russell 8c5fae2b28 patch remove-bitcoin_release_anchor.patch 2016-11-09 08:04:24 +10:30
Rusty Russell f71f0da19c offer_anchor: store a bool, not am enum state_input.
Since we no longer feed it into state.c, we can just us a bool.
And that's the last of the CMD_* in the enum state_input, so remove them
all.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:24 +10:30