Known upgrade points for on-chain version skip (#2545)
* Known upgrade points for on-chain version skip * Update packages/types-known/src/index.ts * Update packages/api/src/base/Init.ts * Actual known upgrade blocks for Polkadot & Kusama * Update with known Kusama upgrade history * linting
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import { DefinitionRpc, DefinitionRpcSub, Registry, RegistryTypes, OverrideModuleType, OverrideVersionedType } from '@polkadot/types/types';
|
||||
import { Hash } from '@polkadot/types/interfaces';
|
||||
import { ChainUpgradeVersion, DefinitionRpc, DefinitionRpcSub, Registry, RegistryTypes, OverrideModuleType, OverrideVersionedType } from '@polkadot/types/types';
|
||||
|
||||
import { Text } from '@polkadot/types';
|
||||
import { bnToBn, isUndefined } from '@polkadot/util';
|
||||
@@ -12,6 +13,7 @@ import typesChain from './chain';
|
||||
import typesMeta from './metadata';
|
||||
import typesModules from './modules';
|
||||
import typesSpec from './spec';
|
||||
import upgrades from './upgrades';
|
||||
import warnings from './warnings';
|
||||
|
||||
// flatten a VersionedType[] into a Record<string, string>
|
||||
@@ -91,3 +93,21 @@ export function getSpecAlias ({ knownTypes }: Registry, chainName: Text | string
|
||||
...(knownTypes.typesBundle?.chain?.[_chainName]?.alias || {})
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns a version record for known chains where upgrades are being tracked
|
||||
*/
|
||||
export function getUpgradeVersion (genesisHash: Hash, blockNumber: BN): [ChainUpgradeVersion | undefined, ChainUpgradeVersion | undefined] {
|
||||
const known = upgrades.find((u) => genesisHash.eq(u.genesisHash));
|
||||
|
||||
return known
|
||||
? [
|
||||
known.versions.reduce((last: ChainUpgradeVersion | undefined, version): ChainUpgradeVersion | undefined => {
|
||||
return blockNumber.gt(version.blockNumber)
|
||||
? version
|
||||
: last;
|
||||
}, undefined),
|
||||
known.versions.find((version) => blockNumber.lte(version.blockNumber))
|
||||
]
|
||||
: [undefined, undefined];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright 2017-2020 @polkadot/types-known authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ChainUpgrades } from '@polkadot/types/types';
|
||||
|
||||
import kusama from './kusama';
|
||||
import polkadot from './polkadot';
|
||||
|
||||
// Type overrides for specific spec types & versions as given in runtimeVersion
|
||||
const upgrades: ChainUpgrades[] = [
|
||||
kusama,
|
||||
polkadot
|
||||
];
|
||||
|
||||
export default upgrades;
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright 2017-2020 @polkadot/types-known authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ChainUpgrades } from '@polkadot/types/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { hexToU8a } from '@polkadot/util';
|
||||
|
||||
const upgrades: ChainUpgrades = {
|
||||
genesisHash: hexToU8a('0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe'),
|
||||
versions: [
|
||||
[0, 1020], [26669, 1021], [38245, 1022], [54248, 1023], [59659, 1024],
|
||||
[67651, 1025], [82191, 1027], [83238, 1028], [101503, 1029], [203466, 1030],
|
||||
[295787, 1031], [461692, 1032], [504329, 1033], [569327, 1038], [587687, 1039],
|
||||
[653183, 1040], [693488, 1042], [901442, 1045], [1375086, 1050], [1445458, 1051],
|
||||
[1472960, 1052], [1475648, 1053], [1491596, 1054], [1574408, 1055], [2064961, 1058],
|
||||
[2201991, 1062], [2671528, 2005], [2704202, 2007], [2728002, 2008], [2832534, 2011],
|
||||
[2962294, 2012], [3240000, 2013], [3274408, 2015], [3323565, 2019], [3534175, 2022]
|
||||
].map(([blockNumber, specVersion]) => ({
|
||||
blockNumber: new BN(blockNumber),
|
||||
specVersion: new BN(specVersion)
|
||||
}))
|
||||
};
|
||||
|
||||
export default upgrades;
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright 2017-2020 @polkadot/types-known authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ChainUpgrades } from '@polkadot/types/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { hexToU8a } from '@polkadot/util';
|
||||
|
||||
const upgrades: ChainUpgrades = {
|
||||
genesisHash: hexToU8a('0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3'),
|
||||
versions: [
|
||||
[0, 0], [29231, 1], [188836, 5], [199405, 6], [214264, 7],
|
||||
[244358, 8], [303079, 9], [314201, 10], [342400, 11], [443963, 12],
|
||||
[528470, 13], [687751, 14], [746085, 15], [787923, 16], [799302, 17],
|
||||
[1205128, 18]
|
||||
].map(([blockNumber, specVersion]) => ({
|
||||
blockNumber: new BN(blockNumber),
|
||||
specVersion: new BN(specVersion)
|
||||
}))
|
||||
};
|
||||
|
||||
export default upgrades;
|
||||
Reference in New Issue
Block a user