mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
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.
This commit is contained in:
parent
5028f7b9d9
commit
d2c626820f
@ -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));
|
||||
|
||||
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
@ -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…
Reference in New Issue
Block a user