From 97073962044de9e7756ba6afb890fa6cea9c99b7 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Tue, 15 Oct 2024 17:06:53 +0800 Subject: [PATCH 1/3] independent pull lv0 data --- .../20241014083428_init/migration.sql | 7 + apollo/prisma/schema.prisma | 5 + apollo/src/aggregation/aggregation.service.ts | 32 ++ apollo/src/lnv3/lnv3.service.ts | 407 +++++++++++------- apollo/src/lnv3/source/envio.service.ts | 88 ++-- apollo/src/lnv3/source/ponder.service.ts | 16 +- apollo/src/lnv3/source/source.service.ts | 6 +- apollo/src/lnv3/source/super.service.ts | 16 +- apollo/src/lnv3/source/thegraph.service.ts | 88 ++-- apollo/src/lnv3/transfer.service.ts | 36 ++ 10 files changed, 469 insertions(+), 232 deletions(-) create mode 100644 apollo/prisma/migrations/20241014083428_init/migration.sql diff --git a/apollo/prisma/migrations/20241014083428_init/migration.sql b/apollo/prisma/migrations/20241014083428_init/migration.sql new file mode 100644 index 0000000..aaccb7c --- /dev/null +++ b/apollo/prisma/migrations/20241014083428_init/migration.sql @@ -0,0 +1,7 @@ +-- CreateTable +CREATE TABLE "ScanCursor" ( + "id" TEXT NOT NULL, + "cursor" BIGINT NOT NULL, + + CONSTRAINT "ScanCursor_pkey" PRIMARY KEY ("id") +); diff --git a/apollo/prisma/schema.prisma b/apollo/prisma/schema.prisma index 50ac6ef..f5c5155 100644 --- a/apollo/prisma/schema.prisma +++ b/apollo/prisma/schema.prisma @@ -46,6 +46,11 @@ model HistoryRecord { extData String? } +model ScanCursor { + id String @id + cursor BigInt +} + model LnBridgeRelayInfo { id String @id version String diff --git a/apollo/src/aggregation/aggregation.service.ts b/apollo/src/aggregation/aggregation.service.ts index 5e406c6..27dd757 100644 --- a/apollo/src/aggregation/aggregation.service.ts +++ b/apollo/src/aggregation/aggregation.service.ts @@ -28,6 +28,25 @@ export class AggregationService extends PrismaClient implements OnModuleInit { }); } + async writeCursor(id: string, cursor: bigint) { + return await this.scanCursor.upsert({ + where: { id: id }, + update: { cursor: cursor }, + create: { id: id, cursor: cursor }, + }); + } + + async readCursor(id: string): Promise { + const cursor = await this.scanCursor.findUnique({ + where: { id: id }, + }); + if (cursor) { + return cursor.cursor; + } else { + return BigInt(0); + } + } + async createHistoryRecord(data: Prisma.HistoryRecordCreateInput): Promise { return this.historyRecord.create({ data, @@ -51,6 +70,19 @@ export class AggregationService extends PrismaClient implements OnModuleInit { }); } + async saveHistoryRecord(params: { + where: Prisma.HistoryRecordWhereUniqueInput; + dataCreate: Prisma.HistoryRecordCreateInput; + dataUpdate: Prisma.HistoryRecordUpdateInput; + }): Promise { + const { where, dataCreate, dataUpdate } = params; + return await this.historyRecord.upsert({ + where: where, + update: dataUpdate, + create: dataCreate, + }); + } + async queryLnBridgeRelayInfoFirst( lnBridgeRelayInfoWhereInput: Prisma.LnBridgeRelayInfoWhereInput, orderBy?: Prisma.Enumerable diff --git a/apollo/src/lnv3/lnv3.service.ts b/apollo/src/lnv3/lnv3.service.ts index eccfc6a..3ffaca8 100644 --- a/apollo/src/lnv3/lnv3.service.ts +++ b/apollo/src/lnv3/lnv3.service.ts @@ -6,6 +6,7 @@ import { PartnerT2, RecordStatus, Level0IndexerType } from '../base/TransferServ import { TasksService } from '../tasks/tasks.service'; import { TransferService } from './transfer.service'; import { ChainToken, ChainMessager, ChainCouple } from '@helixbridge/helixconf'; +import { Lnv3Record, Lnv3RelayRecord } from './source/source.service'; import { Lnv3ThegraphService } from './source/thegraph.service'; import { Lnv3PonderService } from './source/ponder.service'; import { Lnv3EnvioService } from './source/envio.service'; @@ -22,18 +23,35 @@ interface SkipInfo { skip: number; } +interface Lnv3RecordInfo { + lv0Type: Level0IndexerType; + cursor: bigint; + records: Lnv3Record[]; +} + +interface Lnv3RelayInfo { + lv0Type: Level0IndexerType; + cursor: bigint; + records: Lnv3RelayRecord[]; +} + +enum SyncStage { + SyncRecord, + SyncStatus, + SyncFinished, +} + @Injectable() export class Lnv3Service implements OnModuleInit { private readonly logger = new Logger('lnv3'); private fetchCache = new Array(this.transferService.transfers.length).fill('').map((_) => ({ - latestNonce: -1, latestRelayerInfoNonce: -1, - latestFillInfoTimestamp: -1, isSyncingHistory: false, waitingWithdrawInterval: 0, waitingWithdrawRecords: [], fetchProviderInfoInterval: 0, + syncingStage: SyncStage.SyncRecord, })); protected fetchSendDataInterval = 5000; @@ -114,18 +132,51 @@ export class Lnv3Service implements OnModuleInit { } } - async queryRecordInfo(transfer: PartnerT2, latestNonce: number) { - let result = []; + lv0TransferRecordCursorId(chainId: bigint, indexerType: Level0IndexerType): string { + return `lnv3-lv0-tr-${chainId}-${indexerType}`; + } + + lv0RelayRecordCursorId(chainId: bigint, indexerType: Level0IndexerType): string { + return `lnv3-lv0-rr-${chainId}-${indexerType}`; + } + + async getLevel0TransferRecordCursor( + chainId: bigint, + indexerType: Level0IndexerType + ): Promise { + const id = this.lv0TransferRecordCursorId(chainId, indexerType); + return await this.aggregationService.readCursor(id); + } + + async getLevel0RelayRecordCursor( + chainId: bigint, + indexerType: Level0IndexerType + ): Promise { + const id = this.lv0RelayRecordCursorId(chainId, indexerType); + return await this.aggregationService.readCursor(id); + } + + async queryRecordInfo(transfer: PartnerT2, limit: number): Promise { + let results = []; for (const level0Indexer of transfer.level0Indexers) { const service = this.sourceServices.get(level0Indexer.indexerType); try { + const cursor = await this.getLevel0TransferRecordCursor( + transfer.chainConfig.id, + level0Indexer.indexerType + ); const response = await service.queryRecordInfo( level0Indexer.url, transfer.chainConfig.id, - latestNonce + cursor, + limit ); - if (response && response.length >= result.length) { - result = response; + if (response && response.length > 0) { + results.push({ + lv0Type: level0Indexer.indexerType, + cursor: cursor, + records: response, + }); } } catch (err) { this.logger.warn( @@ -133,7 +184,7 @@ export class Lnv3Service implements OnModuleInit { ); } } - return result; + return results; } async queryProviderInfo(transfer: PartnerT2, latestNonce: number) { @@ -218,126 +269,194 @@ export class Lnv3Service implements OnModuleInit { } } - async fetchRecords(transfer: PartnerT2, index: number) { - let latestNonce = this.fetchCache[index].latestNonce; - try { - if (latestNonce === -1) { - const firstRecord = await this.aggregationService.queryHistoryRecordFirst( - { - fromChain: transfer.chainConfig.code, - bridge: `lnv3`, - }, - { nonce: 'desc' } + async saveRecord(transfer: PartnerT2, recordInfo: Lnv3RecordInfo) { + const records = recordInfo.records; + let size = 0; + let cursor = recordInfo.cursor; + let lastTimestamp = ''; + for (const record of records) { + cursor += BigInt(1); + const toChain = this.getDestChain(record.remoteChainId.toString()); + if (toChain === null) { + this.logger.warn(`fetch record cannot find toChain, id ${record.remoteChainId}`); + continue; + } + const fromToken = this.getTokenInfo(transfer, record.sourceToken); + const toToken = this.getTokenInfo(toChain, record.targetToken); + if (fromToken === null) { + this.logger.warn( + `cannot find fromToken symbol, fromToken ${record.sourceToken}, chain: ${transfer.chainConfig.code}` ); - latestNonce = firstRecord ? Number(firstRecord.nonce) : 0; + continue; + } + if (toToken === null) { + this.logger.warn( + `cannot find fromToken symbol, toToken ${record.targetToken}, chain: ${toChain.chainConfig.code}` + ); + continue; } - const records = await this.queryRecordInfo(transfer, latestNonce); + lastTimestamp = record.timestamp; + const id = this.genID( + transfer, + transfer.chainConfig.id.toString(), + record.remoteChainId.toString(), + record.id + ); + let createData = { + id: id, + relayer: record.provider.toLowerCase(), + fromChain: transfer.chainConfig.code, + toChain: toChain.chainConfig.code, + bridge: `lnv3`, + messageNonce: record.messageNonce, + nonce: 0, + requestTxHash: record.transactionHash, + sender: record.sender.toLowerCase(), + recipient: record.receiver.toLowerCase(), + sendToken: fromToken.symbol, + recvToken: toToken.symbol, + sendAmount: record.sourceAmount, + recvAmount: record.targetAmount, + startTime: Number(record.timestamp), + endTime: 0, + result: RecordStatus.pending, + fee: record.fee, + feeToken: fromToken.symbol, + responseTxHash: '', + reason: '', + sendTokenAddress: record.sourceToken.toLowerCase(), + recvTokenAddress: record.targetToken.toLowerCase(), + endTxHash: '', + confirmedBlocks: '', + needWithdrawLiquidity: !record.hasWithdrawn, + lastRequestWithdraw: 0, + }; + const updateData = record.hasWithdrawn ? { needWithdrawLiquidity: false } : {}; + await this.aggregationService.saveHistoryRecord({ + where: { id: id }, + dataCreate: createData, + dataUpdate: updateData, + }); + size += 1; + const skip = this.skip.find( + (s) => s.fromChain === transfer.chainConfig.code && s.toChain === toChain.chainConfig.code + ); + if (!skip) { + this.skip.push({ + fromChain: transfer.chainConfig.code, + toChain: toChain.chainConfig.code, + skip: 0, + }); + } + await this.aggregationService.writeCursor( + this.lv0TransferRecordCursorId(transfer.chainConfig.id, recordInfo.lv0Type), + cursor + ); + } + if (size > 0) { + this.logger.log( + `lnv3 [${transfer.chainConfig.code}] save new send records succeeded: ${Level0IndexerType[recordInfo.lv0Type]}-${cursor}-${lastTimestamp}, size: ${size}` + ); + } + } - if (records && records.length > 0) { - let size = 0; - for (const record of records) { - const toChain = this.getDestChain(record.remoteChainId.toString()); - if (toChain === null) { - this.logger.warn(`fetch record cannot find toChain, id ${record.remoteChainId}`); - latestNonce += 1; - this.fetchCache[index].latestNonce = latestNonce; - continue; - } - const fromToken = this.getTokenInfo(transfer, record.sourceToken); - const toToken = this.getTokenInfo(toChain, record.targetToken); - if (fromToken === null) { - this.logger.warn( - `cannot find fromToken symbol, fromToken ${record.sourceToken}, chain: ${transfer.chainConfig.code}` - ); - continue; - } - if (toToken === null) { - this.logger.warn( - `cannot find fromToken symbol, toToken ${record.targetToken}, chain: ${toChain.chainConfig.code}` - ); - continue; - } + async saveRelayInfo(transfer: PartnerT2, relayInfo: Lnv3RelayInfo) { + const records = relayInfo.records; + let size = 0; + let cursor = relayInfo.cursor; + let lastTimestamp = ''; + for (const relayRecord of records) { + cursor += BigInt(1); + lastTimestamp = relayRecord.timestamp; + // ignore slashed transfer + if (relayRecord.slashed) continue; + let rmvedTransferId = relayRecord.id; + if (rmvedTransferId.startsWith(`${transfer.chainConfig.id}-`)) { + rmvedTransferId = rmvedTransferId.replace(`${transfer.chainConfig.id}-`, ''); + } + const uncheckedRecord = await this.aggregationService.queryHistoryRecordFirst({ + id: { + endsWith: rmvedTransferId, + }, + }); + // the record exist but not finished + if (uncheckedRecord?.endTxHash === '') { + const endTxHash = uncheckedRecord.needWithdrawLiquidity ? '' : relayRecord.transactionHash; + const updateData = { + result: RecordStatus.success, + responseTxHash: relayRecord.transactionHash, + endTxHash: endTxHash, + endTime: Number(relayRecord.timestamp), + relayer: relayRecord.relayer.toLowerCase(), + lastRequestWithdraw: Number(relayRecord.requestWithdrawTimestamp), + }; + + await this.aggregationService.updateHistoryRecord({ + where: { id: uncheckedRecord.id }, + data: updateData, + }); + size += 1; + } + await this.aggregationService.writeCursor( + this.lv0RelayRecordCursorId(transfer.chainConfig.id, relayInfo.lv0Type), + cursor + ); + } + if (records.length > 0) { + this.logger.log( + `lnv3 [${transfer.chainConfig.code}] save new relay records succeeded: ${Level0IndexerType[relayInfo.lv0Type]}-${cursor}-${lastTimestamp}, size: ${size}` + ); + } + } - const responseHash = ''; - const result = RecordStatus.pending; - const endTime = 0; - const skip = this.skip.find( - (s) => - s.fromChain === transfer.chainConfig.code && s.toChain === toChain.chainConfig.code - ); - if (!skip) { - this.skip.push({ - fromChain: transfer.chainConfig.code, - toChain: toChain.chainConfig.code, - skip: 0, - }); + async fetchRecords(transfer: PartnerT2, index: number) { + try { + const cache = this.fetchCache[index]; + const limit = cache.syncingStage === SyncStage.SyncRecord ? 500 : 10; + const recordList = await this.queryRecordInfo(transfer, limit); + for (const recordInfo of recordList) { + if (recordInfo.records && recordInfo.records.length > 0) { + try { + await this.saveRecord(transfer, recordInfo); + } catch (error) { + this.logger.warn(`save record failed, error ${error}`); } - await this.aggregationService.createHistoryRecord({ - id: this.genID( - transfer, - transfer.chainConfig.id.toString(), - record.remoteChainId, - record.id - ), - relayer: record.provider.toLowerCase(), - fromChain: transfer.chainConfig.code, - toChain: toChain.chainConfig.code, - bridge: `lnv3`, - messageNonce: record.messageNonce, - nonce: latestNonce + 1, - requestTxHash: record.transactionHash, - sender: record.sender.toLowerCase(), - recipient: record.receiver.toLowerCase(), - sendToken: fromToken.symbol, - recvToken: toToken.symbol, - sendAmount: record.sourceAmount, - recvAmount: record.targetAmount, - startTime: Number(record.timestamp), - endTime: endTime, - result: result, - fee: record.fee, - feeToken: fromToken.symbol, - responseTxHash: responseHash, - reason: '', - sendTokenAddress: record.sourceToken.toLowerCase(), - recvTokenAddress: record.targetToken.toLowerCase(), - endTxHash: '', - confirmedBlocks: '', - needWithdrawLiquidity: !record.hasWithdrawn, - lastRequestWithdraw: 0, - }); - latestNonce += 1; - size += 1; - } - if (size > 0) { - this.logger.log( - `lnv3 [${transfer.chainConfig.code}] save new send records succeeded nonce: ${latestNonce}, size: ${size}` - ); } - - this.fetchCache[index].latestNonce = latestNonce; + } + if (recordList.length === 0 && cache.syncingStage === SyncStage.SyncRecord) { + this.logger.log(`lnv3 [${transfer.chainConfig.code}->] sync records finished`); + cache.syncingStage = SyncStage.SyncStatus; } } catch (error) { this.logger.warn( - `lnv3 [${transfer.chainConfig.code}->] save new send record failed ${latestNonce}, ${error}` + `lnv3 [${transfer.chainConfig.code}->] save new send record failed ${error}` ); } } // batch get status from target chain on sycing historical phase - async queryFillInfos(transfer: PartnerT2, latestTimestamp: number) { - let result = []; + async queryFillInfos(transfer: PartnerT2, limit: number): Promise { + let results = []; for (const level0Indexer of transfer.level0Indexers) { const service = this.sourceServices.get(level0Indexer.indexerType); try { + const cursor = await this.getLevel0RelayRecordCursor( + transfer.chainConfig.id, + level0Indexer.indexerType + ); const response = await service.batchQueryRelayStatus( level0Indexer.url, transfer.chainConfig.id, - latestTimestamp + cursor, + limit ); - if (response && response.length >= result.length) { - result = response; + if (response && response.length > 0) { + results.push({ + lv0Type: level0Indexer.indexerType, + cursor: cursor, + records: response, + }); } } catch (err) { this.logger.warn( @@ -345,70 +464,29 @@ export class Lnv3Service implements OnModuleInit { ); } } - return result; + return results; } async batchFetchStatus(transfer: PartnerT2, index: number) { - try { - let latestTimestamp = this.fetchCache[index].latestFillInfoTimestamp; - // stop sync history when timestamp set to zero - if (latestTimestamp === 0) { - return; - } else if (latestTimestamp === -1) { - const firstRecord = await this.aggregationService.queryHistoryRecordFirst( - { - toChain: transfer.chainConfig.code, - bridge: `lnv3`, - }, - { nonce: 'desc' } - ); - latestTimestamp = firstRecord ? firstRecord.endTime : -1; - } - const relayRecords = await this.queryFillInfos(transfer, latestTimestamp); - if (relayRecords.length === 0) { - this.fetchCache[index].latestFillInfoTimestamp = 0; - this.logger.log(`the batch sync end, chain: ${transfer.chainConfig.code}`); + for (const cache of this.fetchCache) { + if (cache.syncingStage === SyncStage.SyncRecord) { return; } + } + try { + const cache = this.fetchCache[index]; + const limit = cache.syncingStage === SyncStage.SyncFinished ? 10 : 500; + const relayList = await this.queryFillInfos(transfer, limit); let size = 0; - for (const relayRecord of relayRecords) { - // ignore slashed transfer - if (relayRecord.slashed) continue; - let rmvedTransferId = relayRecord.id; - if (rmvedTransferId.startsWith(`${transfer.chainConfig.id}-`)) { - rmvedTransferId = rmvedTransferId.replace(`${transfer.chainConfig.id}-`, ''); - } - const uncheckedRecord = await this.aggregationService.queryHistoryRecordFirst({ - id: { - endsWith: rmvedTransferId, - }, - }); - // the record exist but not finished - if (uncheckedRecord?.endTxHash === '') { - const endTxHash = uncheckedRecord.needWithdrawLiquidity - ? '' - : relayRecord.transactionHash; - const updateData = { - result: RecordStatus.success, - responseTxHash: relayRecord.transactionHash, - endTxHash: endTxHash, - endTime: Number(relayRecord.timestamp), - relayer: relayRecord.relayer.toLowerCase(), - lastRequestWithdraw: Number(relayRecord.requestWithdrawTimestamp), - }; - - await this.aggregationService.updateHistoryRecord({ - where: { id: uncheckedRecord.id }, - data: updateData, - }); - this.fetchCache[index].latestFillInfoTimestamp = updateData.endTime; - size += 1; - } else if (uncheckedRecord) { - this.fetchCache[index].latestFillInfoTimestamp = Number(relayRecord.timestamp); + for (const relayInfo of relayList) { + if (relayInfo.records && relayInfo.records.length > 0) { + await this.saveRelayInfo(transfer, relayInfo); } } - if (size > 0) { - this.logger.log(`lnv3 [${transfer.chainConfig.code}] batch fetch status, size: ${size}`); + + if (relayList.length === 0 && cache.syncingStage !== SyncStage.SyncFinished) { + this.logger.log(`lnv3 [${transfer.chainConfig.code}->] sync status finished`); + cache.syncingStage = SyncStage.SyncFinished; } } catch (error) { this.logger.warn(`batch fetch lnv3 status failed, error ${error}`); @@ -484,6 +562,11 @@ export class Lnv3Service implements OnModuleInit { } async fetchStatuses(transfer: PartnerT2, index: number) { + for (const cache of this.fetchCache) { + if (cache.syncingStage !== SyncStage.SyncFinished) { + return; + } + } const skips = this.skip.filter((s) => s.fromChain === transfer.chainConfig.code); for (const skip of skips) { await this.fetchStatus(transfer, index, skip); diff --git a/apollo/src/lnv3/source/envio.service.ts b/apollo/src/lnv3/source/envio.service.ts index f233f53..57cd2d6 100644 --- a/apollo/src/lnv3/source/envio.service.ts +++ b/apollo/src/lnv3/source/envio.service.ts @@ -8,13 +8,22 @@ import { } from './source.service'; export class Lnv3EnvioService extends SourceService { - async queryRecordInfo(url: string, chainId: number, latestNonce: number): Promise { - const query = `query { Lnv3TransferRecord(limit: 20, order_by: { nonce: asc }, offset: ${latestNonce}, where: {localChainId: {_eq: ${chainId}}}) { id, nonce, messageNonce, remoteChainId, provider, sourceToken, targetToken, sourceAmount, targetAmount, sender, receiver, timestamp, transactionHash, fee, transferId, hasWithdrawn } }`; + async queryRecordInfo( + url: string, + chainId: number, + latestNonce: number, + limit: number + ): Promise { + const query = `query { Lnv3TransferRecord(limit: ${limit}, order_by: { nonce: asc }, offset: ${latestNonce}, where: {localChainId: {_eq: ${chainId}}}) { id, nonce, messageNonce, remoteChainId, provider, sourceToken, targetToken, sourceAmount, targetAmount, sender, receiver, timestamp, transactionHash, fee, transferId, hasWithdrawn } }`; return await axios - .post(url, { - query: query, - variables: null, - }) + .post( + url, + { + query: query, + variables: null, + }, + { timeout: 10000 } + ) .then((res) => res.data?.data?.Lnv3TransferRecord); } @@ -25,10 +34,14 @@ export class Lnv3EnvioService extends SourceService { ): Promise { const query = `query { Lnv3RelayUpdateRecord(limit: 20, order_by: { nonce: asc }, offset: ${latestNonce}, where: {localChainId: {_eq: ${chainId}}}) { id, updateType, remoteChainId, provider, transactionHash, timestamp, sourceToken, targetToken, penalty, baseFee, liquidityFeeRate, transferLimit, paused } }`; return await axios - .post(url, { - query: query, - variables: null, - }) + .post( + url, + { + query: query, + variables: null, + }, + { timeout: 10000 } + ) .then((res) => res.data?.data?.Lnv3RelayUpdateRecord); } async queryRelayStatus( @@ -38,10 +51,14 @@ export class Lnv3EnvioService extends SourceService { ): Promise { const query = `query { Lnv3RelayRecord(where: { id: { _eq: "${transferId}" }, localChainId: {_eq: ${chainId}}}) { id, relayer, timestamp, transactionHash, slashed, requestWithdrawTimestamp, fee }}`; return await axios - .post(url, { - query: query, - variables: null, - }) + .post( + url, + { + query: query, + variables: null, + }, + { timeout: 10000 } + ) .then((res) => res.data?.data?.Lnv3RelayRecord?.[0]); } async queryMultiRelayStatus( @@ -50,25 +67,34 @@ export class Lnv3EnvioService extends SourceService { transferIds: string[] ): Promise { const idArray = '["' + transferIds.join('","') + '"]'; - const query = `query { Lnv3RelayRecord(limit: 20, where: {id: { _in: ${idArray}}, localChainId: {_eq: ${chainId}}}) { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }`; + const query = `query { Lnv3RelayRecord(limit: 50, where: {id: { _in: ${idArray}}, localChainId: {_eq: ${chainId}}}) { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }`; return await axios - .post(url, { - query: query, - variables: null, - }) + .post( + url, + { + query: query, + variables: null, + }, + { timeout: 10000 } + ) .then((res) => res.data?.data?.Lnv3RelayRecord); } async batchQueryRelayStatus( url: string, chainId: number, - latestTimestamp: number + cursor: bigint, + limit: number ): Promise { - const query = `query { Lnv3RelayRecord(limit: 20, order_by: { timestamp: asc }, where: { timestamp: { _gt: ${latestTimestamp}}, localChainId: {_eq: ${chainId}}, slashed: { _eq: false }}) { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }`; + const query = `query { Lnv3RelayRecord(limit: ${limit}, order_by: { timestamp: asc }, offset: ${cursor}, where: { localChainId: {_eq: ${chainId}}, slashed: { _eq: false }}) { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }`; return await axios - .post(url, { - query: query, - variables: null, - }) + .post( + url, + { + query: query, + variables: null, + }, + { timeout: 10000 } + ) .then((res) => res.data?.data?.Lnv3RelayRecord); } async queryWithdrawStatus( @@ -78,10 +104,14 @@ export class Lnv3EnvioService extends SourceService { ): Promise { const query = `query { Lnv3TransferRecord(where: { id: { _eq: "${transferId}" }, localChainId: {_eq: ${chainId}}}) { id, remoteChainId, hasWithdrawn }}`; return await axios - .post(url, { - query: query, - variables: null, - }) + .post( + url, + { + query: query, + variables: null, + }, + { timeout: 10000 } + ) .then((res) => res.data?.data?.Lnv3TransferRecord?.[0]); } } diff --git a/apollo/src/lnv3/source/ponder.service.ts b/apollo/src/lnv3/source/ponder.service.ts index 21b6fcc..0359b0c 100644 --- a/apollo/src/lnv3/source/ponder.service.ts +++ b/apollo/src/lnv3/source/ponder.service.ts @@ -8,8 +8,13 @@ import { } from './source.service'; export class Lnv3PonderService extends SourceService { - async queryRecordInfo(url: string, localId: number, latestNonce: number): Promise { - const query = `query { lnv3TransferRecords(limit: 20, orderBy: "nonce", orderDirection: "asc", where: {localChainId: "${localId}", nonce_gt: "${latestNonce}"}) { items { id, nonce, messageNonce, remoteChainId, provider, sourceToken, targetToken, sourceAmount, targetAmount, sender, receiver, timestamp, transactionHash, fee, transferId, hasWithdrawn } }}`; + async queryRecordInfo( + url: string, + localId: number, + latestNonce: number, + limit: number + ): Promise { + const query = `query { lnv3TransferRecords(limit: ${limit}, orderBy: "nonce", orderDirection: "asc", where: {localChainId: "${localId}", nonce_gt: "${latestNonce}"}) { items { id, nonce, messageNonce, remoteChainId, provider, sourceToken, targetToken, sourceAmount, targetAmount, sender, receiver, timestamp, transactionHash, fee, transferId, hasWithdrawn } }}`; return await axios .post(url, { query: query, @@ -51,7 +56,7 @@ export class Lnv3PonderService extends SourceService { localId: number, transferIds: string[] ): Promise { - const query = `query { lnv3RelayRecords(limit: 20, orderBy: "timestamp", orderDirection: "asc", where: {localChainId: "${localId}", id_in: ${transferIds} }) { items { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }}`; + const query = `query { lnv3RelayRecords(limit: 50, orderBy: "timestamp", orderDirection: "asc", where: {localChainId: "${localId}", id_in: ${transferIds} }) { items { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }}`; return await axios .post(url, { query: query, @@ -62,9 +67,10 @@ export class Lnv3PonderService extends SourceService { async batchQueryRelayStatus( url: string, localId: number, - latestTimestamp: number + cursor: bigint, + limit: number ): Promise { - const query = `query { lnv3RelayRecords(limit: 20, orderBy: "timestamp", orderDirection: "asc", where: {localChainId: "${localId}", slashed: false, timestamp_gt: "${latestTimestamp}"}) { items { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }}`; + const query = `query { lnv3RelayRecords(limit: ${limit}, orderBy: "timestamp", orderDirection: "asc", where: {localChainId: "${localId}", slashed: false, nonce_gt: "${cursor}"}) { items { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }}`; return await axios .post(url, { query: query, diff --git a/apollo/src/lnv3/source/source.service.ts b/apollo/src/lnv3/source/source.service.ts index 398867f..cde90ce 100644 --- a/apollo/src/lnv3/source/source.service.ts +++ b/apollo/src/lnv3/source/source.service.ts @@ -53,7 +53,8 @@ export abstract class SourceService { abstract queryRecordInfo( url: string, chainId: number, - latestNonce: number + latestNonce: number, + limit: number ): Promise; abstract queryProviderInfo( url: string, @@ -74,7 +75,8 @@ export abstract class SourceService { abstract batchQueryRelayStatus( url: string, chainId: number, - latestTimestamp: number + cursor: bigint, + limit: number ): Promise; abstract queryWithdrawStatus( url: string, diff --git a/apollo/src/lnv3/source/super.service.ts b/apollo/src/lnv3/source/super.service.ts index 0570195..ed3e31e 100644 --- a/apollo/src/lnv3/source/super.service.ts +++ b/apollo/src/lnv3/source/super.service.ts @@ -8,8 +8,13 @@ import { } from './source.service'; export class Lnv3SuperService extends SourceService { - async queryRecordInfo(url: string, chainId: number, latestNonce: number): Promise { - const query = `query { lnv3TransferRecords(first: 20, orderBy: nonce, orderDirection: asc, skip: ${latestNonce}, where: {localChainId: ${chainId}}) { id, nonce, messageNonce, remoteChainId, provider, sourceToken, targetToken, sourceAmount, targetAmount, sender, receiver, timestamp, transactionHash, fee, transferId, hasWithdrawn } }`; + async queryRecordInfo( + url: string, + chainId: number, + latestNonce: number, + limit: number + ): Promise { + const query = `query { lnv3TransferRecords(first: ${limit}, orderBy: nonce, orderDirection: asc, skip: ${latestNonce}, where: {localChainId: ${chainId}}) { id, nonce, messageNonce, remoteChainId, provider, sourceToken, targetToken, sourceAmount, targetAmount, sender, receiver, timestamp, transactionHash, fee, transferId, hasWithdrawn } }`; return await axios .post( url, @@ -62,7 +67,7 @@ export class Lnv3SuperService extends SourceService { transferIds: string[] ): Promise { const idArray = '["' + transferIds.join('","') + '"]'; - const query = `query { lnv3RelayRecords(first: 20, where: {id_in: ${idArray}, localChainId: ${chainId}}) { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }`; + const query = `query { lnv3RelayRecords(first: 50, where: {id_in: ${idArray}, localChainId: ${chainId}}) { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }`; return await axios .post( url, @@ -77,9 +82,10 @@ export class Lnv3SuperService extends SourceService { async batchQueryRelayStatus( url: string, chainId: number, - latestTimestamp: number + cursor: bigint, + limit: number ): Promise { - const query = `query { lnv3RelayRecords(first: 20, orderBy: timestamp, orderDirection: asc, where: {timestamp_gt: ${latestTimestamp}, localChainId: ${chainId}, slashed: false}) { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }`; + const query = `query { lnv3RelayRecords(first: ${limit}, skip: ${cursor}, orderBy: timestamp, orderDirection: asc, where: {localChainId: ${chainId}, slashed: false}) { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }`; return await axios .post( diff --git a/apollo/src/lnv3/source/thegraph.service.ts b/apollo/src/lnv3/source/thegraph.service.ts index 9ce0c80..5343531 100644 --- a/apollo/src/lnv3/source/thegraph.service.ts +++ b/apollo/src/lnv3/source/thegraph.service.ts @@ -8,13 +8,22 @@ import { } from './source.service'; export class Lnv3ThegraphService extends SourceService { - async queryRecordInfo(url: string, chainId: number, latestNonce: number): Promise { - const query = `query { lnv3TransferRecords(first: 20, orderBy: nonce, orderDirection: asc, skip: ${latestNonce}) { id, nonce, messageNonce, remoteChainId, provider, sourceToken, targetToken, sourceAmount, targetAmount, sender, receiver, timestamp, transactionHash, fee, transferId, hasWithdrawn } }`; + async queryRecordInfo( + url: string, + chainId: number, + latestNonce: number, + limit: number + ): Promise { + const query = `query { lnv3TransferRecords(first: ${limit}, orderBy: nonce, orderDirection: asc, skip: ${latestNonce}) { id, nonce, messageNonce, remoteChainId, provider, sourceToken, targetToken, sourceAmount, targetAmount, sender, receiver, timestamp, transactionHash, fee, transferId, hasWithdrawn } }`; return await axios - .post(url, { - query: query, - variables: null, - }) + .post( + url, + { + query: query, + variables: null, + }, + { timeout: 10000 } + ) .then((res) => res.data?.data?.lnv3TransferRecords); } @@ -25,10 +34,14 @@ export class Lnv3ThegraphService extends SourceService { ): Promise { const query = `query { lnv3RelayUpdateRecords(first: 20, orderBy: nonce, orderDirection: asc, skip: ${latestNonce}) { id, updateType, remoteChainId, provider, transactionHash, timestamp, sourceToken, targetToken, penalty, baseFee, liquidityFeeRate, transferLimit, paused } }`; return await axios - .post(url, { - query: query, - variables: null, - }) + .post( + url, + { + query: query, + variables: null, + }, + { timeout: 10000 } + ) .then((res) => res.data?.data?.lnv3RelayUpdateRecords); } async queryRelayStatus( @@ -38,10 +51,14 @@ export class Lnv3ThegraphService extends SourceService { ): Promise { const query = `query { lnv3RelayRecord(id: "${transferId}") { id, relayer, timestamp, transactionHash, slashed, requestWithdrawTimestamp, fee }}`; return await axios - .post(url, { - query: query, - variables: null, - }) + .post( + url, + { + query: query, + variables: null, + }, + { timeout: 10000 } + ) .then((res) => res.data?.data?.lnv3RelayRecord); } async queryMultiRelayStatus( @@ -50,25 +67,34 @@ export class Lnv3ThegraphService extends SourceService { transferIds: string[] ): Promise { const idArray = '["' + transferIds.join('","') + '"]'; - const query = `query { lnv3RelayRecords(first: 20, where: {id_in: ${idArray}}) { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }`; + const query = `query { lnv3RelayRecords(first: 50, where: {id_in: ${idArray}}) { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }`; return await axios - .post(url, { - query: query, - variables: null, - }) + .post( + url, + { + query: query, + variables: null, + }, + { timeout: 10000 } + ) .then((res) => res.data?.data?.lnv3RelayRecords); } async batchQueryRelayStatus( url: string, chainId: number, - latestTimestamp: number + cursor: bigint, + limit: number ): Promise { - const query = `query { lnv3RelayRecords(first: 20, orderBy: timestamp, orderDirection: asc, where: {timestamp_gt: "${latestTimestamp}", slashed: false}) { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }`; + const query = `query { lnv3RelayRecords(first: ${limit}, skip: ${cursor}, orderBy: timestamp, orderDirection: asc, where: {slashed: false}) { id, timestamp, requestWithdrawTimestamp, relayer, transactionHash, slashed, fee } }`; return await axios - .post(url, { - query: query, - variables: null, - }) + .post( + url, + { + query: query, + variables: null, + }, + { timeout: 10000 } + ) .then((res) => res.data?.data?.lnv3RelayRecords); } async queryWithdrawStatus( @@ -78,10 +104,14 @@ export class Lnv3ThegraphService extends SourceService { ): Promise { const query = `query { lnv3TransferRecord(id: "${transferId}") { id, remoteChainId, hasWithdrawn }}`; return await axios - .post(url, { - query: query, - variables: null, - }) + .post( + url, + { + query: query, + variables: null, + }, + { timeout: 10000 } + ) .then((res) => res.data?.data?.lnv3TransferRecord); } } diff --git a/apollo/src/lnv3/transfer.service.ts b/apollo/src/lnv3/transfer.service.ts index 1c77638..b2bcebd 100644 --- a/apollo/src/lnv3/transfer.service.ts +++ b/apollo/src/lnv3/transfer.service.ts @@ -36,6 +36,10 @@ export class TransferService extends BaseTransferServiceT2 { indexerType: Level0IndexerType.thegraph, url: this.polygonEndpoint, }, + { + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, + }, { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, @@ -53,6 +57,10 @@ export class TransferService extends BaseTransferServiceT2 { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, + { + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, + }, ], chainConfig: HelixChain.arbitrum, }, @@ -79,6 +87,10 @@ export class TransferService extends BaseTransferServiceT2 { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, + { + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, + }, ], chainConfig: HelixChain.linea, }, @@ -92,6 +104,10 @@ export class TransferService extends BaseTransferServiceT2 { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, + { + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, + }, ], chainConfig: HelixChain.op, }, @@ -105,6 +121,10 @@ export class TransferService extends BaseTransferServiceT2 { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, + { + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, + }, ], chainConfig: HelixChain.gnosis, }, @@ -118,6 +138,10 @@ export class TransferService extends BaseTransferServiceT2 { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, + { + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, + }, ], chainConfig: HelixChain.mantle, }, @@ -131,6 +155,10 @@ export class TransferService extends BaseTransferServiceT2 { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, + { + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, + }, ], chainConfig: HelixChain.scroll, }, @@ -179,6 +207,10 @@ export class TransferService extends BaseTransferServiceT2 { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, + { + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, + }, ], chainConfig: HelixChain.moonbeam, }, @@ -214,6 +246,10 @@ export class TransferService extends BaseTransferServiceT2 { indexerType: Level0IndexerType.thegraph, url: this.zircuitEndpoint, }, + { + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, + }, ], chainConfig: HelixChain.zircuit, }, From e8e0321d20fcd220406f315ee740ea59b0f1b694 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Tue, 15 Oct 2024 21:49:13 +0800 Subject: [PATCH 2/3] speed up withdrawLiquidity --- apollo/src/lnv3/lnv3.service.ts | 9 --- apollo/src/lnv3/transfer.service.ts | 96 ++++++++++++++--------------- 2 files changed, 48 insertions(+), 57 deletions(-) diff --git a/apollo/src/lnv3/lnv3.service.ts b/apollo/src/lnv3/lnv3.service.ts index 3ffaca8..e43f1b9 100644 --- a/apollo/src/lnv3/lnv3.service.ts +++ b/apollo/src/lnv3/lnv3.service.ts @@ -48,7 +48,6 @@ export class Lnv3Service implements OnModuleInit { private fetchCache = new Array(this.transferService.transfers.length).fill('').map((_) => ({ latestRelayerInfoNonce: -1, isSyncingHistory: false, - waitingWithdrawInterval: 0, waitingWithdrawRecords: [], fetchProviderInfoInterval: 0, syncingStage: SyncStage.SyncRecord, @@ -75,7 +74,6 @@ export class Lnv3Service implements OnModuleInit { async onModuleInit() { this.transferService.transfers.forEach((item, index) => { - this.fetchCache[index].waitingWithdrawInterval = index * 3; this.fetchCache[index].fetchProviderInfoInterval = index; this.taskService.addInterval( `${item.chainConfig.code}-lnv3-fetch_history_data`, @@ -494,13 +492,6 @@ export class Lnv3Service implements OnModuleInit { } async fetchWithdrawCacheStatus(transfer: PartnerT2, index: number) { - const cache = this.fetchCache[index]; - cache.waitingWithdrawInterval += 1; - if (cache.waitingWithdrawInterval < 6) { - return; - } - cache.waitingWithdrawInterval = 0; - const records = await this.aggregationService .queryHistoryRecords({ skip: this.skipForWithdrawLiquidity[index], diff --git a/apollo/src/lnv3/transfer.service.ts b/apollo/src/lnv3/transfer.service.ts index b2bcebd..bf2ae7a 100644 --- a/apollo/src/lnv3/transfer.service.ts +++ b/apollo/src/lnv3/transfer.service.ts @@ -32,10 +32,6 @@ export class TransferService extends BaseTransferServiceT2 { formalChainTransfers: PartnerT2[] = [ { level0Indexers: [ - { - indexerType: Level0IndexerType.thegraph, - url: this.polygonEndpoint, - }, { indexerType: Level0IndexerType.superindex, url: this.superindexEndpoint, @@ -44,52 +40,56 @@ export class TransferService extends BaseTransferServiceT2 { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, + { + indexerType: Level0IndexerType.thegraph, + url: this.polygonEndpoint, + }, ], chainConfig: HelixChain.polygon, }, { level0Indexers: [ { - indexerType: Level0IndexerType.thegraph, - url: this.arbitrumEndpoint, + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, }, { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, { - indexerType: Level0IndexerType.superindex, - url: this.superindexEndpoint, + indexerType: Level0IndexerType.thegraph, + url: this.arbitrumEndpoint, }, ], chainConfig: HelixChain.arbitrum, }, { level0Indexers: [ - { - indexerType: Level0IndexerType.thegraph, - url: this.bscEndpoint, - }, { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, + { + indexerType: Level0IndexerType.thegraph, + url: this.bscEndpoint, + }, ], chainConfig: HelixChain.bsc, }, { level0Indexers: [ { - indexerType: Level0IndexerType.thegraph, - url: this.lineaEndpoint, + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, }, { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, { - indexerType: Level0IndexerType.superindex, - url: this.superindexEndpoint, + indexerType: Level0IndexerType.thegraph, + url: this.lineaEndpoint, }, ], chainConfig: HelixChain.linea, @@ -97,16 +97,16 @@ export class TransferService extends BaseTransferServiceT2 { { level0Indexers: [ { - indexerType: Level0IndexerType.thegraph, - url: this.opEndpoint, + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, }, { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, { - indexerType: Level0IndexerType.superindex, - url: this.superindexEndpoint, + indexerType: Level0IndexerType.thegraph, + url: this.opEndpoint, }, ], chainConfig: HelixChain.op, @@ -114,16 +114,16 @@ export class TransferService extends BaseTransferServiceT2 { { level0Indexers: [ { - indexerType: Level0IndexerType.thegraph, - url: this.gnosisEndpoint, + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, }, { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, { - indexerType: Level0IndexerType.superindex, - url: this.superindexEndpoint, + indexerType: Level0IndexerType.thegraph, + url: this.gnosisEndpoint, }, ], chainConfig: HelixChain.gnosis, @@ -131,16 +131,16 @@ export class TransferService extends BaseTransferServiceT2 { { level0Indexers: [ { - indexerType: Level0IndexerType.thegraph, - url: this.mantleEndpoint, + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, }, { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, { - indexerType: Level0IndexerType.superindex, - url: this.superindexEndpoint, + indexerType: Level0IndexerType.thegraph, + url: this.mantleEndpoint, }, ], chainConfig: HelixChain.mantle, @@ -148,26 +148,22 @@ export class TransferService extends BaseTransferServiceT2 { { level0Indexers: [ { - indexerType: Level0IndexerType.thegraph, - url: this.scrollEndpoint, + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, }, { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, { - indexerType: Level0IndexerType.superindex, - url: this.superindexEndpoint, + indexerType: Level0IndexerType.thegraph, + url: this.scrollEndpoint, }, ], chainConfig: HelixChain.scroll, }, { level0Indexers: [ - { - indexerType: Level0IndexerType.thegraph, - url: this.darwiniaEndpoint, - }, { indexerType: Level0IndexerType.superindex, url: this.superindexEndpoint, @@ -176,6 +172,10 @@ export class TransferService extends BaseTransferServiceT2 { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, + { + indexerType: Level0IndexerType.thegraph, + url: this.darwiniaEndpoint, + }, ], chainConfig: HelixChain.darwiniaDvm, }, @@ -200,16 +200,16 @@ export class TransferService extends BaseTransferServiceT2 { { level0Indexers: [ { - indexerType: Level0IndexerType.thegraph, - url: this.moonbeamEndpoint, + indexerType: Level0IndexerType.superindex, + url: this.superindexEndpoint, }, { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, { - indexerType: Level0IndexerType.superindex, - url: this.superindexEndpoint, + indexerType: Level0IndexerType.thegraph, + url: this.moonbeamEndpoint, }, ], chainConfig: HelixChain.moonbeam, @@ -225,10 +225,6 @@ export class TransferService extends BaseTransferServiceT2 { }, { level0Indexers: [ - { - indexerType: Level0IndexerType.thegraph, - url: this.baseEndpoint, - }, { indexerType: Level0IndexerType.superindex, url: this.superindexEndpoint, @@ -237,19 +233,23 @@ export class TransferService extends BaseTransferServiceT2 { indexerType: Level0IndexerType.envio, url: this.dnvioEndpoint, }, + { + indexerType: Level0IndexerType.thegraph, + url: this.baseEndpoint, + }, ], chainConfig: HelixChain.base, }, { level0Indexers: [ - { - indexerType: Level0IndexerType.thegraph, - url: this.zircuitEndpoint, - }, { indexerType: Level0IndexerType.superindex, url: this.superindexEndpoint, }, + { + indexerType: Level0IndexerType.thegraph, + url: this.zircuitEndpoint, + }, ], chainConfig: HelixChain.zircuit, }, From f24a9bf2257a2fdf4d4888b0b6832062147585e8 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Wed, 16 Oct 2024 13:29:41 +0800 Subject: [PATCH 3/3] rmv unused --- apollo/src/lnv3/lnv3.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apollo/src/lnv3/lnv3.service.ts b/apollo/src/lnv3/lnv3.service.ts index e43f1b9..3acc7b5 100644 --- a/apollo/src/lnv3/lnv3.service.ts +++ b/apollo/src/lnv3/lnv3.service.ts @@ -475,7 +475,6 @@ export class Lnv3Service implements OnModuleInit { const cache = this.fetchCache[index]; const limit = cache.syncingStage === SyncStage.SyncFinished ? 10 : 500; const relayList = await this.queryFillInfos(transfer, limit); - let size = 0; for (const relayInfo of relayList) { if (relayInfo.records && relayInfo.records.length > 0) { await this.saveRelayInfo(transfer, relayInfo);