From 4b558c3af5c6a96cf21b9c7aa9d466a598959852 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Tue, 8 Nov 2022 14:09:43 +0800 Subject: [PATCH 1/3] funding: decrease checking interval to be 10ms in itest When waiting for the peer to send us FundingLocked, we check whether we've received this message periodically. This commit changes the checking interval from 1s to 10ms in itest, which allows us to still stop the CPU spike while responding to the message quickly. --- funding/config_rpctest.go | 11 +++++++++++ funding/manager.go | 11 +++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 funding/config_rpctest.go diff --git a/funding/config_rpctest.go b/funding/config_rpctest.go new file mode 100644 index 000000000..44a2c939c --- /dev/null +++ b/funding/config_rpctest.go @@ -0,0 +1,11 @@ +//go:build rpctest + +package funding + +import "time" + +func init() { + // For itest, we will use a much shorter checking interval here as + // local communications are very fast. + checkPeerFundingLockInterval = 10 * time.Millisecond +} diff --git a/funding/manager.go b/funding/manager.go index d5e6e730e..1130b076a 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -39,6 +39,13 @@ var ( // byteOrder defines the endian-ness we use for encoding to and from // buffers. byteOrder = binary.BigEndian + + // checkPeerFundingLockInterval is used when we are waiting for the + // peer to send us FundingLocked. We will check every 1 second to see + // if the message is received. + // + // NOTE: for itest, this value is changed to 10ms. + checkPeerFundingLockInterval = 1 * time.Second ) // WriteOutpoint writes an outpoint to an io.Writer. This is not the same as @@ -1022,9 +1029,9 @@ 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 after sleeping for - // one second. + // checkPeerFundingLockInterval. select { - case <-time.After(1 * time.Second): + case <-time.After(checkPeerFundingLockInterval): case <-f.quit: return ErrFundingManagerShuttingDown } From b7816489a14d3ee6f8b2e9e97546cb7307df4c5c Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Tue, 8 Nov 2022 14:15:38 +0800 Subject: [PATCH 2/3] itest: add temp fix to bring back btcd build --- lntest/itest/assertions.go | 7 +++++++ lntest/itest/lnd_channel_policy_test.go | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/lntest/itest/assertions.go b/lntest/itest/assertions.go index 64b304760..435e7a4a7 100644 --- a/lntest/itest/assertions.go +++ b/lntest/itest/assertions.go @@ -90,6 +90,13 @@ func openChannelAndAssert(t *harnessTest, net *lntest.NetworkHarness, "unable to assert channel existence", ) + // They should also notice this channel from topology subscription. + err = alice.WaitForNetworkChannelOpen(fundingChanPoint) + require.NoError(t.t, err) + + err = bob.WaitForNetworkChannelOpen(fundingChanPoint) + require.NoError(t.t, err) + return fundingChanPoint } diff --git a/lntest/itest/lnd_channel_policy_test.go b/lntest/itest/lnd_channel_policy_test.go index 857fe0a1e..638878933 100644 --- a/lntest/itest/lnd_channel_policy_test.go +++ b/lntest/itest/lnd_channel_policy_test.go @@ -739,6 +739,10 @@ func testUpdateChannelPolicyForPrivateChannel(net *lntest.NetworkHarness, ) defer closeChannelAndAssert(t, net, net.Bob, chanPointBobCarol, false) + // Carol should be aware of the channel between Alice and Bob. + err = carol.WaitForNetworkChannelOpen(chanPointAliceBob) + require.NoError(t.t, err) + // Get Bob's funding point. bobChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointBobCarol) require.NoError(t.t, err, "unable to get txid") From 22ae772b3f5e8ff869b94d24b3841a5635d32f91 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Tue, 8 Nov 2022 14:16:54 +0800 Subject: [PATCH 3/3] docs: replace release docs re checking FundingLocked interval --- docs/release-notes/release-notes-0.16.0.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/release-notes-0.16.0.md b/docs/release-notes/release-notes-0.16.0.md index 6f5b845cb..8a443f035 100644 --- a/docs/release-notes/release-notes-0.16.0.md +++ b/docs/release-notes/release-notes-0.16.0.md @@ -149,8 +149,8 @@ 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 +* [Sleep for 10ms when funding locked message is not + received](https://github.com/lightningnetwork/lnd/pull/7126) to avoid CPU spike. ## Code Health