Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 5e5a3d8

Browse files
authored
feat: specify chain scan interval in seconds instead of minutes (#99)
Change `BLOCKCHAIN_SCAN_INTERVAL_MINUTES` to `BLOCKCHAIN_SCAN_INTERVAL_SECONDS`
1 parent 8131744 commit 5e5a3d8

File tree

9 files changed

+26
-25
lines changed

9 files changed

+26
-25
lines changed

.env.docker.dev

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ STARTING_BLOCK=1
2424
# Redis URL
2525
REDIS_URL=redis://redis:6379
2626

27-
# How many minutes to delay between successive scans of the chain
28-
# for new accounts (after end of chain is reached)
29-
BLOCKCHAIN_SCAN_INTERVAL_MINUTES=1
27+
# How many seconds to delay between successive scans of the chain
28+
# for new content (after end of chain is reached)
29+
BLOCKCHAIN_SCAN_INTERVAL_SECONDS=12
3030

3131
# Max number of jobs allowed on the queue before
3232
# blockchain scan will be paused to allow queue to drain

ENVIRONMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This application recognizes the following environment variables:
55
| Name | Description | Range/Type | Required? | Default |
66
| ---------------------------------- | ------------------------------------------------------------------------------------------------------------------ | :--------------------: | :-------: | :-----: |
77
| `API_PORT` | HTTP port that the application listens on | 1025 - 65535 | | 3000 |
8-
| `BLOCKCHAIN_SCAN_INTERVAL_MINUTES` | How many minutes to delay between successive scans of the chain for new accounts (after end of chain is reached) | > 0 | | 180 |
8+
| `BLOCKCHAIN_SCAN_INTERVAL_SECONDS` | How many seconds to delay between successive scans of the chain for new content (after end of chain is reached) | > 0 | | 12 |
99
| `FREQUENCY_URL` | Blockchain node address | http(s): or ws(s): URL | Y | |
1010
| `IPFS_BASIC_AUTH_SECRET` | If required for read requests, put Infura auth token here, or leave blank for default Kubo RPC | string | N | blank |
1111
| `IPFS_BASIC_AUTH_USER` | If required for read requests, put Infura Project ID here, or leave blank for default Kubo RPC | string | N | blank |

INSTALLING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ The following is a list of environment variables that may be set to control the
6161
|`FREQUENCY_URL`|**yes**|Blockchain URL|_none_|
6262
|`STARTING_BLOCK`|**maybe**|Starting block for scanner to scan from|_none_|
6363
|`REDIS_URL`|**yes**|URL used to connect to Redis instance|_none_<br/>\*preset to the internal Redis URL in the standalone container|
64-
|`BLOCKCHAIN_SCAN_INTERVAL_MINUTES`|no|# of minutes to wait in between scans of the blockchain|180|
64+
|`BLOCKCHAIN_SCAN_INTERVAL_SECONDS`|no|# of seconds to wait in between scans of the blockchain|12|
6565
|`QUEUE_HIGH_WATER`|no|# of pending queue entries to allow before pausing blockchain scanning until the next scan cycle|1000|

docker-compose.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ x-content-watcher-environment: &content-watcher-environment
33
FREQUENCY_URL: 'ws://frequency:9944'
44
STARTING_BLOCK: 1
55
REDIS_URL: 'redis://redis:6379'
6-
BLOCKCHAIN_SCAN_INTERVAL_MINUTES: 1
6+
BLOCKCHAIN_SCAN_INTERVAL_SECONDS: 12
77
QUEUE_HIGH_WATER: 1000
88
WEBHOOK_FAILURE_THRESHOLD: 4
99
WEBHOOK_RETRY_INTERVAL_SECONDS: 10
1010
API_PORT: 3000
1111
CAPACITY_LIMIT: '{"type":"percentage", "value":80}'
1212
IPFS_ENDPOINT: 'http://ipfs:5001'
13-
13+
1414
services:
1515
redis:
1616
image: redis:latest
@@ -28,9 +28,9 @@ services:
2828
platform: linux/amd64
2929
# Uncomment SEALING_MODE and SEALING_INTERVAL if you want to use interval sealing.
3030
# Other options you may want to add depending on your test scenario.
31-
# environment:
32-
# - SEALING_MODE=interval
33-
# - SEALING_INTERVAL=3
31+
environment:
32+
- SEALING_MODE=interval
33+
- SEALING_INTERVAL=1
3434
# - CREATE_EMPTY_BLOCKS=true
3535
# Uncomment below if you want to let the chain run and keep all of the historical blocks
3636
# command: --state-pruning=archive

env.template

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ STARTING_BLOCK=1
2323
# Redis URL
2424
REDIS_URL=redis://0.0.0.0:6379
2525

26-
# How many minutes to delay between successive scans of the chain
27-
# for new accounts (after end of chain is reached)
28-
BLOCKCHAIN_SCAN_INTERVAL_MINUTES=1
26+
# How many seconds to delay between successive scans of the chain
27+
# for new content (after end of chain is reached)
28+
BLOCKCHAIN_SCAN_INTERVAL_SECONDS=12
2929

3030
# Max number of jobs allowed on the queue before
3131
# blockchain scan will be paused to allow queue to drain

libs/common/src/config/config.service.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('ContentWatcherConfigService', () => {
4040
IPFS_GATEWAY_URL: undefined,
4141
IPFS_BASIC_AUTH_USER: undefined,
4242
IPFS_BASIC_AUTH_SECRET: undefined,
43-
BLOCKCHAIN_SCAN_INTERVAL_MINUTES: undefined,
43+
BLOCKCHAIN_SCAN_INTERVAL_SECONDS: undefined,
4444
QUEUE_HIGH_WATER: undefined,
4545
WEBHOOK_FAILURE_THRESHOLD: undefined,
4646
WEBHOOK_RETRY_INTERVAL_SECONDS: undefined,
@@ -75,10 +75,10 @@ describe('ContentWatcherConfigService', () => {
7575
});
7676

7777
it('invalid scan interval should fail', async () => {
78-
const { BLOCKCHAIN_SCAN_INTERVAL_MINUTES: dummy, ...env } = ALL_ENV;
79-
await expect(setupConfigService({ BLOCKCHAIN_SCAN_INTERVAL_MINUTES: -1, ...env })).rejects.toBeDefined();
80-
await expect(setupConfigService({ BLOCKCHAIN_SCAN_INTERVAL_MINUTES: 0, ...env })).rejects.toBeDefined();
81-
await expect(setupConfigService({ BLOCKCHAIN_SCAN_INTERVAL_MINUTES: 'foo', ...env })).rejects.toBeDefined();
78+
const { BLOCKCHAIN_SCAN_INTERVAL_SECONDS: dummy, ...env } = ALL_ENV;
79+
await expect(setupConfigService({ BLOCKCHAIN_SCAN_INTERVAL_SECONDS: -1, ...env })).rejects.toBeDefined();
80+
await expect(setupConfigService({ BLOCKCHAIN_SCAN_INTERVAL_SECONDS: 0, ...env })).rejects.toBeDefined();
81+
await expect(setupConfigService({ BLOCKCHAIN_SCAN_INTERVAL_SECONDS: 'foo', ...env })).rejects.toBeDefined();
8282
});
8383

8484
it('invalid queue high water should fail', async () => {
@@ -113,7 +113,7 @@ describe('ContentWatcherConfigService', () => {
113113
});
114114

115115
it('should get scan interval', () => {
116-
expect(contentWatcherConfigService.blockchainScanIntervalMinutes).toStrictEqual(parseInt(ALL_ENV.BLOCKCHAIN_SCAN_INTERVAL_MINUTES as string, 10));
116+
expect(contentWatcherConfigService.blockchainScanIntervalSeconds).toStrictEqual(parseInt(ALL_ENV.BLOCKCHAIN_SCAN_INTERVAL_SECONDS as string));
117117
});
118118

119119
it('should get queue high water mark', () => {

libs/common/src/config/config.service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
12
/*
23
https://docs.nestjs.com/providers#services
34
*/
@@ -13,7 +14,7 @@ export interface ConfigEnvironmentVariables {
1314
REDIS_URL: URL;
1415
FREQUENCY_URL: URL;
1516
STARTING_BLOCK: string;
16-
BLOCKCHAIN_SCAN_INTERVAL_MINUTES: number;
17+
BLOCKCHAIN_SCAN_INTERVAL_SECONDS: number;
1718
QUEUE_HIGH_WATER: number;
1819
WEBHOOK_FAILURE_THRESHOLD: number;
1920
WEBHOOK_RETRY_INTERVAL_SECONDS: number;
@@ -41,8 +42,8 @@ export class ConfigService {
4142
return this.nestConfigService.get<number>('STARTING_BLOCK')!;
4243
}
4344

44-
public get blockchainScanIntervalMinutes(): number {
45-
return this.nestConfigService.get<number>('BLOCKCHAIN_SCAN_INTERVAL_MINUTES') ?? 1;
45+
public get blockchainScanIntervalSeconds(): number {
46+
return this.nestConfigService.get<number>('BLOCKCHAIN_SCAN_INTERVAL_SECONDS') ?? 12;
4647
}
4748

4849
public get queueHighWater(): number {

libs/common/src/config/env.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export const configModuleOptions: ConfigModuleOptions = {
1111
REDIS_URL: Joi.string().uri().required(),
1212
FREQUENCY_URL: Joi.string().uri().required(),
1313
STARTING_BLOCK: Joi.number().min(1),
14-
BLOCKCHAIN_SCAN_INTERVAL_MINUTES: Joi.number()
14+
BLOCKCHAIN_SCAN_INTERVAL_SECONDS: Joi.number()
1515
.min(1)
16-
.default(3 * 60),
16+
.default(12),
1717
QUEUE_HIGH_WATER: Joi.number().min(100).default(1000),
1818
WEBHOOK_FAILURE_THRESHOLD: Joi.number().min(0).default(3),
1919
WEBHOOK_RETRY_INTERVAL_SECONDS: Joi.number().min(1).default(10),

libs/common/src/scanner/scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class ScannerService implements OnApplicationBootstrap, OnApplicationShut
4646
}
4747
setImmediate(() => this.scan());
4848

49-
const scanInterval = this.configService.blockchainScanIntervalMinutes * SECONDS_PER_MINUTE * MILLISECONDS_PER_SECOND;
49+
const scanInterval = this.configService.blockchainScanIntervalSeconds * MILLISECONDS_PER_SECOND;
5050
this.schedulerRegistry.addInterval(
5151
INTERVAL_SCAN_NAME,
5252
setInterval(() => this.scan(), scanInterval),

0 commit comments

Comments
 (0)