From ec17376004c363354ac2d107676417ef1559e787 Mon Sep 17 00:00:00 2001 From: paulo-ocean Date: Wed, 4 Dec 2024 14:27:57 +0000 Subject: [PATCH] fix corner case issue on ganache --- src/components/Indexer/crawlerThread.ts | 27 +++++++++++++------------ 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/components/Indexer/crawlerThread.ts b/src/components/Indexer/crawlerThread.ts index 2b8e09e3e..61efa961b 100644 --- a/src/components/Indexer/crawlerThread.ts +++ b/src/components/Indexer/crawlerThread.ts @@ -98,20 +98,21 @@ export async function processNetworkData( ): Promise { stoppedCrawling = startedCrawling = false let contractDeploymentBlock = getDeployedContractBlock(rpcDetails.chainId) - if (!isDefined(contractDeploymentBlock) && !isDefined(await getLastIndexedBlock())) { - if (rpcDetails.chainId === DEVELOPMENT_CHAIN_ID) { - rpcDetails.startBlock = contractDeploymentBlock = 0 - INDEXER_LOGGER.warn( - 'Cannot get block info for local network, starting from block 0' - ) - } else { - INDEXER_LOGGER.logMessage( - `chain: ${rpcDetails.chainId} Both deployed block and last indexed block are null/undefined. Cannot proceed further on this chain`, - true - ) + const isLocalChain = rpcDetails.chainId === DEVELOPMENT_CHAIN_ID + if (isLocalChain && !isDefined(contractDeploymentBlock)) { + rpcDetails.startBlock = contractDeploymentBlock = 0 + INDEXER_LOGGER.warn('Cannot get block info for local network, starting from block 0') + } else if ( + !isLocalChain && + !isDefined(contractDeploymentBlock) && + !isDefined(await getLastIndexedBlock()) + ) { + INDEXER_LOGGER.logMessage( + `chain: ${rpcDetails.chainId} Both deployed block and last indexed block are null/undefined. Cannot proceed further on this chain`, + true + ) - return null - } + return null } // if we defined a valid startBlock use it, oterwise start from deployed one