Skip to content

Commit 262706e

Browse files
committed
refactor!: rename intervalMsMin -> pollingInterval; blockIntervalMs -> blockInterval
1 parent 3ee62f0 commit 262706e

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

packages/orap/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const eventSignalParam = {
2222
const handle = (...args: any) => { console.log('handle', args) }
2323

2424
orap.event(eventSignalParam, handle)
25-
.crosscheck({ intervalMsMin: 1000, batchBlocksCount: 1, blockIntervalMs: 12000 })
25+
.crosscheck({ pollingInterval: 1000, batchBlocksCount: 1, blockInterval: 12000 })
2626

2727
orap.listen(
2828
{ wsProvider: 'wss://127.0.0.1', httpProvider: 'http://127.0.0.1' },

packages/orap/signal/event.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class EventSignal implements Signal {
9797
// TODO: hide address & topics & onMissingLog from interface AutoCrossCheckParam
9898
crosscheck(options?: Omit<AutoCrossCheckParam, 'address' | 'topics' | 'onMissingLog'>) {
9999
const {
100-
intervalMsMin = ONE_MINUTE_MS * 60,
100+
pollingInterval = ONE_MINUTE_MS * 60,
101101
ignoreLogs = [],
102102
} = options ?? {}
103103
// save crosschecker param
@@ -106,7 +106,7 @@ export class EventSignal implements Signal {
106106
address: this.params.address,
107107
topics: [this.esig],
108108
onMissingLog: this.crosscheckCallback,
109-
intervalMsMin,
109+
pollingInterval,
110110
ignoreLogs,
111111
}
112112
return this

packages/reku/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ i.e. It starts with 'realtime' mode by default.
2727
Options:
2828
- `store`?: the Store used to cache the <txhash, logindex> that already processed.
2929
- `batchBlocksCount`?: how many blocks to get per `getLogs` check, in readtime mode it waits until the new block num >= `batchBlocksCount`.
30-
- `intervalMsMin`?: mostly for limiting getLogs calling rate in catchup mode; how long does it take at least between 2 checks
31-
- `blockIntervalMs`?: the block interval (in ms) of the given chain, default: 12000 for eth
30+
- `pollingInterval`?: how long does it take between 2 block height check polling checks; mostly for limiting getLogs calling rate in catchup mode
31+
- `blockInterval`?: the block interval (in ms) of the given chain, default: 12000 for eth
3232
- `delayBlockFromLatest`?: mostly for realtime mode; each time cc wait until `latest height > toBlock + delayBlockFromLatest`
3333
- `fromBlock`?: once specified, it means start catching up from historical blocks
3434
- `toBlock`?: once specified, it means the crosscheck isn't infinite and will end at this height; need `fromBlock` present if this set
@@ -44,6 +44,6 @@ await acc.start({
4444
address: CONTRACT_ADDRESS,
4545
topics,
4646
batchBlocksCount: 1,
47-
intervalMsMin: 3000,
47+
pollingInterval: 3000,
4848
})
4949
```

packages/reku/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const ETH_BLOCK_COUNT_ONE_HOUR = (60 / 12) * 60
2-
export const ETH_BLOCK_INTERVAL_MS = 12 * 1000
2+
export const ETH_BLOCK_INTERVAL = 12 * 1000 // 12 sec in ms
33
export const ONE_MINUTE_MS = 60 * 1000

packages/reku/event/crosschecker/autochecker.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ethers } from 'ethers'
22
import { polling, retryOnNull, sleep } from '@ora-io/utils'
3-
import { ETH_BLOCK_INTERVAL_MS } from '../../constants'
3+
import { ETH_BLOCK_INTERVAL } from '../../constants'
44
import type { Providers } from '../../types/w3'
55
import { CrossCheckerCacheManager } from './cache/manager'
66
import type { AutoCrossCheckParam, CrossCheckRangeParam } from './interface'
@@ -20,8 +20,8 @@ export class AutoCrossChecker extends BaseCrossChecker {
2020
}
2121

2222
validate(options: AutoCrossCheckParam) {
23-
const { batchBlocksCount, toBlock, fromBlock, intervalMsMin, blockIntervalMs } = options
24-
const defaultBlockIntervalMs = ETH_BLOCK_INTERVAL_MS
23+
const { batchBlocksCount, toBlock, fromBlock, pollingInterval, blockInterval } = options
24+
const defaultBlockInterval = ETH_BLOCK_INTERVAL
2525

2626
if (batchBlocksCount !== undefined) {
2727
if (batchBlocksCount <= 0)
@@ -36,10 +36,10 @@ export class AutoCrossChecker extends BaseCrossChecker {
3636
throw new Error('options invalid: should fromBlock <= toBlock')
3737
}
3838
else { // only throw in realtime mode
39-
if (intervalMsMin !== undefined && batchBlocksCount !== undefined) {
40-
const intervalLimit = batchBlocksCount * (blockIntervalMs ?? defaultBlockIntervalMs)
41-
if (intervalMsMin > intervalLimit)
42-
throw new Error('options invalid: should intervalMsMin <= batchBlocksCount * blockIntervalMs when no toBlock present, otherwise crosscheck will never catch up with the latest')
39+
if (pollingInterval !== undefined && batchBlocksCount !== undefined) {
40+
const intervalLimit = batchBlocksCount * (blockInterval ?? defaultBlockInterval)
41+
if (pollingInterval > intervalLimit)
42+
throw new Error('options invalid: should pollingInterval <= batchBlocksCount * blockInterval when no toBlock present, otherwise crosscheck will never catch up with the latest')
4343
}
4444
}
4545
}
@@ -56,8 +56,8 @@ export class AutoCrossChecker extends BaseCrossChecker {
5656
const {
5757
fromBlock = latestblocknum,
5858
batchBlocksCount = 10,
59-
intervalMsMin = 1000,
60-
blockIntervalMs = ETH_BLOCK_INTERVAL_MS,
59+
pollingInterval = 1000,
60+
blockInterval = ETH_BLOCK_INTERVAL,
6161
delayBlockFromLatest = 1,
6262
toBlock, ignoreLogs,
6363
} = options
@@ -95,8 +95,8 @@ export class AutoCrossChecker extends BaseCrossChecker {
9595
this.logger.info('[*] ccrOptions: fromBlock', ccrOptions.fromBlock, ', toBlock', ccrOptions.toBlock, ', latestblocknum', latestblocknum)
9696
if (ccrOptions.toBlock + delayBlockFromLatest > latestblocknum) {
9797
// sleep until the toBlock
98-
this.logger.debug('sleep until the latestblocknum >= toBlock + delayBlockFromLatest, i.e.', (ccrOptions.toBlock + delayBlockFromLatest - latestblocknum) * blockIntervalMs, 'ms')
99-
await sleep((ccrOptions.toBlock + delayBlockFromLatest - latestblocknum) * blockIntervalMs)
98+
this.logger.debug('sleep until the latestblocknum >= toBlock + delayBlockFromLatest, i.e.', (ccrOptions.toBlock + delayBlockFromLatest - latestblocknum) * blockInterval, 'ms')
99+
await sleep((ccrOptions.toBlock + delayBlockFromLatest - latestblocknum) * blockInterval)
100100
return false
101101
}
102102
return true
@@ -123,6 +123,6 @@ export class AutoCrossChecker extends BaseCrossChecker {
123123
}
124124

125125
return endingCondition()
126-
}, intervalMsMin)
126+
}, pollingInterval)
127127
}
128128
}

packages/reku/event/crosschecker/interface.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ export interface CrossCheckRetroParam extends BaseCrossCheckParam {
2929
retroBlockCount: number
3030
}
3131

32-
// TODO: use rpc to calc blockIntervalMs
32+
// TODO: use rpc to calc blockInterval
3333
export interface AutoCrossCheckParam extends BaseCrossCheckParam {
3434
store?: Store
3535
batchBlocksCount?: number // how many blocks at most to get per check
36-
intervalMsMin?: number // mostly for limiting getLogs calling rate in catchup mode; how long does it take at least between 2 checks
37-
blockIntervalMs?: number // the block interval of the given chain, default: eth
36+
pollingInterval?: number // mostly for limiting getLogs calling rate in catchup mode; how long does it take at least between 2 checks
37+
blockInterval?: number // the block interval of the given chain, default: eth
3838
delayBlockFromLatest?: number // mostly for realtime mode; each time cc wait until latest height > toBlock + delayBlockFromLatest
3939
}

packages/reku/tests/crosscheck.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export async function crossCheckerTest() {
4949
address: CONTRACT_ADDRESS,
5050
topics,
5151
batchBlocksCount: 1,
52-
intervalMsMin: 3000,
52+
pollingInterval: 3000,
5353
})
5454
}
5555

0 commit comments

Comments
 (0)