diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6259350..4c2bd19 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -51,24 +51,24 @@ jobs: ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}/apollo:${{ steps.tag-name.outputs.tag }} ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}/apollo:latest - - name: Build ponder with sha - uses: docker/build-push-action@v3 - with: - push: true - context: ponder/lnv3 - tags: | - ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}/ponder:sha-${{ steps.short-sha.outputs.sha }} - ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}/ponder:staging + # - name: Build ponder with sha + # uses: docker/build-push-action@v3 + # with: + # push: true + # context: ponder/lnv3 + # tags: | + # ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}/ponder:sha-${{ steps.short-sha.outputs.sha }} + # ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}/ponder:staging - - name: Build ponder with tag - uses: docker/build-push-action@v3 - if: startsWith(github.ref, 'refs/tags/v') - with: - push: true - context: ponder/lnv3 - tags: | - ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}/ponder:${{ steps.tag-name.outputs.tag }} - ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}/ponder:latest + # - name: Build ponder with tag + # uses: docker/build-push-action@v3 + # if: startsWith(github.ref, 'refs/tags/v') + # with: + # push: true + # context: ponder/lnv3 + # tags: | + # ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}/ponder:${{ steps.tag-name.outputs.tag }} + # ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}/ponder:latest # deploy-railway: # name: Deploy railway diff --git a/apollo/src/lnv3/lnv3.service.ts b/apollo/src/lnv3/lnv3.service.ts index 60a3f31..e7d2112 100644 --- a/apollo/src/lnv3/lnv3.service.ts +++ b/apollo/src/lnv3/lnv3.service.ts @@ -34,6 +34,7 @@ export class Lnv3Service implements OnModuleInit { private readonly takeEachTime = 2; private skip = new Array(this.transferService.transfers.length).fill(0); + private skipForWithdrawLiquidity = new Array(this.transferService.transfers.length).fill(0); private sourceServices = new Map(); constructor( @@ -404,7 +405,27 @@ export class Lnv3Service implements OnModuleInit { return; } cache.waitingWithdrawInterval = 0; - const records = cache.waitingWithdrawRecords; + + const records = await this.aggregationService + .queryHistoryRecords({ + skip: this.skipForWithdrawLiquidity[index], + take: this.takeEachTime, + where: { + fromChain: transfer.chainConfig.code, + bridge: `lnv3`, + NOT: { result: RecordStatus.pending }, + needWithdrawLiquidity: true, + endTxHash: '', + }, + }) + .then((result) => result.records); + + if (records.length < this.takeEachTime) { + this.skipForWithdrawLiquidity[index] = 0; + } else { + this.skipForWithdrawLiquidity[index] += this.takeEachTime; + } + const transferIdMap = new Map(); for (const record of records) { const recordSplitted = record.id.split('-'); @@ -443,7 +464,6 @@ export class Lnv3Service implements OnModuleInit { } } } - cache.waitingWithdrawRecords = []; } async fetchStatus(transfer: PartnerT2, index: number) { @@ -455,6 +475,7 @@ export class Lnv3Service implements OnModuleInit { where: { fromChain: transfer.chainConfig.code, bridge: `lnv3`, + result: RecordStatus.pending, endTxHash: '', }, }) @@ -471,104 +492,67 @@ export class Lnv3Service implements OnModuleInit { const recordSplitted = record.id.split('-'); const transferId = last(recordSplitted); const dstChainId = recordSplitted[2]; - - if (record.endTxHash === '') { - // if record.result === RecordStatus.success, it must wait for withdraw liquidity - // then we need to reduce the frequency of requests - // push the request to the cache - if (record.result === RecordStatus.success && record.needWithdrawLiquidity) { - if ( - !this.fetchCache[index].waitingWithdrawRecords.some((item) => item.id === record.id) - ) { - this.fetchCache[index].waitingWithdrawRecords.push(record); + const toChain = this.getDestChain(dstChainId); + const relayRecord = await this.queryRecordRelayStatus(toChain, transferId); + + if (relayRecord) { + let needWithdrawLiquidity = record.needWithdrawLiquidity; + const requestWithdrawTimestamp = Number(relayRecord.requestWithdrawTimestamp); + let endTxHash = record.endTxHash; + if (record.result !== RecordStatus.success) { + const providerId = this.genRelayInfoID( + transfer.chainConfig.id, + toChain.chainConfig.id, + record.relayer, + record.sendTokenAddress + ); + const relayerInfo = await this.aggregationService.queryLnBridgeRelayInfoById({ + id: providerId, + }); + // waiting for relayer info update + if (!relayerInfo) { + this.logger.log( + `lnv3 [${transfer.chainConfig.code}->${toChain.chainConfig.code}] waiting for relayer info update, id: ${providerId}` + ); + continue; } - continue; - } - const toChain = this.getDestChain(dstChainId); - const relayRecord = await this.queryRecordRelayStatus(toChain, transferId); - - if (relayRecord) { - let needWithdrawLiquidity = record.needWithdrawLiquidity; - const requestWithdrawTimestamp = Number(relayRecord.requestWithdrawTimestamp); - let endTxHash = record.endTxHash; - if (record.result !== RecordStatus.success) { - const providerId = this.genRelayInfoID( - transfer.chainConfig.id, - toChain.chainConfig.id, - record.relayer, - record.sendTokenAddress - ); - const relayerInfo = await this.aggregationService.queryLnBridgeRelayInfoById({ - id: providerId, - }); - // waiting for relayer info update - if (!relayerInfo) { - this.logger.log( - `lnv3 [${transfer.chainConfig.code}->${toChain.chainConfig.code}] waiting for relayer info update, id: ${providerId}` - ); - continue; - } - - if (relayRecord.slashed) { - needWithdrawLiquidity = false; - } - if (!needWithdrawLiquidity) { - endTxHash = relayRecord.transactionHash; - } - const updateData = { - result: RecordStatus.success, - responseTxHash: relayRecord.transactionHash, - endTxHash: endTxHash, - endTime: Number(relayRecord.timestamp), - relayer: relayRecord.relayer.toLowerCase(), - needWithdrawLiquidity: needWithdrawLiquidity, - lastRequestWithdraw: requestWithdrawTimestamp, - }; + if (relayRecord.slashed) { + needWithdrawLiquidity = false; + } + if (!needWithdrawLiquidity) { + endTxHash = relayRecord.transactionHash; + } + const updateData = { + result: RecordStatus.success, + responseTxHash: relayRecord.transactionHash, + endTxHash: endTxHash, + endTime: Number(relayRecord.timestamp), + relayer: relayRecord.relayer.toLowerCase(), + needWithdrawLiquidity: needWithdrawLiquidity, + lastRequestWithdraw: requestWithdrawTimestamp, + }; - await this.aggregationService.updateHistoryRecord({ - where: { id: record.id }, - data: updateData, - }); + await this.aggregationService.updateHistoryRecord({ + where: { id: record.id }, + data: updateData, + }); - const cost = relayRecord.slashed ? 0 : relayRecord.fee; - const profit = relayRecord.slashed ? 0 : record.fee; + const cost = relayRecord.slashed ? 0 : relayRecord.fee; + const profit = relayRecord.slashed ? 0 : record.fee; - await this.aggregationService.updateLnBridgeRelayInfo({ - where: { id: providerId }, - data: { - cost: (BigInt(relayerInfo.cost) + BigInt(cost)).toString(), - profit: (BigInt(relayerInfo.profit) + BigInt(profit)).toString(), - }, - }); + await this.aggregationService.updateLnBridgeRelayInfo({ + where: { id: providerId }, + data: { + cost: (BigInt(relayerInfo.cost) + BigInt(cost)).toString(), + profit: (BigInt(relayerInfo.profit) + BigInt(profit)).toString(), + }, + }); - size += 1; - this.logger.log( - `lnv3 [${transfer.chainConfig.code}->${toChain.chainConfig.code}] new status id: ${record.id} relayed responseTxHash: ${relayRecord.transactionHash}` - ); - } - // query withdrawLiquidity result - if (needWithdrawLiquidity && requestWithdrawTimestamp > 0) { - // query result on source - const transferRecord = await this.queryRecordWithdrawStatus(transfer, transferId); - if ( - transferRecord && - (transferRecord.hasWithdrawn || - record.lastRequestWithdraw < requestWithdrawTimestamp) - ) { - await this.aggregationService.updateHistoryRecord({ - where: { id: record.id }, - data: { - needWithdrawLiquidity: !transferRecord.hasWithdrawn, - endTxHash: transferRecord.hasWithdrawn ? record.responseTxHash : '', - lastRequestWithdraw: requestWithdrawTimestamp, - }, - }); - this.logger.log( - `lnv3 [${transfer.chainConfig.code}->${toChain.chainConfig.code}] tx withdrawn id: ${record.id}, time: ${requestWithdrawTimestamp}, done: ${transferRecord.hasWithdrawn}` - ); - } - } + size += 1; + this.logger.log( + `lnv3 [${transfer.chainConfig.code}->${toChain.chainConfig.code}] new status id: ${record.id} relayed responseTxHash: ${relayRecord.transactionHash}` + ); } } } diff --git a/apollo/src/lnv3/transfer.service.ts b/apollo/src/lnv3/transfer.service.ts index e87cbde..d51f13c 100644 --- a/apollo/src/lnv3/transfer.service.ts +++ b/apollo/src/lnv3/transfer.service.ts @@ -245,15 +245,6 @@ export class TransferService extends BaseTransferServiceT2 { ], chainConfig: HelixChain.taikoHekla, }, - { - level0Indexers: [ - { - indexerType: Level0IndexerType.superindex, - url: this.superindexEndpoint, - }, - ], - chainConfig: HelixChain.bera, - }, { level0Indexers: [ { diff --git a/apollo/src/tasks/tasks.service.ts b/apollo/src/tasks/tasks.service.ts index 6f78e27..48af695 100644 --- a/apollo/src/tasks/tasks.service.ts +++ b/apollo/src/tasks/tasks.service.ts @@ -16,7 +16,7 @@ export class TasksService { const callTimes: number = this.healthChecks.get(name); const busy = await callback(); if (!busy) { - this.healthChecks.set(name, callTimes + 1); + this.healthChecks.set(name, callTimes + 1); } }, milliseconds); this.schedulerRegistry.addInterval(name, interval);