mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
lightningd: expose channel in getpeers.
Lets us manually construct routes, for testing, and replaces the 'locked' flag as well. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
09e489030c
commit
103ac79c34
@ -307,7 +307,7 @@ static void json_sendpay(struct command *cmd,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!peer->locked) {
|
if (!peer->scid) {
|
||||||
command_fail(cmd, "first peer channel not locked");
|
command_fail(cmd, "first peer channel not locked");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -66,12 +66,12 @@ static struct peer *new_peer(struct lightningd *ld,
|
|||||||
peer->ld = ld;
|
peer->ld = ld;
|
||||||
peer->unique_id = id_counter++;
|
peer->unique_id = id_counter++;
|
||||||
peer->owner = NULL;
|
peer->owner = NULL;
|
||||||
|
peer->scid = NULL;
|
||||||
peer->id = NULL;
|
peer->id = NULL;
|
||||||
peer->fd = io_conn_fd(conn);
|
peer->fd = io_conn_fd(conn);
|
||||||
peer->connect_cmd = cmd;
|
peer->connect_cmd = cmd;
|
||||||
peer->funding_txid = NULL;
|
peer->funding_txid = NULL;
|
||||||
peer->seed = NULL;
|
peer->seed = NULL;
|
||||||
peer->locked = false;
|
|
||||||
peer->balance = NULL;
|
peer->balance = NULL;
|
||||||
|
|
||||||
/* Max 128k per peer. */
|
/* Max 128k per peer. */
|
||||||
@ -473,6 +473,8 @@ static void json_getpeers(struct command *cmd,
|
|||||||
json_add_pubkey(response, "peerid", p->id);
|
json_add_pubkey(response, "peerid", p->id);
|
||||||
if (p->owner)
|
if (p->owner)
|
||||||
json_add_string(response, "owner", p->owner->name);
|
json_add_string(response, "owner", p->owner->name);
|
||||||
|
if (p->scid)
|
||||||
|
json_add_short_channel_id(response, "channel", p->scid);
|
||||||
if (p->balance) {
|
if (p->balance) {
|
||||||
json_add_u64(response, "msatoshi_to_us",
|
json_add_u64(response, "msatoshi_to_us",
|
||||||
p->balance[LOCAL]);
|
p->balance[LOCAL]);
|
||||||
@ -547,12 +549,6 @@ static enum watch_result funding_depth_cb(struct peer *peer,
|
|||||||
void *unused)
|
void *unused)
|
||||||
{
|
{
|
||||||
const char *txidstr = type_to_string(peer, struct sha256_double, txid);
|
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",
|
log_debug(peer->log, "Funding tx %s depth %u of %u",
|
||||||
txidstr, depth, peer->minimum_depth);
|
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. */
|
/* 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);
|
peer_set_condition(peer, "Funding tx reached depth %u", depth);
|
||||||
subd_send_msg(peer->owner, take(towire_channel_funding_locked(peer, &scid)));
|
subd_send_msg(peer->owner,
|
||||||
peer->locked = true;
|
take(towire_channel_funding_locked(peer, peer->scid)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* With the above this is max(funding_depth, 6) before
|
/* With the above this is max(funding_depth, 6) before
|
||||||
|
@ -46,6 +46,9 @@ struct peer {
|
|||||||
/* Our channel config. */
|
/* Our channel config. */
|
||||||
struct channel_config our_config;
|
struct channel_config our_config;
|
||||||
|
|
||||||
|
/* Channel if locked. */
|
||||||
|
struct short_channel_id *scid;
|
||||||
|
|
||||||
/* Minimum funding depth (specified by us if they fund). */
|
/* Minimum funding depth (specified by us if they fund). */
|
||||||
u32 minimum_depth;
|
u32 minimum_depth;
|
||||||
|
|
||||||
@ -62,7 +65,6 @@ struct peer {
|
|||||||
|
|
||||||
/* Gossip client fd, forwarded to the respective owner */
|
/* Gossip client fd, forwarded to the respective owner */
|
||||||
int gossip_client_fd;
|
int gossip_client_fd;
|
||||||
bool locked;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct peer *peer_by_unique_id(struct lightningd *ld, u64 unique_id);
|
struct peer *peer_by_unique_id(struct lightningd *ld, u64 unique_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user