Skip to content

Commit

Permalink
refactor!: rename intervalMsMin -> pollingInterval; blockIntervalMs -…
Browse files Browse the repository at this point in the history
…> blockInterval
  • Loading branch information
nom4dv3 committed Aug 13, 2024
1 parent 3ee62f0 commit 262706e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/orap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const eventSignalParam = {
const handle = (...args: any) => { console.log('handle', args) }

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

orap.listen(
{ wsProvider: 'wss://127.0.0.1', httpProvider: 'http://127.0.0.1' },
Expand Down
4 changes: 2 additions & 2 deletions packages/orap/signal/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class EventSignal implements Signal {
// TODO: hide address & topics & onMissingLog from interface AutoCrossCheckParam
crosscheck(options?: Omit<AutoCrossCheckParam, 'address' | 'topics' | 'onMissingLog'>) {
const {
intervalMsMin = ONE_MINUTE_MS * 60,
pollingInterval = ONE_MINUTE_MS * 60,
ignoreLogs = [],
} = options ?? {}
// save crosschecker param
Expand All @@ -106,7 +106,7 @@ export class EventSignal implements Signal {
address: this.params.address,
topics: [this.esig],
onMissingLog: this.crosscheckCallback,
intervalMsMin,
pollingInterval,
ignoreLogs,
}
return this
Expand Down
6 changes: 3 additions & 3 deletions packages/reku/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ i.e. It starts with 'realtime' mode by default.
Options:
- `store`?: the Store used to cache the <txhash, logindex> that already processed.
- `batchBlocksCount`?: how many blocks to get per `getLogs` check, in readtime mode it waits until the new block num >= `batchBlocksCount`.
- `intervalMsMin`?: mostly for limiting getLogs calling rate in catchup mode; how long does it take at least between 2 checks
- `blockIntervalMs`?: the block interval (in ms) of the given chain, default: 12000 for eth
- `pollingInterval`?: how long does it take between 2 block height check polling checks; mostly for limiting getLogs calling rate in catchup mode
- `blockInterval`?: the block interval (in ms) of the given chain, default: 12000 for eth
- `delayBlockFromLatest`?: mostly for realtime mode; each time cc wait until `latest height > toBlock + delayBlockFromLatest`
- `fromBlock`?: once specified, it means start catching up from historical blocks
- `toBlock`?: once specified, it means the crosscheck isn't infinite and will end at this height; need `fromBlock` present if this set
Expand All @@ -44,6 +44,6 @@ await acc.start({
address: CONTRACT_ADDRESS,
topics,
batchBlocksCount: 1,
intervalMsMin: 3000,
pollingInterval: 3000,
})
```
2 changes: 1 addition & 1 deletion packages/reku/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const ETH_BLOCK_COUNT_ONE_HOUR = (60 / 12) * 60
export const ETH_BLOCK_INTERVAL_MS = 12 * 1000
export const ETH_BLOCK_INTERVAL = 12 * 1000 // 12 sec in ms
export const ONE_MINUTE_MS = 60 * 1000
24 changes: 12 additions & 12 deletions packages/reku/event/crosschecker/autochecker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ethers } from 'ethers'
import { polling, retryOnNull, sleep } from '@ora-io/utils'
import { ETH_BLOCK_INTERVAL_MS } from '../../constants'
import { ETH_BLOCK_INTERVAL } from '../../constants'
import type { Providers } from '../../types/w3'
import { CrossCheckerCacheManager } from './cache/manager'
import type { AutoCrossCheckParam, CrossCheckRangeParam } from './interface'
Expand All @@ -20,8 +20,8 @@ export class AutoCrossChecker extends BaseCrossChecker {
}

validate(options: AutoCrossCheckParam) {
const { batchBlocksCount, toBlock, fromBlock, intervalMsMin, blockIntervalMs } = options
const defaultBlockIntervalMs = ETH_BLOCK_INTERVAL_MS
const { batchBlocksCount, toBlock, fromBlock, pollingInterval, blockInterval } = options
const defaultBlockInterval = ETH_BLOCK_INTERVAL

if (batchBlocksCount !== undefined) {
if (batchBlocksCount <= 0)
Expand All @@ -36,10 +36,10 @@ export class AutoCrossChecker extends BaseCrossChecker {
throw new Error('options invalid: should fromBlock <= toBlock')
}
else { // only throw in realtime mode
if (intervalMsMin !== undefined && batchBlocksCount !== undefined) {
const intervalLimit = batchBlocksCount * (blockIntervalMs ?? defaultBlockIntervalMs)
if (intervalMsMin > intervalLimit)
throw new Error('options invalid: should intervalMsMin <= batchBlocksCount * blockIntervalMs when no toBlock present, otherwise crosscheck will never catch up with the latest')
if (pollingInterval !== undefined && batchBlocksCount !== undefined) {
const intervalLimit = batchBlocksCount * (blockInterval ?? defaultBlockInterval)
if (pollingInterval > intervalLimit)
throw new Error('options invalid: should pollingInterval <= batchBlocksCount * blockInterval when no toBlock present, otherwise crosscheck will never catch up with the latest')
}
}
}
Expand All @@ -56,8 +56,8 @@ export class AutoCrossChecker extends BaseCrossChecker {
const {
fromBlock = latestblocknum,
batchBlocksCount = 10,
intervalMsMin = 1000,
blockIntervalMs = ETH_BLOCK_INTERVAL_MS,
pollingInterval = 1000,
blockInterval = ETH_BLOCK_INTERVAL,
delayBlockFromLatest = 1,
toBlock, ignoreLogs,
} = options
Expand Down Expand Up @@ -95,8 +95,8 @@ export class AutoCrossChecker extends BaseCrossChecker {
this.logger.info('[*] ccrOptions: fromBlock', ccrOptions.fromBlock, ', toBlock', ccrOptions.toBlock, ', latestblocknum', latestblocknum)
if (ccrOptions.toBlock + delayBlockFromLatest > latestblocknum) {
// sleep until the toBlock
this.logger.debug('sleep until the latestblocknum >= toBlock + delayBlockFromLatest, i.e.', (ccrOptions.toBlock + delayBlockFromLatest - latestblocknum) * blockIntervalMs, 'ms')
await sleep((ccrOptions.toBlock + delayBlockFromLatest - latestblocknum) * blockIntervalMs)
this.logger.debug('sleep until the latestblocknum >= toBlock + delayBlockFromLatest, i.e.', (ccrOptions.toBlock + delayBlockFromLatest - latestblocknum) * blockInterval, 'ms')
await sleep((ccrOptions.toBlock + delayBlockFromLatest - latestblocknum) * blockInterval)
return false
}
return true
Expand All @@ -123,6 +123,6 @@ export class AutoCrossChecker extends BaseCrossChecker {
}

return endingCondition()
}, intervalMsMin)
}, pollingInterval)
}
}
6 changes: 3 additions & 3 deletions packages/reku/event/crosschecker/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export interface CrossCheckRetroParam extends BaseCrossCheckParam {
retroBlockCount: number
}

// TODO: use rpc to calc blockIntervalMs
// TODO: use rpc to calc blockInterval
export interface AutoCrossCheckParam extends BaseCrossCheckParam {
store?: Store
batchBlocksCount?: number // how many blocks at most to get per check
intervalMsMin?: number // mostly for limiting getLogs calling rate in catchup mode; how long does it take at least between 2 checks
blockIntervalMs?: number // the block interval of the given chain, default: eth
pollingInterval?: number // mostly for limiting getLogs calling rate in catchup mode; how long does it take at least between 2 checks
blockInterval?: number // the block interval of the given chain, default: eth
delayBlockFromLatest?: number // mostly for realtime mode; each time cc wait until latest height > toBlock + delayBlockFromLatest
}
2 changes: 1 addition & 1 deletion packages/reku/tests/crosscheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function crossCheckerTest() {
address: CONTRACT_ADDRESS,
topics,
batchBlocksCount: 1,
intervalMsMin: 3000,
pollingInterval: 3000,
})
}

Expand Down

0 comments on commit 262706e

Please sign in to comment.