From 3dda72c88527721189e5195c207b80d50ca4d3b3 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 1 Sep 2017 15:54:41 +0200 Subject: [PATCH] db: Create table for HTLCs Also added a small warning to one of the used enums not to reorder or insert values. They'd break the update path. Signed-off-by: Christian Decker --- common/htlc_state.h | 4 ++++ wallet/db.c | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/common/htlc_state.h b/common/htlc_state.h index 7818f3d4f..1b9471975 100644 --- a/common/htlc_state.h +++ b/common/htlc_state.h @@ -2,6 +2,10 @@ #define LIGHTNING_COMMON_HTLC_STATE_H #include "config.h" +/* + * /!\ The generated enum values are used in the database, DO NOT + * reorder or insert new values (appending at the end is ok) /!\ + */ enum htlc_state { /* When we add a new htlc, it goes in this order. */ SENT_ADD_HTLC, diff --git a/wallet/db.c b/wallet/db.c index 7a04a6688..ad782cde9 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -92,6 +92,25 @@ char *dbmigrations[] = { " max_accepted_htlcs INTEGER," " PRIMARY KEY (id)" ");", + "CREATE TABLE channel_htlcs (" + " id INTEGER," + " channel_id INTEGER REFERENCES channels(id) ON DELETE CASCADE," + " channel_htlc_id INTEGER," + " direction INTEGER," + " origin_htlc INTEGER," + " msatoshi INTEGER," + " ctlv_expiry INTEGER," + " payment_hash BLOB," + " payment_key BLOB," + " routing_onion BLOB," + " failuremsg BLOB," + " malformed_onion INTEGER," + " hstate INTEGER," + " shared_secret BLOB," + " preimage BLOB," + " PRIMARY KEY (id)," + " UNIQUE (channel_id, channel_htlc_id, direction)" + ");", NULL, };