mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-06 07:34:21 +01:00
billboard: break out common method for billboard updates
This commit is contained in:
committed by
Christian Decker
parent
1ea4e63331
commit
fc49874e32
@@ -32,6 +32,7 @@ CHANNELD_COMMON_OBJS := \
|
||||
common/amount.o \
|
||||
common/base32.o \
|
||||
common/bigsize.o \
|
||||
common/billboard.o \
|
||||
common/bip32.o \
|
||||
common/blinding.o \
|
||||
common/channel_config.o \
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <channeld/commit_tx.h>
|
||||
#include <channeld/full_channel.h>
|
||||
#include <channeld/watchtower.h>
|
||||
#include <common/billboard.h>
|
||||
#include <common/blinding.h>
|
||||
#include <common/coin_mvt.h>
|
||||
#include <common/crypto_sync.h>
|
||||
@@ -191,48 +192,13 @@ static void start_commit_timer(struct peer *peer);
|
||||
|
||||
static void billboard_update(const struct peer *peer)
|
||||
{
|
||||
const char *funding_status, *announce_status,
|
||||
*shutdown_status COMPILER_WANTS_INIT("gcc 8.3.0");
|
||||
const char *update = billboard_message(tmpctx, peer->funding_locked,
|
||||
peer->have_sigs,
|
||||
peer->shutdown_sent,
|
||||
peer->depth_togo,
|
||||
num_channel_htlcs(peer->channel));
|
||||
|
||||
if (peer->funding_locked[LOCAL] && peer->funding_locked[REMOTE])
|
||||
funding_status = "Funding transaction locked.";
|
||||
else if (!peer->funding_locked[LOCAL] && !peer->funding_locked[REMOTE])
|
||||
funding_status = tal_fmt(tmpctx,
|
||||
"Funding needs %d more confirmations for lockin.",
|
||||
peer->depth_togo);
|
||||
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);
|
||||
peer_billboard(false, update);
|
||||
}
|
||||
|
||||
static const u8 *hsm_req(const tal_t *ctx, const u8 *req TAKES)
|
||||
|
||||
@@ -6,6 +6,7 @@ COMMON_SRC_NOGEN := \
|
||||
common/bech32.c \
|
||||
common/bech32_util.c \
|
||||
common/bigsize.c \
|
||||
common/billboard.c \
|
||||
common/bip32.c \
|
||||
common/blinding.c \
|
||||
common/bolt11.c \
|
||||
|
||||
57
common/billboard.c
Normal file
57
common/billboard.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "billboard.h"
|
||||
#include <ccan/ccan/tal/str/str.h>
|
||||
#include <common/utils.h>
|
||||
|
||||
char *billboard_message(const tal_t *ctx,
|
||||
const bool funding_locked[NUM_SIDES],
|
||||
const bool have_sigs[NUM_SIDES],
|
||||
const bool shutdown_sent[NUM_SIDES],
|
||||
u32 depth_togo,
|
||||
size_t num_htlcs)
|
||||
{
|
||||
const char *funding_status, *announce_status,
|
||||
*shutdown_status COMPILER_WANTS_INIT("gcc 8.3.0");
|
||||
|
||||
if (funding_locked[LOCAL] && funding_locked[REMOTE])
|
||||
funding_status = "Funding transaction locked.";
|
||||
else if (!funding_locked[LOCAL] && !funding_locked[REMOTE])
|
||||
funding_status = tal_fmt(ctx,
|
||||
"Funding needs %d more"
|
||||
" confirmations for lockin.",
|
||||
depth_togo);
|
||||
else if (funding_locked[LOCAL] && !funding_locked[REMOTE])
|
||||
funding_status = "We've confirmed funding, they haven't yet.";
|
||||
else if (!funding_locked[LOCAL] && funding_locked[REMOTE])
|
||||
funding_status = "They've confirmed funding, we haven't yet.";
|
||||
|
||||
if (have_sigs[LOCAL] && have_sigs[REMOTE])
|
||||
announce_status = " Channel announced.";
|
||||
else if (have_sigs[LOCAL] && !have_sigs[REMOTE])
|
||||
announce_status = " Waiting for their announcement signatures.";
|
||||
else if (!have_sigs[LOCAL] && have_sigs[REMOTE])
|
||||
announce_status = " They need our announcement signatures.";
|
||||
else if (!have_sigs[LOCAL] && !have_sigs[REMOTE])
|
||||
announce_status = "";
|
||||
|
||||
if (!shutdown_sent[LOCAL] && !shutdown_sent[REMOTE])
|
||||
shutdown_status = "";
|
||||
else if (!shutdown_sent[LOCAL] && shutdown_sent[REMOTE])
|
||||
shutdown_status = " We've send shutdown, waiting for theirs";
|
||||
else if (shutdown_sent[LOCAL] && !shutdown_sent[REMOTE])
|
||||
shutdown_status = " They've sent shutdown, waiting for ours";
|
||||
else if (shutdown_sent[LOCAL] && shutdown_sent[REMOTE]) {
|
||||
if (num_htlcs)
|
||||
shutdown_status = tal_fmt(ctx,
|
||||
" Shutdown messages"
|
||||
" exchanged, waiting for"
|
||||
" %zu HTLCs to complete.",
|
||||
num_htlcs);
|
||||
else
|
||||
shutdown_status = tal_fmt(ctx,
|
||||
" Shutdown messages"
|
||||
" exchanged.");
|
||||
}
|
||||
|
||||
return tal_fmt(ctx, "%s%s%s", funding_status,
|
||||
announce_status, shutdown_status);
|
||||
}
|
||||
14
common/billboard.h
Normal file
14
common/billboard.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef LIGHTNING_COMMON_BILLBOARD_H
|
||||
#define LIGHTNING_COMMON_BILLBOARD_H
|
||||
#include "config.h"
|
||||
#include <ccan/ccan/tal/tal.h>
|
||||
#include <common/htlc.h>
|
||||
|
||||
char *billboard_message(const tal_t *ctx,
|
||||
const bool funding_locked[NUM_SIDES],
|
||||
const bool have_sigs[NUM_SIDES],
|
||||
const bool shutdown_sent[NUM_SIDES],
|
||||
u32 depth_togo,
|
||||
size_t num_htlcs);
|
||||
|
||||
#endif /* LIGHTNING_COMMON_BILLBOARD_H */
|
||||
Reference in New Issue
Block a user