From 39d952bc476b507716f631dcaf94aa2b4767a681 Mon Sep 17 00:00:00 2001 From: Julian <52217955+julianmerlo95@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:59:16 -0300 Subject: [PATCH] [Blockchain Watcher] (FIX) Validate tx logs to process correctly (#1704) * Improve standard relayer mapper * Improve standard relayer mapper * Filter logs by topic * Create random key for sns message --------- Co-authored-by: julian merlo --- .../src/domain/actions/evm/GetEvmTransactions.ts | 16 ++++++++++------ .../strategy/GetTransactionsByBlocksStrategy.ts | 3 ++- .../GetTransactionsByLogFiltersStrategy.ts | 3 ++- .../repositories/target/SnsEventRepository.ts | 9 +++++---- .../env/production-mainnet.env | 2 +- .../blockchain-watcher/env/staging-mainnet.env | 2 +- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/blockchain-watcher/src/domain/actions/evm/GetEvmTransactions.ts b/blockchain-watcher/src/domain/actions/evm/GetEvmTransactions.ts index 678d4982b..6fc0d2b2d 100644 --- a/blockchain-watcher/src/domain/actions/evm/GetEvmTransactions.ts +++ b/blockchain-watcher/src/domain/actions/evm/GetEvmTransactions.ts @@ -62,15 +62,19 @@ export function populateTransaction( evmBlocks: Record, transactionReceipts: Record, filterTransactions: EvmTransaction[], - populatedTransactions: EvmTransaction[] + populatedTransactions: EvmTransaction[], + topics: string[] ) { filterTransactions.forEach((transaction) => { - if (transactionReceipts[transaction.hash]) { - transaction.effectiveGasPrice = transactionReceipts[transaction.hash].effectiveGasPrice; - transaction.gasUsed = transactionReceipts[transaction.hash].gasUsed; + const txReceipt = transactionReceipts[transaction.hash]; + if (txReceipt) { + transaction.effectiveGasPrice = txReceipt.effectiveGasPrice; + transaction.gasUsed = txReceipt.gasUsed; transaction.timestamp = evmBlocks[transaction.blockHash].timestamp; - transaction.status = transactionReceipts[transaction.hash].status; - transaction.logs = transactionReceipts[transaction.hash].logs; + transaction.status = txReceipt.status; + transaction.logs = txReceipt.logs.filter((log) => + log.topics.some((topic) => topics.includes(topic)) + ); transaction.environment = opts.environment; transaction.chainId = opts.chainId; transaction.chain = opts.chain; diff --git a/blockchain-watcher/src/domain/actions/evm/strategy/GetTransactionsByBlocksStrategy.ts b/blockchain-watcher/src/domain/actions/evm/strategy/GetTransactionsByBlocksStrategy.ts index c043473e8..100dd9c87 100644 --- a/blockchain-watcher/src/domain/actions/evm/strategy/GetTransactionsByBlocksStrategy.ts +++ b/blockchain-watcher/src/domain/actions/evm/strategy/GetTransactionsByBlocksStrategy.ts @@ -51,7 +51,8 @@ export class GetTransactionsByBlocksStrategy implements GetTransactions { evmBlocks, transactionReceipts, transactionsByAddressConfigured, - populatedTransactions + populatedTransactions, + filter.topics ); } } diff --git a/blockchain-watcher/src/domain/actions/evm/strategy/GetTransactionsByLogFiltersStrategy.ts b/blockchain-watcher/src/domain/actions/evm/strategy/GetTransactionsByLogFiltersStrategy.ts index e85c1e93e..3229b611f 100644 --- a/blockchain-watcher/src/domain/actions/evm/strategy/GetTransactionsByLogFiltersStrategy.ts +++ b/blockchain-watcher/src/domain/actions/evm/strategy/GetTransactionsByLogFiltersStrategy.ts @@ -63,7 +63,8 @@ export class GetTransactionsByLogFiltersStrategy implements GetTransactions { evmBlocks, transactionReceipts, filterTransactions, - populatedTransactions + populatedTransactions, + filter.topics ); } } diff --git a/blockchain-watcher/src/infrastructure/repositories/target/SnsEventRepository.ts b/blockchain-watcher/src/infrastructure/repositories/target/SnsEventRepository.ts index 076153cbf..a5adb1fde 100644 --- a/blockchain-watcher/src/infrastructure/repositories/target/SnsEventRepository.ts +++ b/blockchain-watcher/src/infrastructure/repositories/target/SnsEventRepository.ts @@ -1,12 +1,13 @@ import { LogFoundEvent } from "../../../domain/entities"; +import { v4 as uuidv4 } from "uuid"; +import winston from "../../log"; import crypto from "node:crypto"; import { - SNSClient, - PublishBatchCommand, PublishBatchCommandInput, PublishBatchRequestEntry, + PublishBatchCommand, + SNSClient, } from "@aws-sdk/client-sns"; -import winston from "../../log"; const CHUNK_SIZE = 10; @@ -127,7 +128,7 @@ export class SnsEvent { static fromLogFoundEvent(logFoundEvent: LogFoundEvent): SnsEvent { return new SnsEvent( - `chain-event-${logFoundEvent.txHash}-${logFoundEvent.blockHeight}`, + `chain-event-${uuidv4()}-${logFoundEvent.txHash}`, "blockchain-watcher", logFoundEvent.name, new Date().toISOString(), diff --git a/deploy/blockchain-watcher/env/production-mainnet.env b/deploy/blockchain-watcher/env/production-mainnet.env index c37fd8213..3c8c04b29 100644 --- a/deploy/blockchain-watcher/env/production-mainnet.env +++ b/deploy/blockchain-watcher/env/production-mainnet.env @@ -37,7 +37,7 @@ OPTIMISM_RPCS='["https://rpc.ankr.com/optimism/${token_ankr}","https://op-pokt.n ARBITRUM_RPCS='["https://rpc.ankr.com/arbitrum/${token_ankr}","https://arb1.arbitrum.io/rpc"]' POLYGON_RPCS='["https://rpc.ankr.com/polygon/${token_ankr}","https://rpc-mainnet.matic.quiknode.pro","https://polygon-rpc.com"]' AVALANCHE_RPCS='["https://rpc.ankr.com/avalanche/${token_ankr}","https://avalanche.blockpi.network/v1/rpc/public","https://api.avax.network/ext/bc/C/rpc","https://avalanche.public-rpc.com","https://endpoints.omniatech.io/v1/avax/mainnet/public", "https://avalanche-c-chain.publicnode.com"]' -MOONBEAM_RPCS='["https://rpc.ankr.com/moonbeam/${token_ankr}","https://rpc.api.moonbeam.network","https://1rpc.io/glmr"]' +MOONBEAM_RPCS='["https://rpc.ankr.com/moonbeam/${token_ankr}","https://rpc.api.moonbeam.network"]' BSC_RPCS='["https://rpc.ankr.com/bsc/${token_ankr}","https://bscrpc.com"]' CELO_RPCS='["https://rpc.ankr.com/celo/${token_ankr}","https://forno.celo.org","https://1rpc.io/celo"]' SCROLL_RPCS='["https://rpc.ankr.com/scroll/${token_ankr}","https://scroll-mainnet-public.unifra.io","https://rpc.scroll.io","https://scroll-mainnet.chainstacklabs.com"]' diff --git a/deploy/blockchain-watcher/env/staging-mainnet.env b/deploy/blockchain-watcher/env/staging-mainnet.env index 01b8faaef..e53e06f8c 100644 --- a/deploy/blockchain-watcher/env/staging-mainnet.env +++ b/deploy/blockchain-watcher/env/staging-mainnet.env @@ -34,7 +34,7 @@ OPTIMISM_RPCS='["https://rpc.ankr.com/optimism/${token_ankr}","https://op-pokt.n ARBITRUM_RPCS='["https://rpc.ankr.com/arbitrum/${token_ankr}","https://arb1.arbitrum.io/rpc"]' POLYGON_RPCS='["https://rpc.ankr.com/polygon/${token_ankr}","https://rpc-mainnet.matic.quiknode.pro","https://polygon-rpc.com"]' AVALANCHE_RPCS='["https://rpc.ankr.com/avalanche/${token_ankr}","https://avalanche.blockpi.network/v1/rpc/public","https://api.avax.network/ext/bc/C/rpc","https://avalanche.public-rpc.com","https://endpoints.omniatech.io/v1/avax/mainnet/public", "https://avalanche-c-chain.publicnode.com"]' -MOONBEAM_RPCS='["https://rpc.ankr.com/moonbeam/${token_ankr}","https://rpc.api.moonbeam.network","https://1rpc.io/glmr"]' +MOONBEAM_RPCS='["https://rpc.ankr.com/moonbeam/${token_ankr}","https://rpc.api.moonbeam.network"]' BSC_RPCS='["https://rpc.ankr.com/bsc/${token_ankr}","https://bscrpc.com"]' CELO_RPCS='["https://rpc.ankr.com/celo/${token_ankr}","https://forno.celo.org","https://1rpc.io/celo"]' SCROLL_RPCS='["https://rpc.ankr.com/scroll/${token_ankr}","https://scroll-mainnet-public.unifra.io","https://rpc.scroll.io","https://scroll-mainnet.chainstacklabs.com"]'