chore: bump go-waku to fix high cpu usage by peer exchange (#4777)

This commit is contained in:
richΛrd 2024-02-21 11:05:58 -04:00 committed by GitHub
parent 0856efff6f
commit f650915a49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 26 additions and 27 deletions

View File

@ -1 +1 @@
0.175.1
0.175.2

2
go.mod
View File

@ -89,7 +89,7 @@ require (
github.com/mutecomm/go-sqlcipher/v4 v4.4.2
github.com/schollz/peerdiscovery v1.7.0
github.com/siphiuel/lc-proxy-wrapper v0.0.0-20230516150924-246507cee8c7
github.com/waku-org/go-waku v0.8.1-0.20240130093642-77ea359ef873
github.com/waku-org/go-waku v0.8.1-0.20240220211751-9bb2c8e39680
github.com/wk8/go-ordered-map/v2 v2.1.7
github.com/yeqown/go-qrcode/v2 v2.2.1
github.com/yeqown/go-qrcode/writer/standard v1.2.1

4
go.sum
View File

@ -2101,8 +2101,8 @@ github.com/waku-org/go-discover v0.0.0-20240129014929-85f2c00b96a3 h1:Kk0KYXZE/u
github.com/waku-org/go-discover v0.0.0-20240129014929-85f2c00b96a3/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw=
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 h1:0e1h+p84yBp0IN7AqgbZlV7lgFBjm214lgSOE7CeJmE=
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7/go.mod h1:pFvOZ9YTFsW0o5zJW7a0B5tr1owAijRWJctXJ2toL04=
github.com/waku-org/go-waku v0.8.1-0.20240130093642-77ea359ef873 h1:pnUvFENjM/h7HVF8VsNWTmOXx/rYs62P7H2EFjAnwVw=
github.com/waku-org/go-waku v0.8.1-0.20240130093642-77ea359ef873/go.mod h1:RjTvkTrIwpoT1cM9HeQqwa2Q7t7WOkb3hpuB/zuZ6SM=
github.com/waku-org/go-waku v0.8.1-0.20240220211751-9bb2c8e39680 h1:WGPMcGDmW7q9ZPoD5V53T1ak36/qo1rYLE9bv4g5BVY=
github.com/waku-org/go-waku v0.8.1-0.20240220211751-9bb2c8e39680/go.mod h1:RjTvkTrIwpoT1cM9HeQqwa2Q7t7WOkb3hpuB/zuZ6SM=
github.com/waku-org/go-zerokit-rln v0.1.14-0.20240102145250-fa738c0bdf59 h1:jisj+OCI6QydLtFq3Pyhu49wl9ytPN7oAHjMfepHDrA=
github.com/waku-org/go-zerokit-rln v0.1.14-0.20240102145250-fa738c0bdf59/go.mod h1:1PdBdPzyTaKt3VnpAHk3zj+r9dXPFOr3IHZP9nFle6E=
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230916172309-ee0ee61dde2b h1:KgZVhsLkxsj5gb/FfndSCQu6VYwALrCOgYI3poR95yE=

View File

@ -317,24 +317,7 @@ func (d *DiscoveryV5) Iterate(ctx context.Context, iterator enode.Iterator, onNo
defer iterator.Close()
peerCnt := 0
for {
if !delayedHasNext(ctx, iterator) {
return
}
peerCnt++
if peerCnt == bucketSize { // Delay every bucketSize peers discovered
peerCnt = 0
t := time.NewTimer(delayBetweenDiscoveredPeerCnt)
select {
case <-ctx.Done():
return
case <-t.C:
t.Stop()
}
}
for DelayedHasNext(ctx, iterator, &peerCnt) {
_, addresses, err := wenr.Multiaddress(iterator.Node())
if err != nil {
d.metrics.RecordError(peerInfoFailure)
@ -364,7 +347,7 @@ func (d *DiscoveryV5) Iterate(ctx context.Context, iterator enode.Iterator, onNo
}
}
func delayedHasNext(ctx context.Context, iterator enode.Iterator) bool {
func DelayedHasNext(ctx context.Context, iterator enode.Iterator, peerCnt *int) bool {
// Delay if .Next() is too fast
start := time.Now()
hasNext := iterator.Next()
@ -383,6 +366,18 @@ func delayedHasNext(ctx context.Context, iterator enode.Iterator) bool {
}
}
*peerCnt++
if *peerCnt == bucketSize { // Delay every bucketSize peers discovered
*peerCnt = 0
t := time.NewTimer(delayBetweenDiscoveredPeerCnt)
select {
case <-ctx.Done():
return false
case <-t.C:
t.Stop()
}
}
return true
}

View File

@ -144,7 +144,8 @@ func (wakuPX *WakuPeerExchange) iterate(ctx context.Context) error {
// Closing iterator
defer iterator.Close()
for iterator.Next() {
peerCnt := 0
for discv5.DelayedHasNext(ctx, iterator, &peerCnt) {
_, addresses, err := enr.Multiaddress(iterator.Node())
if err != nil {
wakuPX.log.Error("extracting multiaddrs from enr", zap.Error(err))
@ -183,12 +184,15 @@ func (wakuPX *WakuPeerExchange) runPeerExchangeDiscv5Loop(ctx context.Context) {
err := wakuPX.iterate(ctx)
if err != nil {
wakuPX.log.Debug("iterating peer exchange", zap.Error(err))
time.Sleep(2 * time.Second)
}
t := time.NewTimer(5 * time.Second)
select {
case <-t.C:
t.Stop()
case <-ctx.Done():
t.Stop()
return
default:
}
}
}

2
vendor/modules.txt vendored
View File

@ -1020,7 +1020,7 @@ github.com/waku-org/go-discover/discover/v5wire
github.com/waku-org/go-libp2p-rendezvous
github.com/waku-org/go-libp2p-rendezvous/db
github.com/waku-org/go-libp2p-rendezvous/pb
# github.com/waku-org/go-waku v0.8.1-0.20240130093642-77ea359ef873
# github.com/waku-org/go-waku v0.8.1-0.20240220211751-9bb2c8e39680
## explicit; go 1.19
github.com/waku-org/go-waku/logging
github.com/waku-org/go-waku/waku/persistence