Skip to content

Commit

Permalink
fix genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci committed Jan 8, 2024
1 parent ed77173 commit 95aff9b
Show file tree
Hide file tree
Showing 12 changed files with 647 additions and 208 deletions.
6 changes: 5 additions & 1 deletion packages/chopsticks/src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export const configSchema = z.object({
'max-memory-block-count': z.number().optional(),
db: z.string({ description: 'Path to database' }).optional(),
'wasm-override': z.string({ description: 'Path to wasm override' }).optional(),
genesis: z.union([z.string(), genesisSchema]).optional(),
genesis: z
.union([z.string(), genesisSchema], {
description: 'URL to genesis config file. NOTE: Only parachains with AURA consensus are supported!',
})
.optional(),
timestamp: z.number().optional(),
'registered-types': z.any().optional(),
'runtime-log-level': z
Expand Down
5 changes: 0 additions & 5 deletions packages/chopsticks/src/setup-with-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import { setupContext } from './context.js'
export const setupWithServer = async (argv: Config) => {
const context = await setupContext(argv)

if (argv.genesis) {
// mine 1st block when starting from genesis to set some mock validation data
await context.chain.newBlock()
}

const { close, port: listenPort } = await createServer(handler(context), argv.port)

defaultLogger.info(`${await context.chain.api.getSystemChain()} RPC listening on port ${listenPort}`)
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/blockchain/block-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ const initNewBlock = async (
const resp = await newBlock.call('Core_initialize_block', [header.toHex()])
newBlock.pushStorageLayer().setAll(resp.storageDiff)

if (head.number === 0) {
// set parent hash for genesis block
// this makes sure to override the default parent hash
const meta = await head.meta
const header = await head.header
newBlock.pushStorageLayer().setAll([[compactHex(meta.query.system.parentHash()), header.hash.toHex()]])
}

callback?.onPhaseApplied?.('initialize', resp)
}

Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/blockchain/inherent/para-enter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ export class ParaInherentEnter implements CreateInherents {
return []
}

if (parent.number === 0) {
return [
new GenericExtrinsic(
meta.registry,
meta.tx.paraInherent.enter({
parentHeader: (await parent.header).toJSON(),
}),
).toHex(),
]
}

const extrinsics = await parent.extrinsics

const paraEnterExtrinsic = extrinsics.find((extrinsic) => {
Expand Down
Loading

0 comments on commit 95aff9b

Please sign in to comment.