Skip to content

Commit

Permalink
feat: Added ability to restrict the number of rounds indexer catchup …
Browse files Browse the repository at this point in the history
…syncs for so large catchups are more reliable
  • Loading branch information
robdmoore committed Mar 22, 2024
1 parent d3bf82b commit ae8c880
Show file tree
Hide file tree
Showing 18 changed files with 240 additions and 91 deletions.
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ Any [filter](#extensive-subscription-filtering) you apply will be seamlessly tra
To see this in action, you can run the Data History Museum example in this repository against MainNet and see it sync millions of rounds in seconds.
The indexer catchup isn't magic - if the filter you are trying to catch up with generates an enormous number of transactions (e.g. hundreds of thousands or millions) then it will run very slowly and has the potential for running out of compute and memory time depending on what the constraints are in the deployment environment you are running in. To understand how the indexer behaviour works to know if you are likely to generate a lot of transactions it's worth understanding the architecture of the indexer catchup.
The indexer catchup isn't magic - if the filter you are trying to catch up with generates an enormous number of transactions (e.g. hundreds of thousands or millions) then it will run very slowly and has the potential for running out of compute and memory time depending on what the constraints are in the deployment environment you are running in. In that instance though, there is a config parameter you can use `maxIndexerRoundsToSync` so you can break the indexer catchup into multiple "polls" e.g. 100,000 rounds at a time. This allows a smaller batch of transactions to be retrieved and persisted in multiple batches.
Indexer catchup runs in two stages:
To understand how the indexer behaviour works to know if you are likely to generate a lot of transactions it's worth understanding the architecture of the indexer catchup; indexer catchup runs in two stages:
1. **Pre-filtering**: Any filters that can be translated to the [indexer search transactions endpoint](https://developer.algorand.org/docs/rest-apis/indexer/#get-v2transactions). This query is then run between the rounds that need to be synced and paginated in the max number of results (1000) at a time until all of the transactions are retrieved. This ensures we get round-based transactional consistency. This is the filter that can easily explode out though and take a long time when using indexer catchup. For avoidance of doubt, the following filters are the ones that are converted to a pre-filter:
- `sender`
Expand Down
30 changes: 15 additions & 15 deletions docs/code/classes/index.AlgorandSubscriber.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ Handles the logic for subscribing to the Algorand blockchain and emitting events

- [abortController](index.AlgorandSubscriber.md#abortcontroller)
- [algod](index.AlgorandSubscriber.md#algod)
- [config](index.AlgorandSubscriber.md#config)
- [eventEmitter](index.AlgorandSubscriber.md#eventemitter)
- [filterNames](index.AlgorandSubscriber.md#filternames)
- [indexer](index.AlgorandSubscriber.md#indexer)
- [startPromise](index.AlgorandSubscriber.md#startpromise)
- [started](index.AlgorandSubscriber.md#started)
- [subscription](index.AlgorandSubscriber.md#subscription)

### Methods

Expand Down Expand Up @@ -77,6 +77,16 @@ ___

___

### config

`Private` **config**: [`AlgorandSubscriberConfig`](../interfaces/types_subscription.AlgorandSubscriberConfig.md)

#### Defined in

[subscriber.ts:21](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/subscriber.ts#L21)

___

### eventEmitter

`Private` **eventEmitter**: [`AsyncEventEmitter`](types_async_event_emitter.AsyncEventEmitter.md)
Expand Down Expand Up @@ -125,16 +135,6 @@ ___

[subscriber.ts:24](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/subscriber.ts#L24)

___

### subscription

`Private` **subscription**: [`AlgorandSubscriberConfig`](../interfaces/types_subscription.AlgorandSubscriberConfig.md)

#### Defined in

[subscriber.ts:21](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/subscriber.ts#L21)

## Methods

### on
Expand Down Expand Up @@ -166,7 +166,7 @@ The subscriber so `on`/`onBatch` calls can be chained

#### Defined in

[subscriber.ts:162](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/subscriber.ts#L162)
[subscriber.ts:159](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/subscriber.ts#L159)

___

Expand Down Expand Up @@ -203,7 +203,7 @@ The subscriber so `on`/`onBatch` calls can be chained

#### Defined in

[subscriber.ts:179](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/subscriber.ts#L179)
[subscriber.ts:176](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/subscriber.ts#L176)

___

Expand Down Expand Up @@ -251,7 +251,7 @@ An object that contains a promise you can wait for after calling stop

#### Defined in

[subscriber.ts:101](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/subscriber.ts#L101)
[subscriber.ts:98](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/subscriber.ts#L98)

___

Expand All @@ -275,4 +275,4 @@ A promise that can be awaited to ensure the subscriber has finished stopping

#### Defined in

[subscriber.ts:144](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/subscriber.ts#L144)
[subscriber.ts:141](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/subscriber.ts#L141)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Configuration for an `AlgorandSubscriber`.
- [arc28Events](types_subscription.AlgorandSubscriberConfig.md#arc28events)
- [filters](types_subscription.AlgorandSubscriberConfig.md#filters)
- [frequencyInSeconds](types_subscription.AlgorandSubscriberConfig.md#frequencyinseconds)
- [maxIndexerRoundsToSync](types_subscription.AlgorandSubscriberConfig.md#maxindexerroundstosync)
- [maxRoundsToSync](types_subscription.AlgorandSubscriberConfig.md#maxroundstosync)
- [syncBehaviour](types_subscription.AlgorandSubscriberConfig.md#syncbehaviour)
- [waitForBlockWhenAtTip](types_subscription.AlgorandSubscriberConfig.md#waitforblockwhenattip)
Expand Down Expand Up @@ -54,7 +55,7 @@ The set of filters to subscribe to / emit events for, along with optional data m

#### Defined in

[types/subscription.ts:164](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L164)
[types/subscription.ts:175](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L175)

___

Expand All @@ -66,15 +67,38 @@ The frequency to poll for new blocks in seconds; defaults to 1s

#### Defined in

[types/subscription.ts:166](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L166)
[types/subscription.ts:177](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L177)

___

### maxIndexerRoundsToSync

`Optional` **maxIndexerRoundsToSync**: `number`

The maximum number of rounds to sync from indexer when using `syncBehaviour: 'catchup-with-indexer'.

By default there is no limit and it will paginate through all of the rounds.
Sometimes this can result in an incredibly long catchup time that may break the service
due to execution and memory constraints, particularly for filters that result in a large number of transactions.

Instead, this allows indexer catchup to be split into multiple polls, each with a transactionally consistent
boundary based on the number of rounds specified here.

#### Inherited from

[CoreTransactionSubscriptionParams](types_subscription.CoreTransactionSubscriptionParams.md).[maxIndexerRoundsToSync](types_subscription.CoreTransactionSubscriptionParams.md#maxindexerroundstosync)

#### Defined in

[types/subscription.ts:89](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L89)

___

### maxRoundsToSync

`Optional` **maxRoundsToSync**: `number`

The maximum number of rounds to sync for each subscription pull/poll.
The maximum number of rounds to sync from algod for each subscription pull/poll.

Defaults to 500.

Expand Down Expand Up @@ -119,7 +143,7 @@ past `watermark` then how should that be handled:

#### Defined in

[types/subscription.ts:96](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L96)
[types/subscription.ts:107](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L107)

___

Expand All @@ -131,7 +155,7 @@ Whether to wait via algod `/status/wait-for-block-after` endpoint when at the ti

#### Defined in

[types/subscription.ts:168](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L168)
[types/subscription.ts:179](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L179)

___

Expand All @@ -151,4 +175,4 @@ its position in the chain

#### Defined in

[types/subscription.ts:171](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L171)
[types/subscription.ts:182](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L182)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Common parameters to control a single subscription pull/poll for both `AlgorandS

- [arc28Events](types_subscription.CoreTransactionSubscriptionParams.md#arc28events)
- [filters](types_subscription.CoreTransactionSubscriptionParams.md#filters)
- [maxIndexerRoundsToSync](types_subscription.CoreTransactionSubscriptionParams.md#maxindexerroundstosync)
- [maxRoundsToSync](types_subscription.CoreTransactionSubscriptionParams.md#maxroundstosync)
- [syncBehaviour](types_subscription.CoreTransactionSubscriptionParams.md#syncbehaviour)

Expand Down Expand Up @@ -68,11 +69,30 @@ A list of filters with corresponding names.

___

### maxIndexerRoundsToSync

`Optional` **maxIndexerRoundsToSync**: `number`

The maximum number of rounds to sync from indexer when using `syncBehaviour: 'catchup-with-indexer'.

By default there is no limit and it will paginate through all of the rounds.
Sometimes this can result in an incredibly long catchup time that may break the service
due to execution and memory constraints, particularly for filters that result in a large number of transactions.

Instead, this allows indexer catchup to be split into multiple polls, each with a transactionally consistent
boundary based on the number of rounds specified here.

#### Defined in

[types/subscription.ts:89](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L89)

___

### maxRoundsToSync

`Optional` **maxRoundsToSync**: `number`

The maximum number of rounds to sync for each subscription pull/poll.
The maximum number of rounds to sync from algod for each subscription pull/poll.

Defaults to 500.

Expand Down Expand Up @@ -109,4 +129,4 @@ past `watermark` then how should that be handled:

#### Defined in

[types/subscription.ts:96](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L96)
[types/subscription.ts:107](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L107)
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The filter itself.

#### Defined in

[types/subscription.ts:104](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L104)
[types/subscription.ts:115](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L115)

___

Expand All @@ -41,4 +41,4 @@ The name to give the filter.

#### Defined in

[types/subscription.ts:102](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L102)
[types/subscription.ts:113](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L113)
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The filter itself.

#### Defined in

[types/subscription.ts:104](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L104)
[types/subscription.ts:115](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L115)

___

Expand Down Expand Up @@ -70,7 +70,7 @@ Note: if you provide multiple filters with the same name then only the mapper of

#### Defined in

[types/subscription.ts:187](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L187)
[types/subscription.ts:198](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L198)

___

Expand All @@ -86,4 +86,4 @@ The name to give the filter.

#### Defined in

[types/subscription.ts:102](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L102)
[types/subscription.ts:113](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L113)
30 changes: 15 additions & 15 deletions docs/code/interfaces/types_subscription.TransactionFilter.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Filter to app transactions that meet the given app arguments predicate.

#### Defined in

[types/subscription.ts:139](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L139)
[types/subscription.ts:150](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L150)

___

Expand All @@ -62,7 +62,7 @@ Filter to transactions that are creating an app.

#### Defined in

[types/subscription.ts:120](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L120)
[types/subscription.ts:131](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L131)

___

Expand All @@ -74,7 +74,7 @@ Filter to transactions against the app with the given ID.

#### Defined in

[types/subscription.ts:118](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L118)
[types/subscription.ts:129](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L129)

___

Expand All @@ -86,7 +86,7 @@ Filter to transactions that have given on complete(s).

#### Defined in

[types/subscription.ts:122](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L122)
[types/subscription.ts:133](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L133)

___

Expand All @@ -99,7 +99,7 @@ Note: the definitions for these events must be passed in to the subscription con

#### Defined in

[types/subscription.ts:143](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L143)
[types/subscription.ts:154](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L154)

___

Expand All @@ -111,7 +111,7 @@ Filter to transactions that are creating an asset.

#### Defined in

[types/subscription.ts:126](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L126)
[types/subscription.ts:137](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L137)

___

Expand All @@ -123,7 +123,7 @@ Filter to transactions against the asset with the given ID.

#### Defined in

[types/subscription.ts:124](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L124)
[types/subscription.ts:135](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L135)

___

Expand All @@ -136,7 +136,7 @@ or equal to the given maximum (microAlgos or decimal units of an ASA if type: ax

#### Defined in

[types/subscription.ts:132](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L132)
[types/subscription.ts:143](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L143)

___

Expand All @@ -149,7 +149,7 @@ the given method signature as the first app argument.

#### Defined in

[types/subscription.ts:135](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L135)
[types/subscription.ts:146](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L146)

___

Expand All @@ -161,7 +161,7 @@ Filter to app transactions that match one of the given ARC-0004 method selectors

#### Defined in

[types/subscription.ts:137](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L137)
[types/subscription.ts:148](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L148)

___

Expand All @@ -174,7 +174,7 @@ than or equal to the given minimum (microAlgos or decimal units of an ASA if typ

#### Defined in

[types/subscription.ts:129](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L129)
[types/subscription.ts:140](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L140)

___

Expand All @@ -186,7 +186,7 @@ Filter to transactions with a note having the given prefix.

#### Defined in

[types/subscription.ts:116](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L116)
[types/subscription.ts:127](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L127)

___

Expand All @@ -198,7 +198,7 @@ Filter to transactions being received by the specified address.

#### Defined in

[types/subscription.ts:114](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L114)
[types/subscription.ts:125](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L125)

___

Expand All @@ -210,7 +210,7 @@ Filter to transactions sent from the specified address.

#### Defined in

[types/subscription.ts:112](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L112)
[types/subscription.ts:123](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L123)

___

Expand All @@ -222,4 +222,4 @@ Filter based on the given transaction type.

#### Defined in

[types/subscription.ts:110](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L110)
[types/subscription.ts:121](https://github.com/algorandfoundation/algokit-subscriber-ts/blob/main/src/types/subscription.ts#L121)
Loading

0 comments on commit ae8c880

Please sign in to comment.