mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-09 09:04:25 +01:00
@@ -625,6 +625,7 @@ static void gossipd_getpeers_complete(struct subd *gossip, const u8 *msg,
|
||||
list_for_each(&gpa->cmd->ld->peers, p, list) {
|
||||
bool connected;
|
||||
struct channel *channel;
|
||||
struct channel_stats channel_stats;
|
||||
|
||||
if (gpa->specific_id && !pubkey_eq(gpa->specific_id, &p->id))
|
||||
continue;
|
||||
@@ -712,6 +713,28 @@ static void gossipd_getpeers_complete(struct subd *gossip, const u8 *msg,
|
||||
json_add_string(response, NULL,
|
||||
channel->billboard.transient);
|
||||
json_array_end(response);
|
||||
|
||||
/* Provide channel statistics */
|
||||
wallet_channel_stats_load(gpa->cmd->ld->wallet,
|
||||
channel->dbid,
|
||||
&channel_stats);
|
||||
json_add_u64(response, "in_payments_offered",
|
||||
channel_stats.in_payments_offered);
|
||||
json_add_u64(response, "in_msatoshi_offered",
|
||||
channel_stats.in_msatoshi_offered);
|
||||
json_add_u64(response, "in_payments_fulfilled",
|
||||
channel_stats.in_payments_fulfilled);
|
||||
json_add_u64(response, "in_msatoshi_fulfilled",
|
||||
channel_stats.in_msatoshi_fulfilled);
|
||||
json_add_u64(response, "out_payments_offered",
|
||||
channel_stats.out_payments_offered);
|
||||
json_add_u64(response, "out_msatoshi_offered",
|
||||
channel_stats.out_msatoshi_offered);
|
||||
json_add_u64(response, "out_payments_fulfilled",
|
||||
channel_stats.out_payments_fulfilled);
|
||||
json_add_u64(response, "out_msatoshi_fulfilled",
|
||||
channel_stats.out_msatoshi_fulfilled);
|
||||
|
||||
json_object_end(response);
|
||||
}
|
||||
json_array_end(response);
|
||||
|
||||
@@ -199,26 +199,32 @@ static bool check_cltv(struct htlc_in *hin,
|
||||
static void fulfill_htlc(struct htlc_in *hin, const struct preimage *preimage)
|
||||
{
|
||||
u8 *msg;
|
||||
struct channel *channel = hin->key.channel;
|
||||
struct wallet *wallet = channel->peer->ld->wallet;
|
||||
|
||||
hin->preimage = tal_dup(hin, struct preimage, preimage);
|
||||
htlc_in_check(hin, __func__);
|
||||
|
||||
/* We update state now to signal it's in progress, for persistence. */
|
||||
htlc_in_update_state(hin->key.channel, hin, SENT_REMOVE_HTLC);
|
||||
htlc_in_update_state(channel, hin, SENT_REMOVE_HTLC);
|
||||
/* Update channel stats */
|
||||
wallet_channel_stats_incr_in_fulfilled(wallet,
|
||||
channel->dbid,
|
||||
hin->msatoshi);
|
||||
|
||||
/* No owner? We'll either send to channeld in peer_htlcs, or
|
||||
* onchaind in onchaind_tell_fulfill. */
|
||||
if (!hin->key.channel->owner) {
|
||||
log_debug(hin->key.channel->log, "HTLC fulfilled, but no owner.");
|
||||
if (!channel->owner) {
|
||||
log_debug(channel->log, "HTLC fulfilled, but no owner.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (channel_on_chain(hin->key.channel)) {
|
||||
if (channel_on_chain(channel)) {
|
||||
msg = towire_onchain_known_preimage(hin, preimage);
|
||||
} else {
|
||||
msg = towire_channel_fulfill_htlc(hin, hin->key.id, preimage);
|
||||
}
|
||||
subd_send_msg(hin->key.channel->owner, take(msg));
|
||||
subd_send_msg(channel->owner, take(msg));
|
||||
}
|
||||
|
||||
static void handle_localpay(struct htlc_in *hin,
|
||||
@@ -665,6 +671,10 @@ static void fulfill_our_htlc_out(struct channel *channel, struct htlc_out *hout,
|
||||
htlc_out_check(hout, __func__);
|
||||
|
||||
wallet_htlc_update(ld->wallet, hout->dbid, hout->hstate, preimage);
|
||||
/* Update channel stats */
|
||||
wallet_channel_stats_incr_out_fulfilled(ld->wallet,
|
||||
channel->dbid,
|
||||
hout->msatoshi);
|
||||
|
||||
if (hout->in)
|
||||
fulfill_htlc(hout->in, preimage);
|
||||
@@ -889,6 +899,10 @@ static bool update_out_htlc(struct channel *channel,
|
||||
|
||||
if (!hout->dbid) {
|
||||
wallet_htlc_save_out(ld->wallet, channel, hout);
|
||||
/* Update channel stats */
|
||||
wallet_channel_stats_incr_out_offered(ld->wallet,
|
||||
channel->dbid,
|
||||
hout->msatoshi);
|
||||
|
||||
/* For our own HTLCs, we commit payment to db lazily */
|
||||
if (hout->origin_htlc_id == 0)
|
||||
@@ -1053,6 +1067,9 @@ static bool channel_added_their_htlc(struct channel *channel,
|
||||
|
||||
/* Save an incoming htlc to the wallet */
|
||||
wallet_htlc_save_in(ld->wallet, channel, hin);
|
||||
/* Update channel stats */
|
||||
wallet_channel_stats_incr_in_offered(ld->wallet, channel->dbid,
|
||||
added->amount_msat);
|
||||
|
||||
log_debug(channel->log, "Adding their HTLC %"PRIu64, added->id);
|
||||
connect_htlc_in(&channel->peer->ld->htlcs_in, hin);
|
||||
|
||||
Reference in New Issue
Block a user