Browse Source

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 <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
8229769438
  1. 17
      lightningd/lightningd.c

17
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. */ /* Now we know our ID, we can set our color/alias if not already. */
setup_color_and_alias(ld); setup_color_and_alias(ld);
/* Initialize block topology. */ /* Initialize block topology (does its own transaction) */
setup_topology(ld->topology, setup_topology(ld->topology,
&ld->timers, &ld->timers,
ld->config.poll_time, ld->config.poll_time,
/* FIXME: Load from peers. */ /* FIXME: Load from peers. */
0); 0);
/* Everything is within a transaction. */
db_begin_transaction(ld->wallet->db);
/* Load invoices from the database */ /* Load invoices from the database */
if (!wallet_invoices_load(ld->wallet, ld->invoices)) { 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. */ /* Set up gossip daemon. */
@ -282,12 +285,14 @@ int main(int argc, char *argv[])
peer->owner = NULL; peer->owner = NULL;
if (!wallet_htlcs_load_for_channel(ld->wallet, peer->channel, if (!wallet_htlcs_load_for_channel(ld->wallet, peer->channel,
&ld->htlcs_in, &ld->htlcs_out)) { &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)) { 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."); fatal("could not reconnect htlcs loaded from wallet, wallet may be inconsistent.");
}
db_commit_transaction(ld->wallet->db);
/* Create RPC socket (if any) */ /* Create RPC socket (if any) */
setup_jsonrpc(ld, ld->rpc_filename); setup_jsonrpc(ld, ld->rpc_filename);

Loading…
Cancel
Save