Skip to content

Commit

Permalink
[CHERRY-PICK] chore: bump go-waku to fix high cpu usage by peer excha…
Browse files Browse the repository at this point in the history
…nge (#4777) (#4787)

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

* fix: saved addresses sync (`TestSyncDeletesOfSavedAddresses` flaky test) (#4742)

---------

Co-authored-by: Igor Sirotin <sirotin@status.im>
  • Loading branch information
jrainville and igor-sirotin authored Feb 22, 2024
1 parent e59805c commit 0aeaf82
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 184 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
8 changes: 3 additions & 5 deletions protocol/messenger_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package protocol
import (
"encoding/json"

"golang.org/x/exp/maps"

ensservice "github.com/status-im/status-go/services/ens"

"github.com/status-im/status-go/services/browsers"
Expand Down Expand Up @@ -510,11 +512,7 @@ func (r *MessengerResponse) AddSavedAddress(er *wallet.SavedAddress) {
}

func (r *MessengerResponse) SavedAddresses() []*wallet.SavedAddress {
var ers []*wallet.SavedAddress
for _, er := range r.savedAddresses {
ers = append(ers, er)
}
return ers
return maps.Values(r.savedAddresses)
}

func (r *MessengerResponse) AddEnsUsernameDetail(detail *ensservice.UsernameDetail) {
Expand Down
26 changes: 16 additions & 10 deletions protocol/messenger_saved_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@ import (
)

func (m *Messenger) UpsertSavedAddress(ctx context.Context, sa wallet.SavedAddress) error {
updatedClock, err := m.savedAddressesManager.UpdateMetadataAndUpsertSavedAddress(sa)
sa.UpdateClock, _ = m.getLastClockWithRelatedChat()
err := m.savedAddressesManager.UpdateMetadataAndUpsertSavedAddress(sa)
if err != nil {
return err
}
return m.syncNewSavedAddress(ctx, &sa, updatedClock, m.dispatchMessage)
return m.syncNewSavedAddress(ctx, &sa, sa.UpdateClock, m.dispatchMessage)
}

func (m *Messenger) DeleteSavedAddress(ctx context.Context, address gethcommon.Address, isTest bool) error {
updateClock := uint64(time.Now().Unix())
updateClock, _ := m.getLastClockWithRelatedChat()
_, err := m.savedAddressesManager.DeleteSavedAddress(address, isTest, updateClock)
if err != nil {
return err
}
return m.syncDeletedSavedAddress(ctx, address, isTest, updateClock, m.dispatchMessage)
}

func (m *Messenger) GetSavedAddresses(ctx context.Context) ([]wallet.SavedAddress, error) {
func (m *Messenger) GetSavedAddresses(ctx context.Context) ([]*wallet.SavedAddress, error) {
return m.savedAddressesManager.GetSavedAddresses()
}

Expand Down Expand Up @@ -89,13 +90,13 @@ func (m *Messenger) syncDeletedSavedAddress(ctx context.Context, address gethcom
}, rawMessageHandler)
}

func (m *Messenger) syncSavedAddress(ctx context.Context, savedAddress wallet.SavedAddress, rawMessageHandler RawMessageHandler) (err error) {
func (m *Messenger) syncSavedAddress(ctx context.Context, savedAddress *wallet.SavedAddress, rawMessageHandler RawMessageHandler) (err error) {
if savedAddress.Removed {
if err = m.syncDeletedSavedAddress(ctx, savedAddress.Address, savedAddress.IsTest, savedAddress.UpdateClock, rawMessageHandler); err != nil {
return err
}
} else {
if err = m.syncNewSavedAddress(ctx, &savedAddress, savedAddress.UpdateClock, rawMessageHandler); err != nil {
if err = m.syncNewSavedAddress(ctx, savedAddress, savedAddress.UpdateClock, rawMessageHandler); err != nil {
return err
}
}
Expand All @@ -105,12 +106,14 @@ func (m *Messenger) syncSavedAddress(ctx context.Context, savedAddress wallet.Sa
func (m *Messenger) HandleSyncSavedAddress(state *ReceivedMessageState, syncMessage *protobuf.SyncSavedAddress, statusMessage *v1protocol.StatusMessage) (err error) {
address := gethcommon.BytesToAddress(syncMessage.Address)
if syncMessage.Removed {
_, err = m.savedAddressesManager.DeleteSavedAddress(
deleted, err := m.savedAddressesManager.DeleteSavedAddress(
address, syncMessage.IsTest, syncMessage.UpdateClock)
if err != nil {
return err
}
state.Response.AddSavedAddress(&wallet.SavedAddress{Address: address, ENSName: syncMessage.Ens, IsTest: syncMessage.IsTest, Removed: true})
if deleted {
state.Response.AddSavedAddress(&wallet.SavedAddress{Address: address, ENSName: syncMessage.Ens, IsTest: syncMessage.IsTest, Removed: true})
}
} else {
sa := wallet.SavedAddress{
Address: address,
Expand All @@ -120,12 +123,15 @@ func (m *Messenger) HandleSyncSavedAddress(state *ReceivedMessageState, syncMess
IsTest: syncMessage.IsTest,
ColorID: multiAccCommon.CustomizationColor(syncMessage.Color),
}
sa.UpdateClock = syncMessage.UpdateClock

_, err = m.savedAddressesManager.AddSavedAddressIfNewerUpdate(sa, syncMessage.UpdateClock)
added, err := m.savedAddressesManager.AddSavedAddressIfNewerUpdate(sa)
if err != nil {
return err
}
state.Response.AddSavedAddress(&sa)
if added {
state.Response.AddSavedAddress(&sa)
}
}
return
}
Loading

0 comments on commit 0aeaf82

Please sign in to comment.