diff --git a/ci/config.json.ci b/ci/config.json.ci index 509b2875d..3d8d26414 100644 --- a/ci/config.json.ci +++ b/ci/config.json.ci @@ -342,7 +342,9 @@ }, "jobUpdateAssets": { "millisecondRepeatJob": 10000, - "lcdRecordGet": 5 + "lcdRecordGet": 5, + "key": "jobUpdateAssets", + "blocksPerCall": 1000 }, "jobCreateConstraintInTransactionMessagePartition": { "jobRepeatCheckNeedCreateConstraint": { diff --git a/config.json b/config.json index ec160885c..488ed14bb 100644 --- a/config.json +++ b/config.json @@ -326,7 +326,9 @@ }, "jobUpdateAssets": { "millisecondRepeatJob": 10000, - "lcdRecordGet": 5 + "lcdRecordGet": 5, + "key": "jobUpdateAssets", + "blocksPerCall": 1000 }, "uploadBlockRawLogToS3": { "key": "uploadBlockRawLogToS3", diff --git a/src/services/evm/constant.ts b/src/services/evm/constant.ts index 5bf3b6203..2fff47623 100644 --- a/src/services/evm/constant.ts +++ b/src/services/evm/constant.ts @@ -295,6 +295,7 @@ export const BULL_JOB_NAME = { REINDEX_ERC20: 'reindex:erc20', REFRESH_ERC721_HOLDER_STATISTIC: 'refresh:erc721-holder-statistic', CRAWL_EVM_ACCOUNT_PUBKEY: 'crawl:evm-account-pubkey', + UPDATE_EVM_ASSETS: 'update:evm-assets', }; export const MSG_TYPE = { diff --git a/src/services/evm/update_assets.service.ts b/src/services/evm/update_assets.service.ts index c356fe073..6f5a845a8 100644 --- a/src/services/evm/update_assets.service.ts +++ b/src/services/evm/update_assets.service.ts @@ -5,6 +5,8 @@ import BullableService, { QueueHandler } from '../../base/bullable.service'; import { BULL_JOB_NAME, SERVICE } from './constant'; import { Asset } from '../../models/asset'; import { Erc20Contract } from '../../models/erc20_contract'; +import { BlockCheckpoint } from '../../models'; +import knex from '../../common/utils/db_connection'; @Service({ name: SERVICE.V1.JobService.UpdateEvmAssets.key, @@ -20,7 +22,15 @@ export default class UpdateEvmAssetsJob extends BullableService { jobName: BULL_JOB_NAME.JOB_UPDATE_EVM_ASSETS, }) async jobUpdateEvmAssets() { - const erc20Assets = await Erc20Contract.query(); + const [startBlock, endBlock, updateBlockCheckpoint] = + await BlockCheckpoint.getCheckpoint( + BULL_JOB_NAME.UPDATE_EVM_ASSETS, + [BULL_JOB_NAME.HANDLE_ERC20_BALANCE], + config.jobUpdateAssets.key + ); + const erc20Assets = await Erc20Contract.query() + .where('last_updated_height', '>', startBlock) + .andWhere('last_updated_height', '<=', endBlock); const assets: Asset[] = []; assets.push( ...erc20Assets.map((erc20Asset) => @@ -35,9 +45,21 @@ export default class UpdateEvmAssetsJob extends BullableService { }) ) ); - if (assets.length > 0) { - await Asset.query().insert(assets).onConflict('denom').merge(); - } + await knex.transaction(async (trx) => { + if (assets.length > 0) { + await Asset.query() + .insert(assets) + .onConflict('denom') + .merge() + .transacting(trx); + } + updateBlockCheckpoint.height = endBlock; + await BlockCheckpoint.query() + .insert(updateBlockCheckpoint) + .onConflict('job_name') + .merge() + .transacting(trx); + }); } public async _start(): Promise {