Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions packages/core/src/blockchain/inherent/parachain/validation-data.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { GenericExtrinsic } from '@polkadot/types'
import type { AbridgedHrmpChannel, HrmpChannelId, Slot } from '@polkadot/types/interfaces'
import { type BN, hexToU8a, u8aConcat, u8aToHex } from '@polkadot/util'
import { hexToU8a, u8aConcat, u8aToHex } from '@polkadot/util'
import type { HexString } from '@polkadot/util/types'
import { blake2AsHex, blake2AsU8a } from '@polkadot/util-crypto'
import _ from 'lodash'
import { defaultLogger } from '../../../logger.js'
import { compactHex, getCurrentSlot, getParaId } from '../../../utils/index.js'
import { compactHex, getCurrentSlot, getParaId, getSlotDuration } from '../../../utils/index.js'
import {
dmqMqcHead,
hrmpChannels,
Expand All @@ -22,6 +22,7 @@ import type { InherentProvider } from '../index.js'

const logger = defaultLogger.child({ name: 'parachain-validation-data' })

const RELAY_CHAIN_SLOT_DURATION_MILLIS: number = 6_000
const MOCK_VALIDATION_DATA = {
validationData: {
relayParentNumber: 1000,
Expand Down Expand Up @@ -140,24 +141,16 @@ export class SetValidationData implements InherentProvider {
extrinsic.relayChainState.trieNodes,
)

const relaySlotIncrease = Math.max(
1, // min
(meta.consts.timestamp?.minimumPeriod as any as BN) // legacy
?.divn(3000) // relaychain min period
?.toNumber() ||
(meta.consts.aura?.slotDuration as any as BN) // async backing
?.divn(6000) // relaychain block time
?.toNumber() ||
1,
)
const slotDuration = await getSlotDuration(newBlock)
const relaySlotIncrease = Math.trunc(slotDuration / RELAY_CHAIN_SLOT_DURATION_MILLIS) || 1 // at least increase by 1

for (const key of Object.values(WELL_KNOWN_KEYS)) {
if (key === WELL_KNOWN_KEYS.CURRENT_SLOT) {
// increment current slot
const relayCurrentSlot = decoded[key]
? meta.registry.createType<Slot>('Slot', hexToU8a(decoded[key])).toNumber()
: (await getCurrentSlot(parent)) * relaySlotIncrease
const newSlot = meta.registry.createType<Slot>('Slot', relayCurrentSlot + relaySlotIncrease + 1) // +1 to be safe
const newSlot = meta.registry.createType<Slot>('Slot', relayCurrentSlot + relaySlotIncrease)
logger.debug({ relayCurrentSlot, newSlot: newSlot.toNumber() }, 'Updating relay current slot')
newEntries.push([key, u8aToHex(newSlot.toU8a())])
} else {
Expand Down
48 changes: 24 additions & 24 deletions packages/e2e/src/__snapshots__/author.test.ts.snap

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions packages/e2e/src/__snapshots__/chain.test.ts.snap

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/e2e/src/block.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ describe('block', async () => {

const head = chain.head
const newBlock = await chain.newBlock()
expect(newBlock.hash).toMatchInlineSnapshot(`"0xb20b7e701f6a6e9e700a8f81849d59241f7ae51e08260491292f34bc9d06b2ba"`)
expect(newBlock.hash).toMatchInlineSnapshot(`"0xfca2b29b2ef3e018b87ce56dfa6200d973201222cbb67dde3aca6db905b440cc"`)

await chain.setHead(head)
await api.tx.system.remark('test').signAndSend(alice)
const newBlock2 = await chain.newBlock()
expect(newBlock2.hash).toMatchInlineSnapshot(`"0x9f8ec5d13ff39c5ab53fd8dc3bf2ce3f65bf5ddf86865eb8e9fea904c0bff45d"`)
expect(newBlock2.hash).toMatchInlineSnapshot(`"0xbf570d4c473241efbc4ffe08145e074e3f22b1f40dc2fac8108912bec8ac845e"`)
})
})
2 changes: 1 addition & 1 deletion packages/e2e/src/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('dev rpc', async () => {
expect((await api.rpc.chain.getBlockHash()).toHex()).toBe(hash)
await dev.setHead(blockNumber - 3)
expect((await api.rpc.chain.getBlockHash()).toHex()).toMatchInlineSnapshot(
`"0xa9af3bba23e0ffca832dbaa7fc28d04764d50ccbe52370717dcc5c9126060628"`,
`"0xc67fac55f8f2e1ba8f3b7d277d3097fd796216998bd6b1bfd8fd9aed87da579d"`,
)
await dev.setHead(-3)
expect((await api.rpc.chain.getBlockHash()).toHex()).toMatchInlineSnapshot(
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e/src/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('storage', () => {

tick = next()
expect(await dev.newBlock()).toMatchInlineSnapshot(
`"0xd93ac4e1814b874c059e647b9726f38c7f42ec673e171572d8e38992f6072b77"`,
`"0x3ee18ba950984f5ed8c6c6d407784c551aea7471ba1000f74998ebd5a3fbc9bf"`,
)
await tick

Expand All @@ -84,7 +84,7 @@ describe('storage', () => {
unsub()

expect(await dev.newBlock()).toMatchInlineSnapshot(
`"0xf9c6e17a227e188f64338f72626f44a84a55c3b959d9305db309bbed05f76de1"`,
`"0x1950829c5687d921d786c184dae9eb20ae55d2020b07adafcb1cfb1a5be4212f"`,
)

await delay(100)
Expand Down
8 changes: 4 additions & 4 deletions packages/web-test/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test.describe('index', () => {
})
return block.result.hash
})
expect(savedHash).toBe('0x64809750cb08df1076b3470ce42a0d1e1d45984d59bcfc876ce2d3424fd5416d')
expect(savedHash).toBe('0x7403a6c53702bfbace9737a5b3cc84fd02d5f8b30259e718455738ae841d992b')
})

test('dry run extrinsic', async ({ page }) => {
Expand Down Expand Up @@ -63,14 +63,14 @@ test.describe('index', () => {
expect(hightestBlock).toEqual(
expect.objectContaining({
number: 4_000_002,
hash: '0xe8657fc0154874e9412aea2c3567743d257384795d99719b900d628763ffb760',
hash: '0x9db1dc9525d7574ad6aed6b4302c9fb5069c5cd35288d97ebc78a58782f57b0d',
}),
)
const blockByNumber = await page.evaluate(() => globalThis.chain.db?.queryBlockByNumber(4_000_001))
expect(blockByNumber).toEqual(
expect.objectContaining({
number: 4_000_001,
hash: '0x64809750cb08df1076b3470ce42a0d1e1d45984d59bcfc876ce2d3424fd5416d',
hash: '0x7403a6c53702bfbace9737a5b3cc84fd02d5f8b30259e718455738ae841d992b',
}),
)
const blocksCount = await page.evaluate(() => globalThis.chain.db?.blocksCount())
Expand All @@ -87,7 +87,7 @@ test.describe('index', () => {
expect(hightestBlock).toEqual(
expect.objectContaining({
number: 4_000_001,
hash: '0x64809750cb08df1076b3470ce42a0d1e1d45984d59bcfc876ce2d3424fd5416d',
hash: '0x7403a6c53702bfbace9737a5b3cc84fd02d5f8b30259e718455738ae841d992b',
}),
)
}
Expand Down
Loading