Skip to content

Commit

Permalink
Improvements for scheduled miniblocks and getShards call (#25)
Browse files Browse the repository at this point in the history
* Improvements for scheduled miniblocks and getShards call

* code review fixes

* shardIds as instance variable instead of static

---------

Co-authored-by: tanghel <[email protected]>
  • Loading branch information
vladbucur1 and tanghel authored Oct 1, 2024
1 parent dae4ef4 commit 2ba4f53
Show file tree
Hide file tree
Showing 20 changed files with 380 additions and 177 deletions.
2 changes: 1 addition & 1 deletion example/crons/transaction.processor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class TransactionProcessorService {
async handleNewMultiversxTransactions() {
Locker.lock('newMultiversxTransactions', async () => {
await this.transactionProcessor.start({
mode: TransactionProcessorMode.Hyperblock,
mode: TransactionProcessorMode.Shardblock,
gatewayUrl: 'https://gateway.multiversx.com', // mainnet
getLastProcessedNonce: async (_shardId: number, _currentNonce: number) => {
// In ProcessByHyperblockTransactions shardId will always be METACHAIN
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-transaction-processor",
"version": "0.1.34",
"version": "0.1.35",
"description": "Real-time transaction processor",
"main": "lib/transaction.processor.js",
"types": "lib/transaction.processor.d.ts",
Expand Down
34 changes: 34 additions & 0 deletions src/shards-maintainer.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { METACHAIN } from "./utils/constants";
import { HttpService } from "./utils/http.service";

export class ShardsMaintainerService {
private shardIds: number[] | undefined = undefined;

async get(
baseUrl: string | undefined,
timeout: number | undefined,
) {
if (this.shardIds != null) {
return this.shardIds;
}

return this.shardIds = await this.getShards(baseUrl, timeout);
}

private async getShards(
baseUrl: string | undefined,
timeout: number | undefined,
): Promise<number[]> {
const httpService = new HttpService(baseUrl, timeout);
const networkConfig = await httpService.get('network/config');
const shardCount = networkConfig.config.erd_num_shards_without_meta;

const result = [];
for (let i = 0; i < shardCount; i++) {
result.push(i);
}
result.push(METACHAIN);

return result;
}
}
Loading

0 comments on commit 2ba4f53

Please sign in to comment.