From db38bfae069b2bb86a129fe7848f11c315ac7f5c Mon Sep 17 00:00:00 2001 From: Pierre Gee Date: Tue, 19 Sep 2023 09:17:32 +0800 Subject: [PATCH] fix(whale-api): skip null txid used by evmtx (#2148) #### What this PR does / why we need it: - [x] If an EVM tx is found (2 exact vin - both null), skip it - [x] Check how it will impact data representation in DeFiScan (can be done in another PR), vin will be empty as expected #### Which issue(s) does this PR fixes?: Fixes # #### Additional comments?: - Add tests on another PR, test all these change in Changi network concurrently --- apps/whale-api/src/module.indexer/helper.ts | 10 ++++++++++ .../src/module.indexer/model/script.activity.ts | 10 +++++++--- .../src/module.indexer/model/script.aggregation.ts | 9 +++++++-- .../src/module.indexer/model/script.unspent.ts | 9 +++++++-- .../src/module.indexer/model/transaction.vin.ts | 5 ++++- 5 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 apps/whale-api/src/module.indexer/helper.ts diff --git a/apps/whale-api/src/module.indexer/helper.ts b/apps/whale-api/src/module.indexer/helper.ts new file mode 100644 index 0000000000..eb7bb93364 --- /dev/null +++ b/apps/whale-api/src/module.indexer/helper.ts @@ -0,0 +1,10 @@ +import { blockchain } from '@defichain/jellyfish-api-core' + +function checkIfEvmTx (txn: blockchain.Transaction): boolean { + // To identify that the transaction is evmtx, it has to have exactly 2 null transaction ids + return txn.vin.length === 2 && txn.vin.every(vin => vin.txid === '0000000000000000000000000000000000000000000000000000000000000000') +} + +export { + checkIfEvmTx +} diff --git a/apps/whale-api/src/module.indexer/model/script.activity.ts b/apps/whale-api/src/module.indexer/model/script.activity.ts index 255ab9568c..7c08ad0e11 100644 --- a/apps/whale-api/src/module.indexer/model/script.activity.ts +++ b/apps/whale-api/src/module.indexer/model/script.activity.ts @@ -5,6 +5,7 @@ import { HexEncoder } from '../../module.model/_hex.encoder' import { TransactionVout } from '../../module.model/transaction.vout' import { VoutFinder } from './_vout_finder' import { NotFoundIndexerError } from '../error' +import { checkIfEvmTx } from '../helper' @Injectable() export class ScriptActivityIndexer extends Indexer { @@ -17,11 +18,12 @@ export class ScriptActivityIndexer extends Indexer { async index (block: RawBlock): Promise { for (const txn of block.tx) { + const isEvmTx = checkIfEvmTx(txn) + for (const vin of txn.vin) { - if (vin.coinbase !== undefined) { + if (vin.coinbase !== undefined || isEvmTx) { continue } - const vout = await this.voutFinder.findVout(block, vin.txid, vin.vout) if (vout === undefined) { throw new NotFoundIndexerError('index', 'TransactionVout', `${vin.txid} - ${vin.vout}`) @@ -40,8 +42,10 @@ export class ScriptActivityIndexer extends Indexer { async invalidate (block: RawBlock): Promise { for (const txn of block.tx) { + const isEvmTx = checkIfEvmTx(txn) + for (const vin of txn.vin) { - if (vin.coinbase !== undefined) { + if (vin.coinbase !== undefined || isEvmTx) { continue } diff --git a/apps/whale-api/src/module.indexer/model/script.aggregation.ts b/apps/whale-api/src/module.indexer/model/script.aggregation.ts index 6abdd43c6e..79bf845f53 100644 --- a/apps/whale-api/src/module.indexer/model/script.aggregation.ts +++ b/apps/whale-api/src/module.indexer/model/script.aggregation.ts @@ -5,6 +5,7 @@ import { VoutFinder } from './_vout_finder' import { HexEncoder } from '../../module.model/_hex.encoder' import BigNumber from 'bignumber.js' import { NotFoundIndexerError } from '../error' +import { checkIfEvmTx } from '../helper' @Injectable() export class ScriptAggregationIndexer extends Indexer { @@ -27,8 +28,10 @@ export class ScriptAggregationIndexer extends Indexer { } for (const txn of block.tx) { + const isEvmTx = checkIfEvmTx(txn) + for (const vin of txn.vin) { - if (vin.coinbase !== undefined) { + if (vin.coinbase !== undefined || isEvmTx) { continue } @@ -76,8 +79,10 @@ export class ScriptAggregationIndexer extends Indexer { const hidList = new Set() for (const txn of block.tx) { + const isEvmTx = checkIfEvmTx(txn) + for (const vin of txn.vin) { - if (vin.coinbase !== undefined) { + if (vin.coinbase !== undefined || isEvmTx) { continue } diff --git a/apps/whale-api/src/module.indexer/model/script.unspent.ts b/apps/whale-api/src/module.indexer/model/script.unspent.ts index 36c2d3911c..5c979d60c6 100644 --- a/apps/whale-api/src/module.indexer/model/script.unspent.ts +++ b/apps/whale-api/src/module.indexer/model/script.unspent.ts @@ -5,6 +5,7 @@ import { HexEncoder } from '../../module.model/_hex.encoder' import { TransactionVout, TransactionVoutMapper } from '../../module.model/transaction.vout' import { Transaction, TransactionMapper } from '../../module.model/transaction' import { NotFoundIndexerError } from '../error' +import { checkIfEvmTx } from '../helper' @Injectable() export class ScriptUnspentIndexer extends Indexer { @@ -18,8 +19,10 @@ export class ScriptUnspentIndexer extends Indexer { async index (block: RawBlock): Promise { for (const txn of block.tx) { + const isEvmTx = checkIfEvmTx(txn) + for (const vin of txn.vin) { - if (vin.coinbase !== undefined) { + if (vin.coinbase !== undefined || isEvmTx) { continue } await this.unspentMapper.delete(vin.txid + HexEncoder.encodeVoutIndex(vin.vout)) @@ -33,8 +36,10 @@ export class ScriptUnspentIndexer extends Indexer { async invalidate (block: RawBlock): Promise { for (const txn of block.tx) { + const isEvmTx = checkIfEvmTx(txn) + for (const vin of txn.vin) { - if (vin.coinbase !== undefined) { + if (vin.coinbase !== undefined || isEvmTx) { continue } diff --git a/apps/whale-api/src/module.indexer/model/transaction.vin.ts b/apps/whale-api/src/module.indexer/model/transaction.vin.ts index 20a3840f08..abb3e7df2b 100644 --- a/apps/whale-api/src/module.indexer/model/transaction.vin.ts +++ b/apps/whale-api/src/module.indexer/model/transaction.vin.ts @@ -5,6 +5,7 @@ import { TransactionVout } from '../../module.model/transaction.vout' import { HexEncoder } from '../../module.model/_hex.encoder' import { VoutFinder } from './_vout_finder' import { NotFoundIndexerError } from '../error' +import { checkIfEvmTx } from '../helper' @Injectable() export class TransactionVinIndexer extends Indexer { @@ -17,8 +18,10 @@ export class TransactionVinIndexer extends Indexer { async index (block: RawBlock): Promise { for (const txn of block.tx) { + const isEvmTx = checkIfEvmTx(txn) + for (const vin of txn.vin) { - if (vin.coinbase !== undefined) { + if (vin.coinbase !== undefined || isEvmTx) { await this.vinMapper.put(this.map(txn, vin, undefined)) } else { const vout = await this.voutFinder.findVout(block, vin.txid, vin.vout)