diff --git a/ci/config.json.ci b/ci/config.json.ci index 2d45f8148..375a7685c 100644 --- a/ci/config.json.ci +++ b/ci/config.json.ci @@ -468,7 +468,8 @@ }, "transport": { "batchSize": 10, - "waitMilisecond": 1000 + "waitMilisecond": 1000, + "timeout": 10000 } }, "crawlEvmAccount": { diff --git a/config.json b/config.json index 9e06de7bb..3fadf5a8c 100644 --- a/config.json +++ b/config.json @@ -466,7 +466,8 @@ }, "transport": { "batchSize": 10, - "waitMilisecond": 1000 + "waitMilisecond": 1000, + "timeout": 10000 } }, "crawlEvmAccount": { diff --git a/migrations/20240909092417_create_index_validator.ts b/migrations/20240909092417_create_index_validator.ts new file mode 100644 index 000000000..ed7e24230 --- /dev/null +++ b/migrations/20240909092417_create_index_validator.ts @@ -0,0 +1,15 @@ +import { Knex } from 'knex'; + +export async function up(knex: Knex): Promise { + await knex.schema.alterTable('validator', (table) => { + table.index('tokens'); + table.index('status'); + }); +} + +export async function down(knex: Knex): Promise { + await knex.schema.alterTable('validator', (table) => { + table.dropIndex('tokens'); + table.dropIndex('status'); + }); +} diff --git a/migrations/20240327075001_evm_internal_transaction.ts b/migrations/evm/20240327075001_evm_internal_transaction.ts similarity index 88% rename from migrations/20240327075001_evm_internal_transaction.ts rename to migrations/evm/20240327075001_evm_internal_transaction.ts index b0c5be09b..6898117af 100644 --- a/migrations/20240327075001_evm_internal_transaction.ts +++ b/migrations/evm/20240327075001_evm_internal_transaction.ts @@ -1,5 +1,5 @@ import { Knex } from 'knex'; -import { EvmInternalTransaction } from '../src/models/evm_internal_transaction'; +import { EvmInternalTransaction } from '../../src/models/evm_internal_transaction'; export async function up(knex: Knex): Promise { await knex.schema.createTable(EvmInternalTransaction.tableName, (table) => { diff --git a/migrations/evm/20240909092542_create_index_miner_in_evm_block.ts b/migrations/evm/20240909092542_create_index_miner_in_evm_block.ts new file mode 100644 index 000000000..18865d2af --- /dev/null +++ b/migrations/evm/20240909092542_create_index_miner_in_evm_block.ts @@ -0,0 +1,13 @@ +import { Knex } from 'knex'; + +export async function up(knex: Knex): Promise { + await knex.schema.alterTable('evm_block', (table) => { + table.index('miner'); + }); +} + +export async function down(knex: Knex): Promise { + await knex.schema.alterTable('evm_block', (table) => { + table.dropIndex('miner'); + }); +} diff --git a/src/common/utils/etherjs_client.ts b/src/common/utils/etherjs_client.ts index 3207457ad..94dac2ac8 100644 --- a/src/common/utils/etherjs_client.ts +++ b/src/common/utils/etherjs_client.ts @@ -27,6 +27,7 @@ export function getViemClient(chainId?: string): PublicClient { batchSize: config.viemConfig.transport.batchSize, wait: config.viemConfig.transport.waitMilisecond, }, + timeout: config.viemConfig.transport.timeout, }), }).extend(publicActionsL1()); viemClientMapping.set(chainId ?? config.chainId, viemClient); diff --git a/src/models/evm_transaction.ts b/src/models/evm_transaction.ts index 477205141..7970b852c 100644 --- a/src/models/evm_transaction.ts +++ b/src/models/evm_transaction.ts @@ -65,9 +65,8 @@ export class EVMTransaction extends BaseModel { static get jsonSchema() { return { type: 'object', - required: ['hash', 'height'], + required: ['height'], properties: { - hash: { type: 'string' }, height: { type: 'number' }, }, }; diff --git a/src/services/evm/crawl_evm_account.service.ts b/src/services/evm/crawl_evm_account.service.ts index 8a327c832..2cb8b5b8b 100644 --- a/src/services/evm/crawl_evm_account.service.ts +++ b/src/services/evm/crawl_evm_account.service.ts @@ -70,7 +70,7 @@ export default class CrawlEvmAccountService extends BullableService { BULL_JOB_NAME.CRAWL_EVM_TRANSACTION, BULL_JOB_NAME.EVM_CRAWL_INTERNAL_TX, ], - config.evmCrawlInternalTx.key + config.crawlEvmAccount.key ); this.logger.info( `Crawl evm_account from block ${startBlock} to ${endBlock}` diff --git a/src/services/evm/crawl_evm_proxy_history.service.ts b/src/services/evm/crawl_evm_proxy_history.service.ts index 29d771889..4cb8097b6 100644 --- a/src/services/evm/crawl_evm_proxy_history.service.ts +++ b/src/services/evm/crawl_evm_proxy_history.service.ts @@ -78,6 +78,7 @@ export default class CrawlProxyContractEVMService extends BullableService { .where('block_height', '>', startBlock) .andWhere('block_height', '<=', endBlock) .select('address', 'topic0', 'topic1', 'block_height', 'tx_hash'); + const distictAddresses = _.uniq(evmEvents.map((e) => e.address)); const proxyContractDb = await EVMSmartContract.query() .whereIn('type', [ EVMSmartContract.TYPES.PROXY_EIP_1967, @@ -86,8 +87,8 @@ export default class CrawlProxyContractEVMService extends BullableService { EVMSmartContract.TYPES.PROXY_EIP_1167, EVMSmartContract.TYPES.PROXY_EIP_1967_BEACON, ]) + .andWhere('address', 'in', distictAddresses) .select('address'); - const distictAddresses = _.uniq(evmEvents.map((e) => e.address)); const batchReqs: any[] = []; distictAddresses.forEach((address) => { batchReqs.push( @@ -190,7 +191,7 @@ export default class CrawlProxyContractEVMService extends BullableService { ) { newProxyContractsToSave.push(proxyHistory); } else { - this.logger.warn( + this.logger.debug( `This contract address ${proxyHistory.proxy_contract} is not proxy, at tx hash ${proxyHistory.tx_hash}` ); } diff --git a/test/unit/services/erc721/erc721_handler.spec.ts b/test/unit/services/erc721/erc721_handler.spec.ts index f02644e7a..c0d946133 100644 --- a/test/unit/services/erc721/erc721_handler.spec.ts +++ b/test/unit/services/erc721/erc721_handler.spec.ts @@ -1,5 +1,6 @@ import { BeforeAll, Describe, Test } from '@jest-decorated/core'; import { ServiceBroker } from 'moleculer'; +import { bytesToHex, hexToBytes } from 'viem'; import config from '../../../../config.json' assert { type: 'json' }; import knex from '../../../../src/common/utils/db_connection'; import { @@ -42,11 +43,12 @@ export default class Erc721HandlerTest { evmTx = EVMTransaction.fromJson({ id: 11111, - hash: '', + hash: hexToBytes( + '0x3faac2ed3ca031892c04598177f7c36e9fdcdf2fb3b6c4a13c520590facb82ef' + ), height: 111, tx_msg_id: 222, tx_id: 223, - contract_address: '', index: 1, }); @@ -100,7 +102,7 @@ export default class Erc721HandlerTest { address: this.evmSmartContract.address, evm_tx_id: this.evmTx.id, tx_id: 1234, - tx_hash: this.evmTx.hash, + tx_hash: bytesToHex(this.evmTx.hash), tx_index: 1, }), EvmEvent.fromJson({ @@ -119,7 +121,7 @@ export default class Erc721HandlerTest { address: this.evmSmartContract.address, evm_tx_id: this.evmTx.id, tx_id: 1234, - tx_hash: this.evmTx.hash, + tx_hash: bytesToHex(this.evmTx.hash), tx_index: 1, }), EvmEvent.fromJson({ @@ -138,7 +140,7 @@ export default class Erc721HandlerTest { address: this.evmSmartContract2.address, evm_tx_id: this.evmTx.id, tx_id: 1234, - tx_hash: this.evmTx.hash, + tx_hash: bytesToHex(this.evmTx.hash), tx_index: 1, }), EvmEvent.fromJson({ @@ -157,7 +159,7 @@ export default class Erc721HandlerTest { address: this.evmSmartContract.address, evm_tx_id: this.evmTx.id, tx_id: 1234, - tx_hash: this.evmTx.hash, + tx_hash: bytesToHex(this.evmTx.hash), tx_index: 1, }), ]; diff --git a/test/unit/services/evm/erc20_handler.spec.ts b/test/unit/services/evm/erc20_handler.spec.ts index ef92dbf97..00a7281d0 100644 --- a/test/unit/services/evm/erc20_handler.spec.ts +++ b/test/unit/services/evm/erc20_handler.spec.ts @@ -1,7 +1,7 @@ import { AfterAll, BeforeAll, Describe, Test } from '@jest-decorated/core'; import _ from 'lodash'; import { ServiceBroker } from 'moleculer'; -import { decodeAbiParameters, toHex } from 'viem'; +import { decodeAbiParameters, hexToBytes, toHex } from 'viem'; import knex from '../../../../src/common/utils/db_connection'; import { getViemClient } from '../../../../src/common/utils/etherjs_client'; import { @@ -111,7 +111,9 @@ const erc20Contract = Erc20Contract.fromJson({ }); const evmTransaction = EVMTransaction.fromJson({ id: 2931, - hash: '0xf15467ec2a25eeef95798d93c2fe9ed8e7c891578b8e1bcc3284105849656c9d', + hash: hexToBytes( + '0xf15467ec2a25eeef95798d93c2fe9ed8e7c891578b8e1bcc3284105849656c9d' + ), height: 1, tx_id: 1612438, tx_msg_id: 4752908, diff --git a/test/unit/services/evm/erc20_reindex.spec.ts b/test/unit/services/evm/erc20_reindex.spec.ts index ef92dbf97..00a7281d0 100644 --- a/test/unit/services/evm/erc20_reindex.spec.ts +++ b/test/unit/services/evm/erc20_reindex.spec.ts @@ -1,7 +1,7 @@ import { AfterAll, BeforeAll, Describe, Test } from '@jest-decorated/core'; import _ from 'lodash'; import { ServiceBroker } from 'moleculer'; -import { decodeAbiParameters, toHex } from 'viem'; +import { decodeAbiParameters, hexToBytes, toHex } from 'viem'; import knex from '../../../../src/common/utils/db_connection'; import { getViemClient } from '../../../../src/common/utils/etherjs_client'; import { @@ -111,7 +111,9 @@ const erc20Contract = Erc20Contract.fromJson({ }); const evmTransaction = EVMTransaction.fromJson({ id: 2931, - hash: '0xf15467ec2a25eeef95798d93c2fe9ed8e7c891578b8e1bcc3284105849656c9d', + hash: hexToBytes( + '0xf15467ec2a25eeef95798d93c2fe9ed8e7c891578b8e1bcc3284105849656c9d' + ), height: 1, tx_id: 1612438, tx_msg_id: 4752908,