Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: onlinechecker #5340

Merged
merged 1 commit into from
Jun 28, 2024
Merged

refactor: onlinechecker #5340

merged 1 commit into from
Jun 28, 2024

Conversation

richard-ramos
Copy link
Member

@richard-ramos richard-ramos commented Jun 12, 2024

I noticed that if the node is offline, the peer connector will still attempt to connect to nodes reported by discv5.
This has a negative impact because the connection to the node will obviously fail, and it will increase the backoff period for the next reconnection attempt.

With this change, the peer connector will no longer attempt to connect to any peer when it's notified that the node is offline.

A similar approach is also used for the filter subscriptions, instead of having to notify each subscription that the node is online/offline, it's done in a single step with the online checker

@status-im-auto
Copy link
Member

status-im-auto commented Jun 12, 2024

Jenkins Builds

Click to see older builds (36)
Commit #️⃣ Finished (UTC) Duration Platform Result
✖️ bc9455e #1 2024-06-12 18:34:04 ~1 min tests 📄log
✔️ bc9455e #1 2024-06-12 18:37:04 ~4 min ios 📦zip
✔️ bc9455e #1 2024-06-12 18:37:15 ~4 min linux 📦zip
✔️ bc9455e #1 2024-06-12 18:38:19 ~5 min android 📦aar
✔️ 5daf06b #2 2024-06-12 18:54:22 ~1 min android 📦aar
✔️ 5daf06b #2 2024-06-12 18:54:46 ~2 min linux 📦zip
✔️ 5daf06b #2 2024-06-12 18:55:17 ~2 min ios 📦zip
✖️ 5daf06b #2 2024-06-12 18:59:18 ~6 min tests 📄log
✖️ 5daf06b #3 2024-06-12 19:13:13 ~5 min tests 📄log
✖️ 52d4d78 #4 2024-06-12 19:23:06 ~1 min tests 📄log
✔️ 52d4d78 #3 2024-06-12 19:23:51 ~2 min android 📦aar
✔️ 52d4d78 #3 2024-06-12 19:24:08 ~2 min linux 📦zip
✔️ 52d4d78 #3 2024-06-12 19:24:47 ~3 min ios 📦zip
✔️ a790f39 #4 2024-06-12 19:27:43 ~2 min linux 📦zip
✔️ a790f39 #4 2024-06-12 19:28:32 ~2 min ios 📦zip
✔️ a790f39 #4 2024-06-12 19:31:04 ~5 min android 📦aar
✔️ a790f39 #5 2024-06-12 20:09:43 ~44 min tests 📄log
eab730d #5 2024-06-25 19:37:49 ~28 sec android 📄log
eab730d #5 2024-06-25 19:37:52 ~30 sec ios 📄log
eab730d #5 2024-06-25 19:38:39 ~1 min linux 📄log
✖️ eab730d #6 2024-06-25 19:39:30 ~2 min tests 📄log
✔️ f03752a #6 2024-06-25 19:41:51 ~2 min ios 📦zip
✔️ f03752a #6 2024-06-25 19:41:52 ~2 min linux 📦zip
✔️ f03752a #6 2024-06-25 19:43:15 ~4 min android 📦aar
✔️ f03752a #7 2024-06-25 20:21:26 ~41 min tests 📄log
✔️ 318cfbb #7 2024-06-25 22:11:53 ~2 min android 📦aar
✔️ 318cfbb #7 2024-06-25 22:12:40 ~2 min ios 📦zip
✔️ 318cfbb #7 2024-06-25 22:13:52 ~4 min linux 📦zip
✔️ 318cfbb #8 2024-06-25 22:51:57 ~42 min tests 📄log
✔️ 8e1e877 #8 2024-06-26 17:29:23 ~2 min linux 📦zip
✔️ 8e1e877 #8 2024-06-26 17:29:50 ~2 min ios 📦zip
✔️ 8e1e877 #8 2024-06-26 17:32:54 ~5 min android 📦aar
✔️ 8e1e877 #9 2024-06-26 18:09:08 ~42 min tests 📄log
✔️ 15058d2 #9 2024-06-27 15:03:35 ~2 min android 📦aar
✔️ 15058d2 #9 2024-06-27 15:03:38 ~2 min linux 📦zip
✔️ 15058d2 #10 2024-06-27 15:42:36 ~41 min tests 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ d4c3c58 #10 2024-06-27 17:34:43 ~2 min android 📦aar
✔️ d4c3c58 #10 2024-06-27 17:35:22 ~3 min ios 📦zip
✔️ d4c3c58 #10 2024-06-27 17:36:11 ~3 min linux 📦zip
✔️ d4c3c58 #11 2024-06-27 18:15:07 ~42 min tests 📄log
✔️ ac6fcf0 #11 2024-06-28 12:47:01 ~2 min linux 📦zip
✔️ ac6fcf0 #11 2024-06-28 12:47:48 ~3 min ios 📦zip
✔️ ac6fcf0 #11 2024-06-28 12:48:54 ~4 min android 📦aar
✔️ ac6fcf0 #12 2024-06-28 13:27:14 ~42 min tests 📄log

@richard-ramos richard-ramos force-pushed the pause/connector branch 3 times, most recently from 52d4d78 to a790f39 Compare June 12, 2024 19:25
@richard-ramos
Copy link
Member Author

@kaichaosun @vpavlin @chaitanyaprem
This PR is outdated due to the changes done in waku-org/go-waku#1125
I'll update it tomorrow with new changes assuming that PR gets green lights to be merged.

@richard-ramos richard-ramos force-pushed the pause/connector branch 2 times, most recently from eab730d to f03752a Compare June 25, 2024 19:38
@richard-ramos richard-ramos changed the title fix: pause peer connector if offline refactor: onlinechecker Jun 25, 2024
@richard-ramos
Copy link
Member Author

@chaitanyaprem @kaichaosun @vpavlin
I updated the PR with new behavior for handling online/offline state,
Please review

Copy link
Contributor

@chaitanyaprem chaitanyaprem left a comment

Choose a reason for hiding this comment

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

LGTM

package onlinechecker

// OnlineChecker is used to determine if node has connectivity.
type OnlineChecker interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

In my understanding, there could be a few status for application, Online, Offline, GoingOnline, GoingOffline, Undetermined. We may don't need all of these in Waku and Status.
Just wondering will it be better if we can have a enum for such status, and let the interface here return the current status? Something like a StatusProvider.

if err := w.discoverAndConnectPeers(); err != nil {
w.logger.Error("failed to add wakuv2 peers", zap.Error(err))
}
}

w.offline = !isOnline
w.onlineChecker.SetOnline(isOnline)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about move this line in above if statement? I feel it's more straightforward. Also you may just want to use true directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

SetOnline should receive true or false depending on wheter the application is conencted or not. Moving it to the if would mean that IsOnline() would always return true as SetOnline would never be called with a false value to indicate the app is offline.

@@ -1770,15 +1769,15 @@ func (w *Waku) StopDiscV5() error {
}

func (w *Waku) ConnectionChanged(state connection.State) {
if !state.Offline && w.offline {
if !state.Offline && !w.onlineChecker.IsOnline() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will be improved if we use enum for the different status.

@richard-ramos richard-ramos force-pushed the pause/connector branch 2 times, most recently from 8e1e877 to 15058d2 Compare June 27, 2024 15:00
@richard-ramos richard-ramos merged commit e47e867 into develop Jun 28, 2024
9 checks passed
@richard-ramos richard-ramos deleted the pause/connector branch June 28, 2024 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants