Skip to content

Commit

Permalink
fix genesis (#624)
Browse files Browse the repository at this point in the history
* fix genesis

* udpate snapshot
  • Loading branch information
ermalkaleci authored Jan 9, 2024
1 parent 64b64a9 commit d7b476e
Show file tree
Hide file tree
Showing 13 changed files with 750 additions and 311 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
206 changes: 103 additions & 103 deletions packages/chopsticks/src/schema/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,107 +3,107 @@ import { expect, it } from 'vitest'

it('get yargs options from zod schema', () => {
expect(getYargsOptions(configSchema.shape)).toMatchInlineSnapshot(`
{
"allow-unresolved-imports": {
"choices": undefined,
"demandOption": false,
"description": undefined,
"type": "boolean",
},
"block": {
"choices": undefined,
"demandOption": false,
"description": "Block hash or block number. Default to latest block",
"type": "string",
},
"build-block-mode": {
"choices": [
"Batch",
"Instant",
"Manual",
],
"demandOption": false,
"description": undefined,
"type": undefined,
},
"db": {
"choices": undefined,
"demandOption": false,
"description": "Path to database",
"type": "string",
},
"endpoint": {
"choices": undefined,
"demandOption": false,
"description": "Endpoint to connect to",
"type": "string",
},
"genesis": {
"choices": undefined,
"demandOption": false,
"description": undefined,
"type": "string",
},
"import-storage": {
"choices": undefined,
"demandOption": false,
"description": "Pre-defined JSON/YAML storage file path",
"type": undefined,
},
"max-memory-block-count": {
"choices": undefined,
"demandOption": false,
"description": undefined,
"type": "number",
},
"mock-signature-host": {
"choices": undefined,
"demandOption": false,
"description": "Mock signature host so any signature starts with 0xdeadbeef and filled by 0xcd is considered valid",
"type": "boolean",
},
"offchain-worker": {
"choices": undefined,
"demandOption": false,
"description": "Enable offchain worker",
"type": "boolean",
},
"port": {
"choices": undefined,
"demandOption": false,
"description": "Port to listen on",
"type": "number",
},
"registered-types": {
"choices": undefined,
"demandOption": false,
"description": undefined,
"type": undefined,
},
"resume": {
"choices": undefined,
"demandOption": false,
"description": "Resume from the specified block hash or block number in db. If true, it will resume from the latest block in db. Note this will override the block option",
"type": "string",
},
"runtime-log-level": {
"choices": undefined,
"demandOption": false,
"description": "Runtime maximum log level [off = 0; error = 1; warn = 2; info = 3; debug = 4; trace = 5]",
"type": "number",
},
"timestamp": {
"choices": undefined,
"demandOption": false,
"description": undefined,
"type": "number",
},
"wasm-override": {
"choices": undefined,
"demandOption": false,
"description": "Path to wasm override",
"type": "string",
},
}
`)
{
"allow-unresolved-imports": {
"choices": undefined,
"demandOption": false,
"description": undefined,
"type": "boolean",
},
"block": {
"choices": undefined,
"demandOption": false,
"description": "Block hash or block number. Default to latest block",
"type": "string",
},
"build-block-mode": {
"choices": [
"Batch",
"Instant",
"Manual",
],
"demandOption": false,
"description": undefined,
"type": undefined,
},
"db": {
"choices": undefined,
"demandOption": false,
"description": "Path to database",
"type": "string",
},
"endpoint": {
"choices": undefined,
"demandOption": false,
"description": "Endpoint to connect to",
"type": "string",
},
"genesis": {
"choices": undefined,
"demandOption": false,
"description": "URL to genesis config file. NOTE: Only parachains with AURA consensus are supported!",
"type": "string",
},
"import-storage": {
"choices": undefined,
"demandOption": false,
"description": "Pre-defined JSON/YAML storage file path",
"type": undefined,
},
"max-memory-block-count": {
"choices": undefined,
"demandOption": false,
"description": undefined,
"type": "number",
},
"mock-signature-host": {
"choices": undefined,
"demandOption": false,
"description": "Mock signature host so any signature starts with 0xdeadbeef and filled by 0xcd is considered valid",
"type": "boolean",
},
"offchain-worker": {
"choices": undefined,
"demandOption": false,
"description": "Enable offchain worker",
"type": "boolean",
},
"port": {
"choices": undefined,
"demandOption": false,
"description": "Port to listen on",
"type": "number",
},
"registered-types": {
"choices": undefined,
"demandOption": false,
"description": undefined,
"type": undefined,
},
"resume": {
"choices": undefined,
"demandOption": false,
"description": "Resume from the specified block hash or block number in db. If true, it will resume from the latest block in db. Note this will override the block option",
"type": "string",
},
"runtime-log-level": {
"choices": undefined,
"demandOption": false,
"description": "Runtime maximum log level [off = 0; error = 1; warn = 2; info = 3; debug = 4; trace = 5]",
"type": "number",
},
"timestamp": {
"choices": undefined,
"demandOption": false,
"description": undefined,
"type": "number",
},
"wasm-override": {
"choices": undefined,
"demandOption": false,
"description": "Path to wasm override",
"type": "string",
},
}
`)
})
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 d7b476e

Please sign in to comment.