Skip to content

Commit

Permalink
fix: override storage after load blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
qiweiii committed Sep 11, 2023
1 parent 42b9727 commit 93fdf52
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions packages/chopsticks/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,12 @@ export const setupContext = async (argv: Config, overrideParent = false) => {
maxMemoryBlockCount: argv['max-memory-block-count'],
})

if (argv.timestamp) await timeTravel(chain, argv.timestamp)

let at: HexString | undefined
if (overrideParent) {
// in case of run block we need to apply wasm-override and import-storage to parent block
const block = await chain.head.parentBlock
if (!block) throw new Error('Cannot find parent block')
at = block.hash
}

// override wasm before importing storage, in case new pallets have been
// added that have storage imports
await overrideStorage(chain, argv['import-storage'], at)
await overrideWasm(chain, argv['wasm-override'], at)

// load blocks from db
if (chain.db) {
if (argv.resume) {
const blocks = await chain.db.getRepository(BlockEntity).find({ where: {}, order: { number: 'asc' } })
// validate the first block in db is chain.head+1 and db blocks are consecutive
const canResume = blocks.every((block, index) => block.number === chain.head.number + index + 1)
const canResume = blocks.length && blocks.every((block, index) => block.number === chain.head.number + index + 1)
if (canResume) {
let head
for (const block of blocks) {
Expand All @@ -54,5 +39,20 @@ export const setupContext = async (argv: Config, overrideParent = false) => {
}
}

if (argv.timestamp) await timeTravel(chain, argv.timestamp)

let at: HexString | undefined
if (overrideParent) {
// in case of run block we need to apply wasm-override and import-storage to parent block
const block = await chain.head.parentBlock
if (!block) throw new Error('Cannot find parent block')
at = block.hash
}

// override wasm before importing storage, in case new pallets have been
// added that have storage imports
await overrideStorage(chain, argv['import-storage'], at)
await overrideWasm(chain, argv['wasm-override'], at)

return { chain }
}

0 comments on commit 93fdf52

Please sign in to comment.