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

feat: improve peer manager and re-integrate to light push #2191

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

weboko
Copy link
Collaborator

@weboko weboko commented Oct 20, 2024

Problem

After spending time with project that use js-waku we were able to determine entities in the code which behavior can be improve. Among them: PeerManager, ReliabilityManager etc.

Solution

For behavior this PR aims to add robustenes to the code by adding new configuration properties and making sure they are enforced.
This PR also re-works PeerManager and partially RelibilityManager.

Notes

Copy link

github-actions bot commented Oct 20, 2024

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Waku node 84.79 KB (-2.24% 🔽) 1.7 s (-2.24% 🔽) 1.8 s (-15.03% 🔽) 3.5 s
Waku Simple Light Node 135.68 KB (-1.08% 🔽) 2.8 s (-1.08% 🔽) 2.4 s (+7.69% 🔺) 5.1 s
ECIES encryption 22.73 KB (-0.65% 🔽) 455 ms (-0.65% 🔽) 703 ms (+32.66% 🔺) 1.2 s
Symmetric encryption 22.23 KB (-0.63% 🔽) 445 ms (-0.63% 🔽) 888 ms (+27.12% 🔺) 1.4 s
DNS discovery 70.8 KB (+0.37% 🔺) 1.5 s (+0.37% 🔺) 1.5 s (-14.89% 🔽) 2.9 s
Peer Exchange discovery 71.8 KB (-0.03% 🔽) 1.5 s (-0.03% 🔽) 1.9 s (+23.48% 🔺) 3.3 s
Local Peer Cache Discovery 65.39 KB (+0.34% 🔺) 1.4 s (+0.34% 🔺) 1.9 s (+10.39% 🔺) 3.2 s
Privacy preserving protocols 76.52 KB (+0.39% 🔺) 1.6 s (+0.39% 🔺) 889 ms (-46.95% 🔽) 2.5 s
Waku Filter 78.11 KB (-3.6% 🔽) 1.6 s (-3.6% 🔽) 2 s (+4.64% 🔺) 3.6 s
Waku LightPush 75.6 KB (-0.18% 🔽) 1.6 s (-0.18% 🔽) 1.9 s (+17.72% 🔺) 3.4 s
History retrieval protocols 75.81 KB (-2.43% 🔽) 1.6 s (-2.43% 🔽) 859 ms (-40.13% 🔽) 2.4 s
Deterministic Message Hashing 7.32 KB (-0.96% 🔽) 147 ms (-0.96% 🔽) 415 ms (+41.19% 🔺) 561 ms

Copy link
Collaborator

@danisharora099 danisharora099 left a comment

Choose a reason for hiding this comment

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

Nice PR! 🚀

Lots happening here.
A few pointers from my side:

  • Are we planning to address the TODOs part of this PR, or follow up?
  • Do we need to introduce newer tests as we delete the functionalities and respective spec tests?
  • How does the peer management work with this PR, considering the overhaul of BaseProtocol, PeerManager and ConnectionManager? Is it stable?

packages/core/src/index.ts Show resolved Hide resolved
return getPeersForProtocol(this.components.peerStore, [this.multicodec]);
}

public async connectedPeers(): Promise<Peer[]> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we still have access to this utility function from elsewhere?
Basically getting the connected peers for a particular protocol

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, in ConnectionManager there is method implemented for it
public async getConnectedPeers(codec?: string): Promise<Peer[]>

Copy link
Collaborator

@danisharora099 danisharora099 Jan 29, 2025

Choose a reason for hiding this comment

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

easier to do
waku.lightpush.connectedPeers()
vs
waku.connectionManager.getPeers(waku.lightpush.multicodec)

im in favor of not removing this
also is a breaking change

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why waku.lightpush.connectedPeers() even needed?
I would assume to be used on the consumer side - but then it's something that we don't expect to be used

whereas waku.connectionManager.getPeers(waku.lightpush.multicodec) is for internal usage for protocols and shouldn't be used outside

also is a breaking change

agree, this PR is pretty much breaking change as we found out previous things were not working well enough

Copy link
Collaborator

Choose a reason for hiding this comment

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

we have had feedback in the past that convinces us that consumers want to be able to check the information of connected peers on the protocol (cc @vpavlin)
we can add it on the SDK layer instead of the core layer

Copy link
Collaborator

Choose a reason for hiding this comment

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

we can continue to use ConnectionManager to provide this API - do you see reason in switching out the use of multicodecs as arg for the function, with the enum type for protocols instead to help DX? (ref: #2191)

packages/interfaces/src/connection_manager.ts Show resolved Hide resolved
Comment on lines +161 to +163
} as unknown as ConnectionManager,
{} as unknown as PeerManager,
options.libp2p
Copy link
Collaborator

Choose a reason for hiding this comment

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

why doesn't typescript comply here/why does it expect an unknown typecase? :(

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it is because mock is partial and there are two ways - mock everything or type casting
since test is a controlled env - type casting is good enough

Copy link
Collaborator

Choose a reason for hiding this comment

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

curious how we were able to do this previously:
Uploading Screenshot 2025-01-29 at 6.59.23 PM.png…

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

screen shot is broken

Copy link
Collaborator

@danisharora099 danisharora099 Jan 30, 2025

Choose a reason for hiding this comment

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

ah
Screenshot 2025-01-30 at 5 52 29 PM

(this is out of curiosity:D)


import { PeerManager } from "./peer_manager.js";

describe("PeerManager", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we add new tests for the PeerManager?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes! But in order not to overcomplicate it even further (now there are 4 PRs) - I will make follow up with them

Copy link
Collaborator

Choose a reason for hiding this comment

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

would be good to add tests in the same PR introducing the functionality

packages/sdk/src/protocols/peer_manager.ts Show resolved Hide resolved
packages/sdk/src/protocols/store/index.ts Outdated Show resolved Hide resolved
@weboko weboko marked this pull request as ready for review January 15, 2025 23:17
@weboko weboko requested a review from a team as a code owner January 15, 2025 23:17
@weboko
Copy link
Collaborator Author

weboko commented Jan 28, 2025

thank you @danisharora099

Are we planning to address the TODOs part of this PR, or follow up?

absolutely, I was looking at some last week

Do we need to introduce newer tests as we delete the functionalities and respective spec tests?

absolutely again, but I limit this PR to drastic changes + manual validation and dogfooding
tests will be a follow up on a case by case basis

How does the peer management work with this PR, considering the overhaul of BaseProtocol, PeerManager and ConnectionManager? Is it stable?

explained in the comment above
it is stable, last Thursday we didn't find bugs as well

@weboko weboko requested a review from danisharora099 January 28, 2025 00:51
@weboko weboko mentioned this pull request Jan 28, 2025
5 tasks
Copy link
Collaborator

@danisharora099 danisharora099 left a comment

Choose a reason for hiding this comment

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

did another review
left comments in individual threads

* add message cache to Filter

* remove WakuOptions and use only ProtocolCreateOptions

* move subscribe options to createLightNode Fitler protocol options

* rename SubscriptionManager to Subscription

* rename to CreateNodeOptions

* add warning

* feat: introduce subscription manager (#2202)

* feat: inroduce subscription manager

* fix: make pipeline succeed (#2238)

* fix test

* use hardcoded value

* update playwright

* fix test:browser

private async onPeerConnected(_event: CustomEvent<PeerId>): Promise<void> {
// TODO(weboko): use config.numOfUsedPeers here
if (this.peers.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

A comment above the function to explain this check would be helpful

}

this.peers = await this.peerManager.getPeers();
await Promise.all(this.peers.map((peer) => this.subscribe(peer)));
Copy link
Member

Choose a reason for hiding this comment

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

similar to above, a comment would be helpful. it appears that if a disconnected peer had been used to establish a filter subscription, then this triggers an attempt to resubscribe to all peers?

Copy link
Collaborator

@danisharora099 danisharora099 left a comment

Choose a reason for hiding this comment

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

nice work! lgtm

primarily comments remaining are around not deleting tests, and adding new tests for new functionalities

Copy link
Collaborator

Choose a reason for hiding this comment

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

we want to follow up with integrating HealthManager back with PeerManager?

Copy link
Collaborator

Choose a reason for hiding this comment

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

we should re add tests for the refactored PeerManager entity

Copy link
Collaborator

@danisharora099 danisharora099 Jan 30, 2025

Choose a reason for hiding this comment

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

similar comment re not deleting tests

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.

feat: improve peer manager and re-integrate to light push
3 participants