From 5417c4717b5cefeed17cd8419a7eb2dda22d4206 Mon Sep 17 00:00:00 2001 From: Antoni Pawlak Date: Mon, 19 Aug 2024 13:28:05 +0200 Subject: [PATCH] Update activity retry strategy (#4815) --- .../activity2/indexers/BlockActivityIndexer.ts | 8 +++++++- .../activity2/indexers/BlockTargetIndexer.ts | 6 ++++-- .../activity2/indexers/DayActivityIndexer.ts | 8 +++++++- .../src/modules/tracked-txs/TrackedTxsIndexer.ts | 4 ++-- .../modules/tvl/indexers/BlockTimestampIndexer.ts | 4 ++-- .../modules/tvl/indexers/ChainAmountIndexer.ts | 3 +-- .../tvl/indexers/CirculatingSupplyIndexer.ts | 3 +-- .../src/modules/tvl/indexers/PremintedIndexer.ts | 3 +-- .../src/modules/tvl/indexers/PriceIndexer.ts | 3 +-- .../backend/src/tools/uif/defaultRetryForTvl.ts | 9 --------- packages/uif/src/Indexer.ts | 15 +++++++++++---- 11 files changed, 37 insertions(+), 29 deletions(-) delete mode 100644 packages/backend/src/tools/uif/defaultRetryForTvl.ts diff --git a/packages/backend/src/modules/activity2/indexers/BlockActivityIndexer.ts b/packages/backend/src/modules/activity2/indexers/BlockActivityIndexer.ts index 3f1e4ec55fb..0eb66e52bf1 100644 --- a/packages/backend/src/modules/activity2/indexers/BlockActivityIndexer.ts +++ b/packages/backend/src/modules/activity2/indexers/BlockActivityIndexer.ts @@ -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 { diff --git a/packages/backend/src/modules/activity2/indexers/BlockTargetIndexer.ts b/packages/backend/src/modules/activity2/indexers/BlockTargetIndexer.ts index 6fe43c1f06b..6046c42020a 100644 --- a/packages/backend/src/modules/activity2/indexers/BlockTargetIndexer.ts +++ b/packages/backend/src/modules/activity2/indexers/BlockTargetIndexer.ts @@ -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' @@ -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() { diff --git a/packages/backend/src/modules/activity2/indexers/DayActivityIndexer.ts b/packages/backend/src/modules/activity2/indexers/DayActivityIndexer.ts index 8b4cc0c8ef6..54f93f3acf6 100644 --- a/packages/backend/src/modules/activity2/indexers/DayActivityIndexer.ts +++ b/packages/backend/src/modules/activity2/indexers/DayActivityIndexer.ts @@ -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 { diff --git a/packages/backend/src/modules/tracked-txs/TrackedTxsIndexer.ts b/packages/backend/src/modules/tracked-txs/TrackedTxsIndexer.ts index 4c27b5f2075..6f8e4c6fe02 100644 --- a/packages/backend/src/modules/tracked-txs/TrackedTxsIndexer.ts +++ b/packages/backend/src/modules/tracked-txs/TrackedTxsIndexer.ts @@ -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, @@ -23,7 +23,7 @@ export class TrackedTxsIndexer extends ManagedMultiIndexer super({ ...$, name: 'tracked_txs_indexer', - updateRetryStrategy: DEFAULT_RETRY_FOR_TVL, + updateRetryStrategy: Indexer.getInfiniteRetryStrategy(), }) } diff --git a/packages/backend/src/modules/tvl/indexers/BlockTimestampIndexer.ts b/packages/backend/src/modules/tvl/indexers/BlockTimestampIndexer.ts index 59548163966..9042334f613 100644 --- a/packages/backend/src/modules/tvl/indexers/BlockTimestampIndexer.ts +++ b/packages/backend/src/modules/tvl/indexers/BlockTimestampIndexer.ts @@ -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 { @@ -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(), }) } diff --git a/packages/backend/src/modules/tvl/indexers/ChainAmountIndexer.ts b/packages/backend/src/modules/tvl/indexers/ChainAmountIndexer.ts index a4c5a8ebef2..bde12636c0d 100644 --- a/packages/backend/src/modules/tvl/indexers/ChainAmountIndexer.ts +++ b/packages/backend/src/modules/tvl/indexers/ChainAmountIndexer.ts @@ -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, @@ -16,7 +15,7 @@ export class ChainAmountIndexer extends ManagedMultiIndexer { ...$, name: NAME, tag: $.chain, - updateRetryStrategy: DEFAULT_RETRY_FOR_TVL, + updateRetryStrategy: Indexer.getInfiniteRetryStrategy(), }) } diff --git a/packages/backend/src/modules/tvl/indexers/CirculatingSupplyIndexer.ts b/packages/backend/src/modules/tvl/indexers/CirculatingSupplyIndexer.ts index f667ebc9d7d..1b3c3d62bdf 100644 --- a/packages/backend/src/modules/tvl/indexers/CirculatingSupplyIndexer.ts +++ b/packages/backend/src/modules/tvl/indexers/CirculatingSupplyIndexer.ts @@ -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' @@ -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) diff --git a/packages/backend/src/modules/tvl/indexers/PremintedIndexer.ts b/packages/backend/src/modules/tvl/indexers/PremintedIndexer.ts index fb42bbc86a5..acf09082ce8 100644 --- a/packages/backend/src/modules/tvl/indexers/PremintedIndexer.ts +++ b/packages/backend/src/modules/tvl/indexers/PremintedIndexer.ts @@ -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' @@ -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) diff --git a/packages/backend/src/modules/tvl/indexers/PriceIndexer.ts b/packages/backend/src/modules/tvl/indexers/PriceIndexer.ts index 1809530fef0..42beb21125b 100644 --- a/packages/backend/src/modules/tvl/indexers/PriceIndexer.ts +++ b/packages/backend/src/modules/tvl/indexers/PriceIndexer.ts @@ -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, @@ -19,7 +18,7 @@ export class PriceIndexer extends ManagedMultiIndexer ...$, name: NAME, tag: $.coingeckoId.toString(), - updateRetryStrategy: DEFAULT_RETRY_FOR_TVL, + updateRetryStrategy: Indexer.getInfiniteRetryStrategy(), }) } diff --git a/packages/backend/src/tools/uif/defaultRetryForTvl.ts b/packages/backend/src/tools/uif/defaultRetryForTvl.ts deleted file mode 100644 index baa8d6c8fde..00000000000 --- a/packages/backend/src/tools/uif/defaultRetryForTvl.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Retries } from '@l2beat/uif' - -const ONE_HOUR_MS = 1 * 60 * 60_000 - -export const DEFAULT_RETRY_FOR_TVL = Retries.exponentialBackOff({ - maxAttempts: Infinity, - initialTimeoutMs: 1000, - maxTimeoutMs: ONE_HOUR_MS, -}) diff --git a/packages/uif/src/Indexer.ts b/packages/uif/src/Indexer.ts index 830f12da3a7..2fce8964de6 100644 --- a/packages/uif/src/Indexer.ts +++ b/packages/uif/src/Indexer.ts @@ -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}` } @@ -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 {