From 22fe2c921fc9316ae8903ae62028383f9ffe54e3 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 23 Apr 2018 19:38:01 +0930 Subject: [PATCH] lightningd: commit short-channel-id to db when we create it. We'd usually commit to the db soon, but there's a window where it could be missed. Also moves loc into the block it's used and make it tmpctx to avoid an explicit free. Signed-off-by: Rusty Russell --- lightningd/peer_control.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index c77ce3e52..783a72ff5 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -628,7 +628,6 @@ static enum watch_result funding_lockin_cb(struct channel *channel, unsigned int depth) { const char *txidstr; - struct txlocator *loc; bool channel_ready; struct lightningd *ld = channel->peer->ld; @@ -640,16 +639,18 @@ static enum watch_result funding_lockin_cb(struct channel *channel, if (depth < channel->minimum_depth) return KEEP_WATCHING; - loc = wallet_transaction_locate(channel, ld->wallet, txid); - /* If we restart, we could already have peer->scid from database */ if (!channel->scid) { + struct txlocator *loc; + + loc = wallet_transaction_locate(tmpctx, ld->wallet, txid); channel->scid = tal(channel, struct short_channel_id); mk_short_channel_id(channel->scid, loc->blkheight, loc->index, channel->funding_outnum); + /* We've added scid, update */ + wallet_channel_save(ld->wallet, channel); } - tal_free(loc); /* In theory, it could have been buried before we got back * from accepting openingd or disconnected: just wait for next one. */