From 8761a9a0568dafaaacbd6318b0fc2a507518f2d9 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Tue, 1 Nov 2022 02:36:23 +0800 Subject: [PATCH] funding: wait for one sec if funding locked is not received --- docs/release-notes/release-notes-0.16.0.md | 4 ++++ funding/manager.go | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/release-notes-0.16.0.md b/docs/release-notes/release-notes-0.16.0.md index e40234067..ddec481c5 100644 --- a/docs/release-notes/release-notes-0.16.0.md +++ b/docs/release-notes/release-notes-0.16.0.md @@ -146,6 +146,10 @@ certain large transactions](https://github.com/lightningnetwork/lnd/pull/7100). so that the user can specify fees during channel creation time in addition to the default configuration. +* [Sleep for one second when funding locked message is not + received](https://github.com/lightningnetwork/lnd/pull/7095) to avoid CPU + spike. + ## Code Health * [test: use `T.TempDir` to create temporary test diff --git a/funding/manager.go b/funding/manager.go index f956a7a87..d5e6e730e 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -1021,7 +1021,14 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel, if !received { // We haven't received FundingLocked, so we'll continue - // to the next iteration of the loop. + // to the next iteration of the loop after sleeping for + // one second. + select { + case <-time.After(1 * time.Second): + case <-f.quit: + return ErrFundingManagerShuttingDown + } + return nil } @@ -2952,6 +2959,7 @@ func (f *Manager) receivedFundingLocked(node *btcec.PublicKey, // Avoid a tight loop if peer is offline. if _, err := f.waitForPeerOnline(node); err != nil { + log.Errorf("Wait for peer online failed: %v", err) return false, err }