Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c7c1a04
test_lightningd.py: make tests more robust by suppressing reconnects.
rustyrussell Apr 25, 2018
3524a32
gossipd: exponential backoff for reconnect (5 minute ceiling).
rustyrussell Apr 25, 2018
f000f52
gossipd: explicitly track which peers are important.
rustyrussell Apr 25, 2018
832fbf3
openingd: tell gossipd that the peer is important once funding tx in …
rustyrussell Apr 25, 2018
e0686ba
lightningd: tell gossipd that peers we load from db are important.
rustyrussell Apr 25, 2018
7e90e4e
gossipd: maintain a separate structure to track important peers.
rustyrussell Apr 25, 2018
b40b8f0
gossipd: keep reaching struct only when we're actively connecting, an…
rustyrussell Apr 26, 2018
39574c0
closing: don't go into temporary failure because we completed negotia…
rustyrussell Apr 26, 2018
66239b5
gossipd: drain fd instead of passing around gossip index.
rustyrussell Apr 26, 2018
c75ecd9
read_peer_msg: handle incoming gossip from gossipd.
rustyrussell Apr 26, 2018
174e578
subd: record which ones connect to a peer.
rustyrussell Apr 26, 2018
2b24e64
gossipd: have master explicitly tell us when peer is disconnected.
rustyrussell Apr 26, 2018
ad6f765
gossipd: make sure master only ever sees one active connection.
rustyrussell Apr 26, 2018
60e9d66
gossipd: use exponential backoff on reconnect for important peers.
rustyrussell Apr 26, 2018
c34ac8b
json_listpeers: use channel connected flag for JSON.
rustyrussell Apr 26, 2018
ea71a2a
gossipd: give more distinct errors.
rustyrussell Apr 26, 2018
a02d466
gossipd: don't create a new chain of timers on every connect command.
rustyrussell Apr 26, 2018
4421050
channeld: get told when announce depth already reached.
rustyrussell Apr 26, 2018
69fa1cc
lightningd: move "tell gossipd peer is no longer important" to drop_t…
rustyrussell Apr 26, 2018
e9da2e1
common: typo fix.
rustyrussell Apr 26, 2018
a553b44
gossipd: don't handle multiple connect requests, combine them in ligh…
rustyrussell Apr 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 28 additions & 82 deletions channeld/channel.c

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions channeld/channel_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ channel_init,,feerate_min,u32
channel_init,,feerate_max,u32
channel_init,,first_commit_sig,secp256k1_ecdsa_signature
channel_init,,crypto_state,struct crypto_state
channel_init,,gossip_index,u64
channel_init,,remote_fundingkey,struct pubkey
channel_init,,remote_revocation_basepoint,struct pubkey
channel_init,,remote_payment_basepoint,struct pubkey
Expand Down Expand Up @@ -59,6 +58,7 @@ channel_init,,final_scriptpubkey,final_scriptpubkey_len*u8
channel_init,,flags,u8
channel_init,,init_peer_pkt_len,u16
channel_init,,init_peer_pkt,init_peer_pkt_len*u8
channel_init,,reached_announce_depth,bool

# Tx is deep enough, go!
channel_funding_locked,1002
Expand Down Expand Up @@ -173,7 +173,6 @@ channel_got_shutdown,,scriptpubkey,scriptpubkey_len*u8
# Shutdown is complete, ready for closing negotiation. + peer_fd & gossip_fd.
channel_shutdown_complete,1025
channel_shutdown_complete,,crypto_state,struct crypto_state
channel_shutdown_complete,,gossip_index,u64

# Re-enable commit timer.
channel_dev_reenable_commit,1026
Expand Down
5 changes: 4 additions & 1 deletion closingd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ CLOSINGD_COMMON_OBJS := \
common/type_to_string.o \
common/utils.o \
common/version.o \
common/wire_error.o
common/wire_error.o \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The read_peer_msg handles this new feature in closingd and openingd? So it still occurs even if closingd and openingd do not include new code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's all inside read_peer_msg, which is why this change was a no-brainer.

common/wireaddr.o \
gossipd/gen_gossip_wire.o \
lightningd/gossip_msg.o

closingd/gen_closing_wire.h: $(WIRE_GEN) closingd/closing_wire.csv
$(WIRE_GEN) --header $@ closing_wire_type < closingd/closing_wire.csv > $@
Expand Down
53 changes: 22 additions & 31 deletions closingd/closing.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

static struct bitcoin_tx *close_tx(const tal_t *ctx,
struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
u8 *scriptpubkey[NUM_SIDES],
const struct bitcoin_txid *funding_txid,
Expand All @@ -43,7 +42,7 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
struct bitcoin_tx *tx;

if (satoshi_out[funder] < fee)
peer_failed(cs, gossip_index, channel_id,
peer_failed(cs, channel_id,
"Funder cannot afford fee %"PRIu64
" (%"PRIu64" and %"PRIu64")",
fee, satoshi_out[LOCAL],
Expand All @@ -62,7 +61,7 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
satoshi_out[REMOTE] - (funder == REMOTE ? fee : 0),
dust_limit);
if (!tx)
peer_failed(cs, gossip_index, channel_id,
peer_failed(cs, channel_id,
"Both outputs below dust limit:"
" funding = %"PRIu64
" fee = %"PRIu64
Expand All @@ -78,7 +77,6 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
}

static void do_reconnect(struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
const u64 next_index[NUM_SIDES],
u64 revocations_received,
Expand Down Expand Up @@ -111,7 +109,7 @@ static void do_reconnect(struct crypto_state *cs,

/* Wait for them to say something interesting */
channel_reestablish
= read_peer_msg(tmpctx, cs, gossip_index, channel_id,
= read_peer_msg(tmpctx, cs, channel_id,
sync_crypto_write_arg,
status_fail_io,
NULL);
Expand All @@ -120,7 +118,7 @@ static void do_reconnect(struct crypto_state *cs,
if (!fromwire_channel_reestablish(channel_reestablish, &their_channel_id,
&next_local_commitment_number,
&next_remote_revocation_number)) {
peer_failed(cs, gossip_index, channel_id,
peer_failed(cs, channel_id,
"bad reestablish msg: %s %s",
wire_type_name(fromwire_peektype(channel_reestablish)),
tal_hex(tmpctx, channel_reestablish));
Expand All @@ -144,7 +142,6 @@ static void do_reconnect(struct crypto_state *cs,
}

static void send_offer(struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
const struct pubkey funding_pubkey[NUM_SIDES],
const u8 *funding_wscript,
Expand All @@ -168,7 +165,7 @@ static void send_offer(struct crypto_state *cs,
* the close transaction as specified in [BOLT
* #3](03-transactions.md#closing-transaction).
*/
tx = close_tx(tmpctx, cs, gossip_index, channel_id,
tx = close_tx(tmpctx, cs, channel_id,
scriptpubkey,
funding_txid,
funding_txout,
Expand Down Expand Up @@ -214,7 +211,6 @@ static void tell_master_their_offer(const secp256k1_ecdsa_signature *their_sig,

/* Returns fee they offered. */
static uint64_t receive_offer(struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
const struct pubkey funding_pubkey[NUM_SIDES],
const u8 *funding_wscript,
Expand All @@ -237,7 +233,7 @@ static uint64_t receive_offer(struct crypto_state *cs,
do {
clean_tmpctx();

msg = read_peer_msg(tmpctx, cs, gossip_index, channel_id,
msg = read_peer_msg(tmpctx, cs, channel_id,
sync_crypto_write_arg,
status_fail_io,
NULL);
Expand All @@ -262,7 +258,7 @@ static uint64_t receive_offer(struct crypto_state *cs,

if (!fromwire_closing_signed(msg, &their_channel_id,
&received_fee, &their_sig))
peer_failed(cs, gossip_index, channel_id,
peer_failed(cs, channel_id,
"Expected closing_signed: %s",
tal_hex(tmpctx, msg));

Expand All @@ -273,7 +269,7 @@ static uint64_t receive_offer(struct crypto_state *cs,
* #3](03-transactions.md#closing-transaction), and MUST fail
* the connection if it is not.
*/
tx = close_tx(tmpctx, cs, gossip_index, channel_id,
tx = close_tx(tmpctx, cs, channel_id,
scriptpubkey,
funding_txid,
funding_txout,
Expand All @@ -299,7 +295,7 @@ static uint64_t receive_offer(struct crypto_state *cs,
* then remove any output below its own `dust_limit_satoshis`,
* and MAY also eliminate its own output.
*/
trimmed = close_tx(tmpctx, cs, gossip_index, channel_id,
trimmed = close_tx(tmpctx, cs, channel_id,
scriptpubkey,
funding_txid,
funding_txout,
Expand All @@ -309,7 +305,7 @@ static uint64_t receive_offer(struct crypto_state *cs,
if (!trimmed
|| !check_tx_sig(trimmed, 0, NULL, funding_wscript,
&funding_pubkey[REMOTE], &their_sig)) {
peer_failed(cs, gossip_index, channel_id,
peer_failed(cs, channel_id,
"Bad closing_signed signature for"
" %s (and trimmed version %s)",
type_to_string(tmpctx,
Expand Down Expand Up @@ -368,14 +364,13 @@ static void init_feerange(struct feerange *feerange,
}

static void adjust_feerange(struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
struct feerange *feerange,
u64 offer, enum side side)
{
if (offer < feerange->min || offer > feerange->max) {
if (!feerange->allow_mistakes || side != REMOTE)
peer_failed(cs, gossip_index, channel_id,
peer_failed(cs, channel_id,
"%s offer %"PRIu64
" not between %"PRIu64" and %"PRIu64,
side == LOCAL ? "local" : "remote",
Expand All @@ -402,7 +397,6 @@ static void adjust_feerange(struct crypto_state *cs,

/* Figure out what we should offer now. */
static u64 adjust_offer(struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
const struct feerange *feerange,
u64 remote_offer,
Expand All @@ -414,7 +408,7 @@ static u64 adjust_offer(struct crypto_state *cs,

/* Max is below our minimum acceptable? */
if (feerange->max < min_fee_to_accept)
peer_failed(cs, gossip_index, channel_id,
peer_failed(cs, channel_id,
"Feerange %"PRIu64"-%"PRIu64
" below minimum acceptable %"PRIu64,
feerange->min, feerange->max,
Expand Down Expand Up @@ -446,7 +440,6 @@ int main(int argc, char *argv[])
struct secrets secrets;
bool reconnected;
u64 next_index[NUM_SIDES], revocations_received;
u64 gossip_index;
enum side whose_turn;
bool deprecated_api;
u8 *channel_reestablish;
Expand All @@ -457,7 +450,7 @@ int main(int argc, char *argv[])

msg = wire_sync_read(tmpctx, REQ_FD);
if (!fromwire_closing_init(ctx, msg,
&cs, &gossip_index, &seed,
&cs, &seed,
&funding_txid, &funding_txout,
&funding_satoshi,
&funding_pubkey[REMOTE],
Expand Down Expand Up @@ -490,7 +483,7 @@ int main(int argc, char *argv[])
&funding_pubkey[REMOTE]);

if (reconnected)
do_reconnect(&cs, gossip_index, &channel_id,
do_reconnect(&cs, &channel_id,
next_index, revocations_received,
channel_reestablish);

Expand All @@ -508,7 +501,7 @@ int main(int argc, char *argv[])
whose_turn = funder;
for (size_t i = 0; i < 2; i++, whose_turn = !whose_turn) {
if (whose_turn == LOCAL) {
send_offer(&cs, gossip_index,
send_offer(&cs,
&channel_id, funding_pubkey,
funding_wscript,
scriptpubkey, &funding_txid, funding_txout,
Expand All @@ -524,7 +517,7 @@ int main(int argc, char *argv[])
" ours was %"PRIu64" satoshi",
offer[LOCAL]);
offer[REMOTE]
= receive_offer(&cs, gossip_index,
= receive_offer(&cs,
&channel_id, funding_pubkey,
funding_wscript,
scriptpubkey, &funding_txid,
Expand All @@ -539,25 +532,24 @@ int main(int argc, char *argv[])
init_feerange(&feerange, commitment_fee, offer);

/* Apply (and check) funder offer now. */
adjust_feerange(&cs, gossip_index, &channel_id,
&feerange, offer[funder], funder);
adjust_feerange(&cs, &channel_id, &feerange, offer[funder], funder);

/* Older spec clients would make offers independently, so allow */
feerange.allow_mistakes = deprecated_api;

/* Now any extra rounds required. */
while (offer[LOCAL] != offer[REMOTE]) {
/* Still don't agree: adjust feerange based on previous offer */
adjust_feerange(&cs, gossip_index, &channel_id,
adjust_feerange(&cs, &channel_id,
&feerange,
offer[!whose_turn], !whose_turn);

if (whose_turn == LOCAL) {
offer[LOCAL] = adjust_offer(&cs, gossip_index,
offer[LOCAL] = adjust_offer(&cs,
&channel_id,
&feerange, offer[REMOTE],
min_fee_to_accept);
send_offer(&cs, gossip_index, &channel_id,
send_offer(&cs, &channel_id,
funding_pubkey,
funding_wscript,
scriptpubkey, &funding_txid, funding_txout,
Expand All @@ -570,7 +562,7 @@ int main(int argc, char *argv[])
" theirs was %"PRIu64" satoshi,",
offer[LOCAL], offer[REMOTE]);
offer[REMOTE]
= receive_offer(&cs, gossip_index, &channel_id,
= receive_offer(&cs, &channel_id,
funding_pubkey,
funding_wscript,
scriptpubkey, &funding_txid,
Expand All @@ -587,8 +579,7 @@ int main(int argc, char *argv[])
offer[LOCAL]);

/* We're done! */
wire_sync_write(REQ_FD,
take(towire_closing_complete(NULL, gossip_index)));
wire_sync_write(REQ_FD, take(towire_closing_complete(NULL)));
tal_free(ctx);
daemon_shutdown();

Expand Down
2 changes: 0 additions & 2 deletions closingd/closing_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Begin! (passes peer fd, gossipd-client fd)
closing_init,2001
closing_init,,crypto_state,struct crypto_state
closing_init,,gossip_index,u64
closing_init,,seed,struct privkey
closing_init,,funding_txid,struct bitcoin_txid
closing_init,,funding_txout,u16
Expand Down Expand Up @@ -38,4 +37,3 @@ closing_received_signature_reply,2102

# Negotiations complete, we're exiting.
closing_complete,2004
closing_complete,,gossip_index,u64
8 changes: 4 additions & 4 deletions common/peer_failed.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/* We only support one channel per peer anyway */
void peer_failed_(int peer_fd, int gossip_fd,
struct crypto_state *cs, u64 gossip_index,
struct crypto_state *cs,
const struct channel_id *channel_id,
const char *fmt, ...)
{
Expand All @@ -22,7 +22,7 @@ void peer_failed_(int peer_fd, int gossip_fd,
va_end(ap);

msg = towire_status_peer_error(NULL, channel_id,
desc, cs, gossip_index,
desc, cs,
towire_errorfmt(desc, channel_id,
"%s", desc));
peer_billboard(true, desc);
Expand All @@ -32,12 +32,12 @@ void peer_failed_(int peer_fd, int gossip_fd,

/* We're failing because peer sent us an error message */
void peer_failed_received_errmsg(int peer_fd, int gossip_fd,
struct crypto_state *cs, u64 gossip_index,
struct crypto_state *cs,
const char *desc,
const struct channel_id *channel_id)
{
u8 *msg = towire_status_peer_error(NULL, channel_id,
desc, cs, gossip_index, NULL);
desc, cs, NULL);
peer_billboard(true, "Received error from peer: %s", desc);
status_send_fatal(take(msg), peer_fd, gossip_fd);
}
Expand Down
12 changes: 5 additions & 7 deletions common/peer_failed.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,21 @@ struct channel_id;
/**
* peer_failed - Exit with error for peer.
* @cs: the peer's current crypto state.
* @gossip_index: the peer's current gossip_index.
* @channel_id: channel with error, or NULL for all.
* @fmt...: format as per status_failed(STATUS_FAIL_PEER_BAD)
*/
#define peer_failed(cs, gossip_index, channel_id, ...) \
peer_failed_(PEER_FD, GOSSIP_FD, (cs), (gossip_index), (channel_id), \
__VA_ARGS__)
#define peer_failed(cs, channel_id, ...) \
peer_failed_(PEER_FD, GOSSIP_FD, (cs), (channel_id), __VA_ARGS__)

void peer_failed_(int peer_fd, int gossip_fd,
struct crypto_state *cs, u64 gossip_index,
struct crypto_state *cs,
const struct channel_id *channel_id,
const char *fmt, ...)
PRINTF_FMT(6,7) NORETURN;
PRINTF_FMT(5,6) NORETURN;

/* We're failing because peer sent us an error message */
void peer_failed_received_errmsg(int peer_fd, int gossip_fd,
struct crypto_state *cs, u64 gossip_index,
struct crypto_state *cs,
const char *desc,
const struct channel_id *channel_id) NORETURN;

Expand Down
1 change: 0 additions & 1 deletion common/peer_status_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ status_peer_error,0xFFF4
status_peer_error,,channel,struct channel_id
status_peer_error,,desc,wirestring
status_peer_error,,crypto_state,struct crypto_state
status_peer_error,,gossip_index,u64
status_peer_error,,len,u16
status_peer_error,,error_for_them,len*u8
Loading