Skip to content

Conversation

weboko
Copy link
Collaborator

@weboko weboko commented Sep 4, 2025

Summary

  • allow Waku event listeners to be registered using string names
  • fix libp2p type mismatches and adjust stream manager tests
  • document event names and usage with string literals

Testing

  • npm run build
  • npm run check
  • npm run test:node --workspace packages/sdk

https://chatgpt.com/codex/tasks/task_e_68b8c8b38f3c833194e44d778110c784

Copy link

github-actions bot commented Sep 4, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Waku node 71.22 KB (-0.01% 🔽) 1.5 s (-0.01% 🔽) 720 ms (+1.13% 🔺) 2.2 s
Waku Simple Light Node 122.56 KB (+0.05% 🔺) 2.5 s (+0.05% 🔺) 692 ms (-21.1% 🔽) 3.2 s
ECIES encryption 22.52 KB (0%) 451 ms (0%) 277 ms (-22.44% 🔽) 727 ms
Symmetric encryption 21.96 KB (0%) 440 ms (0%) 232 ms (-12.94% 🔽) 671 ms
DNS discovery 51.57 KB (-0.14% 🔽) 1.1 s (-0.14% 🔽) 783 ms (+23.03% 🔺) 1.9 s
Peer Exchange discovery 52.29 KB (-0.35% 🔽) 1.1 s (-0.35% 🔽) 405 ms (+7.63% 🔺) 1.5 s
Peer Cache Discovery 46.11 KB (+0.07% 🔺) 923 ms (+0.07% 🔺) 677 ms (+49.12% 🔺) 1.6 s
Privacy preserving protocols 53.68 KB (+0.07% 🔺) 1.1 s (+0.07% 🔺) 546 ms (-44.38% 🔽) 1.7 s
Waku Filter 55.47 KB (-0.08% 🔽) 1.2 s (-0.08% 🔽) 760 ms (+4.89% 🔺) 1.9 s
Waku LightPush 53.01 KB (-0.04% 🔽) 1.1 s (-0.04% 🔽) 796 ms (+22.5% 🔺) 1.9 s
History retrieval protocols 59.33 KB (-0.11% 🔽) 1.2 s (-0.11% 🔽) 747 ms (+2.46% 🔺) 2 s
Deterministic Message Hashing 28.38 KB (-0.13% 🔽) 568 ms (-0.13% 🔽) 320 ms (-33.04% 🔽) 888 ms

@weboko weboko requested a review from Copilot September 4, 2025 21:09
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the Waku event system to allow event listeners to be registered using string names instead of enum values, improving developer experience and API flexibility.

  • Converts WakuEvent from an enum to a const object with type union for better string literal support
  • Fixes libp2p type compatibility issues in FilterCore and stream manager tests
  • Updates documentation examples to demonstrate string-based event registration

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/interfaces/src/waku.ts Converts WakuEvent enum to const object and updates interface definitions and documentation to use string literals
packages/core/src/lib/stream_manager/stream_manager.spec.ts Fixes type casting for libp2p connection manager access in tests and removes trailing whitespace
packages/core/src/lib/filter/filter.ts Updates import statements and converts onRequest method to arrow function property for proper libp2p StreamHandler typing

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

public async start(): Promise<void> {
try {
await this.libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this), {
await this.libp2p.handle(FilterCodecs.PUSH, this.onRequest, {
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

Passing this.onRequest directly will lose the this context when the method is called. Since onRequest is now an arrow function property, this change is correct, but the arrow function should be defined before this line to ensure proper initialization order.

Copilot uses AI. Check for mistakes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What it says. I doubt you can remove the bind here without breaking things. this.onRequest uses this.handleIncomingMessage which I believe will not be available if not binded

public async start(): Promise<void> {
try {
await this.libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this), {
await this.libp2p.handle(FilterCodecs.PUSH, this.onRequest, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What it says. I doubt you can remove the bind here without breaking things. this.onRequest uses this.handleIncomingMessage which I believe will not be available if not binded

];

streamManager["libp2p"]["connectionManager"]["getConnections"] = (
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we avoid the as any in test? it just makes refactoring harder as your bypass the type system. Just leave it as it was.

Comment on lines +28 to +31
export const WakuEvent = {
Connection: "waku:connection",
Health: "waku:health"
} as const;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought you wanted to remove the enum? In any case, add a comment for next implementer to say to leave it as is to expose string for event types to developer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants