Skip to content

Commit

Permalink
Update activity retry strategy (l2beat#4815)
Browse files Browse the repository at this point in the history
  • Loading branch information
antooni authored Aug 19, 2024
1 parent 287e10f commit 5417c47
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { ActivityRecord } from '@l2beat/database'
import { assert, UnixTime } from '@l2beat/shared-pure'
import { Indexer } from '@l2beat/uif'
import { ManagedChildIndexer } from '../../../tools/uif/ManagedChildIndexer'
import { ActivityIndexerDeps } from './types'

export class BlockActivityIndexer extends ManagedChildIndexer {
constructor(private readonly $: ActivityIndexerDeps) {
super({ ...$, name: `activity_block_indexer`, tag: $.projectId })
super({
...$,
name: `activity_block_indexer`,
tag: $.projectId,
updateRetryStrategy: Indexer.getInfiniteRetryStrategy(),
})
}

override async update(from: number, to: number): Promise<number> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger } from '@l2beat/backend-tools'
import { ProjectId } from '@l2beat/shared-pure'
import { RootIndexer } from '@l2beat/uif'
import { Indexer, RootIndexer } from '@l2beat/uif'
import { Clock } from '../../../tools/Clock'
import { BlockTimestampProvider } from '../../tvl/services/BlockTimestampProvider'

Expand All @@ -11,7 +11,9 @@ export class BlockTargetIndexer extends RootIndexer {
private readonly blockTimestampProvider: BlockTimestampProvider,
projectId: ProjectId,
) {
super(logger.tag(projectId))
super(logger.tag(projectId), {
tickRetryStrategy: Indexer.getInfiniteRetryStrategy(),
})
}

override async initialize() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { Indexer } from '@l2beat/uif'
import { ManagedChildIndexer } from '../../../tools/uif/ManagedChildIndexer'
import { DayActivityIndexerDeps } from './types'

export class DayActivityIndexer extends ManagedChildIndexer {
constructor(private readonly $: DayActivityIndexerDeps) {
super({ ...$, name: `activity_day_indexer`, tag: $.projectId })
super({
...$,
name: `activity_day_indexer`,
tag: $.projectId,
updateRetryStrategy: Indexer.getInfiniteRetryStrategy(),
})
}

override async update(from: number, to: number): Promise<number> {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/modules/tracked-txs/TrackedTxsIndexer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Database } from '@l2beat/database'
import { TrackedTxConfigEntry } from '@l2beat/shared'
import { UnixTime, clampRangeToDay } from '@l2beat/shared-pure'
import { DEFAULT_RETRY_FOR_TVL } from '../../tools/uif/defaultRetryForTvl'
import { Indexer } from '@l2beat/uif'
import { ManagedMultiIndexer } from '../../tools/uif/multi/ManagedMultiIndexer'
import {
Configuration,
Expand All @@ -23,7 +23,7 @@ export class TrackedTxsIndexer extends ManagedMultiIndexer<TrackedTxConfigEntry>
super({
...$,
name: 'tracked_txs_indexer',
updateRetryStrategy: DEFAULT_RETRY_FOR_TVL,
updateRetryStrategy: Indexer.getInfiniteRetryStrategy(),
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {} from '@l2beat/shared'
import { UnixTime } from '@l2beat/shared-pure'
import { Indexer } from '@l2beat/uif'
import { ManagedChildIndexer } from '../../../tools/uif/ManagedChildIndexer'
import { DEFAULT_RETRY_FOR_TVL } from '../../../tools/uif/defaultRetryForTvl'
import { BlockTimestampIndexerDeps } from './types'

export class BlockTimestampIndexer extends ManagedChildIndexer {
Expand All @@ -10,7 +10,7 @@ export class BlockTimestampIndexer extends ManagedChildIndexer {
...$,
name: 'block_timestamp_indexer',
tag: $.chain,
updateRetryStrategy: DEFAULT_RETRY_FOR_TVL,
updateRetryStrategy: Indexer.getInfiniteRetryStrategy(),
configHash: $.minHeight.toString(),
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { assert } from '@l2beat/backend-tools'
import { UnixTime } from '@l2beat/shared-pure'
import { Indexer } from '@l2beat/uif'
import { DEFAULT_RETRY_FOR_TVL } from '../../../tools/uif/defaultRetryForTvl'
import { ManagedMultiIndexer } from '../../../tools/uif/multi/ManagedMultiIndexer'
import {
Configuration,
Expand All @@ -16,7 +15,7 @@ export class ChainAmountIndexer extends ManagedMultiIndexer<ChainAmountConfig> {
...$,
name: NAME,
tag: $.chain,
updateRetryStrategy: DEFAULT_RETRY_FOR_TVL,
updateRetryStrategy: Indexer.getInfiniteRetryStrategy(),
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { CoingeckoId, UnixTime } from '@l2beat/shared-pure'
import { Indexer } from '@l2beat/uif'
import { ManagedChildIndexer } from '../../../tools/uif/ManagedChildIndexer'
import { DEFAULT_RETRY_FOR_TVL } from '../../../tools/uif/defaultRetryForTvl'
import { createAmountId } from '../utils/createAmountId'
import { CirculatingSupplyIndexerDeps } from './types'

Expand All @@ -14,7 +13,7 @@ export class CirculatingSupplyIndexer extends ManagedChildIndexer {
...$,
name: NAME,
tag: $.configuration.coingeckoId.toString(),
updateRetryStrategy: DEFAULT_RETRY_FOR_TVL,
updateRetryStrategy: Indexer.getInfiniteRetryStrategy(),
configHash: $.minHeight.toString(),
})
this.configurationId = createAmountId($.configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AmountRecord } from '@l2beat/database'
import { EthereumAddress, UnixTime } from '@l2beat/shared-pure'
import { Indexer } from '@l2beat/uif'
import { ManagedChildIndexer } from '../../../tools/uif/ManagedChildIndexer'
import { DEFAULT_RETRY_FOR_TVL } from '../../../tools/uif/defaultRetryForTvl'
import { createAmountId } from '../utils/createAmountId'
import { PremintedIndexerDeps } from './types'

Expand All @@ -16,7 +15,7 @@ export class PremintedIndexer extends ManagedChildIndexer {
...$,
name: NAME,
tag: createTag($.configuration.chain, $.configuration.address),
updateRetryStrategy: DEFAULT_RETRY_FOR_TVL,
updateRetryStrategy: Indexer.getInfiniteRetryStrategy(),
configHash: $.minHeight.toString(),
})
this.configurationId = createAmountId($.configuration)
Expand Down
3 changes: 1 addition & 2 deletions packages/backend/src/modules/tvl/indexers/PriceIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
UnixTime,
} from '@l2beat/shared-pure'
import { Indexer } from '@l2beat/uif'
import { DEFAULT_RETRY_FOR_TVL } from '../../../tools/uif/defaultRetryForTvl'
import { ManagedMultiIndexer } from '../../../tools/uif/multi/ManagedMultiIndexer'
import {
Configuration,
Expand All @@ -19,7 +18,7 @@ export class PriceIndexer extends ManagedMultiIndexer<CoingeckoPriceConfigEntry>
...$,
name: NAME,
tag: $.coingeckoId.toString(),
updateRetryStrategy: DEFAULT_RETRY_FOR_TVL,
updateRetryStrategy: Indexer.getInfiniteRetryStrategy(),
})
}

Expand Down
9 changes: 0 additions & 9 deletions packages/backend/src/tools/uif/defaultRetryForTvl.ts

This file was deleted.

15 changes: 11 additions & 4 deletions packages/uif/src/Indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,20 @@ export abstract class Indexer {
* used for all indexers that don't specify their own strategy.
* @returns A default retry strategy that will be used for all indexers
*/
static GET_DEFAULT_RETRY_STRATEGY: () => RetryStrategy = () =>
static getDefaultRetryStrategy: () => RetryStrategy = () =>
Retries.exponentialBackOff({
initialTimeoutMs: 1000,
maxAttempts: 10,
maxTimeoutMs: 60 * 1000,
})

static getInfiniteRetryStrategy: () => RetryStrategy = () =>
Retries.exponentialBackOff({
initialTimeoutMs: 1000,
maxAttempts: Infinity,
maxTimeoutMs: 1 * 60 * 60_000,
})

static createId(name: string, tag: string | undefined): string {
return tag === undefined ? name : `${name}::${tag}`
}
Expand Down Expand Up @@ -169,11 +176,11 @@ export abstract class Indexer {
})

this.tickRetryStrategy =
options?.tickRetryStrategy ?? Indexer.GET_DEFAULT_RETRY_STRATEGY()
options?.tickRetryStrategy ?? Indexer.getDefaultRetryStrategy()
this.updateRetryStrategy =
options?.updateRetryStrategy ?? Indexer.GET_DEFAULT_RETRY_STRATEGY()
options?.updateRetryStrategy ?? Indexer.getDefaultRetryStrategy()
this.invalidateRetryStrategy =
options?.invalidateRetryStrategy ?? Indexer.GET_DEFAULT_RETRY_STRATEGY()
options?.invalidateRetryStrategy ?? Indexer.getDefaultRetryStrategy()
}

get safeHeight(): number {
Expand Down

0 comments on commit 5417c47

Please sign in to comment.