From 822976943868cf52231a96f84984a9d6fe0c38fe Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 1 Nov 2017 11:40:48 +1030 Subject: [PATCH] lightningd: do initial database load within a transaction. Safest, and we can then assert that all db calls are in transactions. Signed-off-by: Rusty Russell --- lightningd/lightningd.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index d237b9adf..f14224aa1 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -255,16 +255,19 @@ int main(int argc, char *argv[]) /* Now we know our ID, we can set our color/alias if not already. */ setup_color_and_alias(ld); - /* Initialize block topology. */ + /* Initialize block topology (does its own transaction) */ setup_topology(ld->topology, &ld->timers, ld->config.poll_time, /* FIXME: Load from peers. */ 0); + /* Everything is within a transaction. */ + db_begin_transaction(ld->wallet->db); + /* Load invoices from the database */ if (!wallet_invoices_load(ld->wallet, ld->invoices)) { - err(1, "Could not load invoices from the database"); + fatal("Could not load invoices from the database"); } /* Set up gossip daemon. */ @@ -282,12 +285,14 @@ int main(int argc, char *argv[]) peer->owner = NULL; if (!wallet_htlcs_load_for_channel(ld->wallet, peer->channel, &ld->htlcs_in, &ld->htlcs_out)) { - err(1, "could not load htlcs for channel: %s", ld->wallet->db->err); + fatal("could not load htlcs for channel"); } } - if (!wallet_htlcs_reconnect(ld->wallet, &ld->htlcs_in, &ld->htlcs_out)) { - errx(1, "could not reconnect htlcs loaded from wallet, wallet may be inconsistent."); - } + if (!wallet_htlcs_reconnect(ld->wallet, &ld->htlcs_in, &ld->htlcs_out)) + fatal("could not reconnect htlcs loaded from wallet, wallet may be inconsistent."); + + db_commit_transaction(ld->wallet->db); + /* Create RPC socket (if any) */ setup_jsonrpc(ld, ld->rpc_filename);