From 103ac79c34b82d8831784c9f51cc8231b228cc1e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 2 May 2017 14:56:31 +0930 Subject: [PATCH] lightningd: expose channel in getpeers. Lets us manually construct routes, for testing, and replaces the 'locked' flag as well. Signed-off-by: Rusty Russell --- lightningd/pay.c | 2 +- lightningd/peer_control.c | 25 +++++++++++++++---------- lightningd/peer_control.h | 4 +++- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lightningd/pay.c b/lightningd/pay.c index d8aaf8734..ff125e325 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -307,7 +307,7 @@ static void json_sendpay(struct command *cmd, return; } - if (!peer->locked) { + if (!peer->scid) { command_fail(cmd, "first peer channel not locked"); return; } diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 47ba5b57c..7df244bda 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -66,12 +66,12 @@ static struct peer *new_peer(struct lightningd *ld, peer->ld = ld; peer->unique_id = id_counter++; peer->owner = NULL; + peer->scid = NULL; peer->id = NULL; peer->fd = io_conn_fd(conn); peer->connect_cmd = cmd; peer->funding_txid = NULL; peer->seed = NULL; - peer->locked = false; peer->balance = NULL; /* Max 128k per peer. */ @@ -473,6 +473,8 @@ static void json_getpeers(struct command *cmd, json_add_pubkey(response, "peerid", p->id); if (p->owner) json_add_string(response, "owner", p->owner->name); + if (p->scid) + json_add_short_channel_id(response, "channel", p->scid); if (p->balance) { json_add_u64(response, "msatoshi_to_us", p->balance[LOCAL]); @@ -547,12 +549,6 @@ static enum watch_result funding_depth_cb(struct peer *peer, void *unused) { const char *txidstr = type_to_string(peer, struct sha256_double, txid); - struct txlocator *loc = locate_tx(peer, peer->ld->topology, txid); - struct short_channel_id scid; - scid.blocknum = loc->blkheight; - scid.txnum = loc->index; - scid.outnum = peer->funding_outnum; - loc = tal_free(loc); log_debug(peer->log, "Funding tx %s depth %u of %u", txidstr, depth, peer->minimum_depth); @@ -569,10 +565,19 @@ static enum watch_result funding_depth_cb(struct peer *peer, } /* Make sure we notify `channeld` just once. */ - if (!peer->locked) { + if (!peer->scid) { + struct txlocator *loc + = locate_tx(peer, peer->ld->topology, txid); + + peer->scid = tal(peer, struct short_channel_id); + peer->scid->blocknum = loc->blkheight; + peer->scid->txnum = loc->index; + peer->scid->outnum = peer->funding_outnum; + tal_free(loc); + 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; + subd_send_msg(peer->owner, + take(towire_channel_funding_locked(peer, peer->scid))); } /* With the above this is max(funding_depth, 6) before diff --git a/lightningd/peer_control.h b/lightningd/peer_control.h index 2d4355cd3..a9c438beb 100644 --- a/lightningd/peer_control.h +++ b/lightningd/peer_control.h @@ -46,6 +46,9 @@ struct peer { /* Our channel config. */ struct channel_config our_config; + /* Channel if locked. */ + struct short_channel_id *scid; + /* Minimum funding depth (specified by us if they fund). */ u32 minimum_depth; @@ -62,7 +65,6 @@ 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);