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

Implement WebSocket to Stream Silent Blocks #46

Conversation

seekersoftec
Copy link
Contributor

Objective(s):
Implement a WebSocket connection to stream silent blocks to the client whenever a new block is found and indexed. This will eliminate the need for the client to keep polling for new blocks.

Changes:

  • WebSocket Server Setup:
    • Integrated a WebSocket server using the ws library.
  • Event Listener:
    • Add a function to base-block-data-provider.abstract.ts that emits an event whenever a new block is indexed.
    • Subscribe to this event in the SilentBlocksService and trigger the silent block broadcasting logic when the event is fired.

Scope of Change:
This change is semi-critical. While it doesn't directly affect core functionality, it significantly enhances the user experience and system efficiency by providing real-time updates.

solves #45

Copy link
Collaborator

@theanmolsharma theanmolsharma left a comment

Choose a reason for hiding this comment

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

A few more thoughts:

  1. I see that you are injecting SilentBlocksGateway into SilentBlocksService. That is not the standard pattern. Gateways are like Controllers. You don't inject controllers into a service, you inject service into a controller. Therefore, please remove the event handling logic from SilentBlocksService and move it to inside of SilentBlocksGateway.
  2. I also think we should use socket.io and leverage the concept of rooms. Once a client connects to use, we can subscribe them to a SILENT_BLOCK room. Then we just need to publish silent block to that room and let socket.io handle it from there. This will eliminate the need of forEach loop in broadcastSilentBlock

config/dev.config.yaml Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/block-data-providers/bitcoin-core/provider.ts Outdated Show resolved Hide resolved
src/block-data-providers/block-provider.module.ts Outdated Show resolved Hide resolved
src/silent-blocks/silent-blocks.gateway.ts Outdated Show resolved Hide resolved
src/silent-blocks/silent-blocks.gateway.ts Outdated Show resolved Hide resolved
@seekersoftec
Copy link
Contributor Author

Okay, changes noted

Copy link
Collaborator

@theanmolsharma theanmolsharma left a comment

Choose a reason for hiding this comment

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

I don't think you made all the changes I requested. Please do so before I review it again.

src/common/events.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@theanmolsharma theanmolsharma left a comment

Choose a reason for hiding this comment

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

Please do the following:

  1. fix linting issues
  2. fix broken unit tests
  3. squash all commits into just one commit

config/dev.config.yaml Outdated Show resolved Hide resolved
package-lock.json Outdated Show resolved Hide resolved
src/block-data-providers/bitcoin-core/provider.ts Outdated Show resolved Hide resolved
src/block-data-providers/esplora/provider.ts Outdated Show resolved Hide resolved
src/block-data-providers/esplora/provider.ts Show resolved Hide resolved
src/silent-blocks/silent-blocks.service.ts Outdated Show resolved Hide resolved
src/silent-blocks/silent-blocks.gateway.ts Outdated Show resolved Hide resolved
@aruokhai
Copy link
Contributor

Please Rebase From main

@seekersoftec
Copy link
Contributor Author

Please Rebase From main

Okay

@seekersoftec seekersoftec force-pushed the silent-blocks-websockets branch 4 times, most recently from 3f0b282 to 4caad8e Compare October 22, 2024 09:46
@seekersoftec seekersoftec force-pushed the silent-blocks-websockets branch 2 times, most recently from 0bb8e57 to 30ba463 Compare October 28, 2024 20:10
Copy link
Contributor

@aruokhai aruokhai left a comment

Choose a reason for hiding this comment

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

Seems Good to me, what remains i believe is solve issue for latency.

src/silent-blocks/silent-blocks.service.ts Outdated Show resolved Hide resolved
@seekersoftec seekersoftec force-pushed the silent-blocks-websockets branch 3 times, most recently from ff08e74 to 6817e37 Compare November 19, 2024 12:36
theanmolsharma
theanmolsharma previously approved these changes Nov 26, 2024
Copy link
Collaborator

@theanmolsharma theanmolsharma left a comment

Choose a reason for hiding this comment

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

Approved, but let's also add some e2e tests

@theanmolsharma theanmolsharma dismissed their stale review November 26, 2024 13:22

Requesting some changes

src/common/common.ts Outdated Show resolved Hide resolved
package-lock.json Outdated Show resolved Hide resolved
@seekersoftec seekersoftec force-pushed the silent-blocks-websockets branch 2 times, most recently from d1c939c to 24f3a27 Compare November 29, 2024 09:23
fixed event emitter issue

fix: Add a delay function for silent block events

fix: silent block broadcasting

Fix: Use a more explicit event name for indexing blocks

feat: implement silent block broadcasting

fix: Make event emitter protected

feat: implement silent block broadcasting

fix: Add event emitter and gateway dependencies to tests

chore: added makerfile to make local e2e test a breeze

added makerfile to make local e2e test a breeze:

working

improved maker file structure with output logs for debug purpose

chore: update vulnerable dependancies

Signed-off-by: Anmol Sharma <[email protected]>

feat: implement silent block broadcasting

fixed event emitter issue

fix: Add a delay function for silent block events

fix: silent block broadcasting

Fix: Use a more explicit event name for indexing blocks

feat: implement silent block broadcasting

fix: Make event emitter protected

feat: implement silent block broadcasting

fix: Add event emitter and gateway dependencies to tests

fix: clean block provider module

Fixes duplicate pm2 dependency and updates packages and Removes unused delay function from common.ts.

fix: Remove delay in block processing
@seekersoftec
Copy link
Contributor Author

Fixed all requested changes.

@theanmolsharma theanmolsharma merged commit 7a1aa8e into Bitshala-Incubator:main Dec 2, 2024
4 checks passed
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.

3 participants