From 5f613147adacc0cdc260aeb1136d972c9b050d74 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 9 Dec 2020 12:24:02 +0100 Subject: [PATCH] contractcourt: decouple waitForHeight from commit sweep resolver To make it usable from other resolvers. --- contractcourt/commit_sweep_resolver.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/contractcourt/commit_sweep_resolver.go b/contractcourt/commit_sweep_resolver.go index 06bdfd53..8320ae63 100644 --- a/contractcourt/commit_sweep_resolver.go +++ b/contractcourt/commit_sweep_resolver.go @@ -10,6 +10,7 @@ import ( "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" + "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/lnwallet" @@ -79,10 +80,12 @@ func (c *commitSweepResolver) ResolverKey() []byte { // waitForHeight registers for block notifications and waits for the provided // block height to be reached. -func (c *commitSweepResolver) waitForHeight(waitHeight uint32) error { +func waitForHeight(waitHeight uint32, notifier chainntnfs.ChainNotifier, + quit <-chan struct{}) error { + // Register for block epochs. After registration, the current height // will be sent on the channel immediately. - blockEpochs, err := c.Notifier.RegisterBlockEpochNtfn(nil) + blockEpochs, err := notifier.RegisterBlockEpochNtfn(nil) if err != nil { return err } @@ -99,7 +102,7 @@ func (c *commitSweepResolver) waitForHeight(waitHeight uint32) error { return nil } - case <-c.quit: + case <-quit: return errResolverShuttingDown } } @@ -169,7 +172,7 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) { // We only need to wait for the block before the block that // unlocks the spend path. - err := c.waitForHeight(unlockHeight - 1) + err := waitForHeight(unlockHeight-1, c.Notifier, c.quit) if err != nil { return nil, err }