From e72b03005408f01804f4cb56bbd08b316a3266e0 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 5 Jun 2017 15:04:26 -0700 Subject: [PATCH] funding: use FundingBrodcastHeight as height hint for conf registrations --- fundingmanager.go | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index 2ccfea56..0551e337 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -145,11 +145,6 @@ type fundingConfig struct { // so that the channel creation process can be completed. Notifier chainntnfs.ChainNotifier - // ChainIO is used by the FundingManager to determine the current - // height so it's able to reduce the search space for certain - // ChainNotifier implementations when registering for confirmations. - ChainIO lnwallet.BlockChainIO - // SignMessage signs an arbitrary method with a given public key. The // actual digest signed is the double sha-256 of the message. In the // case that the private key corresponding to the passed public key @@ -269,11 +264,6 @@ func (f *fundingManager) Start() error { return err } - _, currentHeight, err := f.cfg.ChainIO.GetBestBlock() - if err != nil { - return err - } - // For any channels that were in a pending state when the daemon was // last connected, the Funding Manager will re-initialize the channel // barriers and will also launch waitForFundingConfirmation to wait for @@ -287,7 +277,7 @@ func (f *fundingManager) Start() error { f.barrierMtx.Unlock() doneChan := make(chan struct{}) - go f.waitForFundingConfirmation(channel, uint32(currentHeight), doneChan) + go f.waitForFundingConfirmation(channel, doneChan) } f.wg.Add(1) // TODO(roasbeef): tune @@ -807,15 +797,9 @@ func (f *fundingManager) handleFundingComplete(fmsg *fundingCompleteMsg) { return } - _, bestHeight, err := f.cfg.ChainIO.GetBestBlock() - if err != nil { - fndgLog.Errorf("unable to get best height: %v", err) - } - go func() { doneChan := make(chan struct{}) - go f.waitForFundingConfirmation(completeChan, - uint32(bestHeight), doneChan) + go f.waitForFundingConfirmation(completeChan, doneChan) <-doneChan f.deleteReservationCtx(peerKey, fmsg.msg.PendingChannelID) @@ -877,15 +861,9 @@ func (f *fundingManager) handleFundingSignComplete(fmsg *fundingSignCompleteMsg) }, } - _, bestHeight, err := f.cfg.ChainIO.GetBestBlock() - if err != nil { - fndgLog.Errorf("unable to get best height: %v", err) - } - go func() { doneChan := make(chan struct{}) - go f.waitForFundingConfirmation(completeChan, uint32(bestHeight), - doneChan) + go f.waitForFundingConfirmation(completeChan, doneChan) select { case <-f.quit: @@ -917,7 +895,7 @@ func (f *fundingManager) handleFundingSignComplete(fmsg *fundingSignCompleteMsg) // confirmation, and then to notify the other systems that must be notified // when a channel has become active for lightning transactions. func (f *fundingManager) waitForFundingConfirmation(completeChan *channeldb.OpenChannel, - bestHeight uint32, doneChan chan struct{}) { + doneChan chan struct{}) { defer close(doneChan) @@ -926,7 +904,7 @@ func (f *fundingManager) waitForFundingConfirmation(completeChan *channeldb.Open txid := completeChan.FundingOutpoint.Hash numConfs := uint32(completeChan.NumConfsRequired) confNtfn, err := f.cfg.Notifier.RegisterConfirmationsNtfn(&txid, - numConfs, bestHeight) + numConfs, completeChan.FundingBroadcastHeight) if err != nil { fndgLog.Errorf("Unable to register for confirmation of "+ "ChannelPoint(%v)", completeChan.FundingOutpoint)