Skip to content

Commit 40dad9a

Browse files
bogdan-rosianucfaur09stefangutica
authored
Development to main (#1546)
* 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>
1 parent 713c4a8 commit 40dad9a

32 files changed

Lines changed: 995 additions & 90 deletions

config/config.devnet.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ api:
88
websocket: true
99
cron:
1010
cacheWarmer: true
11-
fastWarm: true
11+
fastWarm: false
1212
queueWorker: true
1313
elasticUpdater: false
1414
flags:
@@ -20,6 +20,9 @@ flags:
2020
processNfts: true
2121
collectionPropertiesFromGateway: false
2222
features:
23+
websocketSubscription:
24+
enabled: false
25+
port: 6002
2326
eventsNotifier:
2427
enabled: false
2528
port: 5674
@@ -65,7 +68,7 @@ features:
6568
cronExpression: '*/5 * * * * *'
6669
activationEpoch: 1043
6770
chainAndromeda:
68-
enabled: false
71+
enabled: true
6972
activationEpoch: 4
7073
nodeEpochsLeft:
7174
enabled: false

config/config.e2e-mocked.mainnet.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ api:
55
private: true
66
graphql: true
77
features:
8+
websocketSubscription:
9+
enabled: false
10+
port: 6002
811
dataApi:
912
enabled: false
1013
serviceUrl: 'https://data-api.multiversx.com'

config/config.e2e.mainnet.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ flags:
2020
processNfts: true
2121
collectionPropertiesFromGateway: false
2222
features:
23+
websocketSubscription:
24+
enabled: false
25+
port: 6002
2326
eventsNotifier:
2427
enabled: false
2528
port: 5674
@@ -63,7 +66,7 @@ features:
6366
cronExpression: '*/5 * * * * *'
6467
activationEpoch: 1391
6568
chainAndromeda:
66-
enabled: false
69+
enabled: true
6770
activationEpoch: 4
6871
nodeEpochsLeft:
6972
enabled: false

config/config.mainnet.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ flags:
2020
processNfts: true
2121
collectionPropertiesFromGateway: false
2222
features:
23+
websocketSubscription:
24+
enabled: false
25+
port: 6002
2326
eventsNotifier:
2427
enabled: false
2528
port: 5674

config/config.testnet.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ flags:
2020
processNfts: true
2121
collectionPropertiesFromGateway: false
2222
features:
23+
websocketSubscription:
24+
enabled: false
25+
port: 6002
2326
eventsNotifier:
2427
enabled: false
2528
port: 5674
@@ -62,7 +65,7 @@ features:
6265
cronExpression: '*/5 * * * * *'
6366
activationEpoch: 1043
6467
chainAndromeda:
65-
enabled: false
68+
enabled: true
6669
activationEpoch: 4
6770
nodeEpochsLeft:
6871
enabled: false

package-lock.json

Lines changed: 133 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,13 @@
113113
"@sendgrid/mail": "^8.1.5",
114114
"agentkeepalive": "^4.2.1",
115115
"amqp-connection-manager": "^4.1.3",
116-
"anchorme": "^3.0.8",
117116
"amqplib": "^0.10.0",
117+
"anchorme": "^3.0.8",
118118
"apollo-server-core": "^3.13.0",
119119
"apollo-server-express": "3.13.0",
120120
"bignumber.js": "^9.0.2",
121+
"class-transformer": "^0.5.1",
122+
"class-validator": "^0.14.2",
121123
"compression": "^1.8.0",
122124
"crypto-js": "^4.1.1",
123125
"dataloader": "^2.2.2",
@@ -144,6 +146,8 @@
144146
"rxjs": "^7.1.0",
145147
"sharp": "^0.34.2",
146148
"simple-git": "^3.16.0",
149+
"socket.io": "^4.8.1",
150+
"socket.io-client": "^4.8.1",
147151
"swagger-ui-express": "^4.3.0",
148152
"tiny-async-pool": "^1.2.0",
149153
"typeorm": "^0.3.25",
@@ -216,4 +220,4 @@
216220
"node_modules"
217221
]
218222
}
219-
}
223+
}

src/common/api-config/api.config.service.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,4 +954,22 @@ export class ApiConfigService {
954954
getCompressionChunkSize(): number {
955955
return this.configService.get<number>('compression.chunkSize') ?? 16384;
956956
}
957+
958+
getIsWebsocketSubscriptionActive(): boolean {
959+
const isWebsocketSubscriptionActive = this.configService.get<boolean>('features.websocketSubscription.enabled');
960+
if (isWebsocketSubscriptionActive === undefined) {
961+
throw new Error('No features.websocketSubscription.enabled flag present');
962+
}
963+
964+
return isWebsocketSubscriptionActive;
965+
}
966+
967+
getWebsocketSubscriptionPort(): number {
968+
const port = this.configService.get<number>('features.websocketSubscription.port');
969+
if (port === undefined) {
970+
throw new Error('No features.websocketSubscription.port present');
971+
}
972+
973+
return port;
974+
}
957975
}

src/common/metrics/api.metrics.service.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class ApiMetricsService {
2222
private static transactionsCompletedCounter: Counter<string>;
2323
private static transactionsPendingResultsCounter: Counter<string>;
2424
private static batchUpdatesCounter: Counter<string>;
25+
private static subscriptionsConnectionsGauge: Gauge<string>;
2526

2627
constructor(
2728
private readonly apiConfigService: ApiConfigService,
@@ -32,6 +33,13 @@ export class ApiMetricsService {
3233
private readonly metricsService: MetricsService,
3334
) {
3435

36+
if (!ApiMetricsService.subscriptionsConnectionsGauge) {
37+
ApiMetricsService.subscriptionsConnectionsGauge = new Gauge({
38+
name: 'websocket_subscriptions_connections',
39+
help: 'Number of websocket connections for subscriptions',
40+
});
41+
}
42+
3543
if (!ApiMetricsService.vmQueriesHistogram) {
3644
ApiMetricsService.vmQueriesHistogram = new Histogram({
3745
name: 'vm_query',
@@ -182,6 +190,14 @@ export class ApiMetricsService {
182190
ApiMetricsService.lastProcessedTransactionCompletedProcessorNonce.set({ shardId }, nonce);
183191
}
184192

193+
@OnEvent(MetricsEvents.SetWebsocketMetrics)
194+
setWebsocketSubscriptionsMetrics(payload: { connectedClients: number }) {
195+
const { connectedClients } = payload;
196+
197+
ApiMetricsService.subscriptionsConnectionsGauge.set(connectedClients);
198+
}
199+
200+
185201
@OnEvent(MetricsEvents.SetTransactionsCompleted)
186202
recordTransactionsCompleted(payload: { transactions: any[] }) {
187203
ApiMetricsService.transactionsCompletedCounter.inc(payload.transactions.length);

src/crons/cache.warmer/cache.warmer.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class CacheWarmerService {
156156
await this.invalidateKey(CacheInfo.TransactionPool.key, pool, this.apiConfigService.getTransactionPoolCacheWarmerTtlInSeconds());
157157
}
158158

159-
@Cron(CronExpression.EVERY_MINUTE)
159+
@Cron('*/2 * * * *')
160160
@Lock({ name: 'All Tokens invalidations', verbose: true })
161161
async handleEsdtTokenInvalidations() {
162162
const tokens = await this.tokenService.getAllTokensRaw();

0 commit comments

Comments
 (0)