Skip to content

Commit

Permalink
default slot duration if not aura (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci authored Dec 28, 2022
1 parent 1678db6 commit 40172e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
run_task,
} from '@acala-network/chopsticks-executor'
import { defaultLogger, truncate, truncateStorageDiff } from './logger'
import { memoize } from 'lodash'

interface JsCallback {
getStorage: (key: HexString) => Promise<string | undefined>
Expand Down Expand Up @@ -125,7 +126,7 @@ export const emptyTaskHandler = {
},
}

export const getAuraSlotDuration = async (wasm: HexString, registry: Registry): Promise<number> => {
export const getAuraSlotDuration = memoize(async (wasm: HexString, registry: Registry): Promise<number> => {
const result = await runTask({
wasm,
calls: [['AuraApi_slot_duration', '0x']],
Expand All @@ -137,4 +138,4 @@ export const getAuraSlotDuration = async (wasm: HexString, registry: Registry):
if (!result.Call) throw new Error(result.Error)
const slotDuration = registry.createType('u64', hexToU8a(result.Call.result)).toNumber()
return slotDuration
}
})
4 changes: 3 additions & 1 deletion src/utils/time-travel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export const getSlotDuration = async (chain: Blockchain) => {
const meta = await chain.head.meta
return meta.consts.babe
? (meta.consts.babe.expectedBlockTime as any as BN).toNumber()
: getAuraSlotDuration(await chain.head.wasm, meta.registry)
: meta.query.aura
? getAuraSlotDuration(await chain.head.wasm, meta.registry)
: 12_000
}

export const timeTravel = async (chain: Blockchain, timestamp: number) => {
Expand Down

0 comments on commit 40172e7

Please sign in to comment.