Skip to content

Commit

Permalink
Merge pull request #594 from oceanprotocol/issue-493-start-block-ganache
Browse files Browse the repository at this point in the history
make sure we always start indexing on ganache, even if no block info available (from block 0)…
  • Loading branch information
paulo-ocean authored Aug 6, 2024
2 parents bfbba53 + 4ad121d commit 0c03f69
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/components/Indexer/crawlerThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import {
import { Blockchain } from '../../utils/blockchain.js'
import { BlocksEvents, SupportedNetwork } from '../../@types/blockchain.js'
import { LOG_LEVELS_STR } from '../../utils/logging/Logger.js'
import { sleep } from '../../utils/util.js'
import { isDefined, sleep } from '../../utils/util.js'
import { EVENTS, INDEXER_CRAWLING_EVENTS, INDEXER_MESSAGES } from '../../utils/index.js'
import { INDEXER_LOGGER } from '../../utils/logging/common.js'
import { getDatabase } from '../../utils/database.js'
import { JsonRpcApiProvider, Log, Signer } from 'ethers'
import { DEVELOPMENT_CHAIN_ID } from '../../utils/address.js'

export interface ReindexTask {
txId: string
Expand Down Expand Up @@ -80,13 +81,21 @@ export async function processNetworkData(
signer: Signer
): Promise<void> {
stoppedCrawling = startedCrawling = false
const contractDeploymentBlock = getDeployedContractBlock(rpcDetails.chainId)
if (contractDeploymentBlock == null && (await getLastIndexedBlock()) == null) {
INDEXER_LOGGER.logMessage(
`chain: ${rpcDetails.chainId} Both deployed block and last indexed block are null. Cannot proceed further on this chain`,
true
)
return null
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
)

return null
}
}
// if we defined a valid startBlock use it, oterwise start from deployed one

Expand Down
4 changes: 4 additions & 0 deletions src/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,7 @@ export function asyncCallWithTimeout(
}
})
}

export function isDefined(something: any): boolean {
return something !== undefined && something !== null
}

0 comments on commit 0c03f69

Please sign in to comment.