diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 2fffa15ce..7f3a81731 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -720,9 +720,6 @@ int main(int argc, char *argv[]) /*~ Initialize the transaction filter with our pubkeys. */ init_txfilter(ld->wallet, ld->owned_txfilter); - /*~ Pull peers, channels and HTLCs from db. */ - load_channels_from_wallet(ld); - /*~ Get the blockheight we are currently at, UINT32_MAX is used to signal * an uninitialized wallet and that we should start off of bitcoind's * current height */ @@ -747,6 +744,13 @@ int main(int argc, char *argv[]) setup_topology(ld->topology, &ld->timers, min_blockheight, max_blockheight); + /*~ Pull peers, channels and HTLCs from db. Needs to happen after the + * topology is initialized since some decisions rely on being able to + * know the blockheight. */ + db_begin_transaction(ld->wallet->db); + load_channels_from_wallet(ld); + db_commit_transaction(ld->wallet->db); + /*~ Now create the PID file: this errors out if there's already a * daemon running, so we call before trying to create an RPC socket. */ pid_fd = pidfile_create(ld);