From 3fc53c673b8b0b6eff936c4b1170818d16d43634 Mon Sep 17 00:00:00 2001 From: eugene Date: Mon, 4 Apr 2022 16:51:47 -0400 Subject: [PATCH] contractcourt: set proper height hint for zero-conf channels The contractcourt's chain watcher is now zero-conf aware and will use an appropriate heightHint when scanning the chain. --- contractcourt/chain_watcher.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/contractcourt/chain_watcher.go b/contractcourt/chain_watcher.go index 49067fbd2..3939fef0b 100644 --- a/contractcourt/chain_watcher.go +++ b/contractcourt/chain_watcher.go @@ -266,12 +266,27 @@ func (c *chainWatcher) Start() error { // As a height hint, we'll try to use the opening height, but if the // channel isn't yet open, then we'll use the height it was broadcast - // at. + // at. This may be an unconfirmed zero-conf channel. heightHint := c.cfg.chanState.ShortChanID().BlockHeight if heightHint == 0 { heightHint = chanState.BroadcastHeight() } + // Since no zero-conf state is stored in a channel backup, the below + // logic will not be triggered for restored, zero-conf channels. Set + // the height hint for zero-conf channels. + if chanState.IsZeroConf() { + if chanState.ZeroConfConfirmed() { + // If the zero-conf channel is confirmed, we'll use the + // confirmed SCID's block height. + heightHint = chanState.ZeroConfRealScid().BlockHeight + } else { + // The zero-conf channel is unconfirmed. We'll need to + // use the FundingBroadcastHeight. + heightHint = chanState.BroadcastHeight() + } + } + localKey := chanState.LocalChanCfg.MultiSigKey.PubKey.SerializeCompressed() remoteKey := chanState.RemoteChanCfg.MultiSigKey.PubKey.SerializeCompressed() multiSigScript, err := input.GenMultiSigScript(