Browse Source

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 <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
22fe2c921f
  1. 9
      lightningd/peer_control.c

9
lightningd/peer_control.c

@ -628,7 +628,6 @@ static enum watch_result funding_lockin_cb(struct channel *channel,
unsigned int depth) unsigned int depth)
{ {
const char *txidstr; const char *txidstr;
struct txlocator *loc;
bool channel_ready; bool channel_ready;
struct lightningd *ld = channel->peer->ld; 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) if (depth < channel->minimum_depth)
return KEEP_WATCHING; return KEEP_WATCHING;
loc = wallet_transaction_locate(channel, ld->wallet, txid);
/* If we restart, we could already have peer->scid from database */ /* If we restart, we could already have peer->scid from database */
if (!channel->scid) { if (!channel->scid) {
struct txlocator *loc;
loc = wallet_transaction_locate(tmpctx, ld->wallet, txid);
channel->scid = tal(channel, struct short_channel_id); channel->scid = tal(channel, struct short_channel_id);
mk_short_channel_id(channel->scid, mk_short_channel_id(channel->scid,
loc->blkheight, loc->index, loc->blkheight, loc->index,
channel->funding_outnum); 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 /* In theory, it could have been buried before we got back
* from accepting openingd or disconnected: just wait for next one. */ * from accepting openingd or disconnected: just wait for next one. */

Loading…
Cancel
Save