Browse Source

channel: Wait for 6 confirmations before sending announcement sigs

The protocol specifies that in order for an announcement to be valid,
the channel has to have at least 6 confirmations.
ppa-0.6.1
Christian Decker 8 years ago
parent
commit
d2c626820f
  1. 5
      lightningd/channel/channel.c
  2. 3
      lightningd/channel/channel_wire.csv
  3. 17
      lightningd/peer_control.c
  4. 3
      lightningd/peer_control.h

5
lightningd/channel/channel.c

@ -203,7 +203,6 @@ static struct io_plan *peer_in(struct io_conn *conn, struct peer *peer, u8 *msg)
return peer_read_message(conn, &peer->pcs, peer_in);
}
static struct io_plan *setup_peer_conn(struct io_conn *conn, struct peer *peer)
{
return io_duplex(conn, peer_read_message(conn, &peer->pcs, peer_in),
@ -273,13 +272,15 @@ static struct io_plan *req_in(struct io_conn *conn, struct daemon_conn *master)
&peer->next_per_commit[LOCAL]);
msg_enqueue(&peer->peer_out, take(msg));
peer->funding_locked[LOCAL] = true;
send_announcement_signatures(peer);
if (peer->funding_locked[REMOTE]) {
announce_channel(peer);
daemon_conn_send(master,
take(towire_channel_normal_operation(peer)));
}
} else if(fromwire_channel_funding_announce_depth(master->msg_in, NULL)) {
status_trace("Exchanging announcement signatures.");
send_announcement_signatures(peer);
} else
status_failed(WIRE_CHANNEL_BAD_COMMAND, "%s", strerror(errno));

3
lightningd/channel/channel_wire.csv

@ -41,3 +41,6 @@ channel_init,562,remote_node_id,struct pubkey
# Tx is deep enough, go!
channel_funding_locked,2
channel_funding_locked,0,short_channel_id,struct short_channel_id
# Tell the channel that we may announce the channel's existence
channel_funding_announce_depth,3
Can't render this file because it has a wrong number of fields in line 2.

17
lightningd/peer_control.c

@ -65,6 +65,7 @@ static struct peer *new_peer(struct lightningd *ld,
peer->connect_cmd = cmd;
peer->funding_txid = NULL;
peer->seed = NULL;
peer->locked = false;
/* Max 128k per peer. */
peer->log_book = new_log_book(peer, 128*1024,
@ -555,8 +556,19 @@ static enum watch_result funding_depth_cb(struct peer *peer,
return KEEP_WATCHING;
}
peer_set_condition(peer, "Funding tx reached depth %u", depth);
subd_send_msg(peer->owner, take(towire_channel_funding_locked(peer, &scid)));
/* Make sure we notify `channeld` just once. */
if (!peer->locked) {
peer_set_condition(peer, "Funding tx reached depth %u", depth);
subd_send_msg(peer->owner, take(towire_channel_funding_locked(peer, &scid)));
peer->locked = true;
}
/* With the above this is max(funding_depth, 6) before
* announcing the channel */
if (depth < ANNOUNCE_MIN_DEPTH) {
return KEEP_WATCHING;
}
subd_send_msg(peer->owner, take(towire_channel_funding_announce_depth(peer)));
return DELETE_WATCH;
}
@ -626,6 +638,7 @@ static size_t update_channel_status(struct subd *sd,
/* And we never get these from channeld. */
case WIRE_CHANNEL_INIT:
case WIRE_CHANNEL_FUNDING_LOCKED:
case WIRE_CHANNEL_FUNDING_ANNOUNCE_DEPTH:
break;
}

3
lightningd/peer_control.h

@ -6,6 +6,8 @@
#include <lightningd/channel_config.h>
#include <stdbool.h>
#define ANNOUNCE_MIN_DEPTH 6
struct crypto_state;
struct peer {
@ -52,6 +54,7 @@ struct peer {
/* Gossip client fd, forwarded to the respective owner */
int gossip_client_fd;
bool locked;
};
struct peer *peer_by_unique_id(struct lightningd *ld, u64 unique_id);

Loading…
Cancel
Save