Skip to content

Commit

Permalink
chanrestore: flip case logic
Browse files Browse the repository at this point in the history
If a channel backup from an old node is restored and a channel contained
within that file was unconfirmed at the time of the backup, the whole
channel short ID is 0:0:0. Unfortunately we got stuck in just the first
case and didn't fall through to the second one. To avoid that, we flip
the case logic because for the second case, the block height in the
short channel ID cannot be zero.
  • Loading branch information
guggero committed Dec 14, 2020
1 parent 90a45fe commit 693d0f6
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions chanrestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,26 @@ func (c *chanDBRestorer) RestoreChansFromSingles(backups ...chanbackup.Single) e
channel := chanShell.Chan

switch {
// Fallback case 1: It is extremely unlikely at this point that
// Fallback case 1: This is an unconfirmed channel from an old
// backup file where we didn't have any workaround in place and
// the short channel ID is 0:0:0. Best we can do here is set the
// funding broadcast height to a reasonable value that we
// determined earlier.
case channel.ShortChanID().BlockHeight == 0:
channel.FundingBroadcastHeight = firstChanHeight

// Fallback case 2: It is extremely unlikely at this point that
// a channel we are trying to restore has a coinbase funding TX.
// Therefore we can be quite certain that if the TxIndex is
// zero, it was an unconfirmed channel where we used the
// BlockHeight to encode the funding TX broadcast height. To not
// end up with an invalid short channel ID that looks valid, we
// restore the "original" unconfirmed one here.
// zero but the block height wasn't, it was an unconfirmed
// channel where we used the BlockHeight to encode the funding
// TX broadcast height. To not end up with an invalid short
// channel ID that looks valid, we restore the "original"
// unconfirmed one here.
case channel.ShortChannelID.TxIndex == 0:
broadcastHeight := channel.ShortChannelID.BlockHeight
channel.FundingBroadcastHeight = broadcastHeight
channel.ShortChannelID.BlockHeight = 0

// Fallback case 2: This is an unconfirmed channel from an old
// backup file where we didn't have any workaround in place.
// Best we can do here is set the funding broadcast height to a
// reasonable value that we determined earlier.
case channel.ShortChanID().BlockHeight == 0:
channel.FundingBroadcastHeight = firstChanHeight
}
}

Expand Down

0 comments on commit 693d0f6

Please sign in to comment.