wallet: Add new `forwards` table to keep track of forwarded payments
Signed-off-by: Christian Decker <@cdecker>
This commit is contained in:
parent
6d2e5bace3
commit
07ebc525e9
15
wallet/db.c
15
wallet/db.c
|
@ -339,6 +339,21 @@ char *dbmigrations[] = {
|
||||||
"ALTER TABLE channels ADD future_per_commitment_point BLOB;",
|
"ALTER TABLE channels ADD future_per_commitment_point BLOB;",
|
||||||
/* last_sent_commit array fix */
|
/* last_sent_commit array fix */
|
||||||
"ALTER TABLE channels ADD last_sent_commit BLOB;",
|
"ALTER TABLE channels ADD last_sent_commit BLOB;",
|
||||||
|
|
||||||
|
/* Stats table to track forwarded HTLCs. The values in the HTLCs
|
||||||
|
* and their states are replicated here and the entries are not
|
||||||
|
* deleted when the HTLC entries or the channel entries are
|
||||||
|
* deleted to avoid unexpected drops in statistics. */
|
||||||
|
"CREATE TABLE forwarded_payments ("
|
||||||
|
" in_htlc_id INTEGER REFERENCES channel_htlcs(id) ON DELETE SET NULL"
|
||||||
|
", out_htlc_id INTEGER REFERENCES channel_htlcs(id) ON DELETE SET NULL"
|
||||||
|
", in_channel_scid INTEGER"
|
||||||
|
", out_channel_scid INTEGER"
|
||||||
|
", in_msatoshi INTEGER"
|
||||||
|
", out_msatoshi INTEGER"
|
||||||
|
", state INTEGER"
|
||||||
|
", UNIQUE(in_htlc_id, out_htlc_id)"
|
||||||
|
");",
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,34 @@ static inline enum wallet_output_type wallet_output_type_in_db(enum wallet_outpu
|
||||||
fatal("%s: %u is invalid", __func__, w);
|
fatal("%s: %u is invalid", __func__, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Possible states for forwards
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/* /!\ This is a DB ENUM, please do not change the numbering of any
|
||||||
|
* already defined elements (adding is ok) /!\ */
|
||||||
|
enum forward_status {
|
||||||
|
FORWARD_OFFERED = 0,
|
||||||
|
FORWARD_SETTLED = 1,
|
||||||
|
FORWARD_FAILED = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline enum forward_status wallet_forward_status_in_db(enum forward_status s)
|
||||||
|
{
|
||||||
|
switch (s) {
|
||||||
|
case FORWARD_OFFERED:
|
||||||
|
BUILD_ASSERT(FORWARD_OFFERED == 0);
|
||||||
|
return s;
|
||||||
|
case FORWARD_SETTLED:
|
||||||
|
BUILD_ASSERT(FORWARD_SETTLED == 1);
|
||||||
|
return s;
|
||||||
|
case FORWARD_FAILED:
|
||||||
|
BUILD_ASSERT(FORWARD_FAILED == 2);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
fatal("%s: %u is invalid", __func__, s);
|
||||||
|
}
|
||||||
|
|
||||||
/* A database backed shachain struct. The datastructure is
|
/* A database backed shachain struct. The datastructure is
|
||||||
* writethrough, reads are performed from an in-memory version, all
|
* writethrough, reads are performed from an in-memory version, all
|
||||||
* writes are passed through to the DB. */
|
* writes are passed through to the DB. */
|
||||||
|
|
Loading…
Reference in New Issue