Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix slot increase #677

Merged
merged 1 commit into from
Mar 3, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AbridgedHrmpChannel, HrmpChannelId, Slot } from '@polkadot/types/interfaces'
import { BN, hexToU8a, u8aConcat, u8aToHex } from '@polkadot/util'
import { GenericExtrinsic } from '@polkadot/types'
import { HexString } from '@polkadot/util/types'
import { hexToU8a, u8aConcat, u8aToHex } from '@polkadot/util'
import _ from 'lodash'

import { Block } from '../../block.js'
Expand Down Expand Up @@ -113,14 +113,17 @@ export class SetValidationData implements InherentProvider {
extrinsic.relayChainState.trieNodes,
)

const slotIncrease = (meta.consts.timestamp.minimumPeriod as any as BN)
.divn(3000) // relaychain min period
.toNumber()

for (const key of Object.values(WELL_KNOWN_KEYS)) {
if (key === WELL_KNOWN_KEYS.CURRENT_SLOT) {
// increment current slot
const currentSlot = decoded[key]
const relayCurrentSlot = decoded[key]
? meta.registry.createType<Slot>('Slot', hexToU8a(decoded[key])).toNumber()
: // releay chain slot is 2x parachain slot
(await getCurrentSlot(parent.chain)) * 2
const newSlot = meta.registry.createType<Slot>('Slot', currentSlot + 2)
: (await getCurrentSlot(parent.chain)) * slotIncrease
const newSlot = meta.registry.createType<Slot>('Slot', relayCurrentSlot + slotIncrease)
newEntries.push([key, u8aToHex(newSlot.toU8a())])
} else {
newEntries.push([key, decoded[key]])
Expand Down Expand Up @@ -267,7 +270,7 @@ export class SetValidationData implements InherentProvider {
validationData: {
...extrinsic.validationData,
relayParentStorageRoot: trieRootHash,
relayParentNumber: extrinsic.validationData.relayParentNumber + 2,
relayParentNumber: extrinsic.validationData.relayParentNumber + slotIncrease,
},
relayChainState: {
trieNodes: nodes,
Expand Down
Loading