Skip to content

Websockets #1528

Merged
bogdan-rosianu merged 35 commits intodevelopmentfrom
websockets-poc
Oct 16, 2025
Merged

Websockets #1528
bogdan-rosianu merged 35 commits intodevelopmentfrom
websockets-poc

Conversation

@stefangutica
Copy link
Copy Markdown
Collaborator

@stefangutica stefangutica commented Aug 20, 2025

Reasoning

  • Allow clients to subscribe to endpoints instead of performing multiple request to fetch updates

Proposed Changes

  • Integrate websockets subscription for transactions, blocks and stats

How to test

  • Use a client simulation script and subscribe to multiple endpoints with different parameters and multiple topics on each client
    Example:
    client1: subscribeTransactions with payload {from=0, size=10}, subscribeBlocks with payload {from=0, size=2}
    client2: subscribeTransactions with payload {from=0, size=2}, subscribeBlocks with payload {from=0, size=5}, subscribeStats

on each client you should only receive data the same as you would request that specific endpoint with those specific parameters and the server must perform only 1 computation per each room at a specific interval regardless of the number of clients in that room -> a room is unique by topic and payload (filter parameters)

@stefangutica stefangutica marked this pull request as draft August 20, 2025 13:49
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 20, 2025

k6 load testing comparison.
Base Commit Hash: 91f20cc
Target Commit Hash: a4dfb21

Metric Base Target Diff
AvgMax9095AvgMax9095AvgMax9095
Transactions76.581445.3465.1373.1276.141654.3864.1671.35-0.58% ✅+14.46% 🔴-1.49% ✅-2.43% ✅
Blocks67.67532.1465.3372.4267.71708.2763.8774.65+0.05% 🔴+33.10% 🔴-2.23% ✅+3.08% 🔴
Mex60.33824.9864.1666.8258.00578.8462.7165.60-3.86% ✅-29.84% ✅-2.26% ✅-1.83% ✅
Nodes60.25635.3564.2266.8758.91910.1662.8565.76-2.22% ✅+43.25% 🔴-2.14% ✅-1.65% ✅
Tokens59.86463.2864.1566.7658.11326.5062.7265.65-2.93% ✅-29.52% ✅-2.24% ✅-1.66% ✅
Accounts60.811078.3764.1666.6559.25943.7062.8665.89-2.58% ✅-12.49% ✅-2.03% ✅-1.14% ✅
Pool59.45292.7464.1566.8458.65800.4162.7865.74-1.36% ✅+173.42% 🔴-2.13% ✅-1.65% ✅
Test Run Duration60003.3060004.83

Legend: Avg - Average Response Time, Max - Maximum Response Time, 90 - 90th Percentile, 95 - 95th Percentile
All times are in milliseconds.

Comment thread src/endpoints/blocks/blocks.gateway.ts Outdated
Comment thread src/endpoints/blocks/blocks.gateway.ts Outdated
Comment thread src/endpoints/network/network.gateway.ts Outdated
@stefangutica stefangutica marked this pull request as ready for review September 3, 2025 13:54
Comment thread config/config.testnet.yaml Outdated
collectionPropertiesFromGateway: false
features:
websocketSubscription:
enabled: true
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.

make them disabled by default maybe? can be left as a TODO before PR's merging

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment thread src/crons/websocket/blocks.gateway.ts Outdated
@ConnectedSocket() client: Socket,
@MessageBody(new WsValidationPipe()) payload: BlockSubscribePayload
) {
const filterHash = JSON.stringify(payload);
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.

this is not really a hash, so maybe we should update the naming to something like filterIdentifier. Please apply this suggestion in all the gateways

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

handleDisconnect(_client: Socket) { }

handleConnection(client: Socket, ..._args: any[]) {
client.setMaxListeners(12);
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.

is it enough? should we extract this number to the config file?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

if the number is exceeded we will only receive a warning(not error) from EventEmitter, but it doesn't affect the functionality. For the moment, until we add another class like blocks,pools,... for ws subscription, that warning should not appear

@@ -0,0 +1,29 @@
// block-subscribe.dto.ts
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.

remove this comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@@ -0,0 +1,20 @@
// block-subscribe.dto.ts
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.

remove this comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment thread src/utils/ws-validation.pipe.ts Outdated
@@ -0,0 +1,16 @@
// ws-validation.pipe.ts
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.

remove this comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@bogdan-rosianu bogdan-rosianu merged commit 2a9f59d into development Oct 16, 2025
6 checks passed
@bogdan-rosianu bogdan-rosianu deleted the websockets-poc branch October 16, 2025 07:41
bogdan-rosianu added a commit that referenced this pull request Oct 17, 2025
* Enhance error handling in GatewayProxyController for block retrieval by hash (#1545)

* use EsdtType instead of hardcoded values (#1544)

* token service improvements (#1543)

* processes 50 tokens concurrently using ConcurrencyUtils

* run all three batch operations in parallel with increased concurrency

* add more logs

* apply mex prices

* add logs ( to be removed )

* increse cron time expression

* set cron to 2 minutes

* Websocket subscriptions (#1528)

* add websockets for blocks and txs

* add support for subscribe to stats

* use websockets rooms

* remove logs

* add lock on crons

* check stats room exists

Signed-off-by: GuticaStefan <stefan.gutica@gmail.com>

* fix indent spaces

* add validation pipes + filters

* add try catch + class validator fixes

* fix linter

* add pool subscription + reduce filters combinations for subscriptions

* lint

* add support for events subscription

* lint

* separate subscription websocket into separate app

* add config

* add path

* fix

* add path for events + config default settings

* temp logs

* temp logs 2

* added missing configs + remove temp logs

* enable andromeda in config

* add metrics on subscription

* remove async + reschedule

* refresh metrics every second

* set max listeners to 12

* add EOL

* add count on update + parallel broadcast to rooms

* lower ttl for blocks count cache

* remove comments

* remove comments

* renaming

---------

Signed-off-by: GuticaStefan <stefan.gutica@gmail.com>
Co-authored-by: bogdan-rosianu <bogdan.rosianu@yahoo.com>
Co-authored-by: cfaur09 <catalinfaurpaul@gmail.com>

* log instead of error for invalid legacy delegation contract (#1542)

---------

Signed-off-by: GuticaStefan <stefan.gutica@gmail.com>
Co-authored-by: Catalin Faur <52102171+cfaur09@users.noreply.github.com>
Co-authored-by: Gutica Stefan <123564494+stefangutica@users.noreply.github.com>
Co-authored-by: cfaur09 <catalinfaurpaul@gmail.com>
cfaur09 added a commit that referenced this pull request Nov 19, 2025
* Enhance error handling in GatewayProxyController for block retrieval by hash (#1545)

* use EsdtType instead of hardcoded values (#1544)

* token service improvements (#1543)

* processes 50 tokens concurrently using ConcurrencyUtils

* run all three batch operations in parallel with increased concurrency

* add more logs

* apply mex prices

* add logs ( to be removed )

* increse cron time expression

* set cron to 2 minutes

* Websocket subscriptions (#1528)

* add websockets for blocks and txs

* add support for subscribe to stats

* use websockets rooms

* remove logs

* add lock on crons

* check stats room exists

Signed-off-by: GuticaStefan <stefan.gutica@gmail.com>

* fix indent spaces

* add validation pipes + filters

* add try catch + class validator fixes

* fix linter

* add pool subscription + reduce filters combinations for subscriptions

* lint

* add support for events subscription

* lint

* separate subscription websocket into separate app

* add config

* add path

* fix

* add path for events + config default settings

* temp logs

* temp logs 2

* added missing configs + remove temp logs

* enable andromeda in config

* add metrics on subscription

* remove async + reschedule

* refresh metrics every second

* set max listeners to 12

* add EOL

* add count on update + parallel broadcast to rooms

* lower ttl for blocks count cache

* remove comments

* remove comments

* renaming

---------

Signed-off-by: GuticaStefan <stefan.gutica@gmail.com>
Co-authored-by: bogdan-rosianu <bogdan.rosianu@yahoo.com>
Co-authored-by: cfaur09 <catalinfaurpaul@gmail.com>

* log instead of error for invalid legacy delegation contract (#1542)

* implement event logAddress filter (#1548)

* implement event logAddress filter

* implement topics filter

* Token market cap updates (#1550)

* token mcap update

* add logs

* extend logs

* add support for timestampMs for account

* fix unit tests

* improve token fetch price (#1549)

* improve token fetch price

* remove logger

* update spec

* fix lint error

* add logs for error

* add price

* Enhance NFT type support in cache warmer and collection services (#1552)

* Refactor function filter application in ElasticIndexerHelper to enhance query conditions with AND operator and existence checks (#1554)

* apply supply info for all tokens (#1558)

* Refactor token market cap calculation to ensure price and circulating supply are checked before computation

* add specs

* fix lint

* added reserved field to blocks (#1560)

* add support for custom url custom headers (#1557)

* Add custom URL headers support and enhance token data fetching

* Enhance custom URL headers handling by adding JSON parsing and validation checks

* add logs

* fixes

* remove app.hatom.com value

* add EOL

* fix indentation

---------

Signed-off-by: GuticaStefan <stefan.gutica@gmail.com>
Co-authored-by: Catalin Faur <52102171+cfaur09@users.noreply.github.com>
Co-authored-by: Gutica Stefan <123564494+stefangutica@users.noreply.github.com>
Co-authored-by: cfaur09 <catalinfaurpaul@gmail.com>
Co-authored-by: GuticaStefan <stefan.gutica@gmail.com>
bogdan-rosianu added a commit that referenced this pull request Jan 13, 2026
* extend features flags config values

* fixes after review + test fix

* set more default configs to false

* fixes after merge

* Enhance error handling in GatewayProxyController for block retrieval by hash (#1545)

* use EsdtType instead of hardcoded values (#1544)

* token service improvements (#1543)

* processes 50 tokens concurrently using ConcurrencyUtils

* run all three batch operations in parallel with increased concurrency

* add more logs

* apply mex prices

* add logs ( to be removed )

* increse cron time expression

* set cron to 2 minutes

* Websocket subscriptions (#1528)

* add websockets for blocks and txs

* add support for subscribe to stats

* use websockets rooms

* remove logs

* add lock on crons

* check stats room exists

Signed-off-by: GuticaStefan <stefan.gutica@gmail.com>

* fix indent spaces

* add validation pipes + filters

* add try catch + class validator fixes

* fix linter

* add pool subscription + reduce filters combinations for subscriptions

* lint

* add support for events subscription

* lint

* separate subscription websocket into separate app

* add config

* add path

* fix

* add path for events + config default settings

* temp logs

* temp logs 2

* added missing configs + remove temp logs

* enable andromeda in config

* add metrics on subscription

* remove async + reschedule

* refresh metrics every second

* set max listeners to 12

* add EOL

* add count on update + parallel broadcast to rooms

* lower ttl for blocks count cache

* remove comments

* remove comments

* renaming

---------

Signed-off-by: GuticaStefan <stefan.gutica@gmail.com>
Co-authored-by: bogdan-rosianu <bogdan.rosianu@yahoo.com>
Co-authored-by: cfaur09 <catalinfaurpaul@gmail.com>

* log instead of error for invalid legacy delegation contract (#1542)

* implement event logAddress filter (#1548)

* implement event logAddress filter

* implement topics filter

* Token market cap updates (#1550)

* token mcap update

* add logs

* extend logs

* add support for timestampMs for account

* fix unit tests

* improve token fetch price (#1549)

* improve token fetch price

* remove logger

* update spec

* fix lint error

* add logs for error

* add price

* Enhance NFT type support in cache warmer and collection services (#1552)

* Refactor function filter application in ElasticIndexerHelper to enhance query conditions with AND operator and existence checks (#1554)

* apply supply info for all tokens (#1558)

* Refactor token market cap calculation to ensure price and circulating supply are checked before computation

* add specs

* fix lint

* added reserved field to blocks (#1560)

* add support for custom url custom headers (#1557)

* Add custom URL headers support and enhance token data fetching

* Enhance custom URL headers handling by adding JSON parsing and validation checks

* add logs

* fixes

* remove app.hatom.com value

* add EOL

* fix indentation

* API-741: staking v5 support

* bugfix

* fix lint

* refactor

* fixes

* try-catch for queue computing

* hotfix disable snapshotless

* revert

* add staking v5 activation epoch feature

* added devnet config

* small fix

* added mainnet config

* add stakingv5 e2e configs

* Deprecate relayed v1/v2 (#1564)

* Add transaction reordering by nonce for account sent transactions

* add relayed deprecation to transfers as well

* add custom subscriptions

* fix lint

* fix lint & unit tests

* hardcode class fields

* lint

* refactor

* add tests for room key generator

* iterate over round only if there are active subscriptions

* improvements

* add support for unsubscribe

* lint

* add support for events

* add support for timestampMs in ES

* lint

* hardcode timestamp supernova in the future

* extra checks + clean code

* fixes

* fixes

* typo

* use latest chainsim

* fix

* add unit tests for transaction reordering by nonce for account sent transactions (#1572)

* add chain simulator e2e tests

* lint

* fix

* missing comma

* fix

* Refactor account, NFT, and transaction services to improve concurrency and caching

* improve NFT bulk fetch + applyOwner

* add no empty payload validator for custom subscriptions

* add global subscription limiter

* remove log

* add e2e tests for events

* lint

* added metric per topics

* updates

* implement ConcurrencyUtils in collection service

* add tests for general subscriptions

* add newline

* use timestampMs

* revert e2e mainnet config

* custom verbose

* use timestampMs on chain sim network

* add subscription limits to config

* fix

* update configs

* use barnard config

* typo

* added readme

* typo

* add lock on subscriptions

* use same key for lock

* fix

* add async mutex

* lint

* return success status on stats

* return unsubscribed status on stats

* config update

* collection service improvments

* fix spec

* fixes

* fixes

* add support for transfers subscription

* add support for token transfers subscriptions

* add ws transfers e2e tests

* fix unit tests

* fix transction filters cache

* remove duplicate code

* add new line

* encapsulate into variable

* renaming

* refactoring + skip unneeded iterations for duplicate keys

* explanation comments

* add unit test for disallowed field comb constraint

* fixes after review

* add configurable broadcast interval

* add check keys present for transfers + events filtered

* remove async await

* fix

* fix nft attributes source

* fix lint

* allow admins to trigger nft updates

* print

* revert log

---------

Signed-off-by: GuticaStefan <stefan.gutica@gmail.com>
Co-authored-by: Catalin Faur <52102171+cfaur09@users.noreply.github.com>
Co-authored-by: Gutica Stefan <123564494+stefangutica@users.noreply.github.com>
Co-authored-by: cfaur09 <catalinfaurpaul@gmail.com>
Co-authored-by: GuticaStefan <stefan.gutica@gmail.com>
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