From 4b558c3af5c6a96cf21b9c7aa9d466a598959852 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Tue, 8 Nov 2022 14:09:43 +0800 Subject: [PATCH] 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 }