From 75de2e2f3cd9ab2e61cd01256e9011664011a3d7 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 3 Apr 2019 20:50:14 +0200 Subject: [PATCH] wallet: Record the received_time and resolved_time for HTLCs Signed-off-by: Christian Decker --- wallet/db.c | 2 ++ wallet/wallet.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/wallet/db.c b/wallet/db.c index ebf26796e..7a100a417 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -377,6 +377,8 @@ static struct migration dbmigrations[] = { { "ALTER TABLE channels ADD feerate_ppm INTEGER;", NULL }, { NULL, migrate_pr2342_feerate_per_channel }, { "ALTER TABLE channel_htlcs ADD received_time INTEGER", NULL }, + { "ALTER TABLE forwarded_payments ADD received_time INTEGER", NULL }, + { "ALTER TABLE forwarded_payments ADD resolved_time INTEGER", NULL }, }; /* Leak tracking. */ diff --git a/wallet/wallet.c b/wallet/wallet.c index e6b895fdb..d6c3cef7f 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -2492,7 +2492,10 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, ", out_channel_scid" ", in_msatoshi" ", out_msatoshi" - ", state) VALUES (?, ?, ?, ?, ?, ?, ?);"); + ", state" + ", received_time" + ", resolved_time" + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"); sqlite3_bind_int64(stmt, 1, in->dbid); sqlite3_bind_int64(stmt, 2, out->dbid); sqlite3_bind_int64(stmt, 3, in->key.channel->scid->u64); @@ -2500,6 +2503,13 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, sqlite3_bind_amount_msat(stmt, 5, in->msat); sqlite3_bind_amount_msat(stmt, 6, out->msat); sqlite3_bind_int(stmt, 7, wallet_forward_status_in_db(state)); + sqlite3_bind_timeabs(stmt, 8, in->received_time); + + if (state == FORWARD_SETTLED || state == FORWARD_FAILED) + sqlite3_bind_timeabs(stmt, 9, time_now()); + else + sqlite3_bind_null(stmt, 9); + db_exec_prepared(w->db, stmt); }