Skip to content

Commit

Permalink
set indexing to true if status mapper is set to error
Browse files Browse the repository at this point in the history
  • Loading branch information
lykalabrada committed Nov 8, 2023
1 parent da3a95f commit a3b83c3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions apps/whale-api/src/module.indexer/rpc.block.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ export class RPCBlockProvider {
}

try {
const status = await this.statusMapper.get()
this.logger.log(`[Start Cycle] - status: ${JSON.stringify(status)}`)
if (status?.status === Status.ERROR) {
this.logger.log('Setting status mapper to previous block...')
const currentBlock = await this.client.blockchain.getBlock(status.hash, 2)
const prevBlock = await this.client.blockchain.getBlock(currentBlock.previousblockhash, 2)
await this.statusMapper.put(prevBlock.hash, prevBlock.height, Status.INDEXING)

Check warning on line 53 in apps/whale-api/src/module.indexer/rpc.block.provider.ts

View check run for this annotation

Codecov / codecov/patch

apps/whale-api/src/module.indexer/rpc.block.provider.ts#L50-L53

Added lines #L50 - L53 were not covered by tests
}

await this.cleanup()
this.indexing = await this.synchronize()
} catch (err) {
Expand Down Expand Up @@ -88,8 +97,10 @@ export class RPCBlockProvider {

const nextBlock = await this.client.blockchain.getBlock(nextHash, 2)
if (await RPCBlockProvider.isBestChain(indexed, nextBlock)) {
this.logger.log(`[Synchronize] BEST CHAIN. Indexing next block ${nextBlock.height}...`)
await this.index(nextBlock)
} else {
this.logger.log(`[Synchronize] NOT BEST CHAIN. Indexing prev block ${indexed.height}...`)

Check warning on line 103 in apps/whale-api/src/module.indexer/rpc.block.provider.ts

View check run for this annotation

Codecov / codecov/patch

apps/whale-api/src/module.indexer/rpc.block.provider.ts#L103

Added line #L103 was not covered by tests
// Retry indexing the previous block before invalidating it
const MAX_RETRIES = 3
let prevBlockIndexedSuccessfully = false
Expand Down

0 comments on commit a3b83c3

Please sign in to comment.