Browse Source

jsonrpc: Only show total fees collected in getinfo.

And use wallet_forward_status_in_db() everywhere in db code.
And clean up extra CHANGELOG.md entry (looks like rebase error?)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.2rc1
Rusty Russell 6 years ago
parent
commit
604638712b
  1. 4
      CHANGELOG.md
  2. 32
      lightningd/jsonrpc.c
  3. 3
      tests/test_pay.py
  4. 29
      wallet/wallet.c
  5. 10
      wallet/wallet.h

4
CHANGELOG.md

@ -12,11 +12,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- JSON API: `listpeers` has new array `htlcs`: the current live payments.
- JSON API: `listchannels` has two new fields: `message_flags` and `channel_flags`. This replaces `flags`.
- JSON API: `invoice` now adds route hint to invoices for incoming capacity (RouteBoost), and warns if insufficient capacity.
- JSON API: `listforwards` lists all forwarded payments, their associated channels, and fees.
- JSON API: `getinfo` shows forwarding fees earnt as `msatoshi_fees_collected`.
- Bitcoind: more parallelism in requests, for very slow nodes.
- Testing: fixed logging, cleaner interception of bitcoind, minor fixes.
- Protocol: we set and handle the new `htlc_maximum_msat` channel_update field.
- JSON API: `invoice` now adds route hint to invoices for incoming capacity (RouteBoost), and warns if insufficient capacity.
- JSON API: `listforwards` lists all forwarded payments, their associated channels, and fees.
### Changed

32
lightningd/jsonrpc.c

@ -138,35 +138,6 @@ static const struct json_command dev_crash_command = {
AUTODATA(json_command, &dev_crash_command);
#endif /* DEVELOPER */
static void getinfo_add_routestats(struct json_result *response,
struct wallet *wallet)
{
const struct forwarding_stats *stats;
stats = wallet_forwarded_payments_stats(wallet, tmpctx);
json_object_start(response, "routestats");
json_object_start(response, "settled");
json_add_num(response, "fee_msatoshis", stats->fee[FORWARD_SETTLED]);
json_add_num(response, "count", stats->count[FORWARD_SETTLED]);
json_add_num(response, "msatoshi", stats->msatoshi[FORWARD_SETTLED]);
json_object_end(response);
json_object_start(response, "failed");
json_add_num(response, "fee_msatoshis", stats->fee[FORWARD_FAILED]);
json_add_num(response, "count", stats->count[FORWARD_FAILED]);
json_add_num(response, "msatoshi", stats->msatoshi[FORWARD_FAILED]);
json_object_end(response);
json_object_start(response, "pending");
json_add_num(response, "fee_msatoshis", stats->fee[FORWARD_OFFERED]);
json_add_num(response, "count", stats->count[FORWARD_FAILED]);
json_add_num(response, "msatoshi", stats->msatoshi[FORWARD_FAILED]);
json_object_end(response);
json_object_end(response);
tal_free(stats);
}
static void json_getinfo(struct command *cmd,
const char *buffer UNUSED, const jsmntok_t *params UNUSED)
{
@ -196,7 +167,8 @@ static void json_getinfo(struct command *cmd,
json_add_string(response, "version", version());
json_add_num(response, "blockheight", get_block_height(cmd->ld->topology));
json_add_string(response, "network", get_chainparams(cmd->ld)->network_name);
getinfo_add_routestats(response, cmd->ld->wallet);
json_add_u64(response, "msatoshi_fees_collected",
wallet_total_forward_fees(cmd->ld->wallet));
json_object_end(response);
command_success(cmd, response);
}

3
tests/test_pay.py

@ -1050,3 +1050,6 @@ def test_forward_stats(node_factory, bitcoind):
stats = l2.rpc.listforwards()
assert [f['status'] for f in stats['forwards']] == ['settled', 'failed', 'offered']
assert l2.rpc.getinfo()['msatoshi_fees_collected'] == 1 + amount // 100000
assert l1.rpc.getinfo()['msatoshi_fees_collected'] == 0
assert l3.rpc.getinfo()['msatoshi_fees_collected'] == 0

29
wallet/wallet.c

@ -2427,34 +2427,31 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
sqlite3_bind_int64(stmt, 4, out->key.channel->scid->u64);
sqlite3_bind_int64(stmt, 5, in->msatoshi);
sqlite3_bind_int64(stmt, 6, out->msatoshi);
sqlite3_bind_int(stmt, 7, state);
sqlite3_bind_int(stmt, 7, wallet_forward_status_in_db(state));
db_exec_prepared(w->db, stmt);
}
const struct forwarding_stats *wallet_forwarded_payments_stats(struct wallet *w,
const tal_t *ctx)
u64 wallet_total_forward_fees(struct wallet *w)
{
struct forwarding_stats *stats = talz(ctx, struct forwarding_stats);
sqlite3_stmt *stmt;
u64 total;
int res;
stmt = db_prepare(w->db,
"SELECT"
" state"
", COUNT(*)"
", SUM(out_msatoshi) as total"
", SUM(in_msatoshi - out_msatoshi) as fee "
" SUM(in_msatoshi - out_msatoshi) "
"FROM forwarded_payments "
"GROUP BY state;");
"WHERE state = ?;");
while (sqlite3_step(stmt) == SQLITE_ROW) {
enum forward_status state = sqlite3_column_int(stmt, 0);
stats->count[state] = sqlite3_column_int64(stmt, 1);
stats->msatoshi[state] = sqlite3_column_int64(stmt, 2);
stats->fee[state] = sqlite3_column_int64(stmt, 3);
}
sqlite3_bind_int(stmt, 1, wallet_forward_status_in_db(FORWARD_SETTLED));
res = sqlite3_step(stmt);
assert(res == SQLITE_ROW);
total = sqlite3_column_int64(stmt, 0);
db_stmt_done(stmt);
return stats;
return total;
}
const struct forwarding *wallet_forwarded_payments_get(struct wallet *w,

10
wallet/wallet.h

@ -166,11 +166,6 @@ struct forwarding {
enum forward_status status;
};
struct forwarding_stats {
/* One entry for each of the forward_statuses */
u64 count[3], msatoshi[3], fee[3];
};
/* A database backed shachain struct. The datastructure is
* writethrough, reads are performed from an in-memory version, all
* writes are passed through to the DB. */
@ -1028,10 +1023,9 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
enum forward_status state);
/**
* Retrieve global stats about all forwarded_payments
* Retrieve summary of successful forwarded payments' fees
*/
const struct forwarding_stats *wallet_forwarded_payments_stats(struct wallet *w,
const tal_t *ctx);
u64 wallet_total_forward_fees(struct wallet *w);
/**
* Retrieve a list of all forwarded_payments

Loading…
Cancel
Save