mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 09:04:22 +01:00
channeld: keep billboard uptodate.
For the moment, this just tracks the lockin, announce and shutdown statuses. We currently have trouble telling when we're stuck in CHANNELD_AWAITING_LOCKIN who has sent the transaction. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
10361d5308
commit
8640a5c329
@@ -33,6 +33,7 @@
|
|||||||
#include <common/io_debug.h>
|
#include <common/io_debug.h>
|
||||||
#include <common/key_derive.h>
|
#include <common/key_derive.h>
|
||||||
#include <common/msg_queue.h>
|
#include <common/msg_queue.h>
|
||||||
|
#include <common/peer_billboard.h>
|
||||||
#include <common/peer_failed.h>
|
#include <common/peer_failed.h>
|
||||||
#include <common/ping.h>
|
#include <common/ping.h>
|
||||||
#include <common/read_peer_msg.h>
|
#include <common/read_peer_msg.h>
|
||||||
@@ -168,6 +169,51 @@ struct peer {
|
|||||||
static u8 *create_channel_announcement(const tal_t *ctx, struct peer *peer);
|
static u8 *create_channel_announcement(const tal_t *ctx, struct peer *peer);
|
||||||
static void start_commit_timer(struct peer *peer);
|
static void start_commit_timer(struct peer *peer);
|
||||||
|
|
||||||
|
static void billboard_update(const struct peer *peer)
|
||||||
|
{
|
||||||
|
const tal_t *tmpctx = tal_tmpctx(peer);
|
||||||
|
const char *funding_status, *announce_status, *shutdown_status;
|
||||||
|
|
||||||
|
if (peer->funding_locked[LOCAL] && peer->funding_locked[REMOTE])
|
||||||
|
funding_status = "Funding transaction locked.";
|
||||||
|
else if (!peer->funding_locked[LOCAL] && !peer->funding_locked[REMOTE])
|
||||||
|
/* FIXME: Say how many blocks to go! */
|
||||||
|
funding_status = "Funding needs more confirmations.";
|
||||||
|
else if (peer->funding_locked[LOCAL] && !peer->funding_locked[REMOTE])
|
||||||
|
funding_status = "We've confirmed funding, they haven't yet.";
|
||||||
|
else if (!peer->funding_locked[LOCAL] && peer->funding_locked[REMOTE])
|
||||||
|
funding_status = "They've confirmed funding, we haven't yet.";
|
||||||
|
|
||||||
|
if (peer->have_sigs[LOCAL] && peer->have_sigs[REMOTE])
|
||||||
|
announce_status = " Channel announced.";
|
||||||
|
else if (peer->have_sigs[LOCAL] && !peer->have_sigs[REMOTE])
|
||||||
|
announce_status = " Waiting for their announcement signatures.";
|
||||||
|
else if (!peer->have_sigs[LOCAL] && peer->have_sigs[REMOTE])
|
||||||
|
announce_status = " They need our announcement signatures.";
|
||||||
|
else if (!peer->have_sigs[LOCAL] && !peer->have_sigs[REMOTE])
|
||||||
|
announce_status = "";
|
||||||
|
|
||||||
|
if (!peer->shutdown_sent[LOCAL] && !peer->shutdown_sent[REMOTE])
|
||||||
|
shutdown_status = "";
|
||||||
|
else if (!peer->shutdown_sent[LOCAL] && peer->shutdown_sent[REMOTE])
|
||||||
|
shutdown_status = " We've send shutdown, waiting for theirs";
|
||||||
|
else if (peer->shutdown_sent[LOCAL] && !peer->shutdown_sent[REMOTE])
|
||||||
|
shutdown_status = " They've sent shutdown, waiting for ours";
|
||||||
|
else if (peer->shutdown_sent[LOCAL] && peer->shutdown_sent[REMOTE]) {
|
||||||
|
size_t num_htlcs = num_channel_htlcs(peer->channel);
|
||||||
|
if (num_htlcs)
|
||||||
|
shutdown_status = tal_fmt(tmpctx,
|
||||||
|
" Shutdown messages exchanged,"
|
||||||
|
" waiting for %zu HTLCs to complete.",
|
||||||
|
num_htlcs);
|
||||||
|
else
|
||||||
|
shutdown_status = tal_fmt(tmpctx,
|
||||||
|
" Shutdown messages exchanged.");
|
||||||
|
}
|
||||||
|
peer_billboard(false, "%s%s%s", funding_status,
|
||||||
|
announce_status, shutdown_status);
|
||||||
|
}
|
||||||
|
|
||||||
/* Returns a pointer to the new end */
|
/* Returns a pointer to the new end */
|
||||||
static void *tal_arr_append_(void **p, size_t size)
|
static void *tal_arr_append_(void **p, size_t size)
|
||||||
{
|
{
|
||||||
@@ -358,6 +404,7 @@ static void send_announcement_signatures(struct peer *peer)
|
|||||||
&peer->announcement_bitcoin_sigs[LOCAL]);
|
&peer->announcement_bitcoin_sigs[LOCAL]);
|
||||||
|
|
||||||
peer->have_sigs[LOCAL] = true;
|
peer->have_sigs[LOCAL] = true;
|
||||||
|
billboard_update(peer);
|
||||||
|
|
||||||
msg = towire_announcement_signatures(
|
msg = towire_announcement_signatures(
|
||||||
tmpctx, &peer->channel_id, &peer->short_channel_ids[LOCAL],
|
tmpctx, &peer->channel_id, &peer->short_channel_ids[LOCAL],
|
||||||
@@ -473,6 +520,7 @@ static void handle_peer_funding_locked(struct peer *peer, const u8 *msg)
|
|||||||
wire_sync_write(MASTER_FD,
|
wire_sync_write(MASTER_FD,
|
||||||
take(towire_channel_normal_operation(peer)));
|
take(towire_channel_normal_operation(peer)));
|
||||||
}
|
}
|
||||||
|
billboard_update(peer);
|
||||||
|
|
||||||
/* Send temporary or final announcements */
|
/* Send temporary or final announcements */
|
||||||
send_temporary_announcement(peer);
|
send_temporary_announcement(peer);
|
||||||
@@ -538,6 +586,7 @@ static void handle_peer_announcement_signatures(struct peer *peer, const u8 *msg
|
|||||||
}
|
}
|
||||||
|
|
||||||
peer->have_sigs[REMOTE] = true;
|
peer->have_sigs[REMOTE] = true;
|
||||||
|
billboard_update(peer);
|
||||||
|
|
||||||
/* We have the remote sigs, do we have the local ones as well? */
|
/* We have the remote sigs, do we have the local ones as well? */
|
||||||
if (peer->funding_locked[LOCAL] && peer->have_sigs[LOCAL])
|
if (peer->funding_locked[LOCAL] && peer->have_sigs[LOCAL])
|
||||||
@@ -704,7 +753,7 @@ static bool shutdown_complete(const struct peer *peer)
|
|||||||
{
|
{
|
||||||
return peer->shutdown_sent[LOCAL]
|
return peer->shutdown_sent[LOCAL]
|
||||||
&& peer->shutdown_sent[REMOTE]
|
&& peer->shutdown_sent[REMOTE]
|
||||||
&& !channel_has_htlcs(peer->channel)
|
&& num_channel_htlcs(peer->channel) == 0
|
||||||
/* We could be awaiting revoke-and-ack for a feechange */
|
/* We could be awaiting revoke-and-ack for a feechange */
|
||||||
&& peer->revocations_received == peer->next_index[REMOTE] - 1;
|
&& peer->revocations_received == peer->next_index[REMOTE] - 1;
|
||||||
|
|
||||||
@@ -735,6 +784,7 @@ static void maybe_send_shutdown(struct peer *peer)
|
|||||||
peer->unsent_shutdown_scriptpubkey
|
peer->unsent_shutdown_scriptpubkey
|
||||||
= tal_free(peer->unsent_shutdown_scriptpubkey);
|
= tal_free(peer->unsent_shutdown_scriptpubkey);
|
||||||
peer->shutdown_sent[LOCAL] = true;
|
peer->shutdown_sent[LOCAL] = true;
|
||||||
|
billboard_update(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This queues other traffic from the fd until we get reply. */
|
/* This queues other traffic from the fd until we get reply. */
|
||||||
@@ -914,7 +964,7 @@ static void send_commit(struct peer *peer)
|
|||||||
* - if no HTLCs remain in either commitment transaction:
|
* - if no HTLCs remain in either commitment transaction:
|
||||||
* - MUST NOT send any `update` message after a `shutdown`.
|
* - MUST NOT send any `update` message after a `shutdown`.
|
||||||
*/
|
*/
|
||||||
if (peer->shutdown_sent[LOCAL] && !channel_has_htlcs(peer->channel)) {
|
if (peer->shutdown_sent[LOCAL] && !num_channel_htlcs(peer->channel)) {
|
||||||
status_trace("Can't send commit: final shutdown phase");
|
status_trace("Can't send commit: final shutdown phase");
|
||||||
|
|
||||||
peer->commit_timer = NULL;
|
peer->commit_timer = NULL;
|
||||||
@@ -1544,6 +1594,7 @@ static void handle_peer_shutdown(struct peer *peer, const u8 *shutdown)
|
|||||||
take(towire_channel_got_shutdown(peer, scriptpubkey)));
|
take(towire_channel_got_shutdown(peer, scriptpubkey)));
|
||||||
|
|
||||||
peer->shutdown_sent[REMOTE] = true;
|
peer->shutdown_sent[REMOTE] = true;
|
||||||
|
billboard_update(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Note: msg came from read_peer_msg() which handles pings, gossip,
|
/* Note: msg came from read_peer_msg() which handles pings, gossip,
|
||||||
@@ -1781,6 +1832,8 @@ static void peer_reconnect(struct peer *peer)
|
|||||||
if (!sync_crypto_write(&peer->cs, PEER_FD, take(msg)))
|
if (!sync_crypto_write(&peer->cs, PEER_FD, take(msg)))
|
||||||
peer_failed_connection_lost();
|
peer_failed_connection_lost();
|
||||||
|
|
||||||
|
peer_billboard(false, "Sent reestablish, waiting for theirs");
|
||||||
|
|
||||||
/* Read until they say something interesting */
|
/* Read until they say something interesting */
|
||||||
while ((msg = channeld_read_peer_msg(peer)) == NULL);
|
while ((msg = channeld_read_peer_msg(peer)) == NULL);
|
||||||
|
|
||||||
@@ -1936,6 +1989,8 @@ static void peer_reconnect(struct peer *peer)
|
|||||||
* feechanges which cancelled out. */
|
* feechanges which cancelled out. */
|
||||||
if (peer->channel->funder == LOCAL)
|
if (peer->channel->funder == LOCAL)
|
||||||
peer->channel->changes_pending[LOCAL] = true;
|
peer->channel->changes_pending[LOCAL] = true;
|
||||||
|
|
||||||
|
peer_billboard(true, "Reconnected, and reestablished.");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_funding_locked(struct peer *peer, const u8 *msg)
|
static void handle_funding_locked(struct peer *peer, const u8 *msg)
|
||||||
@@ -1961,6 +2016,7 @@ static void handle_funding_locked(struct peer *peer, const u8 *msg)
|
|||||||
wire_sync_write(MASTER_FD,
|
wire_sync_write(MASTER_FD,
|
||||||
take(towire_channel_normal_operation(peer)));
|
take(towire_channel_normal_operation(peer)));
|
||||||
}
|
}
|
||||||
|
billboard_update(peer);
|
||||||
|
|
||||||
/* Send temporary or final announcements */
|
/* Send temporary or final announcements */
|
||||||
send_temporary_announcement(peer);
|
send_temporary_announcement(peer);
|
||||||
@@ -2551,6 +2607,7 @@ static void init_channel(struct peer *peer)
|
|||||||
if (funding_signed)
|
if (funding_signed)
|
||||||
enqueue_peer_msg(peer, take(funding_signed));
|
enqueue_peer_msg(peer, take(funding_signed));
|
||||||
|
|
||||||
|
billboard_update(peer);
|
||||||
tal_free(msg);
|
tal_free(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -864,19 +864,20 @@ bool channel_sending_revoke_and_ack(struct channel *channel)
|
|||||||
return channel->changes_pending[REMOTE];
|
return channel->changes_pending[REMOTE];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool channel_has_htlcs(const struct channel *channel)
|
size_t num_channel_htlcs(const struct channel *channel)
|
||||||
{
|
{
|
||||||
struct htlc_map_iter it;
|
struct htlc_map_iter it;
|
||||||
const struct htlc *htlc;
|
const struct htlc *htlc;
|
||||||
|
size_t n = 0;
|
||||||
|
|
||||||
for (htlc = htlc_map_first(channel->htlcs, &it);
|
for (htlc = htlc_map_first(channel->htlcs, &it);
|
||||||
htlc;
|
htlc;
|
||||||
htlc = htlc_map_next(channel->htlcs, &it)) {
|
htlc = htlc_map_next(channel->htlcs, &it)) {
|
||||||
/* FIXME: Clean these out! */
|
/* FIXME: Clean these out! */
|
||||||
if (!htlc_is_dead(htlc))
|
if (!htlc_is_dead(htlc))
|
||||||
return true;
|
n++;
|
||||||
}
|
}
|
||||||
return false;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool adjust_balance(struct channel *channel, struct htlc *htlc)
|
static bool adjust_balance(struct channel *channel, struct htlc *htlc)
|
||||||
|
|||||||
@@ -213,10 +213,10 @@ bool channel_rcvd_commit(struct channel *channel,
|
|||||||
bool channel_sending_revoke_and_ack(struct channel *channel);
|
bool channel_sending_revoke_and_ack(struct channel *channel);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* channel_has_htlcs: are there any (live) HTLCs at all in channel?
|
* num_channel_htlcs: how many (live) HTLCs at all in channel?
|
||||||
* @channel: the channel
|
* @channel: the channel
|
||||||
*/
|
*/
|
||||||
bool channel_has_htlcs(const struct channel *channel);
|
size_t num_channel_htlcs(const struct channel *channel);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* channel_force_htlcs: force these htlcs into the (new) channel
|
* channel_force_htlcs: force these htlcs into the (new) channel
|
||||||
|
|||||||
Reference in New Issue
Block a user