Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ replace github.com/libp2p/go-libp2p-pubsub v0.13.1 => github.com/waku-org/go-lib

replace github.com/oNaiPs/go-generate-fast v0.3.0 => github.com/status-im/go-generate-fast v0.0.0-20250916164518-c78009bcfa9e

// Temporary: use fork with background-mode filter subscription fix until
// waku-org/go-waku#1304 is merged and released.
replace github.com/waku-org/go-waku => github.com/xAlisher/go-waku v0.10.2-0.20260603060940-9f8361930df9

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xAlisher here and in other places we should refer to github.com/waku-org/go-waku not to the personal fork.


require (
github.com/anacrolix/torrent v1.41.0
github.com/beevik/ntp v0.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2416,8 +2416,6 @@ github.com/waku-org/go-libp2p-pubsub v0.13.1-gowaku h1:ovXh1m76i0yPWXt95Z9ZRyEk0
github.com/waku-org/go-libp2p-pubsub v0.13.1-gowaku/go.mod h1:MKPU5vMI8RRFyTP0HfdsF9cLmL1nHAeJm44AxJGJx44=
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20240110193335-a67d1cc760a0 h1:R4YYx2QamhBRl/moIxkDCNW+OP7AHbyWLBygDc/xIMo=
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20240110193335-a67d1cc760a0/go.mod h1:EhZP9fee0DYjKH/IOQvoNSy1tSHp2iZadsHGphcAJgY=
github.com/waku-org/go-waku v0.10.2-0.20260518064454-d6d39395ac48 h1:a00GguapTGSRIN9ocw93WsrMOTD07TJ1iqCashttNwA=
github.com/waku-org/go-waku v0.10.2-0.20260518064454-d6d39395ac48/go.mod h1:PDs4hlPbONeMQGsNyfArZV4R2Js1Zy5oqLBfw2VU278=
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 Expand Up @@ -2448,6 +2446,8 @@ github.com/wk8/go-ordered-map/v2 v2.1.7/go.mod h1:9Xvgm2mV2kSq2SAm0Y608tBmu8akTz
github.com/wlynxg/anet v0.0.3/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
github.com/wlynxg/anet v0.0.5 h1:J3VJGi1gvo0JwZ/P1/Yc/8p63SoW98B5dHkYDmpgvvU=
github.com/wlynxg/anet v0.0.5/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
github.com/xAlisher/go-waku v0.10.2-0.20260603060940-9f8361930df9 h1:f1tcz/ftQgHNQkEkfLG8+TBJqluJ10aQO19DpYTUAk8=
github.com/xAlisher/go-waku v0.10.2-0.20260603060940-9f8361930df9/go.mod h1:PDs4hlPbONeMQGsNyfArZV4R2Js1Zy5oqLBfw2VU278=
github.com/xanzy/go-gitlab v0.15.0/go.mod h1:8zdQa/ri1dfn8eS3Ir1SyfvOKlw7WBJ8DVThkpGiXrs=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
Expand Down
7 changes: 7 additions & 0 deletions pkg/backend/node/get_status_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,13 @@ func (n *StatusNode) populateServiceRegistry() {
if n.mediaServer != nil {
n.serviceRegistry.Register(newPausableMediaServer(n.mediaServer))
}
// Wrap and register the messenger so that PauseServices/ResumeServices
// gate filter health-check pings and mailserver syncs in background.
if n.wakuV2ExtSrvc != nil {
if m := n.wakuV2ExtSrvc.Messenger(); m != nil {
n.serviceRegistry.Register(newPausableMessenger(m))
}
}
// Register infrastructure components that are not go-ethereum services
if n.downloader != nil {
n.serviceRegistry.Register(n.downloader)
Expand Down
30 changes: 30 additions & 0 deletions pkg/backend/node/service_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"

"github.com/status-im/status-go/common"
"github.com/status-im/status-go/protocol"
"github.com/status-im/status-go/server"
)

Expand Down Expand Up @@ -38,6 +39,35 @@ func (p *PausableMediaServer) Resume() error {
return nil
}

// PausableMessenger wraps a protocol.Messenger to implement common.Pausable.
// Pause() → ToBackground() and Resume() → ToForeground() so that the Java

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java? 👀

// PauseServices/ResumeServices flow gates filter health-check pings and
// mailserver history syncs without a separate SetAppBackground API call.
type PausableMessenger struct {
Comment thread
jrainville marked this conversation as resolved.
common.PauseBroadcaster
m *protocol.Messenger
}

func newPausableMessenger(m *protocol.Messenger) *PausableMessenger {
p := &PausableMessenger{m: m}
p.MarkStarted()
return p
}

func (p *PausableMessenger) PausableName() string { return "messenger" }

func (p *PausableMessenger) Pause() error {
p.m.ToBackground()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the Messenger's ToBackground never called before?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems so

Comment on lines +59 to +60

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not ideal that Pause == ToBackground here.

I understand that Status app calls Pause when moving to background. But at this API level it's not clear. If I'm calling messenger.Pause, I expect it to pause completely, not just switch some functionality to "background mode".

Not sure how to simply workaround it with current APIs though.

p.MarkPaused()
return nil
}

func (p *PausableMessenger) Resume() error {
p.m.ToForeground()
p.MarkResumed()
return nil
}

// PausableServiceInfo is a lightweight snapshot of a pausable service's state.
type PausableServiceInfo struct {
Name string `json:"name"`
Expand Down
9 changes: 9 additions & 0 deletions pkg/messaging/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ func (a *API) ResumeTransport() {
}
}

// SetFilterBackgroundMode suppresses (background=true) or re-enables
// (background=false) Waku filter-subscription renewal. Call with background=true
// when the app UI is hidden to avoid LTE wakeups from expiring subscriptions.
func (a *API) SetFilterBackgroundMode(background bool) {
if a.core.stack.Transport != nil {
a.core.stack.Transport.SetFilterBackgroundMode(background)
}
}

// PauseDataSync idles (paused==true) or re-arms (paused==false) the reliability
// layer's data-sync node so its outbound loop performs no work while the host is
// backgrounded.
Expand Down
9 changes: 9 additions & 0 deletions pkg/messaging/layers/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ func (t *Transport) Pause() {
}
}

// SetFilterBackgroundMode suppresses (background=true) or re-enables
// (background=false) filter-subscription renewal in the underlying waku
// light-client. No-op when waku is nil or in relay mode.
func (t *Transport) SetFilterBackgroundMode(background bool) {
if t.waku != nil {
t.waku.SetFilterBackgroundMode(background)
}
}

// Resume signals Transport's internal goroutines to resume and cascades to
// EnvelopesMonitor and the underlying waku transport.
func (t *Transport) Resume() {
Expand Down
10 changes: 10 additions & 0 deletions pkg/messaging/waku/gowaku.go
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,16 @@ func (w *Waku) subscribe(f *common.Filter) (string, error) {
return id, nil
}

// SetFilterBackgroundMode suppresses (background=true) or re-enables
// (background=false) filter-subscription renewal in light-client mode.
// No-op when filterManager is nil (relay mode).
func (w *Waku) SetFilterBackgroundMode(background bool) {
if w.filterManager == nil {
return
}
w.filterManager.SetBackgroundMode(background)
}

// Unsubscribe removes an installed message handler.
func (w *Waku) Unsubscribe(ctx context.Context, id string) error {
ok := w.filters.Uninstall(id)
Expand Down
5 changes: 5 additions & 0 deletions pkg/messaging/waku/types/waku.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ type Waku interface {
Pause() error
// Resume re-arms goroutines suspended by Pause. Idempotent.
Resume() error
// SetFilterBackgroundMode suppresses (background=true) or re-enables
// (background=false) filter-subscription renewal in light-client mode.
// When suppressed, expiring subscriptions are not renewed until the app
// returns to foreground, avoiding spurious LTE radio wakeups.
SetFilterBackgroundMode(background bool)

// Waku protocol version
Version() uint
Expand Down
16 changes: 13 additions & 3 deletions protocol/messenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ type Messenger struct {

started bool
paused atomic.Bool
backgroundMode atomic.Bool // true when the app UI is not visible; gates background history syncs
quit chan struct{}
ctx context.Context
cancel context.CancelFunc
Expand Down Expand Up @@ -552,7 +553,10 @@ func (m *Messenger) ToForeground() {
if m.httpServer != nil {
m.httpServer.ToForeground()
}

m.backgroundMode.Store(false)
if m.messaging != nil {
m.messaging.SetFilterBackgroundMode(false)
}
m.asyncRequestAllHistoricMessages()
}

Expand All @@ -561,6 +565,10 @@ func (m *Messenger) ToBackground() {
if m.httpServer != nil {
m.httpServer.ToBackground()
}
m.backgroundMode.Store(true)
if m.messaging != nil {
m.messaging.SetFilterBackgroundMode(true)
}
}

func (m *Messenger) SetPaused(paused bool) {
Expand Down Expand Up @@ -821,8 +829,10 @@ func (m *Messenger) handleConnectionChange(online bool) {
m.shouldPublishContactCode = false
}

// Start fetching messages from store nodes
if online {
// Start fetching messages from store nodes.
// Skip when backgrounded: the sync will run in ToForeground()
// when the app returns to foreground.
if online && !m.backgroundMode.Load() {
m.asyncRequestAllHistoricMessages()
}

Expand Down
6 changes: 5 additions & 1 deletion protocol/messenger_mailserver_cycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ func (m *Messenger) checkForStorenodeCycleSignals() {
if ok {
signal.SendStoreNodeAvailable(&ms)
}
m.asyncRequestAllHistoricMessages()
// Skip history sync when backgrounded; ToForeground()
// will trigger it when the app returns to foreground.
if !m.backgroundMode.Load() {
Comment on lines +162 to +164

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of skipping store node requests, why don't we just completely disconnect from storenodes and stop the StorenodeCycle?

m.asyncRequestAllHistoricMessages()
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions services/ext/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ext

import (
"context"
"errors"
"time"
Comment on lines 3 to 6

"github.com/libp2p/go-libp2p/core/peer"
Expand Down
Loading