Browse Source

gossipd: hand out gossip_index to other daemons.

When gossipd sends a message, have a gossip_index.  When it gets back a
peer, the current gossip_index is included, so it can know exactly where
it's up to.

Most of this is mechanical plumbing through openingd, channeld and closingd,
even though openingd and closingd don't (currently) read gossip, so their
gossip_index will be unchanged.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
94711969f9
  1. 23
      channeld/channel.c
  2. 2
      channeld/channel_wire.csv
  3. 6
      closingd/closing.c
  4. 2
      closingd/closing_wire.csv
  5. 16
      gossipd/gossip.c
  6. 11
      gossipd/gossip_wire.csv
  7. 7
      lightningd/gossip_control.c
  8. 72
      lightningd/peer_control.c
  9. 1
      lightningd/peer_control.h
  10. 6
      openingd/opening.c
  11. 4
      openingd/opening_wire.csv

23
channeld/channel.c

@ -160,6 +160,9 @@ struct peer {
u8 channel_flags;
bool announce_depth_reached;
/* Where we got up to in gossip broadcasts. */
u64 gossip_index;
};
static u8 *create_channel_announcement(const tal_t *ctx, struct peer *peer);
@ -176,15 +179,23 @@ static void *tal_arr_append_(void **p, size_t size)
static void gossip_in(struct peer *peer, const u8 *msg)
{
u16 type = fromwire_peektype(msg);
u8 *gossip;
u16 type;
if (!fromwire_gossip_send_gossip(msg, msg, NULL,
&peer->gossip_index, &gossip))
status_failed(STATUS_FAIL_GOSSIP_IO,
"Got bad message from gossipd: %s",
tal_hex(msg, msg));
type = fromwire_peektype(gossip);
if (type == WIRE_CHANNEL_ANNOUNCEMENT || type == WIRE_CHANNEL_UPDATE ||
type == WIRE_NODE_ANNOUNCEMENT)
msg_enqueue(&peer->peer_out, msg);
msg_enqueue(&peer->peer_out, gossip);
else
status_failed(STATUS_FAIL_GOSSIP_IO,
"Got bad message from gossipd: %s",
tal_hex(msg, msg));
"Got bad message type %s from gossipd: %s",
wire_type_name(type), tal_hex(msg, msg));
}
static void send_announcement_signatures(struct peer *peer)
@ -2256,6 +2267,7 @@ static void init_channel(struct peer *peer)
&peer->feerate_min, &peer->feerate_max,
&peer->their_commit_sig,
&peer->cs,
&peer->gossip_index,
&funding_pubkey[REMOTE],
&points[REMOTE].revocation,
&points[REMOTE].payment,
@ -2427,7 +2439,8 @@ static void send_shutdown_complete(struct peer *peer)
/* Now we can tell master shutdown is complete. */
wire_sync_write(MASTER_FD,
take(towire_channel_shutdown_complete(peer,
&peer->cs)));
&peer->cs,
peer->gossip_index)));
fdpass_send(MASTER_FD, PEER_FD);
fdpass_send(MASTER_FD, GOSSIP_FD);
close(MASTER_FD);

2
channeld/channel_wire.csv

@ -18,6 +18,7 @@ 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
@ -183,6 +184,7 @@ 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

Can't render this file because it has a wrong number of fields in line 2.

6
closingd/closing.c

@ -168,6 +168,7 @@ int main(int argc, char *argv[])
secp256k1_ecdsa_signature sig;
bool reconnected;
u64 next_index[NUM_SIDES], revocations_received;
u64 gossip_index;
if (argc == 2 && streq(argv[1], "--version")) {
printf("%s\n", version());
@ -184,7 +185,7 @@ int main(int argc, char *argv[])
msg = wire_sync_read(ctx, REQ_FD);
if (!fromwire_closing_init(ctx, msg, NULL,
&cs, &seed,
&cs, &gossip_index, &seed,
&funding_txid, &funding_txout,
&funding_satoshi,
&funding_pubkey[REMOTE],
@ -473,7 +474,8 @@ int main(int argc, char *argv[])
}
/* We're done! */
wire_sync_write(REQ_FD, take(towire_closing_complete(ctx)));
wire_sync_write(REQ_FD,
take(towire_closing_complete(ctx, gossip_index)));
tal_free(ctx);
return 0;

2
closingd/closing_wire.csv

@ -3,6 +3,7 @@
# 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 sha256_double
closing_init,,funding_txout,u16
@ -33,3 +34,4 @@ closing_received_signature_reply,2102
# Negotiations complete, we're exiting.
closing_complete,2004
closing_complete,,gossip_index,u64

Can't render this file because it has a wrong number of fields in line 3.

16
gossipd/gossip.c

@ -332,6 +332,7 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
/* We will not have anything queued, since we're not duplex. */
msg = towire_gossip_peer_connected(peer, &peer->id, &peer->addr,
&peer->local->pcs.cs,
peer->broadcast_index,
peer->gfeatures, peer->lfeatures);
if (!send_peer_with_fds(peer, msg))
return io_close(conn);
@ -509,6 +510,7 @@ static struct io_plan *ready_for_master(struct io_conn *conn, struct peer *peer)
msg = towire_gossip_peer_nongossip(peer, &peer->id,
&peer->addr,
&peer->local->pcs.cs,
peer->broadcast_index,
peer->gfeatures,
peer->lfeatures,
peer->local->nongossip_msg);
@ -516,6 +518,7 @@ static struct io_plan *ready_for_master(struct io_conn *conn, struct peer *peer)
msg = towire_gossipctl_release_peer_reply(peer,
&peer->addr,
&peer->local->pcs.cs,
peer->broadcast_index,
peer->gfeatures,
peer->lfeatures);
@ -830,7 +833,10 @@ static struct io_plan *nonlocal_dump_gossip(struct io_conn *conn, struct daemon_
return msg_queue_wait(conn, &peer->remote->out,
daemon_conn_write_next, dc);
} else {
return io_write_wire(conn, next->payload,
u8 *msg = towire_gossip_send_gossip(conn,
peer->broadcast_index,
next->payload);
return io_write_wire(conn, take(msg),
nonlocal_gossip_broadcast_done, dc);
}
}
@ -855,6 +861,7 @@ struct returning_peer {
struct daemon *daemon;
struct pubkey id;
struct crypto_state cs;
u64 gossip_index;
u8 *inner_msg;
int peer_fd, gossip_fd;
};
@ -871,8 +878,8 @@ static struct io_plan *handle_returning_peer(struct io_conn *conn,
"hand_back_peer unknown peer: %s",
type_to_string(trc, struct pubkey, &rpeer->id));
/* We don't need the gossip_fd. We could drain it, so no gossip msgs
* are missed, but that seems overkill. */
/* We don't need the gossip_fd; we know what gossip it got
* from gossip_index */
close(rpeer->gossip_fd);
/* Possible if there's a reconnect: ignore handed back. */
@ -894,6 +901,7 @@ static struct io_plan *handle_returning_peer(struct io_conn *conn,
peer->local = new_local_peer_state(peer, &rpeer->cs);
peer->local->fd = rpeer->peer_fd;
peer->broadcast_index = rpeer->gossip_index;
/* If they told us to send a message, queue it now */
if (tal_len(rpeer->inner_msg))
@ -919,6 +927,7 @@ static struct io_plan *hand_back_peer(struct io_conn *conn,
rpeer->daemon = daemon;
if (!fromwire_gossipctl_hand_back_peer(msg, msg, NULL,
&rpeer->id, &rpeer->cs,
&rpeer->gossip_index,
&rpeer->inner_msg))
master_badmsg(WIRE_GOSSIPCTL_HAND_BACK_PEER, msg);
@ -1555,6 +1564,7 @@ static struct io_plan *recv_req(struct io_conn *conn, struct daemon_conn *master
case WIRE_GOSSIP_PEER_NONGOSSIP:
case WIRE_GOSSIP_GET_UPDATE:
case WIRE_GOSSIP_GET_UPDATE_REPLY:
case WIRE_GOSSIP_SEND_GOSSIP:
break;
}

11
gossipd/gossip_wire.csv

@ -31,6 +31,7 @@ gossip_peer_connected,3002
gossip_peer_connected,,id,struct pubkey
gossip_peer_connected,,addr,struct wireaddr
gossip_peer_connected,,crypto_state,struct crypto_state
gossip_peer_connected,,gossip_index,u64
gossip_peer_connected,,gflen,u16
gossip_peer_connected,,gfeatures,gflen*u8
gossip_peer_connected,,lflen,u16
@ -41,6 +42,7 @@ gossip_peer_nongossip,3003
gossip_peer_nongossip,,id,struct pubkey
gossip_peer_nongossip,,addr,struct wireaddr
gossip_peer_nongossip,,crypto_state,struct crypto_state
gossip_peer_nongossip,,gossip_index,u64
gossip_peer_nongossip,,gflen,u16
gossip_peer_nongossip,,gfeatures,gflen*u8
gossip_peer_nongossip,,lflen,u16
@ -56,6 +58,7 @@ gossipctl_release_peer,,id,struct pubkey
gossipctl_release_peer_reply,3104
gossipctl_release_peer_reply,,addr,struct wireaddr
gossipctl_release_peer_reply,,crypto_state,struct crypto_state
gossipctl_release_peer_reply,,gossip_index,u64
gossipctl_release_peer_reply,,gflen,u16
gossipctl_release_peer_reply,,gfeatures,gflen*u8
gossipctl_release_peer_reply,,lflen,u16
@ -64,10 +67,11 @@ gossipctl_release_peer_reply,,lfeatures,lflen*u8
# Gossipd -> master: reply to gossip_release_peer if we couldn't find the peer.
gossipctl_release_peer_replyfail,3204
# Gossipd -> master: take back peer, with optional msg. (+peer fd, +gossip fd)
# master -> gossipd: take back peer, with optional msg. (+peer fd, +gossip fd)
gossipctl_hand_back_peer,3013
gossipctl_hand_back_peer,,id,struct pubkey
gossipctl_hand_back_peer,,crypto_state,struct crypto_state
gossipctl_hand_back_peer,,gossip_index,u64
gossipctl_hand_back_peer,,len,u16
gossipctl_hand_back_peer,,msg,len*u8
@ -141,3 +145,8 @@ gossip_get_update_reply,3112
gossip_get_update_reply,,len,u16
gossip_get_update_reply,,update,len*u8
# Gossipd can tell channeld etc about gossip to fwd.
gossip_send_gossip,3016
gossip_send_gossip,,gossip_index,u64
gossip_send_gossip,,len,u16
gossip_send_gossip,,gossip,len*u8

Can't render this file because it has a wrong number of fields in line 5.

7
lightningd/gossip_control.c

@ -27,9 +27,10 @@ static void peer_nongossip(struct subd *gossip, const u8 *msg,
struct crypto_state cs;
struct wireaddr addr;
u8 *gfeatures, *lfeatures, *in_pkt;
u64 gossip_index;
if (!fromwire_gossip_peer_nongossip(msg, msg, NULL,
&id, &addr, &cs,
&id, &addr, &cs, &gossip_index,
&gfeatures,
&lfeatures,
&in_pkt))
@ -47,7 +48,8 @@ static void peer_nongossip(struct subd *gossip, const u8 *msg,
return;
}
peer_sent_nongossip(gossip->ld, &id, &addr, &cs, gfeatures, lfeatures,
peer_sent_nongossip(gossip->ld, &id, &addr, &cs, gossip_index,
gfeatures, lfeatures,
peer_fd, gossip_fd, in_pkt);
}
@ -70,6 +72,7 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
case WIRE_GOSSIPCTL_RELEASE_PEER:
case WIRE_GOSSIPCTL_PEER_ADDRHINT:
case WIRE_GOSSIP_GET_UPDATE:
case WIRE_GOSSIP_SEND_GOSSIP:
/* This is a reply, so never gets through to here. */
case WIRE_GOSSIP_GET_UPDATE_REPLY:
case WIRE_GOSSIP_GETNODES_REPLY:

72
lightningd/peer_control.c

@ -61,21 +61,25 @@ static void peer_offer_channel(struct lightningd *ld,
struct funding_channel *fc,
const struct wireaddr *addr,
const struct crypto_state *cs,
u64 gossip_index,
const u8 *gfeatures, const u8 *lfeatures,
int peer_fd, int gossip_fd);
static bool peer_start_channeld(struct peer *peer,
const struct crypto_state *cs,
u64 gossip_index,
int peer_fd, int gossip_fd,
const u8 *funding_signed,
bool reconnected);
static void peer_start_closingd(struct peer *peer,
struct crypto_state *cs,
u64 gossip_index,
int peer_fd, int gossip_fd,
bool reconnected);
static void peer_accept_channel(struct lightningd *ld,
const struct pubkey *peer_id,
const struct wireaddr *addr,
const struct crypto_state *cs,
u64 gossip_index,
const u8 *gfeatures, const u8 *lfeatures,
int peer_fd, int gossip_fd,
const u8 *open_msg);
@ -548,9 +552,10 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
u8 *error;
struct peer *peer;
struct wireaddr addr;
u64 gossip_index;
if (!fromwire_gossip_peer_connected(msg, msg, NULL,
&id, &addr, &cs,
&id, &addr, &cs, &gossip_index,
&gfeatures, &lfeatures))
fatal("Gossip gave bad GOSSIP_PEER_CONNECTED message %s",
tal_hex(msg, msg));
@ -620,7 +625,8 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
peer_set_owner(peer, NULL);
peer->addr = addr;
peer_start_channeld(peer, &cs, peer_fd, gossip_fd, NULL,
peer_start_channeld(peer, &cs, gossip_index,
peer_fd, gossip_fd, NULL,
true);
return;
@ -631,7 +637,8 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
peer_set_owner(peer, NULL);
peer->addr = addr;
peer_start_closingd(peer, &cs, peer_fd, gossip_fd,
peer_start_closingd(peer, &cs, gossip_index,
peer_fd, gossip_fd,
true);
return;
}
@ -640,7 +647,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
return_to_gossipd:
/* Otherwise, we hand back to gossipd, to continue. */
msg = towire_gossipctl_hand_back_peer(msg, &id, &cs, NULL);
msg = towire_gossipctl_hand_back_peer(msg, &id, &cs, gossip_index, NULL);
subd_send_msg(ld->gossip, take(msg));
subd_send_fd(ld->gossip, peer_fd);
subd_send_fd(ld->gossip, gossip_fd);
@ -652,7 +659,8 @@ return_to_gossipd:
send_error:
/* Hand back to gossipd, with an error packet. */
connect_failed(ld, &id, sanitize_error(msg, error, NULL));
msg = towire_gossipctl_hand_back_peer(msg, &id, &cs, error);
msg = towire_gossipctl_hand_back_peer(msg, &id, &cs, gossip_index,
error);
subd_send_msg(ld->gossip, take(msg));
subd_send_fd(ld->gossip, peer_fd);
subd_send_fd(ld->gossip, gossip_fd);
@ -662,6 +670,7 @@ void peer_sent_nongossip(struct lightningd *ld,
const struct pubkey *id,
const struct wireaddr *addr,
const struct crypto_state *cs,
u64 gossip_index,
const u8 *gfeatures,
const u8 *lfeatures,
int peer_fd, int gossip_fd,
@ -689,7 +698,8 @@ void peer_sent_nongossip(struct lightningd *ld,
/* Open request? */
if (fromwire_peektype(in_msg) == WIRE_OPEN_CHANNEL) {
peer_accept_channel(ld, id, addr, cs, gfeatures, lfeatures,
peer_accept_channel(ld, id, addr, cs, gossip_index,
gfeatures, lfeatures,
peer_fd, gossip_fd, in_msg);
return;
}
@ -702,7 +712,7 @@ void peer_sent_nongossip(struct lightningd *ld,
send_error:
/* Hand back to gossipd, with an error packet. */
connect_failed(ld, id, sanitize_error(error, error, NULL));
msg = towire_gossipctl_hand_back_peer(ld, id, cs, error);
msg = towire_gossipctl_hand_back_peer(ld, id, cs, gossip_index, error);
subd_send_msg(ld->gossip, take(msg));
subd_send_fd(ld->gossip, peer_fd);
subd_send_fd(ld->gossip, gossip_fd);
@ -1528,7 +1538,8 @@ static enum watch_result funding_lockin_cb(struct peer *peer,
static void opening_got_hsm_funding_sig(struct funding_channel *fc,
int peer_fd, int gossip_fd,
const u8 *resp,
const struct crypto_state *cs)
const struct crypto_state *cs,
u64 gossip_index)
{
secp256k1_ecdsa_signature *sigs;
struct bitcoin_tx *tx = fc->funding_tx;
@ -1580,7 +1591,8 @@ static void opening_got_hsm_funding_sig(struct funding_channel *fc,
fc->peer->opening_cmd = NULL;
/* Start normal channel daemon. */
peer_start_channeld(fc->peer, cs, peer_fd, gossip_fd, NULL, false);
peer_start_channeld(fc->peer, cs, gossip_index,
peer_fd, gossip_fd, NULL, false);
peer_set_condition(fc->peer, OPENINGD, CHANNELD_AWAITING_LOCKIN);
wallet_confirm_utxos(fc->peer->ld->wallet, fc->utxomap);
@ -1829,7 +1841,10 @@ static void peer_received_closing_signature(struct peer *peer, const u8 *msg)
static void peer_closing_complete(struct peer *peer, const u8 *msg)
{
if (!fromwire_closing_complete(msg, NULL)) {
/* FIXME: We should save this, to return to gossipd */
u64 gossip_index;
if (!fromwire_closing_complete(msg, NULL, &gossip_index)) {
peer_internal_error(peer, "Bad closing_complete %s",
tal_hex(peer, msg));
return;
@ -1867,6 +1882,7 @@ static unsigned closing_msg(struct subd *sd, const u8 *msg, const int *fds)
static void peer_start_closingd(struct peer *peer,
struct crypto_state *cs,
u64 gossip_index,
int peer_fd, int gossip_fd,
bool reconnected)
{
@ -1942,6 +1958,7 @@ static void peer_start_closingd(struct peer *peer,
*/
initmsg = towire_closing_init(tmpctx,
cs,
gossip_index,
peer->seed,
peer->funding_txid,
peer->funding_outnum,
@ -1970,18 +1987,19 @@ static void peer_start_closingd_after_shutdown(struct peer *peer, const u8 *msg,
const int *fds)
{
struct crypto_state cs;
u64 gossip_index;
/* We expect 2 fds. */
assert(tal_count(fds) == 2);
if (!fromwire_channel_shutdown_complete(msg, NULL, &cs)) {
if (!fromwire_channel_shutdown_complete(msg, NULL, &cs, &gossip_index)) {
peer_internal_error(peer, "bad shutdown_complete: %s",
tal_hex(peer, msg));
return;
}
/* This sets peer->owner, closes down channeld. */
peer_start_closingd(peer, &cs, fds[0], fds[1], false);
peer_start_closingd(peer, &cs, gossip_index, fds[0], fds[1], false);
peer_set_condition(peer, CHANNELD_SHUTTING_DOWN, CLOSINGD_SIGEXCHANGE);
}
@ -2045,6 +2063,7 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
static bool peer_start_channeld(struct peer *peer,
const struct crypto_state *cs,
u64 gossip_index,
int peer_fd, int gossip_fd,
const u8 *funding_signed,
bool reconnected)
@ -2135,7 +2154,7 @@ static bool peer_start_channeld(struct peer *peer,
get_feerate(peer->ld->topology, FEERATE_NORMAL),
get_feerate(peer->ld->topology, FEERATE_IMMEDIATE) * 5,
peer->last_sig,
cs,
cs, gossip_index,
&peer->channel_info->remote_fundingkey,
&peer->channel_info->theirbase.revocation,
&peer->channel_info->theirbase.payment,
@ -2196,6 +2215,7 @@ static void opening_funder_finished(struct subd *opening, const u8 *resp,
struct crypto_state cs;
secp256k1_ecdsa_signature remote_commit_sig;
struct bitcoin_tx *remote_commit;
u64 gossip_index;
assert(tal_count(fds) == 2);
@ -2212,6 +2232,7 @@ static void opening_funder_finished(struct subd *opening, const u8 *resp,
remote_commit,
&remote_commit_sig,
&cs,
&gossip_index,
&channel_info->theirbase.revocation,
&channel_info->theirbase.payment,
&channel_info->theirbase.htlc,
@ -2301,7 +2322,7 @@ static void opening_funder_finished(struct subd *opening, const u8 *resp,
fatal("Could not write to HSM: %s", strerror(errno));
msg = hsm_sync_read(fc, fc->peer->ld);
opening_got_hsm_funding_sig(fc, fds[0], fds[1], msg, &cs);
opening_got_hsm_funding_sig(fc, fds[0], fds[1], msg, &cs, gossip_index);
}
static void opening_fundee_finished(struct subd *opening,
@ -2312,6 +2333,7 @@ static void opening_fundee_finished(struct subd *opening,
u8 *funding_signed;
struct channel_info *channel_info;
struct crypto_state cs;
u64 gossip_index;
secp256k1_ecdsa_signature remote_commit_sig;
struct bitcoin_tx *remote_commit;
@ -2331,6 +2353,7 @@ static void opening_fundee_finished(struct subd *opening,
remote_commit,
&remote_commit_sig,
&cs,
&gossip_index,
&channel_info->theirbase.revocation,
&channel_info->theirbase.payment,
&channel_info->theirbase.htlc,
@ -2376,7 +2399,8 @@ static void opening_fundee_finished(struct subd *opening,
peer_set_owner(peer, NULL);
/* On to normal operation! */
peer_start_channeld(peer, &cs, fds[0], fds[1], funding_signed, false);
peer_start_channeld(peer, &cs, gossip_index,
fds[0], fds[1], funding_signed, false);
peer_set_condition(peer, OPENINGD, CHANNELD_AWAITING_LOCKIN);
}
@ -2386,6 +2410,7 @@ static unsigned int opening_negotiation_failed(struct subd *openingd,
const int *fds)
{
struct crypto_state cs;
u64 gossip_index;
struct peer *peer = openingd->peer;
u8 *err;
const char *why;
@ -2394,14 +2419,16 @@ static unsigned int opening_negotiation_failed(struct subd *openingd,
if (tal_count(fds) == 0)
return 2;
if (!fromwire_opening_negotiation_failed(msg, msg, NULL, &cs, &err)) {
if (!fromwire_opening_negotiation_failed(msg, msg, NULL,
&cs, &gossip_index, &err)) {
peer_internal_error(peer,
"bad OPENING_NEGOTIATION_FAILED %s",
tal_hex(msg, msg));
return 0;
}
msg = towire_gossipctl_hand_back_peer(msg, &peer->id, &cs, NULL);
msg = towire_gossipctl_hand_back_peer(msg, &peer->id, &cs, gossip_index,
NULL);
subd_send_msg(openingd->ld->gossip, take(msg));
subd_send_fd(openingd->ld->gossip, fds[0]);
subd_send_fd(openingd->ld->gossip, fds[1]);
@ -2419,6 +2446,7 @@ static void peer_accept_channel(struct lightningd *ld,
const struct pubkey *peer_id,
const struct wireaddr *addr,
const struct crypto_state *cs,
u64 gossip_index,
const u8 *gfeatures, const u8 *lfeatures,
int peer_fd, int gossip_fd,
const u8 *open_msg)
@ -2470,7 +2498,7 @@ static void peer_accept_channel(struct lightningd *ld,
&peer->our_config,
max_to_self_delay,
min_effective_htlc_capacity_msat,
cs, peer->seed);
cs, gossip_index, peer->seed);
subd_send_msg(peer->owner, take(msg));
@ -2493,6 +2521,7 @@ static void peer_offer_channel(struct lightningd *ld,
struct funding_channel *fc,
const struct wireaddr *addr,
const struct crypto_state *cs,
u64 gossip_index,
const u8 *gfeatures, const u8 *lfeatures,
int peer_fd, int gossip_fd)
{
@ -2550,7 +2579,7 @@ static void peer_offer_channel(struct lightningd *ld,
&fc->peer->our_config,
max_to_self_delay,
min_effective_htlc_capacity_msat,
cs, fc->peer->seed);
cs, gossip_index, fc->peer->seed);
subd_send_msg(fc->peer->owner, take(msg));
utxos = from_utxoptr_arr(fc, fc->utxomap);
@ -2579,6 +2608,7 @@ static void gossip_peer_released(struct subd *gossip,
{
struct lightningd *ld = gossip->ld;
struct crypto_state cs;
u64 gossip_index;
u8 *gfeatures, *lfeatures;
struct wireaddr addr;
@ -2586,6 +2616,7 @@ static void gossip_peer_released(struct subd *gossip,
fc->peer = peer_by_id(ld, &fc->peerid);
if (!fromwire_gossipctl_release_peer_reply(fc, resp, NULL, &addr, &cs,
&gossip_index,
&gfeatures, &lfeatures)) {
if (!fromwire_gossipctl_release_peer_replyfail(resp, NULL)) {
fatal("Gossip daemon gave invalid reply %s",
@ -2611,7 +2642,8 @@ static void gossip_peer_released(struct subd *gossip,
}
/* OK, offer peer a channel. */
peer_offer_channel(ld, fc, &addr, &cs, gfeatures, lfeatures,
peer_offer_channel(ld, fc, &addr, &cs, gossip_index,
gfeatures, lfeatures,
fds[0], fds[1]);
}

1
lightningd/peer_control.h

@ -176,6 +176,7 @@ void peer_sent_nongossip(struct lightningd *ld,
const struct pubkey *id,
const struct wireaddr *addr,
const struct crypto_state *cs,
u64 gossip_index,
const u8 *gfeatures,
const u8 *lfeatures,
int peer_fd, int gossip_fd,

6
openingd/opening.c

@ -38,6 +38,7 @@
struct state {
struct crypto_state cs;
u64 gossip_index;
struct pubkey next_per_commit[NUM_SIDES];
/* Initially temporary, then final channel id. */
@ -89,6 +90,7 @@ static void negotiation_failed(struct state *state, bool send_error,
/* Tell master we should return to gossiping. */
msg = towire_opening_negotiation_failed(state, &state->cs,
state->gossip_index,
(const u8 *)errmsg);
wire_sync_write(REQ_FD, msg);
fdpass_send(REQ_FD, PEER_FD);
@ -502,7 +504,7 @@ static u8 *funder_channel(struct state *state,
state->remoteconf,
tx,
&sig,
&state->cs,
&state->cs, state->gossip_index,
&theirs.revocation,
&theirs.payment,
&theirs.htlc,
@ -726,6 +728,7 @@ static u8 *fundee_channel(struct state *state,
their_commit,
&theirsig,
&state->cs,
state->gossip_index,
&theirs.revocation,
&theirs.payment,
&theirs.htlc,
@ -778,6 +781,7 @@ int main(int argc, char *argv[])
&state->max_to_self_delay,
&state->min_effective_htlc_capacity_msat,
&state->cs,
&state->gossip_index,
&seed))
master_badmsg(WIRE_OPENING_INIT, msg);

4
openingd/opening_wire.csv

@ -9,6 +9,7 @@ opening_init,,our_config,struct channel_config
opening_init,,max_to_self_delay,u32
opening_init,,min_effective_htlc_capacity_msat,u64
opening_init,,crypto_state,struct crypto_state
opening_init,,gossip_index,u64
# Seed to generate all the keys from
opening_init,,seed,struct privkey
@ -34,6 +35,7 @@ opening_funder_reply,,their_config,struct channel_config
opening_funder_reply,,first_commit,struct bitcoin_tx
opening_funder_reply,,first_commit_sig,secp256k1_ecdsa_signature
opening_funder_reply,,crypto_state,struct crypto_state
opening_funder_reply,,gossip_index,u64
opening_funder_reply,,revocation_basepoint,struct pubkey
opening_funder_reply,,payment_basepoint,struct pubkey
opening_funder_reply,,htlc_basepoint,struct pubkey
@ -58,6 +60,7 @@ opening_fundee_reply,,their_config,struct channel_config
opening_fundee_reply,,first_commit,struct bitcoin_tx
opening_fundee_reply,,first_commit_sig,secp256k1_ecdsa_signature
opening_fundee_reply,,crypto_state,struct crypto_state
opening_fundee_reply,,gossip_index,u64
opening_fundee_reply,,revocation_basepoint,struct pubkey
opening_fundee_reply,,payment_basepoint,struct pubkey
opening_fundee_reply,,htlc_basepoint,struct pubkey
@ -77,6 +80,7 @@ opening_fundee_reply,,funding_signed_msg,msglen*u8
# We disagreed with opening parameters, but peer is ok for gossip (+ peerfd)
opening_negotiation_failed,6010
opening_negotiation_failed,,crypto_state,struct crypto_state
opening_negotiation_failed,,gossip_index,u64
opening_negotiation_failed,,len,u16
# FIXME: string support!
opening_negotiation_failed,,msg,len*u8

Can't render this file because it has a wrong number of fields in line 3.
Loading…
Cancel
Save