Skip to content

Commit 70ffe7e

Browse files
use events index instead of logs (#1514)
* use events index instead of logs * configurable migrated indices * added protection for empty fields * fix log address * add transaction get unit tests (#1525) --------- Co-authored-by: cfaur09 <catalinfaurpaul@gmail.com> Co-authored-by: Catalin Faur <52102171+cfaur09@users.noreply.github.com>
1 parent 8cbb2d7 commit 70ffe7e

13 files changed

Lines changed: 815 additions & 11 deletions

config/config.devnet.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ features:
8484
durationThresholdMs: 5000
8585
failureCountThreshold: 5
8686
resetTimeoutMs: 30000
87+
elasticMigratedIndices:
88+
logs: 'events'
8789
statusChecker:
8890
enabled: false
8991
thresholds:

config/config.e2e.mainnet.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ features:
8585
durationThresholdMs: 5000
8686
failureCountThreshold: 5
8787
resetTimeoutMs: 30000
88+
elasticMigratedIndices:
89+
logs: 'events'
8890
statusChecker:
8991
enabled: false
9092
thresholds:

config/config.mainnet.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ features:
8585
durationThresholdMs: 5000
8686
failureCountThreshold: 5
8787
resetTimeoutMs: 30000
88+
elasticMigratedIndices:
89+
logs: 'events'
8890
statusChecker:
8991
enabled: false
9092
thresholds:

config/config.testnet.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ features:
8484
durationThresholdMs: 5000
8585
failureCountThreshold: 5
8686
resetTimeoutMs: 30000
87+
elasticMigratedIndices:
88+
logs: 'events'
8789
statusChecker:
8890
enabled: false
8991
thresholds:

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ export class ApiConfigService {
407407
};
408408
}
409409

410+
getElasticMigratedIndicesConfig(): Record<string, string> {
411+
return this.configService.get<Record<string, string>>('features.elasticMigratedIndices') ?? {};
412+
}
413+
410414
getIsWebsocketApiActive(): boolean {
411415
return this.configService.get<boolean>('api.websocket') ?? true;
412416
}

src/common/indexer/elastic/elastic.indexer.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,17 +591,17 @@ export class ElasticIndexerService implements IndexerInterface {
591591
return query;
592592
}
593593

594-
async getTransactionLogs(hashes: string[]): Promise<any[]> {
594+
async getTransactionLogs(hashes: string[], eventsIndex: string, txHashField: string): Promise<any[]> {
595595
const queries = [];
596596
for (const hash of hashes) {
597-
queries.push(QueryType.Match('_id', hash));
597+
queries.push(QueryType.Match(txHashField, hash));
598598
}
599599

600600
const elasticQueryLogs = ElasticQuery.create()
601601
.withPagination({ from: 0, size: 10000 })
602602
.withCondition(QueryConditionOptions.should, queries);
603603

604-
return await this.elasticService.getList('logs', 'id', elasticQueryLogs);
604+
return await this.elasticService.getList(eventsIndex, 'id', elasticQueryLogs);
605605
}
606606

607607
async getTransactionScResults(txHash: string): Promise<any[]> {

src/common/indexer/entities/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ export { Tag } from './tag';
1212
export { Token } from './token';
1313
export { TokenAccount, TokenType } from './token.account';
1414
export { Transaction } from './transaction';
15-
export { TransactionLog, TransactionLogEvent } from './transaction.log';
15+
export { TransactionLog, TransactionLogEvent, ElasticTransactionLogEvent } from './transaction.log';
1616
export { TransactionReceipt } from './transaction.receipt';

src/common/indexer/entities/transaction.log.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,15 @@ export interface TransactionLogEvent {
1313
data?: string;
1414
order: number;
1515
}
16+
17+
export interface ElasticTransactionLogEvent {
18+
address: string;
19+
identifier: string;
20+
topics: string[];
21+
data?: string;
22+
order: number;
23+
txHash: string;
24+
originalTxHash: string;
25+
logAddress: string;
26+
additionalData?: string[];
27+
}

src/common/indexer/indexer.interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { TokenWithRolesFilter } from "src/endpoints/tokens/entities/token.with.r
1212
import { TransactionFilter } from "src/endpoints/transactions/entities/transaction.filter";
1313
import { TokenAssets } from "../assets/entities/token.assets";
1414
import { QueryPagination } from "../entities/query.pagination";
15-
import { Account, AccountHistory, AccountTokenHistory, Block, Collection, MiniBlock, Operation, Round, ScDeploy, ScResult, Tag, Token, TokenAccount, Transaction, TransactionLog, TransactionReceipt } from "./entities";
15+
import { Account, AccountHistory, AccountTokenHistory, Block, Collection, MiniBlock, Operation, Round, ScDeploy, ScResult, Tag, Token, TokenAccount, Transaction, ElasticTransactionLogEvent, TransactionReceipt } from "./entities";
1616
import { AccountAssets } from "../assets/entities/account.assets";
1717
import { ProviderDelegators } from "./entities/provider.delegators";
1818
import { ApplicationFilter } from "src/endpoints/applications/entities/application.filter";
@@ -134,7 +134,7 @@ export interface IndexerInterface {
134134

135135
getTokensForAddress(address: string, queryPagination: QueryPagination, filter: TokenFilter): Promise<Token[]>
136136

137-
getTransactionLogs(hashes: string[]): Promise<TransactionLog[]>
137+
getTransactionLogs(hashes: string[], eventsIndex: string, txHashField: string): Promise<ElasticTransactionLogEvent[]>
138138

139139
getTransactionScResults(txHash: string): Promise<ScResult[]>
140140

src/common/indexer/indexer.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { TransactionFilter } from "src/endpoints/transactions/entities/transacti
1111
import { MetricsEvents } from "src/utils/metrics-events.constants";
1212
import { TokenAssets } from "../assets/entities/token.assets";
1313
import { QueryPagination } from "../entities/query.pagination";
14-
import { Account, AccountHistory, AccountTokenHistory, Block, Collection, MiniBlock, Operation, Round, ScDeploy, ScResult, Tag, Token, TokenAccount, Transaction, TransactionLog, TransactionReceipt } from "./entities";
14+
import { Account, AccountHistory, AccountTokenHistory, Block, Collection, MiniBlock, Operation, Round, ScDeploy, ScResult, Tag, Token, TokenAccount, Transaction, ElasticTransactionLogEvent, TransactionReceipt } from "./entities";
1515
import { IndexerInterface } from "./indexer.interface";
1616
import { LogPerformanceAsync } from "src/utils/log.performance.decorator";
1717
import { AccountQueryOptions } from "src/endpoints/accounts/entities/account.query.options";
@@ -302,8 +302,8 @@ export class IndexerService implements IndexerInterface {
302302
}
303303

304304
@LogPerformanceAsync(MetricsEvents.SetIndexerDuration)
305-
async getTransactionLogs(hashes: string[]): Promise<TransactionLog[]> {
306-
return await this.indexerInterface.getTransactionLogs(hashes);
305+
async getTransactionLogs(hashes: string[], eventsIndex: string, txHashField: string): Promise<ElasticTransactionLogEvent[]> {
306+
return await this.indexerInterface.getTransactionLogs(hashes, eventsIndex, txHashField);
307307
}
308308

309309
@LogPerformanceAsync(MetricsEvents.SetIndexerDuration)

0 commit comments

Comments
 (0)