From 778be5be58ee52ad77c93dd4932e9fa6156dcc90 Mon Sep 17 00:00:00 2001 From: eugene Date: Mon, 4 Apr 2022 16:52:27 -0400 Subject: [PATCH] chanbackup: handle Single creation for zero-conf channels The SCB function NewSingle is now zero-conf aware. Since the confirmed short channel id may be unknown, it may use the broadcast height. --- chanbackup/single.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/chanbackup/single.go b/chanbackup/single.go index 949af708f..6aee903b7 100644 --- a/chanbackup/single.go +++ b/chanbackup/single.go @@ -180,6 +180,24 @@ func NewSingle(channel *channeldb.OpenChannel, chanID.BlockHeight = channel.BroadcastHeight() } + // If this is a zero-conf channel, we'll need to have separate logic + // depending on whether it's confirmed or not. This is because the + // ShortChanID is an alias. + if channel.IsZeroConf() { + // If the channel is confirmed, we'll use the confirmed SCID. + if channel.ZeroConfConfirmed() { + chanID = channel.ZeroConfRealScid() + } else { + // Else if the zero-conf channel is unconfirmed, we'll + // need to use the broadcast height and zero out the + // TxIndex and TxPosition fields. This is so + // openChannelShell works properly. + chanID.BlockHeight = channel.BroadcastHeight() + chanID.TxIndex = 0 + chanID.TxPosition = 0 + } + } + single := Single{ IsInitiator: channel.IsInitiator, ChainHash: channel.ChainHash,